From 44ef9e5596576f2e47a9b63c403ac7c1b67f70be Mon Sep 17 00:00:00 2001 From: lybell Date: Mon, 23 May 2022 01:04:52 +0900 Subject: [PATCH 01/11] code split(to core/readers) --- builder/polyfills/corejs.js | 2 - builder/polyfills/makePolyfill.js | 8 +- builder/rollup.config.js | 192 +- dist/core/core.cjs | 5356 +++++++ dist/core/core.es5.js | 9250 +++++++++++ dist/core/core.es5.min.js | 1 + dist/core/core.js | 5362 +++++++ dist/core/core.min.js | 41 + dist/core/core.module.js | 5341 +++++++ dist/readers/readers.cjs | 2694 ++++ dist/readers/readers.es5.js | 4709 ++++++ dist/readers/readers.es5.min.js | 23 + dist/readers/readers.js | 2700 ++++ dist/readers/readers.min.js | 24 + dist/readers/readers.module.js | 2668 ++++ dist/xnb.cjs | 10337 +++++++------ dist/xnb.es5.js | 12842 ++++++++-------- dist/xnb.es5.min.js | 25 +- dist/xnb.js | 10337 +++++++------ dist/xnb.min.js | 67 +- dist/xnb.module.js | 10337 +++++++------ {src => docs/js/libs/src}/App/BufferReader.js | 0 {src => docs/js/libs/src}/App/BufferWriter.js | 0 .../src}/App/Decompressor/LZXDecompressor.js | 0 .../js/libs/src}/App/Decompressor/Lz4.js | 0 .../js/libs/src}/App/Decompressor/Lzx.js | 0 .../js/libs/src}/App/Decompressor/dxt.js | 0 .../App/Decompressor/dxt/alphaCompressor.js | 0 .../src}/App/Decompressor/dxt/colorBlock.js | 0 .../src}/App/Decompressor/dxt/colorFits.js | 0 .../src}/App/Decompressor/dxt/constant.js | 0 .../src}/App/Decompressor/dxt/decompressor.js | 0 .../js/libs/src}/App/Decompressor/dxt/eigs.js | 0 .../libs/src}/App/Decompressor/dxt/lookup.js | 0 .../js/libs/src}/App/Decompressor/dxt/math.js | 0 .../libs/src}/App/Decompressor/lz4/utils.js | 0 .../libs/src}/App/Decompressor/lz4/xxh32.js | 0 .../js/libs/src}/App/ReaderResolver.js | 0 docs/js/libs/src/App/Readers/ArrayReader.js | 87 + .../js/libs/src}/App/Readers/BaseReader.js | 10 + .../js/libs/src}/App/Readers/BmFontReader.js | 9 + .../js/libs/src}/App/Readers/BooleanReader.js | 10 + .../js/libs/src}/App/Readers/CharReader.js | 10 + .../libs/src}/App/Readers/DictionaryReader.js | 12 + .../js/libs/src}/App/Readers/DoubleReader.js | 0 .../js/libs/src}/App/Readers/EffectReader.js | 0 .../js/libs/src}/App/Readers/Int32Reader.js | 0 .../js/libs/src}/App/Readers/ListReader.js | 0 .../libs/src}/App/Readers/NullableReader.js | 0 .../js/libs/src}/App/Readers/Readers.js | 0 .../libs/src}/App/Readers/RectangleReader.js | 0 .../libs/src}/App/Readers/ReflectiveReader.js | 0 .../js/libs/src}/App/Readers/SingleReader.js | 0 .../libs/src}/App/Readers/SpriteFontReader.js | 0 .../js/libs/src}/App/Readers/StringReader.js | 0 .../js/libs/src}/App/Readers/TBinReader.js | 0 .../libs/src}/App/Readers/Texture2DReader.js | 0 .../js/libs/src}/App/Readers/UInt32Reader.js | 0 .../js/libs/src}/App/Readers/Vector2Reader.js | 0 .../js/libs/src}/App/Readers/Vector3Reader.js | 0 .../js/libs/src}/App/Readers/Vector4Reader.js | 0 {src => docs/js/libs/src}/App/TypeReader.js | 0 {src => docs/js/libs/src}/App/Xnb.js | 2 + {src => docs/js/libs/src}/App/XnbData.js | 0 {src => docs/js/libs/src}/Files.js | 0 {src => docs/js/libs/src}/Utils/Debug.js | 0 .../js/libs/src}/Utils/UTF8ToString.js | 0 {src => docs/js/libs/src}/Utils/XnbError.js | 0 .../js/libs/src}/Utils/xnbNodeConverter.js | 0 {src => docs/js/libs/src}/XnbUnpacker.js | 5 + docs/js/libs/src/es5.js | 7 + {src => docs/js/libs/src}/libs/jsonToYaml.js | 0 {src => docs/js/libs/src}/libs/png.js | 0 docs/js/libs/unpackWorker.js | 2 +- package.json | 7 +- readme.md | 60 + src/core/App/BufferReader.js | 556 + src/core/App/BufferWriter.js | 208 + src/core/App/Decompressor/LZXDecompressor.js | 88 + src/core/App/Decompressor/Lz4.js | 574 + src/core/App/Decompressor/Lzx.js | 763 + src/core/App/Decompressor/lz4/utils.js | 59 + src/core/App/Decompressor/lz4/xxh32.js | 102 + src/core/App/ReaderResolver.js | 58 + src/core/App/Readers/StringReader.js | 36 + src/core/App/Readers/TypeReader.js | 174 + src/core/App/XnbConverter.js | 375 + src/core/App/XnbData.js | 90 + src/core/Files.js | 280 + src/core/Utils/Debug.js | 16 + src/core/Utils/UTF8ToString.js | 183 + src/core/Utils/XnbError.js | 8 + src/core/Utils/xnbNodeConverter.js | 281 + src/core/Xnb.js | 210 + src/core/dist/core.cjs | 5356 +++++++ src/core/dist/core.es5.js | 9250 +++++++++++ src/core/dist/core.es5.min.js | 1 + src/core/dist/core.js | 5362 +++++++ src/core/dist/core.min.js | 41 + src/core/dist/core.module.js | 5341 +++++++ src/core/es5.js | 4 + src/core/libs/jsonToYaml.js | 220 + src/core/libs/png.js | 1 + src/core/package.json | 24 + src/es5.js | 5 +- src/plugins-stardewvalley/readers.js | 0 src/readers/LICENSE | 165 + src/readers/LICENSE-GPL.md | 674 + src/readers/dist/readers.cjs | 2718 ++++ src/readers/dist/readers.es5.js | 4734 ++++++ src/readers/dist/readers.es5.min.js | 23 + src/readers/dist/readers.js | 2724 ++++ src/readers/dist/readers.min.js | 24 + src/readers/dist/readers.module.js | 2692 ++++ src/readers/es5.js | 4 + src/readers/libs/UTF8ToString.js | 183 + src/readers/libs/dxt.js | 328 + src/readers/libs/dxt/alphaCompressor.js | 213 + src/readers/libs/dxt/colorBlock.js | 111 + src/readers/libs/dxt/colorFits.js | 744 + src/readers/libs/dxt/constant.js | 21 + src/readers/libs/dxt/decompressor.js | 163 + src/readers/libs/dxt/eigs.js | 162 + src/readers/libs/dxt/lookup.js | 1041 ++ src/readers/libs/dxt/math.js | 448 + src/readers/package.json | 24 + src/readers/readers.js | 49 + .../readers}/ArrayReader.js | 11 +- src/readers/readers/BaseReader.js | 79 + src/readers/readers/BmFontReader.js | 45 + src/readers/readers/BooleanReader.js | 37 + src/readers/readers/CharReader.js | 47 + src/readers/readers/DictionaryReader.js | 100 + src/readers/readers/DoubleReader.js | 37 + src/readers/readers/EffectReader.js | 47 + src/readers/readers/Int32Reader.js | 37 + .../readers/LightweightTexture2DReader.js | 108 + src/readers/readers/ListReader.js | 70 + src/readers/readers/NullableReader.js | 85 + src/readers/readers/RectangleReader.js | 49 + src/readers/readers/ReflectiveReader.js | 61 + src/readers/readers/SingleReader.js | 31 + src/readers/readers/SpriteFontReader.js | 99 + src/readers/readers/StringReader.js | 51 + src/readers/readers/TBinReader.js | 41 + src/readers/readers/Texture2DReader.js | 115 + src/readers/readers/UInt32Reader.js | 37 + src/readers/readers/Vector2Reader.js | 32 + src/readers/readers/Vector3Reader.js | 41 + src/readers/readers/Vector4Reader.js | 33 + src/xnb.js | 63 + 151 files changed, 109729 insertions(+), 21075 deletions(-) create mode 100644 dist/core/core.cjs create mode 100644 dist/core/core.es5.js create mode 100644 dist/core/core.es5.min.js create mode 100644 dist/core/core.js create mode 100644 dist/core/core.min.js create mode 100644 dist/core/core.module.js create mode 100644 dist/readers/readers.cjs create mode 100644 dist/readers/readers.es5.js create mode 100644 dist/readers/readers.es5.min.js create mode 100644 dist/readers/readers.js create mode 100644 dist/readers/readers.min.js create mode 100644 dist/readers/readers.module.js rename {src => docs/js/libs/src}/App/BufferReader.js (100%) rename {src => docs/js/libs/src}/App/BufferWriter.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/LZXDecompressor.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/Lz4.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/Lzx.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/alphaCompressor.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/colorBlock.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/colorFits.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/constant.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/decompressor.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/eigs.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/lookup.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/dxt/math.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/lz4/utils.js (100%) rename {src => docs/js/libs/src}/App/Decompressor/lz4/xxh32.js (100%) rename {src => docs/js/libs/src}/App/ReaderResolver.js (100%) create mode 100644 docs/js/libs/src/App/Readers/ArrayReader.js rename {src => docs/js/libs/src}/App/Readers/BaseReader.js (94%) rename {src => docs/js/libs/src}/App/Readers/BmFontReader.js (86%) rename {src => docs/js/libs/src}/App/Readers/BooleanReader.js (77%) rename {src => docs/js/libs/src}/App/Readers/CharReader.js (83%) rename {src => docs/js/libs/src}/App/Readers/DictionaryReader.js (92%) rename {src => docs/js/libs/src}/App/Readers/DoubleReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/EffectReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Int32Reader.js (100%) rename {src => docs/js/libs/src}/App/Readers/ListReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/NullableReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Readers.js (100%) rename {src => docs/js/libs/src}/App/Readers/RectangleReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/ReflectiveReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/SingleReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/SpriteFontReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/StringReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/TBinReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Texture2DReader.js (100%) rename {src => docs/js/libs/src}/App/Readers/UInt32Reader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Vector2Reader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Vector3Reader.js (100%) rename {src => docs/js/libs/src}/App/Readers/Vector4Reader.js (100%) rename {src => docs/js/libs/src}/App/TypeReader.js (100%) rename {src => docs/js/libs/src}/App/Xnb.js (99%) rename {src => docs/js/libs/src}/App/XnbData.js (100%) rename {src => docs/js/libs/src}/Files.js (100%) rename {src => docs/js/libs/src}/Utils/Debug.js (100%) rename {src => docs/js/libs/src}/Utils/UTF8ToString.js (100%) rename {src => docs/js/libs/src}/Utils/XnbError.js (100%) rename {src => docs/js/libs/src}/Utils/xnbNodeConverter.js (100%) rename {src => docs/js/libs/src}/XnbUnpacker.js (95%) create mode 100644 docs/js/libs/src/es5.js rename {src => docs/js/libs/src}/libs/jsonToYaml.js (100%) rename {src => docs/js/libs/src}/libs/png.js (100%) create mode 100644 src/core/App/BufferReader.js create mode 100644 src/core/App/BufferWriter.js create mode 100644 src/core/App/Decompressor/LZXDecompressor.js create mode 100644 src/core/App/Decompressor/Lz4.js create mode 100644 src/core/App/Decompressor/Lzx.js create mode 100644 src/core/App/Decompressor/lz4/utils.js create mode 100644 src/core/App/Decompressor/lz4/xxh32.js create mode 100644 src/core/App/ReaderResolver.js create mode 100644 src/core/App/Readers/StringReader.js create mode 100644 src/core/App/Readers/TypeReader.js create mode 100644 src/core/App/XnbConverter.js create mode 100644 src/core/App/XnbData.js create mode 100644 src/core/Files.js create mode 100644 src/core/Utils/Debug.js create mode 100644 src/core/Utils/UTF8ToString.js create mode 100644 src/core/Utils/XnbError.js create mode 100644 src/core/Utils/xnbNodeConverter.js create mode 100644 src/core/Xnb.js create mode 100644 src/core/dist/core.cjs create mode 100644 src/core/dist/core.es5.js create mode 100644 src/core/dist/core.es5.min.js create mode 100644 src/core/dist/core.js create mode 100644 src/core/dist/core.min.js create mode 100644 src/core/dist/core.module.js create mode 100644 src/core/es5.js create mode 100644 src/core/libs/jsonToYaml.js create mode 100644 src/core/libs/png.js create mode 100644 src/core/package.json create mode 100644 src/plugins-stardewvalley/readers.js create mode 100644 src/readers/LICENSE create mode 100644 src/readers/LICENSE-GPL.md create mode 100644 src/readers/dist/readers.cjs create mode 100644 src/readers/dist/readers.es5.js create mode 100644 src/readers/dist/readers.es5.min.js create mode 100644 src/readers/dist/readers.js create mode 100644 src/readers/dist/readers.min.js create mode 100644 src/readers/dist/readers.module.js create mode 100644 src/readers/es5.js create mode 100644 src/readers/libs/UTF8ToString.js create mode 100644 src/readers/libs/dxt.js create mode 100644 src/readers/libs/dxt/alphaCompressor.js create mode 100644 src/readers/libs/dxt/colorBlock.js create mode 100644 src/readers/libs/dxt/colorFits.js create mode 100644 src/readers/libs/dxt/constant.js create mode 100644 src/readers/libs/dxt/decompressor.js create mode 100644 src/readers/libs/dxt/eigs.js create mode 100644 src/readers/libs/dxt/lookup.js create mode 100644 src/readers/libs/dxt/math.js create mode 100644 src/readers/package.json create mode 100644 src/readers/readers.js rename src/{App/Readers => readers/readers}/ArrayReader.js (90%) create mode 100644 src/readers/readers/BaseReader.js create mode 100644 src/readers/readers/BmFontReader.js create mode 100644 src/readers/readers/BooleanReader.js create mode 100644 src/readers/readers/CharReader.js create mode 100644 src/readers/readers/DictionaryReader.js create mode 100644 src/readers/readers/DoubleReader.js create mode 100644 src/readers/readers/EffectReader.js create mode 100644 src/readers/readers/Int32Reader.js create mode 100644 src/readers/readers/LightweightTexture2DReader.js create mode 100644 src/readers/readers/ListReader.js create mode 100644 src/readers/readers/NullableReader.js create mode 100644 src/readers/readers/RectangleReader.js create mode 100644 src/readers/readers/ReflectiveReader.js create mode 100644 src/readers/readers/SingleReader.js create mode 100644 src/readers/readers/SpriteFontReader.js create mode 100644 src/readers/readers/StringReader.js create mode 100644 src/readers/readers/TBinReader.js create mode 100644 src/readers/readers/Texture2DReader.js create mode 100644 src/readers/readers/UInt32Reader.js create mode 100644 src/readers/readers/Vector2Reader.js create mode 100644 src/readers/readers/Vector3Reader.js create mode 100644 src/readers/readers/Vector4Reader.js create mode 100644 src/xnb.js diff --git a/builder/polyfills/corejs.js b/builder/polyfills/corejs.js index 2afc4d7..d8cccff 100644 --- a/builder/polyfills/corejs.js +++ b/builder/polyfills/corejs.js @@ -1,5 +1,3 @@ export "core-js/modules/es.promise.js"; export "regenerator-runtime/runtime.js"; -export "core-js/modules/es.object.get-own-property-descriptors.js"; -export "core-js/modules/es.function.name.js"; export "core-js/modules/es.typed-array.map.js"; \ No newline at end of file diff --git a/builder/polyfills/makePolyfill.js b/builder/polyfills/makePolyfill.js index be012d2..a6b7b9f 100644 --- a/builder/polyfills/makePolyfill.js +++ b/builder/polyfills/makePolyfill.js @@ -133,13 +133,13 @@ export default function polyfiller({version="es5"} = {}) { if(version !== "es2017") { //str.repeat() polyfill - code = polyfill(code, "__repeatConcat", /(["'`\(\[].*["'`\)\]]|[0-9a-zA-Z_$])\.repeat\(([^)]+)/g, "__repeatConcat($1, $2"); + code = polyfill(code, "__repeatConcat", /(["'`\(\[].*["'`\)\]]|[0-9a-zA-Z_$]+)\.repeat\(([^)]+)/g, "__repeatConcat($1, $2"); //str.startsWith() polyfill - code = polyfill(code, "__startsWithString", /(["'`\(].*["'`\)]|[0-9a-zA-Z_$])\.startsWith\(([^)]+)/g, "__startsWithString($1, $2"); + code = polyfill(code, "__startsWithString", /(["'`\(].*["'`\)]|[0-9a-zA-Z_$]+)\.startsWith\(([^)]+)/g, "__startsWithString($1, $2"); //str.endsWith() polyfill - code = polyfill(code, "__endsWithString", /(["'`\(].*["'`\)]|[0-9a-zA-Z_$])\.endsWith\(([^)]+)/g, "__endsWithString($1, $2"); + code = polyfill(code, "__endsWithString", /(["'`\(].*["'`\)]|[0-9a-zA-Z_$]+)\.endsWith\(([^)]+)/g, "__endsWithString($1, $2"); //str.includes() polyfill - code = polyfill(code, "__includes", /(["'`\[].*["'`\]]|[0-9a-zA-Z_$])\.includes\(([^)]+)/g, "__includes($1, $2"); + code = polyfill(code, "__includes", /(["'`\[].*["'`\]]|[0-9a-zA-Z_$]+)\.includes\(([^)]+)/g, "__includes($1, $2"); //Number.parseInt() polyfill code = code.replaceAll("Number.parseInt", "parseInt"); diff --git a/builder/rollup.config.js b/builder/rollup.config.js index d6602c0..1cf73ff 100644 --- a/builder/rollup.config.js +++ b/builder/rollup.config.js @@ -40,104 +40,120 @@ function babelCleanup() { }; } -let builds = [ -// for es2017+ module +function buildMaker(srcBase, srcName, dist) { - input: 'src/XnbUnpacker.js', - output: [{ - file: 'dist/xnb.module.js', - format: 'esm' - }, + return [ + // for es2017+ module { - file: 'dist/xnb.cjs', - name: "XNB", - format: 'cjs' + input: `${srcBase}/${srcName}.js`, + output: [{ + file: `${dist}.module.js`, + format: 'esm' + }, + { + file: `${dist}.cjs`, + name: "XNB", + format: 'cjs' + }, + { + file: `${dist}.js`, + name: "XNB", + format: 'umd' + }], + plugins: [ + removeDebug(), + polyfill({version:"es2017"}), + babel({ + babelHelpers:'bundled', + babelrc: false, + ...babelrc, + shouldPrintComment:(val)=>/^\* @(api|license)(?!\S)/.test(val) + }), + babelCleanup() + ] }, { - file: 'dist/xnb.js', - name: "XNB", - format: 'umd' - }], - plugins: [ - removeDebug(), - polyfill({version:"es2017"}), - babel({ - babelHelpers:'bundled', - babelrc: false, - ...babelrc, - shouldPrintComment:(val)=>val.startsWith("* @api") - }), - babelCleanup() - ] -}, -{ - input: 'src/XnbUnpacker.js', - output: { - file: 'dist/xnb.min.js', - name: "XNB", - format: 'umd' + input: `${srcBase}/${srcName}.js`, + output: { + file: `${dist}.min.js`, + name: "XNB", + format: 'umd' + }, + plugins: [ + removeDebug(), + polyfill({version:"es2017"}), + babel({ + babelHelpers:'bundled', + babelrc: false, + ...babelrc + }), + babelCleanup(), + terser() + ] }, - plugins: [ - removeDebug(), - polyfill({version:"es2017"}), - babel({ - babelHelpers:'bundled', - babelrc: false, - ...babelrc - }), - babelCleanup(), - terser() - ] -}, -// for es5(legacy) -{ - input: 'src/es5.js', - output: { - file: 'dist/xnb.es5.js', - name: 'XNB', - format: 'umd', - indent: '\t' + // for es5(legacy) + { + input: `${srcBase}/es5.js`, + output: { + file: `${dist}.es5.js`, + name: "XNB", + format: 'umd', + indent: '\t' + }, + plugins: [ + nodeResolve(), + commonjs(), + removeDebug(), + polyfill(), + babel({ + babelHelpers:'bundled', + babelrc: false, + exclude:'node_modules/**', + ...es5babelrc, + shouldPrintComment:(val)=>val.startsWith("* @api") + }), + babelCleanup() + ] }, - plugins: [ - nodeResolve(), - commonjs(), - removeDebug(), - polyfill(), - babel({ - babelHelpers:'bundled', - babelrc: false, - exclude:'node_modules/**', - ...es5babelrc, - shouldPrintComment:(val)=>val.startsWith("* @api") - }), - babelCleanup() - ] -}, + { + input: `${srcBase}/es5.js`, + output: { + file: `${dist}.es5.min.js`, + name: "XNB", + format: 'umd', + indent: '\t' + }, + plugins: [ + nodeResolve(), + commonjs(), + removeDebug(), + polyfill(), + babel({ + babelHelpers:'bundled', + babelrc: false, + exclude:'node_modules/**', + ...es5babelrc + }), + babelCleanup(), + terser() + ] + } ]; +} + +function buildTargetMaker(target=-1) { - input: 'src/es5.js', - output: { - file: 'dist/xnb.es5.min.js', - name: 'XNB', - format: 'umd', - indent: '\t' - }, - plugins: [ - nodeResolve(), - commonjs(), - removeDebug(), - polyfill(), - babel({ - babelHelpers:'bundled', - babelrc: false, - exclude:'node_modules/**', - ...es5babelrc - }), - babelCleanup(), - terser() + const targetArray = [ + ["src", "xnb", "dist/xnb"], + ["src/core", "Xnb", "src/core/dist/core"], + ["src/readers", "readers", "src/readers/dist/readers"], +// ["src/plugins-stardewvalley/", "readers", "src/plugins-stardewvalley/dist"] ] + + if(target >= 0 ) return buildMaker(...targetArray[target]); + return targetArray.map((paths)=>buildMaker(...paths)).flat(); } -] +const builds = buildTargetMaker(process.env.BUILD_MODULE); export default builds; \ No newline at end of file diff --git a/dist/core/core.cjs b/dist/core/core.cjs new file mode 100644 index 0000000..395110f --- /dev/null +++ b/dist/core/core.cjs @@ -0,0 +1,5356 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); +}; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + +const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES = 0x80; +const UTF8_MASK = 0b111111; +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; + +function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; +} + +function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; +} + +function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); +} + +function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; +} + +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; +} + +function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; +} + +function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; +} + +function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); +} + +function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); +} + +const LITTLE_ENDIAN = true; + +class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + +} + +class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + +} + +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ +const MIN_MATCH = 2; +const NUM_CHARS = 256; +const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 +}; +const PRETREE_NUM_ELEMENTS = 20; +const ALIGNED_NUM_ELEMENTS = 8; +const NUM_PRIMARY_LENGTHS = 7; +const NUM_SECONDARY_LENGTHS = 249; +const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; +const PRETREE_TABLEBITS = 6; +const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; +const MAINTREE_TABLEBITS = 12; +const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; +const LENGTH_TABLEBITS = 12; +const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; +const ALIGNED_TABLEBITS = 7; + +class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + +} + +Lzx.position_base = []; +Lzx.extra_bits = []; + +class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + +} + +class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + +} + +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ +const minMatch = 4; +const minLength = 13; +const searchLimit = 5; +const skipTrigger = 6; +const hashSize = 1 << 16; +const mlBits = 4; +const mlMask = (1 << mlBits) - 1; +const runBits = 4; +const runMask = (1 << runBits) - 1; +makeBuffer(5 << 20); +const hashTable = makeHashTable(); + +function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } +} + +function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } +} + +function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } +} + +function compressBound(n) { + return n + n / 255 + 16 | 0; +} + +function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; +} + +function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; +} + +function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + +} + +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + +} + +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + +} + +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; +} + +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + +} + +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + +} + +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } +}, + e = {}; + +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; +} + +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; + +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); + +var r = n.P, + s = n.m; + +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} + +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} + +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); +} + +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + +} + +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; +} + +function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; +} + +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} + +function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; +} + +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } +} + +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } +} + +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; +} + +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} + +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; +} + +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; +} + +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} + +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; +} + +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; +} + +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} + +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} + +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} + +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} + +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} + +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} + +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; +} + +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + +function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} + +function setReaders(readers) { + return TypeReader.setReaders(readers); +} + +function addReaders(readers) { + return TypeReader.addReaders(readers); +} + +exports.XnbContent = XnbContent; +exports.XnbData = XnbData; +exports.addReaders = addReaders; +exports.bufferToContents = bufferToContents; +exports.bufferToXnb = bufferToXnb; +exports.pack = pack; +exports.setReaders = setReaders; +exports.unpackToContent = unpackToContent; +exports.unpackToFiles = unpackToFiles; +exports.unpackToXnbData = unpackToXnbData; +exports.xnbDataToContent = xnbDataToContent; +exports.xnbDataToFiles = exportFiles; diff --git a/dist/core/core.es5.js b/dist/core/core.es5.js new file mode 100644 index 0000000..0cfa925 --- /dev/null +++ b/dist/core/core.es5.js @@ -0,0 +1,9250 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + var check = function (it) { + return it && it.Math == Math && it; + }; + + // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + var global$A = + // eslint-disable-next-line es-x/no-global-this -- safe + check(typeof globalThis == 'object' && globalThis) || + check(typeof window == 'object' && window) || + // eslint-disable-next-line no-restricted-globals -- safe + check(typeof self == 'object' && self) || + check(typeof commonjsGlobal == 'object' && commonjsGlobal) || + // eslint-disable-next-line no-new-func -- fallback + (function () { return this; })() || Function('return this')(); + + var objectGetOwnPropertyDescriptor = {}; + + var fails$a = function (exec) { + try { + return !!exec(); + } catch (error) { + return true; + } + }; + + var fails$9 = fails$a; + + // Detect IE8's incomplete defineProperty implementation + var descriptors = !fails$9(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7; + }); + + var fails$8 = fails$a; + + var functionBindNative = !fails$8(function () { + // eslint-disable-next-line es-x/no-function-prototype-bind -- safe + var test = (function () { /* empty */ }).bind(); + // eslint-disable-next-line no-prototype-builtins -- safe + return typeof test != 'function' || test.hasOwnProperty('prototype'); + }); + + var NATIVE_BIND$3 = functionBindNative; + + var call$c = Function.prototype.call; + + var functionCall = NATIVE_BIND$3 ? call$c.bind(call$c) : function () { + return call$c.apply(call$c, arguments); + }; + + var objectPropertyIsEnumerable = {}; + + var $propertyIsEnumerable = {}.propertyIsEnumerable; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getOwnPropertyDescriptor$2 = Object.getOwnPropertyDescriptor; + + // Nashorn ~ JDK8 bug + var NASHORN_BUG = getOwnPropertyDescriptor$2 && !$propertyIsEnumerable.call({ 1: 2 }, 1); + + // `Object.prototype.propertyIsEnumerable` method implementation + // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable + objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) { + var descriptor = getOwnPropertyDescriptor$2(this, V); + return !!descriptor && descriptor.enumerable; + } : $propertyIsEnumerable; + + var createPropertyDescriptor$2 = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; + }; + + var NATIVE_BIND$2 = functionBindNative; + + var FunctionPrototype$2 = Function.prototype; + var bind$5 = FunctionPrototype$2.bind; + var call$b = FunctionPrototype$2.call; + var uncurryThis$d = NATIVE_BIND$2 && bind$5.bind(call$b, call$b); + + var functionUncurryThis = NATIVE_BIND$2 ? function (fn) { + return fn && uncurryThis$d(fn); + } : function (fn) { + return fn && function () { + return call$b.apply(fn, arguments); + }; + }; + + var uncurryThis$c = functionUncurryThis; + + var toString$1 = uncurryThis$c({}.toString); + var stringSlice = uncurryThis$c(''.slice); + + var classofRaw$1 = function (it) { + return stringSlice(toString$1(it), 8, -1); + }; + + var global$z = global$A; + var uncurryThis$b = functionUncurryThis; + var fails$7 = fails$a; + var classof$4 = classofRaw$1; + + var Object$4 = global$z.Object; + var split = uncurryThis$b(''.split); + + // fallback for non-array-like ES3 and non-enumerable old V8 strings + var indexedObject = fails$7(function () { + // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 + // eslint-disable-next-line no-prototype-builtins -- safe + return !Object$4('z').propertyIsEnumerable(0); + }) ? function (it) { + return classof$4(it) == 'String' ? split(it, '') : Object$4(it); + } : Object$4; + + var global$y = global$A; + + var TypeError$e = global$y.TypeError; + + // `RequireObjectCoercible` abstract operation + // https://tc39.es/ecma262/#sec-requireobjectcoercible + var requireObjectCoercible$2 = function (it) { + if (it == undefined) throw TypeError$e("Can't call method on " + it); + return it; + }; + + // toObject with fallback for non-array-like ES3 strings + var IndexedObject = indexedObject; + var requireObjectCoercible$1 = requireObjectCoercible$2; + + var toIndexedObject$3 = function (it) { + return IndexedObject(requireObjectCoercible$1(it)); + }; + + // `IsCallable` abstract operation + // https://tc39.es/ecma262/#sec-iscallable + var isCallable$h = function (argument) { + return typeof argument == 'function'; + }; + + var isCallable$g = isCallable$h; + + var isObject$7 = function (it) { + return typeof it == 'object' ? it !== null : isCallable$g(it); + }; + + var global$x = global$A; + var isCallable$f = isCallable$h; + + var aFunction = function (argument) { + return isCallable$f(argument) ? argument : undefined; + }; + + var getBuiltIn$8 = function (namespace, method) { + return arguments.length < 2 ? aFunction(global$x[namespace]) : global$x[namespace] && global$x[namespace][method]; + }; + + var uncurryThis$a = functionUncurryThis; + + var objectIsPrototypeOf = uncurryThis$a({}.isPrototypeOf); + + var getBuiltIn$7 = getBuiltIn$8; + + var engineUserAgent = getBuiltIn$7('navigator', 'userAgent') || ''; + + var global$w = global$A; + var userAgent$3 = engineUserAgent; + + var process$3 = global$w.process; + var Deno$1 = global$w.Deno; + var versions = process$3 && process$3.versions || Deno$1 && Deno$1.version; + var v8 = versions && versions.v8; + var match, version; + + if (v8) { + match = v8.split('.'); + // in old Chrome, versions of V8 isn't V8 = Chrome / 10 + // but their correct versions are not interesting for us + version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); + } + + // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` + // so check `userAgent` even if `.v8` exists, but 0 + if (!version && userAgent$3) { + match = userAgent$3.match(/Edge\/(\d+)/); + if (!match || match[1] >= 74) { + match = userAgent$3.match(/Chrome\/(\d+)/); + if (match) version = +match[1]; + } + } + + var engineV8Version = version; + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var V8_VERSION$1 = engineV8Version; + var fails$6 = fails$a; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- required for testing + var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$6(function () { + var symbol = Symbol(); + // Chrome 38 Symbol has incorrect toString conversion + // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances + return !String(symbol) || !(Object(symbol) instanceof Symbol) || + // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances + !Symbol.sham && V8_VERSION$1 && V8_VERSION$1 < 41; + }); + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var NATIVE_SYMBOL$1 = nativeSymbol; + + var useSymbolAsUid = NATIVE_SYMBOL$1 + && !Symbol.sham + && typeof Symbol.iterator == 'symbol'; + + var global$v = global$A; + var getBuiltIn$6 = getBuiltIn$8; + var isCallable$e = isCallable$h; + var isPrototypeOf$2 = objectIsPrototypeOf; + var USE_SYMBOL_AS_UID$1 = useSymbolAsUid; + + var Object$3 = global$v.Object; + + var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) { + return typeof it == 'symbol'; + } : function (it) { + var $Symbol = getBuiltIn$6('Symbol'); + return isCallable$e($Symbol) && isPrototypeOf$2($Symbol.prototype, Object$3(it)); + }; + + var global$u = global$A; + + var String$4 = global$u.String; + + var tryToString$4 = function (argument) { + try { + return String$4(argument); + } catch (error) { + return 'Object'; + } + }; + + var global$t = global$A; + var isCallable$d = isCallable$h; + var tryToString$3 = tryToString$4; + + var TypeError$d = global$t.TypeError; + + // `Assert: IsCallable(argument) is true` + var aCallable$7 = function (argument) { + if (isCallable$d(argument)) return argument; + throw TypeError$d(tryToString$3(argument) + ' is not a function'); + }; + + var aCallable$6 = aCallable$7; + + // `GetMethod` abstract operation + // https://tc39.es/ecma262/#sec-getmethod + var getMethod$3 = function (V, P) { + var func = V[P]; + return func == null ? undefined : aCallable$6(func); + }; + + var global$s = global$A; + var call$a = functionCall; + var isCallable$c = isCallable$h; + var isObject$6 = isObject$7; + + var TypeError$c = global$s.TypeError; + + // `OrdinaryToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-ordinarytoprimitive + var ordinaryToPrimitive$1 = function (input, pref) { + var fn, val; + if (pref === 'string' && isCallable$c(fn = input.toString) && !isObject$6(val = call$a(fn, input))) return val; + if (isCallable$c(fn = input.valueOf) && !isObject$6(val = call$a(fn, input))) return val; + if (pref !== 'string' && isCallable$c(fn = input.toString) && !isObject$6(val = call$a(fn, input))) return val; + throw TypeError$c("Can't convert object to primitive value"); + }; + + var shared$3 = {exports: {}}; + + var global$r = global$A; + + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var defineProperty$2 = Object.defineProperty; + + var setGlobal$3 = function (key, value) { + try { + defineProperty$2(global$r, key, { value: value, configurable: true, writable: true }); + } catch (error) { + global$r[key] = value; + } return value; + }; + + var global$q = global$A; + var setGlobal$2 = setGlobal$3; + + var SHARED = '__core-js_shared__'; + var store$3 = global$q[SHARED] || setGlobal$2(SHARED, {}); + + var sharedStore = store$3; + + var store$2 = sharedStore; + + (shared$3.exports = function (key, value) { + return store$2[key] || (store$2[key] = value !== undefined ? value : {}); + })('versions', []).push({ + version: '3.22.4', + mode: 'global', + copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)', + license: 'https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE', + source: 'https://github.com/zloirock/core-js' + }); + + var global$p = global$A; + var requireObjectCoercible = requireObjectCoercible$2; + + var Object$2 = global$p.Object; + + // `ToObject` abstract operation + // https://tc39.es/ecma262/#sec-toobject + var toObject$1 = function (argument) { + return Object$2(requireObjectCoercible(argument)); + }; + + var uncurryThis$9 = functionUncurryThis; + var toObject = toObject$1; + + var hasOwnProperty = uncurryThis$9({}.hasOwnProperty); + + // `HasOwnProperty` abstract operation + // https://tc39.es/ecma262/#sec-hasownproperty + // eslint-disable-next-line es-x/no-object-hasown -- safe + var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) { + return hasOwnProperty(toObject(it), key); + }; + + var uncurryThis$8 = functionUncurryThis; + + var id = 0; + var postfix = Math.random(); + var toString = uncurryThis$8(1.0.toString); + + var uid$2 = function (key) { + return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36); + }; + + var global$o = global$A; + var shared$2 = shared$3.exports; + var hasOwn$8 = hasOwnProperty_1; + var uid$1 = uid$2; + var NATIVE_SYMBOL = nativeSymbol; + var USE_SYMBOL_AS_UID = useSymbolAsUid; + + var WellKnownSymbolsStore = shared$2('wks'); + var Symbol$1 = global$o.Symbol; + var symbolFor = Symbol$1 && Symbol$1['for']; + var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1; + + var wellKnownSymbol$a = function (name) { + if (!hasOwn$8(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) { + var description = 'Symbol.' + name; + if (NATIVE_SYMBOL && hasOwn$8(Symbol$1, name)) { + WellKnownSymbolsStore[name] = Symbol$1[name]; + } else if (USE_SYMBOL_AS_UID && symbolFor) { + WellKnownSymbolsStore[name] = symbolFor(description); + } else { + WellKnownSymbolsStore[name] = createWellKnownSymbol(description); + } + } return WellKnownSymbolsStore[name]; + }; + + var global$n = global$A; + var call$9 = functionCall; + var isObject$5 = isObject$7; + var isSymbol$1 = isSymbol$2; + var getMethod$2 = getMethod$3; + var ordinaryToPrimitive = ordinaryToPrimitive$1; + var wellKnownSymbol$9 = wellKnownSymbol$a; + + var TypeError$b = global$n.TypeError; + var TO_PRIMITIVE = wellKnownSymbol$9('toPrimitive'); + + // `ToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-toprimitive + var toPrimitive$1 = function (input, pref) { + if (!isObject$5(input) || isSymbol$1(input)) return input; + var exoticToPrim = getMethod$2(input, TO_PRIMITIVE); + var result; + if (exoticToPrim) { + if (pref === undefined) pref = 'default'; + result = call$9(exoticToPrim, input, pref); + if (!isObject$5(result) || isSymbol$1(result)) return result; + throw TypeError$b("Can't convert object to primitive value"); + } + if (pref === undefined) pref = 'number'; + return ordinaryToPrimitive(input, pref); + }; + + var toPrimitive = toPrimitive$1; + var isSymbol = isSymbol$2; + + // `ToPropertyKey` abstract operation + // https://tc39.es/ecma262/#sec-topropertykey + var toPropertyKey$2 = function (argument) { + var key = toPrimitive(argument, 'string'); + return isSymbol(key) ? key : key + ''; + }; + + var global$m = global$A; + var isObject$4 = isObject$7; + + var document$2 = global$m.document; + // typeof document.createElement is 'object' in old IE + var EXISTS$1 = isObject$4(document$2) && isObject$4(document$2.createElement); + + var documentCreateElement = function (it) { + return EXISTS$1 ? document$2.createElement(it) : {}; + }; + + var DESCRIPTORS$6 = descriptors; + var fails$5 = fails$a; + var createElement$1 = documentCreateElement; + + // Thanks to IE8 for its funny defineProperty + var ie8DomDefine = !DESCRIPTORS$6 && !fails$5(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(createElement$1('div'), 'a', { + get: function () { return 7; } + }).a != 7; + }); + + var DESCRIPTORS$5 = descriptors; + var call$8 = functionCall; + var propertyIsEnumerableModule = objectPropertyIsEnumerable; + var createPropertyDescriptor$1 = createPropertyDescriptor$2; + var toIndexedObject$2 = toIndexedObject$3; + var toPropertyKey$1 = toPropertyKey$2; + var hasOwn$7 = hasOwnProperty_1; + var IE8_DOM_DEFINE$1 = ie8DomDefine; + + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor; + + // `Object.getOwnPropertyDescriptor` method + // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor + objectGetOwnPropertyDescriptor.f = DESCRIPTORS$5 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) { + O = toIndexedObject$2(O); + P = toPropertyKey$1(P); + if (IE8_DOM_DEFINE$1) try { + return $getOwnPropertyDescriptor$1(O, P); + } catch (error) { /* empty */ } + if (hasOwn$7(O, P)) return createPropertyDescriptor$1(!call$8(propertyIsEnumerableModule.f, O, P), O[P]); + }; + + var objectDefineProperty = {}; + + var DESCRIPTORS$4 = descriptors; + var fails$4 = fails$a; + + // V8 ~ Chrome 36- + // https://bugs.chromium.org/p/v8/issues/detail?id=3334 + var v8PrototypeDefineBug = DESCRIPTORS$4 && fails$4(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(function () { /* empty */ }, 'prototype', { + value: 42, + writable: false + }).prototype != 42; + }); + + var global$l = global$A; + var isObject$3 = isObject$7; + + var String$3 = global$l.String; + var TypeError$a = global$l.TypeError; + + // `Assert: Type(argument) is Object` + var anObject$8 = function (argument) { + if (isObject$3(argument)) return argument; + throw TypeError$a(String$3(argument) + ' is not an object'); + }; + + var global$k = global$A; + var DESCRIPTORS$3 = descriptors; + var IE8_DOM_DEFINE = ie8DomDefine; + var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; + var anObject$7 = anObject$8; + var toPropertyKey = toPropertyKey$2; + + var TypeError$9 = global$k.TypeError; + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var $defineProperty = Object.defineProperty; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ENUMERABLE = 'enumerable'; + var CONFIGURABLE$1 = 'configurable'; + var WRITABLE = 'writable'; + + // `Object.defineProperty` method + // https://tc39.es/ecma262/#sec-object.defineproperty + objectDefineProperty.f = DESCRIPTORS$3 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { + anObject$7(O); + P = toPropertyKey(P); + anObject$7(Attributes); + if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { + var current = $getOwnPropertyDescriptor(O, P); + if (current && current[WRITABLE]) { + O[P] = Attributes.value; + Attributes = { + configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1], + enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], + writable: false + }; + } + } return $defineProperty(O, P, Attributes); + } : $defineProperty : function defineProperty(O, P, Attributes) { + anObject$7(O); + P = toPropertyKey(P); + anObject$7(Attributes); + if (IE8_DOM_DEFINE) try { + return $defineProperty(O, P, Attributes); + } catch (error) { /* empty */ } + if ('get' in Attributes || 'set' in Attributes) throw TypeError$9('Accessors not supported'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; + }; + + var DESCRIPTORS$2 = descriptors; + var definePropertyModule$2 = objectDefineProperty; + var createPropertyDescriptor = createPropertyDescriptor$2; + + var createNonEnumerableProperty$3 = DESCRIPTORS$2 ? function (object, key, value) { + return definePropertyModule$2.f(object, key, createPropertyDescriptor(1, value)); + } : function (object, key, value) { + object[key] = value; + return object; + }; + + var makeBuiltIn$2 = {exports: {}}; + + var DESCRIPTORS$1 = descriptors; + var hasOwn$6 = hasOwnProperty_1; + + var FunctionPrototype$1 = Function.prototype; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getDescriptor = DESCRIPTORS$1 && Object.getOwnPropertyDescriptor; + + var EXISTS = hasOwn$6(FunctionPrototype$1, 'name'); + // additional protection from minified / mangled / dropped function names + var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; + var CONFIGURABLE = EXISTS && (!DESCRIPTORS$1 || (DESCRIPTORS$1 && getDescriptor(FunctionPrototype$1, 'name').configurable)); + + var functionName = { + EXISTS: EXISTS, + PROPER: PROPER, + CONFIGURABLE: CONFIGURABLE + }; + + var uncurryThis$7 = functionUncurryThis; + var isCallable$b = isCallable$h; + var store$1 = sharedStore; + + var functionToString = uncurryThis$7(Function.toString); + + // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper + if (!isCallable$b(store$1.inspectSource)) { + store$1.inspectSource = function (it) { + return functionToString(it); + }; + } + + var inspectSource$4 = store$1.inspectSource; + + var global$j = global$A; + var isCallable$a = isCallable$h; + var inspectSource$3 = inspectSource$4; + + var WeakMap$1 = global$j.WeakMap; + + var nativeWeakMap = isCallable$a(WeakMap$1) && /native code/.test(inspectSource$3(WeakMap$1)); + + var shared$1 = shared$3.exports; + var uid = uid$2; + + var keys = shared$1('keys'); + + var sharedKey$1 = function (key) { + return keys[key] || (keys[key] = uid(key)); + }; + + var hiddenKeys$3 = {}; + + var NATIVE_WEAK_MAP = nativeWeakMap; + var global$i = global$A; + var uncurryThis$6 = functionUncurryThis; + var isObject$2 = isObject$7; + var createNonEnumerableProperty$2 = createNonEnumerableProperty$3; + var hasOwn$5 = hasOwnProperty_1; + var shared = sharedStore; + var sharedKey = sharedKey$1; + var hiddenKeys$2 = hiddenKeys$3; + + var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; + var TypeError$8 = global$i.TypeError; + var WeakMap = global$i.WeakMap; + var set$1, get, has; + + var enforce = function (it) { + return has(it) ? get(it) : set$1(it, {}); + }; + + var getterFor = function (TYPE) { + return function (it) { + var state; + if (!isObject$2(it) || (state = get(it)).type !== TYPE) { + throw TypeError$8('Incompatible receiver, ' + TYPE + ' required'); + } return state; + }; + }; + + if (NATIVE_WEAK_MAP || shared.state) { + var store = shared.state || (shared.state = new WeakMap()); + var wmget = uncurryThis$6(store.get); + var wmhas = uncurryThis$6(store.has); + var wmset = uncurryThis$6(store.set); + set$1 = function (it, metadata) { + if (wmhas(store, it)) throw new TypeError$8(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + wmset(store, it, metadata); + return metadata; + }; + get = function (it) { + return wmget(store, it) || {}; + }; + has = function (it) { + return wmhas(store, it); + }; + } else { + var STATE = sharedKey('state'); + hiddenKeys$2[STATE] = true; + set$1 = function (it, metadata) { + if (hasOwn$5(it, STATE)) throw new TypeError$8(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + createNonEnumerableProperty$2(it, STATE, metadata); + return metadata; + }; + get = function (it) { + return hasOwn$5(it, STATE) ? it[STATE] : {}; + }; + has = function (it) { + return hasOwn$5(it, STATE); + }; + } + + var internalState = { + set: set$1, + get: get, + has: has, + enforce: enforce, + getterFor: getterFor + }; + + var fails$3 = fails$a; + var isCallable$9 = isCallable$h; + var hasOwn$4 = hasOwnProperty_1; + var defineProperty$1 = objectDefineProperty.f; + var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE; + var inspectSource$2 = inspectSource$4; + var InternalStateModule$1 = internalState; + + var enforceInternalState = InternalStateModule$1.enforce; + var getInternalState = InternalStateModule$1.get; + + var CONFIGURABLE_LENGTH = !fails$3(function () { + return defineProperty$1(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; + }); + + var TEMPLATE = String(String).split('String'); + + var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) { + if (String(name).slice(0, 7) === 'Symbol(') { + name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']'; + } + if (options && options.getter) name = 'get ' + name; + if (options && options.setter) name = 'set ' + name; + if (!hasOwn$4(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { + defineProperty$1(value, 'name', { value: name, configurable: true }); + } + if (CONFIGURABLE_LENGTH && options && hasOwn$4(options, 'arity') && value.length !== options.arity) { + defineProperty$1(value, 'length', { value: options.arity }); + } + var state = enforceInternalState(value); + if (!hasOwn$4(state, 'source')) { + state.source = TEMPLATE.join(typeof name == 'string' ? name : ''); + } return value; + }; + + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + // eslint-disable-next-line no-extend-native -- required + Function.prototype.toString = makeBuiltIn$1(function toString() { + return isCallable$9(this) && getInternalState(this).source || inspectSource$2(this); + }, 'toString'); + + var global$h = global$A; + var isCallable$8 = isCallable$h; + var createNonEnumerableProperty$1 = createNonEnumerableProperty$3; + var makeBuiltIn = makeBuiltIn$2.exports; + var setGlobal$1 = setGlobal$3; + + var defineBuiltIn$3 = function (O, key, value, options) { + var unsafe = options ? !!options.unsafe : false; + var simple = options ? !!options.enumerable : false; + var noTargetGet = options ? !!options.noTargetGet : false; + var name = options && options.name !== undefined ? options.name : key; + if (isCallable$8(value)) makeBuiltIn(value, name, options); + if (O === global$h) { + if (simple) O[key] = value; + else setGlobal$1(key, value); + return O; + } else if (!unsafe) { + delete O[key]; + } else if (!noTargetGet && O[key]) { + simple = true; + } + if (simple) O[key] = value; + else createNonEnumerableProperty$1(O, key, value); + return O; + }; + + var objectGetOwnPropertyNames = {}; + + var ceil = Math.ceil; + var floor = Math.floor; + + // `ToIntegerOrInfinity` abstract operation + // https://tc39.es/ecma262/#sec-tointegerorinfinity + var toIntegerOrInfinity$2 = function (argument) { + var number = +argument; + // eslint-disable-next-line no-self-compare -- safe + return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil)(number); + }; + + var toIntegerOrInfinity$1 = toIntegerOrInfinity$2; + + var max = Math.max; + var min$1 = Math.min; + + // Helper for a popular repeating case of the spec: + // Let integer be ? ToInteger(index). + // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). + var toAbsoluteIndex$1 = function (index, length) { + var integer = toIntegerOrInfinity$1(index); + return integer < 0 ? max(integer + length, 0) : min$1(integer, length); + }; + + var toIntegerOrInfinity = toIntegerOrInfinity$2; + + var min = Math.min; + + // `ToLength` abstract operation + // https://tc39.es/ecma262/#sec-tolength + var toLength$1 = function (argument) { + return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 + }; + + var toLength = toLength$1; + + // `LengthOfArrayLike` abstract operation + // https://tc39.es/ecma262/#sec-lengthofarraylike + var lengthOfArrayLike$2 = function (obj) { + return toLength(obj.length); + }; + + var toIndexedObject$1 = toIndexedObject$3; + var toAbsoluteIndex = toAbsoluteIndex$1; + var lengthOfArrayLike$1 = lengthOfArrayLike$2; + + // `Array.prototype.{ indexOf, includes }` methods implementation + var createMethod = function (IS_INCLUDES) { + return function ($this, el, fromIndex) { + var O = toIndexedObject$1($this); + var length = lengthOfArrayLike$1(O); + var index = toAbsoluteIndex(fromIndex, length); + var value; + // Array#includes uses SameValueZero equality algorithm + // eslint-disable-next-line no-self-compare -- NaN check + if (IS_INCLUDES && el != el) while (length > index) { + value = O[index++]; + // eslint-disable-next-line no-self-compare -- NaN check + if (value != value) return true; + // Array#indexOf ignores holes, Array#includes - not + } else for (;length > index; index++) { + if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; + } return !IS_INCLUDES && -1; + }; + }; + + var arrayIncludes = { + // `Array.prototype.includes` method + // https://tc39.es/ecma262/#sec-array.prototype.includes + includes: createMethod(true), + // `Array.prototype.indexOf` method + // https://tc39.es/ecma262/#sec-array.prototype.indexof + indexOf: createMethod(false) + }; + + var uncurryThis$5 = functionUncurryThis; + var hasOwn$3 = hasOwnProperty_1; + var toIndexedObject = toIndexedObject$3; + var indexOf = arrayIncludes.indexOf; + var hiddenKeys$1 = hiddenKeys$3; + + var push = uncurryThis$5([].push); + + var objectKeysInternal = function (object, names) { + var O = toIndexedObject(object); + var i = 0; + var result = []; + var key; + for (key in O) !hasOwn$3(hiddenKeys$1, key) && hasOwn$3(O, key) && push(result, key); + // Don't enum bug & hidden keys + while (names.length > i) if (hasOwn$3(O, key = names[i++])) { + ~indexOf(result, key) || push(result, key); + } + return result; + }; + + // IE8- don't enum bug keys + var enumBugKeys$1 = [ + 'constructor', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'valueOf' + ]; + + var internalObjectKeys = objectKeysInternal; + var enumBugKeys = enumBugKeys$1; + + var hiddenKeys = enumBugKeys.concat('length', 'prototype'); + + // `Object.getOwnPropertyNames` method + // https://tc39.es/ecma262/#sec-object.getownpropertynames + // eslint-disable-next-line es-x/no-object-getownpropertynames -- safe + objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { + return internalObjectKeys(O, hiddenKeys); + }; + + var objectGetOwnPropertySymbols = {}; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- safe + objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols; + + var getBuiltIn$5 = getBuiltIn$8; + var uncurryThis$4 = functionUncurryThis; + var getOwnPropertyNamesModule = objectGetOwnPropertyNames; + var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols; + var anObject$6 = anObject$8; + + var concat = uncurryThis$4([].concat); + + // all object keys, includes non-enumerable and symbols + var ownKeys$2 = getBuiltIn$5('Reflect', 'ownKeys') || function ownKeys(it) { + var keys = getOwnPropertyNamesModule.f(anObject$6(it)); + var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; + return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys; + }; + + var hasOwn$2 = hasOwnProperty_1; + var ownKeys$1 = ownKeys$2; + var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor; + var definePropertyModule$1 = objectDefineProperty; + + var copyConstructorProperties$1 = function (target, source, exceptions) { + var keys = ownKeys$1(source); + var defineProperty = definePropertyModule$1.f; + var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (!hasOwn$2(target, key) && !(exceptions && hasOwn$2(exceptions, key))) { + defineProperty(target, key, getOwnPropertyDescriptor(source, key)); + } + } + }; + + var fails$2 = fails$a; + var isCallable$7 = isCallable$h; + + var replacement = /#|\.prototype\./; + + var isForced$2 = function (feature, detection) { + var value = data[normalize(feature)]; + return value == POLYFILL ? true + : value == NATIVE ? false + : isCallable$7(detection) ? fails$2(detection) + : !!detection; + }; + + var normalize = isForced$2.normalize = function (string) { + return String(string).replace(replacement, '.').toLowerCase(); + }; + + var data = isForced$2.data = {}; + var NATIVE = isForced$2.NATIVE = 'N'; + var POLYFILL = isForced$2.POLYFILL = 'P'; + + var isForced_1 = isForced$2; + + var global$g = global$A; + var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; + var createNonEnumerableProperty = createNonEnumerableProperty$3; + var defineBuiltIn$2 = defineBuiltIn$3; + var setGlobal = setGlobal$3; + var copyConstructorProperties = copyConstructorProperties$1; + var isForced$1 = isForced_1; + + /* + options.target - name of the target object + options.global - target is the global object + options.stat - export as static methods of target + options.proto - export as prototype methods of target + options.real - real prototype method for the `pure` version + options.forced - export even if the native feature is available + options.bind - bind methods to the target, required for the `pure` version + options.wrap - wrap constructors to preventing global pollution, required for the `pure` version + options.unsafe - use the simple assignment of property instead of delete + defineProperty + options.sham - add a flag to not completely full polyfills + options.enumerable - export as enumerable property + options.noTargetGet - prevent calling a getter on target + options.name - the .name of the function if it does not match the key + */ + var _export = function (options, source) { + var TARGET = options.target; + var GLOBAL = options.global; + var STATIC = options.stat; + var FORCED, target, key, targetProperty, sourceProperty, descriptor; + if (GLOBAL) { + target = global$g; + } else if (STATIC) { + target = global$g[TARGET] || setGlobal(TARGET, {}); + } else { + target = (global$g[TARGET] || {}).prototype; + } + if (target) for (key in source) { + sourceProperty = source[key]; + if (options.noTargetGet) { + descriptor = getOwnPropertyDescriptor$1(target, key); + targetProperty = descriptor && descriptor.value; + } else targetProperty = target[key]; + FORCED = isForced$1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); + // contained in target + if (!FORCED && targetProperty !== undefined) { + if (typeof sourceProperty == typeof targetProperty) continue; + copyConstructorProperties(sourceProperty, targetProperty); + } + // add a flag to not completely full polyfills + if (options.sham || (targetProperty && targetProperty.sham)) { + createNonEnumerableProperty(sourceProperty, 'sham', true); + } + defineBuiltIn$2(target, key, sourceProperty, options); + } + }; + + var classof$3 = classofRaw$1; + var global$f = global$A; + + var engineIsNode = classof$3(global$f.process) == 'process'; + + var global$e = global$A; + var isCallable$6 = isCallable$h; + + var String$2 = global$e.String; + var TypeError$7 = global$e.TypeError; + + var aPossiblePrototype$1 = function (argument) { + if (typeof argument == 'object' || isCallable$6(argument)) return argument; + throw TypeError$7("Can't set " + String$2(argument) + ' as a prototype'); + }; + + /* eslint-disable no-proto -- safe */ + + var uncurryThis$3 = functionUncurryThis; + var anObject$5 = anObject$8; + var aPossiblePrototype = aPossiblePrototype$1; + + // `Object.setPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.setprototypeof + // Works with __proto__ only. Old v8 can't work with null proto objects. + // eslint-disable-next-line es-x/no-object-setprototypeof -- safe + var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + setter = uncurryThis$3(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); + setter(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { /* empty */ } + return function setPrototypeOf(O, proto) { + anObject$5(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) setter(O, proto); + else O.__proto__ = proto; + return O; + }; + }() : undefined); + + var defineProperty = objectDefineProperty.f; + var hasOwn$1 = hasOwnProperty_1; + var wellKnownSymbol$8 = wellKnownSymbol$a; + + var TO_STRING_TAG$2 = wellKnownSymbol$8('toStringTag'); + + var setToStringTag$1 = function (target, TAG, STATIC) { + if (target && !STATIC) target = target.prototype; + if (target && !hasOwn$1(target, TO_STRING_TAG$2)) { + defineProperty(target, TO_STRING_TAG$2, { configurable: true, value: TAG }); + } + }; + + var getBuiltIn$4 = getBuiltIn$8; + var definePropertyModule = objectDefineProperty; + var wellKnownSymbol$7 = wellKnownSymbol$a; + var DESCRIPTORS = descriptors; + + var SPECIES$2 = wellKnownSymbol$7('species'); + + var setSpecies$1 = function (CONSTRUCTOR_NAME) { + var Constructor = getBuiltIn$4(CONSTRUCTOR_NAME); + var defineProperty = definePropertyModule.f; + + if (DESCRIPTORS && Constructor && !Constructor[SPECIES$2]) { + defineProperty(Constructor, SPECIES$2, { + configurable: true, + get: function () { return this; } + }); + } + }; + + var global$d = global$A; + var isPrototypeOf$1 = objectIsPrototypeOf; + + var TypeError$6 = global$d.TypeError; + + var anInstance$1 = function (it, Prototype) { + if (isPrototypeOf$1(Prototype, it)) return it; + throw TypeError$6('Incorrect invocation'); + }; + + var wellKnownSymbol$6 = wellKnownSymbol$a; + + var TO_STRING_TAG$1 = wellKnownSymbol$6('toStringTag'); + var test = {}; + + test[TO_STRING_TAG$1] = 'z'; + + var toStringTagSupport = String(test) === '[object z]'; + + var global$c = global$A; + var TO_STRING_TAG_SUPPORT = toStringTagSupport; + var isCallable$5 = isCallable$h; + var classofRaw = classofRaw$1; + var wellKnownSymbol$5 = wellKnownSymbol$a; + + var TO_STRING_TAG = wellKnownSymbol$5('toStringTag'); + var Object$1 = global$c.Object; + + // ES3 wrong here + var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments'; + + // fallback for IE11 Script Access Denied error + var tryGet = function (it, key) { + try { + return it[key]; + } catch (error) { /* empty */ } + }; + + // getting tag from ES6+ `Object.prototype.toString` + var classof$2 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (tag = tryGet(O = Object$1(it), TO_STRING_TAG)) == 'string' ? tag + // builtinTag case + : CORRECT_ARGUMENTS ? classofRaw(O) + // ES3 arguments fallback + : (result = classofRaw(O)) == 'Object' && isCallable$5(O.callee) ? 'Arguments' : result; + }; + + var uncurryThis$2 = functionUncurryThis; + var fails$1 = fails$a; + var isCallable$4 = isCallable$h; + var classof$1 = classof$2; + var getBuiltIn$3 = getBuiltIn$8; + var inspectSource$1 = inspectSource$4; + + var noop = function () { /* empty */ }; + var empty = []; + var construct = getBuiltIn$3('Reflect', 'construct'); + var constructorRegExp = /^\s*(?:class|function)\b/; + var exec = uncurryThis$2(constructorRegExp.exec); + var INCORRECT_TO_STRING = !constructorRegExp.exec(noop); + + var isConstructorModern = function isConstructor(argument) { + if (!isCallable$4(argument)) return false; + try { + construct(noop, empty, argument); + return true; + } catch (error) { + return false; + } + }; + + var isConstructorLegacy = function isConstructor(argument) { + if (!isCallable$4(argument)) return false; + switch (classof$1(argument)) { + case 'AsyncFunction': + case 'GeneratorFunction': + case 'AsyncGeneratorFunction': return false; + } + try { + // we can't check .prototype since constructors produced by .bind haven't it + // `Function#toString` throws on some built-it function in some legacy engines + // (for example, `DOMQuad` and similar in FF41-) + return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource$1(argument)); + } catch (error) { + return true; + } + }; + + isConstructorLegacy.sham = true; + + // `IsConstructor` abstract operation + // https://tc39.es/ecma262/#sec-isconstructor + var isConstructor$1 = !construct || fails$1(function () { + var called; + return isConstructorModern(isConstructorModern.call) + || !isConstructorModern(Object) + || !isConstructorModern(function () { called = true; }) + || called; + }) ? isConstructorLegacy : isConstructorModern; + + var global$b = global$A; + var isConstructor = isConstructor$1; + var tryToString$2 = tryToString$4; + + var TypeError$5 = global$b.TypeError; + + // `Assert: IsConstructor(argument) is true` + var aConstructor$1 = function (argument) { + if (isConstructor(argument)) return argument; + throw TypeError$5(tryToString$2(argument) + ' is not a constructor'); + }; + + var anObject$4 = anObject$8; + var aConstructor = aConstructor$1; + var wellKnownSymbol$4 = wellKnownSymbol$a; + + var SPECIES$1 = wellKnownSymbol$4('species'); + + // `SpeciesConstructor` abstract operation + // https://tc39.es/ecma262/#sec-speciesconstructor + var speciesConstructor$1 = function (O, defaultConstructor) { + var C = anObject$4(O).constructor; + var S; + return C === undefined || (S = anObject$4(C)[SPECIES$1]) == undefined ? defaultConstructor : aConstructor(S); + }; + + var NATIVE_BIND$1 = functionBindNative; + + var FunctionPrototype = Function.prototype; + var apply$1 = FunctionPrototype.apply; + var call$7 = FunctionPrototype.call; + + // eslint-disable-next-line es-x/no-reflect -- safe + var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$1 ? call$7.bind(apply$1) : function () { + return call$7.apply(apply$1, arguments); + }); + + var uncurryThis$1 = functionUncurryThis; + var aCallable$5 = aCallable$7; + var NATIVE_BIND = functionBindNative; + + var bind$4 = uncurryThis$1(uncurryThis$1.bind); + + // optional / simple context binding + var functionBindContext = function (fn, that) { + aCallable$5(fn); + return that === undefined ? fn : NATIVE_BIND ? bind$4(fn, that) : function (/* ...args */) { + return fn.apply(that, arguments); + }; + }; + + var getBuiltIn$2 = getBuiltIn$8; + + var html$1 = getBuiltIn$2('document', 'documentElement'); + + var uncurryThis = functionUncurryThis; + + var arraySlice$1 = uncurryThis([].slice); + + var global$a = global$A; + + var TypeError$4 = global$a.TypeError; + + var validateArgumentsLength$1 = function (passed, required) { + if (passed < required) throw TypeError$4('Not enough arguments'); + return passed; + }; + + var userAgent$2 = engineUserAgent; + + var engineIsIos = /(?:ipad|iphone|ipod).*applewebkit/i.test(userAgent$2); + + var global$9 = global$A; + var apply = functionApply; + var bind$3 = functionBindContext; + var isCallable$3 = isCallable$h; + var hasOwn = hasOwnProperty_1; + var fails = fails$a; + var html = html$1; + var arraySlice = arraySlice$1; + var createElement = documentCreateElement; + var validateArgumentsLength = validateArgumentsLength$1; + var IS_IOS$1 = engineIsIos; + var IS_NODE$2 = engineIsNode; + + var set = global$9.setImmediate; + var clear = global$9.clearImmediate; + var process$2 = global$9.process; + var Dispatch = global$9.Dispatch; + var Function$1 = global$9.Function; + var MessageChannel = global$9.MessageChannel; + var String$1 = global$9.String; + var counter = 0; + var queue$1 = {}; + var ONREADYSTATECHANGE = 'onreadystatechange'; + var location, defer, channel, port; + + try { + // Deno throws a ReferenceError on `location` access without `--location` flag + location = global$9.location; + } catch (error) { /* empty */ } + + var run = function (id) { + if (hasOwn(queue$1, id)) { + var fn = queue$1[id]; + delete queue$1[id]; + fn(); + } + }; + + var runner = function (id) { + return function () { + run(id); + }; + }; + + var listener = function (event) { + run(event.data); + }; + + var post = function (id) { + // old engines have not location.origin + global$9.postMessage(String$1(id), location.protocol + '//' + location.host); + }; + + // Node.js 0.9+ & IE10+ has setImmediate, otherwise: + if (!set || !clear) { + set = function setImmediate(handler) { + validateArgumentsLength(arguments.length, 1); + var fn = isCallable$3(handler) ? handler : Function$1(handler); + var args = arraySlice(arguments, 1); + queue$1[++counter] = function () { + apply(fn, undefined, args); + }; + defer(counter); + return counter; + }; + clear = function clearImmediate(id) { + delete queue$1[id]; + }; + // Node.js 0.8- + if (IS_NODE$2) { + defer = function (id) { + process$2.nextTick(runner(id)); + }; + // Sphere (JS game engine) Dispatch API + } else if (Dispatch && Dispatch.now) { + defer = function (id) { + Dispatch.now(runner(id)); + }; + // Browsers with MessageChannel, includes WebWorkers + // except iOS - https://github.com/zloirock/core-js/issues/624 + } else if (MessageChannel && !IS_IOS$1) { + channel = new MessageChannel(); + port = channel.port2; + channel.port1.onmessage = listener; + defer = bind$3(port.postMessage, port); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if ( + global$9.addEventListener && + isCallable$3(global$9.postMessage) && + !global$9.importScripts && + location && location.protocol !== 'file:' && + !fails(post) + ) { + defer = post; + global$9.addEventListener('message', listener, false); + // IE8- + } else if (ONREADYSTATECHANGE in createElement('script')) { + defer = function (id) { + html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () { + html.removeChild(this); + run(id); + }; + }; + // Rest old browsers + } else { + defer = function (id) { + setTimeout(runner(id), 0); + }; + } + } + + var task$1 = { + set: set, + clear: clear + }; + + var userAgent$1 = engineUserAgent; + var global$8 = global$A; + + var engineIsIosPebble = /ipad|iphone|ipod/i.test(userAgent$1) && global$8.Pebble !== undefined; + + var userAgent = engineUserAgent; + + var engineIsWebosWebkit = /web0s(?!.*chrome)/i.test(userAgent); + + var global$7 = global$A; + var bind$2 = functionBindContext; + var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f; + var macrotask = task$1.set; + var IS_IOS = engineIsIos; + var IS_IOS_PEBBLE = engineIsIosPebble; + var IS_WEBOS_WEBKIT = engineIsWebosWebkit; + var IS_NODE$1 = engineIsNode; + + var MutationObserver = global$7.MutationObserver || global$7.WebKitMutationObserver; + var document$1 = global$7.document; + var process$1 = global$7.process; + var Promise$1 = global$7.Promise; + // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask` + var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global$7, 'queueMicrotask'); + var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; + + var flush, head, last, notify$1, toggle, node, promise, then; + + // modern engines have queueMicrotask method + if (!queueMicrotask) { + flush = function () { + var parent, fn; + if (IS_NODE$1 && (parent = process$1.domain)) parent.exit(); + while (head) { + fn = head.fn; + head = head.next; + try { + fn(); + } catch (error) { + if (head) notify$1(); + else last = undefined; + throw error; + } + } last = undefined; + if (parent) parent.enter(); + }; + + // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339 + // also except WebOS Webkit https://github.com/zloirock/core-js/issues/898 + if (!IS_IOS && !IS_NODE$1 && !IS_WEBOS_WEBKIT && MutationObserver && document$1) { + toggle = true; + node = document$1.createTextNode(''); + new MutationObserver(flush).observe(node, { characterData: true }); + notify$1 = function () { + node.data = toggle = !toggle; + }; + // environments with maybe non-completely correct, but existent Promise + } else if (!IS_IOS_PEBBLE && Promise$1 && Promise$1.resolve) { + // Promise.resolve without an argument throws an error in LG WebOS 2 + promise = Promise$1.resolve(undefined); + // workaround of WebKit ~ iOS Safari 10.1 bug + promise.constructor = Promise$1; + then = bind$2(promise.then, promise); + notify$1 = function () { + then(flush); + }; + // Node.js without promises + } else if (IS_NODE$1) { + notify$1 = function () { + process$1.nextTick(flush); + }; + // for other environments - macrotask based on: + // - setImmediate + // - MessageChannel + // - window.postMessage + // - onreadystatechange + // - setTimeout + } else { + // strange IE + webpack dev server bug - use .bind(global) + macrotask = bind$2(macrotask, global$7); + notify$1 = function () { + macrotask(flush); + }; + } + } + + var microtask$1 = queueMicrotask || function (fn) { + var task = { fn: fn, next: undefined }; + if (last) last.next = task; + if (!head) { + head = task; + notify$1(); + } last = task; + }; + + var global$6 = global$A; + + var hostReportErrors$1 = function (a, b) { + var console = global$6.console; + if (console && console.error) { + arguments.length == 1 ? console.error(a) : console.error(a, b); + } + }; + + var perform$3 = function (exec) { + try { + return { error: false, value: exec() }; + } catch (error) { + return { error: true, value: error }; + } + }; + + var Queue$1 = function () { + this.head = null; + this.tail = null; + }; + + Queue$1.prototype = { + add: function (item) { + var entry = { item: item, next: null }; + if (this.head) this.tail.next = entry; + else this.head = entry; + this.tail = entry; + }, + get: function () { + var entry = this.head; + if (entry) { + this.head = entry.next; + if (this.tail === entry) this.tail = null; + return entry.item; + } + } + }; + + var queue = Queue$1; + + var global$5 = global$A; + + var promiseNativeConstructor = global$5.Promise; + + var engineIsBrowser = typeof window == 'object' && typeof Deno != 'object'; + + var global$4 = global$A; + var NativePromiseConstructor$3 = promiseNativeConstructor; + var isCallable$2 = isCallable$h; + var isForced = isForced_1; + var inspectSource = inspectSource$4; + var wellKnownSymbol$3 = wellKnownSymbol$a; + var IS_BROWSER = engineIsBrowser; + var V8_VERSION = engineV8Version; + + NativePromiseConstructor$3 && NativePromiseConstructor$3.prototype; + var SPECIES = wellKnownSymbol$3('species'); + var SUBCLASSING = false; + var NATIVE_PROMISE_REJECTION_EVENT$1 = isCallable$2(global$4.PromiseRejectionEvent); + + var FORCED_PROMISE_CONSTRUCTOR$5 = isForced('Promise', function () { + var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(NativePromiseConstructor$3); + var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(NativePromiseConstructor$3); + // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables + // https://bugs.chromium.org/p/chromium/issues/detail?id=830565 + // We can't detect it synchronously, so just check versions + if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true; + // We can't use @@species feature detection in V8 since it causes + // deoptimization and performance degradation + // https://github.com/zloirock/core-js/issues/679 + if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false; + // Detect correctness of subclassing with @@species support + var promise = new NativePromiseConstructor$3(function (resolve) { resolve(1); }); + var FakePromise = function (exec) { + exec(function () { /* empty */ }, function () { /* empty */ }); + }; + var constructor = promise.constructor = {}; + constructor[SPECIES] = FakePromise; + SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise; + if (!SUBCLASSING) return true; + // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test + return !GLOBAL_CORE_JS_PROMISE && IS_BROWSER && !NATIVE_PROMISE_REJECTION_EVENT$1; + }); + + var promiseConstructorDetection = { + CONSTRUCTOR: FORCED_PROMISE_CONSTRUCTOR$5, + REJECTION_EVENT: NATIVE_PROMISE_REJECTION_EVENT$1, + SUBCLASSING: SUBCLASSING + }; + + var newPromiseCapability$2 = {}; + + var aCallable$4 = aCallable$7; + + var PromiseCapability = function (C) { + var resolve, reject; + this.promise = new C(function ($$resolve, $$reject) { + if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = aCallable$4(resolve); + this.reject = aCallable$4(reject); + }; + + // `NewPromiseCapability` abstract operation + // https://tc39.es/ecma262/#sec-newpromisecapability + newPromiseCapability$2.f = function (C) { + return new PromiseCapability(C); + }; + + var $$5 = _export; + var IS_NODE = engineIsNode; + var global$3 = global$A; + var call$6 = functionCall; + var defineBuiltIn$1 = defineBuiltIn$3; + var setPrototypeOf = objectSetPrototypeOf; + var setToStringTag = setToStringTag$1; + var setSpecies = setSpecies$1; + var aCallable$3 = aCallable$7; + var isCallable$1 = isCallable$h; + var isObject$1 = isObject$7; + var anInstance = anInstance$1; + var speciesConstructor = speciesConstructor$1; + var task = task$1.set; + var microtask = microtask$1; + var hostReportErrors = hostReportErrors$1; + var perform$2 = perform$3; + var Queue = queue; + var InternalStateModule = internalState; + var NativePromiseConstructor$2 = promiseNativeConstructor; + var PromiseConstructorDetection = promiseConstructorDetection; + var newPromiseCapabilityModule$3 = newPromiseCapability$2; + + var PROMISE = 'Promise'; + var FORCED_PROMISE_CONSTRUCTOR$4 = PromiseConstructorDetection.CONSTRUCTOR; + var NATIVE_PROMISE_REJECTION_EVENT = PromiseConstructorDetection.REJECTION_EVENT; + var NATIVE_PROMISE_SUBCLASSING = PromiseConstructorDetection.SUBCLASSING; + var getInternalPromiseState = InternalStateModule.getterFor(PROMISE); + var setInternalState = InternalStateModule.set; + var NativePromisePrototype$1 = NativePromiseConstructor$2 && NativePromiseConstructor$2.prototype; + var PromiseConstructor = NativePromiseConstructor$2; + var PromisePrototype = NativePromisePrototype$1; + var TypeError$3 = global$3.TypeError; + var document = global$3.document; + var process = global$3.process; + var newPromiseCapability$1 = newPromiseCapabilityModule$3.f; + var newGenericPromiseCapability = newPromiseCapability$1; + + var DISPATCH_EVENT = !!(document && document.createEvent && global$3.dispatchEvent); + var UNHANDLED_REJECTION = 'unhandledrejection'; + var REJECTION_HANDLED = 'rejectionhandled'; + var PENDING = 0; + var FULFILLED = 1; + var REJECTED = 2; + var HANDLED = 1; + var UNHANDLED = 2; + + var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen; + + // helpers + var isThenable = function (it) { + var then; + return isObject$1(it) && isCallable$1(then = it.then) ? then : false; + }; + + var callReaction = function (reaction, state) { + var value = state.value; + var ok = state.state == FULFILLED; + var handler = ok ? reaction.ok : reaction.fail; + var resolve = reaction.resolve; + var reject = reaction.reject; + var domain = reaction.domain; + var result, then, exited; + try { + if (handler) { + if (!ok) { + if (state.rejection === UNHANDLED) onHandleUnhandled(state); + state.rejection = HANDLED; + } + if (handler === true) result = value; + else { + if (domain) domain.enter(); + result = handler(value); // can throw + if (domain) { + domain.exit(); + exited = true; + } + } + if (result === reaction.promise) { + reject(TypeError$3('Promise-chain cycle')); + } else if (then = isThenable(result)) { + call$6(then, result, resolve, reject); + } else resolve(result); + } else reject(value); + } catch (error) { + if (domain && !exited) domain.exit(); + reject(error); + } + }; + + var notify = function (state, isReject) { + if (state.notified) return; + state.notified = true; + microtask(function () { + var reactions = state.reactions; + var reaction; + while (reaction = reactions.get()) { + callReaction(reaction, state); + } + state.notified = false; + if (isReject && !state.rejection) onUnhandled(state); + }); + }; + + var dispatchEvent = function (name, promise, reason) { + var event, handler; + if (DISPATCH_EVENT) { + event = document.createEvent('Event'); + event.promise = promise; + event.reason = reason; + event.initEvent(name, false, true); + global$3.dispatchEvent(event); + } else event = { promise: promise, reason: reason }; + if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = global$3['on' + name])) handler(event); + else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason); + }; + + var onUnhandled = function (state) { + call$6(task, global$3, function () { + var promise = state.facade; + var value = state.value; + var IS_UNHANDLED = isUnhandled(state); + var result; + if (IS_UNHANDLED) { + result = perform$2(function () { + if (IS_NODE) { + process.emit('unhandledRejection', value, promise); + } else dispatchEvent(UNHANDLED_REJECTION, promise, value); + }); + // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should + state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED; + if (result.error) throw result.value; + } + }); + }; + + var isUnhandled = function (state) { + return state.rejection !== HANDLED && !state.parent; + }; + + var onHandleUnhandled = function (state) { + call$6(task, global$3, function () { + var promise = state.facade; + if (IS_NODE) { + process.emit('rejectionHandled', promise); + } else dispatchEvent(REJECTION_HANDLED, promise, state.value); + }); + }; + + var bind$1 = function (fn, state, unwrap) { + return function (value) { + fn(state, value, unwrap); + }; + }; + + var internalReject = function (state, value, unwrap) { + if (state.done) return; + state.done = true; + if (unwrap) state = unwrap; + state.value = value; + state.state = REJECTED; + notify(state, true); + }; + + var internalResolve = function (state, value, unwrap) { + if (state.done) return; + state.done = true; + if (unwrap) state = unwrap; + try { + if (state.facade === value) throw TypeError$3("Promise can't be resolved itself"); + var then = isThenable(value); + if (then) { + microtask(function () { + var wrapper = { done: false }; + try { + call$6(then, value, + bind$1(internalResolve, wrapper, state), + bind$1(internalReject, wrapper, state) + ); + } catch (error) { + internalReject(wrapper, error, state); + } + }); + } else { + state.value = value; + state.state = FULFILLED; + notify(state, false); + } + } catch (error) { + internalReject({ done: false }, error, state); + } + }; + + // constructor polyfill + if (FORCED_PROMISE_CONSTRUCTOR$4) { + // 25.4.3.1 Promise(executor) + PromiseConstructor = function Promise(executor) { + anInstance(this, PromisePrototype); + aCallable$3(executor); + call$6(Internal, this); + var state = getInternalPromiseState(this); + try { + executor(bind$1(internalResolve, state), bind$1(internalReject, state)); + } catch (error) { + internalReject(state, error); + } + }; + + PromisePrototype = PromiseConstructor.prototype; + + // eslint-disable-next-line no-unused-vars -- required for `.length` + Internal = function Promise(executor) { + setInternalState(this, { + type: PROMISE, + done: false, + notified: false, + parent: false, + reactions: new Queue(), + rejection: false, + state: PENDING, + value: undefined + }); + }; + + // `Promise.prototype.then` method + // https://tc39.es/ecma262/#sec-promise.prototype.then + Internal.prototype = defineBuiltIn$1(PromisePrototype, 'then', function then(onFulfilled, onRejected) { + var state = getInternalPromiseState(this); + var reaction = newPromiseCapability$1(speciesConstructor(this, PromiseConstructor)); + state.parent = true; + reaction.ok = isCallable$1(onFulfilled) ? onFulfilled : true; + reaction.fail = isCallable$1(onRejected) && onRejected; + reaction.domain = IS_NODE ? process.domain : undefined; + if (state.state == PENDING) state.reactions.add(reaction); + else microtask(function () { + callReaction(reaction, state); + }); + return reaction.promise; + }); + + OwnPromiseCapability = function () { + var promise = new Internal(); + var state = getInternalPromiseState(promise); + this.promise = promise; + this.resolve = bind$1(internalResolve, state); + this.reject = bind$1(internalReject, state); + }; + + newPromiseCapabilityModule$3.f = newPromiseCapability$1 = function (C) { + return C === PromiseConstructor || C === PromiseWrapper + ? new OwnPromiseCapability(C) + : newGenericPromiseCapability(C); + }; + + if (isCallable$1(NativePromiseConstructor$2) && NativePromisePrototype$1 !== Object.prototype) { + nativeThen = NativePromisePrototype$1.then; + + if (!NATIVE_PROMISE_SUBCLASSING) { + // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs + defineBuiltIn$1(NativePromisePrototype$1, 'then', function then(onFulfilled, onRejected) { + var that = this; + return new PromiseConstructor(function (resolve, reject) { + call$6(nativeThen, that, resolve, reject); + }).then(onFulfilled, onRejected); + // https://github.com/zloirock/core-js/issues/640 + }, { unsafe: true }); + } + + // make `.constructor === Promise` work for native promise-based APIs + try { + delete NativePromisePrototype$1.constructor; + } catch (error) { /* empty */ } + + // make `instanceof Promise` work for native promise-based APIs + if (setPrototypeOf) { + setPrototypeOf(NativePromisePrototype$1, PromisePrototype); + } + } + } + + $$5({ global: true, wrap: true, forced: FORCED_PROMISE_CONSTRUCTOR$4 }, { + Promise: PromiseConstructor + }); + + setToStringTag(PromiseConstructor, PROMISE, false); + setSpecies(PROMISE); + + var iterators = {}; + + var wellKnownSymbol$2 = wellKnownSymbol$a; + var Iterators$1 = iterators; + + var ITERATOR$2 = wellKnownSymbol$2('iterator'); + var ArrayPrototype = Array.prototype; + + // check on default Array iterator + var isArrayIteratorMethod$1 = function (it) { + return it !== undefined && (Iterators$1.Array === it || ArrayPrototype[ITERATOR$2] === it); + }; + + var classof = classof$2; + var getMethod$1 = getMethod$3; + var Iterators = iterators; + var wellKnownSymbol$1 = wellKnownSymbol$a; + + var ITERATOR$1 = wellKnownSymbol$1('iterator'); + + var getIteratorMethod$2 = function (it) { + if (it != undefined) return getMethod$1(it, ITERATOR$1) + || getMethod$1(it, '@@iterator') + || Iterators[classof(it)]; + }; + + var global$2 = global$A; + var call$5 = functionCall; + var aCallable$2 = aCallable$7; + var anObject$3 = anObject$8; + var tryToString$1 = tryToString$4; + var getIteratorMethod$1 = getIteratorMethod$2; + + var TypeError$2 = global$2.TypeError; + + var getIterator$1 = function (argument, usingIterator) { + var iteratorMethod = arguments.length < 2 ? getIteratorMethod$1(argument) : usingIterator; + if (aCallable$2(iteratorMethod)) return anObject$3(call$5(iteratorMethod, argument)); + throw TypeError$2(tryToString$1(argument) + ' is not iterable'); + }; + + var call$4 = functionCall; + var anObject$2 = anObject$8; + var getMethod = getMethod$3; + + var iteratorClose$1 = function (iterator, kind, value) { + var innerResult, innerError; + anObject$2(iterator); + try { + innerResult = getMethod(iterator, 'return'); + if (!innerResult) { + if (kind === 'throw') throw value; + return value; + } + innerResult = call$4(innerResult, iterator); + } catch (error) { + innerError = true; + innerResult = error; + } + if (kind === 'throw') throw value; + if (innerError) throw innerResult; + anObject$2(innerResult); + return value; + }; + + var global$1 = global$A; + var bind = functionBindContext; + var call$3 = functionCall; + var anObject$1 = anObject$8; + var tryToString = tryToString$4; + var isArrayIteratorMethod = isArrayIteratorMethod$1; + var lengthOfArrayLike = lengthOfArrayLike$2; + var isPrototypeOf = objectIsPrototypeOf; + var getIterator = getIterator$1; + var getIteratorMethod = getIteratorMethod$2; + var iteratorClose = iteratorClose$1; + + var TypeError$1 = global$1.TypeError; + + var Result = function (stopped, result) { + this.stopped = stopped; + this.result = result; + }; + + var ResultPrototype = Result.prototype; + + var iterate$2 = function (iterable, unboundFunction, options) { + var that = options && options.that; + var AS_ENTRIES = !!(options && options.AS_ENTRIES); + var IS_ITERATOR = !!(options && options.IS_ITERATOR); + var INTERRUPTED = !!(options && options.INTERRUPTED); + var fn = bind(unboundFunction, that); + var iterator, iterFn, index, length, result, next, step; + + var stop = function (condition) { + if (iterator) iteratorClose(iterator, 'normal', condition); + return new Result(true, condition); + }; + + var callFn = function (value) { + if (AS_ENTRIES) { + anObject$1(value); + return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]); + } return INTERRUPTED ? fn(value, stop) : fn(value); + }; + + if (IS_ITERATOR) { + iterator = iterable; + } else { + iterFn = getIteratorMethod(iterable); + if (!iterFn) throw TypeError$1(tryToString(iterable) + ' is not iterable'); + // optimisation for array iterators + if (isArrayIteratorMethod(iterFn)) { + for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) { + result = callFn(iterable[index]); + if (result && isPrototypeOf(ResultPrototype, result)) return result; + } return new Result(false); + } + iterator = getIterator(iterable, iterFn); + } + + next = iterator.next; + while (!(step = call$3(next, iterator)).done) { + try { + result = callFn(step.value); + } catch (error) { + iteratorClose(iterator, 'throw', error); + } + if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result; + } return new Result(false); + }; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); + } + + function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } + } + + function _asyncToGenerator(fn) { + return function () { + var self = this, + args = arguments; + return new Promise(function (resolve, reject) { + var gen = fn.apply(self, args); + + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + + _next(undefined); + }); + }; + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } else if (call !== void 0) { + throw new TypeError("Derived constructors may only return object or undefined"); + } + + return _assertThisInitialized(self); + } + + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; + } + + function __repeatConcat(str, num) { + if (!!str && typeof str.repeat === "function") return str.repeat(num); + + if (typeof str === "string") { + var result = ""; + + for (var i = 0; i < num; i++) { + result += str; + } + + return result; + } + + if (str instanceof Array) { + var result = []; + + for (var i = 0; i < num; i++) { + result.concat(str); + } + + return result; + } + + throw new Error("Invalid Data!"); + } + + function __includes(str, token) { + if (!!str && typeof str.includes === "function") return str.includes(token); + return str.indexOf(token) !== -1; + } + + function __startsWithString(str, token) { + if (!!str && typeof str.startsWith === "function") return str.startsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp("^" + token); + return regexp.test(str); + } + + function __endsWithString(str, token) { + if (typeof str.endsWith === "function") return str.endsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp(token + "$"); + return regexp.test(str); + } + + function __arrayMaker(obj, func) { + if (!obj || _typeof(obj) !== "object") throw new Error("Invalid Data!"); + var result = []; + var length = obj.length; + + for (var i = 0; i < length; i++) { + result[i] = func(obj[i], i); + } + + return result; + } + + var __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + var mappedPromises = promises.map(function (p) { + return p.then(function (value) { + return { + status: 'fulfilled', + value: value + }; + }).catch(function (reason) { + return { + status: 'rejected', + reason: reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + var wellKnownSymbol = wellKnownSymbol$a; + + var ITERATOR = wellKnownSymbol('iterator'); + var SAFE_CLOSING = false; + + try { + var called = 0; + var iteratorWithReturn = { + next: function () { + return { done: !!called++ }; + }, + 'return': function () { + SAFE_CLOSING = true; + } + }; + iteratorWithReturn[ITERATOR] = function () { + return this; + }; + // eslint-disable-next-line es-x/no-array-from, no-throw-literal -- required for testing + __arrayMaker(iteratorWithReturn, function () { throw 2; }); + } catch (error) { /* empty */ } + + var checkCorrectnessOfIteration$1 = function (exec, SKIP_CLOSING) { + if (!SKIP_CLOSING && !SAFE_CLOSING) return false; + var ITERATION_SUPPORT = false; + try { + var object = {}; + object[ITERATOR] = function () { + return { + next: function () { + return { done: ITERATION_SUPPORT = true }; + } + }; + }; + exec(object); + } catch (error) { /* empty */ } + return ITERATION_SUPPORT; + }; + + var NativePromiseConstructor$1 = promiseNativeConstructor; + var checkCorrectnessOfIteration = checkCorrectnessOfIteration$1; + var FORCED_PROMISE_CONSTRUCTOR$3 = promiseConstructorDetection.CONSTRUCTOR; + + var promiseStaticsIncorrectIteration = FORCED_PROMISE_CONSTRUCTOR$3 || !checkCorrectnessOfIteration(function (iterable) { + NativePromiseConstructor$1.all(iterable).then(undefined, function () { /* empty */ }); + }); + + var $$4 = _export; + var call$2 = functionCall; + var aCallable$1 = aCallable$7; + var newPromiseCapabilityModule$2 = newPromiseCapability$2; + var perform$1 = perform$3; + var iterate$1 = iterate$2; + var PROMISE_STATICS_INCORRECT_ITERATION$1 = promiseStaticsIncorrectIteration; + + // `Promise.all` method + // https://tc39.es/ecma262/#sec-promise.all + $$4({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION$1 }, { + all: function all(iterable) { + var C = this; + var capability = newPromiseCapabilityModule$2.f(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform$1(function () { + var $promiseResolve = aCallable$1(C.resolve); + var values = []; + var counter = 0; + var remaining = 1; + iterate$1(iterable, function (promise) { + var index = counter++; + var alreadyCalled = false; + remaining++; + call$2($promiseResolve, C, promise).then(function (value) { + if (alreadyCalled) return; + alreadyCalled = true; + values[index] = value; + --remaining || resolve(values); + }, reject); + }); + --remaining || resolve(values); + }); + if (result.error) reject(result.value); + return capability.promise; + } + }); + + var $$3 = _export; + var FORCED_PROMISE_CONSTRUCTOR$2 = promiseConstructorDetection.CONSTRUCTOR; + var NativePromiseConstructor = promiseNativeConstructor; + var getBuiltIn$1 = getBuiltIn$8; + var isCallable = isCallable$h; + var defineBuiltIn = defineBuiltIn$3; + + var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype; + + // `Promise.prototype.catch` method + // https://tc39.es/ecma262/#sec-promise.prototype.catch + $$3({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR$2, real: true }, { + 'catch': function (onRejected) { + return this.then(undefined, onRejected); + } + }); + + // makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then` + if (isCallable(NativePromiseConstructor)) { + var method = getBuiltIn$1('Promise').prototype['catch']; + if (NativePromisePrototype['catch'] !== method) { + defineBuiltIn(NativePromisePrototype, 'catch', method, { unsafe: true }); + } + } + + var $$2 = _export; + var call$1 = functionCall; + var aCallable = aCallable$7; + var newPromiseCapabilityModule$1 = newPromiseCapability$2; + var perform = perform$3; + var iterate = iterate$2; + var PROMISE_STATICS_INCORRECT_ITERATION = promiseStaticsIncorrectIteration; + + // `Promise.race` method + // https://tc39.es/ecma262/#sec-promise.race + $$2({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { + race: function race(iterable) { + var C = this; + var capability = newPromiseCapabilityModule$1.f(C); + var reject = capability.reject; + var result = perform(function () { + var $promiseResolve = aCallable(C.resolve); + iterate(iterable, function (promise) { + call$1($promiseResolve, C, promise).then(capability.resolve, reject); + }); + }); + if (result.error) reject(result.value); + return capability.promise; + } + }); + + var $$1 = _export; + var call = functionCall; + var newPromiseCapabilityModule = newPromiseCapability$2; + var FORCED_PROMISE_CONSTRUCTOR$1 = promiseConstructorDetection.CONSTRUCTOR; + + // `Promise.reject` method + // https://tc39.es/ecma262/#sec-promise.reject + $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR$1 }, { + reject: function reject(r) { + var capability = newPromiseCapabilityModule.f(this); + call(capability.reject, undefined, r); + return capability.promise; + } + }); + + var anObject = anObject$8; + var isObject = isObject$7; + var newPromiseCapability = newPromiseCapability$2; + + var promiseResolve$1 = function (C, x) { + anObject(C); + if (isObject(x) && x.constructor === C) return x; + var promiseCapability = newPromiseCapability.f(C); + var resolve = promiseCapability.resolve; + resolve(x); + return promiseCapability.promise; + }; + + var $ = _export; + var getBuiltIn = getBuiltIn$8; + var FORCED_PROMISE_CONSTRUCTOR = promiseConstructorDetection.CONSTRUCTOR; + var promiseResolve = promiseResolve$1; + + getBuiltIn('Promise'); + + // `Promise.resolve` method + // https://tc39.es/ecma262/#sec-promise.resolve + $({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, { + resolve: function resolve(x) { + return promiseResolve(this, x); + } + }); + + var runtime = {exports: {}}; + + /** + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + (function (module) { + var runtime = (function (exports) { + + var Op = Object.prototype; + var hasOwn = Op.hasOwnProperty; + var undefined$1; // More compressible than void 0. + var $Symbol = typeof Symbol === "function" ? Symbol : {}; + var iteratorSymbol = $Symbol.iterator || "@@iterator"; + var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; + var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; + + function define(obj, key, value) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + return obj[key]; + } + try { + // IE 8 has a broken Object.defineProperty that only works on DOM objects. + define({}, ""); + } catch (err) { + define = function(obj, key, value) { + return obj[key] = value; + }; + } + + function wrap(innerFn, outerFn, self, tryLocsList) { + // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. + var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; + var generator = Object.create(protoGenerator.prototype); + var context = new Context(tryLocsList || []); + + // The ._invoke method unifies the implementations of the .next, + // .throw, and .return methods. + generator._invoke = makeInvokeMethod(innerFn, self, context); + + return generator; + } + exports.wrap = wrap; + + // Try/catch helper to minimize deoptimizations. Returns a completion + // record like context.tryEntries[i].completion. This interface could + // have been (and was previously) designed to take a closure to be + // invoked without arguments, but in all the cases we care about we + // already have an existing method we want to call, so there's no need + // to create a new function object. We can even get away with assuming + // the method takes exactly one argument, since that happens to be true + // in every case, so we don't have to touch the arguments object. The + // only additional allocation required is the completion record, which + // has a stable shape and so hopefully should be cheap to allocate. + function tryCatch(fn, obj, arg) { + try { + return { type: "normal", arg: fn.call(obj, arg) }; + } catch (err) { + return { type: "throw", arg: err }; + } + } + + var GenStateSuspendedStart = "suspendedStart"; + var GenStateSuspendedYield = "suspendedYield"; + var GenStateExecuting = "executing"; + var GenStateCompleted = "completed"; + + // Returning this object from the innerFn has the same effect as + // breaking out of the dispatch switch statement. + var ContinueSentinel = {}; + + // Dummy constructor functions that we use as the .constructor and + // .constructor.prototype properties for functions that return Generator + // objects. For full spec compliance, you may wish to configure your + // minifier not to mangle the names of these two functions. + function Generator() {} + function GeneratorFunction() {} + function GeneratorFunctionPrototype() {} + + // This is a polyfill for %IteratorPrototype% for environments that + // don't natively support it. + var IteratorPrototype = {}; + define(IteratorPrototype, iteratorSymbol, function () { + return this; + }); + + var getProto = Object.getPrototypeOf; + var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); + if (NativeIteratorPrototype && + NativeIteratorPrototype !== Op && + hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { + // This environment has a native %IteratorPrototype%; use it instead + // of the polyfill. + IteratorPrototype = NativeIteratorPrototype; + } + + var Gp = GeneratorFunctionPrototype.prototype = + Generator.prototype = Object.create(IteratorPrototype); + GeneratorFunction.prototype = GeneratorFunctionPrototype; + define(Gp, "constructor", GeneratorFunctionPrototype); + define(GeneratorFunctionPrototype, "constructor", GeneratorFunction); + GeneratorFunction.displayName = define( + GeneratorFunctionPrototype, + toStringTagSymbol, + "GeneratorFunction" + ); + + // Helper for defining the .next, .throw, and .return methods of the + // Iterator interface in terms of a single ._invoke method. + function defineIteratorMethods(prototype) { + ["next", "throw", "return"].forEach(function(method) { + define(prototype, method, function(arg) { + return this._invoke(method, arg); + }); + }); + } + + exports.isGeneratorFunction = function(genFun) { + var ctor = typeof genFun === "function" && genFun.constructor; + return ctor + ? ctor === GeneratorFunction || + // For the native GeneratorFunction constructor, the best we can + // do is to check its .name property. + (ctor.displayName || ctor.name) === "GeneratorFunction" + : false; + }; + + exports.mark = function(genFun) { + if (Object.setPrototypeOf) { + Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); + } else { + genFun.__proto__ = GeneratorFunctionPrototype; + define(genFun, toStringTagSymbol, "GeneratorFunction"); + } + genFun.prototype = Object.create(Gp); + return genFun; + }; + + // Within the body of any async function, `await x` is transformed to + // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test + // `hasOwn.call(value, "__await")` to determine if the yielded value is + // meant to be awaited. + exports.awrap = function(arg) { + return { __await: arg }; + }; + + function AsyncIterator(generator, PromiseImpl) { + function invoke(method, arg, resolve, reject) { + var record = tryCatch(generator[method], generator, arg); + if (record.type === "throw") { + reject(record.arg); + } else { + var result = record.arg; + var value = result.value; + if (value && + typeof value === "object" && + hasOwn.call(value, "__await")) { + return PromiseImpl.resolve(value.__await).then(function(value) { + invoke("next", value, resolve, reject); + }, function(err) { + invoke("throw", err, resolve, reject); + }); + } + + return PromiseImpl.resolve(value).then(function(unwrapped) { + // When a yielded Promise is resolved, its final value becomes + // the .value of the Promise<{value,done}> result for the + // current iteration. + result.value = unwrapped; + resolve(result); + }, function(error) { + // If a rejected Promise was yielded, throw the rejection back + // into the async generator function so it can be handled there. + return invoke("throw", error, resolve, reject); + }); + } + } + + var previousPromise; + + function enqueue(method, arg) { + function callInvokeWithMethodAndArg() { + return new PromiseImpl(function(resolve, reject) { + invoke(method, arg, resolve, reject); + }); + } + + return previousPromise = + // If enqueue has been called before, then we want to wait until + // all previous Promises have been resolved before calling invoke, + // so that results are always delivered in the correct order. If + // enqueue has not been called before, then it is important to + // call invoke immediately, without waiting on a callback to fire, + // so that the async generator function has the opportunity to do + // any necessary setup in a predictable way. This predictability + // is why the Promise constructor synchronously invokes its + // executor callback, and why async functions synchronously + // execute code before the first await. Since we implement simple + // async functions in terms of async generators, it is especially + // important to get this right, even though it requires care. + previousPromise ? previousPromise.then( + callInvokeWithMethodAndArg, + // Avoid propagating failures to Promises returned by later + // invocations of the iterator. + callInvokeWithMethodAndArg + ) : callInvokeWithMethodAndArg(); + } + + // Define the unified helper method that is used to implement .next, + // .throw, and .return (see defineIteratorMethods). + this._invoke = enqueue; + } + + defineIteratorMethods(AsyncIterator.prototype); + define(AsyncIterator.prototype, asyncIteratorSymbol, function () { + return this; + }); + exports.AsyncIterator = AsyncIterator; + + // Note that simple async functions are implemented on top of + // AsyncIterator objects; they just return a Promise for the value of + // the final result produced by the iterator. + exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { + if (PromiseImpl === void 0) PromiseImpl = Promise; + + var iter = new AsyncIterator( + wrap(innerFn, outerFn, self, tryLocsList), + PromiseImpl + ); + + return exports.isGeneratorFunction(outerFn) + ? iter // If outerFn is a generator, return the full iterator. + : iter.next().then(function(result) { + return result.done ? result.value : iter.next(); + }); + }; + + function makeInvokeMethod(innerFn, self, context) { + var state = GenStateSuspendedStart; + + return function invoke(method, arg) { + if (state === GenStateExecuting) { + throw new Error("Generator is already running"); + } + + if (state === GenStateCompleted) { + if (method === "throw") { + throw arg; + } + + // Be forgiving, per 25.3.3.3.3 of the spec: + // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume + return doneResult(); + } + + context.method = method; + context.arg = arg; + + while (true) { + var delegate = context.delegate; + if (delegate) { + var delegateResult = maybeInvokeDelegate(delegate, context); + if (delegateResult) { + if (delegateResult === ContinueSentinel) continue; + return delegateResult; + } + } + + if (context.method === "next") { + // Setting context._sent for legacy support of Babel's + // function.sent implementation. + context.sent = context._sent = context.arg; + + } else if (context.method === "throw") { + if (state === GenStateSuspendedStart) { + state = GenStateCompleted; + throw context.arg; + } + + context.dispatchException(context.arg); + + } else if (context.method === "return") { + context.abrupt("return", context.arg); + } + + state = GenStateExecuting; + + var record = tryCatch(innerFn, self, context); + if (record.type === "normal") { + // If an exception is thrown from innerFn, we leave state === + // GenStateExecuting and loop back for another invocation. + state = context.done + ? GenStateCompleted + : GenStateSuspendedYield; + + if (record.arg === ContinueSentinel) { + continue; + } + + return { + value: record.arg, + done: context.done + }; + + } else if (record.type === "throw") { + state = GenStateCompleted; + // Dispatch the exception by looping back around to the + // context.dispatchException(context.arg) call above. + context.method = "throw"; + context.arg = record.arg; + } + } + }; + } + + // Call delegate.iterator[context.method](context.arg) and handle the + // result, either by returning a { value, done } result from the + // delegate iterator, or by modifying context.method and context.arg, + // setting context.delegate to null, and returning the ContinueSentinel. + function maybeInvokeDelegate(delegate, context) { + var method = delegate.iterator[context.method]; + if (method === undefined$1) { + // A .throw or .return when the delegate iterator has no .throw + // method always terminates the yield* loop. + context.delegate = null; + + if (context.method === "throw") { + // Note: ["return"] must be used for ES3 parsing compatibility. + if (delegate.iterator["return"]) { + // If the delegate iterator has a return method, give it a + // chance to clean up. + context.method = "return"; + context.arg = undefined$1; + maybeInvokeDelegate(delegate, context); + + if (context.method === "throw") { + // If maybeInvokeDelegate(context) changed context.method from + // "return" to "throw", let that override the TypeError below. + return ContinueSentinel; + } + } + + context.method = "throw"; + context.arg = new TypeError( + "The iterator does not provide a 'throw' method"); + } + + return ContinueSentinel; + } + + var record = tryCatch(method, delegate.iterator, context.arg); + + if (record.type === "throw") { + context.method = "throw"; + context.arg = record.arg; + context.delegate = null; + return ContinueSentinel; + } + + var info = record.arg; + + if (! info) { + context.method = "throw"; + context.arg = new TypeError("iterator result is not an object"); + context.delegate = null; + return ContinueSentinel; + } + + if (info.done) { + // Assign the result of the finished delegate to the temporary + // variable specified by delegate.resultName (see delegateYield). + context[delegate.resultName] = info.value; + + // Resume execution at the desired location (see delegateYield). + context.next = delegate.nextLoc; + + // If context.method was "throw" but the delegate handled the + // exception, let the outer generator proceed normally. If + // context.method was "next", forget context.arg since it has been + // "consumed" by the delegate iterator. If context.method was + // "return", allow the original .return call to continue in the + // outer generator. + if (context.method !== "return") { + context.method = "next"; + context.arg = undefined$1; + } + + } else { + // Re-yield the result returned by the delegate method. + return info; + } + + // The delegate iterator is finished, so forget it and continue with + // the outer generator. + context.delegate = null; + return ContinueSentinel; + } + + // Define Generator.prototype.{next,throw,return} in terms of the + // unified ._invoke helper method. + defineIteratorMethods(Gp); + + define(Gp, toStringTagSymbol, "Generator"); + + // A Generator should always return itself as the iterator object when the + // @@iterator function is called on it. Some browsers' implementations of the + // iterator prototype chain incorrectly implement this, causing the Generator + // object to not be returned from this call. This ensures that doesn't happen. + // See https://github.com/facebook/regenerator/issues/274 for more details. + define(Gp, iteratorSymbol, function() { + return this; + }); + + define(Gp, "toString", function() { + return "[object Generator]"; + }); + + function pushTryEntry(locs) { + var entry = { tryLoc: locs[0] }; + + if (1 in locs) { + entry.catchLoc = locs[1]; + } + + if (2 in locs) { + entry.finallyLoc = locs[2]; + entry.afterLoc = locs[3]; + } + + this.tryEntries.push(entry); + } + + function resetTryEntry(entry) { + var record = entry.completion || {}; + record.type = "normal"; + delete record.arg; + entry.completion = record; + } + + function Context(tryLocsList) { + // The root entry object (effectively a try statement without a catch + // or a finally block) gives us a place to store values thrown from + // locations where there is no enclosing try statement. + this.tryEntries = [{ tryLoc: "root" }]; + tryLocsList.forEach(pushTryEntry, this); + this.reset(true); + } + + exports.keys = function(object) { + var keys = []; + for (var key in object) { + keys.push(key); + } + keys.reverse(); + + // Rather than returning an object with a next method, we keep + // things simple and return the next function itself. + return function next() { + while (keys.length) { + var key = keys.pop(); + if (key in object) { + next.value = key; + next.done = false; + return next; + } + } + + // To avoid creating an additional object, we just hang the .value + // and .done properties off the next function object itself. This + // also ensures that the minifier will not anonymize the function. + next.done = true; + return next; + }; + }; + + function values(iterable) { + if (iterable) { + var iteratorMethod = iterable[iteratorSymbol]; + if (iteratorMethod) { + return iteratorMethod.call(iterable); + } + + if (typeof iterable.next === "function") { + return iterable; + } + + if (!isNaN(iterable.length)) { + var i = -1, next = function next() { + while (++i < iterable.length) { + if (hasOwn.call(iterable, i)) { + next.value = iterable[i]; + next.done = false; + return next; + } + } + + next.value = undefined$1; + next.done = true; + + return next; + }; + + return next.next = next; + } + } + + // Return an iterator with no values. + return { next: doneResult }; + } + exports.values = values; + + function doneResult() { + return { value: undefined$1, done: true }; + } + + Context.prototype = { + constructor: Context, + + reset: function(skipTempReset) { + this.prev = 0; + this.next = 0; + // Resetting context._sent for legacy support of Babel's + // function.sent implementation. + this.sent = this._sent = undefined$1; + this.done = false; + this.delegate = null; + + this.method = "next"; + this.arg = undefined$1; + + this.tryEntries.forEach(resetTryEntry); + + if (!skipTempReset) { + for (var name in this) { + // Not sure about the optimal order of these conditions: + if (name.charAt(0) === "t" && + hasOwn.call(this, name) && + !isNaN(+name.slice(1))) { + this[name] = undefined$1; + } + } + } + }, + + stop: function() { + this.done = true; + + var rootEntry = this.tryEntries[0]; + var rootRecord = rootEntry.completion; + if (rootRecord.type === "throw") { + throw rootRecord.arg; + } + + return this.rval; + }, + + dispatchException: function(exception) { + if (this.done) { + throw exception; + } + + var context = this; + function handle(loc, caught) { + record.type = "throw"; + record.arg = exception; + context.next = loc; + + if (caught) { + // If the dispatched exception was caught by a catch block, + // then let that catch block handle the exception normally. + context.method = "next"; + context.arg = undefined$1; + } + + return !! caught; + } + + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + var record = entry.completion; + + if (entry.tryLoc === "root") { + // Exception thrown outside of any try block that could handle + // it, so set the completion value of the entire function to + // throw the exception. + return handle("end"); + } + + if (entry.tryLoc <= this.prev) { + var hasCatch = hasOwn.call(entry, "catchLoc"); + var hasFinally = hasOwn.call(entry, "finallyLoc"); + + if (hasCatch && hasFinally) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } else if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else if (hasCatch) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } + + } else if (hasFinally) { + if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else { + throw new Error("try statement without catch or finally"); + } + } + } + }, + + abrupt: function(type, arg) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc <= this.prev && + hasOwn.call(entry, "finallyLoc") && + this.prev < entry.finallyLoc) { + var finallyEntry = entry; + break; + } + } + + if (finallyEntry && + (type === "break" || + type === "continue") && + finallyEntry.tryLoc <= arg && + arg <= finallyEntry.finallyLoc) { + // Ignore the finally entry if control is not jumping to a + // location outside the try/catch block. + finallyEntry = null; + } + + var record = finallyEntry ? finallyEntry.completion : {}; + record.type = type; + record.arg = arg; + + if (finallyEntry) { + this.method = "next"; + this.next = finallyEntry.finallyLoc; + return ContinueSentinel; + } + + return this.complete(record); + }, + + complete: function(record, afterLoc) { + if (record.type === "throw") { + throw record.arg; + } + + if (record.type === "break" || + record.type === "continue") { + this.next = record.arg; + } else if (record.type === "return") { + this.rval = this.arg = record.arg; + this.method = "return"; + this.next = "end"; + } else if (record.type === "normal" && afterLoc) { + this.next = afterLoc; + } + + return ContinueSentinel; + }, + + finish: function(finallyLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.finallyLoc === finallyLoc) { + this.complete(entry.completion, entry.afterLoc); + resetTryEntry(entry); + return ContinueSentinel; + } + } + }, + + "catch": function(tryLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc === tryLoc) { + var record = entry.completion; + if (record.type === "throw") { + var thrown = record.arg; + resetTryEntry(entry); + } + return thrown; + } + } + + // The context.catch method must only be called with a location + // argument that corresponds to a known catch block. + throw new Error("illegal catch attempt"); + }, + + delegateYield: function(iterable, resultName, nextLoc) { + this.delegate = { + iterator: values(iterable), + resultName: resultName, + nextLoc: nextLoc + }; + + if (this.method === "next") { + // Deliberately forget the last sent value so that we don't + // accidentally pass it on to the delegate. + this.arg = undefined$1; + } + + return ContinueSentinel; + } + }; + + // Regardless of whether this script is executing as a CommonJS module + // or not, return the runtime object so that we can declare the variable + // regeneratorRuntime in the outer scope, which allows this module to be + // injected easily by `bin/regenerator --include-runtime script.js`. + return exports; + + }( + // If this script is executing as a CommonJS module, use module.exports + // as the regeneratorRuntime namespace. Otherwise create a new empty + // object. Either way, the resulting object will be used to initialize + // the regeneratorRuntime variable at the top of this file. + module.exports + )); + + try { + regeneratorRuntime = runtime; + } catch (accidentalStrictMode) { + // This module should not be running in strict mode, so the above + // assignment should always work unless something is misconfigured. Just + // in case runtime.js accidentally runs in strict mode, in modern engines + // we can explicitly access globalThis. In older engines we can escape + // strict mode using a global Function call. This could conceivably fail + // if a Content Security Policy forbids using Function, but in that case + // the proper solution is to fix the accidental strict mode problem. If + // you've misconfigured your bundler to force strict mode and applied a + // CSP to forbid Function, and you're not willing to fix either of those + // problems, please detail your unique predicament in a GitHub issue. + if (typeof globalThis === "object") { + globalThis.regeneratorRuntime = runtime; + } else { + Function("r", "regeneratorRuntime = r")(runtime); + } + } + } (runtime)); + + var XnbError = function (_Error) { + _inherits(XnbError, _Error); + + var _super = _createSuper(XnbError); + + function XnbError() { + var _this; + + var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + + _classCallCheck(this, XnbError); + + _this = _super.call(this, message); + _this.name = "XnbError"; + _this.message = message; + Error.captureStackTrace(_assertThisInitialized(_this), XnbError); + return _this; + } + + return _createClass(XnbError); + }(_wrapNativeSuper(Error)); + + var TypeReader = function () { + function TypeReader() { + _classCallCheck(this, TypeReader); + } + + _createClass(TypeReader, null, [{ + key: "setReaders", + value: function setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + }, { + key: "addReaders", + value: function addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + }, { + key: "makeSimplied", + value: function makeSimplied(type, reader) { + var simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + var subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + }, { + key: "simplifyType", + value: function (_simplifyType) { + function simplifyType(_x) { + return _simplifyType.apply(this, arguments); + } + + simplifyType.toString = function () { + return _simplifyType.toString(); + }; + + return simplifyType; + }(function (type) { + var simple = type.split(/`|,/)[0]; + + var isArray = __endsWithString(simple, '[]'); + + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + var reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + return "".concat(reflectiveType); + } + + for (var _i2 = 0, _Object$values2 = Object.values(TypeReader.readers); _i2 < _Object$values2.length; _i2++) { + var reader = _Object$values2[_i2]; + var result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + }) + }, { + key: "parseSubtypes", + value: function parseSubtypes(type) { + var subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + var matches = subtype.match(pattern).map(function (e) { + return e.slice(1, -1); + }); + return matches; + } + }, { + key: "getTypeInfo", + value: function getTypeInfo(type) { + var mainType = type.match(/[^<]+/)[0]; + var subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(function (type) { + return type.trim(); + }) : []; + return { + type: mainType, + subtypes: subtypes + }; + } + }, { + key: "getReaderTypeList", + value: function getReaderTypeList(typeString) { + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; + + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReader", + value: function getReader(typeString) { + var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn2.type, + subtypes = _TypeReader$getTypeIn2.subtypes; + + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReaderFromRaw", + value: function getReaderFromRaw(typeString) { + var simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + }]); + + return TypeReader; + }(); + + _defineProperty(TypeReader, "readers", {}); + + var UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; + var UTF8_SECOND_BITES = 0x80; + var UTF8_MASK = 63; + var UTF16_BITES$1 = [0xD800, 0xDC00]; + var UTF16_MASK$1 = 1023; + + function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + } + + function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; + } + + function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); + } + + function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + } + + function stringToUnicode$1(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8ToUnicode(codes) { + var dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + var result = []; + var index = 0; + + while (index < dataArray.length) { + var headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; + } + + function UnicodeToUTF8(unicodeArr) { + var result = []; + + for (var _i2 = 0; _i2 < unicodeArr.length; _i2++) { + var code = unicodeArr[_i2]; + result.push.apply(result, UTF8Encode(code)); + } + + return result; + } + + function UnicodeToString(unicodeArr) { + var result = []; + + for (var _i4 = 0; _i4 < unicodeArr.length; _i4++) { + var code = unicodeArr[_i4]; + result.push.apply(result, UTF16Encode(code)); + } + + var blockSize = 32768; + var resultStr = ""; + + for (var i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode.apply(String, result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; + } + + function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); + } + + function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); + } + + var LITTLE_ENDIAN = true; + + var BufferReader = function () { + function BufferReader(buffer) { + var endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + + _classCallCheck(this, BufferReader); + + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + _createClass(BufferReader, [{ + key: "seek", + value: function seek(index) { + var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + var offset = this._offset; + this._offset = Math.max(origin + parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + }, { + key: "bytePosition", + get: function get() { + return parseInt(this._offset); + }, + set: function set(value) { + this._offset = value; + } + }, { + key: "bitPosition", + get: function get() { + return parseInt(this._bitOffset); + }, + set: function set(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + var byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + }, { + key: "size", + get: function get() { + return this.buffer.byteLength; + } + }, { + key: "buffer", + get: function get() { + return this._buffer; + } + }, { + key: "copyFrom", + value: function copyFrom(buffer) { + var targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + var sourceView = new Uint8Array(buffer); + var isOverflow = this.buffer.byteLength < length + targetIndex; + var targetBuffer = this.buffer; + var targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (var i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (var _i = sourceIndex, j = targetIndex; _i < length; _i++, j++) { + targetView.setUint8(j, sourceView[_i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + }, { + key: "read", + value: function read(count) { + var buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + }, { + key: "readByte", + value: function readByte() { + return this.readUInt(); + } + }, { + key: "readInt", + value: function readInt() { + var value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + }, { + key: "readUInt", + value: function readUInt() { + var value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + }, { + key: "readUInt16", + value: function readUInt16() { + var value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + }, { + key: "readUInt32", + value: function readUInt32() { + var value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readInt16", + value: function readInt16() { + var value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + }, { + key: "readInt32", + value: function readInt32() { + var value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readSingle", + value: function readSingle() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readDouble", + value: function readDouble() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + }, { + key: "readString", + value: function readString() { + var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + var chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) { + chars.push(this.readByte()); + } + } else { + for (var i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + }, { + key: "peek", + value: function peek(count) { + var buffer = this.read(count); + this.seek(-count); + return buffer; + } + }, { + key: "peekByte", + value: function peekByte() { + return this.peekUInt(); + } + }, { + key: "peekInt", + value: function peekInt() { + var value = this._dataView.getInt8(this._offset); + + return value; + } + }, { + key: "peekUInt", + value: function peekUInt() { + var value = this._dataView.getUint8(this._offset); + + return value; + } + }, { + key: "peekUInt16", + value: function peekUInt16() { + var value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + }, { + key: "peekUInt32", + value: function peekUInt32() { + var value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekInt16", + value: function peekInt16() { + var value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + }, { + key: "peekInt32", + value: function peekInt32() { + var value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekSingle", + value: function peekSingle() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekDouble", + value: function peekDouble() { + var value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + }, { + key: "peekString", + value: function peekString() { + var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var chars = []; + var startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) { + chars.push(this.readByte()); + } + } else { + for (var i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + }, { + key: "read7BitNumber", + value: function read7BitNumber() { + var result = 0; + var bitsRead = 0; + var value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + }, { + key: "readLZXBits", + value: function readLZXBits(bits) { + var bitsLeft = bits; + var read = 0; + + while (bitsLeft > 0) { + var peek = this._dataView.getUint16(this._offset, true); + + var bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + var offset = 16 - this.bitPosition - bitsInFrame; + var value = (peek & Math.pow(2, bitsInFrame) - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + }, { + key: "peekLZXBits", + value: function peekLZXBits(bits) { + var bitPosition = this.bitPosition; + var bytePosition = this.bytePosition; + var read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + }, { + key: "readLZXInt16", + value: function readLZXInt16() { + var seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + var lsB = this.readByte(); + var msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + }, { + key: "align", + value: function align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + }]); + + return BufferReader; + }(); + + var BufferWriter = function () { + function BufferWriter() { + var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + + _classCallCheck(this, BufferWriter); + + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + _createClass(BufferWriter, [{ + key: "buffer", + get: function get() { + return this._buffer; + } + }, { + key: "reconnectDataView", + value: function reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + }, { + key: "trim", + value: function trim() { + var pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + }, { + key: "alloc", + value: function alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + var tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + var tDataView = new DataView(tBuffer); + + for (var i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + }, { + key: "concat", + value: function concat(buffer) { + var targetBufferView = new Uint8Array(buffer); + var newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (var i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + }, { + key: "write", + value: function write(bytes) { + var targetBufferView = new Uint8Array(bytes); + var newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (var i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + }, { + key: "writeString", + value: function writeString(str) { + var utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + }, { + key: "writeByte", + value: function writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + }, { + key: "writeInt", + value: function writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + }, { + key: "writeUInt", + value: function writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + }, { + key: "writeInt16", + value: function writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + }, { + key: "writeUInt16", + value: function writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + }, { + key: "writeInt32", + value: function writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeUInt32", + value: function writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeSingle", + value: function writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeDouble", + value: function writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + }, { + key: "write7BitNumber", + value: function write7BitNumber(number) { + this.alloc(2); + + do { + var byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + }]); + + return BufferWriter; + }(); + + var MIN_MATCH = 2; + var NUM_CHARS = 256; + var BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 + }; + var PRETREE_NUM_ELEMENTS = 20; + var ALIGNED_NUM_ELEMENTS = 8; + var NUM_PRIMARY_LENGTHS = 7; + var NUM_SECONDARY_LENGTHS = 249; + var PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; + var PRETREE_TABLEBITS = 6; + var MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; + var MAINTREE_TABLEBITS = 12; + var LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; + var LENGTH_TABLEBITS = 12; + var ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; + var ALIGNED_TABLEBITS = 7; + + var Lzx = function () { + function Lzx(window_bits) { + _classCallCheck(this, Lzx); + + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (var i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (var _i = 0, _j = 0; _i <= 50; _i++) { + Lzx.position_base[_i] = _j; + _j += 1 << Lzx.extra_bits[_i]; + } + } + + var posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (var _i2 = 0; _i2 < MAINTREE_MAXSYMBOLS; _i2++) { + this.maintree_len[_i2] = 0; + } + + for (var _i3 = 0; _i3 < NUM_SECONDARY_LENGTHS; _i3++) { + this.length_len[_i3] = 0; + } + + this.win = []; + } + + _createClass(Lzx, [{ + key: "decompress", + value: function decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + var intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + var togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + var hi = buffer.readLZXBits(16); + var lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (var i = 0; i < 8; i++) { + this.aligned_len[i] = buffer.readLZXBits(3); + } + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + var this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + var main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + var length_footer = void 0; + var match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + var match_offset = main_element >> 3; + + if (match_offset > 2) { + var extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + var verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + var aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + var rundest = this.window_posn; + var runsrc = void 0; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + var copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) { + this.win[rundest++] = this.win[runsrc++]; + } + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) { + this.win[rundest++] = this.win[runsrc++]; + } + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + var _main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (_main_element < NUM_CHARS) { + this.win[this.window_posn++] = _main_element; + this_run--; + continue; + } + + _main_element -= NUM_CHARS; + + var _length_footer = void 0; + + var _match_length = _main_element & NUM_PRIMARY_LENGTHS; + + if (_match_length == NUM_PRIMARY_LENGTHS) { + _length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + _match_length += _length_footer; + } + + _match_length += MIN_MATCH; + + var _match_offset = _main_element >> 3; + + if (_match_offset > 2) { + if (_match_offset != 3) { + var _extra = Lzx.extra_bits[_match_offset]; + + var _verbatim_bits = buffer.readLZXBits(_extra); + + _match_offset = Lzx.position_base[_match_offset] - 2 + _verbatim_bits; + } else _match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = _match_offset; + } else if (_match_offset === 0) { + _match_offset = this.R0; + } else if (_match_offset == 1) { + _match_offset = this.R1; + this.R1 = this.R0; + this.R0 = _match_offset; + } else { + _match_offset = this.R2; + this.R2 = this.R0; + this.R0 = _match_offset; + } + + var _rundest = this.window_posn; + + var _runsrc = void 0; + + this_run -= _match_length; + if (this.window_posn >= _match_offset) _runsrc = _rundest - _match_offset;else { + _runsrc = _rundest + (this.window_size - _match_offset); + + var _copy_length = _match_offset - this.window_posn; + + if (_copy_length < _match_length) { + _match_length -= _copy_length; + this.window_posn += _copy_length; + + while (_copy_length-- > 0) { + this.win[_rundest++] = this.win[_runsrc++]; + } + + _runsrc = 0; + } + } + this.window_posn += _match_length; + + while (_match_length-- > 0) { + this.win[_rundest++] = this.win[_runsrc++]; + } + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (var _i4 = 0; _i4 < this_run; _i4++) { + this.win[window_posn + _i4] = buffer.buffer[buffer.bytePosition + _i4]; + } + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + var start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + }, { + key: "readLengths", + value: function readLengths(buffer, table, first, last) { + for (var i = 0; i < 20; i++) { + this.pretree_len[i] = buffer.readLZXBits(4); + } + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (var _i5 = first; _i5 < last;) { + var symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + var zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) { + table[_i5++] = 0; + } + } else if (symbol == 18) { + var _zeros = buffer.readLZXBits(5) + 20; + + while (_zeros-- != 0) { + table[_i5++] = 0; + } + } else if (symbol == 19) { + var same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[_i5] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) { + table[_i5++] = symbol; + } + } else { + symbol = table[_i5] - symbol; + if (symbol < 0) symbol += 17; + table[_i5++] = symbol; + } + } + + return table; + } + }, { + key: "decodeTable", + value: function decodeTable(symbols, bits, length) { + var table = []; + var pos = 0; + var table_mask = 1 << bits; + var bit_mask = table_mask >> 1; + + for (var bit_num = 1; bit_num <= bits; bit_num++) { + for (var symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + var leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + var fill = bit_mask; + + while (fill-- > 0) { + table[leaf++] = symbol; + } + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (var _symbol = pos; _symbol < table_mask; _symbol++) { + table[_symbol] = 0xFFFF; + } + + var next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (var _bit_num = bits + 1; _bit_num <= 16; _bit_num++) { + for (var _symbol2 = 0; _symbol2 < symbols; _symbol2++) { + if (length[_symbol2] != _bit_num) continue; + + var _leaf = pos >> 16; + + for (var _fill = 0; _fill < _bit_num - bits; _fill++) { + if (table[_leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[_leaf] = next_symbol++; + } + + _leaf = table[_leaf] << 1; + if (pos >> 15 - _fill & 1) _leaf++; + } + + table[_leaf] = _symbol2; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + }, { + key: "readHuffSymbol", + value: function readHuffSymbol(buffer, table, length, symbols, bits) { + var bit = buffer.peekLZXBits(32) >>> 0; + var i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + var j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + }, { + key: "RRR", + set: function set(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + var R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + var R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + }]); + + return Lzx; + }(); + + Lzx.position_base = []; + Lzx.extra_bits = []; + + var Presser = function () { + function Presser() { + _classCallCheck(this, Presser); + } + + _createClass(Presser, null, [{ + key: "decompress", + value: function decompress(buffer, compressedTodo, decompressedTodo) { + var pos = 0; + var block_size; + var frame_size; + var lzx = new Lzx(16); + var decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + var flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + }]); + + return Presser; + }(); + + var LZ4Utils = function () { + function LZ4Utils() { + _classCallCheck(this, LZ4Utils); + } + + _createClass(LZ4Utils, null, [{ + key: "hashU32", + value: function hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + }, { + key: "readU64", + value: function readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + }, { + key: "readU32", + value: function readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + }, { + key: "writeU32", + value: function writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + }, { + key: "imul", + value: function imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + }]); + + return LZ4Utils; + }(); + + var minMatch = 4; + var minLength = 13; + var searchLimit = 5; + var skipTrigger = 6; + var hashSize = 1 << 16; + var mlBits = 4; + var mlMask = (1 << mlBits) - 1; + var runBits = 4; + var runMask = (1 << runBits) - 1; + makeBuffer(5 << 20); + var hashTable = makeHashTable(); + + function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + var _hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + _hashTable[i] = 0; + } + + return _hashTable; + } + } + + function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + } + + function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } + } + + function compressBound(n) { + return n + n / 255 + 16 | 0; + } + + function decompressBlock(src, dst) { + var sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + var dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; + } + + function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; + } + + function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); + } + + var UTF16_BITES = [0xD800, 0xDC00]; + var UTF16_MASK = 1023; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + var codes = stringToUnicode(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + var StringReaderCore = function () { + function StringReaderCore() { + _classCallCheck(this, StringReaderCore); + } + + _createClass(StringReaderCore, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string) { + var size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }]); + + return StringReaderCore; + }(); + + var ReaderResolver = function () { + function ReaderResolver(readers) { + _classCallCheck(this, ReaderResolver); + + this.readers = readers; + } + + _createClass(ReaderResolver, [{ + key: "read", + value: function read(buffer) { + var index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + }, { + key: "write", + value: function write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + }, { + key: "getIndex", + value: function getIndex(reader) { + for (var i in this.readers) { + if (reader.toString() == this.readers[i].toString()) return i; + } + } + }]); + + return ReaderResolver; + }(); + + var XnbData = function () { + function XnbData(header, readers, content) { + _classCallCheck(this, XnbData); + + var target = header.target, + formatVersion = header.formatVersion, + hidef = header.hidef, + compressed = header.compressed; + this.header = { + target: target, + formatVersion: formatVersion, + hidef: hidef, + compressed: compressed + }; + this.readers = readers; + this.content = content; + } + + _createClass(XnbData, [{ + key: "target", + get: function get() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + }, { + key: "formatVersion", + get: function get() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + }, { + key: "hidef", + get: function get() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + }, { + key: "compressed", + get: function get() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + }, { + key: "contentType", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.type; + return "JSON"; + } + }, { + key: "rawContent", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, function (key, value) { + if (key === "export") return value.type; + return value; + }, 4); + } + }, { + key: "stringify", + value: function stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + }, { + key: "toString", + value: function toString() { + return this.stringify(); + } + }]); + + return XnbData; + }(); + + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; + } + + var XnbContent = _createClass(function XnbContent(data, ext) { + _classCallCheck(this, XnbContent); + + this.type = extensionToDatatype(ext); + this.content = data; + }); + + var HIDEF_MASK = 0x1; + var COMPRESSED_LZ4_MASK = 0x40; + var COMPRESSED_LZX_MASK = 0x80; + var XNB_COMPRESSED_PROLOGUE_SIZE = 14; + + var XnbConverter = function () { + function XnbConverter() { + _classCallCheck(this, XnbConverter); + + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + _createClass(XnbConverter, [{ + key: "load", + value: function load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + var decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + var compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + var decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + var trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); + + var _decompressed = new Uint8Array(decompressedSize); + + decompressBlock(trimmedArray, _decompressed); + this.buffer.copyFrom(_decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + var count = this.buffer.read7BitNumber(); + var stringReader = new StringReaderCore(); + var readers = []; + + for (var i = 0; i < count; i++) { + var type = stringReader.read(this.buffer); + var version = this.buffer.readInt32(); + var reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type: type, + version: version + }); + } + + var shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + var content = new ReaderResolver(this.readers); + var result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + }, { + key: "convert", + value: function convert(json) { + var buffer = new BufferWriter(); + var stringReader = new StringReaderCore(); + var _json$header = json.header, + target = _json$header.target, + formatVersion = _json$header.formatVersion, + hidef = _json$header.hidef, + compressed = _json$header.compressed; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + var lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (var _i2 = 0, _json$readers2 = json.readers; _i2 < _json$readers2.length; _i2++) { + var reader = _json$readers2[_i2]; + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + var content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + var trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); + var compressedSize = compressBound(trimmedArray.length); + + var _compressed = new Uint8Array(compressedSize); + + compressedSize = compressSingleBlock(trimmedArray, _compressed); + _compressed = _compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(_compressed); + var returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + var fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + }, { + key: "_validateHeader", + value: function _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + var magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + var flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + }]); + + return XnbConverter; + }(); + + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + var i = 0; + var n = t.length; + var r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + var _e2 = t.charCodeAt(i++); + + if (_e2 >= 55296 && _e2 <= 56319) { + if (i < n) { + var _n = t.charCodeAt(i); + + 56320 == (64512 & _n) && (++i, _e2 = ((1023 & _e2) << 10) + (1023 & _n) + 65536); + } + + if (_e2 >= 55296 && _e2 <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + + var _e3 = new Uint8Array(s); + + _e3.set(a), a = _e3; + } + + if (0 != (4294967168 & _e2)) { + if (0 == (4294965248 & _e2)) a[r++] = _e2 >> 6 & 31 | 192;else if (0 == (4294901760 & _e2)) a[r++] = _e2 >> 12 & 15 | 224, a[r++] = _e2 >> 6 & 63 | 128;else { + if (0 != (4292870144 & _e2)) continue; + a[r++] = _e2 >> 18 & 7 | 240, a[r++] = _e2 >> 12 & 63 | 128, a[r++] = _e2 >> 6 & 63 | 128; + } + a[r++] = 63 & _e2 | 128; + } else a[r++] = _e2; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + var i = new Uint8Array(t); + var n = 0; + var r = i.length, + s = []; + + for (; n < r;) { + var _t2 = i[n++]; + if (0 === _t2) break; + if (0 == (128 & _t2)) s.push(_t2);else if (192 == (224 & _t2)) { + var _e4 = 63 & i[n++]; + + s.push((31 & _t2) << 6 | _e4); + } else if (224 == (240 & _t2)) { + var _e5 = 63 & i[n++], + _r = 63 & i[n++]; + + s.push((31 & _t2) << 12 | _e5 << 6 | _r); + } else if (240 == (248 & _t2)) { + var _e6 = (7 & _t2) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + + _e6 > 65535 && (_e6 -= 65536, s.push(_e6 >>> 10 & 1023 | 55296), _e6 = 56320 | 1023 & _e6), s.push(_e6); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } + }, + e = {}; + + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; + } + + i.d = function (t, e) { + for (var n in e) { + i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + } + }, i.o = function (t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; + var n = {}; + + (function () { + i.d(n, { + P: function P() { + return Mi; + }, + m: function m() { + return Fi; + } + }), i(396); + var t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + var r = function () { + function r() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, r); + + var i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + var n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + var a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + _createClass(r, [{ + key: "available", + value: function available() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + }, { + key: "isLittleEndian", + value: function isLittleEndian() { + return this.littleEndian; + } + }, { + key: "setLittleEndian", + value: function setLittleEndian() { + return this.littleEndian = !0, this; + } + }, { + key: "isBigEndian", + value: function isBigEndian() { + return !this.littleEndian; + } + }, { + key: "setBigEndian", + value: function setBigEndian() { + return this.littleEndian = !1, this; + } + }, { + key: "skip", + value: function skip() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + }, { + key: "seek", + value: function seek(t) { + return this.offset = t, this; + } + }, { + key: "mark", + value: function mark() { + return this._mark = this.offset, this; + } + }, { + key: "reset", + value: function reset() { + return this.offset = this._mark, this; + } + }, { + key: "pushMark", + value: function pushMark() { + return this._marks.push(this.offset), this; + } + }, { + key: "popMark", + value: function popMark() { + var t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + }, { + key: "rewind", + value: function rewind() { + return this.offset = 0, this; + } + }, { + key: "ensureAvailable", + value: function ensureAvailable() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + var _e7 = 2 * (this.offset + t), + _i2 = new Uint8Array(_e7); + + _i2.set(new Uint8Array(this.buffer)), this.buffer = _i2.buffer, this.length = this.byteLength = _e7, this._data = new DataView(this.buffer); + } + + return this; + } + }, { + key: "readBoolean", + value: function readBoolean() { + return 0 !== this.readUint8(); + } + }, { + key: "readInt8", + value: function readInt8() { + return this._data.getInt8(this.offset++); + } + }, { + key: "readUint8", + value: function readUint8() { + return this._data.getUint8(this.offset++); + } + }, { + key: "readByte", + value: function readByte() { + return this.readUint8(); + } + }, { + key: "readBytes", + value: function readBytes() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = new Uint8Array(t); + + for (var _i3 = 0; _i3 < t; _i3++) { + e[_i3] = this.readByte(); + } + + return e; + } + }, { + key: "readInt16", + value: function readInt16() { + var t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + }, { + key: "readUint16", + value: function readUint16() { + var t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + }, { + key: "readInt32", + value: function readInt32() { + var t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readUint32", + value: function readUint32() { + var t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readFloat32", + value: function readFloat32() { + var t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readFloat64", + value: function readFloat64() { + var t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readBigInt64", + value: function readBigInt64() { + var t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readBigUint64", + value: function readBigUint64() { + var t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readChar", + value: function readChar() { + return String.fromCharCode(this.readInt8()); + } + }, { + key: "readChars", + value: function readChars() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = ""; + + for (var _i4 = 0; _i4 < t; _i4++) { + e += this.readChar(); + } + + return e; + } + }, { + key: "readUtf8", + value: function readUtf8() { + var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + }, { + key: "writeBoolean", + value: function writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + }, { + key: "writeInt8", + value: function writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint8", + value: function writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeByte", + value: function writeByte(t) { + return this.writeUint8(t); + } + }, { + key: "writeBytes", + value: function writeBytes(t) { + this.ensureAvailable(t.length); + + for (var _e8 = 0; _e8 < t.length; _e8++) { + this._data.setUint8(this.offset++, t[_e8]); + } + + return this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt16", + value: function writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint16", + value: function writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt32", + value: function writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint32", + value: function writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat32", + value: function writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat64", + value: function writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigInt64", + value: function writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigUint64", + value: function writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeChar", + value: function writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + }, { + key: "writeChars", + value: function writeChars(t) { + for (var _e9 = 0; _e9 < t.length; _e9++) { + this.writeUint8(t.charCodeAt(_e9)); + } + + return this; + } + }, { + key: "writeUtf8", + value: function writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + }, { + key: "toArray", + value: function toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + }, { + key: "_updateLastWrittenByte", + value: function _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + }]); + + return r; + }(); + + function s(t) { + var e = t.length; + + for (; --e >= 0;) { + t[e] = 0; + } + } + + var a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + var _ = new Array(60); + + s(_); + var f = new Array(512); + s(f); + var c = new Array(256); + s(c); + var u = new Array(29); + s(u); + var w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + var g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + var y = function y(t) { + return t < 256 ? f[t] : f[256 + (t >>> 7)]; + }, + v = function v(t, e) { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = function E(t, e, i) { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = function A(t, e, i) { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = function x(t, e) { + var i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = function U(t, e, i) { + var n = new Array(16); + var r, + s, + a = 0; + + for (r = 1; r <= 15; r++) { + n[r] = a = a + i[r - 1] << 1; + } + + for (s = 0; s <= e; s++) { + var _e10 = t[2 * s + 1]; + 0 !== _e10 && (t[2 * s] = x(n[_e10]++, _e10)); + } + }, + z = function z(t) { + var e; + + for (e = 0; e < 286; e++) { + t.dyn_ltree[2 * e] = 0; + } + + for (e = 0; e < 30; e++) { + t.dyn_dtree[2 * e] = 0; + } + + for (e = 0; e < 19; e++) { + t.bl_tree[2 * e] = 0; + } + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = function R(t) { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = function N(t, e, i, n) { + var r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = function T(t, e, i) { + var n = t.heap[i]; + var r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) { + t.heap[i] = t.heap[r], i = r, r <<= 1; + } + + t.heap[i] = n; + }, + O = function O(t, e, i) { + var n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = function L(t, e) { + var i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + var a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) { + 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + } + + for (; t.heap_len < 2;) { + h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + } + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) { + T(t, i, a); + } + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], function (t, e) { + var i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + var l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) { + t.bl_count[f] = 0; + } + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) { + d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + } + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) { + f--; + } + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) { + for (d = t.bl_count[f]; 0 !== d;) { + _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + } + } + }(t, e), U(i, l, t.bl_count); + }, + B = function B(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) { + r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + } + }, + C = function C(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) { + if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + } + }; + + var D = !1; + + var I = function I(t, e, i, n) { + E(t, 0 + (n ? 1 : 0), 3), function (t, e, i, n) { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + }(t, e, i); + }; + + var S = { + _tr_init: function _tr_init(t) { + D || (function () { + var t, e, i, n, r; + var s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) { + for (u[n] = i, t = 0; t < 1 << a[n]; t++) { + c[i++] = n; + } + } + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) { + for (w[n] = r, t = 0; t < 1 << o[n]; t++) { + f[r++] = n; + } + } + + for (r >>= 7; n < 30; n++) { + for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) { + f[256 + r++] = n; + } + } + + for (e = 0; e <= 15; e++) { + s[e] = 0; + } + + for (t = 0; t <= 143;) { + d[2 * t + 1] = 8, t++, s[8]++; + } + + for (; t <= 255;) { + d[2 * t + 1] = 9, t++, s[9]++; + } + + for (; t <= 279;) { + d[2 * t + 1] = 7, t++, s[7]++; + } + + for (; t <= 287;) { + d[2 * t + 1] = 8, t++, s[8]++; + } + + for (U(d, 287, s), t = 0; t < 30; t++) { + _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + } + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + }(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: function _tr_flush_block(t, e, i, n) { + var r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = function (t) { + var e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) { + if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + } + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) { + if (0 !== t.dyn_ltree[2 * e]) return 1; + } + + return 0; + }(t)), L(t, t.l_desc), L(t, t.d_desc), a = function (t) { + var e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--) { + } + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + }(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), function (t, e, i, n) { + var r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) { + E(t, t.bl_tree[2 * l[r] + 1], 3); + } + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + }(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: function _tr_tally(t, e, i) { + return t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1; + }, + _tr_align: function _tr_align(t) { + E(t, 2, 3), A(t, 256, d), function (t) { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + }(t); + } + }, + Z = function Z(t, e, i, n) { + var r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + var F = new Uint32Array(function () { + var t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) { + t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + } + + e[i] = t; + } + + return e; + }()); + + var M = function M(t, e, i, n) { + var r = F, + s = n + i; + t ^= -1; + + for (var _i5 = n; _i5 < s; _i5++) { + t = t >>> 8 ^ r[255 & (t ^ e[_i5])]; + } + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + var W = S._tr_init, + K = S._tr_stored_block, + $ = S._tr_flush_block, + Y = S._tr_tally, + j = S._tr_align, + G = H.Z_NO_FLUSH, + X = H.Z_PARTIAL_FLUSH, + V = H.Z_FULL_FLUSH, + q = H.Z_FINISH, + J = H.Z_BLOCK, + Q = H.Z_OK, + tt = H.Z_STREAM_END, + et = H.Z_STREAM_ERROR, + it = H.Z_DATA_ERROR, + nt = H.Z_BUF_ERROR, + rt = H.Z_DEFAULT_COMPRESSION, + st = H.Z_FILTERED, + at = H.Z_HUFFMAN_ONLY, + ot = H.Z_RLE, + ht = H.Z_FIXED, + dt = H.Z_UNKNOWN, + _t = H.Z_DEFLATED, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = function gt(t, e) { + return t.msg = P[e], e; + }, + bt = function bt(t) { + return (t << 1) - (t > 4 ? 9 : 0); + }, + mt = function mt(t) { + var e = t.length; + + for (; --e >= 0;) { + t[e] = 0; + } + }; + + var kt = function kt(t, e, i) { + return (e << t.hash_shift ^ i) & t.hash_mask; + }; + + var yt = function yt(t) { + var e = t.state; + var i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = function vt(t, e) { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = function Et(t, e) { + t.pending_buf[t.pending++] = e; + }, + At = function At(t, e) { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = function xt(t, e, i, n) { + var r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = function Ut(t, e) { + var i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + var h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + var c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = function zt(t) { + var e = t.w_size; + var i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));) { + } + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = function Rt(t, e) { + var i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = function Nt(t, e) { + var i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + var Ot = [new Tt(0, 0, 0, 0, function (t, e) { + var i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + + var _n2 = t.block_start + i; + + if ((0 === t.strstart || t.strstart >= _n2) && (t.lookahead = t.strstart - _n2, t.strstart = _n2, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + var Bt = function Bt(t) { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + var e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = function Ct(t) { + var e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = function Dt(t, e, i, n, r, s) { + if (!t) return et; + var a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + var o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = function St(t, e) { + return t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et; + }, + Zt = function Zt(t, e) { + var i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + var r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + var s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + var _e11 = _t + (r.w_bits - 8 << 4) << 8, + _i6 = -1; + + _i6 = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, _e11 |= _i6 << 6, 0 !== r.strstart && (_e11 |= 32), _e11 += 31 - _e11 % 31, r.status = wt, At(r, _e11), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) { + Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + } + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + var _i7 = r.strategy === at ? function (t, e) { + var i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : r.strategy === ot ? function (t, e) { + var i, n, r, s; + var a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : Ot[r.level].func(r, e); + + if (3 !== _i7 && 4 !== _i7 || (r.status = pt), 1 === _i7 || 3 === _i7) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === _i7 && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = function Ft(t) { + if (!t || !t.state) return et; + var e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = function Mt(t, e) { + var i = e.length; + if (!t || !t.state) return et; + var n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + + var _t3 = new Uint8Array(n.w_size); + + _t3.set(e.subarray(i - n.w_size, i), 0), e = _t3, i = n.w_size; + } + + var s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + var _t4 = n.strstart, + _e12 = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[_t4 + 3 - 1]), n.prev[_t4 & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = _t4, _t4++; + } while (--_e12); + + n.strstart = _t4, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + var Pt = function Pt(t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; + + var Ht = function Ht(t) { + var e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + var _i8 = e.shift(); + + if (_i8) { + if ("object" != _typeof(_i8)) throw new TypeError(_i8 + "must be non-object"); + + for (var _e13 in _i8) { + Pt(_i8, _e13) && (t[_e13] = _i8[_e13]); + } + } + } + + return t; + }, + Wt = function Wt(t) { + var e = 0; + + for (var _i9 = 0, _n3 = t.length; _i9 < _n3; _i9++) { + e += t[_i9].length; + } + + var i = new Uint8Array(e); + + for (var _e14 = 0, _n4 = 0, _r2 = t.length; _e14 < _r2; _e14++) { + var _r3 = t[_e14]; + i.set(_r3, _n4), _n4 += _r3.length; + } + + return i; + }; + + var Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + var $t = new Uint8Array(256); + + for (var _t5 = 0; _t5 < 256; _t5++) { + $t[_t5] = _t5 >= 252 ? 6 : _t5 >= 248 ? 5 : _t5 >= 240 ? 4 : _t5 >= 224 ? 3 : _t5 >= 192 ? 2 : 1; + } + + $t[254] = $t[254] = 1; + + var Yt = function Yt(t) { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + var e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + } + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + } + + return e; + }, + jt = function jt(t, e) { + var i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + var n, r; + var s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + var _e15 = t[n++]; + + if (_e15 < 128) { + s[r++] = _e15; + continue; + } + + var _a = $t[_e15]; + if (_a > 4) s[r++] = 65533, n += _a - 1;else { + for (_e15 &= 2 === _a ? 31 : 3 === _a ? 15 : 7; _a > 1 && n < i;) { + _e15 = _e15 << 6 | 63 & t[n++], _a--; + } + + _a > 1 ? s[r++] = 65533 : _e15 < 65536 ? s[r++] = _e15 : (_e15 -= 65536, s[r++] = 55296 | _e15 >> 10 & 1023, s[r++] = 56320 | 1023 & _e15); + } + } + + return function (t, e) { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + var i = ""; + + for (var _n5 = 0; _n5 < e; _n5++) { + i += String.fromCharCode(t[_n5]); + } + + return i; + }(s, r); + }, + Gt = function Gt(t, e) { + (e = e || t.length) > t.length && (e = t.length); + var i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) { + i--; + } + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + var Vt = Object.prototype.toString, + qt = H.Z_NO_FLUSH, + Jt = H.Z_SYNC_FLUSH, + Qt = H.Z_FULL_FLUSH, + te = H.Z_FINISH, + ee = H.Z_OK, + ie = H.Z_STREAM_END, + ne = H.Z_DEFAULT_COMPRESSION, + re = H.Z_DEFAULT_STRATEGY, + se = H.Z_DEFLATED; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + var e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + var _t6; + + if (_t6 = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, _t6), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + var i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize; + var r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + var i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + var U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) { + x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + } + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + var de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = function ue(t, e, i, n, r, s, a, o) { + var h = o.bits; + + var l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + var z = new Uint16Array(16), + R = new Uint16Array(16); + var N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) { + z[w] = 0; + } + + for (p = 0; p < n; p++) { + z[e[i + p]]++; + } + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--) { + } + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++) { + } + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) { + if (v <<= 1, v -= z[w], v < 0) return -1; + } + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) { + R[w + 1] = R[w] + z[w]; + } + + for (p = 0; p < n; p++) { + 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + } + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) { + l >>= 1; + } + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) { + k++, v <<= 1; + } + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + var we = H.Z_FINISH, + pe = H.Z_BLOCK, + ge = H.Z_TREES, + be = H.Z_OK, + me = H.Z_STREAM_END, + ke = H.Z_NEED_DICT, + ye = H.Z_STREAM_ERROR, + ve = H.Z_DATA_ERROR, + Ee = H.Z_MEM_ERROR, + Ae = H.Z_BUF_ERROR, + xe = H.Z_DEFLATED, + Ue = 12, + ze = 30, + Re = function Re(t) { + return (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + }; + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + var Te = function Te(t) { + if (!t || !t.state) return ye; + var e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = function Oe(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = function Le(t, e) { + var i; + if (!t || !t.state) return ye; + var n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = function Be(t, e) { + if (!t) return ye; + var i = new Ne(); + t.state = i, i.window = null; + var n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + var Ce, + De, + Ie = !0; + + var Se = function Se(t) { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + var _e16 = 0; + + for (; _e16 < 144;) { + t.lens[_e16++] = 8; + } + + for (; _e16 < 256;) { + t.lens[_e16++] = 9; + } + + for (; _e16 < 280;) { + t.lens[_e16++] = 7; + } + + for (; _e16 < 288;) { + t.lens[_e16++] = 8; + } + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), _e16 = 0; _e16 < 32;) { + t.lens[_e16++] = 5; + } + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = function Ze(t, e, i, n) { + var r; + var s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = function Pe(t, e) { + var i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + var x = new Uint8Array(4); + var U, z; + var R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) { + switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) { + i.lens[R[i.have++]] = 0; + } + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) { + i.lens[i.have++] = v; + } + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = function He(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = function We(t, e) { + if (!t || !t.state) return ye; + var i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = function Ke(t, e) { + var i = e.length; + var n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + var Ye = Object.prototype.toString, + je = H.Z_NO_FLUSH, + Ge = H.Z_FINISH, + Xe = H.Z_OK, + Ve = H.Z_STREAM_END, + qe = H.Z_NEED_DICT, + Je = H.Z_STREAM_ERROR, + Qe = H.Z_DATA_ERROR, + ti = H.Z_MEM_ERROR; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + var e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + var i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + var s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) { + Fe(i), s = Pe(i, a); + } + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + var _t7 = Gt(i.output, i.next_out), + _e17 = i.next_out - _t7, + _r4 = jt(i.output, _t7); + + i.next_out = _e17, i.avail_out = n - _e17, _e17 && i.output.set(i.output.subarray(_t7, _t7 + _e17), 0), this.onData(_r4); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + var si = he.deflate, + hi = ni.Inflate, + li = ni.inflate; + var fi = si, + ci = hi, + ui = li; + var wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (var _t8 = 0; _t8 < 256; _t8++) { + var _e18 = _t8; + + for (var _t9 = 0; _t9 < 8; _t9++) { + 1 & _e18 ? _e18 = 3988292384 ^ _e18 >>> 1 : _e18 >>>= 1; + } + + pi[_t8] = _e18; + } + + var gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + var n = 4294967295; + + for (var _t10 = 0; _t10 < i; _t10++) { + n = pi[255 & (n ^ e[_t10])] ^ n >>> 8; + } + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + var Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + var Ui = function (_r5) { + _inherits(Ui, _r5); + + var _super = _createSuper(Ui); + + function Ui(t) { + var _this; + + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Ui); + + _this = _super.call(this, t); + var _e$checkCrc = e.checkCrc, + i = _e$checkCrc === void 0 ? !1 : _e$checkCrc; + _this._checkCrc = i, _this._inflator = new ci(), _this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, _this._end = !1, _this._hasPalette = !1, _this._palette = [], _this._compressionMethod = ki.UNKNOWN, _this._filterMethod = yi.UNKNOWN, _this._interlaceMethod = vi.UNKNOWN, _this._colorType = -1, _this.setBigEndian(); + return _this; + } + + _createClass(Ui, [{ + key: "decode", + value: function decode() { + for (this.decodeSignature(); !this._end;) { + this.decodeChunk(); + } + + return this.decodeImage(), this._png; + } + }, { + key: "decodeSignature", + value: function decodeSignature() { + for (var _t11 = 0; _t11 < wi.length; _t11++) { + if (this.readUint8() !== wi[_t11]) throw new Error("wrong PNG signature. Byte at ".concat(_t11, " should be ").concat(wi[_t11], ".")); + } + } + }, { + key: "decodeChunk", + value: function decodeChunk() { + var t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + var _i10 = this.readUint32(), + _n6 = t + 4, + _r6 = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - _n6 - 4, _n6), _n6); + + if (_r6 !== _i10) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(_i10, ", found ").concat(_r6)); + } else this.skip(4); + } + }, { + key: "decodeIHDR", + value: function decodeIHDR() { + var t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + var e = this.readUint8(); + var i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + }, { + key: "decodePLTE", + value: function decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + var e = t / 3; + this._hasPalette = !0; + var i = []; + this._palette = i; + + for (var _t12 = 0; _t12 < e; _t12++) { + i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + } + }, { + key: "decodeIDAT", + value: function decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + }, { + key: "decodetRNS", + value: function decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + var _e19 = 0; + + for (; _e19 < t; _e19++) { + var _t13 = this.readByte(); + + this._palette[_e19].push(_t13); + } + + for (; _e19 < this._palette.length; _e19++) { + this._palette[_e19].push(255); + } + } + } + }, { + key: "decodeiCCP", + value: function decodeiCCP(t) { + var e, + i = ""; + + for (; "\0" !== (e = this.readChar());) { + i += e; + } + + var n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + var r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + }, { + key: "decodetEXt", + value: function decodetEXt(t) { + var e, + i = ""; + + for (; "\0" !== (e = this.readChar());) { + i += e; + } + + this._png.text[i] = this.readChars(t - i.length - 1); + } + }, { + key: "decodepHYs", + value: function decodepHYs() { + var t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + }, { + key: "decodeImage", + value: function decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + var t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + }, { + key: "decodeInterlaceNull", + value: function decodeInterlaceNull(t) { + var e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + var s, + a, + o = Ei, + h = 0; + + for (var _l = 0; _l < e; _l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(_l * n, (_l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + var _t14 = new Uint16Array(r.buffer); + + if (xi) for (var _e20 = 0; _e20 < _t14.length; _e20++) { + _t14[_e20] = (255 & (l = _t14[_e20])) << 8 | l >> 8 & 255; + } + this._png.data = _t14; + } else this._png.data = r; + + var l; + } + }]); + + return Ui; + }(r); + + function zi(t, e, i) { + for (var _n7 = 0; _n7 < i; _n7++) { + e[_n7] = t[_n7]; + } + } + + function Ri(t, e, i, n) { + var r = 0; + + for (; r < n; r++) { + e[r] = t[r]; + } + + for (; r < i; r++) { + e[r] = t[r] + e[r - n] & 255; + } + } + + function Ni(t, e, i, n) { + var r = 0; + if (0 === i.length) for (; r < n; r++) { + e[r] = t[r]; + } else for (; r < n; r++) { + e[r] = t[r] + i[r] & 255; + } + } + + function Ti(t, e, i, n, r) { + var s = 0; + + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; + } + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] >> 1) & 255; + } + } else { + for (; s < r; s++) { + e[s] = t[s] + (i[s] >> 1) & 255; + } + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + } + + function Oi(t, e, i, n, r) { + var s = 0; + + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; + } + + for (; s < n; s++) { + e[s] = t[s] + e[s - r] & 255; + } + } else { + for (; s < r; s++) { + e[s] = t[s] + i[s] & 255; + } + + for (; s < n; s++) { + e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + } + + function Li(t, e, i) { + var n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + var Bi = { + level: 3 + }; + + var Ci = function (_r7) { + _inherits(Ci, _r7); + + var _super2 = _createSuper(Ci); + + function Ci(t) { + var _this2; + + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Ci); + + _this2 = _super2.call(this), _this2._colorType = mi.UNKNOWN, _this2._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), _this2._png = _this2._checkData(t), _this2.setBigEndian(); + return _this2; + } + + _createClass(Ci, [{ + key: "encode", + value: function encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + }, { + key: "encodeSignature", + value: function encodeSignature() { + this.writeBytes(wi); + } + }, { + key: "encodeIHDR", + value: function encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + }, { + key: "encodeIEND", + value: function encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + }, { + key: "encodeIDAT", + value: function encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + }, { + key: "encodeData", + value: function encodeData() { + var _this$_png = this._png, + t = _this$_png.width, + e = _this$_png.height, + i = _this$_png.channels, + n = _this$_png.depth, + s = _this$_png.data, + a = i * t, + o = new r().setBigEndian(); + var h = 0; + + for (var _t15 = 0; _t15 < e; _t15++) { + if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + } + + var l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + }, { + key: "_checkData", + value: function _checkData(t) { + var _ref = function (t) { + var _t$channels = t.channels, + e = _t$channels === void 0 ? 4 : _t$channels, + _t$depth = t.depth, + i = _t$depth === void 0 ? 8 : _t$depth; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + var n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + e = _ref.colorType, + i = _ref.channels, + n = _ref.depth, + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + var s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + }, { + key: "writeCrc", + value: function writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + }]); + + return Ci; + }(r); + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (var _r8 = 0; _r8 < i; _r8++) { + e.writeByte(t[n++]); + } + + return n; + } + + function Si(t, e, i, n) { + for (var _r9 = 0; _r9 < i; _r9++) { + e.writeUint16(t[n++]); + } + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + var Fi = function Fi(t, e, i) { + return new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(); + }, + Mi = function Mi(t) { + return function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + }; + })(); + + var r = n.P, + s = n.m; + + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } + + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + var s = stringify(o.data, gap, indentation); + + if (__includes(s, '\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === _typeof(o)) { + var isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + var _s = '\n'; + + for (var k in o) { + if (Object.hasOwnProperty.call(o, k)) { + _s += __repeatConcat(gap, indentation + 1); + + if (isArray) { + _s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (__includes(k, ': ')) { + _s += stringify(k, gap, indentation + 1); + _s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + _s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + _s += '\n'; + } + } + + return _s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } + + function preStringify(object) { + var space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = __repeatConcat(' ', Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); + } + + var LineGenerator = function () { + function LineGenerator(lines, indentString, startingLine) { + _classCallCheck(this, LineGenerator); + + this.startingLine = startingLine || 0; + this.lineIndex = -1; + var filteredLines = []; + + for (var i = 0; i < lines.length; i++) { + var trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + _createClass(LineGenerator, [{ + key: "getLineNumber", + value: function getLineNumber() { + return this.startingLine + this.lineIndex; + } + }, { + key: "nextGroup", + value: function nextGroup() { + var lines = []; + var baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + }, { + key: "next", + value: function next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + }, { + key: "peek", + value: function peek() { + return this.getLine(this.lineIndex + 1); + } + }, { + key: "finished", + value: function finished() { + return this.lineIndex == this.lines.length - 1; + } + }, { + key: "getLine", + value: function getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + }, { + key: "findIndentString", + value: function findIndentString() { + for (var _i2 = 0, _this$lines2 = this.lines; _i2 < _this$lines2.length; _i2++) { + var _this$lines2$_i = _this$lines2[_i2], + line = _this$lines2$_i[0]; + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + }, { + key: "indentLevel", + value: function indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + var indentLevel = 0; + var line = this.getLine(index); + + while (__startsWithString(line, this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + }]); + + return LineGenerator; + }(); + + function getObject(lineGroup, type) { + var object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + var line = lineGroup.next(); + var trimmedLine = line.trim(); + var keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + var typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + + var key = void 0, + value = void 0, + _type = void 0; + + if (__startsWithString(trimmedLine, '"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + _type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (__startsWithString(trimmedLine, '-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, _type); + } else { + value = getObject(lineGroup.nextGroup(), _type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; + } + + function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; + } + + function parse(str) { + var lines = str.replace(/\t/g, ' ').split('\n'); + var lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } + + function deepCopy(obj) { + var newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (var _i2 = 0; _i2 < obj.length; _i2++) { + var item = obj[_i2]; + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && _typeof(obj) === "object") { + newObj = {}; + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; + } + + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } + } + + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } + } + + function convertJsonContentsToXnbNode(raw, readers) { + var extractedImages = []; + var extractedMaps = []; + + var _recursiveConvert = function recursiveConvert(obj, path) { + var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (__startsWithString(reader, 'Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + var data; + if (Array.isArray(obj)) data = [];else data = {}; + var traversed = index; + var first = true; + var isComplex = !__startsWithString(reader, "Dictionary") && !__startsWithString(reader, "Array") && !__startsWithString(reader, "List"); + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i]; + obj[key]; + var newIndex = void 0; + if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; + + var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted = _recursiveConvert2.converted, + nexter = _recursiveConvert2.traversed; + + data[key] = _converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data: data + }, + traversed: traversed + }; + }(raw, []), + converted = _recursiveConvert.converted; + + return { + converted: converted, + extractedImages: extractedImages, + extractedMaps: extractedMaps + }; + } + + function convertJsonContentsFromXnbNode(obj) { + if (!obj || _typeof(obj) !== "object") return obj; + + if (_typeof(obj) === "object" && obj.hasOwnProperty("data")) { + var _obj = obj, + type = _obj.type, + data = _obj.data; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + var newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (var _i4 = 0, _obj3 = obj; _i4 < _obj3.length; _i4++) { + var item = _obj3[_i4]; + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && _typeof(obj) === "object") { + newObj = {}; + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; + } + + function toXnbNodeData(json) { + var toYamlJson = {}; + var _json$header = json.header, + compressed = _json$header.compressed; + _json$header.formatVersion; + var hiDef = _json$header.hidef, + target = _json$header.target; + var readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target: target, + compressed: !!compressed, + hiDef: hiDef, + readerData: readerData, + numSharedResources: 0 + }; + var rawContent = deepCopy(json.content); + var mainReader = TypeReader.simplifyType(readerData[0].type); + var readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + var _convertJsonContentsT = convertJsonContentsToXnbNode(rawContent, readersTypeList), + converted = _convertJsonContentsT.converted, + extractedImages = _convertJsonContentsT.extractedImages, + extractedMaps = _convertJsonContentsT.extractedMaps; + + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } + + function fromXnbNodeData(json) { + var result = {}; + var _json$xnbData = json.xnbData, + compressed = _json$xnbData.compressed, + readerData = _json$xnbData.readerData, + hidef = _json$xnbData.hiDef, + target = _json$xnbData.target; + result.header = { + target: target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef: hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; + } + + function searchElement(parent, element) { + if (!parent || _typeof(parent) != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent: parent, + value: parent[element] + }; + } + + var __keys = Object.keys(parent); + + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + child = parent[__key]; + + if (!!child || _typeof(child) == 'object') { + var found = searchElement(child, element); + if (found) return found; + } + } + + return null; + } + + function extractFileName(fullname) { + var matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } + + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; + } + + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; + } + + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } + + function exportContent(content) { + var jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var found = searchElement(content, "export"); + + if (found) { + var value = found.value; + var dataType = value.type, + data = value.data; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + var contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + + function exportFiles(xnbObject) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$yaml = _ref.yaml, + isYaml = _ref$yaml === void 0 ? false : _ref$yaml, + _ref$contentOnly = _ref.contentOnly, + contentOnly = _ref$contentOnly === void 0 ? false : _ref$contentOnly, + _ref$fileName = _ref.fileName, + fileName = _ref$fileName === void 0 ? null : _ref$fileName; + + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + var blobs = []; + var content = xnbObject.content; + var contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + var resultJSON = JSON.stringify(xnbObject, function (key, value) { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + var result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } + + function resolveCompression(compressionString) { + var str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } + + function readBlobasText(_x) { + return _readBlobasText.apply(this, arguments); + } + + function _readBlobasText() { + _readBlobasText = _asyncToGenerator(regeneratorRuntime.mark(function _callee(blob) { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context.next = 4; + break; + } + + return _context.abrupt("return", blob.text()); + + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context.next = 6; + break; + } + + return _context.abrupt("return", blob.toString()); + + case 6: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _readBlobasText.apply(this, arguments); + } + + function readBlobasArrayBuffer(_x2) { + return _readBlobasArrayBuffer.apply(this, arguments); + } + + function _readBlobasArrayBuffer() { + _readBlobasArrayBuffer = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(blob) { + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context2.next = 4; + break; + } + + return _context2.abrupt("return", blob.arrayBuffer()); + + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context2.next = 6; + break; + } + + return _context2.abrupt("return", blob.buffer); + + case 6: + case "end": + return _context2.stop(); + } + } + }, _callee2); + })); + return _readBlobasArrayBuffer.apply(this, arguments); + } + + function readExternFiles(_x3, _x4) { + return _readExternFiles.apply(this, arguments); + } + + function _readExternFiles() { + _readExternFiles = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(extension, files) { + var rawPng, png, data, _data, _data2; + + return regeneratorRuntime.wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + if (!(extension === "png")) { + _context3.next = 6; + break; + } + + _context3.next = 3; + return readBlobasArrayBuffer(files.png); + + case 3: + rawPng = _context3.sent; + png = r(new Uint8Array(rawPng)); + return _context3.abrupt("return", { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }); + + case 6: + if (!(extension === "cso")) { + _context3.next = 11; + break; + } + + _context3.next = 9; + return readBlobasArrayBuffer(files.cso); + + case 9: + data = _context3.sent; + return _context3.abrupt("return", { + type: "Effect", + data: data + }); + + case 11: + if (!(extension === "tbin")) { + _context3.next = 16; + break; + } + + _context3.next = 14; + return readBlobasArrayBuffer(files.tbin); + + case 14: + _data = _context3.sent; + return _context3.abrupt("return", { + type: "TBin", + data: _data + }); + + case 16: + if (!(extension === "xml")) { + _context3.next = 21; + break; + } + + _context3.next = 19; + return readBlobasText(files.xml); + + case 19: + _data2 = _context3.sent; + return _context3.abrupt("return", { + type: "BmFont", + data: _data2 + }); + + case 21: + case "end": + return _context3.stop(); + } + } + }, _callee3); + })); + return _readExternFiles.apply(this, arguments); + } + + function resolveImports(_x5) { + return _resolveImports.apply(this, arguments); + } + + function _resolveImports() { + _resolveImports = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(files) { + var configs, + _configs$compression, + compression, + jsonFile, + rawText, + jsonData, + compressBits, + found, + parent, + value, + _extractFileName, + extension, + _args4 = arguments; + + return regeneratorRuntime.wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + configs = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}; + _configs$compression = configs.compression, compression = _configs$compression === void 0 ? "default" : _configs$compression; + jsonFile = files.json || files.yaml; + + if (jsonFile) { + _context4.next = 5; + break; + } + + throw new XnbError("There is no JSON or YAML file to pack!"); + + case 5: + _context4.next = 7; + return readBlobasText(jsonFile); + + case 7: + rawText = _context4.sent; + jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (jsonData.hasOwnProperty('content')) { + _context4.next = 14; + break; + } + + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + + case 14: + found = searchElement(jsonData.content, "export"); + + if (!found) { + _context4.next = 21; + break; + } + + parent = found.parent, value = found.value; + _extractFileName = extractFileName(value), extension = _extractFileName[1]; + _context4.next = 20; + return readExternFiles(extension, files); + + case 20: + parent.export = _context4.sent; + + case 21: + return _context4.abrupt("return", jsonData); + + case 22: + case "end": + return _context4.stop(); + } + } + }, _callee4); + })); + return _resolveImports.apply(this, arguments); + } + + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + + function unpackToXnbData(_x) { + return _unpackToXnbData.apply(this, arguments); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + + function _unpackToXnbData() { + _unpackToXnbData = _asyncToGenerator(regeneratorRuntime.mark(function _callee(file) { + var _extractFileName3, extension, buffer; + + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof window !== "undefined")) { + _context.next = 8; + break; + } + + _extractFileName3 = extractFileName(file.name), extension = _extractFileName3[1]; + + if (!(extension !== "xnb")) { + _context.next = 4; + break; + } + + return _context.abrupt("return", new Error("Invalid XNB File!")); + + case 4: + _context.next = 6; + return file.arrayBuffer(); + + case 6: + buffer = _context.sent; + return _context.abrupt("return", bufferToXnb(buffer)); + + case 8: + return _context.abrupt("return", bufferToXnb(file.buffer)); + + case 9: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _unpackToXnbData.apply(this, arguments); + } + + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + + function unpackToFiles(file) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var _configs$yaml = configs.yaml, + yaml = _configs$yaml === void 0 ? false : _configs$yaml, + _configs$contentOnly = configs.contentOnly, + contentOnly = _configs$contentOnly === void 0 ? false : _configs$contentOnly, + _configs$fileName = configs.fileName, + name = _configs$fileName === void 0 ? null : _configs$fileName; + if (typeof window !== "undefined" && name === null) name = file.name; + + var _extractFileName = extractFileName(name), + fileName = _extractFileName[0]; + + var exporter = function exporter(xnbObject) { + return exportFiles(xnbObject, { + yaml: yaml, + contentOnly: contentOnly, + fileName: fileName + }); + }; + + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + + function bufferToXnb(buffer) { + var xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + + function bufferToContents(buffer) { + var xnb = new XnbConverter(); + var xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + + function xnbDataToContent(loadedXnb) { + var content = loadedXnb.content; + + var _exportContent = exportContent(content, true), + data = _exportContent.data, + extension = _exportContent.extension; + + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + + function fileMapper(files) { + var returnMap = {}; + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + + var _extractFileName2 = extractFileName(file.name), + fileName = _extractFileName2[0], + extension = _extractFileName2[1]; + + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + var namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + + function packJsonToBinary(json) { + var xnb = new XnbConverter(); + var buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + + function pack(files) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var groupedFiles = fileMapper(files); + var promises = []; + + var __keys = Object.keys(groupedFiles); + + for (var __i = 0; __i < __keys.length; __i++) { + var fileName = __keys[__i], + filePack = groupedFiles[fileName]; + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(function (buffer) { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(function (blobArray) { + if (configs.debug === true) return blobArray; + return blobArray.filter(function (_ref) { + var status = _ref.status; + _ref.value; + return status === "fulfilled"; + }).map(function (_ref2) { + var value = _ref2.value; + return value; + }); + }); + } + + function setReaders(readers) { + return TypeReader.setReaders(readers); + } + + function addReaders(readers) { + return TypeReader.addReaders(readers); + } + + exports.XnbContent = XnbContent; + exports.XnbData = XnbData; + exports.addReaders = addReaders; + exports.bufferToContents = bufferToContents; + exports.bufferToXnb = bufferToXnb; + exports.pack = pack; + exports.setReaders = setReaders; + exports.unpackToContent = unpackToContent; + exports.unpackToFiles = unpackToFiles; + exports.unpackToXnbData = unpackToXnbData; + exports.xnbDataToContent = xnbDataToContent; + exports.xnbDataToFiles = exportFiles; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/dist/core/core.es5.min.js b/dist/core/core.es5.min.js new file mode 100644 index 0000000..3fe78b2 --- /dev/null +++ b/dist/core/core.es5.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},z=I,j=P,D=function(t){return z(j(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},zt=x,jt=0,Dt=Math.random(),Ct=zt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++jt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,ze=r.TypeError,je=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return je(t,e,n)}:je:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return je(t,e,n)}catch(t){}if("get"in n||"set"in n)throw ze("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,zn=$e.CONFIGURABLE,jn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||zn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||jn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==zr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",zr=Br.POLYFILL="P",jr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,zo=C,jo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=za.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!jo(t)||!zo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!zo(t)||t,r.fail=zo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},zo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,zs=Te,js=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;zs(t);try{if(!(r=js(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return zs(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error)),eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"setReaders",value:function(e){t.readers=Qs({},e)}},{key:"addReaders",value:function(e){t.readers=Qs(Qs({},t.readers),e)}},{key:"makeSimplied",value:function(e,n){var r=e.split(/`|,/)[0];if(n.isTypeOf(r)){if(n.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n.type(),"<").concat(i.join(","),">")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(simplifyType);return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(t.readers.hasOwnProperty("".concat(r,"Reader")))return t.readers["".concat(r,"Reader")].parseTypeList(i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(eh,"readers",{});var nh=[192,224,240],rh=128,ih=63,ah=[55296,56320],oh=1023;function sh(t){return t<128?[t]:t<2048?[nh[0]|t>>6,rh|t&ih]:t<65536?[nh[1]|t>>12,rh|t>>6&ih,rh|t&ih]:[nh[2]|t>>18,rh|t>>12&ih,rh|t>>6&ih,rh|t&ih]}function uh(t){return t<65535?[t]:[ah[0]|(t-=65536)>>10&oh,ah[1]|t&oh]}function hh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^nh[0])<<6)+(t[1]^rh):3===n?((t[0]^nh[1])<<12)+((t[1]^rh)<<6)+(t[2]^rh):((t[0]^nh[2])<<18)+((t[1]^rh)<<12)+((t[2]^rh)<<6)+(t[3]^rh)}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&oh)<<10)+(t[1]&oh)+65536}function ch(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),ph=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),vh=256,_h=0,yh=1,wh=2,gh=3,bh=656,mh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case wh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case yh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(bh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case gh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case wh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(h>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case yh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(_>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case gh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();mh.position_base=[],mh.extra_bits=[];var kh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new mh(16),s=new ph(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Eh=65536,Oh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||xh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Oh){for(e[f++]=240+_,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Oh){for(e[f++]=240,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Fh={};function Zh(t){var e=Fh[t];if(void 0!==e)return e.exports;var n=Fh[t]={exports:{}};return Ch[t].call(n.exports,n,n.exports,Zh),n.exports}Zh.d=function(t,e){for(var n in e)Zh.o(e,n)&&!Zh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Zh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Mh={};!function(){Zh.d(Mh,{P:function(){return Un},m:function(){return An}}),Zh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=z,G=j,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},jt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=zt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=jt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},ze=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=ze(a,r))===He&&s&&((n=De(a,s))===Ve?n=ze(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=ze(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=je(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Hh(t,n,-1)}var Gh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Yh(s,u):Kh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Yh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Jh(t){var e=t.replace(/\t/g,"\t").split("\n");return Kh(new Gh(e))}function $h(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Qh(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,f=!0,c=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function nf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=$h(i),e.content=tf(t.content),"SpriteFont"===eh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function rf(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=rf(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Xh(r.width,r.height,new Uint8Array(a))),uf(a,i)}if(e){var o=JSON.stringify(t,null,4);return uf(o,"JSON")}return null}function ff(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=hf(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(of(e.type)):"".concat(e.type,".").concat(of(e.type)):e}),4),l=c;return r&&(l=Wh(ef(t))),u.unshift(uf(l,r?"yaml":"JSON")),u}function cf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function lf(t){return df.apply(this,arguments)}function df(){return(df=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pf(t){return vf.apply(this,arguments)}function vf(){return(vf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _f(t,e){return yf.apply(this,arguments)}function yf(){return yf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,pf(n.png);case 3:return r=t.sent,i=Vh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,pf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,pf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,lf(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),yf.apply(this,arguments)}function wf(t){return gf.apply(this,arguments)}function gf(){return gf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,lf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):nf(Jh(o)),null!==(u=cf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=rf(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=af(c),d=l[1],t.next=20,_f(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),gf.apply(this,arguments)}function bf(t){return mf.apply(this,arguments)}function mf(){return(mf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=af(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",kf(r));case 8:return t.abrupt("return",kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kf(t){return(new Dh).load(t)}function xf(t){var e=hf(t.content,!0),n=e.data,r=e.extension;return new Nh(n,r)}function Ef(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Ef(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=af(s),h=u[0],f=function(t){return ff(t,{yaml:r,contentOnly:a,fileName:h})};return bf(t).then(f)},t.unpackToXnbData=bf,t.xnbDataToContent=xf,t.xnbDataToFiles=ff,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.js b/dist/core/core.js new file mode 100644 index 0000000..7f5a5b2 --- /dev/null +++ b/dist/core/core.js @@ -0,0 +1,5362 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + + } + + class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + + } + + _defineProperty(TypeReader, "readers", {}); + + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; + const UTF8_SECOND_BITES = 0x80; + const UTF8_MASK = 0b111111; + const UTF16_BITES$1 = [0xD800, 0xDC00]; + const UTF16_MASK$1 = 0b1111111111; + + function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + } + + function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; + } + + function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); + } + + function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + } + + function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; + } + + function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; + } + + function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; + } + + function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); + } + + function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); + } + + const LITTLE_ENDIAN = true; + + class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + + } + + class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + + } + + /** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ + const MIN_MATCH = 2; + const NUM_CHARS = 256; + const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 + }; + const PRETREE_NUM_ELEMENTS = 20; + const ALIGNED_NUM_ELEMENTS = 8; + const NUM_PRIMARY_LENGTHS = 7; + const NUM_SECONDARY_LENGTHS = 249; + const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; + const PRETREE_TABLEBITS = 6; + const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; + const MAINTREE_TABLEBITS = 12; + const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; + const LENGTH_TABLEBITS = 12; + const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; + const ALIGNED_TABLEBITS = 7; + + class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + + } + + Lzx.position_base = []; + Lzx.extra_bits = []; + + class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + + } + + class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + + } + + /** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ + const minMatch = 4; + const minLength = 13; + const searchLimit = 5; + const skipTrigger = 6; + const hashSize = 1 << 16; + const mlBits = 4; + const mlMask = (1 << mlBits) - 1; + const runBits = 4; + const runMask = (1 << runBits) - 1; + makeBuffer(5 << 20); + const hashTable = makeHashTable(); + + function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } + } + + function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + } + + function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } + } + + function compressBound(n) { + return n + n / 255 + 16 | 0; + } + + function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; + } + + function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; + } + + function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); + } + + const UTF16_BITES = [0xD800, 0xDC00]; + const UTF16_MASK = 0b1111111111; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + } + + class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + + } + + class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + + } + + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; + } + + class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + + } + + const HIDEF_MASK = 0x1; + const COMPRESSED_LZ4_MASK = 0x40; + const COMPRESSED_LZX_MASK = 0x80; + const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + + class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + + } + + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } + }, + e = {}; + + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; + } + + i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + var n = {}; + + (() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + })(); + + var r = n.P, + s = n.m; + + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } + + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } + + function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); + } + + class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + + } + + function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; + } + + function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; + } + + function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } + + function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; + } + + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } + } + + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } + } + + function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; + } + + function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; + } + + function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } + + function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; + } + + function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; + } + + function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } + + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; + } + + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; + } + + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } + + function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + + function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } + + function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } + + async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); + } + + async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; + } + + async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } + } + + async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; + } + + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + + async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + + function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + + function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + + function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + + function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + + function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + + function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + + function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); + } + + function setReaders(readers) { + return TypeReader.setReaders(readers); + } + + function addReaders(readers) { + return TypeReader.addReaders(readers); + } + + exports.XnbContent = XnbContent; + exports.XnbData = XnbData; + exports.addReaders = addReaders; + exports.bufferToContents = bufferToContents; + exports.bufferToXnb = bufferToXnb; + exports.pack = pack; + exports.setReaders = setReaders; + exports.unpackToContent = unpackToContent; + exports.unpackToFiles = unpackToFiles; + exports.unpackToXnbData = unpackToXnbData; + exports.xnbDataToContent = xnbDataToContent; + exports.xnbDataToFiles = exportFiles; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/dist/core/core.min.js b/dist/core/core.min.js new file mode 100644 index 0000000..48dc783 --- /dev/null +++ b/dist/core/core.min.js @@ -0,0 +1,41 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=n({},t)}static addReaders(t){a.readers=n(n({},a.readers),t)}static makeSimplied(t,e){let i=t.split(/`|,/)[0];if(e.isTypeOf(i)){if(e.hasSubType()){let i=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(i.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(simplifyType);return"".concat(e)}for(let e of Object.values(a.readers)){let i=a.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let i=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return i}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(i=i.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}r(a,"readers",{});const o=[192,224,240],h=128,l=63,d=[55296,56320],f=1023;function c(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function u(t){return t<65535?[t]:[d[0]|(t-=65536)>>10&f,d[1]|t&f]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^o[0])<<6)+(t[1]^h):3===i?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&f)<<10)+(t[1]&f)+65536}function p(t){return function(t){const e=[];for(let i of t)e.push(...c(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class m{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */const y=256,v=0,k=1,x=2,E=3,A=656;class U{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!U.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)U.extra_bits[t]=U.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!U.position_base.length)for(let t=0,e=0;t<=50;t++)U.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(A,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case E:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){let e=U.extra_bits[s];if(s=U.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){if(3!=s){let e=U.extra_bits[s],i=t.readLZXBits(e);s=U.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case E:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}U.position_base=[],U.extra_bits=[];class R{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}} +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */const B=65536,O=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||R.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=O){for(e[d++]=240+p,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=O){for(e[d++]=240,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class z{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=S(e);t.write7BitNumber(i),t.writeString(e)}}class D{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class P{constructor(t,e,i){let{target:n,formatVersion:r,hidef:s,compressed:a}=t;this.header={target:n,formatVersion:r,hidef:s,compressed:a},this.readers=e,this.content=i}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class C{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const Z=64,F=128,V=14;class M{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new g(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==F){const e=this.fileSize-V,i=class{static decompress(t,e,i){let n,r,a=0;const o=new U(16);let h=new m(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,V,0,t),this.buffer.bytePosition=V}else if(this.compressionType==Z){const e=this.buffer.buffer.slice(V),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function X(t){var e=W[t];if(void 0!==e)return e.exports;var i=W[t]={exports:{}};return j[t].call(i.exports,i,i.exports,X),i.exports}X.d=(t,e)=>{for(var i in e)X.o(e,i)&&!X.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},X.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{X.d(H,{P:()=>Ti,m:()=>Li}),X(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),I(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:K,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},It=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=K(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new Lt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Ot),new Lt(4,5,16,8,Ot),new Lt(4,6,32,32,Ot),new Lt(4,4,16,16,It),new Lt(8,16,32,32,It),new Lt(8,16,128,128,It),new Lt(8,32,128,256,It),new Lt(32,128,258,1024,It),new Lt(32,258,258,4096,It)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,I,L,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(I=0,L=a[p]):a[p]>_?(I=T[N+a[p]],L=A[U+a[p]]):(I=96,L=0),l=1<>v)+d]=O<<24|I<<16|L|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Ie=!0;const Le=t=>{if(Ie){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Ie=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Le(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var K=H.P,Y=H.m;function G(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=G(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+G(t[s],e,i+1):s.includes(": ")?(r+=G(s,e,i+1),r+=": "+G(t[s],e,i+1)):r+=s+": "+G(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),G(t,i,-1)}class ${constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new $(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?Q(n,r):q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return q(new $(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(et(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=et(n);return e}return t}function it(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function nt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function rt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(it(e))return et(i);if(nt(e))return i=et(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;t=et(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(rt(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=rt(n);return e}return null}function st(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let d=a.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(it(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:r}}},traversed:a+1};if(nt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function at(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=et(n),e.content=rt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ot(i,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function dt(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ft(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:dt(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ct(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ot(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=Y(t.width,t.height,new Uint8Array(n))),ft(n,e)}if(e){return ft(JSON.stringify(t,null,4),"JSON")}return null}function ut(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ct(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),r.unshift(ft(l,e?"yaml":"JSON")),r}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function bt(t,e){if("png"===t){const t=await pt(e.png),i=K(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function gt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await wt(n);let a=null;a=t.json?JSON.parse(r):at(tt(r));let o=_t(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=ht(i);e.export=await bt(n,t)}return a}async function mt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return yt(await t.arrayBuffer())}return yt(t.buffer)}function yt(t){return(new M).load(t)}function vt(t){const{content:e}=t,{data:i,extension:n}=ct(e,!0);return new C(i,n)}function kt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=kt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(gt(e,i).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return a.setReaders(t)},t.unpackToContent=function(t){return mt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=ht(r);const a=t=>ut(t,{yaml:i,contentOnly:n,fileName:s});return mt(t).then(a)},t.unpackToXnbData=mt,t.xnbDataToContent=vt,t.xnbDataToFiles=ut,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.module.js b/dist/core/core.module.js new file mode 100644 index 0000000..c0bd5a0 --- /dev/null +++ b/dist/core/core.module.js @@ -0,0 +1,5341 @@ +const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); +}; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + +const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES = 0x80; +const UTF8_MASK = 0b111111; +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; + +function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; +} + +function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; +} + +function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); +} + +function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; +} + +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; +} + +function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; +} + +function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; +} + +function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); +} + +function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); +} + +const LITTLE_ENDIAN = true; + +class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + +} + +class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + +} + +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ +const MIN_MATCH = 2; +const NUM_CHARS = 256; +const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 +}; +const PRETREE_NUM_ELEMENTS = 20; +const ALIGNED_NUM_ELEMENTS = 8; +const NUM_PRIMARY_LENGTHS = 7; +const NUM_SECONDARY_LENGTHS = 249; +const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; +const PRETREE_TABLEBITS = 6; +const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; +const MAINTREE_TABLEBITS = 12; +const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; +const LENGTH_TABLEBITS = 12; +const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; +const ALIGNED_TABLEBITS = 7; + +class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + +} + +Lzx.position_base = []; +Lzx.extra_bits = []; + +class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + +} + +class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + +} + +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ +const minMatch = 4; +const minLength = 13; +const searchLimit = 5; +const skipTrigger = 6; +const hashSize = 1 << 16; +const mlBits = 4; +const mlMask = (1 << mlBits) - 1; +const runBits = 4; +const runMask = (1 << runBits) - 1; +makeBuffer(5 << 20); +const hashTable = makeHashTable(); + +function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } +} + +function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } +} + +function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } +} + +function compressBound(n) { + return n + n / 255 + 16 | 0; +} + +function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; +} + +function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; +} + +function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + +} + +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + +} + +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + +} + +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; +} + +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + +} + +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + +} + +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } +}, + e = {}; + +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; +} + +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; + +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); + +var r = n.P, + s = n.m; + +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} + +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} + +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); +} + +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + +} + +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; +} + +function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; +} + +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} + +function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; +} + +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } +} + +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } +} + +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; +} + +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} + +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; +} + +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; +} + +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} + +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; +} + +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; +} + +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} + +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} + +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} + +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} + +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} + +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} + +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; +} + +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + +function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} + +function setReaders(readers) { + return TypeReader.setReaders(readers); +} + +function addReaders(readers) { + return TypeReader.addReaders(readers); +} + +export { XnbContent, XnbData, addReaders, bufferToContents, bufferToXnb, pack, setReaders, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; diff --git a/dist/readers/readers.cjs b/dist/readers/readers.cjs new file mode 100644 index 0000000..3b2428a --- /dev/null +++ b/dist/readers/readers.cjs @@ -0,0 +1,2694 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +class BaseReader { + static isTypeOf(type) { + return false; + } + + static hasSubType() { + return false; + } + + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + +} + +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + +} + +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + +} + +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + +} + +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + +} + +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + +} + +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + +} + +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + +} + +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + +} + +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + +} + +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const hasValue = booleanReader.read(buffer); + return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + } + + write(buffer, content, resolver) { + buffer.writeByte(content != null); + if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + +} + +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + +} + +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + +} + +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + +} + +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} + +function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} + +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; +} + +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; +} + +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; +} + +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; +} + +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); +} + +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} + +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + +} + +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + +} + +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} + +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} + +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} + +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} + +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } +} + +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + +} + +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + +} + +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} + +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; +} + +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; +} + +function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; +} + +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; +} + +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; +} + +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } +} + +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } +} + +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } +} + +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } +} + +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} + +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} + +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} + +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; +} + +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} + +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} + +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} + +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); +} + +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} + +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } +} + +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; + +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; +} + +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; +} + +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + +} + +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + +} + +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + +} + +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + +} + +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + +} + +exports.ArrayReader = ArrayReader; +exports.BaseReader = BaseReader; +exports.BmFontReader = BmFontReader; +exports.BooleanReader = BooleanReader; +exports.CharReader = CharReader; +exports.DictionaryReader = DictionaryReader; +exports.DoubleReader = DoubleReader; +exports.EffectReader = EffectReader; +exports.Int32Reader = Int32Reader; +exports.LightweightTexture2DReader = LightweightTexture2DReader; +exports.ListReader = ListReader; +exports.NullableReader = NullableReader; +exports.RectangleReader = RectangleReader; +exports.ReflectiveReader = ReflectiveReader; +exports.SingleReader = SingleReader; +exports.SpriteFontReader = SpriteFontReader; +exports.StringReader = StringReader; +exports.TBinReader = TBinReader; +exports.Texture2DReader = Texture2DReader; +exports.UInt32Reader = UInt32Reader; +exports.Vector2Reader = Vector2Reader; +exports.Vector3Reader = Vector3Reader; +exports.Vector4Reader = Vector4Reader; diff --git a/dist/readers/readers.es5.js b/dist/readers/readers.es5.js new file mode 100644 index 0000000..a6cf2e6 --- /dev/null +++ b/dist/readers/readers.es5.js @@ -0,0 +1,4709 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + // eslint-disable-next-line es-x/no-typed-arrays -- safe + var arrayBufferNative = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined'; + + var fails$9 = function (exec) { + try { + return !!exec(); + } catch (error) { + return true; + } + }; + + var fails$8 = fails$9; + + // Detect IE8's incomplete defineProperty implementation + var descriptors = !fails$8(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7; + }); + + var check = function (it) { + return it && it.Math == Math && it; + }; + + // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + var global$q = + // eslint-disable-next-line es-x/no-global-this -- safe + check(typeof globalThis == 'object' && globalThis) || + check(typeof window == 'object' && window) || + // eslint-disable-next-line no-restricted-globals -- safe + check(typeof self == 'object' && self) || + check(typeof commonjsGlobal == 'object' && commonjsGlobal) || + // eslint-disable-next-line no-new-func -- fallback + (function () { return this; })() || Function('return this')(); + + // `IsCallable` abstract operation + // https://tc39.es/ecma262/#sec-iscallable + var isCallable$e = function (argument) { + return typeof argument == 'function'; + }; + + var isCallable$d = isCallable$e; + + var isObject$7 = function (it) { + return typeof it == 'object' ? it !== null : isCallable$d(it); + }; + + var fails$7 = fails$9; + + var functionBindNative = !fails$7(function () { + // eslint-disable-next-line es-x/no-function-prototype-bind -- safe + var test = (function () { /* empty */ }).bind(); + // eslint-disable-next-line no-prototype-builtins -- safe + return typeof test != 'function' || test.hasOwnProperty('prototype'); + }); + + var NATIVE_BIND$2 = functionBindNative; + + var FunctionPrototype$2 = Function.prototype; + var bind$2 = FunctionPrototype$2.bind; + var call$3 = FunctionPrototype$2.call; + var uncurryThis$c = NATIVE_BIND$2 && bind$2.bind(call$3, call$3); + + var functionUncurryThis = NATIVE_BIND$2 ? function (fn) { + return fn && uncurryThis$c(fn); + } : function (fn) { + return fn && function () { + return call$3.apply(fn, arguments); + }; + }; + + var global$p = global$q; + + var TypeError$a = global$p.TypeError; + + // `RequireObjectCoercible` abstract operation + // https://tc39.es/ecma262/#sec-requireobjectcoercible + var requireObjectCoercible$1 = function (it) { + if (it == undefined) throw TypeError$a("Can't call method on " + it); + return it; + }; + + var global$o = global$q; + var requireObjectCoercible = requireObjectCoercible$1; + + var Object$5 = global$o.Object; + + // `ToObject` abstract operation + // https://tc39.es/ecma262/#sec-toobject + var toObject$3 = function (argument) { + return Object$5(requireObjectCoercible(argument)); + }; + + var uncurryThis$b = functionUncurryThis; + var toObject$2 = toObject$3; + + var hasOwnProperty = uncurryThis$b({}.hasOwnProperty); + + // `HasOwnProperty` abstract operation + // https://tc39.es/ecma262/#sec-hasownproperty + // eslint-disable-next-line es-x/no-object-hasown -- safe + var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) { + return hasOwnProperty(toObject$2(it), key); + }; + + var shared$3 = {exports: {}}; + + var global$n = global$q; + + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var defineProperty$3 = Object.defineProperty; + + var setGlobal$2 = function (key, value) { + try { + defineProperty$3(global$n, key, { value: value, configurable: true, writable: true }); + } catch (error) { + global$n[key] = value; + } return value; + }; + + var global$m = global$q; + var setGlobal$1 = setGlobal$2; + + var SHARED = '__core-js_shared__'; + var store$3 = global$m[SHARED] || setGlobal$1(SHARED, {}); + + var sharedStore = store$3; + + var store$2 = sharedStore; + + (shared$3.exports = function (key, value) { + return store$2[key] || (store$2[key] = value !== undefined ? value : {}); + })('versions', []).push({ + version: '3.22.4', + mode: 'global', + copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)', + license: 'https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE', + source: 'https://github.com/zloirock/core-js' + }); + + var uncurryThis$a = functionUncurryThis; + + var id = 0; + var postfix = Math.random(); + var toString$1 = uncurryThis$a(1.0.toString); + + var uid$3 = function (key) { + return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$1(++id + postfix, 36); + }; + + var global$l = global$q; + var isCallable$c = isCallable$e; + + var aFunction = function (argument) { + return isCallable$c(argument) ? argument : undefined; + }; + + var getBuiltIn$3 = function (namespace, method) { + return arguments.length < 2 ? aFunction(global$l[namespace]) : global$l[namespace] && global$l[namespace][method]; + }; + + var getBuiltIn$2 = getBuiltIn$3; + + var engineUserAgent = getBuiltIn$2('navigator', 'userAgent') || ''; + + var global$k = global$q; + var userAgent = engineUserAgent; + + var process = global$k.process; + var Deno = global$k.Deno; + var versions = process && process.versions || Deno && Deno.version; + var v8 = versions && versions.v8; + var match, version; + + if (v8) { + match = v8.split('.'); + // in old Chrome, versions of V8 isn't V8 = Chrome / 10 + // but their correct versions are not interesting for us + version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); + } + + // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` + // so check `userAgent` even if `.v8` exists, but 0 + if (!version && userAgent) { + match = userAgent.match(/Edge\/(\d+)/); + if (!match || match[1] >= 74) { + match = userAgent.match(/Chrome\/(\d+)/); + if (match) version = +match[1]; + } + } + + var engineV8Version = version; + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var V8_VERSION = engineV8Version; + var fails$6 = fails$9; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- required for testing + var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$6(function () { + var symbol = Symbol(); + // Chrome 38 Symbol has incorrect toString conversion + // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances + return !String(symbol) || !(Object(symbol) instanceof Symbol) || + // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances + !Symbol.sham && V8_VERSION && V8_VERSION < 41; + }); + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var NATIVE_SYMBOL$1 = nativeSymbol; + + var useSymbolAsUid = NATIVE_SYMBOL$1 + && !Symbol.sham + && typeof Symbol.iterator == 'symbol'; + + var global$j = global$q; + var shared$2 = shared$3.exports; + var hasOwn$5 = hasOwnProperty_1; + var uid$2 = uid$3; + var NATIVE_SYMBOL = nativeSymbol; + var USE_SYMBOL_AS_UID$1 = useSymbolAsUid; + + var WellKnownSymbolsStore = shared$2('wks'); + var Symbol$1 = global$j.Symbol; + var symbolFor = Symbol$1 && Symbol$1['for']; + var createWellKnownSymbol = USE_SYMBOL_AS_UID$1 ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$2; + + var wellKnownSymbol$6 = function (name) { + if (!hasOwn$5(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) { + var description = 'Symbol.' + name; + if (NATIVE_SYMBOL && hasOwn$5(Symbol$1, name)) { + WellKnownSymbolsStore[name] = Symbol$1[name]; + } else if (USE_SYMBOL_AS_UID$1 && symbolFor) { + WellKnownSymbolsStore[name] = symbolFor(description); + } else { + WellKnownSymbolsStore[name] = createWellKnownSymbol(description); + } + } return WellKnownSymbolsStore[name]; + }; + + var wellKnownSymbol$5 = wellKnownSymbol$6; + + var TO_STRING_TAG$2 = wellKnownSymbol$5('toStringTag'); + var test = {}; + + test[TO_STRING_TAG$2] = 'z'; + + var toStringTagSupport = String(test) === '[object z]'; + + var uncurryThis$9 = functionUncurryThis; + + var toString = uncurryThis$9({}.toString); + var stringSlice = uncurryThis$9(''.slice); + + var classofRaw$1 = function (it) { + return stringSlice(toString(it), 8, -1); + }; + + var global$i = global$q; + var TO_STRING_TAG_SUPPORT = toStringTagSupport; + var isCallable$b = isCallable$e; + var classofRaw = classofRaw$1; + var wellKnownSymbol$4 = wellKnownSymbol$6; + + var TO_STRING_TAG$1 = wellKnownSymbol$4('toStringTag'); + var Object$4 = global$i.Object; + + // ES3 wrong here + var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments'; + + // fallback for IE11 Script Access Denied error + var tryGet = function (it, key) { + try { + return it[key]; + } catch (error) { /* empty */ } + }; + + // getting tag from ES6+ `Object.prototype.toString` + var classof$4 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (tag = tryGet(O = Object$4(it), TO_STRING_TAG$1)) == 'string' ? tag + // builtinTag case + : CORRECT_ARGUMENTS ? classofRaw(O) + // ES3 arguments fallback + : (result = classofRaw(O)) == 'Object' && isCallable$b(O.callee) ? 'Arguments' : result; + }; + + var global$h = global$q; + + var String$3 = global$h.String; + + var tryToString$3 = function (argument) { + try { + return String$3(argument); + } catch (error) { + return 'Object'; + } + }; + + var objectDefineProperty = {}; + + var global$g = global$q; + var isObject$6 = isObject$7; + + var document = global$g.document; + // typeof document.createElement is 'object' in old IE + var EXISTS$1 = isObject$6(document) && isObject$6(document.createElement); + + var documentCreateElement = function (it) { + return EXISTS$1 ? document.createElement(it) : {}; + }; + + var DESCRIPTORS$6 = descriptors; + var fails$5 = fails$9; + var createElement = documentCreateElement; + + // Thanks to IE8 for its funny defineProperty + var ie8DomDefine = !DESCRIPTORS$6 && !fails$5(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(createElement('div'), 'a', { + get: function () { return 7; } + }).a != 7; + }); + + var DESCRIPTORS$5 = descriptors; + var fails$4 = fails$9; + + // V8 ~ Chrome 36- + // https://bugs.chromium.org/p/v8/issues/detail?id=3334 + var v8PrototypeDefineBug = DESCRIPTORS$5 && fails$4(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(function () { /* empty */ }, 'prototype', { + value: 42, + writable: false + }).prototype != 42; + }); + + var global$f = global$q; + var isObject$5 = isObject$7; + + var String$2 = global$f.String; + var TypeError$9 = global$f.TypeError; + + // `Assert: Type(argument) is Object` + var anObject$3 = function (argument) { + if (isObject$5(argument)) return argument; + throw TypeError$9(String$2(argument) + ' is not an object'); + }; + + var NATIVE_BIND$1 = functionBindNative; + + var call$2 = Function.prototype.call; + + var functionCall = NATIVE_BIND$1 ? call$2.bind(call$2) : function () { + return call$2.apply(call$2, arguments); + }; + + var uncurryThis$8 = functionUncurryThis; + + var objectIsPrototypeOf = uncurryThis$8({}.isPrototypeOf); + + var global$e = global$q; + var getBuiltIn$1 = getBuiltIn$3; + var isCallable$a = isCallable$e; + var isPrototypeOf$1 = objectIsPrototypeOf; + var USE_SYMBOL_AS_UID = useSymbolAsUid; + + var Object$3 = global$e.Object; + + var isSymbol$2 = USE_SYMBOL_AS_UID ? function (it) { + return typeof it == 'symbol'; + } : function (it) { + var $Symbol = getBuiltIn$1('Symbol'); + return isCallable$a($Symbol) && isPrototypeOf$1($Symbol.prototype, Object$3(it)); + }; + + var global$d = global$q; + var isCallable$9 = isCallable$e; + var tryToString$2 = tryToString$3; + + var TypeError$8 = global$d.TypeError; + + // `Assert: IsCallable(argument) is true` + var aCallable$2 = function (argument) { + if (isCallable$9(argument)) return argument; + throw TypeError$8(tryToString$2(argument) + ' is not a function'); + }; + + var aCallable$1 = aCallable$2; + + // `GetMethod` abstract operation + // https://tc39.es/ecma262/#sec-getmethod + var getMethod$1 = function (V, P) { + var func = V[P]; + return func == null ? undefined : aCallable$1(func); + }; + + var global$c = global$q; + var call$1 = functionCall; + var isCallable$8 = isCallable$e; + var isObject$4 = isObject$7; + + var TypeError$7 = global$c.TypeError; + + // `OrdinaryToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-ordinarytoprimitive + var ordinaryToPrimitive$1 = function (input, pref) { + var fn, val; + if (pref === 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = call$1(fn, input))) return val; + if (isCallable$8(fn = input.valueOf) && !isObject$4(val = call$1(fn, input))) return val; + if (pref !== 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = call$1(fn, input))) return val; + throw TypeError$7("Can't convert object to primitive value"); + }; + + var global$b = global$q; + var call = functionCall; + var isObject$3 = isObject$7; + var isSymbol$1 = isSymbol$2; + var getMethod = getMethod$1; + var ordinaryToPrimitive = ordinaryToPrimitive$1; + var wellKnownSymbol$3 = wellKnownSymbol$6; + + var TypeError$6 = global$b.TypeError; + var TO_PRIMITIVE = wellKnownSymbol$3('toPrimitive'); + + // `ToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-toprimitive + var toPrimitive$1 = function (input, pref) { + if (!isObject$3(input) || isSymbol$1(input)) return input; + var exoticToPrim = getMethod(input, TO_PRIMITIVE); + var result; + if (exoticToPrim) { + if (pref === undefined) pref = 'default'; + result = call(exoticToPrim, input, pref); + if (!isObject$3(result) || isSymbol$1(result)) return result; + throw TypeError$6("Can't convert object to primitive value"); + } + if (pref === undefined) pref = 'number'; + return ordinaryToPrimitive(input, pref); + }; + + var toPrimitive = toPrimitive$1; + var isSymbol = isSymbol$2; + + // `ToPropertyKey` abstract operation + // https://tc39.es/ecma262/#sec-topropertykey + var toPropertyKey$1 = function (argument) { + var key = toPrimitive(argument, 'string'); + return isSymbol(key) ? key : key + ''; + }; + + var global$a = global$q; + var DESCRIPTORS$4 = descriptors; + var IE8_DOM_DEFINE = ie8DomDefine; + var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; + var anObject$2 = anObject$3; + var toPropertyKey = toPropertyKey$1; + + var TypeError$5 = global$a.TypeError; + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var $defineProperty = Object.defineProperty; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ENUMERABLE = 'enumerable'; + var CONFIGURABLE$1 = 'configurable'; + var WRITABLE = 'writable'; + + // `Object.defineProperty` method + // https://tc39.es/ecma262/#sec-object.defineproperty + objectDefineProperty.f = DESCRIPTORS$4 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { + anObject$2(O); + P = toPropertyKey(P); + anObject$2(Attributes); + if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { + var current = $getOwnPropertyDescriptor(O, P); + if (current && current[WRITABLE]) { + O[P] = Attributes.value; + Attributes = { + configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1], + enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], + writable: false + }; + } + } return $defineProperty(O, P, Attributes); + } : $defineProperty : function defineProperty(O, P, Attributes) { + anObject$2(O); + P = toPropertyKey(P); + anObject$2(Attributes); + if (IE8_DOM_DEFINE) try { + return $defineProperty(O, P, Attributes); + } catch (error) { /* empty */ } + if ('get' in Attributes || 'set' in Attributes) throw TypeError$5('Accessors not supported'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; + }; + + var createPropertyDescriptor$1 = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; + }; + + var DESCRIPTORS$3 = descriptors; + var definePropertyModule = objectDefineProperty; + var createPropertyDescriptor = createPropertyDescriptor$1; + + var createNonEnumerableProperty$3 = DESCRIPTORS$3 ? function (object, key, value) { + return definePropertyModule.f(object, key, createPropertyDescriptor(1, value)); + } : function (object, key, value) { + object[key] = value; + return object; + }; + + var makeBuiltIn$2 = {exports: {}}; + + var DESCRIPTORS$2 = descriptors; + var hasOwn$4 = hasOwnProperty_1; + + var FunctionPrototype$1 = Function.prototype; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getDescriptor = DESCRIPTORS$2 && Object.getOwnPropertyDescriptor; + + var EXISTS = hasOwn$4(FunctionPrototype$1, 'name'); + // additional protection from minified / mangled / dropped function names + var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; + var CONFIGURABLE = EXISTS && (!DESCRIPTORS$2 || (DESCRIPTORS$2 && getDescriptor(FunctionPrototype$1, 'name').configurable)); + + var functionName = { + EXISTS: EXISTS, + PROPER: PROPER, + CONFIGURABLE: CONFIGURABLE + }; + + var uncurryThis$7 = functionUncurryThis; + var isCallable$7 = isCallable$e; + var store$1 = sharedStore; + + var functionToString$1 = uncurryThis$7(Function.toString); + + // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper + if (!isCallable$7(store$1.inspectSource)) { + store$1.inspectSource = function (it) { + return functionToString$1(it); + }; + } + + var inspectSource$3 = store$1.inspectSource; + + var global$9 = global$q; + var isCallable$6 = isCallable$e; + var inspectSource$2 = inspectSource$3; + + var WeakMap$1 = global$9.WeakMap; + + var nativeWeakMap = isCallable$6(WeakMap$1) && /native code/.test(inspectSource$2(WeakMap$1)); + + var shared$1 = shared$3.exports; + var uid$1 = uid$3; + + var keys = shared$1('keys'); + + var sharedKey$2 = function (key) { + return keys[key] || (keys[key] = uid$1(key)); + }; + + var hiddenKeys$1 = {}; + + var NATIVE_WEAK_MAP = nativeWeakMap; + var global$8 = global$q; + var uncurryThis$6 = functionUncurryThis; + var isObject$2 = isObject$7; + var createNonEnumerableProperty$2 = createNonEnumerableProperty$3; + var hasOwn$3 = hasOwnProperty_1; + var shared = sharedStore; + var sharedKey$1 = sharedKey$2; + var hiddenKeys = hiddenKeys$1; + + var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; + var TypeError$4 = global$8.TypeError; + var WeakMap = global$8.WeakMap; + var set, get, has; + + var enforce = function (it) { + return has(it) ? get(it) : set(it, {}); + }; + + var getterFor = function (TYPE) { + return function (it) { + var state; + if (!isObject$2(it) || (state = get(it)).type !== TYPE) { + throw TypeError$4('Incompatible receiver, ' + TYPE + ' required'); + } return state; + }; + }; + + if (NATIVE_WEAK_MAP || shared.state) { + var store = shared.state || (shared.state = new WeakMap()); + var wmget = uncurryThis$6(store.get); + var wmhas = uncurryThis$6(store.has); + var wmset = uncurryThis$6(store.set); + set = function (it, metadata) { + if (wmhas(store, it)) throw new TypeError$4(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + wmset(store, it, metadata); + return metadata; + }; + get = function (it) { + return wmget(store, it) || {}; + }; + has = function (it) { + return wmhas(store, it); + }; + } else { + var STATE = sharedKey$1('state'); + hiddenKeys[STATE] = true; + set = function (it, metadata) { + if (hasOwn$3(it, STATE)) throw new TypeError$4(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + createNonEnumerableProperty$2(it, STATE, metadata); + return metadata; + }; + get = function (it) { + return hasOwn$3(it, STATE) ? it[STATE] : {}; + }; + has = function (it) { + return hasOwn$3(it, STATE); + }; + } + + var internalState = { + set: set, + get: get, + has: has, + enforce: enforce, + getterFor: getterFor + }; + + var fails$3 = fails$9; + var isCallable$5 = isCallable$e; + var hasOwn$2 = hasOwnProperty_1; + var defineProperty$2 = objectDefineProperty.f; + var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE; + var inspectSource$1 = inspectSource$3; + var InternalStateModule = internalState; + + var enforceInternalState = InternalStateModule.enforce; + var getInternalState = InternalStateModule.get; + + var CONFIGURABLE_LENGTH = !fails$3(function () { + return defineProperty$2(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; + }); + + var TEMPLATE = String(String).split('String'); + + var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) { + if (String(name).slice(0, 7) === 'Symbol(') { + name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']'; + } + if (options && options.getter) name = 'get ' + name; + if (options && options.setter) name = 'set ' + name; + if (!hasOwn$2(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { + defineProperty$2(value, 'name', { value: name, configurable: true }); + } + if (CONFIGURABLE_LENGTH && options && hasOwn$2(options, 'arity') && value.length !== options.arity) { + defineProperty$2(value, 'length', { value: options.arity }); + } + var state = enforceInternalState(value); + if (!hasOwn$2(state, 'source')) { + state.source = TEMPLATE.join(typeof name == 'string' ? name : ''); + } return value; + }; + + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + // eslint-disable-next-line no-extend-native -- required + Function.prototype.toString = makeBuiltIn$1(function toString() { + return isCallable$5(this) && getInternalState(this).source || inspectSource$1(this); + }, 'toString'); + + var global$7 = global$q; + var isCallable$4 = isCallable$e; + var createNonEnumerableProperty$1 = createNonEnumerableProperty$3; + var makeBuiltIn = makeBuiltIn$2.exports; + var setGlobal = setGlobal$2; + + var defineBuiltIn$1 = function (O, key, value, options) { + var unsafe = options ? !!options.unsafe : false; + var simple = options ? !!options.enumerable : false; + var noTargetGet = options ? !!options.noTargetGet : false; + var name = options && options.name !== undefined ? options.name : key; + if (isCallable$4(value)) makeBuiltIn(value, name, options); + if (O === global$7) { + if (simple) O[key] = value; + else setGlobal(key, value); + return O; + } else if (!unsafe) { + delete O[key]; + } else if (!noTargetGet && O[key]) { + simple = true; + } + if (simple) O[key] = value; + else createNonEnumerableProperty$1(O, key, value); + return O; + }; + + var fails$2 = fails$9; + + var correctPrototypeGetter = !fails$2(function () { + function F() { /* empty */ } + F.prototype.constructor = null; + // eslint-disable-next-line es-x/no-object-getprototypeof -- required for testing + return Object.getPrototypeOf(new F()) !== F.prototype; + }); + + var global$6 = global$q; + var hasOwn$1 = hasOwnProperty_1; + var isCallable$3 = isCallable$e; + var toObject$1 = toObject$3; + var sharedKey = sharedKey$2; + var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter; + + var IE_PROTO = sharedKey('IE_PROTO'); + var Object$2 = global$6.Object; + var ObjectPrototype$1 = Object$2.prototype; + + // `Object.getPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.getprototypeof + var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? Object$2.getPrototypeOf : function (O) { + var object = toObject$1(O); + if (hasOwn$1(object, IE_PROTO)) return object[IE_PROTO]; + var constructor = object.constructor; + if (isCallable$3(constructor) && object instanceof constructor) { + return constructor.prototype; + } return object instanceof Object$2 ? ObjectPrototype$1 : null; + }; + + var global$5 = global$q; + var isCallable$2 = isCallable$e; + + var String$1 = global$5.String; + var TypeError$3 = global$5.TypeError; + + var aPossiblePrototype$1 = function (argument) { + if (typeof argument == 'object' || isCallable$2(argument)) return argument; + throw TypeError$3("Can't set " + String$1(argument) + ' as a prototype'); + }; + + /* eslint-disable no-proto -- safe */ + + var uncurryThis$5 = functionUncurryThis; + var anObject$1 = anObject$3; + var aPossiblePrototype = aPossiblePrototype$1; + + // `Object.setPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.setprototypeof + // Works with __proto__ only. Old v8 can't work with null proto objects. + // eslint-disable-next-line es-x/no-object-setprototypeof -- safe + var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + setter = uncurryThis$5(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); + setter(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { /* empty */ } + return function setPrototypeOf(O, proto) { + anObject$1(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) setter(O, proto); + else O.__proto__ = proto; + return O; + }; + }() : undefined); + + var NATIVE_ARRAY_BUFFER = arrayBufferNative; + var DESCRIPTORS$1 = descriptors; + var global$4 = global$q; + var isCallable$1 = isCallable$e; + var isObject$1 = isObject$7; + var hasOwn = hasOwnProperty_1; + var classof$3 = classof$4; + var tryToString$1 = tryToString$3; + var createNonEnumerableProperty = createNonEnumerableProperty$3; + var defineBuiltIn = defineBuiltIn$1; + var defineProperty$1 = objectDefineProperty.f; + var isPrototypeOf = objectIsPrototypeOf; + var getPrototypeOf = objectGetPrototypeOf; + var setPrototypeOf = objectSetPrototypeOf; + var wellKnownSymbol$2 = wellKnownSymbol$6; + var uid = uid$3; + + var Int8Array = global$4.Int8Array; + var Int8ArrayPrototype = Int8Array && Int8Array.prototype; + var Uint8ClampedArray = global$4.Uint8ClampedArray; + var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype; + var TypedArray = Int8Array && getPrototypeOf(Int8Array); + var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype); + var ObjectPrototype = Object.prototype; + var TypeError$2 = global$4.TypeError; + + var TO_STRING_TAG = wellKnownSymbol$2('toStringTag'); + var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG'); + var TYPED_ARRAY_CONSTRUCTOR$1 = uid('TYPED_ARRAY_CONSTRUCTOR'); + // Fixing native typed arrays in Opera Presto crashes the browser, see #595 + var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof$3(global$4.opera) !== 'Opera'; + var TYPED_ARRAY_TAG_REQUIRED = false; + var NAME$1, Constructor, Prototype; + + var TypedArrayConstructorsList = { + Int8Array: 1, + Uint8Array: 1, + Uint8ClampedArray: 1, + Int16Array: 2, + Uint16Array: 2, + Int32Array: 4, + Uint32Array: 4, + Float32Array: 4, + Float64Array: 8 + }; + + var BigIntArrayConstructorsList = { + BigInt64Array: 8, + BigUint64Array: 8 + }; + + var isView = function isView(it) { + if (!isObject$1(it)) return false; + var klass = classof$3(it); + return klass === 'DataView' + || hasOwn(TypedArrayConstructorsList, klass) + || hasOwn(BigIntArrayConstructorsList, klass); + }; + + var isTypedArray = function (it) { + if (!isObject$1(it)) return false; + var klass = classof$3(it); + return hasOwn(TypedArrayConstructorsList, klass) + || hasOwn(BigIntArrayConstructorsList, klass); + }; + + var aTypedArray$1 = function (it) { + if (isTypedArray(it)) return it; + throw TypeError$2('Target is not a typed array'); + }; + + var aTypedArrayConstructor$1 = function (C) { + if (isCallable$1(C) && (!setPrototypeOf || isPrototypeOf(TypedArray, C))) return C; + throw TypeError$2(tryToString$1(C) + ' is not a typed array constructor'); + }; + + var exportTypedArrayMethod$1 = function (KEY, property, forced, options) { + if (!DESCRIPTORS$1) return; + if (forced) for (var ARRAY in TypedArrayConstructorsList) { + var TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try { + delete TypedArrayConstructor.prototype[KEY]; + } catch (error) { + // old WebKit bug - some methods are non-configurable + try { + TypedArrayConstructor.prototype[KEY] = property; + } catch (error2) { /* empty */ } + } + } + if (!TypedArrayPrototype[KEY] || forced) { + defineBuiltIn(TypedArrayPrototype, KEY, forced ? property + : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property, options); + } + }; + + var exportTypedArrayStaticMethod = function (KEY, property, forced) { + var ARRAY, TypedArrayConstructor; + if (!DESCRIPTORS$1) return; + if (setPrototypeOf) { + if (forced) for (ARRAY in TypedArrayConstructorsList) { + TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && hasOwn(TypedArrayConstructor, KEY)) try { + delete TypedArrayConstructor[KEY]; + } catch (error) { /* empty */ } + } + if (!TypedArray[KEY] || forced) { + // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable + try { + return defineBuiltIn(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && TypedArray[KEY] || property); + } catch (error) { /* empty */ } + } else return; + } + for (ARRAY in TypedArrayConstructorsList) { + TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) { + defineBuiltIn(TypedArrayConstructor, KEY, property); + } + } + }; + + for (NAME$1 in TypedArrayConstructorsList) { + Constructor = global$4[NAME$1]; + Prototype = Constructor && Constructor.prototype; + if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); + else NATIVE_ARRAY_BUFFER_VIEWS = false; + } + + for (NAME$1 in BigIntArrayConstructorsList) { + Constructor = global$4[NAME$1]; + Prototype = Constructor && Constructor.prototype; + if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); + } + + // WebKit bug - typed arrays constructors prototype is Object.prototype + if (!NATIVE_ARRAY_BUFFER_VIEWS || !isCallable$1(TypedArray) || TypedArray === Function.prototype) { + // eslint-disable-next-line no-shadow -- safe + TypedArray = function TypedArray() { + throw TypeError$2('Incorrect invocation'); + }; + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$4[NAME$1]) setPrototypeOf(global$4[NAME$1], TypedArray); + } + } + + if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) { + TypedArrayPrototype = TypedArray.prototype; + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$4[NAME$1]) setPrototypeOf(global$4[NAME$1].prototype, TypedArrayPrototype); + } + } + + // WebKit bug - one more object in Uint8ClampedArray prototype chain + if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) { + setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype); + } + + if (DESCRIPTORS$1 && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) { + TYPED_ARRAY_TAG_REQUIRED = true; + defineProperty$1(TypedArrayPrototype, TO_STRING_TAG, { get: function () { + return isObject$1(this) ? this[TYPED_ARRAY_TAG] : undefined; + } }); + for (NAME$1 in TypedArrayConstructorsList) if (global$4[NAME$1]) { + createNonEnumerableProperty(global$4[NAME$1], TYPED_ARRAY_TAG, NAME$1); + } + } + + var arrayBufferViewCore = { + NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS, + TYPED_ARRAY_CONSTRUCTOR: TYPED_ARRAY_CONSTRUCTOR$1, + TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQUIRED && TYPED_ARRAY_TAG, + aTypedArray: aTypedArray$1, + aTypedArrayConstructor: aTypedArrayConstructor$1, + exportTypedArrayMethod: exportTypedArrayMethod$1, + exportTypedArrayStaticMethod: exportTypedArrayStaticMethod, + isView: isView, + isTypedArray: isTypedArray, + TypedArray: TypedArray, + TypedArrayPrototype: TypedArrayPrototype + }; + + var uncurryThis$4 = functionUncurryThis; + var aCallable = aCallable$2; + var NATIVE_BIND = functionBindNative; + + var bind$1 = uncurryThis$4(uncurryThis$4.bind); + + // optional / simple context binding + var functionBindContext = function (fn, that) { + aCallable(fn); + return that === undefined ? fn : NATIVE_BIND ? bind$1(fn, that) : function (/* ...args */) { + return fn.apply(that, arguments); + }; + }; + + var global$3 = global$q; + var uncurryThis$3 = functionUncurryThis; + var fails$1 = fails$9; + var classof$2 = classofRaw$1; + + var Object$1 = global$3.Object; + var split = uncurryThis$3(''.split); + + // fallback for non-array-like ES3 and non-enumerable old V8 strings + var indexedObject = fails$1(function () { + // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 + // eslint-disable-next-line no-prototype-builtins -- safe + return !Object$1('z').propertyIsEnumerable(0); + }) ? function (it) { + return classof$2(it) == 'String' ? split(it, '') : Object$1(it); + } : Object$1; + + var ceil = Math.ceil; + var floor = Math.floor; + + // `ToIntegerOrInfinity` abstract operation + // https://tc39.es/ecma262/#sec-tointegerorinfinity + var toIntegerOrInfinity$1 = function (argument) { + var number = +argument; + // eslint-disable-next-line no-self-compare -- safe + return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil)(number); + }; + + var toIntegerOrInfinity = toIntegerOrInfinity$1; + + var min = Math.min; + + // `ToLength` abstract operation + // https://tc39.es/ecma262/#sec-tolength + var toLength$1 = function (argument) { + return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 + }; + + var toLength = toLength$1; + + // `LengthOfArrayLike` abstract operation + // https://tc39.es/ecma262/#sec-lengthofarraylike + var lengthOfArrayLike$1 = function (obj) { + return toLength(obj.length); + }; + + var classof$1 = classofRaw$1; + + // `IsArray` abstract operation + // https://tc39.es/ecma262/#sec-isarray + // eslint-disable-next-line es-x/no-array-isarray -- safe + var isArray$1 = Array.isArray || function isArray(argument) { + return classof$1(argument) == 'Array'; + }; + + var uncurryThis$2 = functionUncurryThis; + var fails = fails$9; + var isCallable = isCallable$e; + var classof = classof$4; + var getBuiltIn = getBuiltIn$3; + var inspectSource = inspectSource$3; + + var noop = function () { /* empty */ }; + var empty = []; + var construct = getBuiltIn('Reflect', 'construct'); + var constructorRegExp = /^\s*(?:class|function)\b/; + var exec = uncurryThis$2(constructorRegExp.exec); + var INCORRECT_TO_STRING = !constructorRegExp.exec(noop); + + var isConstructorModern = function isConstructor(argument) { + if (!isCallable(argument)) return false; + try { + construct(noop, empty, argument); + return true; + } catch (error) { + return false; + } + }; + + var isConstructorLegacy = function isConstructor(argument) { + if (!isCallable(argument)) return false; + switch (classof(argument)) { + case 'AsyncFunction': + case 'GeneratorFunction': + case 'AsyncGeneratorFunction': return false; + } + try { + // we can't check .prototype since constructors produced by .bind haven't it + // `Function#toString` throws on some built-it function in some legacy engines + // (for example, `DOMQuad` and similar in FF41-) + return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource(argument)); + } catch (error) { + return true; + } + }; + + isConstructorLegacy.sham = true; + + // `IsConstructor` abstract operation + // https://tc39.es/ecma262/#sec-isconstructor + var isConstructor$2 = !construct || fails(function () { + var called; + return isConstructorModern(isConstructorModern.call) + || !isConstructorModern(Object) + || !isConstructorModern(function () { called = true; }) + || called; + }) ? isConstructorLegacy : isConstructorModern; + + var global$2 = global$q; + var isArray = isArray$1; + var isConstructor$1 = isConstructor$2; + var isObject = isObject$7; + var wellKnownSymbol$1 = wellKnownSymbol$6; + + var SPECIES$1 = wellKnownSymbol$1('species'); + var Array$1 = global$2.Array; + + // a part of `ArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#sec-arrayspeciescreate + var arraySpeciesConstructor$1 = function (originalArray) { + var C; + if (isArray(originalArray)) { + C = originalArray.constructor; + // cross-realm fallback + if (isConstructor$1(C) && (C === Array$1 || isArray(C.prototype))) C = undefined; + else if (isObject(C)) { + C = C[SPECIES$1]; + if (C === null) C = undefined; + } + } return C === undefined ? Array$1 : C; + }; + + var arraySpeciesConstructor = arraySpeciesConstructor$1; + + // `ArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#sec-arrayspeciescreate + var arraySpeciesCreate$1 = function (originalArray, length) { + return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length); + }; + + var bind = functionBindContext; + var uncurryThis$1 = functionUncurryThis; + var IndexedObject = indexedObject; + var toObject = toObject$3; + var lengthOfArrayLike = lengthOfArrayLike$1; + var arraySpeciesCreate = arraySpeciesCreate$1; + + var push = uncurryThis$1([].push); + + // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation + var createMethod = function (TYPE) { + var IS_MAP = TYPE == 1; + var IS_FILTER = TYPE == 2; + var IS_SOME = TYPE == 3; + var IS_EVERY = TYPE == 4; + var IS_FIND_INDEX = TYPE == 6; + var IS_FILTER_REJECT = TYPE == 7; + var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; + return function ($this, callbackfn, that, specificCreate) { + var O = toObject($this); + var self = IndexedObject(O); + var boundFunction = bind(callbackfn, that); + var length = lengthOfArrayLike(self); + var index = 0; + var create = specificCreate || arraySpeciesCreate; + var target = IS_MAP ? create($this, length) : IS_FILTER || IS_FILTER_REJECT ? create($this, 0) : undefined; + var value, result; + for (;length > index; index++) if (NO_HOLES || index in self) { + value = self[index]; + result = boundFunction(value, index, O); + if (TYPE) { + if (IS_MAP) target[index] = result; // map + else if (result) switch (TYPE) { + case 3: return true; // some + case 5: return value; // find + case 6: return index; // findIndex + case 2: push(target, value); // filter + } else switch (TYPE) { + case 4: return false; // every + case 7: push(target, value); // filterReject + } + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target; + }; + }; + + var arrayIteration = { + // `Array.prototype.forEach` method + // https://tc39.es/ecma262/#sec-array.prototype.foreach + forEach: createMethod(0), + // `Array.prototype.map` method + // https://tc39.es/ecma262/#sec-array.prototype.map + map: createMethod(1), + // `Array.prototype.filter` method + // https://tc39.es/ecma262/#sec-array.prototype.filter + filter: createMethod(2), + // `Array.prototype.some` method + // https://tc39.es/ecma262/#sec-array.prototype.some + some: createMethod(3), + // `Array.prototype.every` method + // https://tc39.es/ecma262/#sec-array.prototype.every + every: createMethod(4), + // `Array.prototype.find` method + // https://tc39.es/ecma262/#sec-array.prototype.find + find: createMethod(5), + // `Array.prototype.findIndex` method + // https://tc39.es/ecma262/#sec-array.prototype.findIndex + findIndex: createMethod(6), + // `Array.prototype.filterReject` method + // https://github.com/tc39/proposal-array-filtering + filterReject: createMethod(7) + }; + + var global$1 = global$q; + var isConstructor = isConstructor$2; + var tryToString = tryToString$3; + + var TypeError$1 = global$1.TypeError; + + // `Assert: IsConstructor(argument) is true` + var aConstructor$1 = function (argument) { + if (isConstructor(argument)) return argument; + throw TypeError$1(tryToString(argument) + ' is not a constructor'); + }; + + var anObject = anObject$3; + var aConstructor = aConstructor$1; + var wellKnownSymbol = wellKnownSymbol$6; + + var SPECIES = wellKnownSymbol('species'); + + // `SpeciesConstructor` abstract operation + // https://tc39.es/ecma262/#sec-speciesconstructor + var speciesConstructor$1 = function (O, defaultConstructor) { + var C = anObject(O).constructor; + var S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? defaultConstructor : aConstructor(S); + }; + + var ArrayBufferViewCore$1 = arrayBufferViewCore; + var speciesConstructor = speciesConstructor$1; + + var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore$1.TYPED_ARRAY_CONSTRUCTOR; + var aTypedArrayConstructor = ArrayBufferViewCore$1.aTypedArrayConstructor; + + // a part of `TypedArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#typedarray-species-create + var typedArraySpeciesConstructor$1 = function (originalArray) { + return aTypedArrayConstructor(speciesConstructor(originalArray, originalArray[TYPED_ARRAY_CONSTRUCTOR])); + }; + + var ArrayBufferViewCore = arrayBufferViewCore; + var $map = arrayIteration.map; + var typedArraySpeciesConstructor = typedArraySpeciesConstructor$1; + + var aTypedArray = ArrayBufferViewCore.aTypedArray; + var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; + + // `%TypedArray%.prototype.map` method + // https://tc39.es/ecma262/#sec-%typedarray%.prototype.map + exportTypedArrayMethod('map', function map(mapfn /* , thisArg */) { + return $map(aTypedArray(this), mapfn, arguments.length > 1 ? arguments[1] : undefined, function (O, length) { + return new (typedArraySpeciesConstructor(O))(length); + }); + }); + + var DESCRIPTORS = descriptors; + var FUNCTION_NAME_EXISTS = functionName.EXISTS; + var uncurryThis = functionUncurryThis; + var defineProperty = objectDefineProperty.f; + + var FunctionPrototype = Function.prototype; + var functionToString = uncurryThis(FunctionPrototype.toString); + var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/; + var regExpExec = uncurryThis(nameRE.exec); + var NAME = 'name'; + + // Function instances `.name` property + // https://tc39.es/ecma262/#sec-function-instances-name + if (DESCRIPTORS && !FUNCTION_NAME_EXISTS) { + defineProperty(FunctionPrototype, NAME, { + configurable: true, + get: function () { + try { + return regExpExec(nameRE, functionToString(this))[1]; + } catch (error) { + return ''; + } + } + }); + } + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } else if (call !== void 0) { + throw new TypeError("Derived constructors may only return object or undefined"); + } + + return _assertThisInitialized(self); + } + + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; + } + + var BaseReader = function () { + function BaseReader() { + _classCallCheck(this, BaseReader); + } + + _createClass(BaseReader, [{ + key: "isValueType", + value: function isValueType() { + return true; + } + }, { + key: "type", + get: function get() { + return this.constructor.type(); + } + }, { + key: "read", + value: function read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "writeIndex", + value: function writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(parseInt(resolver.getIndex(this)) + 1); + } + }, { + key: "toString", + value: function toString() { + return this.type; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + return false; + } + }, { + key: "hasSubType", + value: function hasSubType() { + return false; + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type()].concat(subtype); + } + }, { + key: "type", + value: function type() { + return this.name.slice(0, -6); + } + }]); + + return BaseReader; + }(); + + var UInt32Reader = function (_BaseReader) { + _inherits(UInt32Reader, _BaseReader); + + var _super = _createSuper(UInt32Reader); + + function UInt32Reader() { + _classCallCheck(this, UInt32Reader); + + return _super.apply(this, arguments); + } + + _createClass(UInt32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readUInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + }]); + + return UInt32Reader; + }(BaseReader); + + var ArrayReader = function (_BaseReader) { + _inherits(ArrayReader, _BaseReader); + + var _super = _createSuper(ArrayReader); + + function ArrayReader(reader) { + var _this; + + _classCallCheck(this, ArrayReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ArrayReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var array = []; + + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (var i = 0; i < content.length; i++) { + this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Array<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ArrayReader; + }(BaseReader); + + function __arrayMaker(obj, func) { + if (!obj || _typeof(obj) !== "object") throw new Error("Invalid Data!"); + var result = []; + var length = obj.length; + + for (var i = 0; i < length; i++) { + result[i] = func(obj[i], i); + } + + return result; + } + + function __trunc(number) { + if (number < 0) return Math.ceil(number); + return Math.floor(number); + } + + Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + var mappedPromises = promises.map(function (p) { + return p.then(function (value) { + return { + status: 'fulfilled', + value: value + }; + }).catch(function (reason) { + return { + status: 'rejected', + reason: reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + var UTF16_BITES = [0xD800, 0xDC00]; + var UTF16_MASK = 1023; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + var codes = stringToUnicode(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + var StringReader = function (_BaseReader) { + _inherits(StringReader, _BaseReader); + + var _super = _createSuper(StringReader); + + function StringReader() { + _classCallCheck(this, StringReader); + + return _super.apply(this, arguments); + } + + _createClass(StringReader, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + var size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + }]); + + return StringReader; + }(BaseReader); + + var BmFontReader = function (_BaseReader) { + _inherits(BmFontReader, _BaseReader); + + var _super = _createSuper(BmFontReader); + + function BmFontReader() { + _classCallCheck(this, BmFontReader); + + return _super.apply(this, arguments); + } + + _createClass(BmFontReader, [{ + key: "read", + value: function read(buffer) { + var stringReader = new StringReader(); + var xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + }]); + + return BmFontReader; + }(BaseReader); + + var BooleanReader = function (_BaseReader) { + _inherits(BooleanReader, _BaseReader); + + var _super = _createSuper(BooleanReader); + + function BooleanReader() { + _classCallCheck(this, BooleanReader); + + return _super.apply(this, arguments); + } + + _createClass(BooleanReader, [{ + key: "read", + value: function read(buffer) { + return Boolean(buffer.readInt()); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + }]); + + return BooleanReader; + }(BaseReader); + + var CharReader = function (_BaseReader) { + _inherits(CharReader, _BaseReader); + + var _super = _createSuper(CharReader); + + function CharReader() { + _classCallCheck(this, CharReader); + + return _super.apply(this, arguments); + } + + _createClass(CharReader, [{ + key: "read", + value: function read(buffer) { + var charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + }, { + key: "_getCharSize", + value: function _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + }]); + + return CharReader; + }(BaseReader); + + var DictionaryReader = function (_BaseReader) { + _inherits(DictionaryReader, _BaseReader); + + var _super = _createSuper(DictionaryReader); + + function DictionaryReader(key, value) { + var _this; + + _classCallCheck(this, DictionaryReader); + + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + _this = _super.call(this); + _this.key = key; + _this.value = value; + return _this; + } + + _createClass(DictionaryReader, [{ + key: "read", + value: function read(buffer, resolver) { + var dictionary = {}; + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + + for (var i = 0; i < size; i++) { + var key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + var value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (var _i2 = 0, _Object$keys2 = Object.keys(content); _i2 < _Object$keys2.length; _i2++) { + var key = _Object$keys2[_i2]; + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return DictionaryReader; + }(BaseReader); + + var DoubleReader = function (_BaseReader) { + _inherits(DoubleReader, _BaseReader); + + var _super = _createSuper(DoubleReader); + + function DoubleReader() { + _classCallCheck(this, DoubleReader); + + return _super.apply(this, arguments); + } + + _createClass(DoubleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readDouble(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + }]); + + return DoubleReader; + }(BaseReader); + + var EffectReader = function (_BaseReader) { + _inherits(EffectReader, _BaseReader); + + var _super = _createSuper(EffectReader); + + function EffectReader() { + _classCallCheck(this, EffectReader); + + return _super.apply(this, arguments); + } + + _createClass(EffectReader, [{ + key: "read", + value: function read(buffer) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + }]); + + return EffectReader; + }(BaseReader); + + var Int32Reader = function (_BaseReader) { + _inherits(Int32Reader, _BaseReader); + + var _super = _createSuper(Int32Reader); + + function Int32Reader() { + _classCallCheck(this, Int32Reader); + + return _super.apply(this, arguments); + } + + _createClass(Int32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + }]); + + return Int32Reader; + }(BaseReader); + + var ListReader = function (_BaseReader) { + _inherits(ListReader, _BaseReader); + + var _super = _createSuper(ListReader); + + function ListReader(reader) { + var _this; + + _classCallCheck(this, ListReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ListReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var list = []; + + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + var __keys = Object.keys(content); + + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + data = content[__key]; + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "type", + get: function get() { + return "List<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ListReader; + }(BaseReader); + + var NullableReader = function (_BaseReader) { + _inherits(NullableReader, _BaseReader); + + var _super = _createSuper(NullableReader); + + function NullableReader(reader) { + var _this; + + _classCallCheck(this, NullableReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(NullableReader, [{ + key: "read", + value: function read(buffer, resolver) { + var booleanReader = new BooleanReader(); + var hasValue = booleanReader.read(buffer); + return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + new BooleanReader(); + buffer.writeByte(content != null); + if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Nullable<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return NullableReader; + }(BaseReader); + + var ReflectiveReader = function (_BaseReader) { + _inherits(ReflectiveReader, _BaseReader); + + var _super = _createSuper(ReflectiveReader); + + function ReflectiveReader(reader) { + var _this; + + _classCallCheck(this, ReflectiveReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ReflectiveReader, [{ + key: "read", + value: function read(buffer, resolver) { + var reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + return reflective; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "".concat(this.reader.type); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ReflectiveReader; + }(BaseReader); + + var RectangleReader = function (_BaseReader) { + _inherits(RectangleReader, _BaseReader); + + var _super = _createSuper(RectangleReader); + + function RectangleReader() { + _classCallCheck(this, RectangleReader); + + return _super.apply(this, arguments); + } + + _createClass(RectangleReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var x = int32Reader.read(buffer); + var y = int32Reader.read(buffer); + var width = int32Reader.read(buffer); + var height = int32Reader.read(buffer); + return { + x: x, + y: y, + width: width, + height: height + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + }]); + + return RectangleReader; + }(BaseReader); + + var SingleReader = function (_BaseReader) { + _inherits(SingleReader, _BaseReader); + + var _super = _createSuper(SingleReader); + + function SingleReader() { + _classCallCheck(this, SingleReader); + + return _super.apply(this, arguments); + } + + _createClass(SingleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readSingle(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + }]); + + return SingleReader; + }(BaseReader); + + var kDxt1 = 1 << 0; + var kDxt3 = 1 << 1; + var kDxt5 = 1 << 2; + var kColourIterativeClusterFit = 1 << 8; + var kColourClusterFit = 1 << 3; + var kColourRangeFit = 1 << 4; + var kColourMetricPerceptual = 1 << 5; + var kColourMetricUniform = 1 << 6; + var kWeightColourByAlpha = 1 << 7; + + function Rot(theta) { + var Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } + + function Rij(k, l, theta, N) { + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i = 0; _i < N; _i++) { + for (var j = 0; j < N; j++) { + Mat[_i][j] = (_i === j) * 1.0; + } + } + + var Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } + + function getTheta(aii, ajj, aij) { + var th = 0.0; + var denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; + } + + function getAij(Mij) { + var N = Mij.length; + var maxMij = 0.0; + var maxIJ = [0, 1]; + + for (var i = 0; i < N; i++) { + for (var j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; + } + + function unitary(U, H) { + var N = U.length; + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i2 = 0; _i2 < N; _i2++) { + for (var j = 0; j < N; j++) { + Mat[_i2][j] = 0; + + for (var k = 0; k < N; k++) { + for (var l = 0; l < N; l++) { + Mat[_i2][j] = Mat[_i2][j] + U[k][_i2] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; + } + + function AxB(A, B) { + var N = A.length; + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i3 = 0; _i3 < N; _i3++) { + for (var j = 0; j < N; j++) { + Mat[_i3][j] = 0; + + for (var k = 0; k < N; k++) { + Mat[_i3][j] = Mat[_i3][j] + A[_i3][k] * B[k][j]; + } + } + } + + return Mat; + } + + function eigens(Hij) { + var convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + var N = Hij.length; + var Ei = Array(N); + var e0 = Math.abs(convergence / N); + var Sij = Array(N); + + for (var i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (var _i4 = 0; _i4 < N; _i4++) { + for (var j = 0; j < N; j++) { + Sij[_i4][j] = (_i4 === j) * 1.0; + } + } + + var Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + var _i5 = Vab[0][0]; + var _j = Vab[0][1]; + var psi = getTheta(Hij[_i5][_i5], Hij[_j][_j], Hij[_i5][_j]); + var Gij = Rij(_i5, _j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (var _i6 = 0; _i6 < N; _i6++) { + Ei[_i6] = Hij[_i6][_i6]; + } + + return sorting(Ei, Sij); + } + + function sorting(values, vectors) { + var eigsCount = values.length; + vectors.length; + + var pairs = __arrayMaker({ + length: eigsCount + }, function (_, i) { + var vector = vectors.map(function (v) { + return v[i]; + }); + return { + value: values[i], + vec: vector + }; + }); + + pairs.sort(function (a, b) { + return b.value - a.value; + }); + var sortedValues = pairs.map(function (_ref) { + var value = _ref.value; + return value; + }); + var sortedVectors = pairs.map(function (_ref2) { + var vec = _ref2.vec; + return vec; + }); + return [sortedValues, sortedVectors]; + } + + function dominentPrincipalVector(matrix) { + var _eigens = eigens(matrix), + _eigens$ = _eigens[1], + dominentVector = _eigens$[0]; + + return dominentVector; + } + + var Vec3 = function () { + function Vec3() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + + _classCallCheck(this, Vec3); + + this._values = [x, y, z]; + } + + _createClass(Vec3, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + }, { + key: "colorInt", + get: function get() { + var floatToInt = function floatToInt(value) { + var result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + }, { + key: "clone", + value: function clone() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + }, { + key: "toVec4", + value: function toVec4() { + var w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; + + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + }, { + key: "toString", + value: function toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec3.multScalar(a, 1 - p); + var b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + }]); + + return Vec3; + }(); + + var Vec4 = function () { + function Vec4() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + + _classCallCheck(this, Vec4); + + this._values = [x, y, z, w]; + } + + _createClass(Vec4, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "w", + get: function get() { + return this._values[3]; + }, + set: function set(value) { + this._values[3] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + }, { + key: "xyz", + get: function get() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "splatX", + get: function get() { + return new Vec4(this.x); + } + }, { + key: "splatY", + get: function get() { + return new Vec4(this.y); + } + }, { + key: "splatZ", + get: function get() { + return new Vec4(this.z); + } + }, { + key: "splatW", + get: function get() { + return new Vec4(this.w); + } + }, { + key: "clone", + value: function clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + }, { + key: "toVec3", + value: function toVec3() { + return this.xyz; + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + }, { + key: "subVector", + value: function subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + }, { + key: "reciprocal", + value: function reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; + + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + }, { + key: "truncate", + value: function truncate() { + this._values[0] = __trunc(this._values[0]); + this._values[1] = __trunc(this._values[1]); + this._values[2] = __trunc(this._values[2]); + this._values[3] = __trunc(this._values[3]); + return this; + } + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + }, { + key: "toString", + value: function toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec4.multScalar(a, 1 - p); + var b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + }, { + key: "multiplyAdd", + value: function multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + }, { + key: "negativeMultiplySubtract", + value: function negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + }, { + key: "compareAnyLessThan", + value: function compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + }]); + + return Vec4; + }(); + + function computeWeightedCovariance(values, weights) { + var total = 0; + var mean = values.reduce(function (sum, value, i) { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + var covariance = values.reduce(function (sum, value, i) { + var weight = weights[i]; + var v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } + + function computePCA(values, weights) { + var covariance = computeWeightedCovariance(values, weights); + return _construct(Vec3, dominentPrincipalVector(covariance)); + } + + var lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + var lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + + function floatToInt(value, limit) { + var integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } + + function floatTo565(color) { + var r = floatToInt(31.0 * color.x, 31); + var g = floatToInt(63.0 * color.y, 63); + var b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } + + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (var y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } + } + + function writeColourBlock3(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + var _ref = [secondColor, firstColor]; + firstColor = _ref[0]; + secondColor = _ref[1]; + remapped = indices.map(function (index) { + return index === 0 ? 1 : index === 1 ? 0 : index; + }); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + function writeColourBlock4(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; + + if (firstColor < secondColor) { + var _ref2 = [secondColor, firstColor]; + firstColor = _ref2[0]; + secondColor = _ref2[1]; + remapped = indices.map(function (index) { + return (index ^ 0x1) & 0x3; + }); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + var ColorSet = function () { + function ColorSet(rgba, mask, flags) { + _classCallCheck(this, ColorSet); + + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + var isDxt1 = (this.flags & kDxt1) != 0; + var weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (var i = 0; i < 16; i++) { + var bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (var j = 0;; j++) { + if (j == i) { + var r = rgba[4 * i] / 255.0; + var g = rgba[4 * i + 1] / 255.0; + var b = rgba[4 * i + 2] / 255.0; + var a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + var oldbit = 1 << j; + var match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + var index = this._remap[j]; + var w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (var _i = 0; _i < this._count; ++_i) { + this._weights[_i] = Math.sqrt(this._weights[_i]); + } + } + + _createClass(ColorSet, [{ + key: "transparent", + get: function get() { + return this._transparent; + } + }, { + key: "count", + get: function get() { + return this._count; + } + }, { + key: "points", + get: function get() { + return Object.freeze(this._points.slice()); + } + }, { + key: "weights", + get: function get() { + return Object.freeze(this._weights.slice()); + } + }, { + key: "remapIndicesSingle", + value: function remapIndicesSingle(singleIndex, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : singleIndex; + }); + + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }, { + key: "remapIndices", + value: function remapIndices(indexMap, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : indexMap[index]; + }); + + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }]); + + return ColorSet; + }(); + + var ColorFit = function () { + function ColorFit(colorSet) { + _classCallCheck(this, ColorFit); + + this.colors = colorSet; + this.flags = colorSet.flags; + } + + _createClass(ColorFit, [{ + key: "compress", + value: function compress(result, offset) { + var isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + }, { + key: "compress3", + value: function compress3(result, offset) {} + }, { + key: "compress4", + value: function compress4(result, offset) {} + }]); + + return ColorFit; + }(); + + var SingleColourFit = function (_ColorFit) { + _inherits(SingleColourFit, _ColorFit); + + var _super = _createSuper(SingleColourFit); + + function SingleColourFit(colorSet) { + var _this; + + _classCallCheck(this, SingleColourFit); + + _this = _super.call(this, colorSet); + var singleColor = colorSet.points[0]; + _this.color = singleColor.colorInt; + _this.start = new Vec3(0); + _this.end = new Vec3(0); + _this.index = 0; + _this.error = Infinity; + _this.bestError = Infinity; + return _this; + } + + _createClass(SingleColourFit, [{ + key: "compressBase", + value: function compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(lookups, saveFunc); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(lookups, saveFunc); + } + }, { + key: "computeEndPoints", + value: function computeEndPoints(lookups) { + this.error = Infinity; + + for (var index = 0; index < 2; index++) { + var sources = []; + var error = 0; + + for (var channel = 0; channel < 3; channel++) { + var lookup = lookups[channel]; + var target = this.color[channel]; + sources[channel] = lookup[target][index]; + var diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + }]); + + return SingleColourFit; + }(ColorFit); + + var RangeFit = function (_ColorFit2) { + _inherits(RangeFit, _ColorFit2); + + var _super2 = _createSuper(RangeFit); + + function RangeFit(colorSet) { + var _this2; + + _classCallCheck(this, RangeFit); + + _this2 = _super2.call(this, colorSet); + _this2.metric = new Vec3(1); + + if ((_this2.flags & kColourMetricPerceptual) !== 0) { + _this2.metric.set(0.2126, 0.7152, 0.0722); + } + + _this2.start = new Vec3(0); + _this2.end = new Vec3(0); + _this2.bestError = Infinity; + + _this2.computePoints(); + + return _this2; + } + + _createClass(RangeFit, [{ + key: "compressBase", + value: function compressBase(codes, saveFunc) { + var _this3 = this; + + var values = this.colors.points; + var error = 0; + var closest = values.map(function (color) { + var minDist = Infinity; + var packedIndex = codes.reduce(function (idx, code, j) { + var dist = Vec3.sub(color, code).multVector(_this3.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); + } + }, { + key: "computePoints", + value: function computePoints() { + var _this$colors = this.colors, + count = _this$colors.count, + values = _this$colors.points, + weights = _this$colors.weights; + if (count <= 0) return; + var principle = computePCA(values, weights); + var start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (var i = 1; i < count; i++) { + var value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + }]); + + return RangeFit; + }(ColorFit); + + var ClusterFit = function (_ColorFit3) { + _inherits(ClusterFit, _ColorFit3); + + var _super3 = _createSuper(ClusterFit); + + function ClusterFit(colorSet) { + var _this4; + + _classCallCheck(this, ClusterFit); + + _this4 = _super3.call(this, colorSet); + var kMaxIterations = 8; + _this4.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + _this4.bestError = Infinity; + _this4.metric = new Vec4(1); + + if ((_this4.flags & kColourMetricPerceptual) !== 0) { + _this4.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + var _this4$colors = _this4.colors, + values = _this4$colors.points, + weights = _this4$colors.weights; + _this4.principle = computePCA(values, weights); + _this4.order = new Uint8Array(16 * kMaxIterations); + _this4.pointsWeights = []; + _this4.xSum_wSum = new Vec4(0); + return _this4; + } + + _createClass(ClusterFit, [{ + key: "constructOrdering", + value: function constructOrdering(axis, iteration) { + var currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + var uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var aabbx = function aabbx(_ref) { + var part0 = _ref[0], + part1 = _ref[2], + part2 = _ref[3]; + var const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + var alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(aabbx, saveFunc, 2); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var aabbx = function aabbx(_ref2) { + var part0 = _ref2[0], + part1 = _ref2[1], + part2 = _ref2[2], + part3 = _ref2[3]; + var const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + var const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + var const2_9 = new Vec4(2 / 9); + var alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(aabbx, saveFunc, 3); + } + }, { + key: "compressBase", + value: function compressBase(aabbFunc, saveFunc) { + var _this5 = this; + + var repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + var best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + var leastSquares = function leastSquares(parts, internalIndices) { + var aabbx = aabbFunc(parts); + + var internalBest = _this5.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (var iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + var newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + }, { + key: "makeOrder", + value: function makeOrder(axis) { + var _this$colors2 = this.colors, + count = _this$colors2.count, + values = _this$colors2.points; + var dotProducts = values.map(function (color, i) { + return Vec3.dot(color, axis); + }); + return __arrayMaker({ + length: count + }, function (_, i) { + return i; + }).sort(function (a, b) { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + }, { + key: "copyOrderToThisOrder", + value: function copyOrderToThisOrder(order, iteration) { + var _this6 = this; + + var orderOffset = iteration * 16; + order.forEach(function (ord, i) { + _this6.order[orderOffset + i] = ord; + }); + } + }, { + key: "checkOrderUnique", + value: function checkOrderUnique(order, iteration) { + var count = this.colors.count; + + for (var it = 0; it < iteration; it++) { + var prevOffset = it * 16; + var same = true; + + for (var i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + }, { + key: "copyOrderWeight", + value: function copyOrderWeight(order) { + var _this$colors3 = this.colors, + count = _this$colors3.count, + unweighted = _this$colors3.points, + weights = _this$colors3.weights; + this.xSum_wSum.set(0); + + for (var i = 0; i < count; i++) { + var j = order[i]; + var p = unweighted[j].toVec4(1); + var w = new Vec4(weights[j]); + var x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + }, { + key: "computeOptimalPoints", + value: function computeOptimalPoints(vectorPoint) { + var ax = vectorPoint.ax, + bx = vectorPoint.bx, + aa = vectorPoint.aa, + bb = vectorPoint.bb, + ab = vectorPoint.ab; + var factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + var a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + var b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + var error = this.computeError(_objectSpread2({ + a: a, + b: b + }, vectorPoint)); + return { + start: a, + end: b, + error: error + }; + } + }, { + key: "computeError", + value: function computeError(_ref3) { + var a = _ref3.a, + b = _ref3.b, + ax = _ref3.ax, + bx = _ref3.bx, + aa = _ref3.aa, + bb = _ref3.bb, + ab = _ref3.ab; + var two = new Vec4(2); + var e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + var e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + var e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + var e4 = Vec4.multiplyAdd(two, e3, e1); + var e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + }, { + key: "saveBlock", + value: function saveBlock(best, writeFunc) { + var count = this.colors.count; + var start = best.start, + end = best.end, + iteration = best.iteration, + error = best.error, + bestI = best.bestI, + bestJ = best.bestJ, + _best$bestK = best.bestK, + bestK = _best$bestK === void 0 ? -1 : _best$bestK; + var orderOffset = iteration * 16; + var unordered = new Uint8Array(16); + + var mapper = function mapper(m) { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (var i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + var bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + }, { + key: "clusterIterate", + value: function clusterIterate(index, func) { + var iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + var count = this.colors.count; + + var indexMapper = function indexMapper(i, j, k) { + var mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + var part0 = new Vec4(0.0); + + for (var i = 0; i < count; i++) { + var part1 = new Vec4(0.0); + + for (var j = i;;) { + var preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + var kmin = j == 0 ? 1 : j; + + for (var k = kmin;;) { + var restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + }]); + + return ClusterFit; + }(ColorFit); + + function quantise(alpha) { + var GRID = 15; + var result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; + } + + function compressAlphaDxt3(rgba, mask, result, offset) { + for (var i = 0; i < 8; i++) { + var quant1 = quantise(rgba[8 * i + 3]); + var quant2 = quantise(rgba[8 * i + 7]); + var bit1 = 1 << 2 * i; + var bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } + } + + function compressAlphaDxt5(rgba, mask, result, offset) { + var step5 = interpolateAlpha(rgba, mask, 5); + var step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } + + function interpolateAlpha(rgba, mask, steps) { + var _setAlphaRange = setAlphaRange(rgba, mask, steps), + min = _setAlphaRange.min, + max = _setAlphaRange.max; + + var code = setAlphaCodeBook(min, max, steps); + var indices = new Uint8Array(16); + var error = fitCodes(rgba, mask, code, indices); + return { + min: min, + max: max, + indices: indices, + error: error + }; + } + + function setAlphaRange(rgba, mask, steps) { + var min = 255; + var max = 0; + + for (var i = 0; i < 16; i++) { + var bit = 1 << i; + if ((mask & bit) == 0) continue; + var value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min: min, + max: max + }; + } + + function setAlphaCodeBook(min, max, steps) { + var codes = [min, max].concat(__arrayMaker({ + length: steps - 1 + }, function (_, i) { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })); + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; + } + + function fitCodes(rgba, mask, codes, indices) { + var err = 0; + + for (var i = 0; i < 16; ++i) { + var bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + var value = rgba[4 * i + 3]; + var least = Infinity; + var index = 0; + + for (var j = 0; j < 8; ++j) { + var dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; + } + + function writeAlphaBlock5(_ref, result, offset) { + var alpha0 = _ref.min, + alpha1 = _ref.max, + indices = _ref.indices; + + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock7(_ref2, result, offset) { + var alpha0 = _ref2.min, + alpha1 = _ref2.max, + indices = _ref2.indices; + + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + var indicesPointer = 0; + var resultPointer = offset + 2; + + for (var i = 0; i < 2; i++) { + var value = 0; + + for (var j = 0; j < 8; ++j) { + var index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (var _j = 0; _j < 3; ++_j) { + var byte = value >> 8 * _j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } + } + + function unpack565(color16bit) { + var red = color16bit >> 11 & 0x1f; + var green = color16bit >> 5 & 0x3f; + var blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; + } + + function interpolateColorArray(a, b, amount) { + var result = a.map(function (aColor, i) { + return Math.floor(aColor * (1 - amount) + b[i] * amount); + }); + result[3] = 255; + return result; + } + + function unpackColorCodes(block, offset, isDxt1) { + var color1 = block[offset] | block[offset + 1] << 8; + var color2 = block[offset + 2] | block[offset + 3] << 8; + var unpackedColor1 = unpack565(color1); + var unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } + + function unpackIndices(block, blockOffset) { + var offset = blockOffset + 4; + var result = new Uint8Array(16); + + for (var i = 0; i < 4; i++) { + var packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; + } + + function decompressColor(rgba, block, offset, isDxt1) { + var colorCode = unpackColorCodes(block, offset, isDxt1); + var indices = unpackIndices(block, offset); + + for (var i = 0; i < 16; i++) { + for (var j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } + } + + function decompressAlphaDxt3(rgba, block, offset) { + for (var i = 0; i < 8; ++i) { + var quant = block[offset + i]; + var lo = quant & 0x0f; + var hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } + } + + function decompressAlphaDxt5(rgba, block, offset) { + var alpha0 = block[offset + 0]; + var alpha1 = block[offset + 1]; + var codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + var indices = new Uint8Array(16); + var indicePointer = 0; + var bytePointer = 2; + + for (var i = 0; i < 2; i++) { + var value = 0; + + for (var j = 0; j < 3; j++) { + var byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (var _j = 0; _j < 8; _j++) { + var index = value >> 3 * _j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (var _i = 0; _i < 16; ++_i) { + rgba[4 * _i + 3] = codes[indices[_i]]; + } + } + + var DXT1_COMPRESSED_BYTES = 8; + var DXT5_COMPRESSED_BYTES = 16; + var COLORS = 4; + var DECOMPRESSED_BLOCK_SIZE = 16; + + function blockRepeat(width, height, func) { + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + func(x, y); + } + } + } + + function rectRepeat(func) { + for (var y = 0; y < 4; y++) { + for (var x = 0; x < 4; x++) { + func(x, y); + } + } + } + + function FixFlags(flags) { + var method = flags & (kDxt1 | kDxt3 | kDxt5); + var fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + var metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + var extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; + } + + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + var blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + var blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } + + function extractColorBlock(img) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$x = _ref.x, + x = _ref$x === void 0 ? 0 : _ref$x, + _ref$y = _ref.y, + y = _ref$y === void 0 ? 0 : _ref$y, + _ref$width = _ref.width, + width = _ref$width === void 0 ? 0 : _ref$width, + _ref$height = _ref.height, + height = _ref$height === void 0 ? 0 : _ref$height; + + var block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + var mask = 0; + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; + + if (sx < width && sy < height) { + var sourceColorOffset = COLORS * (width * sy + sx); + + for (var i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block: block, + mask: mask + }; + } + + function copyBuffer(result, block) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$x = _ref2.x, + x = _ref2$x === void 0 ? 0 : _ref2$x, + _ref2$y = _ref2.y, + y = _ref2$y === void 0 ? 0 : _ref2$y, + _ref2$width = _ref2.width, + width = _ref2$width === void 0 ? 0 : _ref2$width, + _ref2$height = _ref2.height, + height = _ref2$height === void 0 ? 0 : _ref2$height; + + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; + + if (sx < width && sy < height) { + var resultColorOffset = COLORS * (width * sy + sx); + + for (var i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } + + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } + + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + var colors = new ColorSet(rgba, mask, flags); + var compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } + + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); + } + + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + var _extractColorBlock = extractColorBlock(source, { + x: x, + y: y, + width: width, + height: height + }), + sourceRGBA = _extractColorBlock.block, + mask = _extractColorBlock.mask; + + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } + + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var sourceBlockPointer = 0; + + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + var targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x: x, + y: y, + width: width, + height: height + }); + sourceBlockPointer += bytesPerBlock; + } + } + } + + var flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; + + function compress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = GetStorageRequirements(width, height, flags); + var result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; + } + + function decompress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = width * height * 4; + var result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; + } + + var Texture2DReader = function (_BaseReader) { + _inherits(Texture2DReader, _BaseReader); + + var _super = _createSuper(Texture2DReader); + + function Texture2DReader() { + _classCallCheck(this, Texture2DReader); + + return _super.apply(this, arguments); + } + + _createClass(Texture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + var width = content.export.width; + var height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; + + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + }]); + + return Texture2DReader; + }(BaseReader); + + var Vector3Reader = function (_BaseReader) { + _inherits(Vector3Reader, _BaseReader); + + var _super = _createSuper(Vector3Reader); + + function Vector3Reader() { + _classCallCheck(this, Vector3Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector3Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + return { + x: x, + y: y, + z: z + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + }]); + + return Vector3Reader; + }(BaseReader); + + var SpriteFontReader = function (_BaseReader) { + _inherits(SpriteFontReader, _BaseReader); + + var _super = _createSuper(SpriteFontReader); + + function SpriteFontReader() { + _classCallCheck(this, SpriteFontReader); + + return _super.apply(this, arguments); + } + + _createClass(SpriteFontReader, [{ + key: "read", + value: function read(buffer, resolver) { + var int32Reader = new Int32Reader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(new CharReader()); + var texture = resolver.read(buffer); + var glyphs = resolver.read(buffer); + var cropping = resolver.read(buffer); + var characterMap = resolver.read(buffer); + var verticalLineSpacing = int32Reader.read(buffer); + var horizontalSpacing = singleReader.read(buffer); + var kerning = resolver.read(buffer); + var defaultCharacter = nullableCharReader.read(buffer); + return { + texture: texture, + glyphs: glyphs, + cropping: cropping, + characterMap: characterMap, + verticalLineSpacing: verticalLineSpacing, + horizontalSpacing: horizontalSpacing, + kerning: kerning, + defaultCharacter: defaultCharacter + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var charReader = new CharReader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(charReader); + var texture2DReader = new Texture2DReader(); + var rectangleListReader = new ListReader(new RectangleReader()); + var charListReader = new ListReader(charReader); + var vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + }]); + + return SpriteFontReader; + }(BaseReader); + + var TBinReader = function (_BaseReader) { + _inherits(TBinReader, _BaseReader); + + var _super = _createSuper(TBinReader); + + function TBinReader() { + _classCallCheck(this, TBinReader); + + return _super.apply(this, arguments); + } + + _createClass(TBinReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var size = int32Reader.read(buffer); + var data = buffer.read(size); + return { + export: { + type: this.type, + data: data + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + }]); + + return TBinReader; + }(BaseReader); + + var LightweightTexture2DReader = function (_BaseReader) { + _inherits(LightweightTexture2DReader, _BaseReader); + + var _super = _createSuper(LightweightTexture2DReader); + + function LightweightTexture2DReader() { + _classCallCheck(this, LightweightTexture2DReader); + + return _super.apply(this, arguments); + } + + _createClass(LightweightTexture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; + + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Texture2D"; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + }, { + key: "type", + value: function type() { + return "Texture2D"; + } + }]); + + return LightweightTexture2DReader; + }(BaseReader); + + var Vector2Reader = function (_BaseReader) { + _inherits(Vector2Reader, _BaseReader); + + var _super = _createSuper(Vector2Reader); + + function Vector2Reader() { + _classCallCheck(this, Vector2Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector2Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + return { + x: x, + y: y + }; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + }]); + + return Vector2Reader; + }(BaseReader); + + var Vector4Reader = function (_BaseReader) { + _inherits(Vector4Reader, _BaseReader); + + var _super = _createSuper(Vector4Reader); + + function Vector4Reader() { + _classCallCheck(this, Vector4Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector4Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + var w = singleReader.read(buffer); + return { + x: x, + y: y, + z: z, + w: w + }; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + }]); + + return Vector4Reader; + }(BaseReader); + + exports.ArrayReader = ArrayReader; + exports.BaseReader = BaseReader; + exports.BmFontReader = BmFontReader; + exports.BooleanReader = BooleanReader; + exports.CharReader = CharReader; + exports.DictionaryReader = DictionaryReader; + exports.DoubleReader = DoubleReader; + exports.EffectReader = EffectReader; + exports.Int32Reader = Int32Reader; + exports.LightweightTexture2DReader = LightweightTexture2DReader; + exports.ListReader = ListReader; + exports.NullableReader = NullableReader; + exports.RectangleReader = RectangleReader; + exports.ReflectiveReader = ReflectiveReader; + exports.SingleReader = SingleReader; + exports.SpriteFontReader = SpriteFontReader; + exports.StringReader = StringReader; + exports.TBinReader = TBinReader; + exports.Texture2DReader = Texture2DReader; + exports.UInt32Reader = UInt32Reader; + exports.Vector2Reader = Vector2Reader; + exports.Vector3Reader = Vector3Reader; + exports.Vector4Reader = Vector4Reader; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/dist/readers/readers.es5.min.js b/dist/readers/readers.es5.min.js new file mode 100644 index 0000000..57e0287 --- /dev/null +++ b/dist/readers/readers.es5.min.js @@ -0,0 +1,23 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,n=function(t){try{return!!t()}catch(t){return!0}},i=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=function(t){return t&&t.Math==Math&&t},o=u("object"==typeof globalThis&&globalThis)||u("object"==typeof window&&window)||u("object"==typeof self&&self)||u("object"==typeof e&&e)||function(){return this}()||Function("return this")(),a=function(t){return"function"==typeof t},s=a,c=function(t){return"object"==typeof t?null!==t:s(t)},l=!n((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),f=l,h=Function.prototype,v=h.bind,y=h.call,p=f&&v.bind(y,y),d=f?function(t){return t&&p(t)}:function(t){return t&&function(){return y.apply(t,arguments)}},w=o.TypeError,m=function(t){if(null==t)throw w("Can't call method on "+t);return t},g=o.Object,k=function(t){return g(m(t))},b=k,_=d({}.hasOwnProperty),x=Object.hasOwn||function(t,e){return _(b(t),e)},S={exports:{}},T=o,O=Object.defineProperty,A=function(t,e){try{O(T,t,{value:e,configurable:!0,writable:!0})}catch(r){T[t]=e}return e},M=A,R="__core-js_shared__",z=o[R]||M(R,{}),V=z;(S.exports=function(t,e){return V[t]||(V[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var j,I,E=d,C=0,P=Math.random(),F=E(1..toString),D=function(t){return"Symbol("+(void 0===t?"":t)+")_"+F(++C+P,36)},B=o,U=a,X=function(t){return U(t)?t:void 0},L=function(t,e){return arguments.length<2?X(B[t]):B[t]&&B[t][e]},W=o,N=L("navigator","userAgent")||"",G=W.process,Y=W.Deno,q=G&&G.versions||Y&&Y.version,K=q&&q.v8;K&&(I=(j=K.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=o,tt=S.exports,et=x,rt=D,nt=$,it=H,ut=tt("wks"),ot=Q.Symbol,at=ot&&ot.for,st=it?ot:ot&&ot.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(ot,t)?ut[t]=ot[t]:ut[t]=it&&at?at(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,vt=ht({}.toString),yt=ht("".slice),pt=function(t){return yt(vt(t),8,-1)},dt=o,wt=ft,mt=a,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},St=o.String,Tt=function(t){try{return St(t)}catch(t){return"Object"}},Ot={},At=c,Mt=o.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=o,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Dt=l,Bt=Function.prototype.call,Ut=Dt?Bt.bind(Bt):function(){return Bt.apply(Bt,arguments)},Xt=d({}.isPrototypeOf),Lt=L,Wt=a,Nt=Xt,Gt=H,Yt=o.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Lt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=a,Jt=Tt,Zt=o.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=a,ee=c,re=o.TypeError,ne=Ut,ie=c,ue=qt,oe=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},ae=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=o.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=oe(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),ae(t,e)},he=qt,ve=i,ye=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=o.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ve?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ye)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Se=Ot,Te=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Se.f(t,e,Te(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=a,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,De,Be,Ue=Ce.inspectSource,Xe=a,Le=Ue,We=o.WeakMap,Ne=Xe(We)&&/native code/.test(Le(We)),Ge=S.exports,Ye=D,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=o,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,or=Ze.WeakMap;if(Je||er.state){var ar=er.state||(er.state=new or),sr=$e(ar.get),cr=$e(ar.has),lr=$e(ar.set);Fe=function(t,e){if(cr(ar,t))throw new ur(ir);return e.facade=t,lr(ar,t,e),e},De=function(t){return sr(ar,t)||{}},Be=function(t){return cr(ar,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},De=function(t){return tr(t,fr)?t[fr]:{}},Be=function(t){return tr(t,fr)}}var hr={set:Fe,get:De,has:Be,enforce:function(t){return Be(t)?De(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=De(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},vr=n,yr=a,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!vr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return yr(this)&&kr(this).source||mr(this)}),"toString");var Sr,Tr,Or,Ar=o,Mr=a,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=o,Er=x,Cr=a,Pr=k,Fr=jr,Dr=Ke("IE_PROTO"),Br=Ir.Object,Ur=Br.prototype,Xr=Fr?Br.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Dr))return e[Dr];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Br?Ur:null},Lr=o,Wr=a,Nr=Lr.String,Gr=Lr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=o,Qr=a,tn=c,en=x,rn=xt,nn=Tt,un=Oe,on=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,a=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,a,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!o&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},an=Ot.f,sn=Xt,cn=Xr,ln=Jr,fn=ct,hn=D,vn=Hr.Int8Array,yn=vn&&vn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=vn&&cn(vn),mn=yn&&cn(yn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Sn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Tn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Sr in On)(Or=(Tr=Hr[Sr])&&Tr.prototype)?un(Or,xn,Tr):Sn=!1;for(Sr in An)(Or=(Tr=Hr[Sr])&&Tr.prototype)&&un(Or,xn,Tr);if((!Sn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr],wn);if((!Sn||!mn||mn===gn)&&(mn=wn.prototype,Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr].prototype,mn);if(Sn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Sr in Tn=!0,an(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Sr]&&un(Hr[Sr],_n,Sr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Sn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Tn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||on(mn,t,r?e:Sn&&yn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return on(wn,t,r?e:Sn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||on(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=o.Object,Fn=In("".split),Dn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Bn=Math.ceil,Un=Math.floor,Xn=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Bn)(e)},Ln=Math.min,Wn=function(t){return t>0?Ln(Xn(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=a,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=L("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,oi=o,ai=Gn,si=ui,ci=c,li=ct("species"),fi=oi.Array,hi=function(t){var e;return ai(t)&&(e=t.constructor,(si(e)&&(e===fi||ai(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},vi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},yi=Dn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,o=7==t,a=5==t||u;return function(s,c,l,f){for(var h,v,y=pi(s),p=yi(y),d=vi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||o?g(s,0):void 0;w>m;m++)if((a||m in p)&&(v=d(h=p[m],m,y),t))if(e)k[m]=v;else if(v)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=Tt,xi=o.TypeError,Si=Ft,Ti=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Si(t).constructor;return void 0===n||null==(r=Si(n)[Oi])?e:Ti(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Di=Ci(Fi.toString),Bi=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Bi.exec);function Xi(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Li(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),ru=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(eu),nu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return(new fu).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}},{key:"write",value:function(t,e,r){new fu,t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.isValueType()?this.reader.read(t):e.read(t)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),o=0;o=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Su(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Tu(t)}for(var v=0;v0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,o=Du(t),a=Du(e);if(o<=a)u=r.slice();else{var s=[a,o];o=s[0],a=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Bu(o,a,u,n,i)}function Xu(t,e,r,n,i){var u,o=Du(t),a=Du(e);if(o=128||!i)){var h=this._remap[a],v=(e[4*o+3]+1)/256;this._weights[h]+=u?v:1,this._remap[o]=h;break}}else this._remap[o]=-1}for(var y=0;y=n?t:(n=o,u)}),0);return i+=n,u}));if(ia&&(u=r[c],a=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,o=i.weights;return n.principle=ju(u,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),o=u.splatW,a=Vu.multiplyAdd(r,i,n);return{ax:u,aa:o,bx:a,bb:a.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),o=new Vu(2/3,2/3,2/3,4/9),a=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,o,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,o,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(a,Vu.add(r,n)).splatW}}),(function(r,n,i){return Xu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),o=r.computeOptimalPoints(u);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),o=0;o15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*l&255;n[o]=f,o++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function to(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),o=Hu(i);return[u,o,Qu(u,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,o,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),o=0;o<16;o++)for(var a=0;a<4;a++)t[4*o+a]=i[u[o]][a]}function eo(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ro(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function no(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,o=void 0===u?0:u,a=r.width,s=void 0===a?0:a,c=r.height,l=void 0===c?0:c,f=0;eo((function(r,n){var u=i+r,a=o+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),o=new Uint8Array(16),a=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var v=l>>3*h&7;o[a]=v,a++}}for(var y=0;y<16;++y)t[4*y+3]=u[o[y]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function oo(t,e,r,n,i){var u=0!=(1&(i=ro(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,o=e.width,a=void 0===o?0:o,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return eo((function(e,r){var i=n+e,o=u+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(4==n)s=fo(s,i,u,ao);else if(5==n)s=fo(s,i,u,so);else if(6==n)s=fo(s,i,u,co);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),po=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),wo=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),o=r.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + + } + + class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + + } + + class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + + } + + const UTF16_BITES = [0xD800, 0xDC00]; + const UTF16_MASK = 0b1111111111; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + + } + + class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + + } + + class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + + } + + class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + + } + + class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + + } + + class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + + } + + class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + + } + + class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + + } + + class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const hasValue = booleanReader.read(buffer); + return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + } + + write(buffer, content, resolver) { + buffer.writeByte(content != null); + if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + + } + + class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + + } + + class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + + } + + class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + + } + + const kDxt1 = 1 << 0; + const kDxt3 = 1 << 1; + const kDxt5 = 1 << 2; + const kColourIterativeClusterFit = 1 << 8; + const kColourClusterFit = 1 << 3; + const kColourRangeFit = 1 << 4; + const kColourMetricPerceptual = 1 << 5; + const kColourMetricUniform = 1 << 6; + const kWeightColourByAlpha = 1 << 7; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } + + function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } + + function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; + } + + function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; + } + + function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; + } + + function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; + } + + function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); + } + + function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; + } + + function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; + } + + class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + + } + + class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + + } + + function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } + + function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); + } + + const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + + function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } + + function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } + + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } + } + + function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + + } + + class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + + } + + class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + + } + + class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + + } + + class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + + } + + function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; + } + + function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } + } + + function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } + + function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; + } + + function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; + } + + function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; + } + + function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; + } + + function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } + } + + function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; + } + + function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; + } + + function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } + + function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; + } + + function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } + } + + function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } + } + + function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } + } + + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ + const DXT1_COMPRESSED_BYTES = 8; + const DXT5_COMPRESSED_BYTES = 16; + const COLORS = 4; + const DECOMPRESSED_BLOCK_SIZE = 16; + + function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } + } + + function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } + } + + function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; + } + + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } + + function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; + } + + function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } + + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } + + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } + + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); + } + + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } + + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } + } + + const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; + + function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; + } + + function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; + } + + class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + + } + + class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + + } + + class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + + } + + class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + + } + + class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + + } + + exports.ArrayReader = ArrayReader; + exports.BaseReader = BaseReader; + exports.BmFontReader = BmFontReader; + exports.BooleanReader = BooleanReader; + exports.CharReader = CharReader; + exports.DictionaryReader = DictionaryReader; + exports.DoubleReader = DoubleReader; + exports.EffectReader = EffectReader; + exports.Int32Reader = Int32Reader; + exports.LightweightTexture2DReader = LightweightTexture2DReader; + exports.ListReader = ListReader; + exports.NullableReader = NullableReader; + exports.RectangleReader = RectangleReader; + exports.ReflectiveReader = ReflectiveReader; + exports.SingleReader = SingleReader; + exports.SpriteFontReader = SpriteFontReader; + exports.StringReader = StringReader; + exports.TBinReader = TBinReader; + exports.Texture2DReader = Texture2DReader; + exports.UInt32Reader = UInt32Reader; + exports.Vector2Reader = Vector2Reader; + exports.Vector3Reader = Vector3Reader; + exports.Vector4Reader = Vector4Reader; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/dist/readers/readers.min.js b/dist/readers/readers.min.js new file mode 100644 index 0000000..76d17b6 --- /dev/null +++ b/dist/readers/readers.min.js @@ -0,0 +1,24 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";class e{static isTypeOf(t){return!1}static hasSubType(){return!1}static parseTypeList(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){return(new o).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}write(t,e,r){t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:r)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class w extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const f=256;//! Use DXT1 compression. +//! Weight the colour by alpha during cluster fit (disabled by default). +function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function T(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...T(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function X(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class B{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class D{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class U extends D{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>X(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>X(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class P extends D{constructor(t){super(t);this.iterationCount=t.flags&f?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>X(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=f&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new w,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new w,a=new h(n),o=new ot,f=new c(new d),p=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),f.write(t,e.glyphs,r),f.write(t,e.cropping,r),p.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/readers/readers.module.js b/dist/readers/readers.module.js new file mode 100644 index 0000000..9f3e7b1 --- /dev/null +++ b/dist/readers/readers.module.js @@ -0,0 +1,2668 @@ +class BaseReader { + static isTypeOf(type) { + return false; + } + + static hasSubType() { + return false; + } + + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + +} + +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + +} + +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + +} + +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + +} + +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + +} + +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + +} + +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + +} + +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + +} + +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + +} + +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + +} + +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const hasValue = booleanReader.read(buffer); + return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + } + + write(buffer, content, resolver) { + buffer.writeByte(content != null); + if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + +} + +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + +} + +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + +} + +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + +} + +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} + +function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} + +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; +} + +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; +} + +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; +} + +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; +} + +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); +} + +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} + +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + +} + +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + +} + +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} + +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} + +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} + +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} + +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } +} + +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + +} + +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + +} + +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} + +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; +} + +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; +} + +function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; +} + +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; +} + +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; +} + +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } +} + +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } +} + +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } +} + +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } +} + +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} + +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} + +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} + +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; +} + +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} + +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} + +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} + +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); +} + +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} + +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } +} + +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; + +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; +} + +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; +} + +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + +} + +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + +} + +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + +} + +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + +} + +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + +} + +export { ArrayReader, BaseReader, BmFontReader, BooleanReader, CharReader, DictionaryReader, DoubleReader, EffectReader, Int32Reader, LightweightTexture2DReader, ListReader, NullableReader, RectangleReader, ReflectiveReader, SingleReader, SpriteFontReader, StringReader, TBinReader, Texture2DReader, UInt32Reader, Vector2Reader, Vector3Reader, Vector4Reader }; diff --git a/dist/xnb.cjs b/dist/xnb.cjs index 178ac06..beadf3f 100644 --- a/dist/xnb.cjs +++ b/dist/xnb.cjs @@ -19,11 +19,152 @@ const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettl return Promise.all(mappedPromises); }; +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; const UTF8_SECOND_BITES = 0x80; const UTF8_MASK = 0b111111; -const UTF16_BITES = [0xD800, 0xDC00]; -const UTF16_MASK = 0b1111111111; +const UTF16_BITES$2 = [0xD800, 0xDC00]; +const UTF16_MASK$2 = 0b1111111111; function UTF8Encode(code) { if (code < 0x80) return [code]; @@ -35,7 +176,7 @@ function UTF8Encode(code) { function UTF16Encode(code) { if (code < 0xFFFF) return [code]; code -= 0x10000; - return [UTF16_BITES[0] | code >> 10 & UTF16_MASK, UTF16_BITES[1] | code & UTF16_MASK]; + return [UTF16_BITES$2[0] | code >> 10 & UTF16_MASK$2, UTF16_BITES$2[1] | code & UTF16_MASK$2]; } function UTF8Decode(codeSet) { @@ -54,17 +195,17 @@ function UTF8Decode(codeSet) { return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); } -function UTF16Decode(codeSet) { +function UTF16Decode$2(codeSet) { var _codeSet2; if (typeof codeSet === "number") codeSet = [codeSet]; if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); const codeSetRange = codeSet.length; if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + return ((codeSet[0] & UTF16_MASK$2) << 10) + (codeSet[1] & UTF16_MASK$2) + 0x10000; } -function stringToUnicode(str) { +function stringToUnicode$2(str) { const utf16Map = Array.from({ length: str.length }, (_, i) => str.charCodeAt(i)); @@ -74,11 +215,11 @@ function stringToUnicode(str) { while (index < str.length) { let code = utf16Map[index]; - if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + if ((UTF16_BITES$2[0] & code) !== UTF16_BITES$2[0]) { result.push(code); index++; } else { - result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + result.push(UTF16Decode$2(utf16Map.slice(index, index + 2))); index += 2; } } @@ -140,7 +281,7 @@ function UnicodeToString(unicodeArr) { } function stringToUTF8(str) { - return UnicodeToUTF8(stringToUnicode(str)); + return UnicodeToUTF8(stringToUnicode$2(str)); } function UTF8ToString(utf8Array) { @@ -572,17 +713,43 @@ class BufferWriter { } -class XnbError extends Error { - constructor() { - let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - super(message); - this.name = this.constructor.name; - this.message = message; - Error.captureStackTrace(this, XnbError); - } - -} - +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ const MIN_MATCH = 2; const NUM_CHARS = 256; const BLOCKTYPE = { @@ -1078,6 +1245,9 @@ class LZ4Utils { } +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ const minMatch = 4; const minLength = 13; const searchLimit = 5; @@ -1292,56 +1462,43 @@ function compressSingleBlock(src, dst) { return compressBlock(src, dst, 0, src.length, hashTable); } -class ReaderResolver { - constructor(readers) { - this.readers = readers; - } - - read(buffer) { - let index = buffer.read7BitNumber() - 1; - if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); - return this.readers[index].read(buffer, this); - } - - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; - getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; - } +function UTF16Decode$1(codeSet) { + var _codeSet2; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; } -class BaseReader { - isValueType() { - return true; - } - - get type() { - return this.constructor.name.slice(0, -6); - } - - read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - writeIndex(buffer, resolver) { - if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); - } + while (index < str.length) { + let code = utf16Map[index]; - toString() { - return this.type; + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } } + return result; } -function UTF8Length(str) { - const codes = stringToUnicode(str); +function UTF8Length$1(str) { + const codes = stringToUnicode$1(str); return codes.reduce((sum, unicode) => { if (unicode < 0x80) return sum + 1; if (unicode < 0x800) return sum + 2; @@ -1350,6138 +1507,6442 @@ function UTF8Length(str) { }, 0); } -class StringReader extends BaseReader { +class StringReaderCore { read(buffer) { let length = buffer.read7BitNumber(); return buffer.readString(length); } - write(buffer, string, resolver) { - this.writeIndex(buffer, resolver); - const size = UTF8Length(string); + write(buffer, string) { + const size = UTF8Length$1(string); buffer.write7BitNumber(size); buffer.writeString(string); } - isValueType() { - return false; - } - } -class UInt32Reader extends BaseReader { +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + read(buffer) { - return buffer.readUInt32(); + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; } } -class ArrayReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - let size = uint32Reader.read(buffer); - let array = []; + get target() { + var _this$header; - for (let i = 0; i < size; i++) { - let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - array.push(value); - } + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; - return array; - } + case 'm': + return "Windows Phone 7"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, resolver); + case 'x': + return "Xbox 360"; - for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); - } + case 'a': + return "Android"; - isValueType() { - return false; - } + case 'i': + return "iOS"; - get type() { - return "Array<".concat(this.reader.type, ">"); + default: + return "Unknown"; + } } -} + get formatVersion() { + var _this$header2; -class BmFontReader extends BaseReader { - read(buffer) { - const stringReader = new StringReader(); - const xml = stringReader.read(buffer); - return { - export: { - type: this.type, - data: xml - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); - } - - isValueType() { - return false; - } - -} - -class BooleanReader extends BaseReader { - read(buffer) { - return Boolean(buffer.readInt()); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; -} + case 0x4: + return "XNA Game Studio 3.1"; -class CharReader extends BaseReader { - read(buffer) { - let charSize = this._getCharSize(buffer.peekInt()); + case 0x5: + return "XNA Game Studio 4.0"; - return buffer.readString(charSize); + default: + return "Unknown"; + } } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } + get hidef() { + var _this$header3; - _getCharSize(byte) { - return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); } -} + get compressed() { + var _this$header4; -class DictionaryReader extends BaseReader { - constructor(key, value) { - if (key == undefined || value == undefined) throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - super(); - this.key = key; - this.value = value; + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); } - read(buffer, resolver) { - let dictionary = {}; - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - for (let i = 0; i < size; i++) { - let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - dictionary[key] = value; - } - - return dictionary; + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(Object.keys(content).length); - - for (let key of Object.keys(content)) { - this.key.write(buffer, key, this.key.isValueType() ? null : resolver); - this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); - } + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); } - isValueType() { - return false; + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); } - get type() { - return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + toString() { + return this.stringify(); } } -class DoubleReader extends BaseReader { - read(buffer) { - return buffer.readDouble(); - } +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } + case "yaml": + return "yaml"; -} + case "png": + return "Texture2D"; -class EffectReader extends BaseReader { - read(buffer) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const bytecode = buffer.read(size); - return { - export: { - type: this.type, - data: bytecode - } - }; - } + case "cso": + return "Effect"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + case 'tbin': + return "TBin"; - isValueType() { - return false; + case 'xml': + return "BmFont"; } + return "Others"; } -class Int32Reader extends BaseReader { - read(buffer) { - return buffer.readInt32(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; } } -class ListReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const list = []; + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); - for (let i = 0; i < size; i++) { - const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } + this._validateHeader(); - return list; - } + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); - for (let data of Object.values(content)) { - this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock$1(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } } - } - - get type() { - return "List<".concat(this.reader.type, ">"); - } -} + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; -class NullableReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } - read(buffer, resolver) { - const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); - } - - isValueType() { - return false; - } - - get type() { - return "Nullable<".concat(this.reader.type, ">"); - } - -} + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); -class RectangleReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const x = int32Reader.read(buffer); - const y = int32Reader.read(buffer); - const width = int32Reader.read(buffer); - const height = int32Reader.read(buffer); - return { - x, - y, - width, - height - }; - } + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); - } + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); -} + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } -class SingleReader extends BaseReader { - read(buffer) { - return buffer.readSingle(); + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; } } -const kDxt1 = 1 << 0; -const kDxt3 = 1 << 1; -const kDxt5 = 1 << 2; -const kColourIterativeClusterFit = 1 << 8; -const kColourClusterFit = 1 << 3; -const kColourRangeFit = 1 << 4; -const kColourMetricPerceptual = 1 << 5; -const kColourMetricUniform = 1 << 6; -const kWeightColourByAlpha = 1 << 7; +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; -function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); - } + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } - return keys; -} + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } + for (; i < n;) { + let e = t.charCodeAt(i++); - return target; -} + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } + if (e >= 55296 && e <= 56319) continue; + } - return obj; -} + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } -function Rot(theta) { - let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; - return Mat; -} + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } -function Rij(k, l, theta, N) { - let Mat = Array(N); + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = (i === j) * 1.0; - } + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); } +}, + e = {}; - let Rotij = Rot(theta); - Mat[k][k] = Rotij[0][0]; - Mat[l][l] = Rotij[1][1]; - Mat[k][l] = Rotij[0][1]; - Mat[l][k] = Rotij[1][0]; - return Mat; +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; } -function getTheta(aii, ajj, aij) { - let th = 0.0; - let denom = ajj - aii; - - if (Math.abs(denom) <= 1E-12) { - th = Math.PI / 4.0; - } else { - th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); - } +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; - return th; -} +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); -function getAij(Mij) { - let N = Mij.length; - let maxMij = 0.0; - let maxIJ = [0, 1]; + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } - for (let i = 0; i < N; i++) { - for (let j = i + 1; j < N; j++) { - if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { - maxMij = Math.abs(Mij[i][j]); - maxIJ = [i, j]; - } + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; } - } - return [maxIJ, maxMij]; -} + isLittleEndian() { + return this.littleEndian; + } -function unitary(U, H) { - let N = U.length; - let Mat = Array(N); + setLittleEndian() { + return this.littleEndian = !0, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + isBigEndian() { + return !this.littleEndian; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + setBigEndian() { + return this.littleEndian = !1, this; + } - for (let k = 0; k < N; k++) { - for (let l = 0; l < N; l++) { - Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; - } - } + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; } - } - return Mat; -} + seek(t) { + return this.offset = t, this; + } -function AxB(A, B) { - let N = A.length; - let Mat = Array(N); + mark() { + return this._mark = this.offset, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + reset() { + return this.offset = this._mark, this; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + pushMark() { + return this._marks.push(this.offset), this; + } - for (let k = 0; k < N; k++) { - Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; - } + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; } - } - return Mat; -} + rewind() { + return this.offset = 0, this; + } -function eigens(Hij) { - let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; - let N = Hij.length; - let Ei = Array(N); - let e0 = Math.abs(convergence / N); - let Sij = Array(N); + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - for (let i = 0; i < N; i++) { - Sij[i] = Array(N); - } + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Sij[i][j] = (i === j) * 1.0; + return this; } - } - let Vab = getAij(Hij); + readBoolean() { + return 0 !== this.readUint8(); + } - while (Math.abs(Vab[1]) >= Math.abs(e0)) { - let i = Vab[0][0]; - let j = Vab[0][1]; - let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); - let Gij = Rij(i, j, psi, N); - Hij = unitary(Gij, Hij); - Sij = AxB(Sij, Gij); - Vab = getAij(Hij); - } + readInt8() { + return this._data.getInt8(this.offset++); + } - for (let i = 0; i < N; i++) { - Ei[i] = Hij[i][i]; - } + readUint8() { + return this._data.getUint8(this.offset++); + } - return sorting(Ei, Sij); -} + readByte() { + return this.readUint8(); + } -function sorting(values, vectors) { - let eigsCount = values.length; - vectors.length; - let pairs = Array.from({ - length: eigsCount - }, (_, i) => { - let vector = vectors.map(v => v[i]); - return { - value: values[i], - vec: vector - }; - }); - pairs.sort((a, b) => b.value - a.value); - let sortedValues = pairs.map(_ref => { - let { - value - } = _ref; - return value; - }); - let sortedVectors = pairs.map(_ref2 => { - let { - vec - } = _ref2; - return vec; - }); - return [sortedValues, sortedVectors]; -} + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); -function dominentPrincipalVector(matrix) { - let [, [dominentVector]] = eigens(matrix); - return dominentVector; -} + for (let i = 0; i < t; i++) e[i] = this.readByte(); -class Vec3 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values = [x, y, z]; - } + return e; + } - get x() { - return this._values[0]; - } + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); - get y() { - return this._values[1]; - } + return this.offset += 2, t; + } - get z() { - return this._values[2]; - } + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); - set x(value) { - this._values[0] = value; - } + return this.offset += 2, t; + } - set y(value) { - this._values[1] = value; - } + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); - set z(value) { - this._values[2] = value; - } + return this.offset += 4, t; + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } + return this.offset += 4, t; + } - get normalized() { - if (this.length === 0) return null; - return Vec3.multScalar(this, 1 / this.length); - } + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); - get colorInt() { - const floatToInt = value => { - const result = parseInt(value * 255 + 0.5); - return Math.max(Math.min(result, 255), 0); - }; + return this.offset += 4, t; + } - return this._values.map(floatToInt); - } + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); - clone() { - return new Vec3(this.x, this.y, this.z); - } + return this.offset += 8, t; + } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - return this; - } + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); - toVec4() { - let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return new Vec4(this.x, this.y, this.z, w); - } + return this.offset += 8, t; + } - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - return this; - } + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - return this; - } + return this.offset += 8, t; + } - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - return this; - } + readChar() { + return String.fromCharCode(this.readInt8()); + } - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - return this; - } + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (let i = 0; i < t; i++) e += this.readChar(); - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - return this; - } + return e; + } - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - return this; - } + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - return this; - } + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } - toString() { - return "Vec3( ".concat(this._values.join(", "), " )"); - } + writeByte(t) { + return this.writeUint8(t); + } - static add(a, b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } + writeBytes(t) { + this.ensureAvailable(t.length); - static sub(a, b) { - return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); - } + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z; - } + return this._updateLastWrittenByte(), this; + } - static multScalar(a, scalar) { - return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); - } + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static multVector(a, b) { - return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); - } + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static interpolate(a, b, p) { - let a_ = Vec3.multScalar(a, 1 - p); - let b_ = Vec3.multScalar(b, p); - return Vec3.add(a_, b_); - } + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } -} + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } -class Vec4 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values = [x, y, z, w]; - } + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } - get x() { - return this._values[0]; - } + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get y() { - return this._values[1]; - } + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get z() { - return this._values[2]; - } + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get w() { - return this._values[3]; - } + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } - set x(value) { - this._values[0] = value; - } + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); - set y(value) { - this._values[1] = value; - } + return this; + } - set z(value) { - this._values[2] = value; - } + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } - set w(value) { - this._values[3] = value; - } + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); - } + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; } - get normalized() { - if (this.length === 0) return null; - return Vec4.multScalar(this, 1 / this.length); - } + function s(t) { + let e = t.length; - get xyz() { - return new Vec3(this.x, this.y, this.z); + for (; --e >= 0;) t[e] = 0; } - get splatX() { - return new Vec4(this.x); - } + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); - get splatY() { - return new Vec4(this.y); - } + const _ = new Array(60); - get splatZ() { - return new Vec4(this.z); - } + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); - get splatW() { - return new Vec4(this.w); + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; } - clone() { - return new Vec4(this.x, this.y, this.z, this.w); + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - this._values[3] = w; - return this; - } + s(w); - toVec3() { - return this.xyz; - } + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - return this; - } + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - return this; - } + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; - subVector(v) { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - return this; - } + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - return this; - } + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - return this; - } + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; - reciprocal() { - this._values[0] = 1 / this._values[0]; - this._values[1] = 1 / this._values[1]; - this._values[2] = 1 / this._values[2]; - this._values[3] = 1 / this._values[3]; - return this; - } + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - return this; - } + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - return this; - } + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; - truncate() { - this._values[0] = Math.trunc(this._values[0]); - this._values[1] = Math.trunc(this._values[1]); - this._values[2] = Math.trunc(this._values[2]); - this._values[3] = Math.trunc(this._values[3]); - return this; - } + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - return this; - } + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); - toString() { - return "Vec4( ".concat(this._values.join(", "), " )"); - } + h = s; - static add(a, b) { - return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); - } + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); - static sub(a, b) { - return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); - } + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; - } + let l, + d, + _, + f, + c, + u, + w = 0; - static multScalar(a, scalar) { - return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); - } + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; - static multVector(a, b) { - return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); - } + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); - static interpolate(a, b, p) { - let a_ = Vec4.multScalar(a, 1 - p); - let b_ = Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; - static multiplyAdd(a, b, c) { - return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); - } + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); - static negativeMultiplySubtract(a, b, c) { - return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); - } + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - static compareAnyLessThan(left, right) { - return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; - } + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; -} + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; -function computeWeightedCovariance(values, weights) { - let total = 0; - let mean = values.reduce((sum, value, i) => { - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1 / total); - let covariance = values.reduce((sum, value, i) => { - let weight = weights[i]; - let v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; - sum[0][1] += v.x * v.y * weight; - sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; - sum[1][2] += v.y * v.z * weight; - sum[2][2] += v.z * v.z * weight; - return sum; - }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - return covariance; -} - -function computePCA(values, weights) { - const covariance = computeWeightedCovariance(values, weights); - return new Vec3(...dominentPrincipalVector(covariance)); -} - -const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; -const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - -function floatToInt(value, limit) { - const integer = parseInt(value + 0.5); - if (integer < 0) return 0; - if (integer > limit) return integer; - return integer; -} - -function floatTo565(color) { - const r = floatToInt(31.0 * color.x, 31); - const g = floatToInt(63.0 * color.y, 63); - const b = floatToInt(31.0 * color.z, 31); - return r << 11 | g << 5 | b; -} - -function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { - result[blockOffset + 0] = firstColor & 0xff; - result[blockOffset + 1] = firstColor >> 8; - result[blockOffset + 2] = secondColor & 0xff; - result[blockOffset + 3] = secondColor >> 8; - - for (let y = 0; y < 4; y++) { - result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; - } -} - -function writeColourBlock3(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + let D = !1; - if (firstColor <= secondColor) { - remapped = indices.slice(); - } else { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); - } + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); -function writeColourBlock4(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; - if (firstColor < secondColor) { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => (index ^ 0x1) & 0x3); - } else if (firstColor == secondColor) { - remapped = new Array(16).fill(0); - } else { - remapped = indices.slice(); - } + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; -class ColorSet { - constructor(rgba, mask, flags) { - this.flags = flags; - this._count = 0; - this._transparent = false; - this._remap = []; - this._weights = []; - this._points = []; - const isDxt1 = (this.flags & kDxt1) != 0; - const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + for (e = 0; e <= 15; e++) s[e] = 0; - for (let i = 0; i < 16; i++) { - const bit = 1 << i; + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; - if ((mask & bit) == 0) { - this._remap[i] = -1; - continue; - } + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; - if (isDxt1 && rgba[4 * i + 3] < 128) { - this._remap[i] = -1; - this._transparent = true; - continue; - } + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; - for (let j = 0;; j++) { - if (j == i) { - const r = rgba[4 * i] / 255.0; - const g = rgba[4 * i + 1] / 255.0; - const b = rgba[4 * i + 2] / 255.0; - const a = (rgba[4 * i + 3] + 1) / 256.0; - this._points[this._count] = new Vec3(r, g, b); - this._weights[this._count] = weightByAlpha ? a : 1.0; - this._remap[i] = this._count; - this._count++; - break; - } + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; - const oldbit = 1 << j; - const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); - if (match) { - const index = this._remap[j]; - const w = (rgba[4 * i + 3] + 1) / 256.0; - this._weights[index] += weightByAlpha ? w : 1.0; - this._remap[i] = index; - break; - } - } - } + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; - for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); - } + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; - get transparent() { - return this._transparent; - } + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; - get count() { - return this._count; - } + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; - get points() { - return Object.freeze(this._points.slice()); - } + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; - get weights() { - return Object.freeze(this._weights.slice()); - } + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); - remapIndicesSingle(singleIndex, target) { - const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; - target.forEach((_, i) => target[i] = result[i]); - } + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); - remapIndices(indexMap, target) { - const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; - target.forEach((_, i) => target[i] = result[i]); - } + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; -} + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); -class ColorFit { - constructor(colorSet) { - this.colors = colorSet; - this.flags = colorSet.flags; - } + r %= 65521, s %= 65521; + } - compress(result, offset) { - const isDxt1 = (this.flags & kDxt1) != 0; + return r | s << 16 | 0; + }; - if (isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } else this.compress4(result, offset); - } + const F = new Uint32Array((() => { + let t, + e = []; - compress3(result, offset) {} + for (var i = 0; i < 256; i++) { + t = i; - compress4(result, offset) {} + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; -} + e[i] = t; + } -class SingleColourFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const singleColor = colorSet.points[0]; - this.color = singleColor.colorInt; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.index = 0; - this.error = Infinity; - this.bestError = Infinity; - } + return e; + })()); - compressBase(lookups, saveFunc) { - this.computeEndPoints(lookups); + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; - if (this.error < this.bestError) { - const indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - this.bestError = this.error; - } - } + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; - compress3(result, offset) { - const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; - this.compressBase(lookups, saveFunc); - } + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; - compress4(result, offset) { - const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + for (; --e >= 0;) t[e] = 0; + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; - this.compressBase(lookups, saveFunc); - } + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); - computeEndPoints(lookups) { - this.error = Infinity; + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; - for (let index = 0; index < 2; index++) { - const sources = []; - let error = 0; + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); - for (let channel = 0; channel < 3; channel++) { - const lookup = lookups[channel]; - const target = this.color[channel]; - sources[channel] = lookup[target][index]; - const diff = sources[channel][2]; - error += diff * diff; + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } } + } while ((e = _[e & d]) > h && 0 != --r); - if (error < this.error) { - this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); - this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); - this.index = 2 * index; - this.error = error; - } - } - } + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; -} + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; -class RangeFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - this.metric = new Vec3(1); + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722); - } + n = e, i = n; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.bestError = Infinity; - this.computePoints(); - } + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); - compressBase(codes, saveFunc) { - const { - points: values - } = this.colors; - let error = 0; - const closest = values.map(color => { - let minDist = Infinity; - const packedIndex = codes.reduce((idx, code, j) => { - const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; - if (dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - error += minDist; - return packedIndex; - }); + s += e; + } - if (error < this.bestError) { - let indices = new Uint8Array(16); - this.colors.remapIndices(closest, indices); - saveFunc(this.start, this.end, indices); - this.bestError = error; - } - } + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; - compress3(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; - this.compressBase(codes, saveFunc); - } + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); - compress4(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; - this.compressBase(codes, saveFunc); - } + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - computePoints() { - const { - count, - points: values, - weights - } = this.colors; - if (count <= 0) return; - const principle = computePCA(values, weights); - let start, end, min, max; - start = end = values[0]; - min = max = Vec3.dot(start, principle); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; - for (let i = 1; i < count; i++) { - let value = Vec3.dot(values[i], principle); + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); - if (value < min) { - start = values[i]; - min = value; - } else if (value > max) { - end = values[i]; - max = value; - } + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; } - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; } -} + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; -class ClusterFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const kMaxIterations = 8; - this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; - this.bestError = Infinity; - this.metric = new Vec4(1); + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722, 0); + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - const { - points: values, - weights - } = this.colors; - this.principle = computePCA(values, weights); - this.order = new Uint8Array(16 * kMaxIterations); - this.pointsWeights = []; - this.xSum_wSum = new Vec4(0); - } - - constructOrdering(axis, iteration) { - const currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration); - const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if (!uniqueOrder) return false; - this.copyOrderWeight(currentOrder); - return true; - } - - compress3(result, offset) { - const aabbx = _ref => { - let [part0,, part1, part2] = _ref; - const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); - const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; - this.compressBase(aabbx, saveFunc, 2); + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; } - compress4(result, offset) { - const aabbx = _ref2 => { - let [part0, part1, part2, part3] = _ref2; - const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); - const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); - const const2_9 = new Vec4(2 / 9); - const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; - this.compressBase(aabbx, saveFunc, 3); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; - compressBase(aabbFunc, saveFunc) { - let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - this.constructOrdering(this.principle, 0); - let best = { - start: new Vec4(0), - end: new Vec4(0), - error: this.bestError, - iteration: 0, - bestI: 0, - bestJ: 0 - }; - if (repeater === 3) best.bestK = 0; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - const leastSquares = (parts, internalIndices) => { - const aabbx = aabbFunc(parts); - const internalBest = this.computeOptimalPoints(aabbx); + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (internalBest.error < best.error) { - best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); - return true; - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; - return false; - }; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - for (let iterationIndex = 0;;) { - this.clusterIterate(iterationIndex, leastSquares, repeater); - if (best.iteration != iterationIndex) break; - iterationIndex++; - if (iterationIndex == this.iterationCount) break; - const newAxis = Vec4.sub(best.end, best.start).xyz; - if (!this.constructOrdering(newAxis, iterationIndex)) break; - } + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (best.error < this.bestError) this.saveBlock(best, saveFunc); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; - makeOrder(axis) { - const { - count, - points: values - } = this.colors; - const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); - return Array.from({ - length: count - }, (_, i) => i).sort((a, b) => { - if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; - return a - b; - }); - } + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); - copyOrderToThisOrder(order, iteration) { - const orderOffset = iteration * 16; - order.forEach((ord, i) => { - this.order[orderOffset + i] = ord; - }); - } + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); - checkOrderUnique(order, iteration) { - const { - count - } = this.colors; + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; - for (let it = 0; it < iteration; it++) { - let prevOffset = it * 16; - let same = true; + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } - for (let i = 0; i < count; i++) { - if (order[i] !== this.order[prevOffset + i]) { - same = false; - break; + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - } - if (same) return false; - } + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; - return true; - } + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } - copyOrderWeight(order) { - const { - count, - points: unweighted, - weights - } = this.colors; - this.xSum_wSum.set(0); + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; - for (let i = 0; i < count; i++) { - const j = order[i]; - const p = unweighted[j].toVec4(1); - const w = new Vec4(weights[j]); - const x = Vec4.multVector(p, w); - this.pointsWeights[i] = x; - this.xSum_wSum.addVector(x); - } - } + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); - computeOptimalPoints(vectorPoint) { - const { - ax, - bx, - aa, - bb, - ab - } = vectorPoint; - const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); - let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); - let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); - a.clampGrid(); - b.clampGrid(); - let error = this.computeError(_objectSpread2({ - a, - b - }, vectorPoint)); - return { - start: a, - end: b, - error - }; - } + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } - computeError(_ref3) { - let { - a, - b, - ax, - bx, - aa, - bb, - ab - } = _ref3; - const two = new Vec4(2); - const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); - const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); - const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); - const e4 = Vec4.multiplyAdd(two, e3, e1); - const e5 = Vec4.multVector(e4, this.metric); - return e5.x + e5.y + e5.z; - } + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - saveBlock(best, writeFunc) { - const { - count - } = this.colors; - const { - start, - end, - iteration, - error, - bestI, - bestJ, - bestK = -1 - } = best; - const orderOffset = iteration * 16; - const unordered = new Uint8Array(16); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } - const mapper = m => { - if (m < bestI) return 0; - if (m < bestJ) return 2; - if (m < bestK) return 3; - return 1; - }; + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; - for (let i = 0; i < count; i++) { - unordered[this.order[orderOffset + i]] = mapper(i); + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; } - const bestIndices = new Uint8Array(16); - this.colors.remapIndices(unordered, bestIndices); - writeFunc(start.xyz, end.xyz, bestIndices); - this.bestError = error; - } + const s = t.avail_in, + a = t.next_in, + o = t.input; - clusterIterate(index, func) { - let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - const { - count - } = this.colors; + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; - const indexMapper = (i, j, k) => { - const mapper = { - bestI: i, - bestJ: iterCount === 2 ? k : j, - iteration: index - }; - if (iterCount === 3) mapper.bestK = k; - return mapper; - }; + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); - let part0 = new Vec4(0.0); + n.strstart = t, n.lookahead = 2, zt(n); + } - for (let i = 0; i < count; i++) { - let part1 = new Vec4(0.0); + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; - for (let j = i;;) { - let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); - const kmin = j == 0 ? 1 : j; + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); - for (let k = kmin;;) { - const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - if (k == count) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); - if (iterCount === 2) break; - if (j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; - } + for (; e.length;) { + const i = e.shift(); - part0.addVector(this.pointsWeights[i]); + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } } - } -} + return t; + }, + Wt = t => { + let e = 0; -function quantise(alpha) { - const GRID = 15; - let result = Math.floor(alpha * (GRID / 255) + 0.5); - if (result < 0) return 0; - if (result > GRID) return GRID; - return result; -} + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; -function compressAlphaDxt3(rgba, mask, result, offset) { - for (let i = 0; i < 8; i++) { - let quant1 = quantise(rgba[8 * i + 3]); - let quant2 = quantise(rgba[8 * i + 7]); - const bit1 = 1 << 2 * i; - const bit2 = 1 << 2 * i + 1; - if ((mask & bit1) == 0) quant1 = 0; - if ((mask & bit2) == 0) quant2 = 0; - result[offset + i] = quant1 | quant2 << 4; - } -} + const i = new Uint8Array(e); -function compressAlphaDxt5(rgba, mask, result, offset) { - let step5 = interpolateAlpha(rgba, mask, 5); - let step7 = interpolateAlpha(rgba, mask, 7); - if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); -} + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } -function interpolateAlpha(rgba, mask, steps) { - let { - min, - max - } = setAlphaRange(rgba, mask, steps); - let code = setAlphaCodeBook(min, max, steps); - let indices = new Uint8Array(16); - let error = fitCodes(rgba, mask, code, indices); - return { - min, - max, - indices, - error + return i; }; -} - -function setAlphaRange(rgba, mask, steps) { - let min = 255; - let max = 0; - for (let i = 0; i < 16; i++) { - let bit = 1 << i; - if ((mask & bit) == 0) continue; - let value = rgba[4 * i + 3]; + let Kt = !0; - if (steps === 5) { - if (value !== 0 && value < min) min = value; - if (value !== 255 && value > max) max = value; - } else { - if (value < min) min = value; - if (value > max) max = value; - } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; } - if (min > max) min = max; - if (max - min < steps) max = Math.min(min + steps, 255); - if (max - min < steps) min = Math.max(max - steps, 0); - return { - min, - max - }; -} + const $t = new Uint8Array(256); -function setAlphaCodeBook(min, max, steps) { - let codes = [min, max, ...Array.from({ - length: steps - 1 - }, (_, i) => { - return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); - })]; + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - if (steps === 5) { - codes[6] = 0; - codes[7] = 255; - } + $t[254] = $t[254] = 1; - return codes; -} + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; -function fitCodes(rgba, mask, codes, indices) { - let err = 0; + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (let i = 0; i < 16; ++i) { - let bit = 1 << i; + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); - if ((mask & bit) == 0) { - indices[i] = 0; - continue; - } + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); - let value = rgba[4 * i + 3]; - let least = Infinity; - let index = 0; + for (r = 0, n = 0; n < i;) { + let e = t[n++]; - for (let j = 0; j < 8; ++j) { - let dist = value - codes[j]; - dist *= dist; + if (e < 128) { + s[r++] = e; + continue; + } - if (dist < least) { - least = dist; - index = j; + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); } } - indices[i] = index; - err += least; - } - - return err; -} + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; -function writeAlphaBlock5(_ref, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref; + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - if (index <= 5) return 7 - index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; -function writeAlphaBlock7(_ref2, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref2; + for (; i >= 0 && 128 == (192 & t[i]);) i--; - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - return 9 - index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; -function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { - result[offset] = alpha0; - result[offset + 1] = alpha1; - let indicesPointer = 0; - let resultPointer = offset + 2; + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; - for (let i = 0; i < 2; i++) { - let value = 0; + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); - for (let j = 0; j < 8; ++j) { - let index = indices[indicesPointer]; - value |= index << 3 * j; - indicesPointer++; + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; } + } - for (let j = 0; j < 3; ++j) { - let byte = value >> 8 * j & 0xff; - result[resultPointer] = byte; - resultPointer++; - } + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; } -} -function unpack565(color16bit) { - const red = color16bit >> 11 & 0x1f; - const green = color16bit >> 5 & 0x3f; - const blue = color16bit & 0x1f; - return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; -} + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; -function interpolateColorArray(a, b, amount) { - const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); - result[3] = 255; - return result; -} + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; -function unpackColorCodes(block, offset, isDxt1) { - const color1 = block[offset] | block[offset + 1] << 8; - const color2 = block[offset + 2] | block[offset + 3] << 8; - const unpackedColor1 = unpack565(color1); - const unpackedColor2 = unpack565(color2); - return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; -} + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } -function unpackIndices(block, blockOffset) { - let offset = blockOffset + 4; - let result = new Uint8Array(16); + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; - for (let i = 0; i < 4; i++) { - let packedIndices = block[offset + i]; - result[i * 4 + 0] = packedIndices & 0x3; - result[i * 4 + 1] = packedIndices >> 2 & 0x3; - result[i * 4 + 2] = packedIndices >> 4 & 0x3; - result[i * 4 + 3] = packedIndices >> 6 & 0x3; - } + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; - return result; -} + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; -function decompressColor(rgba, block, offset, isDxt1) { - const colorCode = unpackColorCodes(block, offset, isDxt1); - const indices = unpackIndices(block, offset); + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; - for (let i = 0; i < 16; i++) { - for (let j = 0; j < 4; j++) { - rgba[4 * i + j] = colorCode[indices[i]][j]; - } - } -} + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } -function decompressAlphaDxt3(rgba, block, offset) { - for (let i = 0; i < 8; ++i) { - let quant = block[offset + i]; - let lo = quant & 0x0f; - let hi = quant & 0xf0; - rgba[8 * i + 3] = lo | lo << 4; - rgba[8 * i + 7] = hi | hi >> 4; - } -} + if (32 & m) { + U.mode = 12; + break t; + } -function decompressAlphaDxt5(rgba, block, offset) { - let alpha0 = block[offset + 0]; - let alpha1 = block[offset + 1]; - let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); - let indices = new Uint8Array(16); - let indicePointer = 0; - let bytePointer = 2; + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } - for (let i = 0; i < 2; i++) { - let value = 0; + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; - for (let j = 0; j < 3; j++) { - let byte = block[offset + bytePointer]; - value |= byte << 8 * j; - bytePointer++; - } + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } - for (let j = 0; j < 8; j++) { - let index = value >> 3 * j & 0x7; - indices[indicePointer] = index; - indicePointer++; - } - } + t.msg = "invalid distance code", U.mode = 30; + break t; + } - for (let i = 0; i < 16; ++i) { - rgba[4 * i + 3] = codes[indices[i]]; - } -} + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } -const DXT1_COMPRESSED_BYTES = 8; -const DXT5_COMPRESSED_BYTES = 16; -const COLORS = 4; -const DECOMPRESSED_BLOCK_SIZE = 16; + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } -function blockRepeat(width, height, func) { - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - func(x, y); - } - } -} + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; -function rectRepeat(func) { - for (let y = 0; y < 4; y++) { - for (let x = 0; x < 4; x++) { - func(x, y); - } - } -} + do { + x[r++] = _[v++]; + } while (--m); -function FixFlags(flags) { - let method = flags & (kDxt1 | kDxt3 | kDxt5); - let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); - let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); - const extra = flags & kWeightColourByAlpha; - if (method != kDxt3 && method != kDxt5) method = kDxt1; - if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; - if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; - return method | fit | metric | extra; -} + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; -function GetStorageRequirements(width, height, flags) { - flags = FixFlags(flags); - const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); - const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - return blockcount * blocksize; -} + do { + x[r++] = _[v++]; + } while (--m); -function extractColorBlock(img) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - let mask = 0; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + if (v = 0, d < k) { + m = d, k -= m; - if (sx < width && sy < height) { - let sourceColorOffset = COLORS * (width * sy + sx); + do { + x[r++] = _[v++]; + } while (--m); - for (let i = 0; i < COLORS; i++) { - block[blockColorOffset++] = img[sourceColorOffset++]; + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; } + } while (i < n && r < a); - mask |= 1 << 4 * py + px; - } else blockColorOffset += COLORS; - }); - return { - block, - mask + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; }; -} -function copyBuffer(result, block) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); - if (sx < width && sy < height) { - let resultColorOffset = COLORS * (width * sy + sx); + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; - for (let i = 0; i < COLORS; i++) { - result[resultColorOffset + i] = block[blockColorOffset++]; - } - } else blockColorOffset += COLORS; - }); -} + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; -function getCompressor(colorSet) { - if (colorSet.count === 1) return new SingleColourFit(colorSet); - if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); - return new ClusterFit(colorSet); -} + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; -function CompressMasked(rgba, mask, result, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - const colors = new ColorSet(rgba, mask, flags); - const compressor = getCompressor(colors); - compressor.compress(result, offset + colorOffset); - if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); -} + for (w = 0; w <= 15; w++) z[w] = 0; -function decompressBlock(result, block, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); - if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); -} + for (p = 0; p < n; p++) z[e[i + p]]++; -function compressImage(source, width, height, result, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let targetBlockPointer = 0; - blockRepeat(width, height, function (x, y) { - const { - block: sourceRGBA, - mask - } = extractColorBlock(source, { - x, - y, - width, - height - }); - CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); - targetBlockPointer += bytesPerBlock; - }); -} + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); -function decompressImage(result, width, height, source, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let sourceBlockPointer = 0; + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - decompressBlock(targetRGBA, source, sourceBlockPointer, flags); - copyBuffer(result, targetRGBA, { - x, - y, - width, - height - }); - sourceBlockPointer += bytesPerBlock; - } - } -} + for (g = 1; g < b && 0 === z[g]; g++); -const flags = { - DXT1: kDxt1, - DXT3: kDxt3, - DXT5: kDxt5, - ColourIterativeClusterFit: kColourIterativeClusterFit, - ColourClusterFit: kColourClusterFit, - ColourRangeFit: kColourRangeFit, - ColourMetricPerceptual: kColourMetricPerceptual, - ColourMetricUniform: kColourMetricUniform, - WeightColourByAlpha: kWeightColourByAlpha -}; + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; -function compress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = GetStorageRequirements(width, height, flags); - const result = new Uint8Array(targetSize); - compressImage(source, width, height, result, flags); - return result; -} + if (v > 0 && (0 === t || 1 !== b)) return -1; -function decompress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = width * height * 4; - const result = new Uint8Array(targetSize); - decompressImage(result, width, height, source, flags); - return result; -} + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; -class Texture2DReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - let format = int32Reader.read(buffer); - let width = uint32Reader.read(buffer); - let height = uint32Reader.read(buffer); - let mipCount = uint32Reader.read(buffer); - if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); - let dataSize = uint32Reader.read(buffer); - let data = buffer.read(dataSize); - if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } else if (format != 0) throw new XnbError("Non-implemented Texture2D format type (".concat(format, ") found.")); + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); - for (let i = 0; i < data.length; i += 4) { - let inverseAlpha = 255 / data[i + 3]; - data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); - } + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; - return { - format, - export: { - type: this.type, - data, - width, - height + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; } - }; - } - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - this.writeIndex(buffer, resolver); - const width = content.export.width; - const height = content.export.height; - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - let data = content.export.data; + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; - for (let i = 0; i < data.length; i += 4) { - const alpha = data[i + 3] / 255; - data[i] = Math.floor(data[i] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } } - if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); - } - - isValueType() { - return false; - } + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; -} + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); -class Vector3Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - return { - x, - y, - z - }; + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; -} + let Ce, + De, + Ie = !0; -class SpriteFontReader extends BaseReader { - read(buffer, resolver) { - const int32Reader = new Int32Reader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(new CharReader()); - const texture = resolver.read(buffer); - const glyphs = resolver.read(buffer); - const cropping = resolver.read(buffer); - const characterMap = resolver.read(buffer); - const verticalLineSpacing = int32Reader.read(buffer); - const horizontalSpacing = singleReader.read(buffer); - const kerning = resolver.read(buffer); - const defaultCharacter = nullableCharReader.read(buffer); - return { - texture, - glyphs, - cropping, - characterMap, - verticalLineSpacing, - horizontalSpacing, - kerning, - defaultCharacter - }; - } + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const charReader = new CharReader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(charReader); - const texture2DReader = new Texture2DReader(); - const rectangleListReader = new ListReader(new RectangleReader()); - const charListReader = new ListReader(charReader); - const vector3ListReader = new ListReader(new Vector3Reader()); - this.writeIndex(buffer, resolver); + for (; e < 144;) t.lens[e++] = 8; - try { - texture2DReader.write(buffer, content.texture, resolver); - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } catch (ex) { - throw ex; - } + for (; e < 256;) t.lens[e++] = 9; - console.log("writing complitd!"); - } + for (; e < 280;) t.lens[e++] = 7; - isValueType() { - return false; - } + for (; e < 288;) t.lens[e++] = 8; -} + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; -class TBinReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - let size = int32Reader.read(buffer); - let data = buffer.read(size); - return { - export: { - type: this.type, - data - } - }; - } + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; - isValueType() { - return false; - } + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; -} + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; -class Vector2Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - return { - x, - y - }; - } + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } -} + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -class Vector4Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - let w = singleReader.read(buffer); - return { - x, - y, - z, - w - }; - } + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } -} + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } -const Readers = { - ArrayReader, - BaseReader, - BmFontReader, - BooleanReader, - CharReader, - DictionaryReader, - DoubleReader, - EffectReader, - Int32Reader, - ListReader, - NullableReader, - RectangleReader, - SingleReader, - SpriteFontReader, - StringReader, - TBinReader, - Texture2DReader, - UInt32Reader, - Vector2Reader, - Vector3Reader, - Vector4Reader -}; + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } -const simplifyType = type => { - let simple = type.split(/`|,/)[0]; - let isArray = simple.endsWith('[]'); - if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; - switch (simple) { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - let subtypes = parseSubtypes(type).map(simplifyType); - return "Dictionary<".concat(subtypes[0], ",").concat(subtypes[1], ">"); + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.ArrayReader': - let arrayType = parseSubtypes(type).map(simplifyType); - return "Array<".concat(arrayType, ">"); + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - let listType = parseSubtypes(type).map(simplifyType); - return "List<".concat(listType, ">"); + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; + i.mode = 6; - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); - case 'xTile.Pipeline.TideReader': - return 'TBin'; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); - case 'BmFont.XmlSourceReader': - return 'BmFont'; + i.length = 0, i.mode = 8; - default: - throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); - } -}; + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; -const parseSubtypes = type => { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); - return matches; -}; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); -const getTypeInfo = type => { - let mainType = type.match(/[^<]+/)[0]; - let subtypes = type.match(/<(.+)>/); - subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; - return { - type: mainType, - subtypes - }; -}; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); -const getReader = typeString => { - let { - type, - subtypes - } = getTypeInfo(typeString); - subtypes = subtypes.map(getReader); - if (Readers.hasOwnProperty("".concat(type, "Reader"))) return new Readers["".concat(type, "Reader")](...subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); -}; + i.mode = 9; -class XnbData { - constructor(header, readers, content) { - let { - target, - formatVersion, - hidef, - compressed - } = header; - this.header = { - target, - formatVersion, - hidef, - compressed - }; - this.readers = readers; - this.content = content; - } + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get target() { - var _this$header; + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } - switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { - case 'w': - return "Microsoft Windows"; + l = 0, d = 0; + } - case 'm': - return "Windows Phone 7"; + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; - case 'x': - return "Xbox 360"; + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'a': - return "Android"; + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; - case 'i': - return "iOS"; + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; - default: - return "Unknown"; - } - } + case Ue: + if (e === pe || e === ge) break t; - get formatVersion() { - var _this$header2; + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } - switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { - case 0x3: - return "XNA Game Studio 3.0"; + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 0x4: - return "XNA Game Studio 3.1"; + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; - case 0x5: - return "XNA Game Studio 4.0"; + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } - default: - return "Unknown"; - } - } + break; - get hidef() { - var _this$header3; + case 2: + i.mode = 17; + break; - return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); - } + case 3: + t.msg = "invalid block type", i.mode = ze; + } - get compressed() { - var _this$header4; + l >>>= 2, d -= 2; + break; - return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); - } + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get contentType() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.type; - return "JSON"; - } + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } - get rawContent() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.data; - return JSON.stringify(this.content, (key, value) => { - if (key === "export") return value.type; - return value; - }, 4); - } + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; - stringify() { - return JSON.stringify({ - header: this.header, - readers: this.readers, - content: this.content - }, null, 4); - } + case 15: + i.mode = 16; - toString() { - return this.stringify(); - } + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } -} + i.mode = Ue; + break; -function extensionToDatatype(extension) { - switch (extension) { - case "json": - return "JSON"; + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case "yaml": - return "yaml"; + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } - case "png": - return "Texture2D"; + i.have = 0, i.mode = 18; - case "cso": - return "Effect"; + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'tbin': - return "TBin"; + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } - case 'xml': - return "BmFont"; - } + for (; i.have < 19;) i.lens[R[i.have++]] = 0; - return "Others"; -} + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } -class XnbContent { - constructor(data, ext) { - this.type = extensionToDatatype(ext); - this.content = data; - } + i.have = 0, i.mode = 19; -} + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -const HIDEF_MASK = 0x1; -const COMPRESSED_LZ4_MASK = 0x40; -const COMPRESSED_LZX_MASK = 0x80; -const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -class XnbConverter { - constructor() { - this.target = ''; - this.formatVersion = 0; - this.hidef = false; - this.compressed = false; - this.compressionType = 0; - this.buffer = null; - this.fileSize = 0; - this.readers = []; - this.sharedResources = []; - } + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - load(arrayBuffer) { - this.buffer = new BufferReader(arrayBuffer); + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - this._validateHeader(); + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - console.info('XNB file validated successfully!'); - this.fileSize = this.buffer.readUInt32(); - if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } - if (this.compressed) { - const decompressedSize = this.buffer.readUInt32(); + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - if (this.compressionType == COMPRESSED_LZX_MASK) { - const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; - const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } else if (this.compressionType == COMPRESSED_LZ4_MASK) { - const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - const decompressed = new Uint8Array(decompressedSize); - decompressBlock$1(trimmedArray, decompressed); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - } + for (; c--;) i.lens[i.have++] = v; + } + } - let count = this.buffer.read7BitNumber(); - const stringReader = new StringReader(); - const readers = []; + if (i.mode === ze) break; - for (let i = 0; i < count; i++) { - const type = stringReader.read(this.buffer); - const version = this.buffer.readInt32(); - const simpleType = simplifyType(type); - const reader = getReader(simpleType); - this.readers.push(reader); - readers.push({ - type, - version - }); - } + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } - const shared = this.buffer.read7BitNumber(); - if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); - const content = new ReaderResolver(this.readers); - const result = content.read(this.buffer); - console.log('Successfuly read XNB file!'); - return new XnbData({ - target: this.target, - formatVersion: this.formatVersion, - hidef: this.hidef, - compressed: this.compressed - }, readers, result); - } + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } - convert(json) { - const buffer = new BufferWriter(); - const stringReader = new StringReader(); - let { - target, - formatVersion, - hidef, - compressed - } = json.header; - this.target = target; - this.formatVersion = formatVersion; - this.hidef = hidef; - const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; - this.compressed = lz4Compression ? true : false; - buffer.writeString("XNB"); - buffer.writeString(this.target); - buffer.writeByte(this.formatVersion); - buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); - buffer.writeUInt32(0); - if (lz4Compression) buffer.writeUInt32(0); - buffer.write7BitNumber(json.readers.length); + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } - for (let reader of json.readers) { - this.readers.push(getReader(simplifyType(reader.type))); - stringReader.write(buffer, reader.type); - buffer.writeUInt32(reader.version); - } + if (i.mode = 20, e === ge) break t; - buffer.write7BitNumber(0); - const content = new ReaderResolver(this.readers); - content.write(buffer, json.content); - buffer.trim(); + case 20: + i.mode = 21; - if (lz4Compression) { - const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - let compressedSize = compressBound(trimmedArray.length); - let compressed = new Uint8Array(compressedSize); - compressedSize = compressSingleBlock(trimmedArray, compressed); - compressed = compressed.slice(0, compressedSize); - buffer.bytePosition = 6; - buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - buffer.writeUInt32(trimmedArray.length); - buffer.concat(compressed); - let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - return returnBuffer; + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; } - let fileSize = buffer.bytePosition; - buffer.bytePosition = 6; - buffer.writeUInt32(fileSize, 6); - return buffer.buffer; + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); } - _validateHeader() { - if (this.buffer == null) throw new XnbError('Buffer is null'); - const magic = this.buffer.readString(3); - if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); - this.target = this.buffer.readString(1).toLowerCase(); - this.formatVersion = this.buffer.readByte(); - const flags = this.buffer.readByte(1); - this.hidef = (flags & HIDEF_MASK) != 0; - this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; - this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; } -} + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; -var t = { - 396: function _() { - !function (t) { - if (t.TextEncoder && t.TextDecoder) return !1; + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); - function e() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; } - function i() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - fatal: !1 - }; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); - if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; } + } - Object.defineProperty(e.prototype, "encoding", { - value: "utf-8" - }), e.prototype.encode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); - let i = 0; - const n = t.length; - let r = 0, - s = Math.max(32, n + (n >> 1) + 7), - a = new Uint8Array(s >> 3 << 3); + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; - for (; i < n;) { - let e = t.charCodeAt(i++); + for (let t = 0; t < 256; t++) { + let e = t; - if (e >= 55296 && e <= 56319) { - if (i < n) { - const n = t.charCodeAt(i); - 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); - } + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; - if (e >= 55296 && e <= 56319) continue; - } + pi[t] = e; + } - if (r + 4 > a.length) { - s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; - const e = new Uint8Array(s); - e.set(a), a = e; - } + const gi = 4294967295; - if (0 != (4294967168 & e)) { - if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { - if (0 != (4292870144 & e)) continue; - a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; - } - a[r++] = 63 & e | 128; - } else a[r++] = e; - } + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; - return a.slice(0, r); - }, Object.defineProperty(i.prototype, "encoding", { - value: "utf-8" - }), Object.defineProperty(i.prototype, "fatal", { - value: !1 - }), Object.defineProperty(i.prototype, "ignoreBOM", { - value: !1 - }), i.prototype.decode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); - const i = new Uint8Array(t); - let n = 0; - const r = i.length, - s = []; + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; - for (; n < r;) { - const t = i[n++]; - if (0 === t) break; - if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { - const e = 63 & i[n++]; - s.push((31 & t) << 6 | e); - } else if (224 == (240 & t)) { - const e = 63 & i[n++], - r = 63 & i[n++]; - s.push((31 & t) << 12 | e << 6 | r); - } else if (240 == (248 & t)) { - let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; - e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); - } - } + case "IDAT": + this.decodeIDAT(t); + break; - return String.fromCharCode.apply(null, s); - }, t.TextEncoder = e, t.TextDecoder = i; - }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); - } -}, - e = {}; + case "IEND": + this._end = !0; + break; -function i(n) { - var r = e[n]; - if (void 0 !== r) return r.exports; - var s = e[n] = { - exports: {} - }; - return t[n].call(s.exports, s, s.exports, i), s.exports; -} + case "tRNS": + this.decodetRNS(t); + break; -i.d = (t, e) => { - for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { - enumerable: !0, - get: e[n] - }); -}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); -var n = {}; + case "iCCP": + this.decodeiCCP(t); + break; -(() => { - i.d(n, { - P: () => Mi, - m: () => Fi - }), i(396); - const t = new TextDecoder("utf-8"), - e = new TextEncoder(); + case "tEXt": + this.decodetEXt(t); + break; - class r { - constructor() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let i = !1; - "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); - const n = e.offset ? e.offset >>> 0 : 0, - s = t.byteLength - n; - let a = n; - (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; - } + case "pHYs": + this.decodepHYs(); + break; - available() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset + t <= this.length; - } + default: + this.skip(t); + } - isLittleEndian() { - return this.littleEndian; - } + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); - setLittleEndian() { - return this.littleEndian = !0, this; + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); } - isBigEndian() { - return !this.littleEndian; - } + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; - setBigEndian() { - return this.littleEndian = !1, this; - } + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; - skip() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset += t, this; - } + case mi.TRUECOLOUR: + i = 3; + break; - seek(t) { - return this.offset = t, this; - } + case mi.INDEXED_COLOUR: + i = 1; + break; - mark() { - return this._mark = this.offset, this; - } + case mi.GREYSCALE_ALPHA: + i = 2; + break; - reset() { - return this.offset = this._mark, this; - } + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; - pushMark() { - return this._marks.push(this.offset), this; + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); } - popMark() { - const t = this._marks.pop(); + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; - if (void 0 === t) throw new Error("Mark stack empty"); - return this.seek(t), this; + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); } - rewind() { - return this.offset = 0, this; + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); } - ensureAvailable() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; - if (!this.available(t)) { - const e = 2 * (this.offset + t), - i = new Uint8Array(e); - i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); - } + for (; e < t; e++) { + const t = this.readByte(); - return this; + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } } - readBoolean() { - return 0 !== this.readUint8(); + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; } - readInt8() { - return this._data.getInt8(this.offset++); + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); } - readUint8() { - return this._data.getUint8(this.offset++); + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; } - readByte() { - return this.readUint8(); + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); } - readBytes() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - const e = new Uint8Array(t); + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; - for (let i = 0; i < t; i++) e[i] = this.readByte(); + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; - return e; - } + case 1: + Ri(s, a, n, i); + break; - readInt16() { - const t = this._data.getInt16(this.offset, this.littleEndian); + case 2: + Ni(s, a, o, n); + break; - return this.offset += 2, t; - } + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; - readUint16() { - const t = this._data.getUint16(this.offset, this.littleEndian); + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } - return this.offset += 2, t; - } + o = a, h += n + 1; + } - readInt32() { - const t = this._data.getInt32(this.offset, this.littleEndian); + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; - return this.offset += 4, t; + var l; } - readUint32() { - const t = this._data.getUint32(this.offset, this.littleEndian); + } - return this.offset += 4, t; - } + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } - readFloat32() { - const t = this._data.getFloat32(this.offset, this.littleEndian); + function Ri(t, e, i, n) { + let r = 0; - return this.offset += 4, t; - } + for (; r < n; r++) e[r] = t[r]; - readFloat64() { - const t = this._data.getFloat64(this.offset, this.littleEndian); + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } - return this.offset += 8, t; - } + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } - readBigInt64() { - const t = this._data.getBigInt64(this.offset, this.littleEndian); + function Ti(t, e, i, n, r) { + let s = 0; - return this.offset += 8, t; - } + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - readBigUint64() { - const t = this._data.getBigUint64(this.offset, this.littleEndian); + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; - return this.offset += 8, t; + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; } + } - readChar() { - return String.fromCharCode(this.readInt8()); - } + function Oi(t, e, i, n, r) { + let s = 0; - readChars() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - let e = ""; + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - for (let i = 0; i < t; i++) e += this.readChar(); + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; - return e; + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; } + } - readUtf8() { - let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return i = this.readBytes(e), t.decode(i); - var i; - } + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } - writeBoolean(t) { - return this.writeUint8(t ? 255 : 0), this; - } + const Bi = { + level: 3 + }; - writeInt8(t) { - return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); } - writeUint8(t) { - return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); } - writeByte(t) { - return this.writeUint8(t); + encodeSignature() { + this.writeBytes(wi); } - writeBytes(t) { - this.ensureAvailable(t.length); - - for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - - return this._updateLastWrittenByte(), this; + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); } - writeInt16(t) { - return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); } - writeUint16(t) { - return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); } - writeInt32(t) { - return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; - writeUint32(t) { - return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } - writeFloat32(t) { - return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); } - writeFloat64(t) { - return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; - writeBigInt64(t) { - return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; - writeBigUint64(t) { - return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + case 3: + n.colorType = mi.TRUECOLOUR; + break; - writeChar(t) { - return this.writeUint8(t.charCodeAt(0)); - } + case 1: + n.colorType = mi.GREYSCALE; + break; - writeChars(t) { - for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; - return this; - } + default: + throw new Error("unsupported number of channels"); + } - writeUtf8(t) { - return this.writeBytes(function (t) { - return e.encode(t); - }(t)); - } + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; - toArray() { - return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; } - _updateLastWrittenByte() { - this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); } } - function s(t) { - let e = t.length; - - for (; --e >= 0;) t[e] = 0; + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); } - const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), - o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), - h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), - l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), - d = new Array(576); - s(d); - - const _ = new Array(60); - - s(_); - const f = new Array(512); - s(f); - const c = new Array(256); - s(c); - const u = new Array(29); - s(u); - const w = new Array(30); + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); - function p(t, e, i, n, r) { - this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + return n; } - let g, b, m; + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); - function k(t, e) { - this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + return n; } - s(w); + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); - const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], - v = (t, e) => { - t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; - }, - E = (t, e, i) => { - t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); - }, - A = (t, e, i) => { - E(t, i[2 * e], i[2 * e + 1]); - }, - x = (t, e) => { - let i = 0; + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); - do { - i |= 1 & t, t >>>= 1, i <<= 1; - } while (--e > 0); +var r = n.P, + s = n.m; - return i >>> 1; - }, - U = (t, e, i) => { - const n = new Array(16); - let r, - s, - a = 0; +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} - for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); - for (s = 0; s <= e; s++) { - let e = t[2 * s + 1]; - 0 !== e && (t[2 * s] = x(n[e]++, e)); + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; } - }, - z = t => { - let e; - - for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); - for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } - for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + let s = '\n'; - t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; - }, - R = t => { - t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; - }, - N = (t, e, i, n) => { - const r = 2 * e, - s = 2 * i; - return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; - }, - T = (t, e, i) => { - const n = t.heap[i]; - let r = i << 1; + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); - for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } - t.heap[i] = n; - }, - O = (t, e, i) => { - let n, - r, - s, - h, - l = 0; - if (0 !== t.last_lit) do { - n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); - } while (l < t.last_lit); - A(t, 256, e); - }, - L = (t, e) => { - const i = e.dyn_tree, - n = e.stat_desc.static_tree, - r = e.stat_desc.has_stree, - s = e.stat_desc.elems; - let a, - o, - h, - l = -1; + s += '\n'; + } + } - for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} - for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; - for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } - h = s; + return stringify(object, gap, -1); +} - do { - a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); - } while (t.heap_len >= 2); +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; - t.heap[--t.heap_max] = t.heap[1], ((t, e) => { - const i = e.dyn_tree, - n = e.max_code, - r = e.stat_desc.static_tree, - s = e.stat_desc.has_stree, - a = e.stat_desc.extra_bits, - o = e.stat_desc.extra_base, - h = e.stat_desc.max_length; + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); - let l, - d, - _, - f, - c, - u, - w = 0; + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } - for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } - for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + getLineNumber() { + return this.startingLine + this.lineIndex; + } - if (0 !== w) { - do { - for (f = h - 1; 0 === t.bl_count[f];) f--; + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); - t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; - } while (w > 0); + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } - for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); - } - })(t, e), U(i, l, t.bl_count); - }, - B = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } - for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); - }, - C = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } - for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { - if (o < l) do { - A(t, r, t.bl_tree); - } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); - o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); - } - }; + peek() { + return this.getLine(this.lineIndex + 1); + } - let D = !1; + finished() { + return this.lineIndex == this.lines.length - 1; + } - const I = (t, e, i, n) => { - E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { - R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; - })(t, e, i); - }; + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } - var S = { - _tr_init: t => { - D || ((() => { - let t, e, i, n, r; - const s = new Array(16); + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } - for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + return ''; + } - for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); - for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } - for (e = 0; e <= 15; e++) s[e] = 0; + return indentLevel; + } - for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; +} - for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); - for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; - for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } - for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } - g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); - })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); - }, - _tr_stored_block: I, - _tr_flush_block: (t, e, i, n) => { - let r, - s, - a = 0; - t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { - let e, - i = 4093624447; + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } - for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } - if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } - for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + if (type) { + object = { + type: type, + data: object + }; + } - return 0; - })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { - let e; + return object; +} - for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); +function getValue(value, type) { + value = JSON.parse(value); - return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; - })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { - let r; + if (type) { + value = { + type: type, + data: value + }; + } - for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + return value; +} - C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); - })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); - }, - _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), - _tr_align: t => { - E(t, 2, 3), A(t, 256, d), (t => { - 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); - })(t); - } - }, - Z = (t, e, i, n) => { - let r = 65535 & t | 0, - s = t >>> 16 & 65535 | 0, - a = 0; +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} - for (; 0 !== i;) { - a = i > 2e3 ? 2e3 : i, i -= a; +function deepCopy(obj) { + let newObj; - do { - r = r + e[n++] | 0, s = s + r | 0; - } while (--a); + if (Array.isArray(obj)) { + newObj = []; - r %= 65521, s %= 65521; + for (let item of obj) { + newObj.push(deepCopy(item)); } - return r | s << 16 | 0; - }; - - const F = new Uint32Array((() => { - let t, - e = []; - - for (var i = 0; i < 256; i++) { - t = i; + return newObj; + } - for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + if (!!obj && typeof obj === "object") { + newObj = {}; - e[i] = t; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); } - return e; - })()); + return newObj; + } - var M = (t, e, i, n) => { - const r = F, - s = n + i; - t ^= -1; + return obj; +} - for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; - return -1 ^ t; - }, - P = { - 2: "need dictionary", - 1: "stream end", - 0: "", - "-1": "file error", - "-2": "stream error", - "-3": "data error", - "-4": "insufficient memory", - "-5": "buffer error", - "-6": "incompatible version" - }, - H = { - Z_NO_FLUSH: 0, - Z_PARTIAL_FLUSH: 1, - Z_SYNC_FLUSH: 2, - Z_FULL_FLUSH: 3, - Z_FINISH: 4, - Z_BLOCK: 5, - Z_TREES: 6, - Z_OK: 0, - Z_STREAM_END: 1, - Z_NEED_DICT: 2, - Z_ERRNO: -1, - Z_STREAM_ERROR: -2, - Z_DATA_ERROR: -3, - Z_MEM_ERROR: -4, - Z_BUF_ERROR: -5, - Z_NO_COMPRESSION: 0, - Z_BEST_SPEED: 1, - Z_BEST_COMPRESSION: 9, - Z_DEFAULT_COMPRESSION: -1, - Z_FILTERED: 1, - Z_HUFFMAN_ONLY: 2, - Z_RLE: 3, - Z_FIXED: 4, - Z_DEFAULT_STRATEGY: 0, - Z_BINARY: 0, - Z_TEXT: 1, - Z_UNKNOWN: 2, - Z_DEFLATED: 8 - }; + default: + return false; + } +} - const { - _tr_init: W, - _tr_stored_block: K, - _tr_flush_block: $, - _tr_tally: Y, - _tr_align: j - } = S, - { - Z_NO_FLUSH: G, - Z_PARTIAL_FLUSH: X, - Z_FULL_FLUSH: V, - Z_FINISH: q, - Z_BLOCK: J, - Z_OK: Q, - Z_STREAM_END: tt, - Z_STREAM_ERROR: et, - Z_DATA_ERROR: it, - Z_BUF_ERROR: nt, - Z_DEFAULT_COMPRESSION: rt, - Z_FILTERED: st, - Z_HUFFMAN_ONLY: at, - Z_RLE: ot, - Z_FIXED: ht, - Z_DEFAULT_STRATEGY: lt, - Z_UNKNOWN: dt, - Z_DEFLATED: _t - } = H, - ft = 258, - ct = 262, - ut = 103, - wt = 113, - pt = 666, - gt = (t, e) => (t.msg = P[e], e), - bt = t => (t << 1) - (t > 4 ? 9 : 0), - mt = t => { - let e = t.length; +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; - for (; --e >= 0;) t[e] = 0; - }; + default: + return false; + } +} - let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; - const yt = t => { - const e = t.state; - let i = e.pending; - i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); - }, - vt = (t, e) => { - $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); - }, - Et = (t, e) => { - t.pending_buf[t.pending++] = e; - }, - At = (t, e) => { - t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; - }, - xt = (t, e, i, n) => { - let r = t.avail_in; - return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); - }, - Ut = (t, e) => { - let i, - n, - r = t.max_chain_length, - s = t.strstart, - a = t.prev_length, - o = t.nice_match; - const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, - l = t.window, - d = t.w_mask, - _ = t.prev, - f = t.strstart + ft; - let c = l[s + a - 1], - u = l[s + a]; - t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; - do { - if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { - s += 2, i++; + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } - do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } - if (n = ft - (f - s), s = f - ft, n > a) { - if (t.match_start = e, a = n, n >= o) break; - c = l[s + a - 1], u = l[s + a]; - } + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; } - } while ((e = _[e & d]) > h && 0 != --r); - return a <= t.lookahead ? a : t.lookahead; - }, - zt = t => { - const e = t.w_size; - let i, n, r, s, a; + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } - do { - if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { - t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } - do { - r = t.head[--i], t.head[i] = r >= e ? r - e : 0; - } while (--n); + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); - n = e, i = n; + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } - do { - r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; - } while (--n); + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); - s += e; - } + return { + converted, + extractedImages, + extractedMaps + }; +} - if (0 === t.strm.avail_in) break; - if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); - } while (t.lookahead < ct && 0 !== t.strm.avail_in); - }, - Rt = (t, e) => { - let i, n; +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { - if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { - t.match_length--; + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } - do { - t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; - } while (0 != --t.match_length); + obj = deepCopy(data); + } - t.strstart++; - } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); - } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; - if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); } - return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }, - Nt = (t, e) => { - let i, n, r; + return newObj; + } - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (!!obj && typeof obj === "object") { + newObj = {}; - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { - r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } - do { - ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); - } while (0 != --t.prev_length); + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } - if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } else if (t.match_available) { - if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; - } else t.match_available = 1, t.strstart++, t.lookahead--; - } + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} - return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); - function Tt(t, e, i, n, r) { - this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; } - const Ot = [new Tt(0, 0, 0, 0, (t, e) => { - let i = 65535; + return result; +} - for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { - if (t.lookahead <= 1) { - if (zt(t), 0 === t.lookahead && e === G) return 1; - if (0 === t.lookahead) break; - } +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; - t.strstart += t.lookahead, t.lookahead = 0; - const n = t.block_start + i; - if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; - if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; } + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); - }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + return null; +} - function Lt() { - this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; - } +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} - const Bt = t => { - if (!t || !t.state) return gt(t, et); - t.total_in = t.total_out = 0, t.data_type = dt; - const e = t.state; - return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; - }, - Ct = t => { - const e = Bt(t); - var i; - return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; - }, - Dt = (t, e, i, n, r, s) => { - if (!t) return et; - let a = 1; - if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); - 8 === n && (n = 9); - const o = new Lt(); - return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); - }; +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; - var It = Dt, - St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, - Zt = (t, e) => { - let i, n; - if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; - const r = t.state; - if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); - r.strm = t; - const s = r.last_flush; - if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { - let e = _t + (r.w_bits - 8 << 4) << 8, - i = -1; - i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; - } - if (69 === r.status) if (r.gzhead.extra) { - for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + case "yaml": + return "yaml"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); - } else r.status = 73; - if (73 === r.status) if (r.gzhead.name) { - i = r.pending; + case "Texture2D": + return "png"; - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + case "Effect": + return "cso"; - n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + case 'TBin': + return "tbin"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); - } else r.status = 91; - if (91 === r.status) if (r.gzhead.comment) { - i = r.pending; + case 'BmFont': + return "xml"; + } - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + return "bin"; +} - n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); - } else r.status = ut; + case "yaml": + return "text/plain"; - if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { - if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; - } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + case "Texture2D": + return "image/png"; - if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + case "Effect": + return "application/x-cso"; - if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { - let i = r.strategy === at ? ((t, e) => { - let i; + case 'BmFont': + return "application/xml"; + } - for (;;) { - if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { - if (e === G) return 1; - break; - } + return "application/octet-stream"; +} - if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : r.strategy === ot ? ((t, e) => { - let i, n, r, s; - const a = t.window; +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); - for (;;) { - if (t.lookahead <= ft) { - if (zt(t), t.lookahead <= ft && e === G) return 1; - if (0 === t.lookahead) break; - } + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; - if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { - s = t.strstart + ft; + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } - do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + return makeBlob(data, dataType); + } - t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); - } + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } - if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : Ot[r.level].func(r, e); - if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; - if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + return "".concat(value.type, ".").concat(getExtension(value.type)); } - return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); - }, - Ft = t => { - if (!t || !t.state) return et; - const e = t.state.status; - return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); - }, - Mt = (t, e) => { - let i = e.length; - if (!t || !t.state) return et; - const n = t.state, - r = n.wrap; - if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} - if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { - 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); - let t = new Uint8Array(n.w_size); - t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; - } +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} - const s = t.avail_in, - a = t.next_in, - o = t.input; +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} - for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { - let t = n.strstart, - e = n.lookahead - 2; +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} - do { - n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; - } while (--e); +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } - n.strstart = t, n.lookahead = 2, zt(n); - } + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } - return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; - }; + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } - const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} - var Ht = function Ht(t) { - const e = Array.prototype.slice.call(arguments, 1); +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; - for (; e.length;) { - const i = e.shift(); + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } - if (i) { - if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + const found = searchElement(jsonData.content, "export"); - for (const e in i) Pt(i, e) && (t[e] = i[e]); - } - } + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } - return t; - }, - Wt = t => { - let e = 0; + return jsonData; +} - for (let i = 0, n = t.length; i < n; i++) e += t[i].length; +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ - const i = new Uint8Array(e); +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); - for (let e = 0, n = 0, r = t.length; e < r; e++) { - let r = t[e]; - i.set(r, n), n += r.length; + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); } - return i; - }; - - let Kt = !0; - - try { - String.fromCharCode.apply(null, new Uint8Array(1)); - } catch (t) { - Kt = !1; + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); } - const $t = new Uint8Array(256); - - for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - - $t[254] = $t[254] = 1; - - var Yt = t => { - if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); - let e, - i, - n, - r, - s, - a = t.length, - o = 0; + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ - for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ - return e; - }, - jt = (t, e) => { - const i = e || t.length; - if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); - let n, r; - const s = new Array(2 * i); - for (r = 0, n = 0; n < i;) { - let e = t[n++]; +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); - if (e < 128) { - s[r++] = e; - continue; - } + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); - let a = $t[e]; - if (a > 4) s[r++] = 65533, n += a - 1;else { - for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ - a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); - } - } - return ((t, e) => { - if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); - let i = ""; +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ - for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - return i; - })(s, r); - }, - Gt = (t, e) => { - (e = e || t.length) > t.length && (e = t.length); - let i = e - 1; +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ - for (; i >= 0 && 128 == (192 & t[i]);) i--; - return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; - }, - Xt = function Xt() { - this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; - }; +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ - const Vt = Object.prototype.toString, - { - Z_NO_FLUSH: qt, - Z_SYNC_FLUSH: Jt, - Z_FULL_FLUSH: Qt, - Z_FINISH: te, - Z_OK: ee, - Z_STREAM_END: ie, - Z_DEFAULT_COMPRESSION: ne, - Z_DEFAULT_STRATEGY: re, - Z_DEFLATED: se - } = H; - function ae(t) { - this.options = Ht({ - level: ne, - method: se, - chunkSize: 16384, - windowBits: 15, - memLevel: 8, - strategy: re - }, t || {}); - let e = this.options; - e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); - if (i !== ee) throw new Error(P[i]); +function fileMapper(files) { + let returnMap = {}; - if (e.header && St(this.strm, e.header), e.dictionary) { - let t; - if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); - this._dict_set = !0; - } + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; } - function oe(t, e) { - const i = new ae(e); - if (i.push(t, !0), i.err) throw i.msg || P[i.err]; - return i.result; - } + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ - ae.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize; - let r, s; - if (this.ended) return !1; - for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { - if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ - if (0 !== i.avail_out) { - if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; - } else this.onData(i.output); - } - return !0; - }, ae.prototype.onData = function (t) { - this.chunks.push(t); - }, ae.prototype.onEnd = function (t) { - t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; - var he = { - Deflate: ae, - deflate: oe, - deflateRaw: function deflateRaw(t, e) { - return (e = e || {}).raw = !0, oe(t, e); - }, - gzip: function gzip(t, e) { - return (e = e || {}).gzip = !0, oe(t, e); - }, - constants: H - }, - le = function le(t, e) { - let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } - const U = t.state; - i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} - t: do { - c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; +function setReaders(readers) { + return TypeReader.setReaders(readers); +} - e: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { - if (!(16 & m)) { - if (0 == (64 & m)) { - b = u[(65535 & b) + (f & (1 << m) - 1)]; - continue e; - } +function addReaders(readers) { + return TypeReader.addReaders(readers); +} - if (32 & m) { - U.mode = 12; - break t; - } +class BaseReader { + static isTypeOf(type) { + return false; + } - t.msg = "invalid literal/length code", U.mode = 30; - break t; - } + static hasSubType() { + return false; + } - k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } - i: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { - if (0 == (64 & m)) { - b = w[(65535 & b) + (f & (1 << m) - 1)]; - continue i; - } + static type() { + return this.name.slice(0, -6); + } - t.msg = "invalid distance code", U.mode = 30; - break t; - } + isValueType() { + return true; + } - if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + get type() { + return this.constructor.type(); + } - if (f >>>= m, c -= m, m = r - s, y > m) { - if (m = y - m, m > l && U.sane) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - if (v = 0, E = _, 0 === d) { - if (v += h - m, m < k) { - k -= m; + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - do { - x[r++] = _[v++]; - } while (--m); + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } - v = r - y, E = x; - } - } else if (d < m) { - if (v += h + d - m, m -= d, m < k) { - k -= m; + toString() { + return this.type; + } - do { - x[r++] = _[v++]; - } while (--m); +} - if (v = 0, d < k) { - m = d, k -= m; +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; - do { - x[r++] = _[v++]; - } while (--m); + default: + return false; + } + } - v = r - y, E = x; - } - } - } else if (v += d - m, m < k) { - k -= m; + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } - do { - x[r++] = _[v++]; - } while (--m); +} - v = r - y, E = x; - } +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; - for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + default: + return false; + } + } - k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); - } else { - v = r - y; + static hasSubType() { + return true; + } - do { - x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; - } while (k > 2); + constructor(reader) { + super(); + this.reader = reader; + } - k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); - } + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; - break; - } - } - break; - } - } while (i < n && r < a); + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } - k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; - }; + return array; + } - const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), - _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), - fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), - ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); - var ue = (t, e, i, n, r, s, a, o) => { - const h = o.bits; + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } - let l, - d, - _, - f, - c, - u, - w = 0, - p = 0, - g = 0, - b = 0, - m = 0, - k = 0, - y = 0, - v = 0, - E = 0, - A = 0, - x = null, - U = 0; + isValueType() { + return false; + } - const z = new Uint16Array(16), - R = new Uint16Array(16); - let N, - T, - O, - L = null, - B = 0; + get type() { + return "Array<".concat(this.reader.type, ">"); + } - for (w = 0; w <= 15; w++) z[w] = 0; +} - for (p = 0; p < n; p++) z[e[i + p]]++; +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; - for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); +function UTF16Decode(codeSet) { + var _codeSet2; - if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} - for (g = 1; g < b && 0 === z[g]; g++); +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + while (index < str.length) { + let code = utf16Map[index]; - if (v > 0 && (0 === t || 1 !== b)) return -1; + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } - for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + return result; +} - for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} - if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; - for (;;) { - N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + default: + return false; + } + } - do { - d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; - } while (0 !== d); + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } - for (l = 1 << w - 1; A & l;) l >>= 1; + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } - if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { - if (w === b) break; - w = e[i + a[p]]; - } + isValueType() { + return false; + } - if (w > m && (A & f) !== _) { - for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; +} - if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; - _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; - } +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; } + } - return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; - }; + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } - const { - Z_FINISH: we, - Z_BLOCK: pe, - Z_TREES: ge, - Z_OK: be, - Z_STREAM_END: me, - Z_NEED_DICT: ke, - Z_STREAM_ERROR: ye, - Z_DATA_ERROR: ve, - Z_MEM_ERROR: Ee, - Z_BUF_ERROR: Ae, - Z_DEFLATED: xe - } = H, - Ue = 12, - ze = 30, - Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } - function Ne() { - this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + isValueType() { + return false; } - const Te = t => { - if (!t || !t.state) return ye; - const e = t.state; - return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; - }, - Oe = t => { - if (!t || !t.state) return ye; - const e = t.state; - return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); - }, - Le = (t, e) => { - let i; - if (!t || !t.state) return ye; - const n = t.state; - return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); - }, - Be = (t, e) => { - if (!t) return ye; - const i = new Ne(); - t.state = i, i.window = null; - const n = Le(t, e); - return n !== be && (t.state = null), n; - }; +} - let Ce, - De, - Ie = !0; +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; - const Se = t => { - if (Ie) { - Ce = new Int32Array(512), De = new Int32Array(32); - let e = 0; + default: + return false; + } + } - for (; e < 144;) t.lens[e++] = 8; + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } - for (; e < 256;) t.lens[e++] = 9; +} - for (; e < 280;) t.lens[e++] = 7; +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; - for (; e < 288;) t.lens[e++] = 8; + default: + return false; + } + } - for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { - bits: 9 - }), e = 0; e < 32;) t.lens[e++] = 5; + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); - ue(2, t.lens, 0, 32, De, 0, t.work, { - bits: 5 - }), Ie = !1; - } + return buffer.readString(charSize); + } - t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; - }, - Ze = (t, e, i, n) => { - let r; - const s = t.state; - return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; - }; + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } - var Fe = Oe, - Me = Be, - Pe = (t, e) => { - let i, - n, - r, - s, - a, - o, - h, - l, - d, - _, - f, - c, - u, - w, - p, - g, - b, - m, - k, - y, - v, - E, - A = 0; + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } - const x = new Uint8Array(4); - let U, z; - const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; - i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; +} - t: for (;;) switch (i.mode) { - case 1: - if (0 === i.wrap) { - i.mode = 13; - break; - } +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + default: + return false; + } + } - if (2 & i.wrap && 35615 === l) { - i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; - break; - } + static hasSubType() { + return true; + } - if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { - t.msg = "incorrect header check", i.mode = ze; - break; - } + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } - if ((15 & l) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); - if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { - t.msg = "invalid window size", i.mode = ze; - break; - } - i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; - break; + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } - case 2: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return dictionary; + } - if (i.flags = l, (255 & i.flags) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); - if (57344 & i.flags) { - t.msg = "unknown header flags set", i.mode = ze; - break; - } + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } - i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + isValueType() { + return false; + } - case 3: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } - i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; +} - case 4: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; - i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + default: + return false; + } + } - case 5: - if (1024 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + read(buffer) { + return buffer.readDouble(); + } - i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; - } else i.head && (i.head.extra = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } - i.mode = 6; +} - case 6: - if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; - i.length = 0, i.mode = 7; +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; - case 7: - if (2048 & i.flags) { - if (0 === o) break t; - c = 0; + default: + return false; + } + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); - } while (v && c < o); + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.name = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } - i.length = 0, i.mode = 8; + isValueType() { + return false; + } - case 8: - if (4096 & i.flags) { - if (0 === o) break t; - c = 0; +} - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); - } while (v && c < o); +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.comment = null); + default: + return false; + } + } - i.mode = 9; + read(buffer) { + return buffer.readInt32(); + } - case 9: - if (512 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } - if (l !== (65535 & i.check)) { - t.msg = "header crc mismatch", i.mode = ze; - break; - } +} - l = 0, d = 0; - } +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; - i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; - break; + default: + return false; + } + } - case 10: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + constructor(reader) { + super(); + this.reader = reader; + } - case 11: - if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; - t.adler = i.check = 1, i.mode = Ue; + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; - case Ue: - if (e === pe || e === ge) break t; + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } - case 13: - if (i.last) { - l >>>= 7 & d, d -= 7 & d, i.mode = 27; - break; - } + return list; + } - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); - switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { - case 0: - i.mode = 14; - break; + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } - case 1: - if (Se(i), i.mode = 20, e === ge) { - l >>>= 2, d -= 2; - break t; - } + isValueType() { + return false; + } - break; + get type() { + return "List<".concat(this.reader.type, ">"); + } - case 2: - i.mode = 17; - break; +} - case 3: - t.msg = "invalid block type", i.mode = ze; - } +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; - l >>>= 2, d -= 2; - break; + default: + return false; + } + } - case 14: - for (l >>>= 7 & d, d -= 7 & d; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if ((65535 & l) != (l >>> 16 ^ 65535)) { - t.msg = "invalid stored block lengths", i.mode = ze; - break; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); - case 15: - i.mode = 16; + if (!hasValue) { + booleanReader.read(buffer); + return null; + } - case 16: - if (c = i.length, c) { - if (c > o && (c = o), c > h && (c = h), 0 === c) break t; - r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; - break; - } + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } - i.mode = Ue; - break; + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } - case 17: - for (; d < 14;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { - t.msg = "too many length or distance symbols", i.mode = ze; - break; - } + if (content !== null) { + buffer.writeByte(0); + return; + } - i.have = 0, i.mode = 18; + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - case 18: - for (; i.have < i.ncode;) { - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; - } + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } - for (; i.have < 19;) i.lens[R[i.have++]] = 0; +} - if (i.lencode = i.lendyn, i.lenbits = 7, U = { - bits: i.lenbits - }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid code lengths set", i.mode = ze; - break; - } +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; - i.have = 0, i.mode = 19; + default: + return false; + } + } - case 19: - for (; i.have < i.nlen + i.ndist;) { - for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { - if (16 === b) { - for (z = p + 2; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (l >>>= p, d -= p, 0 === i.have) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } - v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; - } else if (17 === b) { - for (z = p + 3; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; - } else { - for (z = p + 7; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; - } + get type() { + return "".concat(this.reader.type); + } - if (i.have + c > i.nlen + i.ndist) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } +} - for (; c--;) i.lens[i.have++] = v; - } - } +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; - if (i.mode === ze) break; + default: + return false; + } + } - if (0 === i.lens[256]) { - t.msg = "invalid code -- missing end-of-block", i.mode = ze; - break; - } + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } - if (i.lenbits = 9, U = { - bits: i.lenbits - }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid literal/lengths set", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } - if (i.distbits = 6, i.distcode = i.distdyn, U = { - bits: i.distbits - }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { - t.msg = "invalid distances set", i.mode = ze; - break; - } +} - if (i.mode = 20, e === ge) break t; +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; - case 20: - i.mode = 21; + default: + return false; + } + } - case 21: - if (o >= 6 && h >= 258) { - t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); - break; - } + read(buffer) { + return buffer.readSingle(); + } - for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } - if (g && 0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +} - l >>>= m, d -= m, i.back += m; - } +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; - if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { - i.mode = 26; - break; - } +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} - if (32 & g) { - i.back = -1, i.mode = Ue; - break; - } +function Rij(k, l, theta, N) { + let Mat = Array(N); - if (64 & g) { - t.msg = "invalid literal/length code", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.extra = 15 & g, i.mode = 22; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } - case 22: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} - i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; - i.was = i.length, i.mode = 23; + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } - case 23: - for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return th; +} - if (0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; - l >>>= m, d -= m, i.back += m; - } + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } - if (l >>>= p, d -= p, i.back += p, 64 & g) { - t.msg = "invalid distance code", i.mode = ze; - break; - } + return [maxIJ, maxMij]; +} - i.offset = b, i.extra = 15 & g, i.mode = 24; +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); - case 24: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - if (i.offset > i.dmax) { - t.msg = "invalid distance too far back", i.mode = ze; - break; + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; } + } + } + } - i.mode = 25; - - case 25: - if (0 === h) break t; + return Mat; +} - if (c = f - h, i.offset > c) { - if (c = i.offset - c, c > i.whave && i.sane) { - t.msg = "invalid distance too far back", i.mode = ze; - break; - } +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); - c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; - } else w = r, u = a - i.offset, c = i.length; + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - c > h && (c = h), h -= c, i.length -= c; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - do { - r[a++] = w[u++]; - } while (--c); + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } - 0 === i.length && (i.mode = 21); - break; + return Mat; +} - case 26: - if (0 === h) break t; - r[a++] = i.length, h--, i.mode = 21; - break; +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); - case 27: - if (i.wrap) { - for (; d < 32;) { - if (0 === o) break t; - o--, l |= n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } - if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { - t.msg = "incorrect data check", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } - l = 0, d = 0; - } + let Vab = getAij(Hij); - i.mode = 28; + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } - case 28: - if (i.wrap && i.flags) { - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } - if (l !== (4294967295 & i.total)) { - t.msg = "incorrect length check", i.mode = ze; - break; - } + return sorting(Ei, Sij); +} - l = 0, d = 0; - } +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} - i.mode = 29; +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} - case 29: - E = me; - break t; +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } - case ze: - E = ve; - break t; + get x() { + return this._values[0]; + } - case 31: - return Ee; + get y() { + return this._values[1]; + } - default: - return ye; - } + get z() { + return this._values[2]; + } - return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; - }, - He = t => { - if (!t || !t.state) return ye; - let e = t.state; - return e.window && (e.window = null), t.state = null, be; - }, - We = (t, e) => { - if (!t || !t.state) return ye; - const i = t.state; - return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); - }, - Ke = (t, e) => { - const i = e.length; - let n, r, s; - return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; - }, - $e = function $e() { - this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; - }; + set x(value) { + this._values[0] = value; + } - const Ye = Object.prototype.toString, - { - Z_NO_FLUSH: je, - Z_FINISH: Ge, - Z_OK: Xe, - Z_STREAM_END: Ve, - Z_NEED_DICT: qe, - Z_STREAM_ERROR: Je, - Z_DATA_ERROR: Qe, - Z_MEM_ERROR: ti - } = H; + set y(value) { + this._values[1] = value; + } - function ei(t) { - this.options = Ht({ - chunkSize: 65536, - windowBits: 15, - to: "" - }, t || {}); - const e = this.options; - e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = Me(this.strm, e.windowBits); - if (i !== Xe) throw new Error(P[i]); - if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + set z(value) { + this._values[2] = value; } - function ii(t, e) { - const i = new ei(e); - if (i.push(t), i.err) throw i.msg || P[i.err]; - return i.result; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } - ei.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize, - r = this.options.dictionary; - let s, a, o; - if (this.ended) return !1; + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } - for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { - for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } - switch (s) { - case Je: - case Qe: - case qe: - case ti: - return this.onEnd(s), this.ended = !0, !1; - } + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; - if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { - let t = Gt(i.output, i.next_out), - e = i.next_out - t, - r = jt(i.output, t); - i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); - } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + return this._values.map(floatToInt); + } - if (s !== Xe || 0 !== o) { - if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; - if (0 === i.avail_in) break; - } - } + clone() { + return new Vec3(this.x, this.y, this.z); + } - return !0; - }, ei.prototype.onData = function (t) { - this.chunks.push(t); - }, ei.prototype.onEnd = function (t) { - t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; - var ni = { - Inflate: ei, - inflate: ii, - inflateRaw: function inflateRaw(t, e) { - return (e = e || {}).raw = !0, ii(t, e); - }, - ungzip: ii, - constants: H - }; - const { - Deflate: ri, - deflate: si, - deflateRaw: ai, - gzip: oi - } = he, - { - Inflate: hi, - inflate: li, - inflateRaw: di, - ungzip: _i - } = ni; - var fi = si, - ci = hi, - ui = li; - const wi = [137, 80, 78, 71, 13, 10, 26, 10], - pi = []; + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } - for (let t = 0; t < 256; t++) { - let e = t; + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } - for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } - pi[t] = e; + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; } - const gi = 4294967295; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } - function bi(t, e) { - return (function (t, e, i) { - let n = 4294967295; + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } - for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - return n; - }(0, t, e) ^ gi) >>> 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; } - var mi, ki, yi, vi; - !function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; - }(mi || (mi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; - }(ki || (ki = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; - }(yi || (yi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; - }(vi || (vi = {})); - const Ei = new Uint8Array(0), - Ai = new Uint16Array([255]), - xi = 255 === new Uint8Array(Ai.buffer)[0]; - - class Ui extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(t); - const { - checkCrc: i = !1 - } = e; - this._checkCrc = i, this._inflator = new ci(), this._png = { - width: -1, - height: -1, - channels: -1, - data: new Uint8Array(0), - depth: 1, - text: {} - }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); - } + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - decode() { - for (this.decodeSignature(); !this._end;) this.decodeChunk(); + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - return this.decodeImage(), this._png; - } + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } - decodeSignature() { - for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); - } + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } - decodeChunk() { - const t = this.readUint32(), - e = this.readChars(4), - i = this.offset; + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } - switch (e) { - case "IHDR": - this.decodeIHDR(); - break; + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } - case "PLTE": - this.decodePLTE(t); - break; + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } - case "IDAT": - this.decodeIDAT(t); - break; + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } - case "IEND": - this._end = !0; - break; + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } - case "tRNS": - this.decodetRNS(t); - break; + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } - case "iCCP": - this.decodeiCCP(t); - break; + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } - case "tEXt": - this.decodetEXt(t); - break; +} - case "pHYs": - this.decodepHYs(); - break; +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } - default: - this.skip(t); - } + get x() { + return this._values[0]; + } - if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + get y() { + return this._values[1]; + } - if (this._checkCrc) { - const i = this.readUint32(), - n = t + 4, - r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); - if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); - } else this.skip(4); - } + get z() { + return this._values[2]; + } - decodeIHDR() { - const t = this._png; - t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { - if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); - return t; - }(this.readUint8()); - const e = this.readUint8(); - let i; + get w() { + return this._values[3]; + } - switch (this._colorType = e, e) { - case mi.GREYSCALE: - i = 1; - break; + set x(value) { + this._values[0] = value; + } - case mi.TRUECOLOUR: - i = 3; - break; + set y(value) { + this._values[1] = value; + } - case mi.INDEXED_COLOUR: - i = 1; - break; + set z(value) { + this._values[2] = value; + } - case mi.GREYSCALE_ALPHA: - i = 2; - break; + set w(value) { + this._values[3] = value; + } - case mi.TRUECOLOUR_ALPHA: - i = 4; - break; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } - default: - throw new Error("Unknown color type: ".concat(e)); - } + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } - if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); - this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); - } + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } - decodePLTE(t) { - if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); - const e = t / 3; - this._hasPalette = !0; - const i = []; - this._palette = i; + get xyz() { + return new Vec3(this.x, this.y, this.z); + } - for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); - } + get splatX() { + return new Vec4(this.x); + } - decodeIDAT(t) { - this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); - } + get splatY() { + return new Vec4(this.y); + } - decodetRNS(t) { - if (3 === this._colorType) { - if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); - let e = 0; + get splatZ() { + return new Vec4(this.z); + } - for (; e < t; e++) { - const t = this.readByte(); + get splatW() { + return new Vec4(this.w); + } - this._palette[e].push(t); - } + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } - for (; e < this._palette.length; e++) this._palette[e].push(255); - } - } + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } - decodeiCCP(t) { - let e, - i = ""; + toVec3() { + return this.xyz; + } - for (; "\0" !== (e = this.readChar());) i += e; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } - const n = this.readUint8(); - if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); - const r = this.readBytes(t - i.length - 2); - this._png.iccEmbeddedProfile = { - name: i, - profile: ui(r) - }; - } + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } - decodetEXt(t) { - let e, - i = ""; + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } - for (; "\0" !== (e = this.readChar());) i += e; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } - this._png.text[i] = this.readChars(t - i.length - 1); - } + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } - decodepHYs() { - const t = this.readUint32(), - e = this.readUint32(), - i = this.readByte(); - this._png.resolution = { - x: t, - y: e, - unit: i - }; - } + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } - decodeImage() { - if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); - const t = this._inflator.result; - if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); - if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); - this.decodeInterlaceNull(t); - } + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - decodeInterlaceNull(t) { - const e = this._png.height, - i = this._png.channels * this._png.depth / 8, - n = this._png.width * i, - r = new Uint8Array(this._png.height * n); - let s, - a, - o = Ei, - h = 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } - for (let l = 0; l < e; l++) { - switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { - case 0: - zi(s, a, n); - break; + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - case 1: - Ri(s, a, n, i); - break; + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - case 2: - Ni(s, a, o, n); - break; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } - case 3: - Ti(s, a, o, n, i); - break; + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } - case 4: - Oi(s, a, o, n, i); - break; + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } - default: - throw new Error("Unsupported filter: ".concat(t[h])); - } + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } - o = a, h += n + 1; - } + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } - if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { - const t = new Uint16Array(r.buffer); - if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; - this._png.data = t; - } else this._png.data = r; + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } - var l; - } + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); } - function zi(t, e, i) { - for (let n = 0; n < i; n++) e[n] = t[n]; + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } - function Ri(t, e, i, n) { - let r = 0; + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } - for (; r < n; r++) e[r] = t[r]; + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } - for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); } - function Ni(t, e, i, n) { - let r = 0; - if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; } - function Ti(t, e, i, n, r) { - let s = 0; +} - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} - for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; - } else { - for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} - for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; - } - } +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - function Oi(t, e, i, n, r) { - let s = 0; +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} - for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; - } else { - for (; s < r; s++) e[s] = t[s] + i[s] & 255; +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; - for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; - } + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; } +} - function Li(t, e, i) { - const n = t + e - i, - r = Math.abs(n - t), - s = Math.abs(n - e), - a = Math.abs(n - i); - return r <= s && r <= a ? t : s <= a ? e : i; +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); } - const Bi = { - level: 3 - }; + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} - class Ci extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); - } +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; - encode() { - return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); - } + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - encodeSignature() { - this.writeBytes(wi); - } + for (let i = 0; i < 16; i++) { + const bit = 1 << i; - encodeIHDR() { - this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); - } + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } - encodeIEND() { - this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); - } + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } - encodeIDAT(t) { - this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); - } + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } - encodeData() { - const { - width: t, - height: e, - channels: i, - depth: n, - data: s - } = this._png, - a = i * t, - o = new r().setBigEndian(); - let h = 0; + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { - if (16 !== n) throw new Error("unreachable"); - h = Si(s, o, a, h); + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } } - - const l = o.toArray(), - d = fi(l, this._zlibOptions); - this.encodeIDAT(d); } - _checkData(t) { - const { - colorType: e, - channels: i, - depth: n - } = function (t) { - const { - channels: e = 4, - depth: i = 8 - } = t; - if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); - if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); - const n = { - channels: e, - depth: i, - colorType: mi.UNKNOWN - }; - - switch (e) { - case 4: - n.colorType = mi.TRUECOLOUR_ALPHA; - break; + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } - case 3: - n.colorType = mi.TRUECOLOUR; - break; + get transparent() { + return this._transparent; + } - case 1: - n.colorType = mi.GREYSCALE; - break; + get count() { + return this._count; + } - case 2: - n.colorType = mi.GREYSCALE_ALPHA; - break; + get points() { + return Object.freeze(this._points.slice()); + } - default: - throw new Error("unsupported number of channels"); - } + get weights() { + return Object.freeze(this._weights.slice()); + } - return n; - }(t), - r = { - width: Di(t.width, "width"), - height: Di(t.height, "height"), - channels: i, - data: t.data, - depth: n, - text: {} - }; + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); - this._colorType = e; - const s = r.width * r.height * i; - if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); - return r; - } + target.forEach((_, i) => target[i] = result[i]); + } - writeCrc(t) { - this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); - } + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + target.forEach((_, i) => target[i] = result[i]); } - function Di(t, e) { - if (Number.isInteger(t) && t > 0) return t; - throw new TypeError("".concat(e, " must be a positive integer")); +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; } - function Ii(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeByte(t[n++]); + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; - return n; + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); } - function Si(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + compress3(result, offset) {} - return n; + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; } - var Zi; - !function (t) { - t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; - }(Zi || (Zi = {})); + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); - const Fi = (t, e, i) => new Ci({ - width: t, - height: e, - data: i - }, undefined).encode(), - Mi = t => function (t, e) { - return new Ui(t, void 0).decode(); - }(t); -})(); + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } -var r = n.P, - s = n.m; + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; -function isTypeObject(object) { - return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); -} + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); -function stringify(o, gap, indentation) { - if (isTypeObject(o)) { - let s = stringify(o.data, gap, indentation); + this.compressBase(lookups, saveFunc); + } - if (s.includes('\n')) { - return ' #!' + o.type + s; - } else { - return s + ' #!' + o.type; - } - } else if (o && 'object' === typeof o) { - let isArray = Array.isArray(o); + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - if (Object.keys(o).length == 0) { - if (isArray) return '[]';else return '{}'; - } + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - let s = '\n'; + this.compressBase(lookups, saveFunc); + } - for (let k in o) { - if (Object.hasOwnProperty.call(o, k)) { - s += gap.repeat(indentation + 1); + computeEndPoints(lookups) { + this.error = Infinity; - if (isArray) { - s += '- ' + stringify(o[k], gap, indentation + 1); - } else { - if (k.includes(': ')) { - s += stringify(k, gap, indentation + 1); - s += ': ' + stringify(o[k], gap, indentation + 1); - } else { - s += k + ': ' + stringify(o[k], gap, indentation + 1); - } - } + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; - s += '\n'; + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; } } - - return s; - } else if ('string' === typeof o) { - return JSON.stringify(o); - } else if ('undefined' === typeof o || o === null) { - return 'null'; - } else if (!!o == o || +o == o) { - return JSON.stringify(o); - } else { - throw new Error('Non-implemented parsing for ' + o); } + } -function preStringify(object) { - let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; - var gap = ''; +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); - if (typeof space == 'number') { - gap = ' '.repeat(Math.min(10, space)); - } else if (typeof space == 'string') { - gap = space.slice(0, 10); + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); } - return stringify(object, gap, -1); -} + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); -class LineGenerator { - constructor(lines, indentString, startingLine) { - this.startingLine = startingLine || 0; - this.lineIndex = -1; - let filteredLines = []; + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } - for (let i = 0; i < lines.length; i++) { - let trimmedLine = lines[i].trim(); + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; - if (trimmedLine !== '') { - filteredLines.push([lines[i], i]); - } - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - this.lines = filteredLines; - this.indentString = indentString || this.findIndentString(); + this.compressBase(codes, saveFunc); } - getLineNumber() { - return this.startingLine + this.lineIndex; + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); } - nextGroup() { - let lines = []; - let baseIndent = this.indentLevel(this.lineIndex + 1); + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); - while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { - lines.push(this.next()); + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } } - return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); } - next() { - if (this.finished()) throw new Error('Trying to next finished generator'); - this.lineIndex++; - return this.getLine(); - } +} - peek() { - return this.getLine(this.lineIndex + 1); - } +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); - finished() { - return this.lineIndex == this.lines.length - 1; - } + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } - getLine(index) { - index = index !== undefined ? index : this.lineIndex; - if (index >= this.lines.length) return null; - return this.lines[index][0]; + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); } - findIndentString() { - for (let [line] of this.lines) { - if (!line.trim() || line.replace(/^\s+/, "") == line) continue; - return line.match(/^(\s+)/)[1]; - } - - return ''; + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; } - indentLevel(index) { - index = index !== undefined ? index : this.lineIndex; - if (index < 0) index = 0; - let indentLevel = 0; - let line = this.getLine(index); + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - while (line.startsWith(this.indentString)) { - line = line.slice(this.indentString.length); - indentLevel++; - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - return indentLevel; + this.compressBase(aabbx, saveFunc, 2); } -} + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; -function getObject(lineGroup, type) { - let object; - lineGroup.indentLevel(); + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - while (!lineGroup.finished()) { - let line = lineGroup.next(); - let trimmedLine = line.trim(); - let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); - let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); - let key, value, type; + this.compressBase(aabbx, saveFunc, 3); + } - if (trimmedLine.startsWith('"')) { - keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); - } + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; - if (typeMatch) { - type = typeMatch[1]; - trimmedLine = trimmedLine.replace(typeMatch[0], ''); - } + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); - if (keyMatch) { - if (!object) object = {}; - key = keyMatch[1]; - value = trimmedLine.replace(keyMatch[0], '').trim(); - } else if (trimmedLine.startsWith('-')) { - if (!object) object = []; - value = trimmedLine.slice(1).trim(); - } + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; - if (value) { - value = getValue(value, type); - } else { - value = getObject(lineGroup.nextGroup(), type); + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; } - if (Array.isArray(object)) { - object.push(value); - } else { - object[key] = value; - } + if (best.error < this.bestError) this.saveBlock(best, saveFunc); } - if (type) { - object = { - type: type, - data: object - }; + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); } - return object; -} - -function getValue(value, type) { - value = JSON.parse(value); - - if (type) { - value = { - type: type, - data: value - }; + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); } - return value; -} - -function parse(str) { - let lines = str.replace(/\t/g, ' ').split('\n'); - let lineGenerator = new LineGenerator(lines); - return getObject(lineGenerator); -} + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; -function deepCopy(obj) { - let newObj; + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; - if (Array.isArray(obj)) { - newObj = []; + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } - for (let item of obj) { - newObj.push(deepCopy(item)); + if (same) return false; } - return newObj; + return true; } - if (!!obj && typeof obj === "object") { - newObj = {}; + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); - for (let [key, value] of Object.entries(obj)) { - newObj[key] = deepCopy(value); + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); } - - return newObj; } - return obj; -} - -function isPrimitiveReaderType(reader) { - switch (reader) { - case 'Boolean': - case 'Int32': - case 'Char': - case 'String': - case '': - case 'Vector2': - case 'Vector3': - case 'Vector4': - case 'Rectangle': - return true; - - default: - return false; + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; } -} - -function isExportReaderType(reader) { - switch (reader) { - case 'Texture2D': - case 'TBin': - case 'Effect': - case 'BmFont': - return true; - default: - return false; + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; } -} - -function convertJsonContentsToXnbNode(raw, readers) { - let extractedImages = []; - let extractedMaps = []; - - const { - converted - } = function recursiveConvert(obj, path) { - let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - const reader = readers[index]; - if (isPrimitiveReaderType(reader)) { - return { - converted: { - type: reader, - data: obj - }, - traversed: index - }; - } + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); - if (reader === null) { - return { - converted: obj, - traversed: index - }; - } + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; - if (reader.startsWith('Nullable')) { - return { - converted: { - type: reader, - data: { - data: { - type: readers[index + 1], - data: obj - } - } - }, - traversed: index + 1 - }; + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); } - if (isExportReaderType(reader)) { - if (reader === 'Texture2D') { - extractedImages.push({ - path: path.join('.') - }); - return { - converted: { - type: reader, - data: { - format: obj.format - } - }, - traversed: index - }; - } + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } - if (reader === 'TBin') { - extractedMaps.push({ - path: path.join('.') - }); - } + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; - return { - converted: { - type: reader, - data: {} - }, - traversed: index + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index }; - } + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; - let data; - if (Array.isArray(obj)) data = [];else data = {}; - let traversed = index; - let first = true; - let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + let part0 = new Vec4(0.0); - for (let [key, value] of Object.entries(obj)) { - let newIndex; + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; - if (reader.startsWith("Dictionary")) { - if (getTypeInfo(reader).subtypes[1] === readers[index + 2]) newIndex = index + 2;else newIndex = index + 1; - } else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } - const { - converted, - traversed: nexter - } = recursiveConvert(obj[key], [...path, key], newIndex); - data[key] = converted; - if (isComplex) traversed = nexter;else if (first) { - traversed = nexter; - first = false; + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; } + + part0.addVector(this.pointsWeights[i]); } + } - return { - converted: { - type: reader, - data - }, - traversed - }; - }(raw, []); +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); return { - converted, - extractedImages, - extractedMaps + min, + max, + indices, + error }; } -function convertJsonContentsFromXnbNode(obj) { - if (!obj || typeof obj !== "object") return obj; +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; - if (typeof obj === "object" && obj.hasOwnProperty("data")) { - let { - type, - data - } = obj; - if (isPrimitiveReaderType(type)) return deepCopy(data); + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; - if (isExportReaderType(type)) { - data = deepCopy(data); - if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; - return data; + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; } + } - obj = deepCopy(data); + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; } - let newObj; + return codes; +} - if (Array.isArray(obj)) { - newObj = []; +function fitCodes(rgba, mask, codes, indices) { + let err = 0; - for (let item of obj) { - newObj.push(convertJsonContentsFromXnbNode(item)); + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; } - return newObj; - } + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; - if (!!obj && typeof obj === "object") { - newObj = {}; + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; - for (let [key, value] of Object.entries(obj)) { - newObj[key] = convertJsonContentsFromXnbNode(value); + if (dist < least) { + least = dist; + index = j; + } } - return newObj; + indices[i] = index; + err += least; } - return null; + return err; } -function toXnbNodeData(json) { - const toYamlJson = {}; - const { - compressed, - formatVersion, - hidef: hiDef, - target - } = json.header; - let readerData = deepCopy(json.readers); - toYamlJson.xnbData = { - target, - compressed: !!compressed, - hiDef, - readerData, - numSharedResources: 0 - }; - const rawContent = deepCopy(json.content); - let readersTypeList = readerData.map(_ref => { - let { - type - } = _ref; - return simplifyType(type); - }); +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } - if (readersTypeList[0] === 'SpriteFont') { - readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; - rawContent.verticalSpacing = rawContent.verticalLineSpacing; - delete rawContent.verticalLineSpacing; + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } } +} - const { - converted, - extractedImages, - extractedMaps - } = convertJsonContentsToXnbNode(rawContent, readersTypeList); - toYamlJson.content = converted; - if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; - if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; - return toYamlJson; +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; } -function fromXnbNodeData(json) { - const result = {}; - const { - compressed, - readerData, - hiDef: hidef, - target - } = json.xnbData; - result.header = { - target, - formatVersion: 5, - compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, - hidef - }; - result.readers = deepCopy(readerData); - result.content = convertJsonContentsFromXnbNode(json.content); +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} - if (simplifyType(result.readers[0].type) === 'SpriteFont') { - result.content.verticalLineSpacing = result.content.verticalSpacing; - delete result.content.verticalSpacing; +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; } return result; } -function searchElement(parent, element) { - if (!parent || typeof parent != 'object') return; - - if (parent.hasOwnProperty(element)) { - return { - parent, - value: parent[element] - }; - } +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); - for (let child of Object.values(parent)) { - if (!!child || typeof child == 'object') { - let found = searchElement(child, element); - if (found) return found; + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; } } - - return null; } -function extractFileName(fullname) { - let matcher = fullname.match(/(.*)\.([^\s.]+)$/); - if (matcher === null) return [fullname, null]; - return [matcher[1], matcher[2]]; +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } } -function getExtension(dataType) { - switch (dataType) { - case "JSON": - return "json"; - - case "yaml": - return "yaml"; +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; - case "Texture2D": - return "png"; + for (let i = 0; i < 2; i++) { + let value = 0; - case "Effect": - return "cso"; + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } - case 'TBin': - return "tbin"; + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } - case 'BmFont': - return "xml"; + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; } +} - return "bin"; +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } } -function getMimeType(dataType) { - switch (dataType) { - case "JSON": - return "application/json"; +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} - case "yaml": - return "text/plain"; +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} - case "Texture2D": - return "image/png"; +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} - case "Effect": - return "application/x-cso"; +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - case 'BmFont': - return "application/xml"; - } + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); - return "application/octet-stream"; -} + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } -function makeBlob(data, dataType) { - if (typeof Blob === "function") return { - data: new Blob([data], { - type: getMimeType(dataType) - }), - extension: getExtension(dataType) - }; + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); return { - data: data, - extension: getExtension(dataType) + block, + mask }; } -function exportContent(content) { - let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - let found = searchElement(content, "export"); +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - if (found) { - const { - value - } = found; - let { - type: dataType, - data - } = value; + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); - if (dataType === "Texture2D") { - data = s(value.width, value.height, new Uint8Array(data)); - } + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} - return makeBlob(data, dataType); - } +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} - if (jsonContent) { - let contentJson = JSON.stringify(content, null, 4); - return makeBlob(contentJson, "JSON"); - } +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} - return null; +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); } -/** @api - * decompressed xnb object to real file blobs. - * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) - * @param {Object} config (yaml:export file as yaml, - * contentOnly:export content file only, - * fileName:exported files's name) (optional) - */ +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} -function exportFiles(xnbObject) { - let { - yaml: isYaml = false, - contentOnly = false, - fileName = null - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (isYaml && contentOnly) isYaml = false; - if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); - const blobs = []; - const { - content - } = xnbObject; - const contentBlob = exportContent(content, contentOnly); - if (contentBlob !== null) blobs.push(contentBlob); - if (contentOnly) return blobs; - const resultJSON = JSON.stringify(xnbObject, (key, value) => { - if (key === "export") { - if (typeof fileName == "string" && fileName !== "") { - return "".concat(fileName, ".").concat(getExtension(value.type)); - } +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; - return "".concat(value.type, ".").concat(getExtension(value.type)); + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; } - - return value; - }, 4); - let result = resultJSON; - if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); - blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); - return blobs; + } } -function resolveCompression(compressionString) { - let str = compressionString.toLowerCase(); - if (str === "none") return 0; - if (str === "lz4") return 0x40; - return null; -} +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; -async function readBlobasText(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; } -async function readBlobasArrayBuffer(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; } -async function readExternFiles(extension, files) { - if (extension === "png") { - const rawPng = await readBlobasArrayBuffer(files.png); - const png = r(new Uint8Array(rawPng)); - return { - type: "Texture2D", - data: png.data, - width: png.width, - height: png.height - }; +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } } - if (extension === "cso") { - const data = await readBlobasArrayBuffer(files.cso); + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + return { - type: "Effect", - data + format, + export: { + type: this.type, + data, + width, + height + } }; } - if (extension === "tbin") { - const data = await readBlobasArrayBuffer(files.tbin); - return { - type: "TBin", - data - }; + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); } - if (extension === "xml") { - const data = await readBlobasText(files.xml); - return { - type: "BmFont", - data - }; + isValueType() { + return false; } + } -async function resolveImports(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const { - compression = "default" - } = configs; - const jsonFile = files.json || files.yaml; - if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); - const rawText = await readBlobasText(jsonFile); - let jsonData = null; - if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); - let compressBits = resolveCompression(compression); - if (compressBits !== null) jsonData.header.compressed = compressBits; +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; - if (!jsonData.hasOwnProperty('content')) { - throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + default: + return false; + } } - const found = searchElement(jsonData.content, "export"); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } - if (found) { - const { - parent, - value - } = found; - const [, extension] = extractFileName(value); - parent.export = await readExternFiles(extension, files); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); } - return jsonData; } -/** @api - * Asynchronously reads the file into binary and then unpacks the json data. - * XNB -> arrayBuffer -> XnbData - * @param {File / Buffer} file - * @return {XnbData} JSON data with headers - */ - -async function unpackToXnbData(file) { - if (typeof window !== "undefined") { - const [, extension] = extractFileName(file.name); +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; - if (extension !== "xnb") { - return new Error("Invalid XNB File!"); + default: + return false; } - - const buffer = await file.arrayBuffer(); - return bufferToXnb(buffer); } - return bufferToXnb(file.buffer); -} -/** @api - * Asynchronously reads the file into binary and then return content file. - * XNB -> arrayBuffer -> XnbData -> Content - * @param {File / Buffer} file - * @return {XnbContent} exported Content Object - */ + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } -function unpackToContent(file) { - return unpackToXnbData(file).then(xnbDataToContent); -} -/** @api - * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. - * XNB -> arrayBuffer -> XnbData -> Files - * @param {File / Buffer} file - * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) - * @return {Array} exported Files Blobs - */ + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } -function unpackToFiles(file) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let { - yaml = false, - contentOnly = false, - fileName: name = null - } = configs; - if (typeof window !== "undefined" && name === null) name = file.name; - let [fileName] = extractFileName(name); + console.log("writing complitd!"); + } - const exporter = xnbObject => exportFiles(xnbObject, { - yaml, - contentOnly, - fileName - }); + isValueType() { + return false; + } - return unpackToXnbData(file).then(exporter); } -/** @api - * reads the buffer and then unpacks. - * arrayBuffer -> XnbData - * @param {ArrayBuffer} buffer - * @return {XnbData} the loaded XNB json - */ +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; -function bufferToXnb(buffer) { - const xnb = new XnbConverter(); - return xnb.load(buffer); -} -/** @api - * reads the buffer and then unpacks the contents. - * arrayBuffer -> XnbData -> Content - * @param {ArrayBuffer} buffer - * @return {XnbContent} exported Content Object - */ + default: + return false; + } + } + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } -function bufferToContents(buffer) { - const xnb = new XnbConverter(); - const xnbData = xnb.load(buffer); - return xnbDataToContent(xnbData); -} -/** @api - * remove header from the loaded XNB Object - * XnbData -> Content - * @param {XnbData} the loaded XNB object include headers - * @return {XnbContent} exported Content Object - */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + isValueType() { + return false; + } -function xnbDataToContent(loadedXnb) { - const { - content - } = loadedXnb; - const { - data, - extension - } = exportContent(content, true); - return new XnbContent(data, extension); } -/** @api - * reads the json and then unpacks the contents. - * @param {FileList/Array} to pack json data - * @return {Object/Object} packed XNB Array Buffer - */ - -function fileMapper(files) { - let returnMap = {}; +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; - for (let i = 0; i < files.length; i++) { - const file = files[i]; - let [fileName, extension] = extractFileName(file.name); - if (extension === null) continue; - if (returnMap[fileName] === undefined) returnMap[fileName] = {}; - const namedFileObj = returnMap[fileName]; - if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + default: + return false; + } } - return returnMap; -} -/** @api - * reads the json and then unpacks the contents. - * @param {json} to pack json data - * @return {ArrayBuffer} packed XNB Array Buffer - */ - + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } -function packJsonToBinary(json) { - const xnb = new XnbConverter(); - const buffer = xnb.convert(json); - return buffer; } -/** @api - * Asynchronously reads the file into binary and then pack xnb files. - * @param {FlieList} files - * @param {Object} configs(compression:default, none, LZ4, LZX / debug) - * @return {Array(Blobs)} - */ +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; -function pack(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const groupedFiles = fileMapper(files); - let promises = []; + default: + return false; + } + } - for (let [fileName, filePack] of Object.entries(groupedFiles)) { - promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { - if (typeof Blob === "function") return { - name: fileName, - data: new Blob([buffer], { - type: "application/octet-stream" - }) - }; - return { - name: fileName, - data: new Uint8Array(buffer) - }; - })); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; } - return __promise_allSettled(promises).then(blobArray => { - if (configs.debug === true) return blobArray; - return blobArray.filter(_ref => { - let { - status, - value - } = _ref; - return status === "fulfilled"; - }).map(_ref2 => { - let { - value - } = _ref2; - return value; - }); - }); } +const Readers = { + ArrayReader: ArrayReader, + BaseReader: BaseReader, + BmFontReader: BmFontReader, + BooleanReader: BooleanReader, + CharReader: CharReader, + DictionaryReader: DictionaryReader, + DoubleReader: DoubleReader, + EffectReader: EffectReader, + Int32Reader: Int32Reader, + ListReader: ListReader, + NullableReader: NullableReader, + RectangleReader: RectangleReader, + ReflectiveReader: ReflectiveReader, + SingleReader: SingleReader, + SpriteFontReader: SpriteFontReader, + StringReader: StringReader, + TBinReader: TBinReader, + Texture2DReader: Texture2DReader, + UInt32Reader: UInt32Reader, + Vector2Reader: Vector2Reader, + Vector3Reader: Vector3Reader, + Vector4Reader: Vector4Reader +}; +setReaders(Readers); + +exports.Readers = Readers; exports.XnbContent = XnbContent; exports.XnbData = XnbData; +exports.addReaders = addReaders; exports.bufferToContents = bufferToContents; exports.bufferToXnb = bufferToXnb; exports.pack = pack; diff --git a/dist/xnb.es5.js b/dist/xnb.es5.js index 2499287..f279887 100644 --- a/dist/xnb.es5.js +++ b/dist/xnb.es5.js @@ -72,7 +72,7 @@ return !!descriptor && descriptor.enumerable; } : $propertyIsEnumerable; - var createPropertyDescriptor$3 = function (bitmap, value) { + var createPropertyDescriptor$2 = function (bitmap, value) { return { enumerable: !(bitmap & 1), configurable: !(bitmap & 2), @@ -137,7 +137,7 @@ var IndexedObject$1 = indexedObject; var requireObjectCoercible$1 = requireObjectCoercible$2; - var toIndexedObject$4 = function (it) { + var toIndexedObject$3 = function (it) { return IndexedObject$1(requireObjectCoercible$1(it)); }; @@ -413,7 +413,7 @@ // `ToPropertyKey` abstract operation // https://tc39.es/ecma262/#sec-topropertykey - var toPropertyKey$3 = function (argument) { + var toPropertyKey$2 = function (argument) { var key = toPrimitive(argument, 'string'); return isSymbol(key) ? key : key + ''; }; @@ -429,24 +429,24 @@ return EXISTS$1 ? document$2.createElement(it) : {}; }; - var DESCRIPTORS$9 = descriptors; + var DESCRIPTORS$8 = descriptors; var fails$6 = fails$b; var createElement$1 = documentCreateElement; // Thanks to IE8 for its funny defineProperty - var ie8DomDefine = !DESCRIPTORS$9 && !fails$6(function () { + var ie8DomDefine = !DESCRIPTORS$8 && !fails$6(function () { // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing return Object.defineProperty(createElement$1('div'), 'a', { get: function () { return 7; } }).a != 7; }); - var DESCRIPTORS$8 = descriptors; + var DESCRIPTORS$7 = descriptors; var call$8 = functionCall; var propertyIsEnumerableModule = objectPropertyIsEnumerable; - var createPropertyDescriptor$2 = createPropertyDescriptor$3; - var toIndexedObject$3 = toIndexedObject$4; - var toPropertyKey$2 = toPropertyKey$3; + var createPropertyDescriptor$1 = createPropertyDescriptor$2; + var toIndexedObject$2 = toIndexedObject$3; + var toPropertyKey$1 = toPropertyKey$2; var hasOwn$9 = hasOwnProperty_1; var IE8_DOM_DEFINE$1 = ie8DomDefine; @@ -455,23 +455,23 @@ // `Object.getOwnPropertyDescriptor` method // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor - objectGetOwnPropertyDescriptor.f = DESCRIPTORS$8 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) { - O = toIndexedObject$3(O); - P = toPropertyKey$2(P); + objectGetOwnPropertyDescriptor.f = DESCRIPTORS$7 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) { + O = toIndexedObject$2(O); + P = toPropertyKey$1(P); if (IE8_DOM_DEFINE$1) try { return $getOwnPropertyDescriptor$1(O, P); } catch (error) { /* empty */ } - if (hasOwn$9(O, P)) return createPropertyDescriptor$2(!call$8(propertyIsEnumerableModule.f, O, P), O[P]); + if (hasOwn$9(O, P)) return createPropertyDescriptor$1(!call$8(propertyIsEnumerableModule.f, O, P), O[P]); }; var objectDefineProperty = {}; - var DESCRIPTORS$7 = descriptors; + var DESCRIPTORS$6 = descriptors; var fails$5 = fails$b; // V8 ~ Chrome 36- // https://bugs.chromium.org/p/v8/issues/detail?id=3334 - var v8PrototypeDefineBug = DESCRIPTORS$7 && fails$5(function () { + var v8PrototypeDefineBug = DESCRIPTORS$6 && fails$5(function () { // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing return Object.defineProperty(function () { /* empty */ }, 'prototype', { value: 42, @@ -492,11 +492,11 @@ }; var global$n = global$D; - var DESCRIPTORS$6 = descriptors; + var DESCRIPTORS$5 = descriptors; var IE8_DOM_DEFINE = ie8DomDefine; var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; var anObject$7 = anObject$8; - var toPropertyKey$1 = toPropertyKey$3; + var toPropertyKey = toPropertyKey$2; var TypeError$a = global$n.TypeError; // eslint-disable-next-line es-x/no-object-defineproperty -- safe @@ -509,9 +509,9 @@ // `Object.defineProperty` method // https://tc39.es/ecma262/#sec-object.defineproperty - objectDefineProperty.f = DESCRIPTORS$6 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { + objectDefineProperty.f = DESCRIPTORS$5 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { anObject$7(O); - P = toPropertyKey$1(P); + P = toPropertyKey(P); anObject$7(Attributes); if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { var current = $getOwnPropertyDescriptor(O, P); @@ -526,7 +526,7 @@ } return $defineProperty(O, P, Attributes); } : $defineProperty : function defineProperty(O, P, Attributes) { anObject$7(O); - P = toPropertyKey$1(P); + P = toPropertyKey(P); anObject$7(Attributes); if (IE8_DOM_DEFINE) try { return $defineProperty(O, P, Attributes); @@ -536,12 +536,12 @@ return O; }; - var DESCRIPTORS$5 = descriptors; - var definePropertyModule$3 = objectDefineProperty; - var createPropertyDescriptor$1 = createPropertyDescriptor$3; + var DESCRIPTORS$4 = descriptors; + var definePropertyModule$2 = objectDefineProperty; + var createPropertyDescriptor = createPropertyDescriptor$2; - var createNonEnumerableProperty$4 = DESCRIPTORS$5 ? function (object, key, value) { - return definePropertyModule$3.f(object, key, createPropertyDescriptor$1(1, value)); + var createNonEnumerableProperty$4 = DESCRIPTORS$4 ? function (object, key, value) { + return definePropertyModule$2.f(object, key, createPropertyDescriptor(1, value)); } : function (object, key, value) { object[key] = value; return object; @@ -549,17 +549,17 @@ var makeBuiltIn$2 = {exports: {}}; - var DESCRIPTORS$4 = descriptors; + var DESCRIPTORS$3 = descriptors; var hasOwn$8 = hasOwnProperty_1; var FunctionPrototype$2 = Function.prototype; // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe - var getDescriptor = DESCRIPTORS$4 && Object.getOwnPropertyDescriptor; + var getDescriptor = DESCRIPTORS$3 && Object.getOwnPropertyDescriptor; var EXISTS = hasOwn$8(FunctionPrototype$2, 'name'); // additional protection from minified / mangled / dropped function names var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; - var CONFIGURABLE = EXISTS && (!DESCRIPTORS$4 || (DESCRIPTORS$4 && getDescriptor(FunctionPrototype$2, 'name').configurable)); + var CONFIGURABLE = EXISTS && (!DESCRIPTORS$3 || (DESCRIPTORS$3 && getDescriptor(FunctionPrototype$2, 'name').configurable)); var functionName = { EXISTS: EXISTS, @@ -782,14 +782,14 @@ return toLength(obj.length); }; - var toIndexedObject$2 = toIndexedObject$4; + var toIndexedObject$1 = toIndexedObject$3; var toAbsoluteIndex = toAbsoluteIndex$1; var lengthOfArrayLike$2 = lengthOfArrayLike$3; // `Array.prototype.{ indexOf, includes }` methods implementation var createMethod$1 = function (IS_INCLUDES) { return function ($this, el, fromIndex) { - var O = toIndexedObject$2($this); + var O = toIndexedObject$1($this); var length = lengthOfArrayLike$2(O); var index = toAbsoluteIndex(fromIndex, length); var value; @@ -817,14 +817,14 @@ var uncurryThis$7 = functionUncurryThis; var hasOwn$5 = hasOwnProperty_1; - var toIndexedObject$1 = toIndexedObject$4; + var toIndexedObject = toIndexedObject$3; var indexOf = arrayIncludes.indexOf; var hiddenKeys$1 = hiddenKeys$3; var push$1 = uncurryThis$7([].push); var objectKeysInternal = function (object, names) { - var O = toIndexedObject$1(object); + var O = toIndexedObject(object); var i = 0; var result = []; var key; @@ -873,21 +873,21 @@ var concat = uncurryThis$6([].concat); // all object keys, includes non-enumerable and symbols - var ownKeys$3 = getBuiltIn$5('Reflect', 'ownKeys') || function ownKeys(it) { + var ownKeys$2 = getBuiltIn$5('Reflect', 'ownKeys') || function ownKeys(it) { var keys = getOwnPropertyNamesModule.f(anObject$6(it)); var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys; }; var hasOwn$4 = hasOwnProperty_1; - var ownKeys$2 = ownKeys$3; - var getOwnPropertyDescriptorModule$1 = objectGetOwnPropertyDescriptor; - var definePropertyModule$2 = objectDefineProperty; + var ownKeys$1 = ownKeys$2; + var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor; + var definePropertyModule$1 = objectDefineProperty; var copyConstructorProperties$1 = function (target, source, exceptions) { - var keys = ownKeys$2(source); - var defineProperty = definePropertyModule$2.f; - var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule$1.f; + var keys = ownKeys$1(source); + var defineProperty = definePropertyModule$1.f; + var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; for (var i = 0; i < keys.length; i++) { var key = keys[i]; if (!hasOwn$4(target, key) && !(exceptions && hasOwn$4(exceptions, key))) { @@ -1033,17 +1033,17 @@ }; var getBuiltIn$4 = getBuiltIn$8; - var definePropertyModule$1 = objectDefineProperty; + var definePropertyModule = objectDefineProperty; var wellKnownSymbol$9 = wellKnownSymbol$c; - var DESCRIPTORS$3 = descriptors; + var DESCRIPTORS$2 = descriptors; var SPECIES$3 = wellKnownSymbol$9('species'); var setSpecies$1 = function (CONSTRUCTOR_NAME) { var Constructor = getBuiltIn$4(CONSTRUCTOR_NAME); - var defineProperty = definePropertyModule$1.f; + var defineProperty = definePropertyModule.f; - if (DESCRIPTORS$3 && Constructor && !Constructor[SPECIES$3]) { + if (DESCRIPTORS$2 && Constructor && !Constructor[SPECIES$3]) { defineProperty(Constructor, SPECIES$3, { configurable: true, get: function () { return this; } @@ -1550,7 +1550,7 @@ return new PromiseCapability(C); }; - var $$6 = _export; + var $$5 = _export; var IS_NODE = engineIsNode; var global$6 = global$D; var call$6 = functionCall; @@ -1830,7 +1830,7 @@ } } - $$6({ global: true, wrap: true, forced: FORCED_PROMISE_CONSTRUCTOR$4 }, { + $$5({ global: true, wrap: true, forced: FORCED_PROMISE_CONSTRUCTOR$4 }, { Promise: PromiseConstructor }); @@ -1969,7 +1969,7 @@ } return new Result(false); }; - function ownKeys$1(object, enumerableOnly) { + function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { @@ -1985,9 +1985,9 @@ function _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } @@ -2251,6 +2251,20 @@ return str.indexOf(token) !== -1; } + function __startsWithString(str, token) { + if (!!str && typeof str.startsWith === "function") return str.startsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp("^" + token); + return regexp.test(str); + } + + function __endsWithString(str, token) { + if (typeof str.endsWith === "function") return str.endsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp(token + "$"); + return regexp.test(str); + } + function __arrayMaker(obj, func) { if (!obj || _typeof(obj) !== "object") throw new Error("Invalid Data!"); var result = []; @@ -2332,7 +2346,7 @@ NativePromiseConstructor$1.all(iterable).then(undefined, function () { /* empty */ }); }); - var $$5 = _export; + var $$4 = _export; var call$2 = functionCall; var aCallable$1 = aCallable$7; var newPromiseCapabilityModule$2 = newPromiseCapability$2; @@ -2342,7 +2356,7 @@ // `Promise.all` method // https://tc39.es/ecma262/#sec-promise.all - $$5({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION$1 }, { + $$4({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION$1 }, { all: function all(iterable) { var C = this; var capability = newPromiseCapabilityModule$2.f(C); @@ -2371,7 +2385,7 @@ } }); - var $$4 = _export; + var $$3 = _export; var FORCED_PROMISE_CONSTRUCTOR$2 = promiseConstructorDetection.CONSTRUCTOR; var NativePromiseConstructor = promiseNativeConstructor; var getBuiltIn$1 = getBuiltIn$8; @@ -2382,7 +2396,7 @@ // `Promise.prototype.catch` method // https://tc39.es/ecma262/#sec-promise.prototype.catch - $$4({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR$2, real: true }, { + $$3({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR$2, real: true }, { 'catch': function (onRejected) { return this.then(undefined, onRejected); } @@ -2396,7 +2410,7 @@ } } - var $$3 = _export; + var $$2 = _export; var call$1 = functionCall; var aCallable = aCallable$7; var newPromiseCapabilityModule$1 = newPromiseCapability$2; @@ -2406,7 +2420,7 @@ // `Promise.race` method // https://tc39.es/ecma262/#sec-promise.race - $$3({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { + $$2({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { race: function race(iterable) { var C = this; var capability = newPromiseCapabilityModule$1.f(C); @@ -2422,14 +2436,14 @@ } }); - var $$2 = _export; + var $$1 = _export; var call = functionCall; var newPromiseCapabilityModule = newPromiseCapability$2; var FORCED_PROMISE_CONSTRUCTOR$1 = promiseConstructorDetection.CONSTRUCTOR; // `Promise.reject` method // https://tc39.es/ecma262/#sec-promise.reject - $$2({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR$1 }, { + $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR$1 }, { reject: function reject(r) { var capability = newPromiseCapabilityModule.f(this); call(capability.reject, undefined, r); @@ -2450,7 +2464,7 @@ return promiseCapability.promise; }; - var $$1 = _export; + var $ = _export; var getBuiltIn = getBuiltIn$8; var FORCED_PROMISE_CONSTRUCTOR = promiseConstructorDetection.CONSTRUCTOR; var promiseResolve = promiseResolve$1; @@ -2459,7 +2473,7 @@ // `Promise.resolve` method // https://tc39.es/ecma262/#sec-promise.resolve - $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, { + $({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, { resolve: function resolve(x) { return promiseResolve(this, x); } @@ -3223,67 +3237,6 @@ } } (runtime)); - var toPropertyKey = toPropertyKey$3; - var definePropertyModule = objectDefineProperty; - var createPropertyDescriptor = createPropertyDescriptor$3; - - var createProperty$1 = function (object, key, value) { - var propertyKey = toPropertyKey(key); - if (propertyKey in object) definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value)); - else object[propertyKey] = value; - }; - - var $ = _export; - var DESCRIPTORS$2 = descriptors; - var ownKeys = ownKeys$3; - var toIndexedObject = toIndexedObject$4; - var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor; - var createProperty = createProperty$1; - - // `Object.getOwnPropertyDescriptors` method - // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors - $({ target: 'Object', stat: true, sham: !DESCRIPTORS$2 }, { - getOwnPropertyDescriptors: function getOwnPropertyDescriptors(object) { - var O = toIndexedObject(object); - var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; - var keys = ownKeys(O); - var result = {}; - var index = 0; - var key, descriptor; - while (keys.length > index) { - descriptor = getOwnPropertyDescriptor(O, key = keys[index++]); - if (descriptor !== undefined) createProperty(result, key, descriptor); - } - return result; - } - }); - - var DESCRIPTORS$1 = descriptors; - var FUNCTION_NAME_EXISTS = functionName.EXISTS; - var uncurryThis$1 = functionUncurryThis; - var defineProperty$1 = objectDefineProperty.f; - - var FunctionPrototype = Function.prototype; - var functionToString = uncurryThis$1(FunctionPrototype.toString); - var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/; - var regExpExec = uncurryThis$1(nameRE.exec); - var NAME$1 = 'name'; - - // Function instances `.name` property - // https://tc39.es/ecma262/#sec-function-instances-name - if (DESCRIPTORS$1 && !FUNCTION_NAME_EXISTS) { - defineProperty$1(FunctionPrototype, NAME$1, { - configurable: true, - get: function () { - try { - return regExpExec(nameRE, functionToString(this))[1]; - } catch (error) { - return ''; - } - } - }); - } - // eslint-disable-next-line es-x/no-typed-arrays -- safe var arrayBufferNative = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined'; @@ -3319,7 +3272,7 @@ }; var NATIVE_ARRAY_BUFFER = arrayBufferNative; - var DESCRIPTORS = descriptors; + var DESCRIPTORS$1 = descriptors; var global$2 = global$D; var isCallable = isCallable$j; var isObject$1 = isObject$9; @@ -3328,7 +3281,7 @@ var tryToString = tryToString$5; var createNonEnumerableProperty = createNonEnumerableProperty$4; var defineBuiltIn = defineBuiltIn$4; - var defineProperty = objectDefineProperty.f; + var defineProperty$1 = objectDefineProperty.f; var isPrototypeOf = objectIsPrototypeOf; var getPrototypeOf = objectGetPrototypeOf; var setPrototypeOf = objectSetPrototypeOf; @@ -3350,7 +3303,7 @@ // Fixing native typed arrays in Opera Presto crashes the browser, see #595 var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof$1(global$2.opera) !== 'Opera'; var TYPED_ARRAY_TAG_REQUIRED = false; - var NAME, Constructor, Prototype; + var NAME$1, Constructor, Prototype; var TypedArrayConstructorsList = { Int8Array: 1, @@ -3395,7 +3348,7 @@ }; var exportTypedArrayMethod$1 = function (KEY, property, forced, options) { - if (!DESCRIPTORS) return; + if (!DESCRIPTORS$1) return; if (forced) for (var ARRAY in TypedArrayConstructorsList) { var TypedArrayConstructor = global$2[ARRAY]; if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try { @@ -3415,7 +3368,7 @@ var exportTypedArrayStaticMethod = function (KEY, property, forced) { var ARRAY, TypedArrayConstructor; - if (!DESCRIPTORS) return; + if (!DESCRIPTORS$1) return; if (setPrototypeOf) { if (forced) for (ARRAY in TypedArrayConstructorsList) { TypedArrayConstructor = global$2[ARRAY]; @@ -3438,15 +3391,15 @@ } }; - for (NAME in TypedArrayConstructorsList) { - Constructor = global$2[NAME]; + for (NAME$1 in TypedArrayConstructorsList) { + Constructor = global$2[NAME$1]; Prototype = Constructor && Constructor.prototype; if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); else NATIVE_ARRAY_BUFFER_VIEWS = false; } - for (NAME in BigIntArrayConstructorsList) { - Constructor = global$2[NAME]; + for (NAME$1 in BigIntArrayConstructorsList) { + Constructor = global$2[NAME$1]; Prototype = Constructor && Constructor.prototype; if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); } @@ -3457,15 +3410,15 @@ TypedArray = function TypedArray() { throw TypeError$1('Incorrect invocation'); }; - if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) { - if (global$2[NAME]) setPrototypeOf(global$2[NAME], TypedArray); + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$2[NAME$1]) setPrototypeOf(global$2[NAME$1], TypedArray); } } if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) { TypedArrayPrototype = TypedArray.prototype; - if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) { - if (global$2[NAME]) setPrototypeOf(global$2[NAME].prototype, TypedArrayPrototype); + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$2[NAME$1]) setPrototypeOf(global$2[NAME$1].prototype, TypedArrayPrototype); } } @@ -3474,13 +3427,13 @@ setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype); } - if (DESCRIPTORS && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) { + if (DESCRIPTORS$1 && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) { TYPED_ARRAY_TAG_REQUIRED = true; - defineProperty(TypedArrayPrototype, TO_STRING_TAG, { get: function () { + defineProperty$1(TypedArrayPrototype, TO_STRING_TAG, { get: function () { return isObject$1(this) ? this[TYPED_ARRAY_TAG] : undefined; } }); - for (NAME in TypedArrayConstructorsList) if (global$2[NAME]) { - createNonEnumerableProperty(global$2[NAME], TYPED_ARRAY_TAG, NAME); + for (NAME$1 in TypedArrayConstructorsList) if (global$2[NAME$1]) { + createNonEnumerableProperty(global$2[NAME$1], TYPED_ARRAY_TAG, NAME$1); } } @@ -3540,13 +3493,13 @@ }; var bind = functionBindContext; - var uncurryThis = functionUncurryThis; + var uncurryThis$1 = functionUncurryThis; var IndexedObject = indexedObject; var toObject = toObject$3; var lengthOfArrayLike = lengthOfArrayLike$3; var arraySpeciesCreate = arraySpeciesCreate$1; - var push = uncurryThis([].push); + var push = uncurryThis$1([].push); // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation var createMethod = function (TYPE) { @@ -3640,11 +3593,179 @@ }); }); + var DESCRIPTORS = descriptors; + var FUNCTION_NAME_EXISTS = functionName.EXISTS; + var uncurryThis = functionUncurryThis; + var defineProperty = objectDefineProperty.f; + + var FunctionPrototype = Function.prototype; + var functionToString = uncurryThis(FunctionPrototype.toString); + var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/; + var regExpExec = uncurryThis(nameRE.exec); + var NAME = 'name'; + + // Function instances `.name` property + // https://tc39.es/ecma262/#sec-function-instances-name + if (DESCRIPTORS && !FUNCTION_NAME_EXISTS) { + defineProperty(FunctionPrototype, NAME, { + configurable: true, + get: function () { + try { + return regExpExec(nameRE, functionToString(this))[1]; + } catch (error) { + return ''; + } + } + }); + } + + var XnbError = function (_Error) { + _inherits(XnbError, _Error); + + var _super = _createSuper(XnbError); + + function XnbError() { + var _this; + + var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + + _classCallCheck(this, XnbError); + + _this = _super.call(this, message); + _this.name = "XnbError"; + _this.message = message; + Error.captureStackTrace(_assertThisInitialized(_this), XnbError); + return _this; + } + + return _createClass(XnbError); + }(_wrapNativeSuper(Error)); + + var TypeReader = function () { + function TypeReader() { + _classCallCheck(this, TypeReader); + } + + _createClass(TypeReader, null, [{ + key: "setReaders", + value: function setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + }, { + key: "addReaders", + value: function addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + }, { + key: "makeSimplied", + value: function makeSimplied(type, reader) { + var simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + var subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + }, { + key: "simplifyType", + value: function (_simplifyType) { + function simplifyType(_x) { + return _simplifyType.apply(this, arguments); + } + + simplifyType.toString = function () { + return _simplifyType.toString(); + }; + + return simplifyType; + }(function (type) { + var simple = type.split(/`|,/)[0]; + + var isArray = __endsWithString(simple, '[]'); + + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + var reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (var _i2 = 0, _Object$values2 = Object.values(TypeReader.readers); _i2 < _Object$values2.length; _i2++) { + var reader = _Object$values2[_i2]; + var result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + }) + }, { + key: "parseSubtypes", + value: function parseSubtypes(type) { + var subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + var matches = subtype.match(pattern).map(function (e) { + return e.slice(1, -1); + }); + return matches; + } + }, { + key: "getTypeInfo", + value: function getTypeInfo(type) { + var mainType = type.match(/[^<]+/)[0]; + var subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(function (type) { + return type.trim(); + }) : []; + return { + type: mainType, + subtypes: subtypes + }; + } + }, { + key: "getReaderTypeList", + value: function getReaderTypeList(typeString) { + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; + + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReader", + value: function getReader(typeString) { + var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn2.type, + subtypes = _TypeReader$getTypeIn2.subtypes; + + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReaderFromRaw", + value: function getReaderFromRaw(typeString) { + var simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + }]); + + return TypeReader; + }(); + + _defineProperty(TypeReader, "readers", {}); + var UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; var UTF8_SECOND_BITES = 0x80; var UTF8_MASK = 63; - var UTF16_BITES$1 = [0xD800, 0xDC00]; - var UTF16_MASK$1 = 1023; + var UTF16_BITES$2 = [0xD800, 0xDC00]; + var UTF16_MASK$2 = 1023; function UTF8Encode(code) { if (code < 0x80) return [code]; @@ -3656,7 +3777,7 @@ function UTF16Encode(code) { if (code < 0xFFFF) return [code]; code -= 0x10000; - return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; + return [UTF16_BITES$2[0] | code >> 10 & UTF16_MASK$2, UTF16_BITES$2[1] | code & UTF16_MASK$2]; } function UTF8Decode(codeSet) { @@ -3675,17 +3796,17 @@ return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); } - function UTF16Decode$1(codeSet) { + function UTF16Decode$2(codeSet) { var _codeSet2; if (typeof codeSet === "number") codeSet = [codeSet]; if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); var codeSetRange = codeSet.length; if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + return ((codeSet[0] & UTF16_MASK$2) << 10) + (codeSet[1] & UTF16_MASK$2) + 0x10000; } - function stringToUnicode$1(str) { + function stringToUnicode$2(str) { var utf16Map = __arrayMaker({ length: str.length }, function (_, i) { @@ -3698,11 +3819,11 @@ while (index < str.length) { var code = utf16Map[index]; - if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + if ((UTF16_BITES$2[0] & code) !== UTF16_BITES$2[0]) { result.push(code); index++; } else { - result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + result.push(UTF16Decode$2(utf16Map.slice(index, index + 2))); index += 2; } } @@ -3766,7 +3887,7 @@ } function stringToUTF8(str) { - return UnicodeToUTF8(stringToUnicode$1(str)); + return UnicodeToUTF8(stringToUnicode$2(str)); } function UTF8ToString(utf8Array) { @@ -4262,28 +4383,6 @@ return BufferWriter; }(); - var XnbError = function (_Error) { - _inherits(XnbError, _Error); - - var _super = _createSuper(XnbError); - - function XnbError() { - var _this; - - var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - - _classCallCheck(this, XnbError); - - _this = _super.call(this, message); - _this.name = _this.constructor.name; - _this.message = message; - Error.captureStackTrace(_assertThisInitialized(_this), XnbError); - return _this; - } - - return _createClass(XnbError); - }(_wrapNativeSuper(Error)); - var MIN_MATCH = 2; var NUM_CHARS = 256; var BLOCKTYPE = { @@ -5060,6 +5159,77 @@ return compressBlock(src, dst, 0, src.length, hashTable); } + var UTF16_BITES$1 = [0xD800, 0xDC00]; + var UTF16_MASK$1 = 1023; + + function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + } + + function stringToUnicode$1(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length$1(str) { + var codes = stringToUnicode$1(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + var StringReaderCore = function () { + function StringReaderCore() { + _classCallCheck(this, StringReaderCore); + } + + _createClass(StringReaderCore, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string) { + var size = UTF8Length$1(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }]); + + return StringReaderCore; + }(); + var ReaderResolver = function () { function ReaderResolver(readers) { _classCallCheck(this, ReaderResolver); @@ -5091,7251 +5261,7615 @@ return ReaderResolver; }(); - var BaseReader = function () { - function BaseReader() { - _classCallCheck(this, BaseReader); + var XnbData = function () { + function XnbData(header, readers, content) { + _classCallCheck(this, XnbData); + + var target = header.target, + formatVersion = header.formatVersion, + hidef = header.hidef, + compressed = header.compressed; + this.header = { + target: target, + formatVersion: formatVersion, + hidef: hidef, + compressed: compressed + }; + this.readers = readers; + this.content = content; } - _createClass(BaseReader, [{ - key: "isValueType", - value: function isValueType() { - return true; + _createClass(XnbData, [{ + key: "target", + get: function get() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } } }, { - key: "type", + key: "formatVersion", get: function get() { - return this.constructor.name.slice(0, -6); + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } } }, { - key: "read", - value: function read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); + key: "hidef", + get: function get() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); } }, { - key: "write", - value: function write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); + key: "compressed", + get: function get() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); } }, { - key: "writeIndex", - value: function writeIndex(buffer, resolver) { - if (resolver != null) buffer.write7BitNumber(parseInt(resolver.getIndex(this)) + 1); + key: "contentType", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.type; + return "JSON"; + } + }, { + key: "rawContent", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, function (key, value) { + if (key === "export") return value.type; + return value; + }, 4); + } + }, { + key: "stringify", + value: function stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); } }, { key: "toString", value: function toString() { - return this.type; + return this.stringify(); } }]); - return BaseReader; + return XnbData; }(); - var UTF16_BITES = [0xD800, 0xDC00]; - var UTF16_MASK = 1023; - - function UTF16Decode(codeSet) { - var _codeSet2; + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; - if (typeof codeSet === "number") codeSet = [codeSet]; - if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); - var codeSetRange = codeSet.length; - if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; - } + case "yaml": + return "yaml"; - function stringToUnicode(str) { - var utf16Map = __arrayMaker({ - length: str.length - }, function (_, i) { - return str.charCodeAt(i); - }); + case "png": + return "Texture2D"; - var result = []; - var index = 0; + case "cso": + return "Effect"; - while (index < str.length) { - var code = utf16Map[index]; + case 'tbin': + return "TBin"; - if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { - result.push(code); - index++; - } else { - result.push(UTF16Decode(utf16Map.slice(index, index + 2))); - index += 2; - } + case 'xml': + return "BmFont"; } - return result; + return "Others"; } - function UTF8Length(str) { - var codes = stringToUnicode(str); - return codes.reduce(function (sum, unicode) { - if (unicode < 0x80) return sum + 1; - if (unicode < 0x800) return sum + 2; - if (unicode < 0x10000) return sum + 3; - return sum + 4; - }, 0); - } + var XnbContent = _createClass(function XnbContent(data, ext) { + _classCallCheck(this, XnbContent); - var StringReader = function (_BaseReader) { - _inherits(StringReader, _BaseReader); + this.type = extensionToDatatype(ext); + this.content = data; + }); - var _super = _createSuper(StringReader); + var HIDEF_MASK = 0x1; + var COMPRESSED_LZ4_MASK = 0x40; + var COMPRESSED_LZX_MASK = 0x80; + var XNB_COMPRESSED_PROLOGUE_SIZE = 14; - function StringReader() { - _classCallCheck(this, StringReader); + var XnbConverter = function () { + function XnbConverter() { + _classCallCheck(this, XnbConverter); - return _super.apply(this, arguments); + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; } - _createClass(StringReader, [{ - key: "read", - value: function read(buffer) { - var length = buffer.read7BitNumber(); - return buffer.readString(length); - } - }, { - key: "write", - value: function write(buffer, string, resolver) { - this.writeIndex(buffer, resolver); - var size = UTF8Length(string); - buffer.write7BitNumber(size); - buffer.writeString(string); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }]); + _createClass(XnbConverter, [{ + key: "load", + value: function load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); - return StringReader; - }(BaseReader); + this._validateHeader(); - var UInt32Reader = function (_BaseReader) { - _inherits(UInt32Reader, _BaseReader); + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); - var _super = _createSuper(UInt32Reader); + if (this.compressed) { + var decompressedSize = this.buffer.readUInt32(); - function UInt32Reader() { - _classCallCheck(this, UInt32Reader); + if (this.compressionType == COMPRESSED_LZX_MASK) { + var compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + var decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + var trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); - return _super.apply(this, arguments); - } + var _decompressed = new Uint8Array(decompressedSize); - _createClass(UInt32Reader, [{ - key: "read", - value: function read(buffer) { - return buffer.readUInt32(); - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); - } - }]); + decompressBlock$1(trimmedArray, _decompressed); + this.buffer.copyFrom(_decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } - return UInt32Reader; - }(BaseReader); + var count = this.buffer.read7BitNumber(); + var stringReader = new StringReaderCore(); + var readers = []; - var ArrayReader = function (_BaseReader) { - _inherits(ArrayReader, _BaseReader); - - var _super = _createSuper(ArrayReader); - - function ArrayReader(reader) { - var _this; - - _classCallCheck(this, ArrayReader); - - _this = _super.call(this); - _this.reader = reader; - return _this; - } - - _createClass(ArrayReader, [{ - key: "read", - value: function read(buffer, resolver) { - var uint32Reader = new UInt32Reader(); - var size = uint32Reader.read(buffer); - var array = []; - - for (var i = 0; i < size; i++) { - var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - array.push(value); + for (var i = 0; i < count; i++) { + var type = stringReader.read(this.buffer); + var version = this.buffer.readInt32(); + var reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type: type, + version: version + }); } - return array; + var shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + var content = new ReaderResolver(this.readers); + var result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); } }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, resolver); + key: "convert", + value: function convert(json) { + var buffer = new BufferWriter(); + var stringReader = new StringReaderCore(); + var _json$header = json.header, + target = _json$header.target, + formatVersion = _json$header.formatVersion, + hidef = _json$header.hidef, + compressed = _json$header.compressed; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + var lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); - for (var i = 0; i < content.length; i++) { - this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + for (var _i2 = 0, _json$readers2 = json.readers; _i2 < _json$readers2.length; _i2++) { + var reader = _json$readers2[_i2]; + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); } - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }, { - key: "type", - get: function get() { - return "Array<".concat(this.reader.type, ">"); - } - }]); - - return ArrayReader; - }(BaseReader); - var BmFontReader = function (_BaseReader) { - _inherits(BmFontReader, _BaseReader); + buffer.write7BitNumber(0); + var content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); - var _super = _createSuper(BmFontReader); + if (lz4Compression) { + var trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); + var compressedSize = compressBound(trimmedArray.length); - function BmFontReader() { - _classCallCheck(this, BmFontReader); + var _compressed = new Uint8Array(compressedSize); - return _super.apply(this, arguments); - } + compressedSize = compressSingleBlock(trimmedArray, _compressed); + _compressed = _compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(_compressed); + var returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } - _createClass(BmFontReader, [{ - key: "read", - value: function read(buffer) { - var stringReader = new StringReader(); - var xml = stringReader.read(buffer); - return { - export: { - type: this.type, - data: xml - } - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); + var fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; } }, { - key: "isValueType", - value: function isValueType() { - return false; + key: "_validateHeader", + value: function _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + var magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + var flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; } }]); - return BmFontReader; - }(BaseReader); - - var BooleanReader = function (_BaseReader) { - _inherits(BooleanReader, _BaseReader); + return XnbConverter; + }(); - var _super = _createSuper(BooleanReader); + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; - function BooleanReader() { - _classCallCheck(this, BooleanReader); + function e() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } - return _super.apply(this, arguments); - } + function i() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } - _createClass(BooleanReader, [{ - key: "read", - value: function read(buffer) { - return Boolean(buffer.readInt()); - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } - }]); + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + var i = 0; + var n = t.length; + var r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); - return BooleanReader; - }(BaseReader); + for (; i < n;) { + var _e2 = t.charCodeAt(i++); - var CharReader = function (_BaseReader) { - _inherits(CharReader, _BaseReader); + if (_e2 >= 55296 && _e2 <= 56319) { + if (i < n) { + var _n = t.charCodeAt(i); - var _super = _createSuper(CharReader); + 56320 == (64512 & _n) && (++i, _e2 = ((1023 & _e2) << 10) + (1023 & _n) + 65536); + } - function CharReader() { - _classCallCheck(this, CharReader); + if (_e2 >= 55296 && _e2 <= 56319) continue; + } - return _super.apply(this, arguments); - } + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; - _createClass(CharReader, [{ - key: "read", - value: function read(buffer) { - var charSize = this._getCharSize(buffer.peekInt()); + var _e3 = new Uint8Array(s); - return buffer.readString(charSize); - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } - }, { - key: "_getCharSize", - value: function _getCharSize(byte) { - return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; - } - }]); + _e3.set(a), a = _e3; + } - return CharReader; - }(BaseReader); + if (0 != (4294967168 & _e2)) { + if (0 == (4294965248 & _e2)) a[r++] = _e2 >> 6 & 31 | 192;else if (0 == (4294901760 & _e2)) a[r++] = _e2 >> 12 & 15 | 224, a[r++] = _e2 >> 6 & 63 | 128;else { + if (0 != (4292870144 & _e2)) continue; + a[r++] = _e2 >> 18 & 7 | 240, a[r++] = _e2 >> 12 & 63 | 128, a[r++] = _e2 >> 6 & 63 | 128; + } + a[r++] = 63 & _e2 | 128; + } else a[r++] = _e2; + } - var DictionaryReader = function (_BaseReader) { - _inherits(DictionaryReader, _BaseReader); + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + var i = new Uint8Array(t); + var n = 0; + var r = i.length, + s = []; - var _super = _createSuper(DictionaryReader); + for (; n < r;) { + var _t2 = i[n++]; + if (0 === _t2) break; + if (0 == (128 & _t2)) s.push(_t2);else if (192 == (224 & _t2)) { + var _e4 = 63 & i[n++]; - function DictionaryReader(key, value) { - var _this; + s.push((31 & _t2) << 6 | _e4); + } else if (224 == (240 & _t2)) { + var _e5 = 63 & i[n++], + _r = 63 & i[n++]; - _classCallCheck(this, DictionaryReader); + s.push((31 & _t2) << 12 | _e5 << 6 | _r); + } else if (240 == (248 & _t2)) { + var _e6 = (7 & _t2) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; - if (key == undefined || value == undefined) throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - _this = _super.call(this); - _this.key = key; - _this.value = value; - return _this; - } + _e6 > 65535 && (_e6 -= 65536, s.push(_e6 >>> 10 & 1023 | 55296), _e6 = 56320 | 1023 & _e6), s.push(_e6); + } + } - _createClass(DictionaryReader, [{ - key: "read", - value: function read(buffer, resolver) { - var dictionary = {}; - var uint32Reader = new UInt32Reader(); - var size = uint32Reader.read(buffer); + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } + }, + e = {}; - for (var i = 0; i < size; i++) { - var key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - var value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - dictionary[key] = value; - } + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; + } - return dictionary; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(Object.keys(content).length); + i.d = function (t, e) { + for (var n in e) { + i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + } + }, i.o = function (t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; + var n = {}; - for (var _i2 = 0, _Object$keys2 = Object.keys(content); _i2 < _Object$keys2.length; _i2++) { - var key = _Object$keys2[_i2]; - this.key.write(buffer, key, this.key.isValueType() ? null : resolver); - this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); - } - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }, { - key: "type", - get: function get() { - return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + (function () { + i.d(n, { + P: function P() { + return Mi; + }, + m: function m() { + return Fi; } - }]); + }), i(396); + var t = new TextDecoder("utf-8"), + e = new TextEncoder(); - return DictionaryReader; - }(BaseReader); + var r = function () { + function r() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var DoubleReader = function (_BaseReader) { - _inherits(DoubleReader, _BaseReader); + _classCallCheck(this, r); - var _super = _createSuper(DoubleReader); + var i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + var n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + var a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } - function DoubleReader() { - _classCallCheck(this, DoubleReader); + _createClass(r, [{ + key: "available", + value: function available() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + }, { + key: "isLittleEndian", + value: function isLittleEndian() { + return this.littleEndian; + } + }, { + key: "setLittleEndian", + value: function setLittleEndian() { + return this.littleEndian = !0, this; + } + }, { + key: "isBigEndian", + value: function isBigEndian() { + return !this.littleEndian; + } + }, { + key: "setBigEndian", + value: function setBigEndian() { + return this.littleEndian = !1, this; + } + }, { + key: "skip", + value: function skip() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + }, { + key: "seek", + value: function seek(t) { + return this.offset = t, this; + } + }, { + key: "mark", + value: function mark() { + return this._mark = this.offset, this; + } + }, { + key: "reset", + value: function reset() { + return this.offset = this._mark, this; + } + }, { + key: "pushMark", + value: function pushMark() { + return this._marks.push(this.offset), this; + } + }, { + key: "popMark", + value: function popMark() { + var t = this._marks.pop(); - return _super.apply(this, arguments); - } + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + }, { + key: "rewind", + value: function rewind() { + return this.offset = 0, this; + } + }, { + key: "ensureAvailable", + value: function ensureAvailable() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - _createClass(DoubleReader, [{ - key: "read", - value: function read(buffer) { - return buffer.readDouble(); - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } - }]); + if (!this.available(t)) { + var _e7 = 2 * (this.offset + t), + _i2 = new Uint8Array(_e7); - return DoubleReader; - }(BaseReader); + _i2.set(new Uint8Array(this.buffer)), this.buffer = _i2.buffer, this.length = this.byteLength = _e7, this._data = new DataView(this.buffer); + } - var EffectReader = function (_BaseReader) { - _inherits(EffectReader, _BaseReader); + return this; + } + }, { + key: "readBoolean", + value: function readBoolean() { + return 0 !== this.readUint8(); + } + }, { + key: "readInt8", + value: function readInt8() { + return this._data.getInt8(this.offset++); + } + }, { + key: "readUint8", + value: function readUint8() { + return this._data.getUint8(this.offset++); + } + }, { + key: "readByte", + value: function readByte() { + return this.readUint8(); + } + }, { + key: "readBytes", + value: function readBytes() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = new Uint8Array(t); - var _super = _createSuper(EffectReader); + for (var _i3 = 0; _i3 < t; _i3++) { + e[_i3] = this.readByte(); + } - function EffectReader() { - _classCallCheck(this, EffectReader); + return e; + } + }, { + key: "readInt16", + value: function readInt16() { + var t = this._data.getInt16(this.offset, this.littleEndian); - return _super.apply(this, arguments); - } - - _createClass(EffectReader, [{ - key: "read", - value: function read(buffer) { - var uint32Reader = new UInt32Reader(); - var size = uint32Reader.read(buffer); - var bytecode = buffer.read(size); - return { - export: { - type: this.type, - data: bytecode - } - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var data = content.export.data; - var uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }]); + return this.offset += 2, t; + } + }, { + key: "readUint16", + value: function readUint16() { + var t = this._data.getUint16(this.offset, this.littleEndian); - return EffectReader; - }(BaseReader); + return this.offset += 2, t; + } + }, { + key: "readInt32", + value: function readInt32() { + var t = this._data.getInt32(this.offset, this.littleEndian); - var Int32Reader = function (_BaseReader) { - _inherits(Int32Reader, _BaseReader); + return this.offset += 4, t; + } + }, { + key: "readUint32", + value: function readUint32() { + var t = this._data.getUint32(this.offset, this.littleEndian); - var _super = _createSuper(Int32Reader); + return this.offset += 4, t; + } + }, { + key: "readFloat32", + value: function readFloat32() { + var t = this._data.getFloat32(this.offset, this.littleEndian); - function Int32Reader() { - _classCallCheck(this, Int32Reader); + return this.offset += 4, t; + } + }, { + key: "readFloat64", + value: function readFloat64() { + var t = this._data.getFloat64(this.offset, this.littleEndian); - return _super.apply(this, arguments); - } + return this.offset += 8, t; + } + }, { + key: "readBigInt64", + value: function readBigInt64() { + var t = this._data.getBigInt64(this.offset, this.littleEndian); - _createClass(Int32Reader, [{ - key: "read", - value: function read(buffer) { - return buffer.readInt32(); - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); - } - }]); + return this.offset += 8, t; + } + }, { + key: "readBigUint64", + value: function readBigUint64() { + var t = this._data.getBigUint64(this.offset, this.littleEndian); - return Int32Reader; - }(BaseReader); + return this.offset += 8, t; + } + }, { + key: "readChar", + value: function readChar() { + return String.fromCharCode(this.readInt8()); + } + }, { + key: "readChars", + value: function readChars() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = ""; - var ListReader = function (_BaseReader) { - _inherits(ListReader, _BaseReader); + for (var _i4 = 0; _i4 < t; _i4++) { + e += this.readChar(); + } - var _super = _createSuper(ListReader); + return e; + } + }, { + key: "readUtf8", + value: function readUtf8() { + var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + }, { + key: "writeBoolean", + value: function writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + }, { + key: "writeInt8", + value: function writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint8", + value: function writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeByte", + value: function writeByte(t) { + return this.writeUint8(t); + } + }, { + key: "writeBytes", + value: function writeBytes(t) { + this.ensureAvailable(t.length); - function ListReader(reader) { - var _this; + for (var _e8 = 0; _e8 < t.length; _e8++) { + this._data.setUint8(this.offset++, t[_e8]); + } - _classCallCheck(this, ListReader); + return this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt16", + value: function writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint16", + value: function writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt32", + value: function writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint32", + value: function writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat32", + value: function writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat64", + value: function writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigInt64", + value: function writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigUint64", + value: function writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeChar", + value: function writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + }, { + key: "writeChars", + value: function writeChars(t) { + for (var _e9 = 0; _e9 < t.length; _e9++) { + this.writeUint8(t.charCodeAt(_e9)); + } - _this = _super.call(this); - _this.reader = reader; - return _this; - } + return this; + } + }, { + key: "writeUtf8", + value: function writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + }, { + key: "toArray", + value: function toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + }, { + key: "_updateLastWrittenByte", + value: function _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + }]); - _createClass(ListReader, [{ - key: "read", - value: function read(buffer, resolver) { - var uint32Reader = new UInt32Reader(); - var size = uint32Reader.read(buffer); - var list = []; + return r; + }(); - for (var i = 0; i < size; i++) { - var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } + function s(t) { + var e = t.length; - return list; + for (; --e >= 0;) { + t[e] = 0; } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); - - var __keys = Object.keys(content); + } - for (var __i = 0; __i < __keys.length; __i++) { - var __key = __keys[__i], - data = content[__key]; - this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); - } - } - }, { - key: "type", - get: function get() { - return "List<".concat(this.reader.type, ">"); - } - }]); - - return ListReader; - }(BaseReader); + var a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); - var NullableReader = function (_BaseReader) { - _inherits(NullableReader, _BaseReader); + var _ = new Array(60); - var _super = _createSuper(NullableReader); + s(_); + var f = new Array(512); + s(f); + var c = new Array(256); + s(c); + var u = new Array(29); + s(u); + var w = new Array(30); - function NullableReader(reader) { - var _this; + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } - _classCallCheck(this, NullableReader); + var g, b, m; - _this = _super.call(this); - _this.reader = reader; - return _this; + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; } - _createClass(NullableReader, [{ - key: "read", - value: function read(buffer, resolver) { - var booleanReader = new BooleanReader(); - var hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - new BooleanReader(); - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }, { - key: "type", - get: function get() { - return "Nullable<".concat(this.reader.type, ">"); - } - }]); + s(w); - return NullableReader; - }(BaseReader); + var y = function y(t) { + return t < 256 ? f[t] : f[256 + (t >>> 7)]; + }, + v = function v(t, e) { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = function E(t, e, i) { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = function A(t, e, i) { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = function x(t, e) { + var i = 0; - var RectangleReader = function (_BaseReader) { - _inherits(RectangleReader, _BaseReader); + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); - var _super = _createSuper(RectangleReader); + return i >>> 1; + }, + U = function U(t, e, i) { + var n = new Array(16); + var r, + s, + a = 0; - function RectangleReader() { - _classCallCheck(this, RectangleReader); + for (r = 1; r <= 15; r++) { + n[r] = a = a + i[r - 1] << 1; + } - return _super.apply(this, arguments); - } + for (s = 0; s <= e; s++) { + var _e10 = t[2 * s + 1]; + 0 !== _e10 && (t[2 * s] = x(n[_e10]++, _e10)); + } + }, + z = function z(t) { + var e; - _createClass(RectangleReader, [{ - key: "read", - value: function read(buffer) { - var int32Reader = new Int32Reader(); - var x = int32Reader.read(buffer); - var y = int32Reader.read(buffer); - var width = int32Reader.read(buffer); - var height = int32Reader.read(buffer); - return { - x: x, - y: y, - width: width, - height: height - }; + for (e = 0; e < 286; e++) { + t.dyn_ltree[2 * e] = 0; } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); + + for (e = 0; e < 30; e++) { + t.dyn_dtree[2 * e] = 0; } - }]); - return RectangleReader; - }(BaseReader); + for (e = 0; e < 19; e++) { + t.bl_tree[2 * e] = 0; + } - var SingleReader = function (_BaseReader) { - _inherits(SingleReader, _BaseReader); + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = function R(t) { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = function N(t, e, i, n) { + var r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = function T(t, e, i) { + var n = t.heap[i]; + var r = i << 1; - var _super = _createSuper(SingleReader); + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) { + t.heap[i] = t.heap[r], i = r, r <<= 1; + } - function SingleReader() { - _classCallCheck(this, SingleReader); + t.heap[i] = n; + }, + O = function O(t, e, i) { + var n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = function L(t, e) { + var i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + var a, + o, + h, + l = -1; - return _super.apply(this, arguments); - } + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) { + 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + } - _createClass(SingleReader, [{ - key: "read", - value: function read(buffer) { - return buffer.readSingle(); + for (; t.heap_len < 2;) { + h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) { + T(t, i, a); } - }]); - return SingleReader; - }(BaseReader); + h = s; - var kDxt1 = 1 << 0; - var kDxt3 = 1 << 1; - var kDxt5 = 1 << 2; - var kColourIterativeClusterFit = 1 << 8; - var kColourClusterFit = 1 << 3; - var kColourRangeFit = 1 << 4; - var kColourMetricPerceptual = 1 << 5; - var kColourMetricUniform = 1 << 6; - var kWeightColourByAlpha = 1 << 7; + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); - function Rot(theta) { - var Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; - return Mat; - } + t.heap[--t.heap_max] = t.heap[1], function (t, e) { + var i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; - function Rij(k, l, theta, N) { - var Mat = Array(N); + var l, + d, + _, + f, + c, + u, + w = 0; - for (var i = 0; i < N; i++) { - Mat[i] = Array(N); - } + for (f = 0; f <= 15; f++) { + t.bl_count[f] = 0; + } - for (var _i = 0; _i < N; _i++) { - for (var j = 0; j < N; j++) { - Mat[_i][j] = (_i === j) * 1.0; - } - } + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) { + d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + } - var Rotij = Rot(theta); - Mat[k][k] = Rotij[0][0]; - Mat[l][l] = Rotij[1][1]; - Mat[k][l] = Rotij[0][1]; - Mat[l][k] = Rotij[1][0]; - return Mat; - } - - function getTheta(aii, ajj, aij) { - var th = 0.0; - var denom = ajj - aii; + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) { + f--; + } - if (Math.abs(denom) <= 1E-12) { - th = Math.PI / 4.0; - } else { - th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); - } + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); - return th; - } + for (f = h; 0 !== f; f--) { + for (d = t.bl_count[f]; 0 !== d;) { + _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + } + } + }(t, e), U(i, l, t.bl_count); + }, + B = function B(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - function getAij(Mij) { - var N = Mij.length; - var maxMij = 0.0; - var maxIJ = [0, 1]; + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) { + r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + } + }, + C = function C(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - for (var i = 0; i < N; i++) { - for (var j = i + 1; j < N; j++) { - if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { - maxMij = Math.abs(Mij[i][j]); - maxIJ = [i, j]; + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) { + if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); } } - } + }; - return [maxIJ, maxMij]; - } + var D = !1; - function unitary(U, H) { - var N = U.length; - var Mat = Array(N); + var I = function I(t, e, i, n) { + E(t, 0 + (n ? 1 : 0), 3), function (t, e, i, n) { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + }(t, e, i); + }; - for (var i = 0; i < N; i++) { - Mat[i] = Array(N); - } + var S = { + _tr_init: function _tr_init(t) { + D || (function () { + var t, e, i, n, r; + var s = new Array(16); - for (var _i2 = 0; _i2 < N; _i2++) { - for (var j = 0; j < N; j++) { - Mat[_i2][j] = 0; + for (i = 0, n = 0; n < 28; n++) { + for (u[n] = i, t = 0; t < 1 << a[n]; t++) { + c[i++] = n; + } + } - for (var k = 0; k < N; k++) { - for (var l = 0; l < N; l++) { - Mat[_i2][j] = Mat[_i2][j] + U[k][_i2] * H[k][l] * U[l][j]; + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) { + for (w[n] = r, t = 0; t < 1 << o[n]; t++) { + f[r++] = n; + } } - } - } - } - return Mat; - } + for (r >>= 7; n < 30; n++) { + for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) { + f[256 + r++] = n; + } + } - function AxB(A, B) { - var N = A.length; - var Mat = Array(N); + for (e = 0; e <= 15; e++) { + s[e] = 0; + } - for (var i = 0; i < N; i++) { - Mat[i] = Array(N); - } + for (t = 0; t <= 143;) { + d[2 * t + 1] = 8, t++, s[8]++; + } - for (var _i3 = 0; _i3 < N; _i3++) { - for (var j = 0; j < N; j++) { - Mat[_i3][j] = 0; + for (; t <= 255;) { + d[2 * t + 1] = 9, t++, s[9]++; + } - for (var k = 0; k < N; k++) { - Mat[_i3][j] = Mat[_i3][j] + A[_i3][k] * B[k][j]; - } - } - } + for (; t <= 279;) { + d[2 * t + 1] = 7, t++, s[7]++; + } - return Mat; - } + for (; t <= 287;) { + d[2 * t + 1] = 8, t++, s[8]++; + } - function eigens(Hij) { - var convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; - var N = Hij.length; - var Ei = Array(N); - var e0 = Math.abs(convergence / N); - var Sij = Array(N); + for (U(d, 287, s), t = 0; t < 30; t++) { + _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + } - for (var i = 0; i < N; i++) { - Sij[i] = Array(N); - } + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + }(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: function _tr_flush_block(t, e, i, n) { + var r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = function (t) { + var e, + i = 4093624447; - for (var _i4 = 0; _i4 < N; _i4++) { - for (var j = 0; j < N; j++) { - Sij[_i4][j] = (_i4 === j) * 1.0; - } - } + for (e = 0; e <= 31; e++, i >>>= 1) { + if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + } - var Vab = getAij(Hij); + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; - while (Math.abs(Vab[1]) >= Math.abs(e0)) { - var _i5 = Vab[0][0]; - var _j = Vab[0][1]; - var psi = getTheta(Hij[_i5][_i5], Hij[_j][_j], Hij[_i5][_j]); - var Gij = Rij(_i5, _j, psi, N); - Hij = unitary(Gij, Hij); - Sij = AxB(Sij, Gij); - Vab = getAij(Hij); - } + for (e = 32; e < 256; e++) { + if (0 !== t.dyn_ltree[2 * e]) return 1; + } - for (var _i6 = 0; _i6 < N; _i6++) { - Ei[_i6] = Hij[_i6][_i6]; - } + return 0; + }(t)), L(t, t.l_desc), L(t, t.d_desc), a = function (t) { + var e; - return sorting(Ei, Sij); - } + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--) { + } - function sorting(values, vectors) { - var eigsCount = values.length; - vectors.length; + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + }(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), function (t, e, i, n) { + var r; - var pairs = __arrayMaker({ - length: eigsCount - }, function (_, i) { - var vector = vectors.map(function (v) { - return v[i]; - }); - return { - value: values[i], - vec: vector - }; - }); + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) { + E(t, t.bl_tree[2 * l[r] + 1], 3); + } - pairs.sort(function (a, b) { - return b.value - a.value; - }); - var sortedValues = pairs.map(function (_ref) { - var value = _ref.value; - return value; - }); - var sortedVectors = pairs.map(function (_ref2) { - var vec = _ref2.vec; - return vec; - }); - return [sortedValues, sortedVectors]; - } + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + }(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: function _tr_tally(t, e, i) { + return t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1; + }, + _tr_align: function _tr_align(t) { + E(t, 2, 3), A(t, 256, d), function (t) { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + }(t); + } + }, + Z = function Z(t, e, i, n) { + var r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; - function dominentPrincipalVector(matrix) { - var _eigens = eigens(matrix), - _eigens$ = _eigens[1], - dominentVector = _eigens$[0]; + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; - return dominentVector; - } + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); - var Vec3 = function () { - function Vec3() { - var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + r %= 65521, s %= 65521; + } - _classCallCheck(this, Vec3); + return r | s << 16 | 0; + }; - this._values = [x, y, z]; - } + var F = new Uint32Array(function () { + var t, + e = []; - _createClass(Vec3, [{ - key: "x", - get: function get() { - return this._values[0]; - }, - set: function set(value) { - this._values[0] = value; - } - }, { - key: "y", - get: function get() { - return this._values[1]; - }, - set: function set(value) { - this._values[1] = value; - } - }, { - key: "z", - get: function get() { - return this._values[2]; - }, - set: function set(value) { - this._values[2] = value; - } - }, { - key: "length", - get: function get() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } - }, { - key: "lengthSq", - get: function get() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - }, { - key: "normalized", - get: function get() { - if (this.length === 0) return null; - return Vec3.multScalar(this, 1 / this.length); - } - }, { - key: "colorInt", - get: function get() { - var floatToInt = function floatToInt(value) { - var result = parseInt(value * 255 + 0.5); - return Math.max(Math.min(result, 255), 0); - }; + for (var i = 0; i < 256; i++) { + t = i; - return this._values.map(floatToInt); - } - }, { - key: "clone", - value: function clone() { - return new Vec3(this.x, this.y, this.z); - } - }, { - key: "set", - value: function set(x) { - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - return this; - } - }, { - key: "toVec4", - value: function toVec4() { - var w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return new Vec4(this.x, this.y, this.z, w); - } - }, { - key: "addVector", - value: function addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - return this; - } - }, { - key: "addScaledVector", - value: function addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - return this; - } - }, { - key: "mult", - value: function mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - return this; - } - }, { - key: "multVector", - value: function multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - return this; - } - }, { - key: "clamp", - value: function clamp(min, max) { - var clamper = function clamper(v) { - return min > v ? min : max < v ? max : v; - }; + for (var n = 0; n < 8; n++) { + t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + } - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - return this; + e[i] = t; } - }, { - key: "clampGrid", - value: function clampGrid() { - var clamper = function clamper(v) { - return 0 > v ? 0 : 1 < v ? 1 : v; - }; - var gridClamper = function gridClamper(value, grid) { - return __trunc(clamper(value) * grid + 0.5) / grid; - }; + return e; + }()); - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - return this; - } - }, { - key: "normalize", - value: function normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - return this; - } - }, { - key: "toString", - value: function toString() { - return "Vec3( ".concat(this._values.join(", "), " )"); - } - }], [{ - key: "add", - value: function add(a, b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } - }, { - key: "sub", - value: function sub(a, b) { - return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); - } - }, { - key: "dot", - value: function dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - }, { - key: "multScalar", - value: function multScalar(a, scalar) { - return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); - } - }, { - key: "multVector", - value: function multVector(a, b) { - return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); - } - }, { - key: "interpolate", - value: function interpolate(a, b, p) { - var a_ = Vec3.multScalar(a, 1 - p); - var b_ = Vec3.multScalar(b, p); - return Vec3.add(a_, b_); + var M = function M(t, e, i, n) { + var r = F, + s = n + i; + t ^= -1; + + for (var _i5 = n; _i5 < s; _i5++) { + t = t >>> 8 ^ r[255 & (t ^ e[_i5])]; } - }]); - return Vec3; - }(); + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; - var Vec4 = function () { - function Vec4() { - var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - - _classCallCheck(this, Vec4); - - this._values = [x, y, z, w]; - } - - _createClass(Vec4, [{ - key: "x", - get: function get() { - return this._values[0]; - }, - set: function set(value) { - this._values[0] = value; - } - }, { - key: "y", - get: function get() { - return this._values[1]; - }, - set: function set(value) { - this._values[1] = value; - } - }, { - key: "z", - get: function get() { - return this._values[2]; - }, - set: function set(value) { - this._values[2] = value; - } - }, { - key: "w", - get: function get() { - return this._values[3]; - }, - set: function set(value) { - this._values[3] = value; - } - }, { - key: "length", - get: function get() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); - } - }, { - key: "lengthSq", - get: function get() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; - } - }, { - key: "normalized", - get: function get() { - if (this.length === 0) return null; - return Vec4.multScalar(this, 1 / this.length); - } - }, { - key: "xyz", - get: function get() { - return new Vec3(this.x, this.y, this.z); - } - }, { - key: "splatX", - get: function get() { - return new Vec4(this.x); - } - }, { - key: "splatY", - get: function get() { - return new Vec4(this.y); - } - }, { - key: "splatZ", - get: function get() { - return new Vec4(this.z); - } - }, { - key: "splatW", - get: function get() { - return new Vec4(this.w); - } - }, { - key: "clone", - value: function clone() { - return new Vec4(this.x, this.y, this.z, this.w); - } - }, { - key: "set", - value: function set(x) { - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - this._values[3] = w; - return this; - } - }, { - key: "toVec3", - value: function toVec3() { - return this.xyz; - } - }, { - key: "addVector", - value: function addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - return this; - } - }, { - key: "addScaledVector", - value: function addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - return this; - } - }, { - key: "subVector", - value: function subVector(v) { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - return this; - } - }, { - key: "mult", - value: function mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - return this; - } - }, { - key: "multVector", - value: function multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - return this; - } - }, { - key: "reciprocal", - value: function reciprocal() { - this._values[0] = 1 / this._values[0]; - this._values[1] = 1 / this._values[1]; - this._values[2] = 1 / this._values[2]; - this._values[3] = 1 / this._values[3]; - return this; - } - }, { - key: "clamp", - value: function clamp(min, max) { - var clamper = function clamper(v) { - return min > v ? min : max < v ? max : v; - }; - - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - return this; - } - }, { - key: "clampGrid", - value: function clampGrid() { - var clamper = function clamper(v) { - return 0 > v ? 0 : 1 < v ? 1 : v; - }; - - var gridClamper = function gridClamper(value, grid) { - return __trunc(clamper(value) * grid + 0.5) / grid; - }; - - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - return this; - } - }, { - key: "truncate", - value: function truncate() { - this._values[0] = __trunc(this._values[0]); - this._values[1] = __trunc(this._values[1]); - this._values[2] = __trunc(this._values[2]); - this._values[3] = __trunc(this._values[3]); - return this; - } - }, { - key: "normalize", - value: function normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - return this; - } - }, { - key: "toString", - value: function toString() { - return "Vec4( ".concat(this._values.join(", "), " )"); - } - }], [{ - key: "add", - value: function add(a, b) { - return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); - } - }, { - key: "sub", - value: function sub(a, b) { - return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); - } - }, { - key: "dot", - value: function dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; - } - }, { - key: "multScalar", - value: function multScalar(a, scalar) { - return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); - } - }, { - key: "multVector", - value: function multVector(a, b) { - return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); - } - }, { - key: "interpolate", - value: function interpolate(a, b, p) { - var a_ = Vec4.multScalar(a, 1 - p); - var b_ = Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } - }, { - key: "multiplyAdd", - value: function multiplyAdd(a, b, c) { - return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); - } - }, { - key: "negativeMultiplySubtract", - value: function negativeMultiplySubtract(a, b, c) { - return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); - } - }, { - key: "compareAnyLessThan", - value: function compareAnyLessThan(left, right) { - return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; - } - }]); - - return Vec4; - }(); - - function computeWeightedCovariance(values, weights) { - var total = 0; - var mean = values.reduce(function (sum, value, i) { - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1 / total); - var covariance = values.reduce(function (sum, value, i) { - var weight = weights[i]; - var v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; - sum[0][1] += v.x * v.y * weight; - sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; - sum[1][2] += v.y * v.z * weight; - sum[2][2] += v.z * v.z * weight; - return sum; - }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - return covariance; - } - - function computePCA(values, weights) { - var covariance = computeWeightedCovariance(values, weights); - return _construct(Vec3, dominentPrincipalVector(covariance)); - } - - var lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; - var lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - var lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; - var lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - - function floatToInt(value, limit) { - var integer = parseInt(value + 0.5); - if (integer < 0) return 0; - if (integer > limit) return integer; - return integer; - } - - function floatTo565(color) { - var r = floatToInt(31.0 * color.x, 31); - var g = floatToInt(63.0 * color.y, 63); - var b = floatToInt(31.0 * color.z, 31); - return r << 11 | g << 5 | b; - } - - function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { - result[blockOffset + 0] = firstColor & 0xff; - result[blockOffset + 1] = firstColor >> 8; - result[blockOffset + 2] = secondColor & 0xff; - result[blockOffset + 3] = secondColor >> 8; - - for (var y = 0; y < 4; y++) { - result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; - } - } - - function writeColourBlock3(start, end, indices, result, blockOffset) { - var firstColor = floatTo565(start); - var secondColor = floatTo565(end); - var remapped; - - if (firstColor <= secondColor) { - remapped = indices.slice(); - } else { - var _ref = [secondColor, firstColor]; - firstColor = _ref[0]; - secondColor = _ref[1]; - remapped = indices.map(function (index) { - return index === 0 ? 1 : index === 1 ? 0 : index; - }); - } - - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); - } - - function writeColourBlock4(start, end, indices, result, blockOffset) { - var firstColor = floatTo565(start); - var secondColor = floatTo565(end); - var remapped; - - if (firstColor < secondColor) { - var _ref2 = [secondColor, firstColor]; - firstColor = _ref2[0]; - secondColor = _ref2[1]; - remapped = indices.map(function (index) { - return (index ^ 0x1) & 0x3; - }); - } else if (firstColor == secondColor) { - remapped = new Array(16).fill(0); - } else { - remapped = indices.slice(); - } - - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); - } - - var ColorSet = function () { - function ColorSet(rgba, mask, flags) { - _classCallCheck(this, ColorSet); - - this.flags = flags; - this._count = 0; - this._transparent = false; - this._remap = []; - this._weights = []; - this._points = []; - var isDxt1 = (this.flags & kDxt1) != 0; - var weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - - for (var i = 0; i < 16; i++) { - var bit = 1 << i; - - if ((mask & bit) == 0) { - this._remap[i] = -1; - continue; - } - - if (isDxt1 && rgba[4 * i + 3] < 128) { - this._remap[i] = -1; - this._transparent = true; - continue; - } - - for (var j = 0;; j++) { - if (j == i) { - var r = rgba[4 * i] / 255.0; - var g = rgba[4 * i + 1] / 255.0; - var b = rgba[4 * i + 2] / 255.0; - var a = (rgba[4 * i + 3] + 1) / 256.0; - this._points[this._count] = new Vec3(r, g, b); - this._weights[this._count] = weightByAlpha ? a : 1.0; - this._remap[i] = this._count; - this._count++; - break; - } - - var oldbit = 1 << j; - var match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - - if (match) { - var index = this._remap[j]; - var w = (rgba[4 * i + 3] + 1) / 256.0; - this._weights[index] += weightByAlpha ? w : 1.0; - this._remap[i] = index; - break; - } - } - } - - for (var _i = 0; _i < this._count; ++_i) { - this._weights[_i] = Math.sqrt(this._weights[_i]); - } - } - - _createClass(ColorSet, [{ - key: "transparent", - get: function get() { - return this._transparent; - } - }, { - key: "count", - get: function get() { - return this._count; - } - }, { - key: "points", - get: function get() { - return Object.freeze(this._points.slice()); - } - }, { - key: "weights", - get: function get() { - return Object.freeze(this._weights.slice()); - } - }, { - key: "remapIndicesSingle", - value: function remapIndicesSingle(singleIndex, target) { - var result = this._remap.map(function (index) { - return index === -1 ? 3 : singleIndex; - }); - - target.forEach(function (_, i) { - return target[i] = result[i]; - }); - } - }, { - key: "remapIndices", - value: function remapIndices(indexMap, target) { - var result = this._remap.map(function (index) { - return index === -1 ? 3 : indexMap[index]; - }); + var W = S._tr_init, + K = S._tr_stored_block, + $ = S._tr_flush_block, + Y = S._tr_tally, + j = S._tr_align, + G = H.Z_NO_FLUSH, + X = H.Z_PARTIAL_FLUSH, + V = H.Z_FULL_FLUSH, + q = H.Z_FINISH, + J = H.Z_BLOCK, + Q = H.Z_OK, + tt = H.Z_STREAM_END, + et = H.Z_STREAM_ERROR, + it = H.Z_DATA_ERROR, + nt = H.Z_BUF_ERROR, + rt = H.Z_DEFAULT_COMPRESSION, + st = H.Z_FILTERED, + at = H.Z_HUFFMAN_ONLY, + ot = H.Z_RLE, + ht = H.Z_FIXED, + dt = H.Z_UNKNOWN, + _t = H.Z_DEFLATED, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = function gt(t, e) { + return t.msg = P[e], e; + }, + bt = function bt(t) { + return (t << 1) - (t > 4 ? 9 : 0); + }, + mt = function mt(t) { + var e = t.length; - target.forEach(function (_, i) { - return target[i] = result[i]; - }); + for (; --e >= 0;) { + t[e] = 0; } - }]); + }; - return ColorSet; - }(); + var kt = function kt(t, e, i) { + return (e << t.hash_shift ^ i) & t.hash_mask; + }; - var ColorFit = function () { - function ColorFit(colorSet) { - _classCallCheck(this, ColorFit); + var yt = function yt(t) { + var e = t.state; + var i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = function vt(t, e) { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = function Et(t, e) { + t.pending_buf[t.pending++] = e; + }, + At = function At(t, e) { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = function xt(t, e, i, n) { + var r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = function Ut(t, e) { + var i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + var h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + var c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); - this.colors = colorSet; - this.flags = colorSet.flags; - } + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; - _createClass(ColorFit, [{ - key: "compress", - value: function compress(result, offset) { - var isDxt1 = (this.flags & kDxt1) != 0; + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); - if (isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } else this.compress4(result, offset); - } - }, { - key: "compress3", - value: function compress3(result, offset) {} - }, { - key: "compress4", - value: function compress4(result, offset) {} - }]); + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); - return ColorFit; - }(); + return a <= t.lookahead ? a : t.lookahead; + }, + zt = function zt(t) { + var e = t.w_size; + var i, n, r, s, a; - var SingleColourFit = function (_ColorFit) { - _inherits(SingleColourFit, _ColorFit); + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; - var _super = _createSuper(SingleColourFit); + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); - function SingleColourFit(colorSet) { - var _this; + n = e, i = n; - _classCallCheck(this, SingleColourFit); + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); - _this = _super.call(this, colorSet); - var singleColor = colorSet.points[0]; - _this.color = singleColor.colorInt; - _this.start = new Vec3(0); - _this.end = new Vec3(0); - _this.index = 0; - _this.error = Infinity; - _this.bestError = Infinity; - return _this; - } + s += e; + } - _createClass(SingleColourFit, [{ - key: "compressBase", - value: function compressBase(lookups, saveFunc) { - this.computeEndPoints(lookups); + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));) { + } + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = function Rt(t, e) { + var i, n; - if (this.error < this.bestError) { - var indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - this.bestError = this.error; + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; } - } - }, { - key: "compress3", - value: function compress3(result, offset) { - var lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock3(start, end, indices, result, offset); - }; + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; - this.compressBase(lookups, saveFunc); + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - }, { - key: "compress4", - value: function compress4(result, offset) { - var lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock4(start, end, indices, result, offset); - }; + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = function Nt(t, e) { + var i, n, r; - this.compressBase(lookups, saveFunc); + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; } - }, { - key: "computeEndPoints", - value: function computeEndPoints(lookups) { - this.error = Infinity; - for (var index = 0; index < 2; index++) { - var sources = []; - var error = 0; + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; - for (var channel = 0; channel < 3; channel++) { - var lookup = lookups[channel]; - var target = this.color[channel]; - sources[channel] = lookup[target][index]; - var diff = sources[channel][2]; - error += diff * diff; - } + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } - if (error < this.error) { - this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); - this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); - this.index = 2 * index; - this.error = error; - } + var Ot = [new Tt(0, 0, 0, 0, function (t, e) { + var i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; } - } - }]); - return SingleColourFit; - }(ColorFit); + t.strstart += t.lookahead, t.lookahead = 0; - var RangeFit = function (_ColorFit2) { - _inherits(RangeFit, _ColorFit2); + var _n2 = t.block_start + i; - var _super2 = _createSuper(RangeFit); + if ((0 === t.strstart || t.strstart >= _n2) && (t.lookahead = t.strstart - _n2, t.strstart = _n2, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - function RangeFit(colorSet) { - var _this2; + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; - _classCallCheck(this, RangeFit); + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + var Bt = function Bt(t) { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + var e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = function Ct(t) { + var e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = function Dt(t, e, i, n, r, s) { + if (!t) return et; + var a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + var o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; - _this2 = _super2.call(this, colorSet); - _this2.metric = new Vec3(1); + var It = Dt, + St = function St(t, e) { + return t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et; + }, + Zt = function Zt(t, e) { + var i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + var r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + var s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + var _e11 = _t + (r.w_bits - 8 << 4) << 8, + _i6 = -1; - if ((_this2.flags & kColourMetricPerceptual) !== 0) { - _this2.metric.set(0.2126, 0.7152, 0.0722); + _i6 = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, _e11 |= _i6 << 6, 0 !== r.strstart && (_e11 |= 32), _e11 += 31 - _e11 % 31, r.status = wt, At(r, _e11), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) { + Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + } - _this2.start = new Vec3(0); - _this2.end = new Vec3(0); - _this2.bestError = Infinity; + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; - _this2.computePoints(); + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - return _this2; - } + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - _createClass(RangeFit, [{ - key: "compressBase", - value: function compressBase(codes, saveFunc) { - var _this3 = this; + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; - var values = this.colors.points; - var error = 0; - var closest = values.map(function (color) { - var minDist = Infinity; - var packedIndex = codes.reduce(function (idx, code, j) { - var dist = Vec3.sub(color, code).multVector(_this3.metric).lengthSq; - if (dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - error += minDist; - return packedIndex; - }); + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - if (error < this.bestError) { - var indices = new Uint8Array(16); - this.colors.remapIndices(closest, indices); - saveFunc(this.start, this.end, indices); - this.bestError = error; - } - } - }, { - key: "compress3", - value: function compress3(result, offset) { - var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock3(start, end, indices, result, offset); - }; + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; - this.compressBase(codes, saveFunc); - } - }, { - key: "compress4", - value: function compress4(result, offset) { - var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock4(start, end, indices, result, offset); - }; + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); - this.compressBase(codes, saveFunc); - } - }, { - key: "computePoints", - value: function computePoints() { - var _this$colors = this.colors, - count = _this$colors.count, - values = _this$colors.points, - weights = _this$colors.weights; - if (count <= 0) return; - var principle = computePCA(values, weights); - var start, end, min, max; - start = end = values[0]; - min = max = Vec3.dot(start, principle); + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + var _i7 = r.strategy === at ? function (t, e) { + var i; - for (var i = 1; i < count; i++) { - var value = Vec3.dot(values[i], principle); + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } - if (value < min) { - start = values[i]; - min = value; - } else if (value > max) { - end = values[i]; - max = value; + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - } - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); - } - }]); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : r.strategy === ot ? function (t, e) { + var i, n, r, s; + var a = t.window; - return RangeFit; - }(ColorFit); + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } - var ClusterFit = function (_ColorFit3) { - _inherits(ClusterFit, _ColorFit3); + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; - var _super3 = _createSuper(ClusterFit); + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); - function ClusterFit(colorSet) { - var _this4; + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } - _classCallCheck(this, ClusterFit); + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - _this4 = _super3.call(this, colorSet); - var kMaxIterations = 8; - _this4.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; - _this4.bestError = Infinity; - _this4.metric = new Vec4(1); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : Ot[r.level].func(r, e); - if ((_this4.flags & kColourMetricPerceptual) !== 0) { - _this4.metric.set(0.2126, 0.7152, 0.0722, 0); + if (3 !== _i7 && 4 !== _i7 || (r.status = pt), 1 === _i7 || 3 === _i7) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === _i7 && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; } - var _this4$colors = _this4.colors, - values = _this4$colors.points, - weights = _this4$colors.weights; - _this4.principle = computePCA(values, weights); - _this4.order = new Uint8Array(16 * kMaxIterations); - _this4.pointsWeights = []; - _this4.xSum_wSum = new Vec4(0); - return _this4; - } - - _createClass(ClusterFit, [{ - key: "constructOrdering", - value: function constructOrdering(axis, iteration) { - var currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration); - var uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if (!uniqueOrder) return false; - this.copyOrderWeight(currentOrder); - return true; - } - }, { - key: "compress3", - value: function compress3(result, offset) { - var aabbx = function aabbx(_ref) { - var part0 = _ref[0], - part1 = _ref[2], - part2 = _ref[3]; - var const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); - var alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); - var alpha2_sum = alphax_sum.splatW; - var betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); - var beta2_sum = betax_sum.splatW; - var alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = function Ft(t) { + if (!t || !t.state) return et; + var e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = function Mt(t, e) { + var i = e.length; + if (!t || !t.state) return et; + var n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock3(start, end, indices, result, offset); - }; + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); - this.compressBase(aabbx, saveFunc, 2); - } - }, { - key: "compress4", - value: function compress4(result, offset) { - var aabbx = function aabbx(_ref2) { - var part0 = _ref2[0], - part1 = _ref2[1], - part2 = _ref2[2], - part3 = _ref2[3]; - var const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); - var const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); - var const2_9 = new Vec4(2 / 9); - var alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); - var alpha2_sum = alphax_sum.splatW; - var betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); - var beta2_sum = betax_sum.splatW; - var alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; + var _t3 = new Uint8Array(n.w_size); - var saveFunc = function saveFunc(start, end, indices) { - return writeColourBlock4(start, end, indices, result, offset); - }; + _t3.set(e.subarray(i - n.w_size, i), 0), e = _t3, i = n.w_size; + } - this.compressBase(aabbx, saveFunc, 3); + var s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + var _t4 = n.strstart, + _e12 = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[_t4 + 3 - 1]), n.prev[_t4 & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = _t4, _t4++; + } while (--_e12); + + n.strstart = _t4, n.lookahead = 2, zt(n); } - }, { - key: "compressBase", - value: function compressBase(aabbFunc, saveFunc) { - var _this5 = this; - var repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - this.constructOrdering(this.principle, 0); - var best = { - start: new Vec4(0), - end: new Vec4(0), - error: this.bestError, - iteration: 0, - bestI: 0, - bestJ: 0 - }; - if (repeater === 3) best.bestK = 0; + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; - var leastSquares = function leastSquares(parts, internalIndices) { - var aabbx = aabbFunc(parts); + var Pt = function Pt(t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; - var internalBest = _this5.computeOptimalPoints(aabbx); + var Ht = function Ht(t) { + var e = Array.prototype.slice.call(arguments, 1); - if (internalBest.error < best.error) { - best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); - return true; - } + for (; e.length;) { + var _i8 = e.shift(); - return false; - }; + if (_i8) { + if ("object" != _typeof(_i8)) throw new TypeError(_i8 + "must be non-object"); - for (var iterationIndex = 0;;) { - this.clusterIterate(iterationIndex, leastSquares, repeater); - if (best.iteration != iterationIndex) break; - iterationIndex++; - if (iterationIndex == this.iterationCount) break; - var newAxis = Vec4.sub(best.end, best.start).xyz; - if (!this.constructOrdering(newAxis, iterationIndex)) break; + for (var _e13 in _i8) { + Pt(_i8, _e13) && (t[_e13] = _i8[_e13]); + } } - - if (best.error < this.bestError) this.saveBlock(best, saveFunc); } - }, { - key: "makeOrder", - value: function makeOrder(axis) { - var _this$colors2 = this.colors, - count = _this$colors2.count, - values = _this$colors2.points; - var dotProducts = values.map(function (color, i) { - return Vec3.dot(color, axis); - }); - return __arrayMaker({ - length: count - }, function (_, i) { - return i; - }).sort(function (a, b) { - if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; - return a - b; - }); + + return t; + }, + Wt = function Wt(t) { + var e = 0; + + for (var _i9 = 0, _n3 = t.length; _i9 < _n3; _i9++) { + e += t[_i9].length; } - }, { - key: "copyOrderToThisOrder", - value: function copyOrderToThisOrder(order, iteration) { - var _this6 = this; - var orderOffset = iteration * 16; - order.forEach(function (ord, i) { - _this6.order[orderOffset + i] = ord; - }); + var i = new Uint8Array(e); + + for (var _e14 = 0, _n4 = 0, _r2 = t.length; _e14 < _r2; _e14++) { + var _r3 = t[_e14]; + i.set(_r3, _n4), _n4 += _r3.length; } - }, { - key: "checkOrderUnique", - value: function checkOrderUnique(order, iteration) { - var count = this.colors.count; - for (var it = 0; it < iteration; it++) { - var prevOffset = it * 16; - var same = true; + return i; + }; - for (var i = 0; i < count; i++) { - if (order[i] !== this.order[prevOffset + i]) { - same = false; - break; - } - } + var Kt = !0; - if (same) return false; - } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } - return true; - } - }, { - key: "copyOrderWeight", - value: function copyOrderWeight(order) { - var _this$colors3 = this.colors, - count = _this$colors3.count, - unweighted = _this$colors3.points, - weights = _this$colors3.weights; - this.xSum_wSum.set(0); + var $t = new Uint8Array(256); - for (var i = 0; i < count; i++) { - var j = order[i]; - var p = unweighted[j].toVec4(1); - var w = new Vec4(weights[j]); - var x = Vec4.multVector(p, w); - this.pointsWeights[i] = x; - this.xSum_wSum.addVector(x); - } - } - }, { - key: "computeOptimalPoints", - value: function computeOptimalPoints(vectorPoint) { - var ax = vectorPoint.ax, - bx = vectorPoint.bx, - aa = vectorPoint.aa, - bb = vectorPoint.bb, - ab = vectorPoint.ab; - var factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); - var a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); - var b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); - a.clampGrid(); - b.clampGrid(); - var error = this.computeError(_objectSpread2({ - a: a, - b: b - }, vectorPoint)); - return { - start: a, - end: b, - error: error - }; - } - }, { - key: "computeError", - value: function computeError(_ref3) { - var a = _ref3.a, - b = _ref3.b, - ax = _ref3.ax, - bx = _ref3.bx, - aa = _ref3.aa, - bb = _ref3.bb, - ab = _ref3.ab; - var two = new Vec4(2); - var e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); - var e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); - var e3 = Vec4.negativeMultiplySubtract(b, bx, e2); - var e4 = Vec4.multiplyAdd(two, e3, e1); - var e5 = Vec4.multVector(e4, this.metric); - return e5.x + e5.y + e5.z; - } - }, { - key: "saveBlock", - value: function saveBlock(best, writeFunc) { - var count = this.colors.count; - var start = best.start, - end = best.end, - iteration = best.iteration, - error = best.error, - bestI = best.bestI, - bestJ = best.bestJ, - _best$bestK = best.bestK, - bestK = _best$bestK === void 0 ? -1 : _best$bestK; - var orderOffset = iteration * 16; - var unordered = new Uint8Array(16); + for (var _t5 = 0; _t5 < 256; _t5++) { + $t[_t5] = _t5 >= 252 ? 6 : _t5 >= 248 ? 5 : _t5 >= 240 ? 4 : _t5 >= 224 ? 3 : _t5 >= 192 ? 2 : 1; + } - var mapper = function mapper(m) { - if (m < bestI) return 0; - if (m < bestJ) return 2; - if (m < bestK) return 3; - return 1; - }; + $t[254] = $t[254] = 1; - for (var i = 0; i < count; i++) { - unordered[this.order[orderOffset + i]] = mapper(i); - } + var Yt = function Yt(t) { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + var e, + i, + n, + r, + s, + a = t.length, + o = 0; - var bestIndices = new Uint8Array(16); - this.colors.remapIndices(unordered, bestIndices); - writeFunc(start.xyz, end.xyz, bestIndices); - this.bestError = error; + for (r = 0; r < a; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; } - }, { - key: "clusterIterate", - value: function clusterIterate(index, func) { - var iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - var count = this.colors.count; - - var indexMapper = function indexMapper(i, j, k) { - var mapper = { - bestI: i, - bestJ: iterCount === 2 ? k : j, - iteration: index - }; - if (iterCount === 3) mapper.bestK = k; - return mapper; - }; - var part0 = new Vec4(0.0); + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + } - for (var i = 0; i < count; i++) { - var part1 = new Vec4(0.0); + return e; + }, + jt = function jt(t, e) { + var i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + var n, r; + var s = new Array(2 * i); - for (var j = i;;) { - var preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); - var kmin = j == 0 ? 1 : j; + for (r = 0, n = 0; n < i;) { + var _e15 = t[n++]; - for (var k = kmin;;) { - var restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - if (k == count) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } + if (_e15 < 128) { + s[r++] = _e15; + continue; + } - if (iterCount === 2) break; - if (j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; + var _a = $t[_e15]; + if (_a > 4) s[r++] = 65533, n += _a - 1;else { + for (_e15 &= 2 === _a ? 31 : 3 === _a ? 15 : 7; _a > 1 && n < i;) { + _e15 = _e15 << 6 | 63 & t[n++], _a--; } - part0.addVector(this.pointsWeights[i]); + _a > 1 ? s[r++] = 65533 : _e15 < 65536 ? s[r++] = _e15 : (_e15 -= 65536, s[r++] = 55296 | _e15 >> 10 & 1023, s[r++] = 56320 | 1023 & _e15); } } - }]); - - return ClusterFit; - }(ColorFit); - function quantise(alpha) { - var GRID = 15; - var result = Math.floor(alpha * (GRID / 255) + 0.5); - if (result < 0) return 0; - if (result > GRID) return GRID; - return result; - } + return function (t, e) { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + var i = ""; - function compressAlphaDxt3(rgba, mask, result, offset) { - for (var i = 0; i < 8; i++) { - var quant1 = quantise(rgba[8 * i + 3]); - var quant2 = quantise(rgba[8 * i + 7]); - var bit1 = 1 << 2 * i; - var bit2 = 1 << 2 * i + 1; - if ((mask & bit1) == 0) quant1 = 0; - if ((mask & bit2) == 0) quant2 = 0; - result[offset + i] = quant1 | quant2 << 4; - } - } + for (var _n5 = 0; _n5 < e; _n5++) { + i += String.fromCharCode(t[_n5]); + } - function compressAlphaDxt5(rgba, mask, result, offset) { - var step5 = interpolateAlpha(rgba, mask, 5); - var step7 = interpolateAlpha(rgba, mask, 7); - if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); - } + return i; + }(s, r); + }, + Gt = function Gt(t, e) { + (e = e || t.length) > t.length && (e = t.length); + var i = e - 1; - function interpolateAlpha(rgba, mask, steps) { - var _setAlphaRange = setAlphaRange(rgba, mask, steps), - min = _setAlphaRange.min, - max = _setAlphaRange.max; + for (; i >= 0 && 128 == (192 & t[i]);) { + i--; + } - var code = setAlphaCodeBook(min, max, steps); - var indices = new Uint8Array(16); - var error = fitCodes(rgba, mask, code, indices); - return { - min: min, - max: max, - indices: indices, - error: error + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; }; - } - function setAlphaRange(rgba, mask, steps) { - var min = 255; - var max = 0; + var Vt = Object.prototype.toString, + qt = H.Z_NO_FLUSH, + Jt = H.Z_SYNC_FLUSH, + Qt = H.Z_FULL_FLUSH, + te = H.Z_FINISH, + ee = H.Z_OK, + ie = H.Z_STREAM_END, + ne = H.Z_DEFAULT_COMPRESSION, + re = H.Z_DEFAULT_STRATEGY, + se = H.Z_DEFLATED; - for (var i = 0; i < 16; i++) { - var bit = 1 << i; - if ((mask & bit) == 0) continue; - var value = rgba[4 * i + 3]; + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + var e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); - if (steps === 5) { - if (value !== 0 && value < min) min = value; - if (value !== 255 && value > max) max = value; - } else { - if (value < min) min = value; - if (value > max) max = value; + if (e.header && St(this.strm, e.header), e.dictionary) { + var _t6; + + if (_t6 = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, _t6), i !== ee) throw new Error(P[i]); + this._dict_set = !0; } } - if (min > max) min = max; - if (max - min < steps) max = Math.min(min + steps, 255); - if (max - min < steps) min = Math.max(max - steps, 0); - return { - min: min, - max: max + function oe(t, e) { + var i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize; + var r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; }; - } - function setAlphaCodeBook(min, max, steps) { - var codes = [min, max].concat(__arrayMaker({ - length: steps - 1 - }, function (_, i) { - return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); - })); + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + var i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; - if (steps === 5) { - codes[6] = 0; - codes[7] = 255; - } + var U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; - return codes; - } + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; - function fitCodes(rgba, mask, codes, indices) { - var err = 0; + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } - for (var i = 0; i < 16; ++i) { - var bit = 1 << i; + if (32 & m) { + U.mode = 12; + break t; + } - if ((mask & bit) == 0) { - indices[i] = 0; - continue; - } + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } - var value = rgba[4 * i + 3]; - var least = Infinity; - var index = 0; + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; - for (var j = 0; j < 8; ++j) { - var dist = value - codes[j]; - dist *= dist; + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } - if (dist < least) { - least = dist; - index = j; - } - } + t.msg = "invalid distance code", U.mode = 30; + break t; + } - indices[i] = index; - err += least; - } + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); - return err; - } + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; - function writeAlphaBlock5(_ref, result, offset) { - var alpha0 = _ref.min, - alpha1 = _ref.max, - indices = _ref.indices; + do { + x[r++] = _[v++]; + } while (--m); - if (alpha0 > alpha1) { - var swapped = indices.map(function (index) { - if (index === 0) return 1; - if (index === 1) return 0; - if (index <= 5) return 7 - index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); - } + if (v = 0, d < k) { + m = d, k -= m; - function writeAlphaBlock7(_ref2, result, offset) { - var alpha0 = _ref2.min, - alpha1 = _ref2.max, - indices = _ref2.indices; + do { + x[r++] = _[v++]; + } while (--m); - if (alpha0 > alpha1) { - var swapped = indices.map(function (index) { - if (index === 0) return 1; - if (index === 1) return 0; - return 9 - index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); - } + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; - function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { - result[offset] = alpha0; - result[offset + 1] = alpha1; - var indicesPointer = 0; - var resultPointer = offset + 2; + do { + x[r++] = _[v++]; + } while (--m); - for (var i = 0; i < 2; i++) { - var value = 0; + v = r - y, E = x; + } - for (var j = 0; j < 8; ++j) { - var index = indices[indicesPointer]; - value |= index << 3 * j; - indicesPointer++; - } + for (; k > 2;) { + x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + } - for (var _j = 0; _j < 3; ++_j) { - var byte = value >> 8 * _j & 0xff; - result[resultPointer] = byte; - resultPointer++; - } - } - } + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; - function unpack565(color16bit) { - var red = color16bit >> 11 & 0x1f; - var green = color16bit >> 5 & 0x3f; - var blue = color16bit & 0x1f; - return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; - } + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); - function interpolateColorArray(a, b, amount) { - var result = a.map(function (aColor, i) { - return Math.floor(aColor * (1 - amount) + b[i] * amount); - }); - result[3] = 255; - return result; - } + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } - function unpackColorCodes(block, offset, isDxt1) { - var color1 = block[offset] | block[offset + 1] << 8; - var color2 = block[offset + 2] | block[offset + 3] << 8; - var unpackedColor1 = unpack565(color1); - var unpackedColor2 = unpack565(color2); - return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; - } + break; + } + } + break; + } + } while (i < n && r < a); - function unpackIndices(block, blockOffset) { - var offset = blockOffset + 4; - var result = new Uint8Array(16); + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; - for (var i = 0; i < 4; i++) { - var packedIndices = block[offset + i]; - result[i * 4 + 0] = packedIndices & 0x3; - result[i * 4 + 1] = packedIndices >> 2 & 0x3; - result[i * 4 + 2] = packedIndices >> 4 & 0x3; - result[i * 4 + 3] = packedIndices >> 6 & 0x3; - } + var de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); - return result; - } + var ue = function ue(t, e, i, n, r, s, a, o) { + var h = o.bits; - function decompressColor(rgba, block, offset, isDxt1) { - var colorCode = unpackColorCodes(block, offset, isDxt1); - var indices = unpackIndices(block, offset); + var l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; - for (var i = 0; i < 16; i++) { - for (var j = 0; j < 4; j++) { - rgba[4 * i + j] = colorCode[indices[i]][j]; + var z = new Uint16Array(16), + R = new Uint16Array(16); + var N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) { + z[w] = 0; } - } - } - function decompressAlphaDxt3(rgba, block, offset) { - for (var i = 0; i < 8; ++i) { - var quant = block[offset + i]; - var lo = quant & 0x0f; - var hi = quant & 0xf0; - rgba[8 * i + 3] = lo | lo << 4; - rgba[8 * i + 7] = hi | hi >> 4; - } - } + for (p = 0; p < n; p++) { + z[e[i + p]]++; + } - function decompressAlphaDxt5(rgba, block, offset) { - var alpha0 = block[offset + 0]; - var alpha1 = block[offset + 1]; - var codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); - var indices = new Uint8Array(16); - var indicePointer = 0; - var bytePointer = 2; + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--) { + } - for (var i = 0; i < 2; i++) { - var value = 0; + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; - for (var j = 0; j < 3; j++) { - var byte = block[offset + bytePointer]; - value |= byte << 8 * j; - bytePointer++; + for (g = 1; g < b && 0 === z[g]; g++) { } - for (var _j = 0; _j < 8; _j++) { - var index = value >> 3 * _j & 0x7; - indices[indicePointer] = index; - indicePointer++; + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) { + if (v <<= 1, v -= z[w], v < 0) return -1; } - } - for (var _i = 0; _i < 16; ++_i) { - rgba[4 * _i + 3] = codes[indices[_i]]; - } - } - - var DXT1_COMPRESSED_BYTES = 8; - var DXT5_COMPRESSED_BYTES = 16; - var COLORS = 4; - var DECOMPRESSED_BLOCK_SIZE = 16; + if (v > 0 && (0 === t || 1 !== b)) return -1; - function blockRepeat(width, height, func) { - for (var y = 0; y < height; y += 4) { - for (var x = 0; x < width; x += 4) { - func(x, y); + for (R[1] = 0, w = 1; w < 15; w++) { + R[w + 1] = R[w] + z[w]; } - } - } - function rectRepeat(func) { - for (var y = 0; y < 4; y++) { - for (var x = 0; x < 4; x++) { - func(x, y); + for (p = 0; p < n; p++) { + 0 !== e[i + p] && (a[R[e[i + p]]++] = p); } - } - } - - function FixFlags(flags) { - var method = flags & (kDxt1 | kDxt3 | kDxt5); - var fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); - var metric = flags & (kColourMetricPerceptual | kColourMetricUniform); - var extra = flags & kWeightColourByAlpha; - if (method != kDxt3 && method != kDxt5) method = kDxt1; - if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; - if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; - return method | fit | metric | extra; - } - function GetStorageRequirements(width, height, flags) { - flags = FixFlags(flags); - var blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); - var blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - return blockcount * blocksize; - } + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; - function extractColorBlock(img) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref$x = _ref.x, - x = _ref$x === void 0 ? 0 : _ref$x, - _ref$y = _ref.y, - y = _ref$y === void 0 ? 0 : _ref$y, - _ref$width = _ref.width, - width = _ref$width === void 0 ? 0 : _ref$width, - _ref$height = _ref.height, - height = _ref$height === void 0 ? 0 : _ref$height; + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; - var block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - var mask = 0; - var blockColorOffset = 0; - rectRepeat(function (px, py) { - var sx = x + px; - var sy = y + py; + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); - if (sx < width && sy < height) { - var sourceColorOffset = COLORS * (width * sy + sx); + for (l = 1 << w - 1; A & l;) { + l >>= 1; + } - for (var i = 0; i < COLORS; i++) { - block[blockColorOffset++] = img[sourceColorOffset++]; + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; } - mask |= 1 << 4 * py + px; - } else blockColorOffset += COLORS; - }); - return { - block: block, - mask: mask + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) { + k++, v <<= 1; + } + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; }; - } - function copyBuffer(result, block) { - var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref2$x = _ref2.x, - x = _ref2$x === void 0 ? 0 : _ref2$x, - _ref2$y = _ref2.y, - y = _ref2$y === void 0 ? 0 : _ref2$y, - _ref2$width = _ref2.width, - width = _ref2$width === void 0 ? 0 : _ref2$width, - _ref2$height = _ref2.height, - height = _ref2$height === void 0 ? 0 : _ref2$height; + var we = H.Z_FINISH, + pe = H.Z_BLOCK, + ge = H.Z_TREES, + be = H.Z_OK, + me = H.Z_STREAM_END, + ke = H.Z_NEED_DICT, + ye = H.Z_STREAM_ERROR, + ve = H.Z_DATA_ERROR, + Ee = H.Z_MEM_ERROR, + Ae = H.Z_BUF_ERROR, + xe = H.Z_DEFLATED, + Ue = 12, + ze = 30, + Re = function Re(t) { + return (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + }; - var blockColorOffset = 0; - rectRepeat(function (px, py) { - var sx = x + px; - var sy = y + py; + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } - if (sx < width && sy < height) { - var resultColorOffset = COLORS * (width * sy + sx); + var Te = function Te(t) { + if (!t || !t.state) return ye; + var e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = function Oe(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = function Le(t, e) { + var i; + if (!t || !t.state) return ye; + var n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = function Be(t, e) { + if (!t) return ye; + var i = new Ne(); + t.state = i, i.window = null; + var n = Le(t, e); + return n !== be && (t.state = null), n; + }; - for (var i = 0; i < COLORS; i++) { - result[resultColorOffset + i] = block[blockColorOffset++]; - } - } else blockColorOffset += COLORS; - }); - } + var Ce, + De, + Ie = !0; - function getCompressor(colorSet) { - if (colorSet.count === 1) return new SingleColourFit(colorSet); - if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); - return new ClusterFit(colorSet); - } + var Se = function Se(t) { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + var _e16 = 0; - function CompressMasked(rgba, mask, result, offset, flags) { - flags = FixFlags(flags); - var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - var colors = new ColorSet(rgba, mask, flags); - var compressor = getCompressor(colors); - compressor.compress(result, offset + colorOffset); - if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); - } + for (; _e16 < 144;) { + t.lens[_e16++] = 8; + } - function decompressBlock(result, block, offset, flags) { - flags = FixFlags(flags); - var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); - if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); - } + for (; _e16 < 256;) { + t.lens[_e16++] = 9; + } - function compressImage(source, width, height, result, flags) { - flags = FixFlags(flags); - var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - var targetBlockPointer = 0; - blockRepeat(width, height, function (x, y) { - var _extractColorBlock = extractColorBlock(source, { - x: x, - y: y, - width: width, - height: height - }), - sourceRGBA = _extractColorBlock.block, - mask = _extractColorBlock.mask; + for (; _e16 < 280;) { + t.lens[_e16++] = 7; + } - CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); - targetBlockPointer += bytesPerBlock; - }); - } + for (; _e16 < 288;) { + t.lens[_e16++] = 8; + } - function decompressImage(result, width, height, source, flags) { - flags = FixFlags(flags); - var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - var sourceBlockPointer = 0; + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), _e16 = 0; _e16 < 32;) { + t.lens[_e16++] = 5; + } - for (var y = 0; y < height; y += 4) { - for (var x = 0; x < width; x += 4) { - var targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - decompressBlock(targetRGBA, source, sourceBlockPointer, flags); - copyBuffer(result, targetRGBA, { - x: x, - y: y, - width: width, - height: height - }); - sourceBlockPointer += bytesPerBlock; + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; } - } - } - var flags = { - DXT1: kDxt1, - DXT3: kDxt3, - DXT5: kDxt5, - ColourIterativeClusterFit: kColourIterativeClusterFit, - ColourClusterFit: kColourClusterFit, - ColourRangeFit: kColourRangeFit, - ColourMetricPerceptual: kColourMetricPerceptual, - ColourMetricUniform: kColourMetricUniform, - WeightColourByAlpha: kWeightColourByAlpha - }; + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = function Ze(t, e, i, n) { + var r; + var s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; - function compress(inputData, width, height, flags) { - var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - var targetSize = GetStorageRequirements(width, height, flags); - var result = new Uint8Array(targetSize); - compressImage(source, width, height, result, flags); - return result; - } + var Fe = Oe, + Me = Be, + Pe = function Pe(t, e) { + var i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + var x = new Uint8Array(4); + var U, z; + var R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) { + switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } - function decompress(inputData, width, height, flags) { - var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - var targetSize = width * height * 4; - var result = new Uint8Array(targetSize); - decompressImage(result, width, height, source, flags); - return result; - } + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } - var Texture2DReader = function (_BaseReader) { - _inherits(Texture2DReader, _BaseReader); + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - var _super = _createSuper(Texture2DReader); + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; - function Texture2DReader() { - _classCallCheck(this, Texture2DReader); + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - return _super.apply(this, arguments); - } + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - _createClass(Texture2DReader, [{ - key: "read", - value: function read(buffer) { - var int32Reader = new Int32Reader(); - var uint32Reader = new UInt32Reader(); - var format = int32Reader.read(buffer); - var width = uint32Reader.read(buffer); - var height = uint32Reader.read(buffer); - var mipCount = uint32Reader.read(buffer); - if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); - var dataSize = uint32Reader.read(buffer); - var data = buffer.read(dataSize); - if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } else if (format != 0) throw new XnbError("Non-implemented Texture2D format type (".concat(format, ") found.")); + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } - for (var i = 0; i < data.length; i += 4) { - var inverseAlpha = 255 / data[i + 3]; - data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); - } + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; - return { - format: format, - export: { - type: this.type, - data: data, - width: width, - height: height - } - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - var int32Reader = new Int32Reader(); - var uint32Reader = new UInt32Reader(); - this.writeIndex(buffer, resolver); - var width = content.export.width; - var height = content.export.height; - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - var data = content.export.data; + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - for (var i = 0; i < data.length; i += 4) { - var alpha = data[i + 3] / 255; - data[i] = Math.floor(data[i] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); - } + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; - if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }]); + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - return Texture2DReader; - }(BaseReader); + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; - var Vector3Reader = function (_BaseReader) { - _inherits(Vector3Reader, _BaseReader); + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var _super = _createSuper(Vector3Reader); + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); - function Vector3Reader() { - _classCallCheck(this, Vector3Reader); + i.mode = 6; - return _super.apply(this, arguments); - } + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; - _createClass(Vector3Reader, [{ - key: "read", - value: function read(buffer) { - var singleReader = new SingleReader(); - var x = singleReader.read(buffer); - var y = singleReader.read(buffer); - var z = singleReader.read(buffer); - return { - x: x, - y: y, - z: z - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } - }]); + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; - return Vector3Reader; - }(BaseReader); + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); - var SpriteFontReader = function (_BaseReader) { - _inherits(SpriteFontReader, _BaseReader); + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); - var _super = _createSuper(SpriteFontReader); + i.length = 0, i.mode = 8; - function SpriteFontReader() { - _classCallCheck(this, SpriteFontReader); + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; - return _super.apply(this, arguments); - } + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); - _createClass(SpriteFontReader, [{ - key: "read", - value: function read(buffer, resolver) { - var int32Reader = new Int32Reader(); - var singleReader = new SingleReader(); - var nullableCharReader = new NullableReader(new CharReader()); - var texture = resolver.read(buffer); - var glyphs = resolver.read(buffer); - var cropping = resolver.read(buffer); - var characterMap = resolver.read(buffer); - var verticalLineSpacing = int32Reader.read(buffer); - var horizontalSpacing = singleReader.read(buffer); - var kerning = resolver.read(buffer); - var defaultCharacter = nullableCharReader.read(buffer); - return { - texture: texture, - glyphs: glyphs, - cropping: cropping, - characterMap: characterMap, - verticalLineSpacing: verticalLineSpacing, - horizontalSpacing: horizontalSpacing, - kerning: kerning, - defaultCharacter: defaultCharacter - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - var int32Reader = new Int32Reader(); - var charReader = new CharReader(); - var singleReader = new SingleReader(); - var nullableCharReader = new NullableReader(charReader); - var texture2DReader = new Texture2DReader(); - var rectangleListReader = new ListReader(new RectangleReader()); - var charListReader = new ListReader(charReader); - var vector3ListReader = new ListReader(new Vector3Reader()); - this.writeIndex(buffer, resolver); + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); - try { - texture2DReader.write(buffer, content.texture, resolver); - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } catch (ex) { - throw ex; - } + i.mode = 9; - console.log("writing complitd!"); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }]); + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } - return SpriteFontReader; - }(BaseReader); + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; - var TBinReader = function (_BaseReader) { - _inherits(TBinReader, _BaseReader); + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var _super = _createSuper(TBinReader); + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; - function TBinReader() { - _classCallCheck(this, TBinReader); + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; - return _super.apply(this, arguments); - } + case Ue: + if (e === pe || e === ge) break t; - _createClass(TBinReader, [{ - key: "read", - value: function read(buffer) { - var int32Reader = new Int32Reader(); - var size = int32Reader.read(buffer); - var data = buffer.read(size); - return { - export: { - type: this.type, - data: data - } - }; - } - }, { - key: "write", - value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - var data = content.export.data; - var int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } - }, { - key: "isValueType", - value: function isValueType() { - return false; - } - }]); + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } - return TBinReader; - }(BaseReader); + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var Vector2Reader = function (_BaseReader) { - _inherits(Vector2Reader, _BaseReader); + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; - var _super = _createSuper(Vector2Reader); + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } - function Vector2Reader() { - _classCallCheck(this, Vector2Reader); + break; - return _super.apply(this, arguments); - } + case 2: + i.mode = 17; + break; - _createClass(Vector2Reader, [{ - key: "read", - value: function read(buffer) { - var singleReader = new SingleReader(); - var x = singleReader.read(buffer); - var y = singleReader.read(buffer); - return { - x: x, - y: y - }; - } - }]); + case 3: + t.msg = "invalid block type", i.mode = ze; + } - return Vector2Reader; - }(BaseReader); + l >>>= 2, d -= 2; + break; - var Vector4Reader = function (_BaseReader) { - _inherits(Vector4Reader, _BaseReader); + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var _super = _createSuper(Vector4Reader); + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } - function Vector4Reader() { - _classCallCheck(this, Vector4Reader); + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; - return _super.apply(this, arguments); - } + case 15: + i.mode = 16; - _createClass(Vector4Reader, [{ - key: "read", - value: function read(buffer) { - var singleReader = new SingleReader(); - var x = singleReader.read(buffer); - var y = singleReader.read(buffer); - var z = singleReader.read(buffer); - var w = singleReader.read(buffer); - return { - x: x, - y: y, - z: z, - w: w - }; - } - }]); + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } - return Vector4Reader; - }(BaseReader); + i.mode = Ue; + break; - var Readers = { - ArrayReader: ArrayReader, - BaseReader: BaseReader, - BmFontReader: BmFontReader, - BooleanReader: BooleanReader, - CharReader: CharReader, - DictionaryReader: DictionaryReader, - DoubleReader: DoubleReader, - EffectReader: EffectReader, - Int32Reader: Int32Reader, - ListReader: ListReader, - NullableReader: NullableReader, - RectangleReader: RectangleReader, - SingleReader: SingleReader, - SpriteFontReader: SpriteFontReader, - StringReader: StringReader, - TBinReader: TBinReader, - Texture2DReader: Texture2DReader, - UInt32Reader: UInt32Reader, - Vector2Reader: Vector2Reader, - Vector3Reader: Vector3Reader, - Vector4Reader: Vector4Reader - }; + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } - var simplifyType = function simplifyType(type) { - var simple = type.split(/`|,/)[0]; - var isArray = simpl__endsWithString(e, '[]'); - if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + i.have = 0, i.mode = 18; - switch (simple) { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; + for (; i.have < 19;) { + i.lens[R[i.have++]] = 0; + } - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - var subtypes = parseSubtypes(type).map(simplifyType); - return "Dictionary<".concat(subtypes[0], ",").concat(subtypes[1], ">"); + i.have = 0, i.mode = 19; - case 'Microsoft.Xna.Framework.Content.ArrayReader': - var arrayType = parseSubtypes(type).map(simplifyType); - return "Array<".concat(arrayType, ">"); + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - var listType = parseSubtypes(type).map(simplifyType); - return "List<".concat(listType, ">"); + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; + for (; c--;) { + i.lens[i.have++] = v; + } + } + } - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; + if (i.mode === ze) break; - case 'xTile.Pipeline.TideReader': - return 'TBin'; + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } - case 'BmFont.XmlSourceReader': - return 'BmFont'; + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } - default: - throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); - } - }; + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } - var parseSubtypes = function parseSubtypes(type) { - var subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - var matches = subtype.match(pattern).map(function (e) { - return e.slice(1, -1); - }); - return matches; - }; + if (i.mode = 20, e === ge) break t; - var getTypeInfo = function getTypeInfo(type) { - var mainType = type.match(/[^<]+/)[0]; - var subtypes = type.match(/<(.+)>/); - subtypes = subtypes ? subtypes[1].split(',').map(function (type) { - return type.trim(); - }) : []; - return { - type: mainType, - subtypes: subtypes - }; - }; + case 20: + i.mode = 21; - var getReader = function getReader(typeString) { - var _getTypeInfo = getTypeInfo(typeString), - type = _getTypeInfo.type, - subtypes = _getTypeInfo.subtypes; + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } - subtypes = subtypes.map(getReader); - if (Readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(Readers["".concat(type, "Reader")], subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); - }; + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var XnbData = function () { - function XnbData(header, readers, content) { - _classCallCheck(this, XnbData); + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - var target = header.target, - formatVersion = header.formatVersion, - hidef = header.hidef, - compressed = header.compressed; - this.header = { - target: target, - formatVersion: formatVersion, - hidef: hidef, - compressed: compressed - }; - this.readers = readers; - this.content = content; - } + l >>>= m, d -= m, i.back += m; + } - _createClass(XnbData, [{ - key: "target", - get: function get() { - var _this$header; + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } - switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { - case 'w': - return "Microsoft Windows"; + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } - case 'm': - return "Windows Phone 7"; + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } - case 'x': - return "Xbox 360"; + i.extra = 15 & g, i.mode = 22; - case 'a': - return "Android"; + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'i': - return "iOS"; + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } - default: - return "Unknown"; - } - } - }, { - key: "formatVersion", - get: function get() { - var _this$header2; + i.was = i.length, i.mode = 23; - switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { - case 0x3: - return "XNA Game Studio 3.0"; + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 0x4: - return "XNA Game Studio 3.1"; + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 0x5: - return "XNA Game Studio 4.0"; + l >>>= m, d -= m, i.back += m; + } - default: - return "Unknown"; - } - } - }, { - key: "hidef", - get: function get() { - var _this$header3; + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } - return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); - } - }, { - key: "compressed", - get: function get() { - var _this$header4; + i.offset = b, i.extra = 15 & g, i.mode = 24; - return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); - } - }, { - key: "contentType", - get: function get() { - var raw = this.content.export; - if (raw !== undefined) return raw.type; - return "JSON"; - } - }, { - key: "rawContent", - get: function get() { - var raw = this.content.export; - if (raw !== undefined) return raw.data; - return JSON.stringify(this.content, function (key, value) { - if (key === "export") return value.type; - return value; - }, 4); - } - }, { - key: "stringify", - value: function stringify() { - return JSON.stringify({ - header: this.header, - readers: this.readers, - content: this.content - }, null, 4); - } - }, { - key: "toString", - value: function toString() { - return this.stringify(); - } - }]); + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - return XnbData; - }(); + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } - function extensionToDatatype(extension) { - switch (extension) { - case "json": - return "JSON"; + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } - case "yaml": - return "yaml"; + i.mode = 25; - case "png": - return "Texture2D"; + case 25: + if (0 === h) break t; - case "cso": - return "Effect"; + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } - case 'tbin': - return "TBin"; + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; - case 'xml': - return "BmFont"; - } + c > h && (c = h), h -= c, i.length -= c; - return "Others"; - } + do { + r[a++] = w[u++]; + } while (--c); - var XnbContent = _createClass(function XnbContent(data, ext) { - _classCallCheck(this, XnbContent); + 0 === i.length && (i.mode = 21); + break; - this.type = extensionToDatatype(ext); - this.content = data; - }); + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; - var HIDEF_MASK = 0x1; - var COMPRESSED_LZ4_MASK = 0x40; - var COMPRESSED_LZX_MASK = 0x80; - var XNB_COMPRESSED_PROLOGUE_SIZE = 14; + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } - var XnbConverter = function () { - function XnbConverter() { - _classCallCheck(this, XnbConverter); + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } - this.target = ''; - this.formatVersion = 0; - this.hidef = false; - this.compressed = false; - this.compressionType = 0; - this.buffer = null; - this.fileSize = 0; - this.readers = []; - this.sharedResources = []; - } + l = 0, d = 0; + } - _createClass(XnbConverter, [{ - key: "load", - value: function load(arrayBuffer) { - this.buffer = new BufferReader(arrayBuffer); + i.mode = 28; - this._validateHeader(); + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - console.info('XNB file validated successfully!'); - this.fileSize = this.buffer.readUInt32(); - if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } - if (this.compressed) { - var decompressedSize = this.buffer.readUInt32(); + l = 0, d = 0; + } - if (this.compressionType == COMPRESSED_LZX_MASK) { - var compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; - var decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } else if (this.compressionType == COMPRESSED_LZ4_MASK) { - var trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - var trimmedArray = new Uint8Array(trimmed); + i.mode = 29; - var _decompressed = new Uint8Array(decompressedSize); + case 29: + E = me; + break t; - decompressBlock$1(trimmedArray, _decompressed); - this.buffer.copyFrom(_decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - } + case ze: + E = ve; + break t; - var count = this.buffer.read7BitNumber(); - var stringReader = new StringReader(); - var readers = []; + case 31: + return Ee; - for (var i = 0; i < count; i++) { - var type = stringReader.read(this.buffer); - var version = this.buffer.readInt32(); - var simpleType = simplifyType(type); - var reader = getReader(simpleType); - this.readers.push(reader); - readers.push({ - type: type, - version: version - }); + default: + return ye; } - - var shared = this.buffer.read7BitNumber(); - if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); - var content = new ReaderResolver(this.readers); - var result = content.read(this.buffer); - console.log('Successfuly read XNB file!'); - return new XnbData({ - target: this.target, - formatVersion: this.formatVersion, - hidef: this.hidef, - compressed: this.compressed - }, readers, result); } - }, { - key: "convert", - value: function convert(json) { - var buffer = new BufferWriter(); - var stringReader = new StringReader(); - var _json$header = json.header, - target = _json$header.target, - formatVersion = _json$header.formatVersion, - hidef = _json$header.hidef, - compressed = _json$header.compressed; - this.target = target; - this.formatVersion = formatVersion; - this.hidef = hidef; - var lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; - this.compressed = lz4Compression ? true : false; - buffer.writeString("XNB"); - buffer.writeString(this.target); - buffer.writeByte(this.formatVersion); - buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); - buffer.writeUInt32(0); - if (lz4Compression) buffer.writeUInt32(0); - buffer.write7BitNumber(json.readers.length); - for (var _i2 = 0, _json$readers2 = json.readers; _i2 < _json$readers2.length; _i2++) { - var reader = _json$readers2[_i2]; - this.readers.push(getReader(simplifyType(reader.type))); - stringReader.write(buffer, reader.type); - buffer.writeUInt32(reader.version); - } + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = function He(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = function We(t, e) { + if (!t || !t.state) return ye; + var i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = function Ke(t, e) { + var i = e.length; + var n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; - buffer.write7BitNumber(0); - var content = new ReaderResolver(this.readers); - content.write(buffer, json.content); - buffer.trim(); + var Ye = Object.prototype.toString, + je = H.Z_NO_FLUSH, + Ge = H.Z_FINISH, + Xe = H.Z_OK, + Ve = H.Z_STREAM_END, + qe = H.Z_NEED_DICT, + Je = H.Z_STREAM_ERROR, + Qe = H.Z_DATA_ERROR, + ti = H.Z_MEM_ERROR; - if (lz4Compression) { - var trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - var trimmedArray = new Uint8Array(trimmed); - var compressedSize = compressBound(trimmedArray.length); + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + var e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } - var _compressed = new Uint8Array(compressedSize); + function ii(t, e) { + var i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } - compressedSize = compressSingleBlock(trimmedArray, _compressed); - _compressed = _compressed.slice(0, compressedSize); - buffer.bytePosition = 6; - buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - buffer.writeUInt32(trimmedArray.length); - buffer.concat(_compressed); - var returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - return returnBuffer; + ei.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + var s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) { + Fe(i), s = Pe(i, a); } - var fileSize = buffer.bytePosition; - buffer.bytePosition = 6; - buffer.writeUInt32(fileSize, 6); - return buffer.buffer; - } - }, { - key: "_validateHeader", - value: function _validateHeader() { - if (this.buffer == null) throw new XnbError('Buffer is null'); - var magic = this.buffer.readString(3); - if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); - this.target = this.buffer.readString(1).toLowerCase(); - this.formatVersion = this.buffer.readByte(); - var flags = this.buffer.readByte(1); - this.hidef = (flags & HIDEF_MASK) != 0; - this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; - this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; - } - }]); + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } - return XnbConverter; - }(); + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + var _t7 = Gt(i.output, i.next_out), + _e17 = i.next_out - _t7, + _r4 = jt(i.output, _t7); - var t = { - 396: function _() { - !function (t) { - if (t.TextEncoder && t.TextDecoder) return !1; + i.next_out = _e17, i.avail_out = n - _e17, _e17 && i.output.set(i.output.subarray(_t7, _t7 + _e17), 0), this.onData(_r4); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); - function e() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; } + } - function i() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - fatal: !1 - }; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); - if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); - } + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + var si = he.deflate, + hi = ni.Inflate, + li = ni.inflate; + var fi = si, + ci = hi, + ui = li; + var wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; - Object.defineProperty(e.prototype, "encoding", { - value: "utf-8" - }), e.prototype.encode = function (t) { - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); - var i = 0; - var n = t.length; - var r = 0, - s = Math.max(32, n + (n >> 1) + 7), - a = new Uint8Array(s >> 3 << 3); + for (var _t8 = 0; _t8 < 256; _t8++) { + var _e18 = _t8; + + for (var _t9 = 0; _t9 < 8; _t9++) { + 1 & _e18 ? _e18 = 3988292384 ^ _e18 >>> 1 : _e18 >>>= 1; + } + + pi[_t8] = _e18; + } - for (; i < n;) { - var _e2 = t.charCodeAt(i++); + var gi = 4294967295; - if (_e2 >= 55296 && _e2 <= 56319) { - if (i < n) { - var _n = t.charCodeAt(i); + function bi(t, e) { + return (function (t, e, i) { + var n = 4294967295; - 56320 == (64512 & _n) && (++i, _e2 = ((1023 & _e2) << 10) + (1023 & _n) + 65536); - } + for (var _t10 = 0; _t10 < i; _t10++) { + n = pi[255 & (n ^ e[_t10])] ^ n >>> 8; + } - if (_e2 >= 55296 && _e2 <= 56319) continue; - } + return n; + }(0, t, e) ^ gi) >>> 0; + } - if (r + 4 > a.length) { - s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + var Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; - var _e3 = new Uint8Array(s); + var Ui = function (_r5) { + _inherits(Ui, _r5); - _e3.set(a), a = _e3; - } + var _super = _createSuper(Ui); - if (0 != (4294967168 & _e2)) { - if (0 == (4294965248 & _e2)) a[r++] = _e2 >> 6 & 31 | 192;else if (0 == (4294901760 & _e2)) a[r++] = _e2 >> 12 & 15 | 224, a[r++] = _e2 >> 6 & 63 | 128;else { - if (0 != (4292870144 & _e2)) continue; - a[r++] = _e2 >> 18 & 7 | 240, a[r++] = _e2 >> 12 & 63 | 128, a[r++] = _e2 >> 6 & 63 | 128; - } - a[r++] = 63 & _e2 | 128; - } else a[r++] = _e2; - } + function Ui(t) { + var _this; - return a.slice(0, r); - }, Object.defineProperty(i.prototype, "encoding", { - value: "utf-8" - }), Object.defineProperty(i.prototype, "fatal", { - value: !1 - }), Object.defineProperty(i.prototype, "ignoreBOM", { - value: !1 - }), i.prototype.decode = function (t) { - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); - var i = new Uint8Array(t); - var n = 0; - var r = i.length, - s = []; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - for (; n < r;) { - var _t2 = i[n++]; - if (0 === _t2) break; - if (0 == (128 & _t2)) s.push(_t2);else if (192 == (224 & _t2)) { - var _e4 = 63 & i[n++]; + _classCallCheck(this, Ui); - s.push((31 & _t2) << 6 | _e4); - } else if (224 == (240 & _t2)) { - var _e5 = 63 & i[n++], - _r = 63 & i[n++]; + _this = _super.call(this, t); + var _e$checkCrc = e.checkCrc, + i = _e$checkCrc === void 0 ? !1 : _e$checkCrc; + _this._checkCrc = i, _this._inflator = new ci(), _this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, _this._end = !1, _this._hasPalette = !1, _this._palette = [], _this._compressionMethod = ki.UNKNOWN, _this._filterMethod = yi.UNKNOWN, _this._interlaceMethod = vi.UNKNOWN, _this._colorType = -1, _this.setBigEndian(); + return _this; + } - s.push((31 & _t2) << 12 | _e5 << 6 | _r); - } else if (240 == (248 & _t2)) { - var _e6 = (7 & _t2) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + _createClass(Ui, [{ + key: "decode", + value: function decode() { + for (this.decodeSignature(); !this._end;) { + this.decodeChunk(); + } - _e6 > 65535 && (_e6 -= 65536, s.push(_e6 >>> 10 & 1023 | 55296), _e6 = 56320 | 1023 & _e6), s.push(_e6); - } + return this.decodeImage(), this._png; + } + }, { + key: "decodeSignature", + value: function decodeSignature() { + for (var _t11 = 0; _t11 < wi.length; _t11++) { + if (this.readUint8() !== wi[_t11]) throw new Error("wrong PNG signature. Byte at ".concat(_t11, " should be ").concat(wi[_t11], ".")); } + } + }, { + key: "decodeChunk", + value: function decodeChunk() { + var t = this.readUint32(), + e = this.readChars(4), + i = this.offset; - return String.fromCharCode.apply(null, s); - }, t.TextEncoder = e, t.TextDecoder = i; - }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); - } - }, - e$1 = {}; + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; - function i(n) { - var r = e$1[n]; - if (void 0 !== r) return r.exports; - var s = e$1[n] = { - exports: {} - }; - return t[n].call(s.exports, s, s.exports, i), s.exports; - } + case "PLTE": + this.decodePLTE(t); + break; - i.d = function (t, e) { - for (var n in e) { - i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { - enumerable: !0, - get: e[n] - }); - } - }, i.o = function (t, e) { - return Object.prototype.hasOwnProperty.call(t, e); - }; - var n = {}; + case "IDAT": + this.decodeIDAT(t); + break; - (function () { - i.d(n, { - P: function P() { - return Mi; - }, - m: function m() { - return Fi; - } - }), i(396); - var t = new TextDecoder("utf-8"), - e = new TextEncoder(); + case "IEND": + this._end = !0; + break; - var r = function () { - function r() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + case "tRNS": + this.decodetRNS(t); + break; - _classCallCheck(this, r); + case "iCCP": + this.decodeiCCP(t); + break; - var i = !1; - "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); - var n = e.offset ? e.offset >>> 0 : 0, - s = t.byteLength - n; - var a = n; - (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; - } + case "tEXt": + this.decodetEXt(t); + break; - _createClass(r, [{ - key: "available", - value: function available() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset + t <= this.length; - } - }, { - key: "isLittleEndian", - value: function isLittleEndian() { - return this.littleEndian; - } - }, { - key: "setLittleEndian", - value: function setLittleEndian() { - return this.littleEndian = !0, this; - } - }, { - key: "isBigEndian", - value: function isBigEndian() { - return !this.littleEndian; - } - }, { - key: "setBigEndian", - value: function setBigEndian() { - return this.littleEndian = !1, this; - } - }, { - key: "skip", - value: function skip() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset += t, this; - } - }, { - key: "seek", - value: function seek(t) { - return this.offset = t, this; - } - }, { - key: "mark", - value: function mark() { - return this._mark = this.offset, this; - } - }, { - key: "reset", - value: function reset() { - return this.offset = this._mark, this; - } - }, { - key: "pushMark", - value: function pushMark() { - return this._marks.push(this.offset), this; - } - }, { - key: "popMark", - value: function popMark() { - var t = this._marks.pop(); + case "pHYs": + this.decodepHYs(); + break; - if (void 0 === t) throw new Error("Mark stack empty"); - return this.seek(t), this; - } - }, { - key: "rewind", - value: function rewind() { - return this.offset = 0, this; + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + var _i10 = this.readUint32(), + _n6 = t + 4, + _r6 = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - _n6 - 4, _n6), _n6); + + if (_r6 !== _i10) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(_i10, ", found ").concat(_r6)); + } else this.skip(4); } }, { - key: "ensureAvailable", - value: function ensureAvailable() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + key: "decodeIHDR", + value: function decodeIHDR() { + var t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + var e = this.readUint8(); + var i; - if (!this.available(t)) { - var _e7 = 2 * (this.offset + t), - _i2 = new Uint8Array(_e7); + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; - _i2.set(new Uint8Array(this.buffer)), this.buffer = _i2.buffer, this.length = this.byteLength = _e7, this._data = new DataView(this.buffer); + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); } - return this; - } - }, { - key: "readBoolean", - value: function readBoolean() { - return 0 !== this.readUint8(); + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); } }, { - key: "readInt8", - value: function readInt8() { - return this._data.getInt8(this.offset++); + key: "decodePLTE", + value: function decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + var e = t / 3; + this._hasPalette = !0; + var i = []; + this._palette = i; + + for (var _t12 = 0; _t12 < e; _t12++) { + i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } } }, { - key: "readUint8", - value: function readUint8() { - return this._data.getUint8(this.offset++); + key: "decodeIDAT", + value: function decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); } }, { - key: "readByte", - value: function readByte() { - return this.readUint8(); + key: "decodetRNS", + value: function decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + var _e19 = 0; + + for (; _e19 < t; _e19++) { + var _t13 = this.readByte(); + + this._palette[_e19].push(_t13); + } + + for (; _e19 < this._palette.length; _e19++) { + this._palette[_e19].push(255); + } + } } }, { - key: "readBytes", - value: function readBytes() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - var e = new Uint8Array(t); + key: "decodeiCCP", + value: function decodeiCCP(t) { + var e, + i = ""; - for (var _i3 = 0; _i3 < t; _i3++) { - e[_i3] = this.readByte(); + for (; "\0" !== (e = this.readChar());) { + i += e; } - return e; + var n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + var r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; } }, { - key: "readInt16", - value: function readInt16() { - var t = this._data.getInt16(this.offset, this.littleEndian); + key: "decodetEXt", + value: function decodetEXt(t) { + var e, + i = ""; - return this.offset += 2, t; - } - }, { - key: "readUint16", - value: function readUint16() { - var t = this._data.getUint16(this.offset, this.littleEndian); + for (; "\0" !== (e = this.readChar());) { + i += e; + } - return this.offset += 2, t; + this._png.text[i] = this.readChars(t - i.length - 1); } }, { - key: "readInt32", - value: function readInt32() { - var t = this._data.getInt32(this.offset, this.littleEndian); - - return this.offset += 4, t; + key: "decodepHYs", + value: function decodepHYs() { + var t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; } }, { - key: "readUint32", - value: function readUint32() { - var t = this._data.getUint32(this.offset, this.littleEndian); - - return this.offset += 4, t; + key: "decodeImage", + value: function decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + var t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); } }, { - key: "readFloat32", - value: function readFloat32() { - var t = this._data.getFloat32(this.offset, this.littleEndian); + key: "decodeInterlaceNull", + value: function decodeInterlaceNull(t) { + var e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + var s, + a, + o = Ei, + h = 0; - return this.offset += 4, t; - } - }, { - key: "readFloat64", - value: function readFloat64() { - var t = this._data.getFloat64(this.offset, this.littleEndian); + for (var _l = 0; _l < e; _l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(_l * n, (_l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; - return this.offset += 8, t; - } - }, { - key: "readBigInt64", - value: function readBigInt64() { - var t = this._data.getBigInt64(this.offset, this.littleEndian); + case 1: + Ri(s, a, n, i); + break; - return this.offset += 8, t; - } - }, { - key: "readBigUint64", - value: function readBigUint64() { - var t = this._data.getBigUint64(this.offset, this.littleEndian); + case 2: + Ni(s, a, o, n); + break; - return this.offset += 8, t; - } - }, { - key: "readChar", - value: function readChar() { - return String.fromCharCode(this.readInt8()); + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + var _t14 = new Uint16Array(r.buffer); + + if (xi) for (var _e20 = 0; _e20 < _t14.length; _e20++) { + _t14[_e20] = (255 & (l = _t14[_e20])) << 8 | l >> 8 & 255; + } + this._png.data = _t14; + } else this._png.data = r; + + var l; } - }, { - key: "readChars", - value: function readChars() { - var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - var e = ""; + }]); + + return Ui; + }(r); + + function zi(t, e, i) { + for (var _n7 = 0; _n7 < i; _n7++) { + e[_n7] = t[_n7]; + } + } + + function Ri(t, e, i, n) { + var r = 0; + + for (; r < n; r++) { + e[r] = t[r]; + } + + for (; r < i; r++) { + e[r] = t[r] + e[r - n] & 255; + } + } - for (var _i4 = 0; _i4 < t; _i4++) { - e += this.readChar(); - } + function Ni(t, e, i, n) { + var r = 0; + if (0 === i.length) for (; r < n; r++) { + e[r] = t[r]; + } else for (; r < n; r++) { + e[r] = t[r] + i[r] & 255; + } + } - return e; - } - }, { - key: "readUtf8", - value: function readUtf8() { - var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return i = this.readBytes(e), t.decode(i); - var i; - } - }, { - key: "writeBoolean", - value: function writeBoolean(t) { - return this.writeUint8(t ? 255 : 0), this; + function Ti(t, e, i, n, r) { + var s = 0; + + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; } - }, { - key: "writeInt8", - value: function writeInt8(t) { - return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] >> 1) & 255; } - }, { - key: "writeUint8", - value: function writeUint8(t) { - return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } else { + for (; s < r; s++) { + e[s] = t[s] + (i[s] >> 1) & 255; } - }, { - key: "writeByte", - value: function writeByte(t) { - return this.writeUint8(t); + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; } - }, { - key: "writeBytes", - value: function writeBytes(t) { - this.ensureAvailable(t.length); + } + } - for (var _e8 = 0; _e8 < t.length; _e8++) { - this._data.setUint8(this.offset++, t[_e8]); - } + function Oi(t, e, i, n, r) { + var s = 0; - return this._updateLastWrittenByte(), this; - } - }, { - key: "writeInt16", - value: function writeInt16(t) { - return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; } - }, { - key: "writeUint16", - value: function writeUint16(t) { - return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + + for (; s < n; s++) { + e[s] = t[s] + e[s - r] & 255; } - }, { - key: "writeInt32", - value: function writeInt32(t) { - return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } else { + for (; s < r; s++) { + e[s] = t[s] + i[s] & 255; } - }, { - key: "writeUint32", - value: function writeUint32(t) { - return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + + for (; s < n; s++) { + e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; } - }, { - key: "writeFloat32", - value: function writeFloat32(t) { - return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + } + + function Li(t, e, i) { + var n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + var Bi = { + level: 3 + }; + + var Ci = function (_r7) { + _inherits(Ci, _r7); + + var _super2 = _createSuper(Ci); + + function Ci(t) { + var _this2; + + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Ci); + + _this2 = _super2.call(this), _this2._colorType = mi.UNKNOWN, _this2._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), _this2._png = _this2._checkData(t), _this2.setBigEndian(); + return _this2; + } + + _createClass(Ci, [{ + key: "encode", + value: function encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); } }, { - key: "writeFloat64", - value: function writeFloat64(t) { - return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + key: "encodeSignature", + value: function encodeSignature() { + this.writeBytes(wi); } }, { - key: "writeBigInt64", - value: function writeBigInt64(t) { - return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + key: "encodeIHDR", + value: function encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); } }, { - key: "writeBigUint64", - value: function writeBigUint64(t) { - return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + key: "encodeIEND", + value: function encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); } }, { - key: "writeChar", - value: function writeChar(t) { - return this.writeUint8(t.charCodeAt(0)); + key: "encodeIDAT", + value: function encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); } }, { - key: "writeChars", - value: function writeChars(t) { - for (var _e9 = 0; _e9 < t.length; _e9++) { - this.writeUint8(t.charCodeAt(_e9)); + key: "encodeData", + value: function encodeData() { + var _this$_png = this._png, + t = _this$_png.width, + e = _this$_png.height, + i = _this$_png.channels, + n = _this$_png.depth, + s = _this$_png.data, + a = i * t, + o = new r().setBigEndian(); + var h = 0; + + for (var _t15 = 0; _t15 < e; _t15++) { + if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } } - return this; - } - }, { - key: "writeUtf8", - value: function writeUtf8(t) { - return this.writeBytes(function (t) { - return e.encode(t); - }(t)); - } - }, { - key: "toArray", - value: function toArray() { - return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + var l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); } }, { - key: "_updateLastWrittenByte", - value: function _updateLastWrittenByte() { - this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); - } - }]); + key: "_checkData", + value: function _checkData(t) { + var _ref = function (t) { + var _t$channels = t.channels, + e = _t$channels === void 0 ? 4 : _t$channels, + _t$depth = t.depth, + i = _t$depth === void 0 ? 8 : _t$depth; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + var n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; - return r; - }(); + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; - function s(t) { - var e = t.length; + case 3: + n.colorType = mi.TRUECOLOUR; + break; - for (; --e >= 0;) { - t[e] = 0; - } - } + case 1: + n.colorType = mi.GREYSCALE; + break; - var a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), - o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), - h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), - l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), - d = new Array(576); - s(d); + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + e = _ref.colorType, + i = _ref.channels, + n = _ref.depth, + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; - var _ = new Array(60); + this._colorType = e; + var s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + }, { + key: "writeCrc", + value: function writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + }]); - s(_); - var f = new Array(512); - s(f); - var c = new Array(256); - s(c); - var u = new Array(29); - s(u); - var w = new Array(30); + return Ci; + }(r); - function p(t, e, i, n, r) { - this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); } - var g, b, m; + function Ii(t, e, i, n) { + for (var _r8 = 0; _r8 < i; _r8++) { + e.writeByte(t[n++]); + } - function k(t, e) { - this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + return n; } - s(w); + function Si(t, e, i, n) { + for (var _r9 = 0; _r9 < i; _r9++) { + e.writeUint16(t[n++]); + } - var y = function y(t) { - return t < 256 ? f[t] : f[256 + (t >>> 7)]; - }, - v = function v(t, e) { - t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; - }, - E = function E(t, e, i) { - t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); - }, - A = function A(t, e, i) { - E(t, i[2 * e], i[2 * e + 1]); - }, - x = function x(t, e) { - var i = 0; + return n; + } - do { - i |= 1 & t, t >>>= 1, i <<= 1; - } while (--e > 0); + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); - return i >>> 1; + var Fi = function Fi(t, e, i) { + return new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(); }, - U = function U(t, e, i) { - var n = new Array(16); - var r, - s, - a = 0; + Mi = function Mi(t) { + return function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + }; + })(); - for (r = 1; r <= 15; r++) { - n[r] = a = a + i[r - 1] << 1; - } + var r = n.P, + s = n.m; - for (s = 0; s <= e; s++) { - var _e10 = t[2 * s + 1]; - 0 !== _e10 && (t[2 * s] = x(n[_e10]++, _e10)); - } - }, - z = function z(t) { - var e; + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } - for (e = 0; e < 286; e++) { - t.dyn_ltree[2 * e] = 0; - } + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + var s = stringify(o.data, gap, indentation); - for (e = 0; e < 30; e++) { - t.dyn_dtree[2 * e] = 0; + if (__includes(s, '\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; } + } else if (o && 'object' === _typeof(o)) { + var isArray = Array.isArray(o); - for (e = 0; e < 19; e++) { - t.bl_tree[2 * e] = 0; + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; } - t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; - }, - R = function R(t) { - t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; - }, - N = function N(t, e, i, n) { - var r = 2 * e, - s = 2 * i; - return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; - }, - T = function T(t, e, i) { - var n = t.heap[i]; - var r = i << 1; + var _s = '\n'; - for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) { - t.heap[i] = t.heap[r], i = r, r <<= 1; - } + for (var k in o) { + if (Object.hasOwnProperty.call(o, k)) { + _s += __repeatConcat(gap, indentation + 1); - t.heap[i] = n; - }, - O = function O(t, e, i) { - var n, - r, - s, - h, - l = 0; - if (0 !== t.last_lit) do { - n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); - } while (l < t.last_lit); - A(t, 256, e); - }, - L = function L(t, e) { - var i = e.dyn_tree, - n = e.stat_desc.static_tree, - r = e.stat_desc.has_stree, - s = e.stat_desc.elems; - var a, - o, - h, - l = -1; + if (isArray) { + _s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (__includes(k, ': ')) { + _s += stringify(k, gap, indentation + 1); + _s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + _s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } - for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) { - 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + _s += '\n'; + } } - for (; t.heap_len < 2;) { - h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); - } + return _s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } - for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) { - T(t, i, a); - } + function preStringify(object) { + var space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; - h = s; + if (typeof space == 'number') { + gap = __repeatConcat(' ', Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } - do { - a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); - } while (t.heap_len >= 2); + return stringify(object, gap, -1); + } - t.heap[--t.heap_max] = t.heap[1], function (t, e) { - var i = e.dyn_tree, - n = e.max_code, - r = e.stat_desc.static_tree, - s = e.stat_desc.has_stree, - a = e.stat_desc.extra_bits, - o = e.stat_desc.extra_base, - h = e.stat_desc.max_length; + var LineGenerator = function () { + function LineGenerator(lines, indentString, startingLine) { + _classCallCheck(this, LineGenerator); - var l, - d, - _, - f, - c, - u, - w = 0; + this.startingLine = startingLine || 0; + this.lineIndex = -1; + var filteredLines = []; - for (f = 0; f <= 15; f++) { - t.bl_count[f] = 0; - } + for (var i = 0; i < lines.length; i++) { + var trimmedLine = lines[i].trim(); - for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) { - d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); } + } - if (0 !== w) { - do { - for (f = h - 1; 0 === t.bl_count[f];) { - f--; - } - - t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; - } while (w > 0); - - for (f = h; 0 !== f; f--) { - for (d = t.bl_count[f]; 0 !== d;) { - _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); - } - } - } - }(t, e), U(i, l, t.bl_count); - }, - B = function B(t, e, i) { - var n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } - for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) { - r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + _createClass(LineGenerator, [{ + key: "getLineNumber", + value: function getLineNumber() { + return this.startingLine + this.lineIndex; } - }, - C = function C(t, e, i) { - var n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + }, { + key: "nextGroup", + value: function nextGroup() { + var lines = []; + var baseIndent = this.indentLevel(this.lineIndex + 1); - for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) { - if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { - if (o < l) do { - A(t, r, t.bl_tree); - } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); - o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); } - }; + }, { + key: "next", + value: function next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + }, { + key: "peek", + value: function peek() { + return this.getLine(this.lineIndex + 1); + } + }, { + key: "finished", + value: function finished() { + return this.lineIndex == this.lines.length - 1; + } + }, { + key: "getLine", + value: function getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + }, { + key: "findIndentString", + value: function findIndentString() { + for (var _i2 = 0, _this$lines2 = this.lines; _i2 < _this$lines2.length; _i2++) { + var _this$lines2$_i = _this$lines2[_i2], + line = _this$lines2$_i[0]; + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } - var D = !1; + return ''; + } + }, { + key: "indentLevel", + value: function indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + var indentLevel = 0; + var line = this.getLine(index); - var I = function I(t, e, i, n) { - E(t, 0 + (n ? 1 : 0), 3), function (t, e, i, n) { - R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; - }(t, e, i); - }; + while (__startsWithString(line, this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } - var S = { - _tr_init: function _tr_init(t) { - D || (function () { - var t, e, i, n, r; - var s = new Array(16); + return indentLevel; + } + }]); - for (i = 0, n = 0; n < 28; n++) { - for (u[n] = i, t = 0; t < 1 << a[n]; t++) { - c[i++] = n; - } - } + return LineGenerator; + }(); - for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) { - for (w[n] = r, t = 0; t < 1 << o[n]; t++) { - f[r++] = n; - } - } + function getObject(lineGroup, type) { + var object; + lineGroup.indentLevel(); - for (r >>= 7; n < 30; n++) { - for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) { - f[256 + r++] = n; - } - } + while (!lineGroup.finished()) { + var line = lineGroup.next(); + var trimmedLine = line.trim(); + var keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + var typeMatch = trimmedLine.match(/#!([\w<,>]+)/); - for (e = 0; e <= 15; e++) { - s[e] = 0; - } + var key = void 0, + value = void 0, + _type = void 0; - for (t = 0; t <= 143;) { - d[2 * t + 1] = 8, t++, s[8]++; - } + if (__startsWithString(trimmedLine, '"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } - for (; t <= 255;) { - d[2 * t + 1] = 9, t++, s[9]++; - } + if (typeMatch) { + _type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } - for (; t <= 279;) { - d[2 * t + 1] = 7, t++, s[7]++; - } + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (__startsWithString(trimmedLine, '-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } - for (; t <= 287;) { - d[2 * t + 1] = 8, t++, s[8]++; - } + if (value) { + value = getValue(value, _type); + } else { + value = getObject(lineGroup.nextGroup(), _type); + } - for (U(d, 287, s), t = 0; t < 30; t++) { - _[2 * t + 1] = 5, _[2 * t] = x(t, 5); - } + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } - g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); - }(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); - }, - _tr_stored_block: I, - _tr_flush_block: function _tr_flush_block(t, e, i, n) { - var r, - s, - a = 0; - t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = function (t) { - var e, - i = 4093624447; + if (type) { + object = { + type: type, + data: object + }; + } - for (e = 0; e <= 31; e++, i >>>= 1) { - if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; - } + return object; + } - if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + function getValue(value, type) { + value = JSON.parse(value); - for (e = 32; e < 256; e++) { - if (0 !== t.dyn_ltree[2 * e]) return 1; - } + if (type) { + value = { + type: type, + data: value + }; + } - return 0; - }(t)), L(t, t.l_desc), L(t, t.d_desc), a = function (t) { - var e; + return value; + } - for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--) { - } + function parse(str) { + var lines = str.replace(/\t/g, ' ').split('\n'); + var lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } - return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; - }(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), function (t, e, i, n) { - var r; + function deepCopy(obj) { + var newObj; - for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) { - E(t, t.bl_tree[2 * l[r] + 1], 3); - } + if (Array.isArray(obj)) { + newObj = []; - C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); - }(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); - }, - _tr_tally: function _tr_tally(t, e, i) { - return t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1; - }, - _tr_align: function _tr_align(t) { - E(t, 2, 3), A(t, 256, d), function (t) { - 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); - }(t); + for (var _i2 = 0; _i2 < obj.length; _i2++) { + var item = obj[_i2]; + newObj.push(deepCopy(item)); } - }, - Z = function Z(t, e, i, n) { - var r = 65535 & t | 0, - s = t >>> 16 & 65535 | 0, - a = 0; - for (; 0 !== i;) { - a = i > 2e3 ? 2e3 : i, i -= a; - - do { - r = r + e[n++] | 0, s = s + r | 0; - } while (--a); + return newObj; + } - r %= 65521, s %= 65521; - } + if (!!obj && _typeof(obj) === "object") { + newObj = {}; - return r | s << 16 | 0; - }; + var __keys = Object.keys(obj); - var F = new Uint32Array(function () { - var t, - e = []; + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = deepCopy(value); + } - for (var i = 0; i < 256; i++) { - t = i; + return newObj; + } - for (var n = 0; n < 8; n++) { - t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; - } + return obj; + } - e[i] = t; - } + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; - return e; - }()); + default: + return false; + } + } - var M = function M(t, e, i, n) { - var r = F, - s = n + i; - t ^= -1; + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; - for (var _i5 = n; _i5 < s; _i5++) { - t = t >>> 8 ^ r[255 & (t ^ e[_i5])]; - } + default: + return false; + } + } - return -1 ^ t; - }, - P = { - 2: "need dictionary", - 1: "stream end", - 0: "", - "-1": "file error", - "-2": "stream error", - "-3": "data error", - "-4": "insufficient memory", - "-5": "buffer error", - "-6": "incompatible version" - }, - H = { - Z_NO_FLUSH: 0, - Z_PARTIAL_FLUSH: 1, - Z_SYNC_FLUSH: 2, - Z_FULL_FLUSH: 3, - Z_FINISH: 4, - Z_BLOCK: 5, - Z_TREES: 6, - Z_OK: 0, - Z_STREAM_END: 1, - Z_NEED_DICT: 2, - Z_ERRNO: -1, - Z_STREAM_ERROR: -2, - Z_DATA_ERROR: -3, - Z_MEM_ERROR: -4, - Z_BUF_ERROR: -5, - Z_NO_COMPRESSION: 0, - Z_BEST_SPEED: 1, - Z_BEST_COMPRESSION: 9, - Z_DEFAULT_COMPRESSION: -1, - Z_FILTERED: 1, - Z_HUFFMAN_ONLY: 2, - Z_RLE: 3, - Z_FIXED: 4, - Z_DEFAULT_STRATEGY: 0, - Z_BINARY: 0, - Z_TEXT: 1, - Z_UNKNOWN: 2, - Z_DEFLATED: 8 - }; + function convertJsonContentsToXnbNode(raw, readers) { + var extractedImages = []; + var extractedMaps = []; - var W = S._tr_init, - K = S._tr_stored_block, - $ = S._tr_flush_block, - Y = S._tr_tally, - j = S._tr_align, - G = H.Z_NO_FLUSH, - X = H.Z_PARTIAL_FLUSH, - V = H.Z_FULL_FLUSH, - q = H.Z_FINISH, - J = H.Z_BLOCK, - Q = H.Z_OK, - tt = H.Z_STREAM_END, - et = H.Z_STREAM_ERROR, - it = H.Z_DATA_ERROR, - nt = H.Z_BUF_ERROR, - rt = H.Z_DEFAULT_COMPRESSION, - st = H.Z_FILTERED, - at = H.Z_HUFFMAN_ONLY, - ot = H.Z_RLE, - ht = H.Z_FIXED, - dt = H.Z_UNKNOWN, - _t = H.Z_DEFLATED, - ft = 258, - ct = 262, - ut = 103, - wt = 113, - pt = 666, - gt = function gt(t, e) { - return t.msg = P[e], e; - }, - bt = function bt(t) { - return (t << 1) - (t > 4 ? 9 : 0); - }, - mt = function mt(t) { - var e = t.length; + var _recursiveConvert = function recursiveConvert(obj, path) { + var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var reader = readers[index]; - for (; --e >= 0;) { - t[e] = 0; + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; } - }; - - var kt = function kt(t, e, i) { - return (e << t.hash_shift ^ i) & t.hash_mask; - }; - var yt = function yt(t) { - var e = t.state; - var i = e.pending; - i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); - }, - vt = function vt(t, e) { - $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); - }, - Et = function Et(t, e) { - t.pending_buf[t.pending++] = e; - }, - At = function At(t, e) { - t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; - }, - xt = function xt(t, e, i, n) { - var r = t.avail_in; - return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); - }, - Ut = function Ut(t, e) { - var i, - n, - r = t.max_chain_length, - s = t.strstart, - a = t.prev_length, - o = t.nice_match; - var h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, - l = t.window, - d = t.w_mask, - _ = t.prev, - f = t.strstart + ft; - var c = l[s + a - 1], - u = l[s + a]; - t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } - do { - if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { - s += 2, i++; + if (__startsWithString(reader, 'Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } - do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } - if (n = ft - (f - s), s = f - ft, n > a) { - if (t.match_start = e, a = n, n >= o) break; - c = l[s + a - 1], u = l[s + a]; - } + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); } - } while ((e = _[e & d]) > h && 0 != --r); - return a <= t.lookahead ? a : t.lookahead; - }, - zt = function zt(t) { - var e = t.w_size; - var i, n, r, s, a; + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } - do { - if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { - t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + var data; + if (Array.isArray(obj)) data = [];else data = {}; + var traversed = index; + var first = true; + var isComplex = !__startsWithString(reader, "Dictionary") && !__startsWithString(reader, "Array") && !__startsWithString(reader, "List"); - do { - r = t.head[--i], t.head[i] = r >= e ? r - e : 0; - } while (--n); + var __keys = Object.keys(obj); - n = e, i = n; + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i]; + obj[key]; + var newIndex = void 0; + if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; - do { - r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; - } while (--n); + var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted = _recursiveConvert2.converted, + nexter = _recursiveConvert2.traversed; - s += e; + data[key] = _converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; } + } - if (0 === t.strm.avail_in) break; - if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));) { - } - } while (t.lookahead < ct && 0 !== t.strm.avail_in); - }, - Rt = function Rt(t, e) { - var i, n; + return { + converted: { + type: reader, + data: data + }, + traversed: traversed + }; + }(raw, []), + converted = _recursiveConvert.converted; - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + return { + converted: converted, + extractedImages: extractedImages, + extractedMaps: extractedMaps + }; + } - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { - if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { - t.match_length--; + function convertJsonContentsFromXnbNode(obj) { + if (!obj || _typeof(obj) !== "object") return obj; - do { - t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; - } while (0 != --t.match_length); + if (_typeof(obj) === "object" && obj.hasOwnProperty("data")) { + var _obj = obj, + type = _obj.type, + data = _obj.data; + if (isPrimitiveReaderType(type)) return deepCopy(data); - t.strstart++; - } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); - } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; - if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; } - return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }, - Nt = function Nt(t, e) { - var i, n, r; - - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + obj = deepCopy(data); + } - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { - r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + var newObj; - do { - ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); - } while (0 != --t.prev_length); + if (Array.isArray(obj)) { + newObj = []; - if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } else if (t.match_available) { - if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; - } else t.match_available = 1, t.strstart++, t.lookahead--; + for (var _i4 = 0, _obj3 = obj; _i4 < _obj3.length; _i4++) { + var item = _obj3[_i4]; + newObj.push(convertJsonContentsFromXnbNode(item)); } - return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }; - - function Tt(t, e, i, n, r) { - this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + return newObj; } - var Ot = [new Tt(0, 0, 0, 0, function (t, e) { - var i = 65535; - - for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { - if (t.lookahead <= 1) { - if (zt(t), 0 === t.lookahead && e === G) return 1; - if (0 === t.lookahead) break; - } - - t.strstart += t.lookahead, t.lookahead = 0; + if (!!obj && _typeof(obj) === "object") { + newObj = {}; - var _n2 = t.block_start + i; + var __keys = Object.keys(obj); - if ((0 === t.strstart || t.strstart >= _n2) && (t.lookahead = t.strstart - _n2, t.strstart = _n2, vt(t, !1), 0 === t.strm.avail_out)) return 1; - if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = convertJsonContentsFromXnbNode(value); } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); - }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; - - function Lt() { - this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + return newObj; } - var Bt = function Bt(t) { - if (!t || !t.state) return gt(t, et); - t.total_in = t.total_out = 0, t.data_type = dt; - var e = t.state; - return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; - }, - Ct = function Ct(t) { - var e = Bt(t); - var i; - return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; - }, - Dt = function Dt(t, e, i, n, r, s) { - if (!t) return et; - var a = 1; - if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); - 8 === n && (n = 9); - var o = new Lt(); - return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + return null; + } + + function toXnbNodeData(json) { + var toYamlJson = {}; + var _json$header = json.header, + compressed = _json$header.compressed; + _json$header.formatVersion; + var hiDef = _json$header.hidef, + target = _json$header.target; + var readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target: target, + compressed: !!compressed, + hiDef: hiDef, + readerData: readerData, + numSharedResources: 0 }; + var rawContent = deepCopy(json.content); + var mainReader = TypeReader.simplifyType(readerData[0].type); + var readersTypeList = TypeReader.getReaderTypeList(mainReader); - var It = Dt, - St = function St(t, e) { - return t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et; - }, - Zt = function Zt(t, e) { - var i, n; - if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; - var r = t.state; - if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); - r.strm = t; - var s = r.last_flush; - if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { - var _e11 = _t + (r.w_bits - 8 << 4) << 8, - _i6 = -1; + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } - _i6 = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, _e11 |= _i6 << 6, 0 !== r.strstart && (_e11 |= 32), _e11 += 31 - _e11 % 31, r.status = wt, At(r, _e11), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; - } - if (69 === r.status) if (r.gzhead.extra) { - for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) { - Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; - } + var _convertJsonContentsT = convertJsonContentsToXnbNode(rawContent, readersTypeList), + converted = _convertJsonContentsT.converted, + extractedImages = _convertJsonContentsT.extractedImages, + extractedMaps = _convertJsonContentsT.extractedMaps; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); - } else r.status = 73; - if (73 === r.status) if (r.gzhead.name) { - i = r.pending; + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + function fromXnbNodeData(json) { + var result = {}; + var _json$xnbData = json.xnbData, + compressed = _json$xnbData.compressed, + readerData = _json$xnbData.readerData, + hidef = _json$xnbData.hiDef, + target = _json$xnbData.target; + result.header = { + target: target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef: hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); - n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); - } else r.status = 91; - if (91 === r.status) if (r.gzhead.comment) { - i = r.pending; + return result; + } - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + function searchElement(parent, element) { + if (!parent || _typeof(parent) != 'object') return; - n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + if (parent.hasOwnProperty(element)) { + return { + parent: parent, + value: parent[element] + }; + } - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); - } else r.status = ut; + var __keys = Object.keys(parent); - if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { - if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; - } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + child = parent[__key]; - if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + if (!!child || _typeof(child) == 'object') { + var found = searchElement(child, element); + if (found) return found; + } + } - if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { - var _i7 = r.strategy === at ? function (t, e) { - var i; + return null; + } - for (;;) { - if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { - if (e === G) return 1; - break; - } + function extractFileName(fullname) { + var matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } - if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }(r, e) : r.strategy === ot ? function (t, e) { - var i, n, r, s; - var a = t.window; + case "yaml": + return "yaml"; - for (;;) { - if (t.lookahead <= ft) { - if (zt(t), t.lookahead <= ft && e === G) return 1; - if (0 === t.lookahead) break; - } + case "Texture2D": + return "png"; - if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { - s = t.strstart + ft; + case "Effect": + return "cso"; - do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + case 'TBin': + return "tbin"; - t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); - } + case 'BmFont': + return "xml"; + } - if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + return "bin"; + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }(r, e) : Ot[r.level].func(r, e); + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; - if (3 !== _i7 && 4 !== _i7 || (r.status = pt), 1 === _i7 || 3 === _i7) return 0 === t.avail_out && (r.last_flush = -1), Q; - if (2 === _i7 && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; - } + case "yaml": + return "text/plain"; - return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); - }, - Ft = function Ft(t) { - if (!t || !t.state) return et; - var e = t.state.status; - return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); - }, - Mt = function Mt(t, e) { - var i = e.length; - if (!t || !t.state) return et; - var n = t.state, - r = n.wrap; - if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + case "Texture2D": + return "image/png"; - if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { - 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + case "Effect": + return "application/x-cso"; - var _t3 = new Uint8Array(n.w_size); + case 'BmFont': + return "application/xml"; + } - _t3.set(e.subarray(i - n.w_size, i), 0), e = _t3, i = n.w_size; - } + return "application/octet-stream"; + } - var s = t.avail_in, - a = t.next_in, - o = t.input; + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } - for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { - var _t4 = n.strstart, - _e12 = n.lookahead - 2; + function exportContent(content) { + var jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var found = searchElement(content, "export"); - do { - n.ins_h = kt(n, n.ins_h, n.window[_t4 + 3 - 1]), n.prev[_t4 & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = _t4, _t4++; - } while (--_e12); + if (found) { + var value = found.value; + var dataType = value.type, + data = value.data; - n.strstart = _t4, n.lookahead = 2, zt(n); + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); } - return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; - }; + return makeBlob(data, dataType); + } - var Pt = function Pt(t, e) { - return Object.prototype.hasOwnProperty.call(t, e); - }; + if (jsonContent) { + var contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } - var Ht = function Ht(t) { - var e = Array.prototype.slice.call(arguments, 1); + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ - for (; e.length;) { - var _i8 = e.shift(); - if (_i8) { - if ("object" != _typeof(_i8)) throw new TypeError(_i8 + "must be non-object"); + function exportFiles(xnbObject) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$yaml = _ref.yaml, + isYaml = _ref$yaml === void 0 ? false : _ref$yaml, + _ref$contentOnly = _ref.contentOnly, + contentOnly = _ref$contentOnly === void 0 ? false : _ref$contentOnly, + _ref$fileName = _ref.fileName, + fileName = _ref$fileName === void 0 ? null : _ref$fileName; - for (var _e13 in _i8) { - Pt(_i8, _e13) && (t[_e13] = _i8[_e13]); - } + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + var blobs = []; + var content = xnbObject.content; + var contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + var resultJSON = JSON.stringify(xnbObject, function (key, value) { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); } - } - return t; - }, - Wt = function Wt(t) { - var e = 0; - - for (var _i9 = 0, _n3 = t.length; _i9 < _n3; _i9++) { - e += t[_i9].length; + return "".concat(value.type, ".").concat(getExtension(value.type)); } - var i = new Uint8Array(e); + return value; + }, 4); + var result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } - for (var _e14 = 0, _n4 = 0, _r2 = t.length; _e14 < _r2; _e14++) { - var _r3 = t[_e14]; - i.set(_r3, _n4), _n4 += _r3.length; - } + function resolveCompression(compressionString) { + var str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } - return i; - }; + function readBlobasText(_x) { + return _readBlobasText.apply(this, arguments); + } - var Kt = !0; + function _readBlobasText() { + _readBlobasText = _asyncToGenerator(regeneratorRuntime.mark(function _callee(blob) { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context.next = 4; + break; + } - try { - String.fromCharCode.apply(null, new Uint8Array(1)); - } catch (t) { - Kt = !1; - } + return _context.abrupt("return", blob.text()); - var $t = new Uint8Array(256); + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context.next = 6; + break; + } - for (var _t5 = 0; _t5 < 256; _t5++) { - $t[_t5] = _t5 >= 252 ? 6 : _t5 >= 248 ? 5 : _t5 >= 240 ? 4 : _t5 >= 224 ? 3 : _t5 >= 192 ? 2 : 1; - } + return _context.abrupt("return", blob.toString()); - $t[254] = $t[254] = 1; + case 6: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _readBlobasText.apply(this, arguments); + } - var Yt = function Yt(t) { - if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); - var e, - i, - n, - r, - s, - a = t.length, - o = 0; + function readBlobasArrayBuffer(_x2) { + return _readBlobasArrayBuffer.apply(this, arguments); + } - for (r = 0; r < a; r++) { - i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - } + function _readBlobasArrayBuffer() { + _readBlobasArrayBuffer = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(blob) { + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context2.next = 4; + break; + } - for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) { - i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); - } + return _context2.abrupt("return", blob.arrayBuffer()); - return e; - }, - jt = function jt(t, e) { - var i = e || t.length; - if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); - var n, r; - var s = new Array(2 * i); + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context2.next = 6; + break; + } - for (r = 0, n = 0; n < i;) { - var _e15 = t[n++]; + return _context2.abrupt("return", blob.buffer); - if (_e15 < 128) { - s[r++] = _e15; - continue; + case 6: + case "end": + return _context2.stop(); + } } + }, _callee2); + })); + return _readBlobasArrayBuffer.apply(this, arguments); + } - var _a = $t[_e15]; - if (_a > 4) s[r++] = 65533, n += _a - 1;else { - for (_e15 &= 2 === _a ? 31 : 3 === _a ? 15 : 7; _a > 1 && n < i;) { - _e15 = _e15 << 6 | 63 & t[n++], _a--; - } + function readExternFiles(_x3, _x4) { + return _readExternFiles.apply(this, arguments); + } - _a > 1 ? s[r++] = 65533 : _e15 < 65536 ? s[r++] = _e15 : (_e15 -= 65536, s[r++] = 55296 | _e15 >> 10 & 1023, s[r++] = 56320 | 1023 & _e15); - } - } + function _readExternFiles() { + _readExternFiles = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(extension, files) { + var rawPng, png, data, _data, _data2; - return function (t, e) { - if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); - var i = ""; + return regeneratorRuntime.wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + if (!(extension === "png")) { + _context3.next = 6; + break; + } - for (var _n5 = 0; _n5 < e; _n5++) { - i += String.fromCharCode(t[_n5]); - } + _context3.next = 3; + return readBlobasArrayBuffer(files.png); - return i; - }(s, r); - }, - Gt = function Gt(t, e) { - (e = e || t.length) > t.length && (e = t.length); - var i = e - 1; + case 3: + rawPng = _context3.sent; + png = r(new Uint8Array(rawPng)); + return _context3.abrupt("return", { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }); - for (; i >= 0 && 128 == (192 & t[i]);) { - i--; - } + case 6: + if (!(extension === "cso")) { + _context3.next = 11; + break; + } - return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; - }, - Xt = function Xt() { - this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; - }; + _context3.next = 9; + return readBlobasArrayBuffer(files.cso); - var Vt = Object.prototype.toString, - qt = H.Z_NO_FLUSH, - Jt = H.Z_SYNC_FLUSH, - Qt = H.Z_FULL_FLUSH, - te = H.Z_FINISH, - ee = H.Z_OK, - ie = H.Z_STREAM_END, - ne = H.Z_DEFAULT_COMPRESSION, - re = H.Z_DEFAULT_STRATEGY, - se = H.Z_DEFLATED; + case 9: + data = _context3.sent; + return _context3.abrupt("return", { + type: "Effect", + data: data + }); - function ae(t) { - this.options = Ht({ - level: ne, - method: se, - chunkSize: 16384, - windowBits: 15, - memLevel: 8, - strategy: re - }, t || {}); - var e = this.options; - e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - var i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); - if (i !== ee) throw new Error(P[i]); + case 11: + if (!(extension === "tbin")) { + _context3.next = 16; + break; + } - if (e.header && St(this.strm, e.header), e.dictionary) { - var _t6; + _context3.next = 14; + return readBlobasArrayBuffer(files.tbin); - if (_t6 = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, _t6), i !== ee) throw new Error(P[i]); - this._dict_set = !0; - } - } + case 14: + _data = _context3.sent; + return _context3.abrupt("return", { + type: "TBin", + data: _data + }); - function oe(t, e) { - var i = new ae(e); - if (i.push(t, !0), i.err) throw i.msg || P[i.err]; - return i.result; - } + case 16: + if (!(extension === "xml")) { + _context3.next = 21; + break; + } - ae.prototype.push = function (t, e) { - var i = this.strm, - n = this.options.chunkSize; - var r, s; - if (this.ended) return !1; + _context3.next = 19; + return readBlobasText(files.xml); - for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { - if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { - if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + case 19: + _data2 = _context3.sent; + return _context3.abrupt("return", { + type: "BmFont", + data: _data2 + }); - if (0 !== i.avail_out) { - if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; - } else this.onData(i.output); + case 21: + case "end": + return _context3.stop(); + } } - } - - return !0; - }, ae.prototype.onData = function (t) { - this.chunks.push(t); - }, ae.prototype.onEnd = function (t) { - t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; + }, _callee3); + })); + return _readExternFiles.apply(this, arguments); + } - var he = { - Deflate: ae, - deflate: oe, - deflateRaw: function deflateRaw(t, e) { - return (e = e || {}).raw = !0, oe(t, e); - }, - gzip: function gzip(t, e) { - return (e = e || {}).gzip = !0, oe(t, e); - }, - constants: H - }, - le = function le(t, e) { - var i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + function resolveImports(_x5) { + return _resolveImports.apply(this, arguments); + } - var U = t.state; - i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + function _resolveImports() { + _resolveImports = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(files) { + var configs, + _configs$compression, + compression, + jsonFile, + rawText, + jsonData, + compressBits, + found, + parent, + value, + _extractFileName, + extension, + _args4 = arguments; - t: do { - c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + return regeneratorRuntime.wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + configs = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}; + _configs$compression = configs.compression, compression = _configs$compression === void 0 ? "default" : _configs$compression; + jsonFile = files.json || files.yaml; - e: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { - if (!(16 & m)) { - if (0 == (64 & m)) { - b = u[(65535 & b) + (f & (1 << m) - 1)]; - continue e; + if (jsonFile) { + _context4.next = 5; + break; } - if (32 & m) { - U.mode = 12; - break t; + throw new XnbError("There is no JSON or YAML file to pack!"); + + case 5: + _context4.next = 7; + return readBlobasText(jsonFile); + + case 7: + rawText = _context4.sent; + jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (jsonData.hasOwnProperty('content')) { + _context4.next = 14; + break; } - t.msg = "invalid literal/length code", U.mode = 30; - break t; - } - - k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); - i: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { - if (0 == (64 & m)) { - b = w[(65535 & b) + (f & (1 << m) - 1)]; - continue i; - } + case 14: + found = searchElement(jsonData.content, "export"); - t.msg = "invalid distance code", U.mode = 30; - break t; + if (!found) { + _context4.next = 21; + break; } - if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + parent = found.parent, value = found.value; + _extractFileName = extractFileName(value), extension = _extractFileName[1]; + _context4.next = 20; + return readExternFiles(extension, files); - if (f >>>= m, c -= m, m = r - s, y > m) { - if (m = y - m, m > l && U.sane) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + case 20: + parent.export = _context4.sent; - if (v = 0, E = _, 0 === d) { - if (v += h - m, m < k) { - k -= m; + case 21: + return _context4.abrupt("return", jsonData); - do { - x[r++] = _[v++]; - } while (--m); + case 22: + case "end": + return _context4.stop(); + } + } + }, _callee4); + })); + return _resolveImports.apply(this, arguments); + } - v = r - y, E = x; - } - } else if (d < m) { - if (v += h + d - m, m -= d, m < k) { - k -= m; + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ - do { - x[r++] = _[v++]; - } while (--m); + function unpackToXnbData(_x) { + return _unpackToXnbData.apply(this, arguments); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ - if (v = 0, d < k) { - m = d, k -= m; - do { - x[r++] = _[v++]; - } while (--m); + function _unpackToXnbData() { + _unpackToXnbData = _asyncToGenerator(regeneratorRuntime.mark(function _callee(file) { + var _extractFileName3, extension, buffer; - v = r - y, E = x; - } - } - } else if (v += d - m, m < k) { - k -= m; + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof window !== "undefined")) { + _context.next = 8; + break; + } - do { - x[r++] = _[v++]; - } while (--m); + _extractFileName3 = extractFileName(file.name), extension = _extractFileName3[1]; - v = r - y, E = x; - } + if (!(extension !== "xnb")) { + _context.next = 4; + break; + } - for (; k > 2;) { - x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; - } + return _context.abrupt("return", new Error("Invalid XNB File!")); - k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); - } else { - v = r - y; + case 4: + _context.next = 6; + return file.arrayBuffer(); - do { - x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; - } while (k > 2); + case 6: + buffer = _context.sent; + return _context.abrupt("return", bufferToXnb(buffer)); - k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); - } + case 8: + return _context.abrupt("return", bufferToXnb(file.buffer)); - break; - } + case 9: + case "end": + return _context.stop(); } - break; } - } while (i < n && r < a); - - k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; - }; - - var de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), - _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), - fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), - ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + }, _callee); + })); + return _unpackToXnbData.apply(this, arguments); + } - var ue = function ue(t, e, i, n, r, s, a, o) { - var h = o.bits; + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ - var l, - d, - _, - f, - c, - u, - w = 0, - p = 0, - g = 0, - b = 0, - m = 0, - k = 0, - y = 0, - v = 0, - E = 0, - A = 0, - x = null, - U = 0; - var z = new Uint16Array(16), - R = new Uint16Array(16); - var N, - T, - O, - L = null, - B = 0; + function unpackToFiles(file) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var _configs$yaml = configs.yaml, + yaml = _configs$yaml === void 0 ? false : _configs$yaml, + _configs$contentOnly = configs.contentOnly, + contentOnly = _configs$contentOnly === void 0 ? false : _configs$contentOnly, + _configs$fileName = configs.fileName, + name = _configs$fileName === void 0 ? null : _configs$fileName; + if (typeof window !== "undefined" && name === null) name = file.name; - for (w = 0; w <= 15; w++) { - z[w] = 0; - } + var _extractFileName = extractFileName(name), + fileName = _extractFileName[0]; - for (p = 0; p < n; p++) { - z[e[i + p]]++; - } + var exporter = function exporter(xnbObject) { + return exportFiles(xnbObject, { + yaml: yaml, + contentOnly: contentOnly, + fileName: fileName + }); + }; - for (m = h, b = 15; b >= 1 && 0 === z[b]; b--) { - } + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ - if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; - for (g = 1; g < b && 0 === z[g]; g++) { - } + function bufferToXnb(buffer) { + var xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ - for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) { - if (v <<= 1, v -= z[w], v < 0) return -1; - } - if (v > 0 && (0 === t || 1 !== b)) return -1; + function bufferToContents(buffer) { + var xnb = new XnbConverter(); + var xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ - for (R[1] = 0, w = 1; w < 15; w++) { - R[w + 1] = R[w] + z[w]; - } - for (p = 0; p < n; p++) { - 0 !== e[i + p] && (a[R[e[i + p]]++] = p); - } + function xnbDataToContent(loadedXnb) { + var content = loadedXnb.content; - if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + var _exportContent = exportContent(content, true), + data = _exportContent.data, + extension = _exportContent.extension; - for (;;) { - N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ - do { - d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; - } while (0 !== d); - for (l = 1 << w - 1; A & l;) { - l >>= 1; - } + function fileMapper(files) { + var returnMap = {}; - if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { - if (w === b) break; - w = e[i + a[p]]; - } + for (var i = 0; i < files.length; i++) { + var file = files[i]; - if (w > m && (A & f) !== _) { - for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) { - k++, v <<= 1; - } + var _extractFileName2 = extractFileName(file.name), + fileName = _extractFileName2[0], + extension = _extractFileName2[1]; - if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; - _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; - } - } + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + var namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } - return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; - }; + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ - var we = H.Z_FINISH, - pe = H.Z_BLOCK, - ge = H.Z_TREES, - be = H.Z_OK, - me = H.Z_STREAM_END, - ke = H.Z_NEED_DICT, - ye = H.Z_STREAM_ERROR, - ve = H.Z_DATA_ERROR, - Ee = H.Z_MEM_ERROR, - Ae = H.Z_BUF_ERROR, - xe = H.Z_DEFLATED, - Ue = 12, - ze = 30, - Re = function Re(t) { - return (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); - }; - function Ne() { - this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; - } + function packJsonToBinary(json) { + var xnb = new XnbConverter(); + var buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ - var Te = function Te(t) { - if (!t || !t.state) return ye; - var e = t.state; - return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; - }, - Oe = function Oe(t) { - if (!t || !t.state) return ye; - var e = t.state; - return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); - }, - Le = function Le(t, e) { - var i; - if (!t || !t.state) return ye; - var n = t.state; - return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); - }, - Be = function Be(t, e) { - if (!t) return ye; - var i = new Ne(); - t.state = i, i.window = null; - var n = Le(t, e); - return n !== be && (t.state = null), n; - }; - var Ce, - De, - Ie = !0; + function pack(files) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var groupedFiles = fileMapper(files); + var promises = []; - var Se = function Se(t) { - if (Ie) { - Ce = new Int32Array(512), De = new Int32Array(32); - var _e16 = 0; + var __keys = Object.keys(groupedFiles); - for (; _e16 < 144;) { - t.lens[_e16++] = 8; - } + for (var __i = 0; __i < __keys.length; __i++) { + var fileName = __keys[__i], + filePack = groupedFiles[fileName]; + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(function (buffer) { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } - for (; _e16 < 256;) { - t.lens[_e16++] = 9; - } + return __promise_allSettled(promises).then(function (blobArray) { + if (configs.debug === true) return blobArray; + return blobArray.filter(function (_ref) { + var status = _ref.status; + _ref.value; + return status === "fulfilled"; + }).map(function (_ref2) { + var value = _ref2.value; + return value; + }); + }); + } - for (; _e16 < 280;) { - t.lens[_e16++] = 7; - } + function setReaders(readers) { + return TypeReader.setReaders(readers); + } - for (; _e16 < 288;) { - t.lens[_e16++] = 8; - } + function addReaders(readers) { + return TypeReader.addReaders(readers); + } - for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { - bits: 9 - }), _e16 = 0; _e16 < 32;) { - t.lens[_e16++] = 5; - } + var BaseReader = function () { + function BaseReader() { + _classCallCheck(this, BaseReader); + } - ue(2, t.lens, 0, 32, De, 0, t.work, { - bits: 5 - }), Ie = !1; + _createClass(BaseReader, [{ + key: "isValueType", + value: function isValueType() { + return true; + } + }, { + key: "type", + get: function get() { + return this.constructor.type(); + } + }, { + key: "read", + value: function read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "writeIndex", + value: function writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(parseInt(resolver.getIndex(this)) + 1); + } + }, { + key: "toString", + value: function toString() { + return this.type; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + return false; + } + }, { + key: "hasSubType", + value: function hasSubType() { + return false; + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type()].concat(subtype); + } + }, { + key: "type", + value: function type() { + return this.name.slice(0, -6); } + }]); - t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; - }, - Ze = function Ze(t, e, i, n) { - var r; - var s = t.state; - return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; - }; + return BaseReader; + }(); - var Fe = Oe, - Me = Be, - Pe = function Pe(t, e) { - var i, - n, - r, - s, - a, - o, - h, - l, - d, - _, - f, - c, - u, - w, - p, - g, - b, - m, - k, - y, - v, - E, - A = 0; + var UInt32Reader = function (_BaseReader) { + _inherits(UInt32Reader, _BaseReader); - var x = new Uint8Array(4); - var U, z; - var R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; - i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + var _super = _createSuper(UInt32Reader); - t: for (;;) { - switch (i.mode) { - case 1: - if (0 === i.wrap) { - i.mode = 13; - break; - } + function UInt32Reader() { + _classCallCheck(this, UInt32Reader); - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return _super.apply(this, arguments); + } - if (2 & i.wrap && 35615 === l) { - i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; - break; - } + _createClass(UInt32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readUInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; - if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { - t.msg = "incorrect header check", i.mode = ze; - break; - } + default: + return false; + } + } + }]); - if ((15 & l) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + return UInt32Reader; + }(BaseReader); - if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { - t.msg = "invalid window size", i.mode = ze; - break; - } - i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; - break; + var ArrayReader = function (_BaseReader) { + _inherits(ArrayReader, _BaseReader); - case 2: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var _super = _createSuper(ArrayReader); - if (i.flags = l, (255 & i.flags) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + function ArrayReader(reader) { + var _this; - if (57344 & i.flags) { - t.msg = "unknown header flags set", i.mode = ze; - break; - } + _classCallCheck(this, ArrayReader); - i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + _this = _super.call(this); + _this.reader = reader; + return _this; + } - case 3: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + _createClass(ArrayReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var array = []; - i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } - case 4: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return array; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); - i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + for (var i = 0; i < content.length; i++) { + this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Array<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; - case 5: - if (1024 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); - i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; - } else i.head && (i.head.extra = null); + return ArrayReader; + }(BaseReader); - i.mode = 6; + var UTF16_BITES = [0xD800, 0xDC00]; + var UTF16_MASK = 1023; - case 6: - if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; - i.length = 0, i.mode = 7; + function UTF16Decode(codeSet) { + var _codeSet2; - case 7: - if (2048 & i.flags) { - if (0 === o) break t; - c = 0; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); - } while (v && c < o); + function stringToUnicode(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.name = null); + var result = []; + var index = 0; - i.length = 0, i.mode = 8; + while (index < str.length) { + var code = utf16Map[index]; - case 8: - if (4096 & i.flags) { - if (0 === o) break t; - c = 0; + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); - } while (v && c < o); + return result; + } - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.comment = null); + function UTF8Length(str) { + var codes = stringToUnicode(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } - i.mode = 9; + var StringReader = function (_BaseReader) { + _inherits(StringReader, _BaseReader); - case 9: - if (512 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var _super = _createSuper(StringReader); - if (l !== (65535 & i.check)) { - t.msg = "header crc mismatch", i.mode = ze; - break; - } + function StringReader() { + _classCallCheck(this, StringReader); - l = 0, d = 0; - } + return _super.apply(this, arguments); + } - i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; - break; + _createClass(StringReader, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + var size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; - case 10: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + default: + return false; + } + } + }]); - t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + return StringReader; + }(BaseReader); - case 11: - if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; - t.adler = i.check = 1, i.mode = Ue; + var BmFontReader = function (_BaseReader) { + _inherits(BmFontReader, _BaseReader); - case Ue: - if (e === pe || e === ge) break t; + var _super = _createSuper(BmFontReader); - case 13: - if (i.last) { - l >>>= 7 & d, d -= 7 & d, i.mode = 27; - break; - } + function BmFontReader() { + _classCallCheck(this, BmFontReader); - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return _super.apply(this, arguments); + } - switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { - case 0: - i.mode = 14; - break; + _createClass(BmFontReader, [{ + key: "read", + value: function read(buffer) { + var stringReader = new StringReader(); + var xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; - case 1: - if (Se(i), i.mode = 20, e === ge) { - l >>>= 2, d -= 2; - break t; - } + default: + return false; + } + } + }]); - break; + return BmFontReader; + }(BaseReader); - case 2: - i.mode = 17; - break; + var BooleanReader = function (_BaseReader) { + _inherits(BooleanReader, _BaseReader); - case 3: - t.msg = "invalid block type", i.mode = ze; - } + var _super = _createSuper(BooleanReader); - l >>>= 2, d -= 2; - break; + function BooleanReader() { + _classCallCheck(this, BooleanReader); - case 14: - for (l >>>= 7 & d, d -= 7 & d; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return _super.apply(this, arguments); + } - if ((65535 & l) != (l >>> 16 ^ 65535)) { - t.msg = "invalid stored block lengths", i.mode = ze; - break; - } + _createClass(BooleanReader, [{ + key: "read", + value: function read(buffer) { + return Boolean(buffer.readInt()); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; - if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + default: + return false; + } + } + }]); - case 15: - i.mode = 16; + return BooleanReader; + }(BaseReader); - case 16: - if (c = i.length, c) { - if (c > o && (c = o), c > h && (c = h), 0 === c) break t; - r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; - break; - } + var CharReader = function (_BaseReader) { + _inherits(CharReader, _BaseReader); - i.mode = Ue; - break; + var _super = _createSuper(CharReader); - case 17: - for (; d < 14;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + function CharReader() { + _classCallCheck(this, CharReader); - if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { - t.msg = "too many length or distance symbols", i.mode = ze; - break; - } + return _super.apply(this, arguments); + } - i.have = 0, i.mode = 18; + _createClass(CharReader, [{ + key: "read", + value: function read(buffer) { + var charSize = this._getCharSize(buffer.peekInt()); - case 18: - for (; i.have < i.ncode;) { - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return buffer.readString(charSize); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + }, { + key: "_getCharSize", + value: function _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; - i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; - } + default: + return false; + } + } + }]); - for (; i.have < 19;) { - i.lens[R[i.have++]] = 0; - } + return CharReader; + }(BaseReader); - if (i.lencode = i.lendyn, i.lenbits = 7, U = { - bits: i.lenbits - }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid code lengths set", i.mode = ze; - break; - } + var DictionaryReader = function (_BaseReader) { + _inherits(DictionaryReader, _BaseReader); - i.have = 0, i.mode = 19; + var _super = _createSuper(DictionaryReader); - case 19: - for (; i.have < i.nlen + i.ndist;) { - for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + function DictionaryReader(key, value) { + var _this; - if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { - if (16 === b) { - for (z = p + 2; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + _classCallCheck(this, DictionaryReader); - if (l >>>= p, d -= p, 0 === i.have) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + _this = _super.call(this); + _this.key = key; + _this.value = value; + return _this; + } - v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; - } else if (17 === b) { - for (z = p + 3; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + _createClass(DictionaryReader, [{ + key: "read", + value: function read(buffer, resolver) { + var dictionary = {}; + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); - l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; - } else { - for (z = p + 7; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (var i = 0; i < size; i++) { + var key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + var value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } - l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; - } + return dictionary; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); - if (i.have + c > i.nlen + i.ndist) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + for (var _i2 = 0, _Object$keys2 = Object.keys(content); _i2 < _Object$keys2.length; _i2++) { + var key = _Object$keys2[_i2]; + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); - for (; c--;) { - i.lens[i.have++] = v; - } - } - } + return DictionaryReader; + }(BaseReader); - if (i.mode === ze) break; + var DoubleReader = function (_BaseReader) { + _inherits(DoubleReader, _BaseReader); - if (0 === i.lens[256]) { - t.msg = "invalid code -- missing end-of-block", i.mode = ze; - break; - } + var _super = _createSuper(DoubleReader); - if (i.lenbits = 9, U = { - bits: i.lenbits - }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid literal/lengths set", i.mode = ze; - break; - } + function DoubleReader() { + _classCallCheck(this, DoubleReader); - if (i.distbits = 6, i.distcode = i.distdyn, U = { - bits: i.distbits - }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { - t.msg = "invalid distances set", i.mode = ze; - break; - } + return _super.apply(this, arguments); + } - if (i.mode = 20, e === ge) break t; + _createClass(DoubleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readDouble(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; - case 20: - i.mode = 21; + default: + return false; + } + } + }]); - case 21: - if (o >= 6 && h >= 258) { - t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); - break; - } + return DoubleReader; + }(BaseReader); - for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var EffectReader = function (_BaseReader) { + _inherits(EffectReader, _BaseReader); - if (g && 0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var _super = _createSuper(EffectReader); - l >>>= m, d -= m, i.back += m; - } + function EffectReader() { + _classCallCheck(this, EffectReader); - if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { - i.mode = 26; - break; - } + return _super.apply(this, arguments); + } - if (32 & g) { - i.back = -1, i.mode = Ue; - break; - } + _createClass(EffectReader, [{ + key: "read", + value: function read(buffer) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; - if (64 & g) { - t.msg = "invalid literal/length code", i.mode = ze; - break; - } + default: + return false; + } + } + }]); - i.extra = 15 & g, i.mode = 22; + return EffectReader; + }(BaseReader); - case 22: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var Int32Reader = function (_BaseReader) { + _inherits(Int32Reader, _BaseReader); - i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + var _super = _createSuper(Int32Reader); - i.was = i.length, i.mode = 23; + function Int32Reader() { + _classCallCheck(this, Int32Reader); - case 23: - for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return _super.apply(this, arguments); + } - if (0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + _createClass(Int32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; - l >>>= m, d -= m, i.back += m; - } + default: + return false; + } + } + }]); - if (l >>>= p, d -= p, i.back += p, 64 & g) { - t.msg = "invalid distance code", i.mode = ze; - break; - } + return Int32Reader; + }(BaseReader); - i.offset = b, i.extra = 15 & g, i.mode = 24; + var ListReader = function (_BaseReader) { + _inherits(ListReader, _BaseReader); - case 24: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + var _super = _createSuper(ListReader); - i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + function ListReader(reader) { + var _this; - if (i.offset > i.dmax) { - t.msg = "invalid distance too far back", i.mode = ze; - break; - } + _classCallCheck(this, ListReader); - i.mode = 25; + _this = _super.call(this); + _this.reader = reader; + return _this; + } - case 25: - if (0 === h) break t; + _createClass(ListReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var list = []; - if (c = f - h, i.offset > c) { - if (c = i.offset - c, c > i.whave && i.sane) { - t.msg = "invalid distance too far back", i.mode = ze; - break; - } + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } - c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; - } else w = r, u = a - i.offset, c = i.length; + return list; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); - c > h && (c = h), h -= c, i.length -= c; + var __keys = Object.keys(content); - do { - r[a++] = w[u++]; - } while (--c); + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + data = content[__key]; + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "List<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; - 0 === i.length && (i.mode = 21); - break; + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); - case 26: - if (0 === h) break t; - r[a++] = i.length, h--, i.mode = 21; - break; + return ListReader; + }(BaseReader); - case 27: - if (i.wrap) { - for (; d < 32;) { - if (0 === o) break t; - o--, l |= n[s++] << d, d += 8; - } + var NullableReader = function (_BaseReader) { + _inherits(NullableReader, _BaseReader); - if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { - t.msg = "incorrect data check", i.mode = ze; - break; - } + var _super = _createSuper(NullableReader); - l = 0, d = 0; - } + function NullableReader(reader) { + var _this; - i.mode = 28; + _classCallCheck(this, NullableReader); - case 28: - if (i.wrap && i.flags) { - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + _this = _super.call(this); + _this.reader = reader; + return _this; + } - if (l !== (4294967295 & i.total)) { - t.msg = "incorrect length check", i.mode = ze; - break; - } + _createClass(NullableReader, [{ + key: "read", + value: function read(buffer) { + var resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var booleanReader = new BooleanReader(); + var hasValue = buffer.peekByte(1); - l = 0, d = 0; - } + if (!hasValue) { + booleanReader.read(buffer); + return null; + } - i.mode = 29; + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } - case 29: - E = me; - break t; + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } + }, { + key: "write", + value: function write(buffer) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + new BooleanReader(); - case ze: - E = ve; - break t; + if (content !== null) { + buffer.writeByte(0); + return; + } - case 31: - return Ee; + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Nullable<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; default: - return ye; + return false; } } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); - return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; - }, - He = function He(t) { - if (!t || !t.state) return ye; - var e = t.state; - return e.window && (e.window = null), t.state = null, be; - }, - We = function We(t, e) { - if (!t || !t.state) return ye; - var i = t.state; - return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); - }, - Ke = function Ke(t, e) { - var i = e.length; - var n, r, s; - return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; - }, - $e = function $e() { - this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; - }; + return NullableReader; + }(BaseReader); - var Ye = Object.prototype.toString, - je = H.Z_NO_FLUSH, - Ge = H.Z_FINISH, - Xe = H.Z_OK, - Ve = H.Z_STREAM_END, - qe = H.Z_NEED_DICT, - Je = H.Z_STREAM_ERROR, - Qe = H.Z_DATA_ERROR, - ti = H.Z_MEM_ERROR; + var ReflectiveReader = function (_BaseReader) { + _inherits(ReflectiveReader, _BaseReader); - function ei(t) { - this.options = Ht({ - chunkSize: 65536, - windowBits: 15, - to: "" - }, t || {}); - var e = this.options; - e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - var i = Me(this.strm, e.windowBits); - if (i !== Xe) throw new Error(P[i]); - if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); - } + var _super = _createSuper(ReflectiveReader); - function ii(t, e) { - var i = new ei(e); - if (i.push(t), i.err) throw i.msg || P[i.err]; - return i.result; - } + function ReflectiveReader(reader) { + var _this; - ei.prototype.push = function (t, e) { - var i = this.strm, - n = this.options.chunkSize, - r = this.options.dictionary; - var s, a, o; - if (this.ended) return !1; + _classCallCheck(this, ReflectiveReader); - for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { - for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) { - Fe(i), s = Pe(i, a); - } + _this = _super.call(this); + _this.reader = reader; + return _this; + } - switch (s) { - case Je: - case Qe: - case qe: - case ti: - return this.onEnd(s), this.ended = !0, !1; + _createClass(ReflectiveReader, [{ + key: "read", + value: function read(buffer, resolver) { + var reflective = this.reader.read(buffer, resolver); + return reflective; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "".concat(this.reader.type); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); - if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { - var _t7 = Gt(i.output, i.next_out), - _e17 = i.next_out - _t7, - _r4 = jt(i.output, _t7); + return ReflectiveReader; + }(BaseReader); - i.next_out = _e17, i.avail_out = n - _e17, _e17 && i.output.set(i.output.subarray(_t7, _t7 + _e17), 0), this.onData(_r4); - } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + var RectangleReader = function (_BaseReader) { + _inherits(RectangleReader, _BaseReader); - if (s !== Xe || 0 !== o) { - if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; - if (0 === i.avail_in) break; - } - } + var _super = _createSuper(RectangleReader); - return !0; - }, ei.prototype.onData = function (t) { - this.chunks.push(t); - }, ei.prototype.onEnd = function (t) { - t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; - var ni = { - Inflate: ei, - inflate: ii, - inflateRaw: function inflateRaw(t, e) { - return (e = e || {}).raw = !0, ii(t, e); - }, - ungzip: ii, - constants: H - }; - var si = he.deflate, - hi = ni.Inflate, - li = ni.inflate; - var fi = si, - ci = hi, - ui = li; - var wi = [137, 80, 78, 71, 13, 10, 26, 10], - pi = []; + function RectangleReader() { + _classCallCheck(this, RectangleReader); - for (var _t8 = 0; _t8 < 256; _t8++) { - var _e18 = _t8; + return _super.apply(this, arguments); + } - for (var _t9 = 0; _t9 < 8; _t9++) { - 1 & _e18 ? _e18 = 3988292384 ^ _e18 >>> 1 : _e18 >>>= 1; + _createClass(RectangleReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var x = int32Reader.read(buffer); + var y = int32Reader.read(buffer); + var width = int32Reader.read(buffer); + var height = int32Reader.read(buffer); + return { + x: x, + y: y, + width: width, + height: height + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; - pi[_t8] = _e18; - } + default: + return false; + } + } + }]); - var gi = 4294967295; + return RectangleReader; + }(BaseReader); - function bi(t, e) { - return (function (t, e, i) { - var n = 4294967295; + var SingleReader = function (_BaseReader) { + _inherits(SingleReader, _BaseReader); - for (var _t10 = 0; _t10 < i; _t10++) { - n = pi[255 & (n ^ e[_t10])] ^ n >>> 8; - } + var _super = _createSuper(SingleReader); - return n; - }(0, t, e) ^ gi) >>> 0; + function SingleReader() { + _classCallCheck(this, SingleReader); + + return _super.apply(this, arguments); } - var mi, ki, yi, vi; - !function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; - }(mi || (mi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; - }(ki || (ki = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; - }(yi || (yi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; - }(vi || (vi = {})); - var Ei = new Uint8Array(0), - Ai = new Uint16Array([255]), - xi = 255 === new Uint8Array(Ai.buffer)[0]; + _createClass(SingleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readSingle(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; - var Ui = function (_r5) { - _inherits(Ui, _r5); + default: + return false; + } + } + }]); - var _super = _createSuper(Ui); + return SingleReader; + }(BaseReader); - function Ui(t) { - var _this; + var kDxt1 = 1 << 0; + var kDxt3 = 1 << 1; + var kDxt5 = 1 << 2; + var kColourIterativeClusterFit = 1 << 8; + var kColourClusterFit = 1 << 3; + var kColourRangeFit = 1 << 4; + var kColourMetricPerceptual = 1 << 5; + var kColourMetricUniform = 1 << 6; + var kWeightColourByAlpha = 1 << 7; - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + function Rot(theta) { + var Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } - _classCallCheck(this, Ui); + function Rij(k, l, theta, N) { + var Mat = Array(N); - _this = _super.call(this, t); - var _e$checkCrc = e.checkCrc, - i = _e$checkCrc === void 0 ? !1 : _e$checkCrc; - _this._checkCrc = i, _this._inflator = new ci(), _this._png = { - width: -1, - height: -1, - channels: -1, - data: new Uint8Array(0), - depth: 1, - text: {} - }, _this._end = !1, _this._hasPalette = !1, _this._palette = [], _this._compressionMethod = ki.UNKNOWN, _this._filterMethod = yi.UNKNOWN, _this._interlaceMethod = vi.UNKNOWN, _this._colorType = -1, _this.setBigEndian(); - return _this; + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i = 0; _i < N; _i++) { + for (var j = 0; j < N; j++) { + Mat[_i][j] = (_i === j) * 1.0; } + } - _createClass(Ui, [{ - key: "decode", - value: function decode() { - for (this.decodeSignature(); !this._end;) { - this.decodeChunk(); - } + var Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } - return this.decodeImage(), this._png; - } - }, { - key: "decodeSignature", - value: function decodeSignature() { - for (var _t11 = 0; _t11 < wi.length; _t11++) { - if (this.readUint8() !== wi[_t11]) throw new Error("wrong PNG signature. Byte at ".concat(_t11, " should be ").concat(wi[_t11], ".")); - } - } - }, { - key: "decodeChunk", - value: function decodeChunk() { - var t = this.readUint32(), - e = this.readChars(4), - i = this.offset; + function getTheta(aii, ajj, aij) { + var th = 0.0; + var denom = ajj - aii; - switch (e) { - case "IHDR": - this.decodeIHDR(); - break; + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } - case "PLTE": - this.decodePLTE(t); - break; + return th; + } - case "IDAT": - this.decodeIDAT(t); - break; + function getAij(Mij) { + var N = Mij.length; + var maxMij = 0.0; + var maxIJ = [0, 1]; - case "IEND": - this._end = !0; - break; + for (var i = 0; i < N; i++) { + for (var j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } - case "tRNS": - this.decodetRNS(t); - break; + return [maxIJ, maxMij]; + } - case "iCCP": - this.decodeiCCP(t); - break; + function unitary(U, H) { + var N = U.length; + var Mat = Array(N); - case "tEXt": - this.decodetEXt(t); - break; + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } - case "pHYs": - this.decodepHYs(); - break; + for (var _i2 = 0; _i2 < N; _i2++) { + for (var j = 0; j < N; j++) { + Mat[_i2][j] = 0; - default: - this.skip(t); + for (var k = 0; k < N; k++) { + for (var l = 0; l < N; l++) { + Mat[_i2][j] = Mat[_i2][j] + U[k][_i2] * H[k][l] * U[l][j]; } + } + } + } - if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + return Mat; + } - if (this._checkCrc) { - var _i10 = this.readUint32(), - _n6 = t + 4, - _r6 = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - _n6 - 4, _n6), _n6); + function AxB(A, B) { + var N = A.length; + var Mat = Array(N); - if (_r6 !== _i10) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(_i10, ", found ").concat(_r6)); - } else this.skip(4); - } - }, { - key: "decodeIHDR", - value: function decodeIHDR() { - var t = this._png; - t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { - if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); - return t; - }(this.readUint8()); - var e = this.readUint8(); - var i; + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } - switch (this._colorType = e, e) { - case mi.GREYSCALE: - i = 1; - break; + for (var _i3 = 0; _i3 < N; _i3++) { + for (var j = 0; j < N; j++) { + Mat[_i3][j] = 0; - case mi.TRUECOLOUR: - i = 3; - break; + for (var k = 0; k < N; k++) { + Mat[_i3][j] = Mat[_i3][j] + A[_i3][k] * B[k][j]; + } + } + } - case mi.INDEXED_COLOUR: - i = 1; - break; + return Mat; + } - case mi.GREYSCALE_ALPHA: - i = 2; - break; + function eigens(Hij) { + var convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + var N = Hij.length; + var Ei = Array(N); + var e0 = Math.abs(convergence / N); + var Sij = Array(N); - case mi.TRUECOLOUR_ALPHA: - i = 4; - break; + for (var i = 0; i < N; i++) { + Sij[i] = Array(N); + } - default: - throw new Error("Unknown color type: ".concat(e)); - } + for (var _i4 = 0; _i4 < N; _i4++) { + for (var j = 0; j < N; j++) { + Sij[_i4][j] = (_i4 === j) * 1.0; + } + } + + var Vab = getAij(Hij); - if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); - this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); - } - }, { - key: "decodePLTE", - value: function decodePLTE(t) { - if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); - var e = t / 3; - this._hasPalette = !0; - var i = []; - this._palette = i; + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + var _i5 = Vab[0][0]; + var _j = Vab[0][1]; + var psi = getTheta(Hij[_i5][_i5], Hij[_j][_j], Hij[_i5][_j]); + var Gij = Rij(_i5, _j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } - for (var _t12 = 0; _t12 < e; _t12++) { - i.push([this.readUint8(), this.readUint8(), this.readUint8()]); - } - } - }, { - key: "decodeIDAT", - value: function decodeIDAT(t) { - this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); - } - }, { - key: "decodetRNS", - value: function decodetRNS(t) { - if (3 === this._colorType) { - if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); - var _e19 = 0; + for (var _i6 = 0; _i6 < N; _i6++) { + Ei[_i6] = Hij[_i6][_i6]; + } - for (; _e19 < t; _e19++) { - var _t13 = this.readByte(); + return sorting(Ei, Sij); + } - this._palette[_e19].push(_t13); - } + function sorting(values, vectors) { + var eigsCount = values.length; + vectors.length; - for (; _e19 < this._palette.length; _e19++) { - this._palette[_e19].push(255); - } - } - } - }, { - key: "decodeiCCP", - value: function decodeiCCP(t) { - var e, - i = ""; + var pairs = __arrayMaker({ + length: eigsCount + }, function (_, i) { + var vector = vectors.map(function (v) { + return v[i]; + }); + return { + value: values[i], + vec: vector + }; + }); - for (; "\0" !== (e = this.readChar());) { - i += e; - } + pairs.sort(function (a, b) { + return b.value - a.value; + }); + var sortedValues = pairs.map(function (_ref) { + var value = _ref.value; + return value; + }); + var sortedVectors = pairs.map(function (_ref2) { + var vec = _ref2.vec; + return vec; + }); + return [sortedValues, sortedVectors]; + } - var n = this.readUint8(); - if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); - var r = this.readBytes(t - i.length - 2); - this._png.iccEmbeddedProfile = { - name: i, - profile: ui(r) - }; - } - }, { - key: "decodetEXt", - value: function decodetEXt(t) { - var e, - i = ""; + function dominentPrincipalVector(matrix) { + var _eigens = eigens(matrix), + _eigens$ = _eigens[1], + dominentVector = _eigens$[0]; - for (; "\0" !== (e = this.readChar());) { - i += e; - } + return dominentVector; + } - this._png.text[i] = this.readChars(t - i.length - 1); - } - }, { - key: "decodepHYs", - value: function decodepHYs() { - var t = this.readUint32(), - e = this.readUint32(), - i = this.readByte(); - this._png.resolution = { - x: t, - y: e, - unit: i - }; - } - }, { - key: "decodeImage", - value: function decodeImage() { - if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); - var t = this._inflator.result; - if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); - if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); - this.decodeInterlaceNull(t); - } - }, { - key: "decodeInterlaceNull", - value: function decodeInterlaceNull(t) { - var e = this._png.height, - i = this._png.channels * this._png.depth / 8, - n = this._png.width * i, - r = new Uint8Array(this._png.height * n); - var s, - a, - o = Ei, - h = 0; + var Vec3 = function () { + function Vec3() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - for (var _l = 0; _l < e; _l++) { - switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(_l * n, (_l + 1) * n), t[h]) { - case 0: - zi(s, a, n); - break; + _classCallCheck(this, Vec3); - case 1: - Ri(s, a, n, i); - break; + this._values = [x, y, z]; + } - case 2: - Ni(s, a, o, n); - break; + _createClass(Vec3, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + }, { + key: "colorInt", + get: function get() { + var floatToInt = function floatToInt(value) { + var result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + }, { + key: "clone", + value: function clone() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + }, { + key: "toVec4", + value: function toVec4() { + var w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; - case 3: - Ti(s, a, o, n, i); - break; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; - case 4: - Oi(s, a, o, n, i); - break; + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; - default: - throw new Error("Unsupported filter: ".concat(t[h])); - } + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + }, { + key: "toString", + value: function toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec3.multScalar(a, 1 - p); + var b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + }]); - o = a, h += n + 1; - } + return Vec3; + }(); - if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { - var _t14 = new Uint16Array(r.buffer); + var Vec4 = function () { + function Vec4() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - if (xi) for (var _e20 = 0; _e20 < _t14.length; _e20++) { - _t14[_e20] = (255 & (l = _t14[_e20])) << 8 | l >> 8 & 255; - } - this._png.data = _t14; - } else this._png.data = r; + _classCallCheck(this, Vec4); - var l; - } - }]); + this._values = [x, y, z, w]; + } - return Ui; - }(r); + _createClass(Vec4, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "w", + get: function get() { + return this._values[3]; + }, + set: function set(value) { + this._values[3] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + }, { + key: "xyz", + get: function get() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "splatX", + get: function get() { + return new Vec4(this.x); + } + }, { + key: "splatY", + get: function get() { + return new Vec4(this.y); + } + }, { + key: "splatZ", + get: function get() { + return new Vec4(this.z); + } + }, { + key: "splatW", + get: function get() { + return new Vec4(this.w); + } + }, { + key: "clone", + value: function clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + }, { + key: "toVec3", + value: function toVec3() { + return this.xyz; + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + }, { + key: "subVector", + value: function subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + }, { + key: "reciprocal", + value: function reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; - function zi(t, e, i) { - for (var _n7 = 0; _n7 < i; _n7++) { - e[_n7] = t[_n7]; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; } - } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; - function Ri(t, e, i, n) { - var r = 0; + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; - for (; r < n; r++) { - e[r] = t[r]; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; } - - for (; r < i; r++) { - e[r] = t[r] + e[r - n] & 255; + }, { + key: "truncate", + value: function truncate() { + this._values[0] = __trunc(this._values[0]); + this._values[1] = __trunc(this._values[1]); + this._values[2] = __trunc(this._values[2]); + this._values[3] = __trunc(this._values[3]); + return this; } - } - - function Ni(t, e, i, n) { - var r = 0; - if (0 === i.length) for (; r < n; r++) { - e[r] = t[r]; - } else for (; r < n; r++) { - e[r] = t[r] + i[r] & 255; + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; } - } + }, { + key: "toString", + value: function toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec4.multScalar(a, 1 - p); + var b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + }, { + key: "multiplyAdd", + value: function multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + }, { + key: "negativeMultiplySubtract", + value: function negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + }, { + key: "compareAnyLessThan", + value: function compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + }]); - function Ti(t, e, i, n, r) { - var s = 0; + return Vec4; + }(); - if (0 === i.length) { - for (; s < r; s++) { - e[s] = t[s]; - } + function computeWeightedCovariance(values, weights) { + var total = 0; + var mean = values.reduce(function (sum, value, i) { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + var covariance = values.reduce(function (sum, value, i) { + var weight = weights[i]; + var v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } - for (; s < n; s++) { - e[s] = t[s] + (e[s - r] >> 1) & 255; - } - } else { - for (; s < r; s++) { - e[s] = t[s] + (i[s] >> 1) & 255; - } + function computePCA(values, weights) { + var covariance = computeWeightedCovariance(values, weights); + return _construct(Vec3, dominentPrincipalVector(covariance)); + } - for (; s < n; s++) { - e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; - } - } - } + var lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + var lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - function Oi(t, e, i, n, r) { - var s = 0; + function floatToInt(value, limit) { + var integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } - if (0 === i.length) { - for (; s < r; s++) { - e[s] = t[s]; - } + function floatTo565(color) { + var r = floatToInt(31.0 * color.x, 31); + var g = floatToInt(63.0 * color.y, 63); + var b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } - for (; s < n; s++) { - e[s] = t[s] + e[s - r] & 255; - } - } else { - for (; s < r; s++) { - e[s] = t[s] + i[s] & 255; - } + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; - for (; s < n; s++) { - e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; - } - } + for (var y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; } + } - function Li(t, e, i) { - var n = t + e - i, - r = Math.abs(n - t), - s = Math.abs(n - e), - a = Math.abs(n - i); - return r <= s && r <= a ? t : s <= a ? e : i; + function writeColourBlock3(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + var _ref = [secondColor, firstColor]; + firstColor = _ref[0]; + secondColor = _ref[1]; + remapped = indices.map(function (index) { + return index === 0 ? 1 : index === 1 ? 0 : index; + }); } - var Bi = { - level: 3 - }; + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } - var Ci = function (_r7) { - _inherits(Ci, _r7); + function writeColourBlock4(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; - var _super2 = _createSuper(Ci); + if (firstColor < secondColor) { + var _ref2 = [secondColor, firstColor]; + firstColor = _ref2[0]; + secondColor = _ref2[1]; + remapped = indices.map(function (index) { + return (index ^ 0x1) & 0x3; + }); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } - function Ci(t) { - var _this2; + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } - var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var ColorSet = function () { + function ColorSet(rgba, mask, flags) { + _classCallCheck(this, ColorSet); - _classCallCheck(this, Ci); + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + var isDxt1 = (this.flags & kDxt1) != 0; + var weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - _this2 = _super2.call(this), _this2._colorType = mi.UNKNOWN, _this2._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), _this2._png = _this2._checkData(t), _this2.setBigEndian(); - return _this2; - } + for (var i = 0; i < 16; i++) { + var bit = 1 << i; - _createClass(Ci, [{ - key: "encode", - value: function encode() { - return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); - } - }, { - key: "encodeSignature", - value: function encodeSignature() { - this.writeBytes(wi); - } - }, { - key: "encodeIHDR", - value: function encodeIHDR() { - this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); - } - }, { - key: "encodeIEND", - value: function encodeIEND() { - this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; } - }, { - key: "encodeIDAT", - value: function encodeIDAT(t) { - this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; } - }, { - key: "encodeData", - value: function encodeData() { - var _this$_png = this._png, - t = _this$_png.width, - e = _this$_png.height, - i = _this$_png.channels, - n = _this$_png.depth, - s = _this$_png.data, - a = i * t, - o = new r().setBigEndian(); - var h = 0; - for (var _t15 = 0; _t15 < e; _t15++) { - if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { - if (16 !== n) throw new Error("unreachable"); - h = Si(s, o, a, h); - } + for (var j = 0;; j++) { + if (j == i) { + var r = rgba[4 * i] / 255.0; + var g = rgba[4 * i + 1] / 255.0; + var b = rgba[4 * i + 2] / 255.0; + var a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; } - var l = o.toArray(), - d = fi(l, this._zlibOptions); - this.encodeIDAT(d); - } - }, { - key: "_checkData", - value: function _checkData(t) { - var _ref = function (t) { - var _t$channels = t.channels, - e = _t$channels === void 0 ? 4 : _t$channels, - _t$depth = t.depth, - i = _t$depth === void 0 ? 8 : _t$depth; - if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); - if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); - var n = { - channels: e, - depth: i, - colorType: mi.UNKNOWN - }; - - switch (e) { - case 4: - n.colorType = mi.TRUECOLOUR_ALPHA; - break; + var oldbit = 1 << j; + var match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - case 3: - n.colorType = mi.TRUECOLOUR; - break; + if (match) { + var index = this._remap[j]; + var w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } - case 1: - n.colorType = mi.GREYSCALE; - break; + for (var _i = 0; _i < this._count; ++_i) { + this._weights[_i] = Math.sqrt(this._weights[_i]); + } + } - case 2: - n.colorType = mi.GREYSCALE_ALPHA; - break; + _createClass(ColorSet, [{ + key: "transparent", + get: function get() { + return this._transparent; + } + }, { + key: "count", + get: function get() { + return this._count; + } + }, { + key: "points", + get: function get() { + return Object.freeze(this._points.slice()); + } + }, { + key: "weights", + get: function get() { + return Object.freeze(this._weights.slice()); + } + }, { + key: "remapIndicesSingle", + value: function remapIndicesSingle(singleIndex, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : singleIndex; + }); - default: - throw new Error("unsupported number of channels"); - } + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }, { + key: "remapIndices", + value: function remapIndices(indexMap, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : indexMap[index]; + }); - return n; - }(t), - e = _ref.colorType, - i = _ref.channels, - n = _ref.depth, - r = { - width: Di(t.width, "width"), - height: Di(t.height, "height"), - channels: i, - data: t.data, - depth: n, - text: {} - }; + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }]); - this._colorType = e; - var s = r.width * r.height * i; - if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); - return r; - } - }, { - key: "writeCrc", - value: function writeCrc(t) { - this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); - } - }]); + return ColorSet; + }(); - return Ci; - }(r); + var ColorFit = function () { + function ColorFit(colorSet) { + _classCallCheck(this, ColorFit); - function Di(t, e) { - if (Number.isInteger(t) && t > 0) return t; - throw new TypeError("".concat(e, " must be a positive integer")); + this.colors = colorSet; + this.flags = colorSet.flags; } - function Ii(t, e, i, n) { - for (var _r8 = 0; _r8 < i; _r8++) { - e.writeByte(t[n++]); - } - - return n; - } + _createClass(ColorFit, [{ + key: "compress", + value: function compress(result, offset) { + var isDxt1 = (this.flags & kDxt1) != 0; - function Si(t, e, i, n) { - for (var _r9 = 0; _r9 < i; _r9++) { - e.writeUint16(t[n++]); + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); } + }, { + key: "compress3", + value: function compress3(result, offset) {} + }, { + key: "compress4", + value: function compress4(result, offset) {} + }]); - return n; - } + return ColorFit; + }(); - var Zi; - !function (t) { - t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; - }(Zi || (Zi = {})); + var SingleColourFit = function (_ColorFit) { + _inherits(SingleColourFit, _ColorFit); - var Fi = function Fi(t, e, i) { - return new Ci({ - width: t, - height: e, - data: i - }, undefined).encode(); - }, - Mi = function Mi(t) { - return function (t, e) { - return new Ui(t, void 0).decode(); - }(t); - }; - })(); + var _super = _createSuper(SingleColourFit); + + function SingleColourFit(colorSet) { + var _this; - var r$1 = n.P, - s = n.m; + _classCallCheck(this, SingleColourFit); - function isTypeObject(object) { - return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); - } + _this = _super.call(this, colorSet); + var singleColor = colorSet.points[0]; + _this.color = singleColor.colorInt; + _this.start = new Vec3(0); + _this.end = new Vec3(0); + _this.index = 0; + _this.error = Infinity; + _this.bestError = Infinity; + return _this; + } - function stringify(o, gap, indentation) { - if (isTypeObject(o)) { - var s = stringify(o.data, gap, indentation); + _createClass(SingleColourFit, [{ + key: "compressBase", + value: function compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); - if (__includes(s, '\n')) { - return ' #!' + o.type + s; - } else { - return s + ' #!' + o.type; + if (this.error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } } - } else if (o && 'object' === _typeof(o)) { - var isArray = Array.isArray(o); + }, { + key: "compress3", + value: function compress3(result, offset) { + var lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - if (Object.keys(o).length == 0) { - if (isArray) return '[]';else return '{}'; + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(lookups, saveFunc); } + }, { + key: "compress4", + value: function compress4(result, offset) { + var lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - var _s = '\n'; + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; - for (var k in o) { - if (Object.hasOwnProperty.call(o, k)) { - _s += ga__repeatConcat(p, indentation + 1); + this.compressBase(lookups, saveFunc); + } + }, { + key: "computeEndPoints", + value: function computeEndPoints(lookups) { + this.error = Infinity; - if (isArray) { - _s += '- ' + stringify(o[k], gap, indentation + 1); - } else { - if (__includes(k, ': ')) { - _s += stringify(k, gap, indentation + 1); - _s += ': ' + stringify(o[k], gap, indentation + 1); - } else { - _s += k + ': ' + stringify(o[k], gap, indentation + 1); - } + for (var index = 0; index < 2; index++) { + var sources = []; + var error = 0; + + for (var channel = 0; channel < 3; channel++) { + var lookup = lookups[channel]; + var target = this.color[channel]; + sources[channel] = lookup[target][index]; + var diff = sources[channel][2]; + error += diff * diff; } - _s += '\n'; + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } } } + }]); - return _s; - } else if ('string' === typeof o) { - return JSON.stringify(o); - } else if ('undefined' === typeof o || o === null) { - return 'null'; - } else if (!!o == o || +o == o) { - return JSON.stringify(o); - } else { - throw new Error('Non-implemented parsing for ' + o); - } - } - - function preStringify(object) { - var space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; - var gap = ''; + return SingleColourFit; + }(ColorFit); - if (typeof space == 'number') { - gap = __repeatConcat(' ', Math.min(10, space)); - } else if (typeof space == 'string') { - gap = space.slice(0, 10); - } + var RangeFit = function (_ColorFit2) { + _inherits(RangeFit, _ColorFit2); - return stringify(object, gap, -1); - } + var _super2 = _createSuper(RangeFit); - var LineGenerator = function () { - function LineGenerator(lines, indentString, startingLine) { - _classCallCheck(this, LineGenerator); + function RangeFit(colorSet) { + var _this2; - this.startingLine = startingLine || 0; - this.lineIndex = -1; - var filteredLines = []; + _classCallCheck(this, RangeFit); - for (var i = 0; i < lines.length; i++) { - var trimmedLine = lines[i].trim(); + _this2 = _super2.call(this, colorSet); + _this2.metric = new Vec3(1); - if (trimmedLine !== '') { - filteredLines.push([lines[i], i]); - } + if ((_this2.flags & kColourMetricPerceptual) !== 0) { + _this2.metric.set(0.2126, 0.7152, 0.0722); } - this.lines = filteredLines; - this.indentString = indentString || this.findIndentString(); + _this2.start = new Vec3(0); + _this2.end = new Vec3(0); + _this2.bestError = Infinity; + + _this2.computePoints(); + + return _this2; } - _createClass(LineGenerator, [{ - key: "getLineNumber", - value: function getLineNumber() { - return this.startingLine + this.lineIndex; - } - }, { - key: "nextGroup", - value: function nextGroup() { - var lines = []; - var baseIndent = this.indentLevel(this.lineIndex + 1); + _createClass(RangeFit, [{ + key: "compressBase", + value: function compressBase(codes, saveFunc) { + var _this3 = this; - while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { - lines.push(this.next()); - } + var values = this.colors.points; + var error = 0; + var closest = values.map(function (color) { + var minDist = Infinity; + var packedIndex = codes.reduce(function (idx, code, j) { + var dist = Vec3.sub(color, code).multVector(_this3.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); - return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); - } - }, { - key: "next", - value: function next() { - if (this.finished()) throw new Error('Trying to next finished generator'); - this.lineIndex++; - return this.getLine(); - } - }, { - key: "peek", - value: function peek() { - return this.getLine(this.lineIndex + 1); - } - }, { - key: "finished", - value: function finished() { - return this.lineIndex == this.lines.length - 1; + if (error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } } }, { - key: "getLine", - value: function getLine(index) { - index = index !== undefined ? index : this.lineIndex; - if (index >= this.lines.length) return null; - return this.lines[index][0]; + key: "compress3", + value: function compress3(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); } }, { - key: "findIndentString", - value: function findIndentString() { - for (var _i2 = 0, _this$lines2 = this.lines; _i2 < _this$lines2.length; _i2++) { - var _this$lines2$_i = _this$lines2[_i2], - line = _this$lines2$_i[0]; - if (!line.trim() || line.replace(/^\s+/, "") == line) continue; - return line.match(/^(\s+)/)[1]; - } + key: "compress4", + value: function compress4(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; - return ''; + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); } }, { - key: "indentLevel", - value: function indentLevel(index) { - index = index !== undefined ? index : this.lineIndex; - if (index < 0) index = 0; - var indentLevel = 0; - var line = this.getLine(index); + key: "computePoints", + value: function computePoints() { + var _this$colors = this.colors, + count = _this$colors.count, + values = _this$colors.points, + weights = _this$colors.weights; + if (count <= 0) return; + var principle = computePCA(values, weights); + var start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); - while (lin__startsWithString(e, this.indentString)) { - line = line.slice(this.indentString.length); - indentLevel++; + for (var i = 1; i < count; i++) { + var value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } } - return indentLevel; + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); } }]); - return LineGenerator; - }(); - - function getObject(lineGroup, type) { - var object; - lineGroup.indentLevel(); - - while (!lineGroup.finished()) { - var line = lineGroup.next(); - var trimmedLine = line.trim(); - var keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); - var typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + return RangeFit; + }(ColorFit); - var key = void 0, - value = void 0, - _type = void 0; + var ClusterFit = function (_ColorFit3) { + _inherits(ClusterFit, _ColorFit3); - if (trimmedLin__startsWithString(e, '"')) { - keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); - } + var _super3 = _createSuper(ClusterFit); - if (typeMatch) { - _type = typeMatch[1]; - trimmedLine = trimmedLine.replace(typeMatch[0], ''); - } + function ClusterFit(colorSet) { + var _this4; - if (keyMatch) { - if (!object) object = {}; - key = keyMatch[1]; - value = trimmedLine.replace(keyMatch[0], '').trim(); - } else if (trimmedLin__startsWithString(e, '-')) { - if (!object) object = []; - value = trimmedLine.slice(1).trim(); - } + _classCallCheck(this, ClusterFit); - if (value) { - value = getValue(value, _type); - } else { - value = getObject(lineGroup.nextGroup(), _type); - } + _this4 = _super3.call(this, colorSet); + var kMaxIterations = 8; + _this4.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + _this4.bestError = Infinity; + _this4.metric = new Vec4(1); - if (Array.isArray(object)) { - object.push(value); - } else { - object[key] = value; + if ((_this4.flags & kColourMetricPerceptual) !== 0) { + _this4.metric.set(0.2126, 0.7152, 0.0722, 0); } - } - - if (type) { - object = { - type: type, - data: object - }; - } - return object; - } - - function getValue(value, type) { - value = JSON.parse(value); - - if (type) { - value = { - type: type, - data: value - }; + var _this4$colors = _this4.colors, + values = _this4$colors.points, + weights = _this4$colors.weights; + _this4.principle = computePCA(values, weights); + _this4.order = new Uint8Array(16 * kMaxIterations); + _this4.pointsWeights = []; + _this4.xSum_wSum = new Vec4(0); + return _this4; } - return value; - } - - function parse(str) { - var lines = str.replace(/\t/g, ' ').split('\n'); - var lineGenerator = new LineGenerator(lines); - return getObject(lineGenerator); - } - - function deepCopy(obj) { - var newObj; + _createClass(ClusterFit, [{ + key: "constructOrdering", + value: function constructOrdering(axis, iteration) { + var currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + var uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var aabbx = function aabbx(_ref) { + var part0 = _ref[0], + part1 = _ref[2], + part2 = _ref[3]; + var const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + var alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - if (Array.isArray(obj)) { - newObj = []; + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; - for (var _i2 = 0; _i2 < obj.length; _i2++) { - var item = obj[_i2]; - newObj.push(deepCopy(item)); + this.compressBase(aabbx, saveFunc, 2); } + }, { + key: "compress4", + value: function compress4(result, offset) { + var aabbx = function aabbx(_ref2) { + var part0 = _ref2[0], + part1 = _ref2[1], + part2 = _ref2[2], + part3 = _ref2[3]; + var const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + var const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + var const2_9 = new Vec4(2 / 9); + var alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - return newObj; - } + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; - if (!!obj && _typeof(obj) === "object") { - newObj = {}; + this.compressBase(aabbx, saveFunc, 3); + } + }, { + key: "compressBase", + value: function compressBase(aabbFunc, saveFunc) { + var _this5 = this; - var __keys = Object.keys(obj); + var repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + var best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; - for (var __i = 0; __i < __keys.length; __i++) { - var key = __keys[__i], - value = obj[key]; - newObj[key] = deepCopy(value); - } + var leastSquares = function leastSquares(parts, internalIndices) { + var aabbx = aabbFunc(parts); - return newObj; - } + var internalBest = _this5.computeOptimalPoints(aabbx); - return obj; - } + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } - function isPrimitiveReaderType(reader) { - switch (reader) { - case 'Boolean': - case 'Int32': - case 'Char': - case 'String': - case '': - case 'Vector2': - case 'Vector3': - case 'Vector4': - case 'Rectangle': - return true; + return false; + }; - default: - return false; - } - } + for (var iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + var newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } - function isExportReaderType(reader) { - switch (reader) { - case 'Texture2D': - case 'TBin': - case 'Effect': - case 'BmFont': - return true; + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + }, { + key: "makeOrder", + value: function makeOrder(axis) { + var _this$colors2 = this.colors, + count = _this$colors2.count, + values = _this$colors2.points; + var dotProducts = values.map(function (color, i) { + return Vec3.dot(color, axis); + }); + return __arrayMaker({ + length: count + }, function (_, i) { + return i; + }).sort(function (a, b) { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + }, { + key: "copyOrderToThisOrder", + value: function copyOrderToThisOrder(order, iteration) { + var _this6 = this; - default: - return false; - } - } + var orderOffset = iteration * 16; + order.forEach(function (ord, i) { + _this6.order[orderOffset + i] = ord; + }); + } + }, { + key: "checkOrderUnique", + value: function checkOrderUnique(order, iteration) { + var count = this.colors.count; - function convertJsonContentsToXnbNode(raw, readers) { - var extractedImages = []; - var extractedMaps = []; + for (var it = 0; it < iteration; it++) { + var prevOffset = it * 16; + var same = true; - var _recursiveConvert = function recursiveConvert(obj, path) { - var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - var reader = readers[index]; + for (var i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } - if (isPrimitiveReaderType(reader)) { - return { - converted: { - type: reader, - data: obj - }, - traversed: index - }; + if (same) return false; + } + + return true; } + }, { + key: "copyOrderWeight", + value: function copyOrderWeight(order) { + var _this$colors3 = this.colors, + count = _this$colors3.count, + unweighted = _this$colors3.points, + weights = _this$colors3.weights; + this.xSum_wSum.set(0); - if (reader === null) { + for (var i = 0; i < count; i++) { + var j = order[i]; + var p = unweighted[j].toVec4(1); + var w = new Vec4(weights[j]); + var x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + }, { + key: "computeOptimalPoints", + value: function computeOptimalPoints(vectorPoint) { + var ax = vectorPoint.ax, + bx = vectorPoint.bx, + aa = vectorPoint.aa, + bb = vectorPoint.bb, + ab = vectorPoint.ab; + var factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + var a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + var b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + var error = this.computeError(_objectSpread2({ + a: a, + b: b + }, vectorPoint)); return { - converted: obj, - traversed: index + start: a, + end: b, + error: error }; } + }, { + key: "computeError", + value: function computeError(_ref3) { + var a = _ref3.a, + b = _ref3.b, + ax = _ref3.ax, + bx = _ref3.bx, + aa = _ref3.aa, + bb = _ref3.bb, + ab = _ref3.ab; + var two = new Vec4(2); + var e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + var e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + var e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + var e4 = Vec4.multiplyAdd(two, e3, e1); + var e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + }, { + key: "saveBlock", + value: function saveBlock(best, writeFunc) { + var count = this.colors.count; + var start = best.start, + end = best.end, + iteration = best.iteration, + error = best.error, + bestI = best.bestI, + bestJ = best.bestJ, + _best$bestK = best.bestK, + bestK = _best$bestK === void 0 ? -1 : _best$bestK; + var orderOffset = iteration * 16; + var unordered = new Uint8Array(16); - if (reade__startsWithString(r, 'Nullable')) { - return { - converted: { - type: reader, - data: { - data: { - type: readers[index + 1], - data: obj - } - } - }, - traversed: index + 1 + var mapper = function mapper(m) { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; }; - } - if (isExportReaderType(reader)) { - if (reader === 'Texture2D') { - extractedImages.push({ - path: path.join('.') - }); - return { - converted: { - type: reader, - data: { - format: obj.format - } - }, - traversed: index - }; + for (var i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); } - if (reader === 'TBin') { - extractedMaps.push({ - path: path.join('.') - }); - } + var bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + }, { + key: "clusterIterate", + value: function clusterIterate(index, func) { + var iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + var count = this.colors.count; - return { - converted: { - type: reader, - data: {} - }, - traversed: index + var indexMapper = function indexMapper(i, j, k) { + var mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; }; - } - var data; - if (Array.isArray(obj)) data = [];else data = {}; - var traversed = index; - var first = true; - var isComplex = !reade__startsWithString(r, "Dictionary") && !reade__startsWithString(r, "Array") && !reade__startsWithString(r, "List"); + var part0 = new Vec4(0.0); - var __keys = Object.keys(obj); + for (var i = 0; i < count; i++) { + var part1 = new Vec4(0.0); - for (var __i = 0; __i < __keys.length; __i++) { - var key = __keys[__i]; - obj[key]; - var newIndex = void 0; + for (var j = i;;) { + var preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + var kmin = j == 0 ? 1 : j; - if (reade__startsWithString(r, "Dictionary")) { - if (getTypeInfo(reader).subtypes[1] === readers[index + 2]) newIndex = index + 2;else newIndex = index + 1; - } else if (reade__startsWithString(r, "Array") || reade__startsWithString(r, "List")) newIndex = index + 1;else newIndex = traversed + 1; + for (var k = kmin;;) { + var restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } - var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), - _converted = _recursiveConvert2.converted, - nexter = _recursiveConvert2.traversed; + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } - data[key] = _converted; - if (isComplex) traversed = nexter;else if (first) { - traversed = nexter; - first = false; + part0.addVector(this.pointsWeights[i]); } } + }]); - return { - converted: { - type: reader, - data: data - }, - traversed: traversed - }; - }(raw, []), - converted = _recursiveConvert.converted; + return ClusterFit; + }(ColorFit); - return { - converted: converted, - extractedImages: extractedImages, - extractedMaps: extractedMaps - }; + function quantise(alpha) { + var GRID = 15; + var result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; } - function convertJsonContentsFromXnbNode(obj) { - if (!obj || _typeof(obj) !== "object") return obj; - - if (_typeof(obj) === "object" && obj.hasOwnProperty("data")) { - var _obj = obj, - type = _obj.type, - data = _obj.data; - if (isPrimitiveReaderType(type)) return deepCopy(data); - - if (isExportReaderType(type)) { - data = deepCopy(data); - if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; - return data; - } - - obj = deepCopy(data); + function compressAlphaDxt3(rgba, mask, result, offset) { + for (var i = 0; i < 8; i++) { + var quant1 = quantise(rgba[8 * i + 3]); + var quant2 = quantise(rgba[8 * i + 7]); + var bit1 = 1 << 2 * i; + var bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; } + } - var newObj; - - if (Array.isArray(obj)) { - newObj = []; + function compressAlphaDxt5(rgba, mask, result, offset) { + var step5 = interpolateAlpha(rgba, mask, 5); + var step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } - for (var _i4 = 0, _obj3 = obj; _i4 < _obj3.length; _i4++) { - var item = _obj3[_i4]; - newObj.push(convertJsonContentsFromXnbNode(item)); - } + function interpolateAlpha(rgba, mask, steps) { + var _setAlphaRange = setAlphaRange(rgba, mask, steps), + min = _setAlphaRange.min, + max = _setAlphaRange.max; - return newObj; - } + var code = setAlphaCodeBook(min, max, steps); + var indices = new Uint8Array(16); + var error = fitCodes(rgba, mask, code, indices); + return { + min: min, + max: max, + indices: indices, + error: error + }; + } - if (!!obj && _typeof(obj) === "object") { - newObj = {}; + function setAlphaRange(rgba, mask, steps) { + var min = 255; + var max = 0; - var __keys = Object.keys(obj); + for (var i = 0; i < 16; i++) { + var bit = 1 << i; + if ((mask & bit) == 0) continue; + var value = rgba[4 * i + 3]; - for (var __i = 0; __i < __keys.length; __i++) { - var key = __keys[__i], - value = obj[key]; - newObj[key] = convertJsonContentsFromXnbNode(value); + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; } - - return newObj; } - return null; - } - - function toXnbNodeData(json) { - var toYamlJson = {}; - var _json$header = json.header, - compressed = _json$header.compressed; - _json$header.formatVersion; - var hiDef = _json$header.hidef, - target = _json$header.target; - var readerData = deepCopy(json.readers); - toYamlJson.xnbData = { - target: target, - compressed: !!compressed, - hiDef: hiDef, - readerData: readerData, - numSharedResources: 0 + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min: min, + max: max }; - var rawContent = deepCopy(json.content); - var readersTypeList = readerData.map(function (_ref) { - var type = _ref.type; - return simplifyType(type); - }); - - if (readersTypeList[0] === 'SpriteFont') { - readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; - rawContent.verticalSpacing = rawContent.verticalLineSpacing; - delete rawContent.verticalLineSpacing; - } - - var _convertJsonContentsT = convertJsonContentsToXnbNode(rawContent, readersTypeList), - converted = _convertJsonContentsT.converted, - extractedImages = _convertJsonContentsT.extractedImages, - extractedMaps = _convertJsonContentsT.extractedMaps; - - toYamlJson.content = converted; - if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; - if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; - return toYamlJson; } - function fromXnbNodeData(json) { - var result = {}; - var _json$xnbData = json.xnbData, - compressed = _json$xnbData.compressed, - readerData = _json$xnbData.readerData, - hidef = _json$xnbData.hiDef, - target = _json$xnbData.target; - result.header = { - target: target, - formatVersion: 5, - compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, - hidef: hidef - }; - result.readers = deepCopy(readerData); - result.content = convertJsonContentsFromXnbNode(json.content); + function setAlphaCodeBook(min, max, steps) { + var codes = [min, max].concat(__arrayMaker({ + length: steps - 1 + }, function (_, i) { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })); - if (simplifyType(result.readers[0].type) === 'SpriteFont') { - result.content.verticalLineSpacing = result.content.verticalSpacing; - delete result.content.verticalSpacing; + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; } - return result; + return codes; } - function searchElement(parent, element) { - if (!parent || _typeof(parent) != 'object') return; + function fitCodes(rgba, mask, codes, indices) { + var err = 0; - if (parent.hasOwnProperty(element)) { - return { - parent: parent, - value: parent[element] - }; - } + for (var i = 0; i < 16; ++i) { + var bit = 1 << i; - var __keys = Object.keys(parent); + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } - for (var __i = 0; __i < __keys.length; __i++) { - var __key = __keys[__i], - child = parent[__key]; + var value = rgba[4 * i + 3]; + var least = Infinity; + var index = 0; - if (!!child || _typeof(child) == 'object') { - var found = searchElement(child, element); - if (found) return found; + for (var j = 0; j < 8; ++j) { + var dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } } + + indices[i] = index; + err += least; } - return null; + return err; } - function extractFileName(fullname) { - var matcher = fullname.match(/(.*)\.([^\s.]+)$/); - if (matcher === null) return [fullname, null]; - return [matcher[1], matcher[2]]; + function writeAlphaBlock5(_ref, result, offset) { + var alpha0 = _ref.min, + alpha1 = _ref.max, + indices = _ref.indices; + + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); } - function getExtension(dataType) { - switch (dataType) { - case "JSON": - return "json"; + function writeAlphaBlock7(_ref2, result, offset) { + var alpha0 = _ref2.min, + alpha1 = _ref2.max, + indices = _ref2.indices; - case "yaml": - return "yaml"; + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } - case "Texture2D": - return "png"; + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + var indicesPointer = 0; + var resultPointer = offset + 2; - case "Effect": - return "cso"; + for (var i = 0; i < 2; i++) { + var value = 0; - case 'TBin': - return "tbin"; + for (var j = 0; j < 8; ++j) { + var index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } - case 'BmFont': - return "xml"; + for (var _j = 0; _j < 3; ++_j) { + var byte = value >> 8 * _j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } } - - return "bin"; } - function getMimeType(dataType) { - switch (dataType) { - case "JSON": - return "application/json"; + function unpack565(color16bit) { + var red = color16bit >> 11 & 0x1f; + var green = color16bit >> 5 & 0x3f; + var blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; + } - case "yaml": - return "text/plain"; + function interpolateColorArray(a, b, amount) { + var result = a.map(function (aColor, i) { + return Math.floor(aColor * (1 - amount) + b[i] * amount); + }); + result[3] = 255; + return result; + } - case "Texture2D": - return "image/png"; + function unpackColorCodes(block, offset, isDxt1) { + var color1 = block[offset] | block[offset + 1] << 8; + var color2 = block[offset + 2] | block[offset + 3] << 8; + var unpackedColor1 = unpack565(color1); + var unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } - case "Effect": - return "application/x-cso"; + function unpackIndices(block, blockOffset) { + var offset = blockOffset + 4; + var result = new Uint8Array(16); - case 'BmFont': - return "application/xml"; + for (var i = 0; i < 4; i++) { + var packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; } - return "application/octet-stream"; - } - - function makeBlob(data, dataType) { - if (typeof Blob === "function") return { - data: new Blob([data], { - type: getMimeType(dataType) - }), - extension: getExtension(dataType) - }; - return { - data: data, - extension: getExtension(dataType) - }; + return result; } - function exportContent(content) { - var jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var found = searchElement(content, "export"); - - if (found) { - var value = found.value; - var dataType = value.type, - data = value.data; + function decompressColor(rgba, block, offset, isDxt1) { + var colorCode = unpackColorCodes(block, offset, isDxt1); + var indices = unpackIndices(block, offset); - if (dataType === "Texture2D") { - data = s(value.width, value.height, new Uint8Array(data)); + for (var i = 0; i < 16; i++) { + for (var j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; } - - return makeBlob(data, dataType); } + } - if (jsonContent) { - var contentJson = JSON.stringify(content, null, 4); - return makeBlob(contentJson, "JSON"); + function decompressAlphaDxt3(rgba, block, offset) { + for (var i = 0; i < 8; ++i) { + var quant = block[offset + i]; + var lo = quant & 0x0f; + var hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; } - - return null; } - /** @api - * decompressed xnb object to real file blobs. - * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) - * @param {Object} config (yaml:export file as yaml, - * contentOnly:export content file only, - * fileName:exported files's name) (optional) - */ + function decompressAlphaDxt5(rgba, block, offset) { + var alpha0 = block[offset + 0]; + var alpha1 = block[offset + 1]; + var codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + var indices = new Uint8Array(16); + var indicePointer = 0; + var bytePointer = 2; - function exportFiles(xnbObject) { - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref$yaml = _ref.yaml, - isYaml = _ref$yaml === void 0 ? false : _ref$yaml, - _ref$contentOnly = _ref.contentOnly, - contentOnly = _ref$contentOnly === void 0 ? false : _ref$contentOnly, - _ref$fileName = _ref.fileName, - fileName = _ref$fileName === void 0 ? null : _ref$fileName; + for (var i = 0; i < 2; i++) { + var value = 0; - if (isYaml && contentOnly) isYaml = false; - if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); - var blobs = []; - var content = xnbObject.content; - var contentBlob = exportContent(content, contentOnly); - if (contentBlob !== null) blobs.push(contentBlob); - if (contentOnly) return blobs; - var resultJSON = JSON.stringify(xnbObject, function (key, value) { - if (key === "export") { - if (typeof fileName == "string" && fileName !== "") { - return "".concat(fileName, ".").concat(getExtension(value.type)); - } + for (var j = 0; j < 3; j++) { + var byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } - return "".concat(value.type, ".").concat(getExtension(value.type)); + for (var _j = 0; _j < 8; _j++) { + var index = value >> 3 * _j & 0x7; + indices[indicePointer] = index; + indicePointer++; } + } - return value; - }, 4); - var result = resultJSON; - if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); - blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); - return blobs; + for (var _i = 0; _i < 16; ++_i) { + rgba[4 * _i + 3] = codes[indices[_i]]; + } } - function resolveCompression(compressionString) { - var str = compressionString.toLowerCase(); - if (str === "none") return 0; - if (str === "lz4") return 0x40; - return null; - } + var DXT1_COMPRESSED_BYTES = 8; + var DXT5_COMPRESSED_BYTES = 16; + var COLORS = 4; + var DECOMPRESSED_BLOCK_SIZE = 16; - function readBlobasText(_x) { - return _readBlobasText.apply(this, arguments); + function blockRepeat(width, height, func) { + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + func(x, y); + } + } } - function _readBlobasText() { - _readBlobasText = _asyncToGenerator(regeneratorRuntime.mark(function _callee(blob) { - return regeneratorRuntime.wrap(function _callee$(_context) { - while (1) { - switch (_context.prev = _context.next) { - case 0: - if (!(typeof Blob === "function" && blob instanceof Blob)) { - _context.next = 4; - break; - } - - return _context.abrupt("return", blob.text()); - - case 4: - if (!(typeof Buffer === "function" && blob instanceof Buffer)) { - _context.next = 6; - break; - } - - return _context.abrupt("return", blob.toString()); - - case 6: - case "end": - return _context.stop(); - } - } - }, _callee); - })); - return _readBlobasText.apply(this, arguments); + function rectRepeat(func) { + for (var y = 0; y < 4; y++) { + for (var x = 0; x < 4; x++) { + func(x, y); + } + } } - function readBlobasArrayBuffer(_x2) { - return _readBlobasArrayBuffer.apply(this, arguments); + function FixFlags(flags) { + var method = flags & (kDxt1 | kDxt3 | kDxt5); + var fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + var metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + var extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; } - function _readBlobasArrayBuffer() { - _readBlobasArrayBuffer = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(blob) { - return regeneratorRuntime.wrap(function _callee2$(_context2) { - while (1) { - switch (_context2.prev = _context2.next) { - case 0: - if (!(typeof Blob === "function" && blob instanceof Blob)) { - _context2.next = 4; - break; - } + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + var blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + var blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } - return _context2.abrupt("return", blob.arrayBuffer()); + function extractColorBlock(img) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$x = _ref.x, + x = _ref$x === void 0 ? 0 : _ref$x, + _ref$y = _ref.y, + y = _ref$y === void 0 ? 0 : _ref$y, + _ref$width = _ref.width, + width = _ref$width === void 0 ? 0 : _ref$width, + _ref$height = _ref.height, + height = _ref$height === void 0 ? 0 : _ref$height; - case 4: - if (!(typeof Buffer === "function" && blob instanceof Buffer)) { - _context2.next = 6; - break; - } + var block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + var mask = 0; + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; - return _context2.abrupt("return", blob.buffer); + if (sx < width && sy < height) { + var sourceColorOffset = COLORS * (width * sy + sx); - case 6: - case "end": - return _context2.stop(); - } + for (var i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; } - }, _callee2); - })); - return _readBlobasArrayBuffer.apply(this, arguments); - } - function readExternFiles(_x3, _x4) { - return _readExternFiles.apply(this, arguments); + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block: block, + mask: mask + }; } - function _readExternFiles() { - _readExternFiles = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(extension, files) { - var rawPng, png, data, _data, _data2; - - return regeneratorRuntime.wrap(function _callee3$(_context3) { - while (1) { - switch (_context3.prev = _context3.next) { - case 0: - if (!(extension === "png")) { - _context3.next = 6; - break; - } + function copyBuffer(result, block) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$x = _ref2.x, + x = _ref2$x === void 0 ? 0 : _ref2$x, + _ref2$y = _ref2.y, + y = _ref2$y === void 0 ? 0 : _ref2$y, + _ref2$width = _ref2.width, + width = _ref2$width === void 0 ? 0 : _ref2$width, + _ref2$height = _ref2.height, + height = _ref2$height === void 0 ? 0 : _ref2$height; - _context3.next = 3; - return readBlobasArrayBuffer(files.png); + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; - case 3: - rawPng = _context3.sent; - png = r$1(new Uint8Array(rawPng)); - return _context3.abrupt("return", { - type: "Texture2D", - data: png.data, - width: png.width, - height: png.height - }); + if (sx < width && sy < height) { + var resultColorOffset = COLORS * (width * sy + sx); - case 6: - if (!(extension === "cso")) { - _context3.next = 11; - break; - } + for (var i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } - _context3.next = 9; - return readBlobasArrayBuffer(files.cso); + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } - case 9: - data = _context3.sent; - return _context3.abrupt("return", { - type: "Effect", - data: data - }); + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + var colors = new ColorSet(rgba, mask, flags); + var compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } - case 11: - if (!(extension === "tbin")) { - _context3.next = 16; - break; - } + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); + } - _context3.next = 14; - return readBlobasArrayBuffer(files.tbin); + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + var _extractColorBlock = extractColorBlock(source, { + x: x, + y: y, + width: width, + height: height + }), + sourceRGBA = _extractColorBlock.block, + mask = _extractColorBlock.mask; - case 14: - _data = _context3.sent; - return _context3.abrupt("return", { - type: "TBin", - data: _data - }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } - case 16: - if (!(extension === "xml")) { - _context3.next = 21; - break; - } + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var sourceBlockPointer = 0; - _context3.next = 19; - return readBlobasText(files.xml); + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + var targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x: x, + y: y, + width: width, + height: height + }); + sourceBlockPointer += bytesPerBlock; + } + } + } - case 19: - _data2 = _context3.sent; - return _context3.abrupt("return", { - type: "BmFont", - data: _data2 - }); + var flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; - case 21: - case "end": - return _context3.stop(); - } - } - }, _callee3); - })); - return _readExternFiles.apply(this, arguments); + function compress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = GetStorageRequirements(width, height, flags); + var result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; } - function resolveImports(_x5) { - return _resolveImports.apply(this, arguments); + function decompress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = width * height * 4; + var result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; } - function _resolveImports() { - _resolveImports = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(files) { - var configs, - _configs$compression, - compression, - jsonFile, - rawText, - jsonData, - compressBits, - found, - parent, - value, - _extractFileName, - extension, - _args4 = arguments; + var Texture2DReader = function (_BaseReader) { + _inherits(Texture2DReader, _BaseReader); - return regeneratorRuntime.wrap(function _callee4$(_context4) { - while (1) { - switch (_context4.prev = _context4.next) { - case 0: - configs = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}; - _configs$compression = configs.compression, compression = _configs$compression === void 0 ? "default" : _configs$compression; - jsonFile = files.json || files.yaml; + var _super = _createSuper(Texture2DReader); - if (jsonFile) { - _context4.next = 5; - break; - } + function Texture2DReader() { + _classCallCheck(this, Texture2DReader); - throw new XnbError("There is no JSON or YAML file to pack!"); + return _super.apply(this, arguments); + } - case 5: - _context4.next = 7; - return readBlobasText(jsonFile); + _createClass(Texture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); - case 7: - rawText = _context4.sent; - jsonData = null; - if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); - compressBits = resolveCompression(compression); - if (compressBits !== null) jsonData.header.compressed = compressBits; + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + var width = content.export.width; + var height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; + + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; - if (jsonData.hasOwnProperty('content')) { - _context4.next = 14; - break; - } + default: + return false; + } + } + }]); - throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + return Texture2DReader; + }(BaseReader); - case 14: - found = searchElement(jsonData.content, "export"); + var Vector3Reader = function (_BaseReader) { + _inherits(Vector3Reader, _BaseReader); - if (!found) { - _context4.next = 21; - break; - } + var _super = _createSuper(Vector3Reader); - parent = found.parent, value = found.value; - _extractFileName = extractFileName(value), extension = _extractFileName[1]; - _context4.next = 20; - return readExternFiles(extension, files); + function Vector3Reader() { + _classCallCheck(this, Vector3Reader); - case 20: - parent.export = _context4.sent; + return _super.apply(this, arguments); + } - case 21: - return _context4.abrupt("return", jsonData); + _createClass(Vector3Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + return { + x: x, + y: y, + z: z + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; - case 22: - case "end": - return _context4.stop(); - } + default: + return false; } - }, _callee4); - })); - return _resolveImports.apply(this, arguments); - } + } + }]); - /** @api - * Asynchronously reads the file into binary and then unpacks the json data. - * XNB -> arrayBuffer -> XnbData - * @param {File / Buffer} file - * @return {XnbData} JSON data with headers - */ + return Vector3Reader; + }(BaseReader); - function unpackToXnbData(_x) { - return _unpackToXnbData.apply(this, arguments); - } - /** @api - * Asynchronously reads the file into binary and then return content file. - * XNB -> arrayBuffer -> XnbData -> Content - * @param {File / Buffer} file - * @return {XnbContent} exported Content Object - */ + var SpriteFontReader = function (_BaseReader) { + _inherits(SpriteFontReader, _BaseReader); + var _super = _createSuper(SpriteFontReader); - function _unpackToXnbData() { - _unpackToXnbData = _asyncToGenerator(regeneratorRuntime.mark(function _callee(file) { - var _extractFileName3, extension, buffer; + function SpriteFontReader() { + _classCallCheck(this, SpriteFontReader); - return regeneratorRuntime.wrap(function _callee$(_context) { - while (1) { - switch (_context.prev = _context.next) { - case 0: - if (!(typeof window !== "undefined")) { - _context.next = 8; - break; - } + return _super.apply(this, arguments); + } - _extractFileName3 = extractFileName(file.name), extension = _extractFileName3[1]; + _createClass(SpriteFontReader, [{ + key: "read", + value: function read(buffer, resolver) { + var int32Reader = new Int32Reader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(new CharReader()); + var texture = resolver.read(buffer); + var glyphs = resolver.read(buffer); + var cropping = resolver.read(buffer); + var characterMap = resolver.read(buffer); + var verticalLineSpacing = int32Reader.read(buffer); + var horizontalSpacing = singleReader.read(buffer); + var kerning = resolver.read(buffer); + var defaultCharacter = nullableCharReader.read(buffer); + return { + texture: texture, + glyphs: glyphs, + cropping: cropping, + characterMap: characterMap, + verticalLineSpacing: verticalLineSpacing, + horizontalSpacing: horizontalSpacing, + kerning: kerning, + defaultCharacter: defaultCharacter + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var charReader = new CharReader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(charReader); + var texture2DReader = new Texture2DReader(); + var rectangleListReader = new ListReader(new RectangleReader()); + var charListReader = new ListReader(charReader); + var vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); - if (!(extension !== "xnb")) { - _context.next = 4; - break; - } + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } - return _context.abrupt("return", new Error("Invalid XNB File!")); + console.log("writing complitd!"); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; - case 4: - _context.next = 6; - return file.arrayBuffer(); + default: + return false; + } + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + }]); - case 6: - buffer = _context.sent; - return _context.abrupt("return", bufferToXnb(buffer)); + return SpriteFontReader; + }(BaseReader); - case 8: - return _context.abrupt("return", bufferToXnb(file.buffer)); + var TBinReader = function (_BaseReader) { + _inherits(TBinReader, _BaseReader); - case 9: - case "end": - return _context.stop(); - } - } - }, _callee); - })); - return _unpackToXnbData.apply(this, arguments); - } + var _super = _createSuper(TBinReader); - function unpackToContent(file) { - return unpackToXnbData(file).then(xnbDataToContent); - } - /** @api - * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. - * XNB -> arrayBuffer -> XnbData -> Files - * @param {File / Buffer} file - * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) - * @return {Array} exported Files Blobs - */ + function TBinReader() { + _classCallCheck(this, TBinReader); + return _super.apply(this, arguments); + } - function unpackToFiles(file) { - var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _configs$yaml = configs.yaml, - yaml = _configs$yaml === void 0 ? false : _configs$yaml, - _configs$contentOnly = configs.contentOnly, - contentOnly = _configs$contentOnly === void 0 ? false : _configs$contentOnly, - _configs$fileName = configs.fileName, - name = _configs$fileName === void 0 ? null : _configs$fileName; - if (typeof window !== "undefined" && name === null) name = file.name; + _createClass(TBinReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var size = int32Reader.read(buffer); + var data = buffer.read(size); + return { + export: { + type: this.type, + data: data + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; - var _extractFileName = extractFileName(name), - fileName = _extractFileName[0]; + default: + return false; + } + } + }]); + + return TBinReader; + }(BaseReader); - var exporter = function exporter(xnbObject) { - return exportFiles(xnbObject, { - yaml: yaml, - contentOnly: contentOnly, - fileName: fileName - }); - }; + (function (_BaseReader) { + _inherits(LightweightTexture2DReader, _BaseReader); - return unpackToXnbData(file).then(exporter); - } - /** @api - * reads the buffer and then unpacks. - * arrayBuffer -> XnbData - * @param {ArrayBuffer} buffer - * @return {XnbData} the loaded XNB json - */ + var _super = _createSuper(LightweightTexture2DReader); + function LightweightTexture2DReader() { + _classCallCheck(this, LightweightTexture2DReader); - function bufferToXnb(buffer) { - var xnb = new XnbConverter(); - return xnb.load(buffer); - } - /** @api - * reads the buffer and then unpacks the contents. - * arrayBuffer -> XnbData -> Content - * @param {ArrayBuffer} buffer - * @return {XnbContent} exported Content Object - */ + return _super.apply(this, arguments); + } + _createClass(LightweightTexture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); - function bufferToContents(buffer) { - var xnb = new XnbConverter(); - var xnbData = xnb.load(buffer); - return xnbDataToContent(xnbData); - } - /** @api - * remove header from the loaded XNB Object - * XnbData -> Content - * @param {XnbData} the loaded XNB object include headers - * @return {XnbContent} exported Content Object - */ + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; - function xnbDataToContent(loadedXnb) { - var content = loadedXnb.content; + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } - var _exportContent = exportContent(content, true), - data = _exportContent.data, - extension = _exportContent.extension; + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Texture2D"; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; - return new XnbContent(data, extension); - } - /** @api - * reads the json and then unpacks the contents. - * @param {FileList/Array} to pack json data - * @return {Object/Object} packed XNB Array Buffer - */ + default: + return false; + } + } + }, { + key: "type", + value: function type() { + return "Texture2D"; + } + }]); + return LightweightTexture2DReader; + })(BaseReader); - function fileMapper(files) { - var returnMap = {}; + var Vector2Reader = function (_BaseReader) { + _inherits(Vector2Reader, _BaseReader); - for (var i = 0; i < files.length; i++) { - var file = files[i]; + var _super = _createSuper(Vector2Reader); - var _extractFileName2 = extractFileName(file.name), - fileName = _extractFileName2[0], - extension = _extractFileName2[1]; + function Vector2Reader() { + _classCallCheck(this, Vector2Reader); - if (extension === null) continue; - if (returnMap[fileName] === undefined) returnMap[fileName] = {}; - var namedFileObj = returnMap[fileName]; - if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + return _super.apply(this, arguments); } - return returnMap; - } - /** @api - * reads the json and then unpacks the contents. - * @param {json} to pack json data - * @return {ArrayBuffer} packed XNB Array Buffer - */ + _createClass(Vector2Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + return { + x: x, + y: y + }; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + default: + return false; + } + } + }]); - function packJsonToBinary(json) { - var xnb = new XnbConverter(); - var buffer = xnb.convert(json); - return buffer; - } - /** @api - * Asynchronously reads the file into binary and then pack xnb files. - * @param {FlieList} files - * @param {Object} configs(compression:default, none, LZ4, LZX / debug) - * @return {Array(Blobs)} - */ + return Vector2Reader; + }(BaseReader); + var Vector4Reader = function (_BaseReader) { + _inherits(Vector4Reader, _BaseReader); - function pack(files) { - var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var groupedFiles = fileMapper(files); - var promises = []; + var _super = _createSuper(Vector4Reader); - var __keys = Object.keys(groupedFiles); + function Vector4Reader() { + _classCallCheck(this, Vector4Reader); - for (var __i = 0; __i < __keys.length; __i++) { - var fileName = __keys[__i], - filePack = groupedFiles[fileName]; - promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(function (buffer) { - if (typeof Blob === "function") return { - name: fileName, - data: new Blob([buffer], { - type: "application/octet-stream" - }) - }; + return _super.apply(this, arguments); + } + + _createClass(Vector4Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + var w = singleReader.read(buffer); return { - name: fileName, - data: new Uint8Array(buffer) + x: x, + y: y, + z: z, + w: w }; - })); - } + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; - return __promise_allSettled(promises).then(function (blobArray) { - if (configs.debug === true) return blobArray; - return blobArray.filter(function (_ref) { - var status = _ref.status; - _ref.value; - return status === "fulfilled"; - }).map(function (_ref2) { - var value = _ref2.value; - return value; - }); - }); - } + default: + return false; + } + } + }]); + + return Vector4Reader; + }(BaseReader); + + var Readers = { + ArrayReader: ArrayReader, + BaseReader: BaseReader, + BmFontReader: BmFontReader, + BooleanReader: BooleanReader, + CharReader: CharReader, + DictionaryReader: DictionaryReader, + DoubleReader: DoubleReader, + EffectReader: EffectReader, + Int32Reader: Int32Reader, + ListReader: ListReader, + NullableReader: NullableReader, + RectangleReader: RectangleReader, + ReflectiveReader: ReflectiveReader, + SingleReader: SingleReader, + SpriteFontReader: SpriteFontReader, + StringReader: StringReader, + TBinReader: TBinReader, + Texture2DReader: Texture2DReader, + UInt32Reader: UInt32Reader, + Vector2Reader: Vector2Reader, + Vector3Reader: Vector3Reader, + Vector4Reader: Vector4Reader + }; + setReaders(Readers); + exports.Readers = Readers; exports.XnbContent = XnbContent; exports.XnbData = XnbData; + exports.addReaders = addReaders; exports.bufferToContents = bufferToContents; exports.bufferToXnb = bufferToXnb; exports.pack = pack; diff --git a/dist/xnb.es5.min.js b/dist/xnb.es5.min.js index 34b0d7a..4afba2f 100644 --- a/dist/xnb.es5.min.js +++ b/dist/xnb.es5.min.js @@ -1,2 +1,23 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},i=function(t){return t&&t.Math==Math&&t},a=i("object"==typeof globalThis&&globalThis)||i("object"==typeof window&&window)||i("object"==typeof self&&self)||i("object"==typeof n&&n)||function(){return this}()||Function("return this")(),o={},s=function(t){try{return!!t()}catch(t){return!0}},u=!s((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),h=!s((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),c=h,f=Function.prototype.call,l=c?f.bind(f):function(){return f.apply(f,arguments)},d={},v={}.propertyIsEnumerable,y=Object.getOwnPropertyDescriptor,w=y&&!v.call({1:2},1);d.f=w?function(t){var e=y(this,t);return!!e&&e.enumerable}:v;var _,g,b=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},m=h,k=Function.prototype,x=k.bind,E=k.call,A=m&&x.bind(E,E),S=m?function(t){return t&&A(t)}:function(t){return t&&function(){return E.apply(t,arguments)}},R=S,O=R({}.toString),U=R("".slice),T=function(t){return U(O(t),8,-1)},I=S,B=s,z=T,L=a.Object,P=I("".split),N=B((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==z(t)?P(t,""):L(t)}:L,C=a.TypeError,D=function(t){if(null==t)throw C("Can't call method on "+t);return t},j=N,V=D,M=function(t){return j(V(t))},F=function(t){return"function"==typeof t},Z=F,X=function(t){return"object"==typeof t?null!==t:Z(t)},W=a,H=F,G=function(t){return H(t)?t:void 0},Y=function(t,e){return arguments.length<2?G(W[t]):W[t]&&W[t][e]},K=S({}.isPrototypeOf),J=Y("navigator","userAgent")||"",q=a,$=J,Q=q.process,tt=q.Deno,et=Q&&Q.versions||tt&&tt.version,rt=et&&et.v8;rt&&(g=(_=rt.split("."))[0]>0&&_[0]<4?1:+(_[0]+_[1])),!g&&$&&(!(_=$.match(/Edge\/(\d+)/))||_[1]>=74)&&(_=$.match(/Chrome\/(\d+)/))&&(g=+_[1]);var nt=g,it=nt,at=s,ot=!!Object.getOwnPropertySymbols&&!at((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&it&&it<41})),st=ot&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,ut=Y,ht=F,ct=K,ft=st,lt=a.Object,dt=ft?function(t){return"symbol"==typeof t}:function(t){var e=ut("Symbol");return ht(e)&&ct(e.prototype,lt(t))},vt=a.String,pt=function(t){try{return vt(t)}catch(t){return"Object"}},yt=F,wt=pt,_t=a.TypeError,gt=function(t){if(yt(t))return t;throw _t(wt(t)+" is not a function")},bt=gt,mt=function(t,e){var r=t[e];return null==r?void 0:bt(r)},kt=l,xt=F,Et=X,At=a.TypeError,St={exports:{}},Rt=a,Ot=Object.defineProperty,Ut=function(t,e){try{Ot(Rt,t,{value:e,configurable:!0,writable:!0})}catch(r){Rt[t]=e}return e},Tt=Ut,It="__core-js_shared__",Bt=a[It]||Tt(It,{}),zt=Bt;(St.exports=function(t,e){return zt[t]||(zt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=D,Pt=a.Object,Nt=function(t){return Pt(Lt(t))},Ct=Nt,Dt=S({}.hasOwnProperty),jt=Object.hasOwn||function(t,e){return Dt(Ct(t),e)},Vt=S,Mt=0,Ft=Math.random(),Zt=Vt(1..toString),Xt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Zt(++Mt+Ft,36)},Wt=a,Ht=St.exports,Gt=jt,Yt=Xt,Kt=ot,Jt=st,qt=Ht("wks"),$t=Wt.Symbol,Qt=$t&&$t.for,te=Jt?$t:$t&&$t.withoutSetter||Yt,ee=function(t){if(!Gt(qt,t)||!Kt&&"string"!=typeof qt[t]){var e="Symbol."+t;Kt&&Gt($t,t)?qt[t]=$t[t]:qt[t]=Jt&&Qt?Qt(e):te(e)}return qt[t]},re=l,ne=X,ie=dt,ae=mt,oe=function(t,e){var r,n;if("string"===e&&xt(r=t.toString)&&!Et(n=kt(r,t)))return n;if(xt(r=t.valueOf)&&!Et(n=kt(r,t)))return n;if("string"!==e&&xt(r=t.toString)&&!Et(n=kt(r,t)))return n;throw At("Can't convert object to primitive value")},se=ee,ue=a.TypeError,he=se("toPrimitive"),ce=function(t,e){if(!ne(t)||ie(t))return t;var r,n=ae(t,he);if(n){if(void 0===e&&(e="default"),r=re(n,t,e),!ne(r)||ie(r))return r;throw ue("Can't convert object to primitive value")}return void 0===e&&(e="number"),oe(t,e)},fe=dt,le=function(t){var e=ce(t,"string");return fe(e)?e:e+""},de=X,ve=a.document,pe=de(ve)&&de(ve.createElement),ye=function(t){return pe?ve.createElement(t):{}},we=ye,_e=!u&&!s((function(){return 7!=Object.defineProperty(we("div"),"a",{get:function(){return 7}}).a})),ge=u,be=l,me=d,ke=b,xe=M,Ee=le,Ae=jt,Se=_e,Re=Object.getOwnPropertyDescriptor;o.f=ge?Re:function(t,e){if(t=xe(t),e=Ee(e),Se)try{return Re(t,e)}catch(t){}if(Ae(t,e))return ke(!be(me.f,t,e),t[e])};var Oe={},Ue=u&&s((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Te=a,Ie=X,Be=Te.String,ze=Te.TypeError,Le=function(t){if(Ie(t))return t;throw ze(Be(t)+" is not an object")},Pe=u,Ne=_e,Ce=Ue,De=Le,je=le,Ve=a.TypeError,Me=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Ze="enumerable",Xe="configurable",We="writable";Oe.f=Pe?Ce?function(t,e,r){if(De(t),e=je(e),De(r),"function"==typeof t&&"prototype"===e&&"value"in r&&We in r&&!r.writable){var n=Fe(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:Xe in r?r.configurable:n.configurable,enumerable:Ze in r?r.enumerable:n.enumerable,writable:!1})}return Me(t,e,r)}:Me:function(t,e,r){if(De(t),e=je(e),De(r),Ne)try{return Me(t,e,r)}catch(t){}if("get"in r||"set"in r)throw Ve("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var He=Oe,Ge=b,Ye=u?function(t,e,r){return He.f(t,e,Ge(1,r))}:function(t,e,r){return t[e]=r,t},Ke={exports:{}},Je=u,qe=jt,$e=Function.prototype,Qe=Je&&Object.getOwnPropertyDescriptor,tr=qe($e,"name"),er={EXISTS:tr,PROPER:tr&&"something"===function(){}.name,CONFIGURABLE:tr&&(!Je||Je&&Qe($e,"name").configurable)},rr=F,nr=Bt,ir=S(Function.toString);rr(nr.inspectSource)||(nr.inspectSource=function(t){return ir(t)});var ar,or,sr,ur=nr.inspectSource,hr=F,cr=ur,fr=a.WeakMap,lr=hr(fr)&&/native code/.test(cr(fr)),dr=St.exports,vr=Xt,pr=dr("keys"),yr=function(t){return pr[t]||(pr[t]=vr(t))},wr={},_r=lr,gr=a,br=S,mr=X,kr=Ye,xr=jt,Er=Bt,Ar=yr,Sr=wr,Rr="Object already initialized",Or=gr.TypeError,Ur=gr.WeakMap;if(_r||Er.state){var Tr=Er.state||(Er.state=new Ur),Ir=br(Tr.get),Br=br(Tr.has),zr=br(Tr.set);ar=function(t,e){if(Br(Tr,t))throw new Or(Rr);return e.facade=t,zr(Tr,t,e),e},or=function(t){return Ir(Tr,t)||{}},sr=function(t){return Br(Tr,t)}}else{var Lr=Ar("state");Sr[Lr]=!0,ar=function(t,e){if(xr(t,Lr))throw new Or(Rr);return e.facade=t,kr(t,Lr,e),e},or=function(t){return xr(t,Lr)?t[Lr]:{}},sr=function(t){return xr(t,Lr)}}var Pr={set:ar,get:or,has:sr,enforce:function(t){return sr(t)?or(t):ar(t,{})},getterFor:function(t){return function(e){var r;if(!mr(e)||(r=or(e)).type!==t)throw Or("Incompatible receiver, "+t+" required");return r}}},Nr=s,Cr=F,Dr=jt,jr=Oe.f,Vr=er.CONFIGURABLE,Mr=ur,Fr=Pr.enforce,Zr=Pr.get,Xr=!Nr((function(){return 8!==jr((function(){}),"length",{value:8}).length})),Wr=String(String).split("String"),Hr=Ke.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!Dr(t,"name")||Vr&&t.name!==e)&&jr(t,"name",{value:e,configurable:!0}),Xr&&r&&Dr(r,"arity")&&t.length!==r.arity&&jr(t,"length",{value:r.arity});var n=Fr(t);return Dr(n,"source")||(n.source=Wr.join("string"==typeof e?e:"")),t};Function.prototype.toString=Hr((function(){return Cr(this)&&Zr(this).source||Mr(this)}),"toString");var Gr=a,Yr=F,Kr=Ye,Jr=Ke.exports,qr=Ut,$r=function(t,e,r,n){var i=!!n&&!!n.unsafe,a=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,s=n&&void 0!==n.name?n.name:e;return Yr(r)&&Jr(r,s,n),t===Gr?(a?t[e]=r:qr(e,r),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=r:Kr(t,e,r),t)},Qr={},tn=Math.ceil,en=Math.floor,rn=function(t){var e=+t;return e!=e||0===e?0:(e>0?en:tn)(e)},nn=rn,an=Math.max,on=Math.min,sn=rn,un=Math.min,hn=function(t){return t>0?un(sn(t),9007199254740991):0},cn=function(t){return hn(t.length)},fn=M,ln=function(t,e){var r=nn(t);return r<0?an(r+e,0):on(r,e)},dn=cn,vn=function(t){return function(e,r,n){var i,a=fn(e),o=dn(a),s=ln(n,o);if(t&&r!=r){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===r)return t||s||0;return!t&&-1}},pn={includes:vn(!0),indexOf:vn(!1)},yn=jt,wn=M,_n=pn.indexOf,gn=wr,bn=S([].push),mn=function(t,e){var r,n=wn(t),i=0,a=[];for(r in n)!yn(gn,r)&&yn(n,r)&&bn(a,r);for(;e.length>i;)yn(n,r=e[i++])&&(~_n(a,r)||bn(a,r));return a},kn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Qr.f=Object.getOwnPropertyNames||function(t){return mn(t,kn)};var xn={};xn.f=Object.getOwnPropertySymbols;var En=Y,An=Qr,Sn=xn,Rn=Le,On=S([].concat),Un=En("Reflect","ownKeys")||function(t){var e=An.f(Rn(t)),r=Sn.f;return r?On(e,r(t)):e},Tn=jt,In=Un,Bn=o,zn=Oe,Ln=s,Pn=F,Nn=/#|\.prototype\./,Cn=function(t,e){var r=jn[Dn(t)];return r==Mn||r!=Vn&&(Pn(e)?Ln(e):!!e)},Dn=Cn.normalize=function(t){return String(t).replace(Nn,".").toLowerCase()},jn=Cn.data={},Vn=Cn.NATIVE="N",Mn=Cn.POLYFILL="P",Fn=Cn,Zn=a,Xn=o.f,Wn=Ye,Hn=$r,Gn=Ut,Yn=function(t,e,r){for(var n=In(e),i=zn.f,a=Bn.f,o=0;o=51&&/native code/.test(t))return!1;var r=new po((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};return(r.constructor={})[ko]=n,!(xo=r.then((function(){}))instanceof n)||!e&&bo&&!Eo})),So={CONSTRUCTOR:Ao,REJECTION_EVENT:Eo,SUBCLASSING:xo},Ro={},Oo=gt,Uo=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError("Bad Promise constructor");e=t,r=n})),this.resolve=Oo(e),this.reject=Oo(r)};Ro.f=function(t){return new Uo(t)};var To,Io,Bo,zo=Jn,Lo=qn,Po=a,No=l,Co=$r,Do=ai,jo=function(t,e,r){t&&!r&&(t=t.prototype),t&&!si(t,ui)&&oi(t,ui,{configurable:!0,value:e})},Vo=function(t){var e=hi(t),r=ci.f;fi&&e&&!e[li]&&r(e,li,{configurable:!0,get:function(){return this}})},Mo=gt,Fo=F,Zo=X,Xo=function(t,e){if(di(e,t))return t;throw vi("Incorrect invocation")},Wo=Yi,Ho=Fa.set,Go=oo,Yo=function(t,e){var r=so.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ko=uo,Jo=co,qo=Pr,$o=fo,Qo=Ro,ts="Promise",es=So.CONSTRUCTOR,rs=So.REJECTION_EVENT,ns=So.SUBCLASSING,is=qo.getterFor(ts),as=qo.set,os=$o&&$o.prototype,ss=$o,us=os,hs=Po.TypeError,cs=Po.document,fs=Po.process,ls=Qo.f,ds=ls,vs=!!(cs&&cs.createEvent&&Po.dispatchEvent),ps="unhandledrejection",ys=function(t){var e;return!(!Zo(t)||!Fo(e=t.then))&&e},ws=function(t,e){var r,n,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,c=t.domain;try{s?(o||(2===e.rejection&&ks(e),e.rejection=1),!0===s?r=a:(c&&c.enter(),r=s(a),c&&(c.exit(),i=!0)),r===t.promise?h(hs("Promise-chain cycle")):(n=ys(r))?No(n,r,u,h):u(r)):h(a)}catch(t){c&&!i&&c.exit(),h(t)}},_s=function(t,e){t.notified||(t.notified=!0,Go((function(){for(var r,n=t.reactions;r=n.get();)ws(r,t);t.notified=!1,e&&!t.rejection&&bs(t)})))},gs=function(t,e,r){var n,i;vs?((n=cs.createEvent("Event")).promise=e,n.reason=r,n.initEvent(t,!1,!0),Po.dispatchEvent(n)):n={promise:e,reason:r},!rs&&(i=Po["on"+t])?i(n):t===ps&&Yo("Unhandled promise rejection",r)},bs=function(t){No(Ho,Po,(function(){var e,r=t.facade,n=t.value;if(ms(t)&&(e=Ko((function(){Lo?fs.emit("unhandledRejection",n,r):gs(ps,r,n)})),t.rejection=Lo||ms(t)?2:1,e.error))throw e.value}))},ms=function(t){return 1!==t.rejection&&!t.parent},ks=function(t){No(Ho,Po,(function(){var e=t.facade;Lo?fs.emit("rejectionHandled",e):gs("rejectionhandled",e,t.value)}))},xs=function(t,e,r){return function(n){t(e,n,r)}},Es=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,_s(t,!0))},As=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw hs("Promise can't be resolved itself");var n=ys(e);n?Go((function(){var r={done:!1};try{No(n,e,xs(As,r,t),xs(Es,r,t))}catch(e){Es(r,e,t)}})):(t.value=e,t.state=1,_s(t,!1))}catch(e){Es({done:!1},e,t)}}};if(es&&(us=(ss=function(t){Xo(this,us),Mo(t),No(To,this);var e=is(this);try{t(xs(As,e),xs(Es,e))}catch(t){Es(e,t)}}).prototype,(To=function(t){as(this,{type:ts,done:!1,notified:!1,parent:!1,reactions:new Jo,rejection:!1,state:0,value:void 0})}).prototype=Co(us,"then",(function(t,e){var r=is(this),n=ls(Wo(this,ss));return r.parent=!0,n.ok=!Fo(t)||t,n.fail=Fo(e)&&e,n.domain=Lo?fs.domain:void 0,0==r.state?r.reactions.add(n):Go((function(){ws(n,r)})),n.promise})),Io=function(){var t=new To,e=is(t);this.promise=t,this.resolve=xs(As,e),this.reject=xs(Es,e)},Qo.f=ls=function(t){return t===ss||undefined===t?new Io(t):ds(t)},Fo($o)&&os!==Object.prototype)){Bo=os.then,ns||Co(os,"then",(function(t,e){var r=this;return new ss((function(t,e){No(Bo,r,t,e)})).then(t,e)}),{unsafe:!0});try{delete os.constructor}catch(t){}Do&&Do(os,us)}zo({global:!0,wrap:!0,forced:es},{Promise:ss}),jo(ss,ts,!1),Vo(ts);var Ss={},Rs=Ss,Os=ee("iterator"),Us=Array.prototype,Ts=xi,Is=mt,Bs=Ss,zs=ee("iterator"),Ls=function(t){if(null!=t)return Is(t,zs)||Is(t,"@@iterator")||Bs[Ts(t)]},Ps=l,Ns=gt,Cs=Le,Ds=pt,js=Ls,Vs=a.TypeError,Ms=l,Fs=Le,Zs=mt,Xs=na,Ws=l,Hs=Le,Gs=pt,Ys=function(t){return void 0!==t&&(Rs.Array===t||Us[Os]===t)},Ks=cn,Js=K,qs=function(t,e){var r=arguments.length<2?js(t):e;if(Ns(r))return Cs(Ps(r,t));throw Vs(Ds(t)+" is not iterable")},$s=Ls,Qs=function(t,e,r){var n,i;Fs(t);try{if(!(n=Zs(t,"return"))){if("throw"===e)throw r;return r}n=Ms(n,t)}catch(t){i=!0,n=t}if("throw"===e)throw r;if(i)throw n;return Fs(n),r},tu=a.TypeError,eu=function(t,e){this.stopped=t,this.result=e},ru=eu.prototype,nu=function(t,e,r){var n,i,a,o,s,u,h,c=r&&r.that,f=!(!r||!r.AS_ENTRIES),l=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=Xs(e,c),p=function(t){return n&&Qs(n,"normal",t),new eu(!0,t)},y=function(t){return f?(Hs(t),d?v(t[0],t[1],p):v(t[0],t[1])):d?v(t,p):v(t)};if(l)n=t;else{if(!(i=$s(t)))throw tu(Gs(t)+" is not iterable");if(Ys(i)){for(a=0,o=Ks(t);o>a;a++)if((s=y(t[a]))&&Js(ru,s))return s;return new eu(!1)}n=qs(t,i)}for(u=n.next;!(h=Ws(u,n)).done;){try{s=y(h.value)}catch(t){Qs(n,"throw",t)}if("object"==typeof s&&s&&Js(ru,s))return s}return new eu(!1)};function iu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function au(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),h=n.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;R(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:U(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var oh=le,sh=Oe,uh=b,hh=Un,ch=M,fh=o,lh=function(t,e,r){var n=oh(e);n in t?sh.f(t,n,uh(0,r)):t[n]=r};Jn({target:"Object",stat:!0,sham:!u},{getOwnPropertyDescriptors:function(t){for(var e,r,n=ch(t),i=fh.f,a=hh(n),o={},s=0;a.length>s;)void 0!==(r=i(n,e=a[s++]))&&lh(o,e,r);return o}});var dh=u,vh=er.EXISTS,ph=S,yh=Oe.f,wh=Function.prototype,_h=ph(wh.toString),gh=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,bh=ph(gh.exec);dh&&!vh&&yh(wh,"name",{configurable:!0,get:function(){try{return bh(gh,_h(this))[1]}catch(t){return""}}});var mh,kh,xh,Eh="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,Ah=!s((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Sh=a,Rh=jt,Oh=F,Uh=Nt,Th=Ah,Ih=yr("IE_PROTO"),Bh=Sh.Object,zh=Bh.prototype,Lh=Th?Bh.getPrototypeOf:function(t){var e=Uh(t);if(Rh(e,Ih))return e[Ih];var r=e.constructor;return Oh(r)&&e instanceof r?r.prototype:e instanceof Bh?zh:null},Ph=Eh,Nh=u,Ch=a,Dh=F,jh=X,Vh=jt,Mh=xi,Fh=pt,Zh=Ye,Xh=$r,Wh=Oe.f,Hh=K,Gh=Lh,Yh=ai,Kh=ee,Jh=Xt,qh=Ch.Int8Array,$h=qh&&qh.prototype,Qh=Ch.Uint8ClampedArray,tc=Qh&&Qh.prototype,ec=qh&&Gh(qh),rc=$h&&Gh($h),nc=Object.prototype,ic=Ch.TypeError,ac=Kh("toStringTag"),oc=Jh("TYPED_ARRAY_TAG"),sc=Jh("TYPED_ARRAY_CONSTRUCTOR"),uc=Ph&&!!Yh&&"Opera"!==Mh(Ch.opera),hc=!1,cc={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},fc={BigInt64Array:8,BigUint64Array:8},lc=function(t){if(!jh(t))return!1;var e=Mh(t);return Vh(cc,e)||Vh(fc,e)};for(mh in cc)(xh=(kh=Ch[mh])&&kh.prototype)?Zh(xh,sc,kh):uc=!1;for(mh in fc)(xh=(kh=Ch[mh])&&kh.prototype)&&Zh(xh,sc,kh);if((!uc||!Dh(ec)||ec===Function.prototype)&&(ec=function(){throw ic("Incorrect invocation")},uc))for(mh in cc)Ch[mh]&&Yh(Ch[mh],ec);if((!uc||!rc||rc===nc)&&(rc=ec.prototype,uc))for(mh in cc)Ch[mh]&&Yh(Ch[mh].prototype,rc);if(uc&&Gh(tc)!==rc&&Yh(tc,rc),Nh&&!Vh(rc,ac))for(mh in hc=!0,Wh(rc,ac,{get:function(){return jh(this)?this[oc]:void 0}}),cc)Ch[mh]&&Zh(Ch[mh],oc,mh);var dc={NATIVE_ARRAY_BUFFER_VIEWS:uc,TYPED_ARRAY_CONSTRUCTOR:sc,TYPED_ARRAY_TAG:hc&&oc,aTypedArray:function(t){if(lc(t))return t;throw ic("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Dh(t)&&(!Yh||Hh(ec,t)))return t;throw ic(Fh(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if(Nh){if(r)for(var i in cc){var a=Ch[i];if(a&&Vh(a.prototype,t))try{delete a.prototype[t]}catch(r){try{a.prototype[t]=e}catch(t){}}}rc[t]&&!r||Xh(rc,t,r?e:uc&&$h[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if(Nh){if(Yh){if(r)for(n in cc)if((i=Ch[n])&&Vh(i,t))try{delete i[t]}catch(t){}if(ec[t]&&!r)return;try{return Xh(ec,t,r?e:uc&&ec[t]||e)}catch(t){}}for(n in cc)!(i=Ch[n])||i[t]&&!r||Xh(i,t,e)}},isView:function(t){if(!jh(t))return!1;var e=Mh(t);return"DataView"===e||Vh(cc,e)||Vh(fc,e)},isTypedArray:lc,TypedArray:ec,TypedArrayPrototype:rc},vc=T,pc=a,yc=Array.isArray||function(t){return"Array"==vc(t)},wc=Mi,_c=X,gc=ee("species"),bc=pc.Array,mc=function(t){var e;return yc(t)&&(e=t.constructor,(wc(e)&&(e===bc||yc(e.prototype))||_c(e)&&null===(e=e[gc]))&&(e=void 0)),void 0===e?bc:e},kc=na,xc=N,Ec=Nt,Ac=cn,Sc=function(t,e){return new(mc(t))(0===e?0:e)},Rc=S([].push),Oc=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,a=6==t,o=7==t,s=5==t||a;return function(u,h,c,f){for(var l,d,v=Ec(u),p=xc(v),y=kc(h,c),w=Ac(p),_=0,g=f||Sc,b=e?g(u,w):r||o?g(u,0):void 0;w>_;_++)if((s||_ in p)&&(d=y(l=p[_],_,v),t))if(e)b[_]=d;else if(d)switch(t){case 3:return!0;case 5:return l;case 6:return _;case 2:Rc(b,l)}else switch(t){case 4:return!1;case 7:Rc(b,l)}return a?-1:n||i?i:b}},Uc={forEach:Oc(0),map:Oc(1),filter:Oc(2),some:Oc(3),every:Oc(4),find:Oc(5),findIndex:Oc(6),filterReject:Oc(7)},Tc=Yi,Ic=dc.TYPED_ARRAY_CONSTRUCTOR,Bc=dc.aTypedArrayConstructor,zc=Uc.map,Lc=function(t){return Bc(Tc(t,t[Ic]))},Pc=dc.aTypedArray;(0,dc.exportTypedArrayMethod)("map",(function(t){return zc(Pc(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Lc(t))(e)}))}));var Nc=[192,224,240],Cc=128,Dc=63,jc=[55296,56320],Vc=1023;function Mc(t){return t<128?[t]:t<2048?[Nc[0]|t>>6,Cc|t&Dc]:t<65536?[Nc[1]|t>>12,Cc|t>>6&Dc,Cc|t&Dc]:[Nc[2]|t>>18,Cc|t>>12&Dc,Cc|t>>6&Dc,Cc|t&Dc]}function Fc(t){return t<65535?[t]:[jc[0]|(t-=65536)>>10&Vc,jc[1]|t&Vc]}function Zc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var r=t.length;return 1===r?t[0]:2===r?((t[0]^Nc[0])<<6)+(t[1]^Cc):3===r?((t[0]^Nc[1])<<12)+((t[1]^Cc)<<6)+(t[2]^Cc):((t[0]^Nc[2])<<18)+((t[1]^Cc)<<12)+((t[2]^Cc)<<6)+(t[3]^Cc)}function Xc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&Vc)<<10)+(t[1]&Vc)+65536}function Wc(t){return function(t){for(var e=[],r=0;r1&&void 0!==arguments[1])||arguments[1];hu(this,t),this._endianus=r,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return fu(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,r=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:0,e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0;){var n=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(n&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,r|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),Yc=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;hu(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return fu(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e),n=0;n>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),Kc=function(t){du(r,t);var e=mu(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return hu(this,r),(t=e.call(this,n)).name=t.constructor.name,t.message=n,Error.captureStackTrace(gu(t),r),t}return fu(r)}(_u(Error)),Jc=256,qc=0,$c=1,Qc=2,tf=3,ef=656,rf=function(){function t(e){if(hu(this,t),this.window_size=1<21)throw new Kc("Window size out of range!");if(!t.extra_bits.length)for(var r=0,n=0;r<=50;r+=2)t.extra_bits[r]=t.extra_bits[r+1]=n,0!=r&&n<17&&n++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case Qc:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case $c:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(ef,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case tf:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new Kc("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new Kc("Cannot run outside of window frame.");switch(this.block_type){case Qc:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,ef,12);if(h>3;if(f>2){var l=t.extra_bits[f];if(f=t.position_base[f]-2,l>3)l-=3,f+=e.readLZXBits(l)<<3,f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?f+=e.readLZXBits(l):f=1;this.R2=this.R1,this.R1=this.R0,this.R0=f}else 0===f?f=this.R0:1==f?(f=this.R1,this.R1=this.R0,this.R0=f):(f=this.R2,this.R2=this.R0,this.R0=f);var d=this.window_posn,v=void 0;if(u-=c,this.window_posn>=f)v=d-f;else{v=d+(this.window_size-f);var p=f-this.window_posn;if(p0;)this.win[d++]=this.win[v++];v=0}}for(this.window_posn+=c;c-- >0;)this.win[d++]=this.win[v++]}}break;case $c:for(;u>0;){var y=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,ef,12);if(y>3;if(_>2){if(3!=_){var g=t.extra_bits[_],b=e.readLZXBits(g);_=t.position_base[_]-2+b}else _=1;this.R2=this.R1,this.R1=this.R0,this.R0=_}else 0===_?_=this.R0:1==_?(_=this.R1,this.R1=this.R0,this.R0=_):(_=this.R2,this.R2=this.R0,this.R0=_);var m=this.window_posn,k=void 0;if(u-=w,this.window_posn>=_)k=m-_;else{k=m+(this.window_size-_);var x=_-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=w;w-- >0;)this.win[m++]=this.win[k++]}}break;case tf:if(e.bytePosition+u>n)throw new Kc("Overrun!"+n+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new Kc("Overrun table!");for(var c=o;c-- >0;)n[h++]=u}o>>=1}if(i==a)return n;for(var f=i;f>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var v=0;v>16,y=0;y>15-y&1&&p++;if(n[p]=v,(i+=o)>a)throw new Kc("Overrun table during decoding.")}o>>=1}if(i==a)return n;throw new Kc("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,r,n,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=n){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=n)}return t.bitPosition+=r[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var r=this.R2;this.R2=this.R0,this.R0=r}}}]),t}();rf.position_base=[],rf.extra_bits=[];var nf=function(){function t(){hu(this,t)}return fu(t,null,[{key:"decompress",value:function(t,e,r){for(var n,i,a=0,o=new rf(16),s=new Yc(r);a65536||i>65536)throw new Kc("Invalid size read in compression content.");s.write(o.decompress(t,i,n)),a+=n}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),af=function(){function t(){hu(this,t)}return fu(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}},{key:"readU32",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}},{key:"writeU32",value:function(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}},{key:"imul",value:function(t,e){var r=65535&t,n=65535&e;return r*n+((t>>>16)*n+r*(e>>>16)<<16)|0}}]),t}(),of=65536,sf=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),r=0;r=13)for(var d=67;r+4>>0;if(a=i[p=(p>>16^p)>>>0&65535]-1,i[p]=r+1,a<0||r-a>>>16>0||af.readU32(t,a)!==v)r+=d++>>6;else{for(d=67,h=r-o,u=r-a,a+=4,s=r+=4;r=sf){for(e[c++]=240+y,l=h-sf;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=(h<<4)+y;for(var w=0;w>8,s>=15){for(l=s-15;l>=255;l-=255)e[c++]=255;e[c++]=l}o=r}}if(0===o)return 0;if((h=f-o)>=sf){for(e[c++]=240,l=h-sf;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=h<<4;for(r=o;r")}}]),r}(ff),_f=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){var e=(new pf).read(t);return{export:{type:this.type,data:e}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),(new pf).write(t,e.export.data,null)}},{key:"isValueType",value:function(){return!1}}]),r}(ff),gf=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){return Boolean(t.readInt())}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}]),r}(ff),bf=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){var e=this._getCharSize(t.peekInt());return t.readString(e)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeString(e)}},{key:"_getCharSize",value:function(t){return 1+(3841982464>>(t>>3&30)&3)}}]),r}(ff),mf=function(t){du(r,t);var e=mu(r);function r(t,n){var i;if(hu(this,r),null==t||null==n)throw new Kc("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return fu(r,[{key:"read",value:function(t,e){for(var r={},n=(new yf).read(t),i=0;i")}}]),r}(ff),kf=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}]),r}(ff),xf=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){var e=(new yf).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new yf).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}]),r}(ff),Ef=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}]),r}(ff),Af=function(t){du(r,t);var e=mu(r);function r(t){var n;return hu(this,r),(n=e.call(this)).reader=t,n}return fu(r,[{key:"read",value:function(t,e){for(var r=(new yf).read(t),n=[],i=0;i")}}]),r}(ff),Sf=function(t){du(r,t);var e=mu(r);function r(t){var n;return hu(this,r),(n=e.call(this)).reader=t,n}return fu(r,[{key:"read",value:function(t,e){return(new gf).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}},{key:"write",value:function(t,e,r){new gf,t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}]),r}(ff),Rf=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){var e=new Ef;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new Ef;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}]),r}(ff),Of=function(t){du(r,t);var e=mu(r);function r(){return hu(this,r),e.apply(this,arguments)}return fu(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}]),r}(ff),Uf=256;function Tf(t,e,r,n){for(var i=Array(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),a=Array(r),o=0;o=Math.abs(i);){var c=h[0][0],f=h[0][1],l=Tf(c,f,If(t[c][c],t[f][f],t[c][f]),r);t=zf(l,t),a=Lf(a,l),h=Bf(t)}for(var d=0;d0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;hu(this,t),this._values=[e,r,n]}return fu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Df(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;hu(this,t),this._values=[e,r,n,i]}return fu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new Cf(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var a=0;a<4;a++)n[i+4+a]=r[4*a+0]|r[4*a+1]<<2|r[4*a+2]<<4|r[4*a+3]<<6}function Gf(t,e,r,n,i){var a,o=Wf(t),s=Wf(e);if(o<=s)a=r.slice();else{var u=[s,o];o=u[0],s=u[1],a=r.map((function(t){return 0===t?1:1===t?0:t}))}Hf(o,s,a,n,i)}function Yf(t,e,r,n,i){var a,o=Wf(t),s=Wf(e);if(o=128||!i)){var l=this._remap[s],d=(e[4*o+3]+1)/256;this._weights[l]+=a?d:1,this._remap[o]=l;break}}else this._remap[o]=-1}for(var v=0;v=n?t:(n=o,a)}),0);return i+=n,a}));if(is&&(a=r[h],s=c)}this.start=i.clampGrid().clone(),this.end=a.clampGrid().clone()}}}]),r}(Jf),Qf=function(t){du(r,t);var e=mu(r);function r(t){var n;hu(this,r);(n=e.call(this,t)).iterationCount=t.flags&Uf?8:1,n.bestError=1/0,n.metric=new Df(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,a=i.points,o=i.weights;return n.principle=jf(a,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Df(0),n}return fu(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Df(.5,.5,.5,1/4),a=Df.multiplyAdd(r,i,e),o=a.splatW,s=Df.multiplyAdd(r,i,n);return{ax:a,aa:o,bx:s,bb:s.splatW,ab:Df.multVector(r,i).splatW}}),(function(r,n,i){return Gf(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=new Df(1/3,1/3,1/3,1/9),o=new Df(2/3,2/3,2/3,4/9),s=new Df(2/9),u=Df.multiplyAdd(n,a,Df.multiplyAdd(r,o,e)),h=u.splatW,c=Df.multiplyAdd(r,a,Df.multiplyAdd(n,o,i));return{ax:u,aa:h,bx:c,bb:c.splatW,ab:Df.multVector(s,Df.add(r,n)).splatW}}),(function(r,n,i){return Yf(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Df(0),end:new Df(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var a=function(e,n){var a=t(e),o=r.computeOptimalPoints(a);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var a={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(a.bestK=i),a},a=new Df(0),o=0;o15?15:e}function el(t,e,r,n){var i=rl(t,e,5),a=rl(t,e,7);i.error<=a.error?function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){il(i,n,a.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else il(n,i,a,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){il(i,n,a.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else il(n,i,a,e,r)}(a,r,n)}function rl(t,e,r){var n=function(t,e,r){for(var n=255,i=0,a=0;a<16;a++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*c&255;n[o]=f,o++}}}function al(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function ol(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function sl(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,a=al(n),o=al(i);return[a,o,ol(a,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:ol(a,o,2/3)]}(e,r,n),a=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var a=t[r+i];n[4*i+0]=3&a,n[4*i+1]=a>>2&3,n[4*i+2]=a>>4&3,n[4*i+3]=a>>6&3}return n}(e,r),o=0;o<16;o++)for(var s=0;s<4;s++)t[4*o+s]=i[a[o]][s]}function ul(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function hl(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=Uf&&(r=8),64!=n&&(n=32),e|r|n|128&t}function cl(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,a=r.y,o=void 0===a?0:a,s=r.width,u=void 0===s?0:s,h=r.height,c=void 0===h?0:h,f=0;ul((function(r,n){var a=i+r,s=o+n;if(a>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],a=nl(n,i,n<=i?5:7),o=new Uint8Array(16),s=0,u=2,h=0;h<2;h++){for(var c=0,f=0;f<3;f++)c|=e[r+u]<<8*f,u++;for(var l=0;l<8;l++){var d=c>>3*l&7;o[s]=d,s++}}for(var v=0;v<16;++v)t[4*v+3]=a[o[v]]}(t,e,r)}function dl(t,e,r,n,i){var a=0!=(1&(i=hl(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,a=void 0===i?0:i,o=e.width,s=void 0===o?0:o,u=e.height,h=void 0===u?0:u,c=new Uint8Array(64),f=0,l=0;return ul((function(e,r){var i=n+e,o=a+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var s=r.read(t),u=t.read(s);if(4==n)u=_l(u,i,a,vl);else if(5==n)u=_l(u,i,a,pl);else if(6==n)u=_l(u,i,a,yl);else{if(2==n)throw new Kc("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Kc("Non-implemented Texture2D format type (".concat(n,") found."))}for(var h=0;h");switch(n){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return"Boolean";case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return"Char";case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return"Int32";case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return"String";case"Microsoft.Xna.Framework.Content.DictionaryReader":var i=Rl(r).map(t);return"Dictionary<".concat(i[0],",").concat(i[1],">");case"Microsoft.Xna.Framework.Content.ArrayReader":var a=Rl(r).map(t);return"Array<".concat(a,">");case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":var o=Rl(r).map(t);return"List<".concat(o,">");case"Microsoft.Xna.Framework.Content.Texture2DReader":return"Texture2D";case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return"Vector2";case"Microsoft.Xna.Framework.Content.Vector3Reader":case"Microsoft.Xna.Framework.Vector3":return"Vector3";case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return"Vector4";case"Microsoft.Xna.Framework.Content.SpriteFontReader":return"SpriteFont";case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return"Rectangle";case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return"Effect";case"xTile.Pipeline.TideReader":return"TBin";case"BmFont.XmlSourceReader":return"BmFont";default:throw new Kc('Non-implemented type found, cannot resolve type "'.concat(n,'", "').concat(r,'".'))}},Rl=function(t){var e=t.split("`")[1];e.slice(0,1);return(e=e.slice(2,-1)).match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((function(t){return t.slice(1,-1)}))},Ol=function(t){var e=t.match(/[^<]+/)[0],r=t.match(/<(.+)>/);return r=r?r[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:r}},Ul=function t(e){var r=Ol(e),n=r.type,i=r.subtypes;if(i=i.map(t),Al.hasOwnProperty("".concat(n,"Reader")))return wu(Al["".concat(n,"Reader")],i);throw new Kc('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))},Tl=function(){function t(e,r,n){hu(this,t);var i=e.target,a=e.formatVersion,o=e.hidef,s=e.compressed;this.header={target:i,formatVersion:a,hidef:o,compressed:s},this.readers=r,this.content=n}return fu(t,[{key:"target",get:function(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}},{key:"formatVersion",get:function(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}},{key:"hidef",get:function(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}},{key:"compressed",get:function(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}},{key:"contentType",get:function(){var t=this.content.export;return void 0!==t?t.type:"JSON"}},{key:"rawContent",get:function(){var t=this.content.export;return void 0!==t?t.data:JSON.stringify(this.content,(function(t,e){return"export"===t?e.type:e}),4)}},{key:"stringify",value:function(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}},{key:"toString",value:function(){return this.stringify()}}]),t}();var Il=fu((function t(e,r){hu(this,t),this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(r),this.content=e})),Bl=64,zl=128,Ll=14,Pl=function(){function t(){hu(this,t),this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}return fu(t,[{key:"load",value:function(t){if(this.buffer=new Gc(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new Kc("XNB file has been truncated!");if(this.compressed){var e=this.buffer.readUInt32();if(this.compressionType==zl){var r=this.fileSize-Ll,n=nf.decompress(this.buffer,r,e);this.buffer.copyFrom(n,Ll,0,e),this.buffer.bytePosition=Ll}else if(this.compressionType==Bl){var i=this.buffer.buffer.slice(Ll),a=new Uint8Array(i),o=new Uint8Array(e);!function(t,e){var r,n,i,a,o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,c=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(r=15&f,n=t[s++]|t[s++]<<8,15===r)for(;r+=t[s],255===t[s++];);if(r+=4,c&&1===n)e.fill(0|e[h-1],h,h+r),h+=r;else if(c&&n>r&&r>31)e.copyWithin(h,h-n,h-n+r),h+=r;else for(a=(o=h-n)+r;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var r=0,n=t.length,i=0,a=Math.max(32,n+(n>>1)+7),o=new Uint8Array(a>>3<<3);r=55296&&s<=56319){if(r=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+r/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var r=new Uint8Array(t),n=0,i=r.length,a=[];n65535&&(c-=65536,a.push(c>>>10&1023|55296),c=56320|1023&c),a.push(c)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Cl={};function Dl(t){var e=Cl[t];if(void 0!==e)return e.exports;var r=Cl[t]={exports:{}};return Nl[t].call(r.exports,r,r.exports,Dl),r.exports}Dl.d=function(t,e){for(var r in e)Dl.o(e,r)&&!Dl.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},Dl.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var jl={};!function(){Dl.d(jl,{P:function(){return Rr},m:function(){return Sr}}),Dl(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,r=function(){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};hu(this,r);var n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=n?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return fu(r,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="",r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(r),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),r}();function n(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);n(u);var h=new Array(60);n(h);var c=new Array(512);n(c);var f=new Array(256);n(f);var l=new Array(29);n(l);var d,v,p,y=new Array(30);function w(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}function _(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(y);var g=function(t){return t<256?c[t]:c[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,r){t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<>>=1,r<<=1}while(--e>0);return r>>>1},E=function(t,e,r){var n,i,a=new Array(16),o=0;for(n=1;n<=15;n++)a[n]=o=o+r[n-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},A=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},S=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},R=function(t,e,r,n){var i=2*e,a=2*r;return t[i]>1;r>=1;r--)O(t,a,r);i=u;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,a,1),n=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=n,a[2*i]=a[2*r]+a[2*n],t.depth[i]=(t.depth[r]>=t.depth[n]?t.depth[r]:t.depth[n])+1,a[2*r+1]=a[2*n+1]=i,t.heap[1]=i++,O(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var r,n,i,a,o,s,u=e.dyn_tree,h=e.max_code,c=e.stat_desc.static_tree,f=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,v=e.stat_desc.max_length,p=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,r=t.heap_max+1;r<573;r++)(a=u[2*u[2*(n=t.heap[r])+1]+1]+1)>v&&(a=v,p++),u[2*n+1]=a,n>h||(t.bl_count[a]++,o=0,n>=d&&(o=l[n-d]),s=u[2*n],t.opt_len+=s*(a+o),f&&(t.static_len+=s*(c[2*n+1]+o)));if(0!==p){do{for(a=v-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[v]--,p-=2}while(p>0);for(a=v;0!==a;a--)for(n=t.bl_count[a];0!==n;)(i=t.heap[--r])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),n--)}}(t,e),E(a,h,t.bl_count)},I=function(t,e,r){var n,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(r+1)+1]=65535,n=0;n<=r;n++)i=o,o=e[2*(n+1)+1],++s>=7;n<30;n++)for(y[n]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(I(t,t.dyn_ltree,t.l_desc.max_code),I(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==e?L(t,e,r,n):4===t.strategy||a===i?(m(t,2+(n?1:0),3),U(t,u,h)):(m(t,4+(n?1:0),3),function(t,e,r,n){var i;for(m(t,e-257,5),m(t,r-1,5),m(t,n-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(f[r]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},j=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},V=function(t,e,r,n){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+e[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},M=new Uint32Array(function(){for(var t,e=[],r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e}()),F=function(t,e,r,n){var i=M,a=n+r;t^=-1;for(var o=n;o>>8^i[255&(t^e[o])];return-1^t},Z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},W=P,H=N,G=C,Y=D,K=j,J=X.Z_NO_FLUSH,q=X.Z_PARTIAL_FLUSH,$=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,rt=X.Z_STREAM_END,nt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ct=X.Z_FIXED,ft=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,vt=262,pt=103,yt=113,wt=666,_t=function(t,e){return t.msg=Z[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,r){return(e<t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},At=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},St=function(t,e,r,n){var i=t.avail_in;return i>n&&(i=n),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),1===t.state.wrap?t.adler=V(t.adler,e,i,r):2===t.state.wrap&&(t.adler=F(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},Rt=function(t,e){var r,n,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-vt?t.strstart-(t.w_size-vt):0,h=t.window,c=t.w_mask,f=t.prev,l=t.strstart+dt,d=h[a+o-1],v=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(r=e)+o]===v&&h[r+o-1]===d&&h[r]===h[a]&&h[++r]===h[a+1]){a+=2,r++;do{}while(h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&ao){if(t.match_start=e,o=n,n>=s)break;d=h[a+o-1],v=h[a+o]}}}while((e=f[e&c])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ot=function(t){var e,r,n,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-vt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=r=t.hash_size;do{n=t.head[--e],t.head[e]=n>=o?n-o:0}while(--r);e=r=o;do{n=t.prev[--e],t.prev[e]=n>=o?n-o:0}while(--r);i+=o}if(0===t.strm.avail_in)break;if(r=St(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=r,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-vt&&(t.match_length=Rt(t,r)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var r,n,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((n=Y(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Bt=[new It(0,0,0,0,(function(t,e){var r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ot(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+r;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-vt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,Ut),new It(4,5,16,8,Ut),new It(4,6,32,32,Ut),new It(4,4,16,16,Tt),new It(8,16,32,32,Tt),new It(8,16,128,128,Tt),new It(8,32,128,256,Tt),new It(32,128,258,1024,Tt),new It(32,258,258,4096,Tt)];function zt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Lt=function(t){var e,r=function(t){if(!t||!t.state)return _t(t,nt);t.total_in=t.total_out=0,t.data_type=ft;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:yt,t.adler=2===e.wrap?0:1,e.last_flush=J,W(e),et}(t);return r===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),r},Pt=function(t,e,r,n,i,a){if(!t)return nt;var o=1;if(e===ot&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>9||r!==lt||n<8||n>15||e<0||e>9||a<0||a>ct)return _t(t,nt);8===n&&(n=9);var s=new zt;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<tt||e<0)return t?_t(t,nt):nt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===wt&&e!==Q)return _t(t,0===t.avail_out?at:nt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=F(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=yt);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=yt,At(i,o),0!==i.strstart&&(At(i,t.adler>>>16),At(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=F(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=pt)}else i.status=pt;if(i.status===pt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=yt)):i.status=yt),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return _t(t,at);if(i.status===wt&&0!==t.avail_in)return _t(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==wt){var s=i.strategy===ut?function(t,e){for(var r;;){if(0===t.lookahead&&(Ot(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var r,n,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ot(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((n=o[i=t.strstart-1])===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+dt;do{}while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=wt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===q?K(i):e!==tt&&(H(i,0,0,!1),e===$&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?rt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(At(i,t.adler>>>16),At(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:rt)},Ct=function(t){if(!t||!t.state)return nt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==pt&&e!==yt&&e!==wt?_t(t,nt):(t.state=null,e===yt?_t(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},jt=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var r=e.shift();if(r){if("object"!=ou(r))throw new TypeError(r+"must be non-object");for(var n in r)Dt(r,n)&&(t[n]=r[n])}}return t},Vt=function(t){for(var e=0,r=0,n=t.length;r=252?6:Zt>=248?5:Zt>=240?4:Zt>=224?3:Zt>=192?2:1;Ft[254]=Ft[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,r,n,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&r):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|63&r):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|63&r);return e},Wt=function(t,e){var r,n,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Mt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var r="",n=0;nt.length&&(e=t.length);for(var r=e-1;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Ft[t[r]]>e?r:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Yt=Object.prototype.toString,Kt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,qt=X.Z_FULL_FLUSH,$t=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,re=X.Z_DEFAULT_STRATEGY,ne=X.Z_DEFLATED;function ie(t){this.options=jt({level:ee,method:ne,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Qt)throw new Error(Z[r]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Yt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=function(t,e){var r=e.length;if(!t||!t.state)return nt;var n=t.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return nt;if(1===i&&(t.adler=V(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){0===i&&(bt(n.head),n.strstart=0,n.block_start=0,n.insert=0);var a=new Uint8Array(n.w_size);a.set(e.subarray(r-n.w_size,r),0),e=a,r=n.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Ot(n);n.lookahead>=3;){var h=n.strstart,c=n.lookahead-2;do{n.ins_h=mt(n,n.ins_h,n.window[h+3-1]),n.prev[h&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=h,h++}while(--c);n.strstart=h,n.lookahead=2,Ot(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,n.wrap=i,et}(this.strm,n),r!==Qt)throw new Error(Z[r]);this._dict_set=!0}}function ae(t,e){var r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||Z[r.err];return r.result}ie.prototype.push=function(t,e){var r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=e===~~e?e:!0===e?$t:Kt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Yt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===Jt||n===qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((r=Nt(i,n))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ct(this.strm),this.onEnd(r),this.ended=!0,r===Qt;if(0!==i.avail_out){if(n>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Vt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,A,S=t.state;r=t.next_in,E=t.input,n=r+(t.avail_in-5),i=t.next_out,A=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=S.dmax,u=S.wsize,h=S.whave,c=S.wnext,f=S.window,l=S.hold,d=S.bits,v=S.lencode,p=S.distcode,y=(1<>>=g=_>>>24,d-=g,0===(g=_>>>16&255))A[i++]=65535&_;else{if(!(16&g)){if(0==(64&g)){_=v[(65535&_)+(l&(1<>>=g,d-=g),d<15&&(l+=E[r++]<>>=g=_>>>24,d-=g,!(16&(g=_>>>16&255))){if(0==(64&g)){_=p[(65535&_)+(l&(1<s){t.msg="invalid distance too far back",S.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&S.sane){t.msg="invalid distance too far back",S.mode=30;break t}if(k=0,x=f,0===c){if(k+=u-g,g2;)A[i++]=x[k++],A[i++]=x[k++],A[i++]=x[k++],b-=3;b&&(A[i++]=x[k++],b>1&&(A[i++]=x[k++]))}else{k=i-m;do{A[i++]=A[k++],A[i++]=A[k++],A[i++]=A[k++],b-=3}while(b>2);b&&(A[i++]=A[k++],b>1&&(A[i++]=A[k++]))}break}}break}}while(r>3,l&=(1<<(d-=b<<3))-1,t.next_in=r,t.next_out=i,t.avail_in=r=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(I[1]=0,_=1;_<15;_++)I[_+1]=I[_]+T[_];for(g=0;g852||2===t&&S>592)return 1;for(;;){v=_-E,o[g]d?(p=B[z+o[g]],y=O[U+o[g]]):(p=96,y=0),u=1<<_-E,b=h=1<>E)+(h-=u)]=v<<24|p<<16|y|0}while(0!==h);for(u=1<<_-1;R&u;)u>>=1;if(0!==u?(R&=u-1,R+=u):R=0,g++,0==--T[_]){if(_===m)break;_=e[r+o[g]]}if(_>k&&(R&f)!==c){for(0===E&&(E=k),l+=b,A=1<<(x=_-E);x+E852||2===t&&S>592)return 1;i[c=R&f]=k<<24|x<<16|l-a|0}}return 0!==R&&(i[l+R]=_-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,ve=X.Z_BLOCK,pe=X.Z_TREES,ye=X.Z_OK,we=X.Z_STREAM_END,_e=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Ae=30,Se=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Re(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Oe,Ue,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ye}(t)},Ie=!0,Be=function(t){if(Ie){Oe=new Int32Array(512),Ue=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Oe,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Ue,0,t.work,{bits:5}),Ie=!1}t.lencode=Oe,t.lenbits=9,t.distcode=Ue,t.distbits=5},ze=function(t,e,r,n){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,Te(t))}(t,e);return n!==ye&&(t.state=null),n},Ne=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,A,S=0,R=new Uint8Array(4),O=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(r=t.state).mode===Ee&&(r.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,f=s,l=u,x=ye;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=F(r.check,R,2,0),h=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",r.mode=Ae;break}if((15&h)!==xe){t.msg="unknown compression method",r.mode=Ae;break}if(c-=4,k=8+(15&(h>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Ae;break}r.dmax=1<>8&1),512&r.flags&&(R[0]=255&h,R[1]=h>>>8&255,r.check=F(r.check,R,2,0)),h=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>8&255,R[2]=h>>>16&255,R[3]=h>>>24&255,r.check=F(r.check,R,4,0)),h=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>8),512&r.flags&&(R[0]=255&h,R[1]=h>>>8&255,r.check=F(r.check,R,2,0)),h=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=F(r.check,R,2,0)),h=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),k)),512&r.flags&&(r.check=F(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break t;d=0;do{k=n[a+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&d>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ee;break;case 10:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===s)break t;s--,h+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Be(r),r.mode=20,e===pe){h>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Ae}h>>>=2,c-=2;break;case 14:for(h>>>=7&c,c-=7&c;c<32;){if(0===s)break t;s--,h+=n[a++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Ae;break}if(r.length=65535&h,h=0,c=0,r.mode=15,e===pe)break t;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(n.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,r.length-=d;break}r.mode=Ee;break;case 17:for(;c<14;){if(0===s)break t;s--,h+=n[a++]<>>=5,c-=5,r.ndist=1+(31&h),h>>>=5,c-=5,r.ncode=4+(15&h),h>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Ae;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[O[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,E={bits:r.lenbits},x=le(0,r.lens,0,19,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid code lengths set",r.mode=Ae;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,_=65535&S,!((y=S>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=y,c-=y,r.lens[r.have++]=_;else{if(16===_){for(A=y+2;c>>=y,c-=y,0===r.have){t.msg="invalid bit length repeat",r.mode=Ae;break}k=r.lens[r.have-1],d=3+(3&h),h>>>=2,c-=2}else if(17===_){for(A=y+3;c>>=y)),h>>>=3,c-=3}else{for(A=y+7;c>>=y)),h>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Ae;break}for(;d--;)r.lens[r.have++]=k}}if(r.mode===Ae)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Ae;break}if(r.lenbits=9,E={bits:r.lenbits},x=le(1,r.lens,0,r.nlen,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid literal/lengths set",r.mode=Ae;break}if(r.distbits=6,r.distcode=r.distdyn,E={bits:r.distbits},x=le(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,E),r.distbits=E.bits,x){t.msg="invalid distances set",r.mode=Ae;break}if(r.mode=20,e===pe)break t;case 20:r.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,r.hold=h,r.bits=c,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,r.mode===Ee&&(r.back=-1);break}for(r.back=0;w=(S=r.lencode[h&(1<>>16&255,_=65535&S,!((y=S>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&S,!(g+(y=S>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,r.length=_,0===w){r.mode=26;break}if(32&w){r.back=-1,r.mode=Ee;break}if(64&w){t.msg="invalid literal/length code",r.mode=Ae;break}r.extra=15&w,r.mode=22;case 22:if(r.extra){for(A=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;w=(S=r.distcode[h&(1<>>16&255,_=65535&S,!((y=S>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&S,!(g+(y=S>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,64&w){t.msg="invalid distance code",r.mode=Ae;break}r.offset=_,r.extra=15&w,r.mode=24;case 24:if(r.extra){for(A=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Ae;break}r.mode=25;case 25:if(0===u)break t;if(d=l-u,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Ae;break}d>r.wnext?(d-=r.wnext,v=r.wsize-d):v=r.wnext-d,d>r.length&&(d=r.length),p=r.window}else p=i,v=o-r.offset,d=r.length;d>u&&(d=u),u-=d,r.length-=d;do{i[o++]=p[v++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===u)break t;i[o++]=r.length,u--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===s)break t;s--,h|=n[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pe(this.strm,e.windowBits);if(r!==Ze)throw new Error(Z[r]);if(this.header=new je,function(t,e){if(!t||!t.state)return ge;var r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Ve.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary))!==Ze))throw new Error(Z[r])}function Je(t,e){var r=new Ke(e);if(r.push(t),r.err)throw r.msg||Z[r.err];return r.result}Ke.prototype.push=function(t,e){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Fe:Me,"[object ArrayBuffer]"===Ve.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ne(a,n))===We&&s&&((r=De(a,s))===Ze?r=Ne(a,n):r===Ge&&(r=We));a.avail_in>0&&r===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Le(a),r=Ne(a,n);switch(r){case He:case Ge:case We:case Ye:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Xe))if("string"===this.options.to){var u=Ht(a.output,a.next_out),h=a.next_out-u,c=Wt(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(c)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Ze||0!==i){if(r===Xe)return r=Ce(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ke.prototype.onData=function(t){this.chunks.push(t)},Ke.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Vt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var qe=oe,$e=Ke,Qe=Je,tr=[137,80,78,71,13,10,26,10],er=[],rr=0;rr<256;rr++){for(var nr=rr,ir=0;ir<8;ir++)1&nr?nr=3988292384^nr>>>1:nr>>>=1;er[rr]=nr}var ar,or,sr,ur;function hr(t,e){return(4294967295^function(t,e,r){for(var n=4294967295,i=0;i>>8;return n}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(ar||(ar={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(or||(or={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(sr||(sr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(ur||(ur={}));var cr=new Uint8Array(0),fr=new Uint16Array([255]),lr=255===new Uint8Array(fr.buffer)[0],dr=function(t){du(r,t);var e=mu(r);function r(t){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};hu(this,r),n=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return n._checkCrc=o,n._inflator=new $e,n._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},n._end=!1,n._hasPalette=!1,n._palette=[],n._compressionMethod=or.UNKNOWN,n._filterMethod=sr.UNKNOWN,n._interlaceMethod=ur.UNKNOWN,n._colorType=-1,n.setBigEndian(),n}return fu(r,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=f}else this._png.data=s}}]),r}(r);function vr(t,e,r){for(var n=0;n>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function _r(t,e,r,n,i){var a=0;if(0===r.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return hu(this,n),(r=e.call(this))._colorType=ar.UNKNOWN,r._zlibOptions=au(au({},mr),i.zlib),r._png=r._checkData(t),r.setBigEndian(),r}return fu(n,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tr)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(or.DEFLATE),this.writeByte(sr.ADAPTIVE),this.writeByte(ur.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,n=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new r).setBigEndian(),h=0,c=0;c0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Er(t,e,r,n){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,r="";return"number"==typeof e?r=ku(" ",Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),Fl(t,r,-1)}var Xl=function(){function t(e,r,n){hu(this,t),this.startingLine=n||0,this.lineIndex=-1;for(var i=[],a=0;a=r;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),s=void 0,u=void 0,h=void 0;trimmedLin__startsWithString(e,'"')&&(a=i.match(/^"(.*?)":(?: |$)/)),o&&(h=o[1],i=i.replace(o[0],"")),a?(n||(n={}),s=a[1],u=i.replace(a[0],"").trim()):trimmedLin__startsWithString(e,"-")&&(n||(n=[]),u=i.slice(1).trim()),u=u?Hl(u,h):Wl(t.nextGroup(),h),Array.isArray(n)?n.push(u):n[s]=u}return r&&(n={type:r,data:n}),n}function Hl(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Gl(t){var e=t.replace(/\t/g,"\t").split("\n");return Wl(new Xl(e))}function Yl(t){var e;if(Array.isArray(t)){e=[];for(var r=0;r","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],u.verticalSpacing=u.verticalLineSpacing,delete u.verticalLineSpacing);var c=function(t,e){var n=[],i=[],a=function t(a,o){var s,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,h=e[u];if(Kl(h))return{converted:{type:h,data:a},traversed:u};if(null===h)return{converted:a,traversed:u};if(reade__startsWithString(r,"Nullable"))return{converted:{type:h,data:{data:{type:e[u+1],data:a}}},traversed:u+1};if(Jl(h))return"Texture2D"===h?(n.push({path:o.join(".")}),{converted:{type:h,data:{format:a.format}},traversed:u}):("TBin"===h&&i.push({path:o.join(".")}),{converted:{type:h,data:{}},traversed:u});s=Array.isArray(a)?[]:{};for(var c=u,f=!0,l=!reade__startsWithString(r,"Dictionary")&&!reade__startsWithString(r,"Array")&&!reade__startsWithString(r,"List"),d=Object.keys(a),v=0;v0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function Ql(t){var e={},r=t.xnbData,n=r.compressed,i=r.readerData,a=r.hiDef,o=r.target;return e.header={target:o,formatVersion:5,compressed:n?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=Yl(i),e.content=ql(t.content),"SpriteFont"===Sl(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function td(t,e){if(t&&"object"==ou(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var r=Object.keys(t),n=0;n1&&void 0!==arguments[1]&&arguments[1],r=td(t,"export");if(r){var n=r.value,i=n.type,a=n.data;return"Texture2D"===i&&(a=Ml(n.width,n.height,new Uint8Array(a))),id(a,i)}if(e){var o=JSON.stringify(t,null,4);return id(o,"JSON")}return null}function od(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(n&&a&&(n=!1),!t.hasOwnProperty("content"))throw new Kc("Invalid object!");var u=[],h=t.content,c=ad(h,a);if(null!==c&&u.push(c),a)return u;var f=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(rd(e.type)):"".concat(e.type,".").concat(rd(e.type)):e}),4),l=f;return n&&(l=Zl($l(t))),u.unshift(id(l,n?"yaml":"JSON")),u}function sd(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function ud(t){return hd.apply(this,arguments)}function hd(){return(hd=uu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function cd(t){return fd.apply(this,arguments)}function fd(){return(fd=uu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ld(t,e){return dd.apply(this,arguments)}function dd(){return dd=uu(regeneratorRuntime.mark((function t(e,r){var n,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,cd(r.png);case 3:return n=t.sent,i=Vl(new Uint8Array(n)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,cd(r.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,cd(r.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,ud(r.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),dd.apply(this,arguments)}function vd(t){return pd.apply(this,arguments)}function pd(){return pd=uu(regeneratorRuntime.mark((function t(e){var r,n,i,a,o,s,u,h,c,f,l,d,v=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=v.length>1&&void 0!==v[1]?v[1]:{},n=r.compression,i=void 0===n?"default":n,a=e.json||e.yaml){t.next=5;break}throw new Kc("There is no JSON or YAML file to pack!");case 5:return t.next=7,ud(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):Ql(Gl(o)),null!==(u=sd(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new Kc("".concat(a.name,' does not have "content".'));case 14:if(!(h=td(s.content,"export"))){t.next=21;break}return c=h.parent,f=h.value,l=ed(f),d=l[1],t.next=20,ld(d,e);case 20:c.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),pd.apply(this,arguments)}function yd(t){return wd.apply(this,arguments)}function wd(){return(wd=uu(regeneratorRuntime.mark((function t(e){var r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(r=ed(e.name),"xnb"===r[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return n=t.sent,t.abrupt("return",_d(n));case 8:return t.abrupt("return",_d(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _d(t){return(new Pl).load(t)}function gd(t){var e=ad(t.content,!0),r=e.data,n=e.extension;return new Il(r,n)}function bd(t){for(var e={},r=0;r1&&void 0!==arguments[1]?arguments[1]:{},r=bd(t),n=[],i=Object.keys(r),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=ed(s),h=u[0],c=function(t){return od(t,{yaml:n,contentOnly:a,fileName:h})};return yd(t).then(c)},t.unpackToXnbData=yd,t.xnbDataToContent=gd,t.xnbDataToFiles=od,Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=function(t){return t&&t.Math==Math&&t},n=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,c=u?h.bind(h):function(){return h.apply(h,arguments)},f={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,v=d&&!l.call({1:2},1);f.f=v?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var p,y,w=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},_=s,g=Function.prototype,b=g.bind,m=g.call,k=_&&b.bind(m,m),x=_?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,R=E({}.toString),A=E("".slice),O=function(t){return A(R(t),8,-1)},T=x,S=a,U=O,I=n.Object,B=T("".split),z=S((function(){return!I("z").propertyIsEnumerable(0)}))?function(t){return"String"==U(t)?B(t,""):I(t)}:I,L=n.TypeError,P=function(t){if(null==t)throw L("Can't call method on "+t);return t},N=z,C=P,D=function(t){return N(C(t))},j=function(t){return"function"==typeof t},M=j,F=function(t){return"object"==typeof t?null!==t:M(t)},V=n,Z=j,X=function(t){return Z(t)?t:void 0},W=function(t,e){return arguments.length<2?X(V[t]):V[t]&&V[t][e]},H=x({}.isPrototypeOf),G=W("navigator","userAgent")||"",Y=n,K=G,J=Y.process,q=Y.Deno,$=J&&J.versions||q&&q.version,Q=$&&$.v8;Q&&(y=(p=Q.split("."))[0]>0&&p[0]<4?1:+(p[0]+p[1])),!y&&K&&(!(p=K.match(/Edge\/(\d+)/))||p[1]>=74)&&(p=K.match(/Chrome\/(\d+)/))&&(y=+p[1]);var tt=y,et=tt,rt=a,nt=!!Object.getOwnPropertySymbols&&!rt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=nt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=W,ot=j,st=H,ut=it,ht=n.Object,ct=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ft=n.String,lt=function(t){try{return ft(t)}catch(t){return"Object"}},dt=j,vt=lt,pt=n.TypeError,yt=function(t){if(dt(t))return t;throw pt(vt(t)+" is not a function")},wt=yt,_t=function(t,e){var r=t[e];return null==r?void 0:wt(r)},gt=c,bt=j,mt=F,kt=n.TypeError,xt={exports:{}},Et=n,Rt=Object.defineProperty,At=function(t,e){try{Rt(Et,t,{value:e,configurable:!0,writable:!0})}catch(r){Et[t]=e}return e},Ot=At,Tt="__core-js_shared__",St=n[Tt]||Ot(Tt,{}),Ut=St;(xt.exports=function(t,e){return Ut[t]||(Ut[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var It=P,Bt=n.Object,zt=function(t){return Bt(It(t))},Lt=zt,Pt=x({}.hasOwnProperty),Nt=Object.hasOwn||function(t,e){return Pt(Lt(t),e)},Ct=x,Dt=0,jt=Math.random(),Mt=Ct(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Mt(++Dt+jt,36)},Vt=n,Zt=xt.exports,Xt=Nt,Wt=Ft,Ht=nt,Gt=it,Yt=Zt("wks"),Kt=Vt.Symbol,Jt=Kt&&Kt.for,qt=Gt?Kt:Kt&&Kt.withoutSetter||Wt,$t=function(t){if(!Xt(Yt,t)||!Ht&&"string"!=typeof Yt[t]){var e="Symbol."+t;Ht&&Xt(Kt,t)?Yt[t]=Kt[t]:Yt[t]=Gt&&Jt?Jt(e):qt(e)}return Yt[t]},Qt=c,te=F,ee=ct,re=_t,ne=function(t,e){var r,n;if("string"===e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;if(bt(r=t.valueOf)&&!mt(n=gt(r,t)))return n;if("string"!==e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;throw kt("Can't convert object to primitive value")},ie=$t,ae=n.TypeError,oe=ie("toPrimitive"),se=function(t,e){if(!te(t)||ee(t))return t;var r,n=re(t,oe);if(n){if(void 0===e&&(e="default"),r=Qt(n,t,e),!te(r)||ee(r))return r;throw ae("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},ue=ct,he=function(t){var e=se(t,"string");return ue(e)?e:e+""},ce=F,fe=n.document,le=ce(fe)&&ce(fe.createElement),de=function(t){return le?fe.createElement(t):{}},ve=de,pe=!o&&!a((function(){return 7!=Object.defineProperty(ve("div"),"a",{get:function(){return 7}}).a})),ye=o,we=c,_e=f,ge=w,be=D,me=he,ke=Nt,xe=pe,Ee=Object.getOwnPropertyDescriptor;i.f=ye?Ee:function(t,e){if(t=be(t),e=me(e),xe)try{return Ee(t,e)}catch(t){}if(ke(t,e))return ge(!we(_e.f,t,e),t[e])};var Re={},Ae=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Oe=n,Te=F,Se=Oe.String,Ue=Oe.TypeError,Ie=function(t){if(Te(t))return t;throw Ue(Se(t)+" is not an object")},Be=o,ze=pe,Le=Ae,Pe=Ie,Ne=he,Ce=n.TypeError,De=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Me="enumerable",Fe="configurable",Ve="writable";Re.f=Be?Le?function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),"function"==typeof t&&"prototype"===e&&"value"in r&&Ve in r&&!r.writable){var n=je(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:Fe in r?r.configurable:n.configurable,enumerable:Me in r?r.enumerable:n.enumerable,writable:!1})}return De(t,e,r)}:De:function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),ze)try{return De(t,e,r)}catch(t){}if("get"in r||"set"in r)throw Ce("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Ze=Re,Xe=w,We=o?function(t,e,r){return Ze.f(t,e,Xe(1,r))}:function(t,e,r){return t[e]=r,t},He={exports:{}},Ge=o,Ye=Nt,Ke=Function.prototype,Je=Ge&&Object.getOwnPropertyDescriptor,qe=Ye(Ke,"name"),$e={EXISTS:qe,PROPER:qe&&"something"===function(){}.name,CONFIGURABLE:qe&&(!Ge||Ge&&Je(Ke,"name").configurable)},Qe=j,tr=St,er=x(Function.toString);Qe(tr.inspectSource)||(tr.inspectSource=function(t){return er(t)});var rr,nr,ir,ar=tr.inspectSource,or=j,sr=ar,ur=n.WeakMap,hr=or(ur)&&/native code/.test(sr(ur)),cr=xt.exports,fr=Ft,lr=cr("keys"),dr=function(t){return lr[t]||(lr[t]=fr(t))},vr={},pr=hr,yr=n,wr=x,_r=F,gr=We,br=Nt,mr=St,kr=dr,xr=vr,Er="Object already initialized",Rr=yr.TypeError,Ar=yr.WeakMap;if(pr||mr.state){var Or=mr.state||(mr.state=new Ar),Tr=wr(Or.get),Sr=wr(Or.has),Ur=wr(Or.set);rr=function(t,e){if(Sr(Or,t))throw new Rr(Er);return e.facade=t,Ur(Or,t,e),e},nr=function(t){return Tr(Or,t)||{}},ir=function(t){return Sr(Or,t)}}else{var Ir=kr("state");xr[Ir]=!0,rr=function(t,e){if(br(t,Ir))throw new Rr(Er);return e.facade=t,gr(t,Ir,e),e},nr=function(t){return br(t,Ir)?t[Ir]:{}},ir=function(t){return br(t,Ir)}}var Br={set:rr,get:nr,has:ir,enforce:function(t){return ir(t)?nr(t):rr(t,{})},getterFor:function(t){return function(e){var r;if(!_r(e)||(r=nr(e)).type!==t)throw Rr("Incompatible receiver, "+t+" required");return r}}},zr=a,Lr=j,Pr=Nt,Nr=Re.f,Cr=$e.CONFIGURABLE,Dr=ar,jr=Br.enforce,Mr=Br.get,Fr=!zr((function(){return 8!==Nr((function(){}),"length",{value:8}).length})),Vr=String(String).split("String"),Zr=He.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!Pr(t,"name")||Cr&&t.name!==e)&&Nr(t,"name",{value:e,configurable:!0}),Fr&&r&&Pr(r,"arity")&&t.length!==r.arity&&Nr(t,"length",{value:r.arity});var n=jr(t);return Pr(n,"source")||(n.source=Vr.join("string"==typeof e?e:"")),t};Function.prototype.toString=Zr((function(){return Lr(this)&&Mr(this).source||Dr(this)}),"toString");var Xr=n,Wr=j,Hr=We,Gr=He.exports,Yr=At,Kr=function(t,e,r,n){var i=!!n&&!!n.unsafe,a=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,s=n&&void 0!==n.name?n.name:e;return Wr(r)&&Gr(r,s,n),t===Xr?(a?t[e]=r:Yr(e,r),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=r:Hr(t,e,r),t)},Jr={},qr=Math.ceil,$r=Math.floor,Qr=function(t){var e=+t;return e!=e||0===e?0:(e>0?$r:qr)(e)},tn=Qr,en=Math.max,rn=Math.min,nn=Qr,an=Math.min,on=function(t){return t>0?an(nn(t),9007199254740991):0},sn=function(t){return on(t.length)},un=D,hn=function(t,e){var r=tn(t);return r<0?en(r+e,0):rn(r,e)},cn=sn,fn=function(t){return function(e,r,n){var i,a=un(e),o=cn(a),s=hn(n,o);if(t&&r!=r){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===r)return t||s||0;return!t&&-1}},ln={includes:fn(!0),indexOf:fn(!1)},dn=Nt,vn=D,pn=ln.indexOf,yn=vr,wn=x([].push),_n=function(t,e){var r,n=vn(t),i=0,a=[];for(r in n)!dn(yn,r)&&dn(n,r)&&wn(a,r);for(;e.length>i;)dn(n,r=e[i++])&&(~pn(a,r)||wn(a,r));return a},gn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Jr.f=Object.getOwnPropertyNames||function(t){return _n(t,gn)};var bn={};bn.f=Object.getOwnPropertySymbols;var mn=W,kn=Jr,xn=bn,En=Ie,Rn=x([].concat),An=mn("Reflect","ownKeys")||function(t){var e=kn.f(En(t)),r=xn.f;return r?Rn(e,r(t)):e},On=Nt,Tn=An,Sn=i,Un=Re,In=a,Bn=j,zn=/#|\.prototype\./,Ln=function(t,e){var r=Nn[Pn(t)];return r==Dn||r!=Cn&&(Bn(e)?In(e):!!e)},Pn=Ln.normalize=function(t){return String(t).replace(zn,".").toLowerCase()},Nn=Ln.data={},Cn=Ln.NATIVE="N",Dn=Ln.POLYFILL="P",jn=Ln,Mn=n,Fn=i.f,Vn=We,Zn=Kr,Xn=At,Wn=function(t,e,r){for(var n=Tn(e),i=Un.f,a=Sn.f,o=0;o=51&&/native code/.test(t))return!1;var r=new fo((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};return(r.constructor={})[go]=n,!(bo=r.then((function(){}))instanceof n)||!e&&wo&&!mo})),xo={CONSTRUCTOR:ko,REJECTION_EVENT:mo,SUBCLASSING:bo},Eo={},Ro=yt,Ao=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError("Bad Promise constructor");e=t,r=n})),this.resolve=Ro(e),this.reject=Ro(r)};Eo.f=function(t){return new Ao(t)};var Oo,To,So,Uo=Gn,Io=Yn,Bo=n,zo=c,Lo=Kr,Po=ri,No=function(t,e,r){t&&!r&&(t=t.prototype),t&&!ii(t,ai)&&ni(t,ai,{configurable:!0,value:e})},Co=function(t){var e=oi(t),r=si.f;ui&&e&&!e[hi]&&r(e,hi,{configurable:!0,get:function(){return this}})},Do=yt,jo=j,Mo=F,Fo=function(t,e){if(ci(e,t))return t;throw fi("Incorrect invocation")},Vo=Wi,Zo=ja.set,Xo=no,Wo=function(t,e){var r=io.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ho=ao,Go=so,Yo=Br,Ko=uo,Jo=Eo,qo="Promise",$o=xo.CONSTRUCTOR,Qo=xo.REJECTION_EVENT,ts=xo.SUBCLASSING,es=Yo.getterFor(qo),rs=Yo.set,ns=Ko&&Ko.prototype,is=Ko,as=ns,os=Bo.TypeError,ss=Bo.document,us=Bo.process,hs=Jo.f,cs=hs,fs=!!(ss&&ss.createEvent&&Bo.dispatchEvent),ls="unhandledrejection",ds=function(t){var e;return!(!Mo(t)||!jo(e=t.then))&&e},vs=function(t,e){var r,n,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,c=t.domain;try{s?(o||(2===e.rejection&&gs(e),e.rejection=1),!0===s?r=a:(c&&c.enter(),r=s(a),c&&(c.exit(),i=!0)),r===t.promise?h(os("Promise-chain cycle")):(n=ds(r))?zo(n,r,u,h):u(r)):h(a)}catch(t){c&&!i&&c.exit(),h(t)}},ps=function(t,e){t.notified||(t.notified=!0,Xo((function(){for(var r,n=t.reactions;r=n.get();)vs(r,t);t.notified=!1,e&&!t.rejection&&ws(t)})))},ys=function(t,e,r){var n,i;fs?((n=ss.createEvent("Event")).promise=e,n.reason=r,n.initEvent(t,!1,!0),Bo.dispatchEvent(n)):n={promise:e,reason:r},!Qo&&(i=Bo["on"+t])?i(n):t===ls&&Wo("Unhandled promise rejection",r)},ws=function(t){zo(Zo,Bo,(function(){var e,r=t.facade,n=t.value;if(_s(t)&&(e=Ho((function(){Io?us.emit("unhandledRejection",n,r):ys(ls,r,n)})),t.rejection=Io||_s(t)?2:1,e.error))throw e.value}))},_s=function(t){return 1!==t.rejection&&!t.parent},gs=function(t){zo(Zo,Bo,(function(){var e=t.facade;Io?us.emit("rejectionHandled",e):ys("rejectionhandled",e,t.value)}))},bs=function(t,e,r){return function(n){t(e,n,r)}},ms=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,ps(t,!0))},ks=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw os("Promise can't be resolved itself");var n=ds(e);n?Xo((function(){var r={done:!1};try{zo(n,e,bs(ks,r,t),bs(ms,r,t))}catch(e){ms(r,e,t)}})):(t.value=e,t.state=1,ps(t,!1))}catch(e){ms({done:!1},e,t)}}};if($o&&(as=(is=function(t){Fo(this,as),Do(t),zo(Oo,this);var e=es(this);try{t(bs(ks,e),bs(ms,e))}catch(t){ms(e,t)}}).prototype,(Oo=function(t){rs(this,{type:qo,done:!1,notified:!1,parent:!1,reactions:new Go,rejection:!1,state:0,value:void 0})}).prototype=Lo(as,"then",(function(t,e){var r=es(this),n=hs(Vo(this,is));return r.parent=!0,n.ok=!jo(t)||t,n.fail=jo(e)&&e,n.domain=Io?us.domain:void 0,0==r.state?r.reactions.add(n):Xo((function(){vs(n,r)})),n.promise})),To=function(){var t=new Oo,e=es(t);this.promise=t,this.resolve=bs(ks,e),this.reject=bs(ms,e)},Jo.f=hs=function(t){return t===is||undefined===t?new To(t):cs(t)},jo(Ko)&&ns!==Object.prototype)){So=ns.then,ts||Lo(ns,"then",(function(t,e){var r=this;return new is((function(t,e){zo(So,r,t,e)})).then(t,e)}),{unsafe:!0});try{delete ns.constructor}catch(t){}Po&&Po(ns,as)}Uo({global:!0,wrap:!0,forced:$o},{Promise:is}),No(is,qo,!1),Co(qo);var xs={},Es=xs,Rs=$t("iterator"),As=Array.prototype,Os=bi,Ts=_t,Ss=xs,Us=$t("iterator"),Is=function(t){if(null!=t)return Ts(t,Us)||Ts(t,"@@iterator")||Ss[Os(t)]},Bs=c,zs=yt,Ls=Ie,Ps=lt,Ns=Is,Cs=n.TypeError,Ds=c,js=Ie,Ms=_t,Fs=ta,Vs=c,Zs=Ie,Xs=lt,Ws=function(t){return void 0!==t&&(Es.Array===t||As[Rs]===t)},Hs=sn,Gs=H,Ys=function(t,e){var r=arguments.length<2?Ns(t):e;if(zs(r))return Ls(Bs(r,t));throw Cs(Ps(t)+" is not iterable")},Ks=Is,Js=function(t,e,r){var n,i;js(t);try{if(!(n=Ms(t,"return"))){if("throw"===e)throw r;return r}n=Ds(n,t)}catch(t){i=!0,n=t}if("throw"===e)throw r;if(i)throw n;return js(n),r},qs=n.TypeError,$s=function(t,e){this.stopped=t,this.result=e},Qs=$s.prototype,tu=function(t,e,r){var n,i,a,o,s,u,h,c=r&&r.that,f=!(!r||!r.AS_ENTRIES),l=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=Fs(e,c),p=function(t){return n&&Js(n,"normal",t),new $s(!0,t)},y=function(t){return f?(Zs(t),d?v(t[0],t[1],p):v(t[0],t[1])):d?v(t,p):v(t)};if(l)n=t;else{if(!(i=Ks(t)))throw qs(Xs(t)+" is not iterable");if(Ws(i)){for(a=0,o=Hs(t);o>a;a++)if((s=y(t[a]))&&Gs(Qs,s))return s;return new $s(!1)}n=Ys(t,i)}for(u=n.next;!(h=Vs(u,n)).done;){try{s=y(h.value)}catch(t){Js(n,"throw",t)}if("object"==typeof s&&s&&Gs(Qs,s))return s}return new $s(!1)};function eu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function ru(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),h=n.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var ih,ah,oh,sh="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,uh=!a((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),hh=n,ch=Nt,fh=j,lh=zt,dh=uh,vh=dr("IE_PROTO"),ph=hh.Object,yh=ph.prototype,wh=dh?ph.getPrototypeOf:function(t){var e=lh(t);if(ch(e,vh))return e[vh];var r=e.constructor;return fh(r)&&e instanceof r?r.prototype:e instanceof ph?yh:null},_h=sh,gh=o,bh=n,mh=j,kh=F,xh=Nt,Eh=bi,Rh=lt,Ah=We,Oh=Kr,Th=Re.f,Sh=H,Uh=wh,Ih=ri,Bh=$t,zh=Ft,Lh=bh.Int8Array,Ph=Lh&&Lh.prototype,Nh=bh.Uint8ClampedArray,Ch=Nh&&Nh.prototype,Dh=Lh&&Uh(Lh),jh=Ph&&Uh(Ph),Mh=Object.prototype,Fh=bh.TypeError,Vh=Bh("toStringTag"),Zh=zh("TYPED_ARRAY_TAG"),Xh=zh("TYPED_ARRAY_CONSTRUCTOR"),Wh=_h&&!!Ih&&"Opera"!==Eh(bh.opera),Hh=!1,Gh={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Yh={BigInt64Array:8,BigUint64Array:8},Kh=function(t){if(!kh(t))return!1;var e=Eh(t);return xh(Gh,e)||xh(Yh,e)};for(ih in Gh)(oh=(ah=bh[ih])&&ah.prototype)?Ah(oh,Xh,ah):Wh=!1;for(ih in Yh)(oh=(ah=bh[ih])&&ah.prototype)&&Ah(oh,Xh,ah);if((!Wh||!mh(Dh)||Dh===Function.prototype)&&(Dh=function(){throw Fh("Incorrect invocation")},Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih],Dh);if((!Wh||!jh||jh===Mh)&&(jh=Dh.prototype,Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih].prototype,jh);if(Wh&&Uh(Ch)!==jh&&Ih(Ch,jh),gh&&!xh(jh,Vh))for(ih in Hh=!0,Th(jh,Vh,{get:function(){return kh(this)?this[Zh]:void 0}}),Gh)bh[ih]&&Ah(bh[ih],Zh,ih);var Jh={NATIVE_ARRAY_BUFFER_VIEWS:Wh,TYPED_ARRAY_CONSTRUCTOR:Xh,TYPED_ARRAY_TAG:Hh&&Zh,aTypedArray:function(t){if(Kh(t))return t;throw Fh("Target is not a typed array")},aTypedArrayConstructor:function(t){if(mh(t)&&(!Ih||Sh(Dh,t)))return t;throw Fh(Rh(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if(gh){if(r)for(var i in Gh){var a=bh[i];if(a&&xh(a.prototype,t))try{delete a.prototype[t]}catch(r){try{a.prototype[t]=e}catch(t){}}}jh[t]&&!r||Oh(jh,t,r?e:Wh&&Ph[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if(gh){if(Ih){if(r)for(n in Gh)if((i=bh[n])&&xh(i,t))try{delete i[t]}catch(t){}if(Dh[t]&&!r)return;try{return Oh(Dh,t,r?e:Wh&&Dh[t]||e)}catch(t){}}for(n in Gh)!(i=bh[n])||i[t]&&!r||Oh(i,t,e)}},isView:function(t){if(!kh(t))return!1;var e=Eh(t);return"DataView"===e||xh(Gh,e)||xh(Yh,e)},isTypedArray:Kh,TypedArray:Dh,TypedArrayPrototype:jh},qh=O,$h=n,Qh=Array.isArray||function(t){return"Array"==qh(t)},tc=Di,ec=F,rc=$t("species"),nc=$h.Array,ic=function(t){var e;return Qh(t)&&(e=t.constructor,(tc(e)&&(e===nc||Qh(e.prototype))||ec(e)&&null===(e=e[rc]))&&(e=void 0)),void 0===e?nc:e},ac=ta,oc=z,sc=zt,uc=sn,hc=function(t,e){return new(ic(t))(0===e?0:e)},cc=x([].push),fc=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,a=6==t,o=7==t,s=5==t||a;return function(u,h,c,f){for(var l,d,v=sc(u),p=oc(v),y=ac(h,c),w=uc(p),_=0,g=f||hc,b=e?g(u,w):r||o?g(u,0):void 0;w>_;_++)if((s||_ in p)&&(d=y(l=p[_],_,v),t))if(e)b[_]=d;else if(d)switch(t){case 3:return!0;case 5:return l;case 6:return _;case 2:cc(b,l)}else switch(t){case 4:return!1;case 7:cc(b,l)}return a?-1:n||i?i:b}},lc={forEach:fc(0),map:fc(1),filter:fc(2),some:fc(3),every:fc(4),find:fc(5),findIndex:fc(6),filterReject:fc(7)},dc=Wi,vc=Jh.TYPED_ARRAY_CONSTRUCTOR,pc=Jh.aTypedArrayConstructor,yc=lc.map,wc=function(t){return pc(dc(t,t[vc]))},_c=Jh.aTypedArray;(0,Jh.exportTypedArrayMethod)("map",(function(t){return yc(_c(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(wc(t))(e)}))}));var gc=o,bc=$e.EXISTS,mc=x,kc=Re.f,xc=Function.prototype,Ec=mc(xc.toString),Rc=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ac=mc(Rc.exec);gc&&!bc&&kc(xc,"name",{configurable:!0,get:function(){try{return Ac(Rc,Ec(this))[1]}catch(t){return""}}});var Oc=function(t){cu(r,t);var e=_u(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ou(this,r),(t=e.call(this,n)).name="XnbError",t.message=n,Error.captureStackTrace(yu(t),r),t}return uu(r)}(pu(Error)),Tc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"setReaders",value:function(e){t.readers=ru({},e)}},{key:"addReaders",value:function(e){t.readers=ru(ru({},t.readers),e)}},{key:"makeSimplied",value:function(e,r){var n=e.split(/`|,/)[0];if(r.isTypeOf(n)){if(r.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r.type(),"<").concat(i.join(","),">")}return r.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var r=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(r,"[]"))return"Array<".concat(simplifyType(r.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===r){var n=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n)}for(var i=0,a=Object.values(t.readers);i/);return r=r?r[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:r}}},{key:"getReaderTypeList",value:function(e){var r=t.getTypeInfo(e),n=r.type,i=r.subtypes;if(t.readers.hasOwnProperty("".concat(n,"Reader")))return t.readers["".concat(n,"Reader")].parseTypeList(i);throw new Oc('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var r=t.getTypeInfo(e),n=r.type,i=r.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(n,"Reader")))return vu(t.readers["".concat(n,"Reader")],i);throw new Oc('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var r=t.simplifyType(e);return t.getReader(r)}}]),t}();hu(Tc,"readers",{});var Sc=[192,224,240],Uc=128,Ic=63,Bc=[55296,56320],zc=1023;function Lc(t){return t<128?[t]:t<2048?[Sc[0]|t>>6,Uc|t&Ic]:t<65536?[Sc[1]|t>>12,Uc|t>>6&Ic,Uc|t&Ic]:[Sc[2]|t>>18,Uc|t>>12&Ic,Uc|t>>6&Ic,Uc|t&Ic]}function Pc(t){return t<65535?[t]:[Bc[0]|(t-=65536)>>10&zc,Bc[1]|t&zc]}function Nc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var r=t.length;return 1===r?t[0]:2===r?((t[0]^Sc[0])<<6)+(t[1]^Uc):3===r?((t[0]^Sc[1])<<12)+((t[1]^Uc)<<6)+(t[2]^Uc):((t[0]^Sc[2])<<18)+((t[1]^Uc)<<12)+((t[2]^Uc)<<6)+(t[3]^Uc)}function Cc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&zc)<<10)+(t[1]&zc)+65536}function Dc(t){return function(t){for(var e=[],r=0;r1&&void 0!==arguments[1])||arguments[1];ou(this,t),this._endianus=r,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return uu(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,r=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:0,e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0;){var n=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(n&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,r|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),Fc=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ou(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return uu(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e),n=0;n>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),Vc=256,Zc=0,Xc=1,Wc=2,Hc=3,Gc=656,Yc=function(){function t(e){if(ou(this,t),this.window_size=1<21)throw new Oc("Window size out of range!");if(!t.extra_bits.length)for(var r=0,n=0;r<=50;r+=2)t.extra_bits[r]=t.extra_bits[r+1]=n,0!=r&&n<17&&n++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case Wc:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case Xc:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(Gc,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case Hc:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new Oc("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new Oc("Cannot run outside of window frame.");switch(this.block_type){case Wc:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Gc,12);if(h>3;if(f>2){var l=t.extra_bits[f];if(f=t.position_base[f]-2,l>3)l-=3,f+=e.readLZXBits(l)<<3,f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?f+=e.readLZXBits(l):f=1;this.R2=this.R1,this.R1=this.R0,this.R0=f}else 0===f?f=this.R0:1==f?(f=this.R1,this.R1=this.R0,this.R0=f):(f=this.R2,this.R2=this.R0,this.R0=f);var d=this.window_posn,v=void 0;if(u-=c,this.window_posn>=f)v=d-f;else{v=d+(this.window_size-f);var p=f-this.window_posn;if(p0;)this.win[d++]=this.win[v++];v=0}}for(this.window_posn+=c;c-- >0;)this.win[d++]=this.win[v++]}}break;case Xc:for(;u>0;){var y=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Gc,12);if(y>3;if(_>2){if(3!=_){var g=t.extra_bits[_],b=e.readLZXBits(g);_=t.position_base[_]-2+b}else _=1;this.R2=this.R1,this.R1=this.R0,this.R0=_}else 0===_?_=this.R0:1==_?(_=this.R1,this.R1=this.R0,this.R0=_):(_=this.R2,this.R2=this.R0,this.R0=_);var m=this.window_posn,k=void 0;if(u-=w,this.window_posn>=_)k=m-_;else{k=m+(this.window_size-_);var x=_-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=w;w-- >0;)this.win[m++]=this.win[k++]}}break;case Hc:if(e.bytePosition+u>n)throw new Oc("Overrun!"+n+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new Oc("Overrun table!");for(var c=o;c-- >0;)n[h++]=u}o>>=1}if(i==a)return n;for(var f=i;f>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var v=0;v>16,y=0;y>15-y&1&&p++;if(n[p]=v,(i+=o)>a)throw new Oc("Overrun table during decoding.")}o>>=1}if(i==a)return n;throw new Oc("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,r,n,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=n){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=n)}return t.bitPosition+=r[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var r=this.R2;this.R2=this.R0,this.R0=r}}}]),t}();Yc.position_base=[],Yc.extra_bits=[];var Kc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"decompress",value:function(t,e,r){for(var n,i,a=0,o=new Yc(16),s=new Fc(r);a65536||i>65536)throw new Oc("Invalid size read in compression content.");s.write(o.decompress(t,i,n)),a+=n}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),Jc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}},{key:"readU32",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}},{key:"writeU32",value:function(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}},{key:"imul",value:function(t,e){var r=65535&t,n=65535&e;return r*n+((t>>>16)*n+r*(e>>>16)<<16)|0}}]),t}(),qc=65536,$c=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),r=0;r=13)for(var d=67;r+4>>0;if(a=i[p=(p>>16^p)>>>0&65535]-1,i[p]=r+1,a<0||r-a>>>16>0||Jc.readU32(t,a)!==v)r+=d++>>6;else{for(d=67,h=r-o,u=r-a,a+=4,s=r+=4;r=$c){for(e[c++]=240+y,l=h-$c;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=(h<<4)+y;for(var w=0;w>8,s>=15){for(l=s-15;l>=255;l-=255)e[c++]=255;e[c++]=l}o=r}}if(0===o)return 0;if((h=f-o)>=$c){for(e[c++]=240,l=h-$c;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=h<<4;for(r=o;r2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,c=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(r=15&f,n=t[s++]|t[s++]<<8,15===r)for(;r+=t[s],255===t[s++];);if(r+=4,c&&1===n)e.fill(0|e[h-1],h,h+r),h+=r;else if(c&&n>r&&r>31)e.copyWithin(h,h-n,h-n+r),h+=r;else for(a=(o=h-n)+r;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var r=0,n=t.length,i=0,a=Math.max(32,n+(n>>1)+7),o=new Uint8Array(a>>3<<3);r=55296&&s<=56319){if(r=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+r/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var r=new Uint8Array(t),n=0,i=r.length,a=[];n65535&&(c-=65536,a.push(c>>>10&1023|55296),c=56320|1023&c),a.push(c)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},vf={};function pf(t){var e=vf[t];if(void 0!==e)return e.exports;var r=vf[t]={exports:{}};return df[t].call(r.exports,r,r.exports,pf),r.exports}pf.d=function(t,e){for(var r in e)pf.o(e,r)&&!pf.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},pf.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var yf={};!function(){pf.d(yf,{P:function(){return Or},m:function(){return Ar}}),pf(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,r=function(){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r);var n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=n?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return uu(r,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="",r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(r),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),r}();function n(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);n(u);var h=new Array(60);n(h);var c=new Array(512);n(c);var f=new Array(256);n(f);var l=new Array(29);n(l);var d,v,p,y=new Array(30);function w(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}function _(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(y);var g=function(t){return t<256?c[t]:c[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,r){t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<>>=1,r<<=1}while(--e>0);return r>>>1},E=function(t,e,r){var n,i,a=new Array(16),o=0;for(n=1;n<=15;n++)a[n]=o=o+r[n-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},R=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},A=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},O=function(t,e,r,n){var i=2*e,a=2*r;return t[i]>1;r>=1;r--)T(t,a,r);i=u;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],T(t,a,1),n=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=n,a[2*i]=a[2*r]+a[2*n],t.depth[i]=(t.depth[r]>=t.depth[n]?t.depth[r]:t.depth[n])+1,a[2*r+1]=a[2*n+1]=i,t.heap[1]=i++,T(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var r,n,i,a,o,s,u=e.dyn_tree,h=e.max_code,c=e.stat_desc.static_tree,f=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,v=e.stat_desc.max_length,p=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,r=t.heap_max+1;r<573;r++)(a=u[2*u[2*(n=t.heap[r])+1]+1]+1)>v&&(a=v,p++),u[2*n+1]=a,n>h||(t.bl_count[a]++,o=0,n>=d&&(o=l[n-d]),s=u[2*n],t.opt_len+=s*(a+o),f&&(t.static_len+=s*(c[2*n+1]+o)));if(0!==p){do{for(a=v-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[v]--,p-=2}while(p>0);for(a=v;0!==a;a--)for(n=t.bl_count[a];0!==n;)(i=t.heap[--r])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),n--)}}(t,e),E(a,h,t.bl_count)},I=function(t,e,r){var n,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(r+1)+1]=65535,n=0;n<=r;n++)i=o,o=e[2*(n+1)+1],++s>=7;n<30;n++)for(y[n]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),U(t,t.l_desc),U(t,t.d_desc),o=function(t){var e;for(I(t,t.dyn_ltree,t.l_desc.max_code),I(t,t.dyn_dtree,t.d_desc.max_code),U(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==e?L(t,e,r,n):4===t.strategy||a===i?(m(t,2+(n?1:0),3),S(t,u,h)):(m(t,4+(n?1:0),3),function(t,e,r,n){var i;for(m(t,e-257,5),m(t,r-1,5),m(t,n-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(f[r]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},j=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},M=function(t,e,r,n){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+e[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},F=new Uint32Array(function(){for(var t,e=[],r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e}()),V=function(t,e,r,n){var i=F,a=n+r;t^=-1;for(var o=n;o>>8^i[255&(t^e[o])];return-1^t},Z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},W=P,H=N,G=C,Y=D,K=j,J=X.Z_NO_FLUSH,q=X.Z_PARTIAL_FLUSH,$=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,rt=X.Z_STREAM_END,nt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ct=X.Z_FIXED,ft=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,vt=262,pt=103,yt=113,wt=666,_t=function(t,e){return t.msg=Z[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,r){return(e<t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Rt=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},At=function(t,e,r,n){var i=t.avail_in;return i>n&&(i=n),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),1===t.state.wrap?t.adler=M(t.adler,e,i,r):2===t.state.wrap&&(t.adler=V(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},Ot=function(t,e){var r,n,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-vt?t.strstart-(t.w_size-vt):0,h=t.window,c=t.w_mask,f=t.prev,l=t.strstart+dt,d=h[a+o-1],v=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(r=e)+o]===v&&h[r+o-1]===d&&h[r]===h[a]&&h[++r]===h[a+1]){a+=2,r++;do{}while(h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&ao){if(t.match_start=e,o=n,n>=s)break;d=h[a+o-1],v=h[a+o]}}}while((e=f[e&c])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Tt=function(t){var e,r,n,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-vt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=r=t.hash_size;do{n=t.head[--e],t.head[e]=n>=o?n-o:0}while(--r);e=r=o;do{n=t.prev[--e],t.prev[e]=n>=o?n-o:0}while(--r);i+=o}if(0===t.strm.avail_in)break;if(r=At(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=r,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-vt&&(t.match_length=Ot(t,r)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Ut=function(t,e){for(var r,n,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((n=Y(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Bt=[new It(0,0,0,0,(function(t,e){var r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+r;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-vt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,St),new It(4,5,16,8,St),new It(4,6,32,32,St),new It(4,4,16,16,Ut),new It(8,16,32,32,Ut),new It(8,16,128,128,Ut),new It(8,32,128,256,Ut),new It(32,128,258,1024,Ut),new It(32,258,258,4096,Ut)];function zt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Lt=function(t){var e,r=function(t){if(!t||!t.state)return _t(t,nt);t.total_in=t.total_out=0,t.data_type=ft;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:yt,t.adler=2===e.wrap?0:1,e.last_flush=J,W(e),et}(t);return r===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),r},Pt=function(t,e,r,n,i,a){if(!t)return nt;var o=1;if(e===ot&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>9||r!==lt||n<8||n>15||e<0||e>9||a<0||a>ct)return _t(t,nt);8===n&&(n=9);var s=new zt;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<tt||e<0)return t?_t(t,nt):nt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===wt&&e!==Q)return _t(t,0===t.avail_out?at:nt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=V(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=yt);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=yt,Rt(i,o),0!==i.strstart&&(Rt(i,t.adler>>>16),Rt(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=pt)}else i.status=pt;if(i.status===pt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=yt)):i.status=yt),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return _t(t,at);if(i.status===wt&&0!==t.avail_in)return _t(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==wt){var s=i.strategy===ut?function(t,e){for(var r;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var r,n,i,a,o=t.window;;){if(t.lookahead<=dt){if(Tt(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((n=o[i=t.strstart-1])===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+dt;do{}while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=wt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===q?K(i):e!==tt&&(H(i,0,0,!1),e===$&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?rt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Rt(i,t.adler>>>16),Rt(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:rt)},Ct=function(t){if(!t||!t.state)return nt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==pt&&e!==yt&&e!==wt?_t(t,nt):(t.state=null,e===yt?_t(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},jt=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var r=e.shift();if(r){if("object"!=nu(r))throw new TypeError(r+"must be non-object");for(var n in r)Dt(r,n)&&(t[n]=r[n])}}return t},Mt=function(t){for(var e=0,r=0,n=t.length;r=252?6:Zt>=248?5:Zt>=240?4:Zt>=224?3:Zt>=192?2:1;Vt[254]=Vt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,r,n,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&r):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|63&r):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|63&r);return e},Wt=function(t,e){var r,n,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var r="",n=0;nt.length&&(e=t.length);for(var r=e-1;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Vt[t[r]]>e?r:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Yt=Object.prototype.toString,Kt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,qt=X.Z_FULL_FLUSH,$t=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,re=X.Z_DEFAULT_STRATEGY,ne=X.Z_DEFLATED;function ie(t){this.options=jt({level:ee,method:ne,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Qt)throw new Error(Z[r]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Yt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=function(t,e){var r=e.length;if(!t||!t.state)return nt;var n=t.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return nt;if(1===i&&(t.adler=M(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){0===i&&(bt(n.head),n.strstart=0,n.block_start=0,n.insert=0);var a=new Uint8Array(n.w_size);a.set(e.subarray(r-n.w_size,r),0),e=a,r=n.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Tt(n);n.lookahead>=3;){var h=n.strstart,c=n.lookahead-2;do{n.ins_h=mt(n,n.ins_h,n.window[h+3-1]),n.prev[h&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=h,h++}while(--c);n.strstart=h,n.lookahead=2,Tt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,n.wrap=i,et}(this.strm,n),r!==Qt)throw new Error(Z[r]);this._dict_set=!0}}function ae(t,e){var r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||Z[r.err];return r.result}ie.prototype.push=function(t,e){var r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=e===~~e?e:!0===e?$t:Kt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Yt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===Jt||n===qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((r=Nt(i,n))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ct(this.strm),this.onEnd(r),this.ended=!0,r===Qt;if(0!==i.avail_out){if(n>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Mt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,R,A=t.state;r=t.next_in,E=t.input,n=r+(t.avail_in-5),i=t.next_out,R=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=A.dmax,u=A.wsize,h=A.whave,c=A.wnext,f=A.window,l=A.hold,d=A.bits,v=A.lencode,p=A.distcode,y=(1<>>=g=_>>>24,d-=g,0===(g=_>>>16&255))R[i++]=65535&_;else{if(!(16&g)){if(0==(64&g)){_=v[(65535&_)+(l&(1<>>=g,d-=g),d<15&&(l+=E[r++]<>>=g=_>>>24,d-=g,!(16&(g=_>>>16&255))){if(0==(64&g)){_=p[(65535&_)+(l&(1<s){t.msg="invalid distance too far back",A.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&A.sane){t.msg="invalid distance too far back",A.mode=30;break t}if(k=0,x=f,0===c){if(k+=u-g,g2;)R[i++]=x[k++],R[i++]=x[k++],R[i++]=x[k++],b-=3;b&&(R[i++]=x[k++],b>1&&(R[i++]=x[k++]))}else{k=i-m;do{R[i++]=R[k++],R[i++]=R[k++],R[i++]=R[k++],b-=3}while(b>2);b&&(R[i++]=R[k++],b>1&&(R[i++]=R[k++]))}break}}break}}while(r>3,l&=(1<<(d-=b<<3))-1,t.next_in=r,t.next_out=i,t.avail_in=r=1&&0===U[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(I[1]=0,_=1;_<15;_++)I[_+1]=I[_]+U[_];for(g=0;g852||2===t&&A>592)return 1;for(;;){v=_-E,o[g]d?(p=B[z+o[g]],y=T[S+o[g]]):(p=96,y=0),u=1<<_-E,b=h=1<>E)+(h-=u)]=v<<24|p<<16|y|0}while(0!==h);for(u=1<<_-1;O&u;)u>>=1;if(0!==u?(O&=u-1,O+=u):O=0,g++,0==--U[_]){if(_===m)break;_=e[r+o[g]]}if(_>k&&(O&f)!==c){for(0===E&&(E=k),l+=b,R=1<<(x=_-E);x+E852||2===t&&A>592)return 1;i[c=O&f]=k<<24|x<<16|l-a|0}}return 0!==O&&(i[l+O]=_-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,ve=X.Z_BLOCK,pe=X.Z_TREES,ye=X.Z_OK,we=X.Z_STREAM_END,_e=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Re=30,Ae=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Oe(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Te,Se,Ue=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ye}(t)},Ie=!0,Be=function(t){if(Ie){Te=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Te,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Ie=!1}t.lencode=Te,t.lenbits=9,t.distcode=Se,t.distbits=5},ze=function(t,e,r,n){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,Ue(t))}(t,e);return n!==ye&&(t.state=null),n},Ne=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,R,A=0,O=new Uint8Array(4),T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(r=t.state).mode===Ee&&(r.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,f=s,l=u,x=ye;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,O,2,0),h=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",r.mode=Re;break}if((15&h)!==xe){t.msg="unknown compression method",r.mode=Re;break}if(c-=4,k=8+(15&(h>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Re;break}r.dmax=1<>8&1),512&r.flags&&(O[0]=255&h,O[1]=h>>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>8&255,O[2]=h>>>16&255,O[3]=h>>>24&255,r.check=V(r.check,O,4,0)),h=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>8),512&r.flags&&(O[0]=255&h,O[1]=h>>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),k)),512&r.flags&&(r.check=V(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break t;d=0;do{k=n[a+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&d>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ee;break;case 10:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===s)break t;s--,h+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Be(r),r.mode=20,e===pe){h>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Re}h>>>=2,c-=2;break;case 14:for(h>>>=7&c,c-=7&c;c<32;){if(0===s)break t;s--,h+=n[a++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Re;break}if(r.length=65535&h,h=0,c=0,r.mode=15,e===pe)break t;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(n.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,r.length-=d;break}r.mode=Ee;break;case 17:for(;c<14;){if(0===s)break t;s--,h+=n[a++]<>>=5,c-=5,r.ndist=1+(31&h),h>>>=5,c-=5,r.ncode=4+(15&h),h>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Re;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,E={bits:r.lenbits},x=le(0,r.lens,0,19,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid code lengths set",r.mode=Re;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=y,c-=y,r.lens[r.have++]=_;else{if(16===_){for(R=y+2;c>>=y,c-=y,0===r.have){t.msg="invalid bit length repeat",r.mode=Re;break}k=r.lens[r.have-1],d=3+(3&h),h>>>=2,c-=2}else if(17===_){for(R=y+3;c>>=y)),h>>>=3,c-=3}else{for(R=y+7;c>>=y)),h>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Re;break}for(;d--;)r.lens[r.have++]=k}}if(r.mode===Re)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Re;break}if(r.lenbits=9,E={bits:r.lenbits},x=le(1,r.lens,0,r.nlen,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid literal/lengths set",r.mode=Re;break}if(r.distbits=6,r.distcode=r.distdyn,E={bits:r.distbits},x=le(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,E),r.distbits=E.bits,x){t.msg="invalid distances set",r.mode=Re;break}if(r.mode=20,e===pe)break t;case 20:r.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,r.hold=h,r.bits=c,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,r.mode===Ee&&(r.back=-1);break}for(r.back=0;w=(A=r.lencode[h&(1<>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&A,!(g+(y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,r.length=_,0===w){r.mode=26;break}if(32&w){r.back=-1,r.mode=Ee;break}if(64&w){t.msg="invalid literal/length code",r.mode=Re;break}r.extra=15&w,r.mode=22;case 22:if(r.extra){for(R=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;w=(A=r.distcode[h&(1<>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&A,!(g+(y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,64&w){t.msg="invalid distance code",r.mode=Re;break}r.offset=_,r.extra=15&w,r.mode=24;case 24:if(r.extra){for(R=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Re;break}r.mode=25;case 25:if(0===u)break t;if(d=l-u,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Re;break}d>r.wnext?(d-=r.wnext,v=r.wsize-d):v=r.wnext-d,d>r.length&&(d=r.length),p=r.window}else p=i,v=o-r.offset,d=r.length;d>u&&(d=u),u-=d,r.length-=d;do{i[o++]=p[v++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===u)break t;i[o++]=r.length,u--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===s)break t;s--,h|=n[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pe(this.strm,e.windowBits);if(r!==Ze)throw new Error(Z[r]);if(this.header=new je,function(t,e){if(!t||!t.state)return ge;var r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Me.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary))!==Ze))throw new Error(Z[r])}function Je(t,e){var r=new Ke(e);if(r.push(t),r.err)throw r.msg||Z[r.err];return r.result}Ke.prototype.push=function(t,e){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Me.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ne(a,n))===We&&s&&((r=De(a,s))===Ze?r=Ne(a,n):r===Ge&&(r=We));a.avail_in>0&&r===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Le(a),r=Ne(a,n);switch(r){case He:case Ge:case We:case Ye:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Xe))if("string"===this.options.to){var u=Ht(a.output,a.next_out),h=a.next_out-u,c=Wt(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(c)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Ze||0!==i){if(r===Xe)return r=Ce(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ke.prototype.onData=function(t){this.chunks.push(t)},Ke.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Mt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var qe=oe,$e=Ke,Qe=Je,tr=[137,80,78,71,13,10,26,10],er=[],rr=0;rr<256;rr++){for(var nr=rr,ir=0;ir<8;ir++)1&nr?nr=3988292384^nr>>>1:nr>>>=1;er[rr]=nr}var ar,or,sr,ur;function hr(t,e){return(4294967295^function(t,e,r){for(var n=4294967295,i=0;i>>8;return n}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(ar||(ar={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(or||(or={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(sr||(sr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(ur||(ur={}));var cr=new Uint8Array(0),fr=new Uint16Array([255]),lr=255===new Uint8Array(fr.buffer)[0],dr=function(t){cu(r,t);var e=_u(r);function r(t){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r),n=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return n._checkCrc=o,n._inflator=new $e,n._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},n._end=!1,n._hasPalette=!1,n._palette=[],n._compressionMethod=or.UNKNOWN,n._filterMethod=sr.UNKNOWN,n._interlaceMethod=ur.UNKNOWN,n._colorType=-1,n.setBigEndian(),n}return uu(r,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=f}else this._png.data=s}}]),r}(r);function vr(t,e,r){for(var n=0;n>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function _r(t,e,r,n,i){var a=0;if(0===r.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ou(this,n),(r=e.call(this))._colorType=ar.UNKNOWN,r._zlibOptions=ru(ru({},mr),i.zlib),r._png=r._checkData(t),r.setBigEndian(),r}return uu(n,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tr)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(or.DEFLATE),this.writeByte(sr.ADAPTIVE),this.writeByte(ur.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,n=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new r).setBigEndian(),h=0,c=0;c0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Er(t,e,r,n){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,r="";return"number"==typeof e?r=gu(" ",Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),gf(t,r,-1)}var mf=function(){function t(e,r,n){ou(this,t),this.startingLine=n||0,this.lineIndex=-1;for(var i=[],a=0;a=r;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;mu(n,'"')&&(i=n.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],n=n.replace(a[0],"")),i?(r||(r={}),o=i[1],s=n.replace(i[0],"").trim()):mu(n,"-")&&(r||(r=[]),s=n.slice(1).trim()),s=s?xf(s,u):kf(t.nextGroup(),u),Array.isArray(r)?r.push(s):r[o]=s}return e&&(r={type:e,data:r}),r}function xf(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Ef(t){var e=t.replace(/\t/g,"\t").split("\n");return kf(new mf(e))}function Rf(t){var e;if(Array.isArray(t)){e=[];for(var r=0;r","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var c=function(t,e){var r=[],n=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(Af(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(mu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Of(u))return"Texture2D"===u?(r.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&n.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,c=!0,f=!mu(u,"Dictionary")&&!mu(u,"Array")&&!mu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function Uf(t){var e={},r=t.xnbData,n=r.compressed,i=r.readerData,a=r.hiDef,o=r.target;return e.header={target:o,formatVersion:5,compressed:n?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=Rf(i),e.content=Tf(t.content),"SpriteFont"===Tc.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function If(t,e){if(t&&"object"==nu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var r=Object.keys(t),n=0;n1&&void 0!==arguments[1]&&arguments[1],r=If(t,"export");if(r){var n=r.value,i=n.type,a=n.data;return"Texture2D"===i&&(a=_f(n.width,n.height,new Uint8Array(a))),Pf(a,i)}if(e){var o=JSON.stringify(t,null,4);return Pf(o,"JSON")}return null}function Cf(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(n&&a&&(n=!1),!t.hasOwnProperty("content"))throw new Oc("Invalid object!");var u=[],h=t.content,c=Nf(h,a);if(null!==c&&u.push(c),a)return u;var f=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(zf(e.type)):"".concat(e.type,".").concat(zf(e.type)):e}),4),l=f;return n&&(l=bf(Sf(t))),u.unshift(Pf(l,n?"yaml":"JSON")),u}function Df(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function jf(t){return Mf.apply(this,arguments)}function Mf(){return(Mf=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ff(t){return Vf.apply(this,arguments)}function Vf(){return(Vf=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Zf(t,e){return Xf.apply(this,arguments)}function Xf(){return Xf=au(regeneratorRuntime.mark((function t(e,r){var n,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,Ff(r.png);case 3:return n=t.sent,i=wf(new Uint8Array(n)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,Ff(r.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,Ff(r.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,jf(r.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),Xf.apply(this,arguments)}function Wf(t){return Hf.apply(this,arguments)}function Hf(){return Hf=au(regeneratorRuntime.mark((function t(e){var r,n,i,a,o,s,u,h,c,f,l,d,v=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=v.length>1&&void 0!==v[1]?v[1]:{},n=r.compression,i=void 0===n?"default":n,a=e.json||e.yaml){t.next=5;break}throw new Oc("There is no JSON or YAML file to pack!");case 5:return t.next=7,jf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):Uf(Ef(o)),null!==(u=Df(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new Oc("".concat(a.name,' does not have "content".'));case 14:if(!(h=If(s.content,"export"))){t.next=21;break}return c=h.parent,f=h.value,l=Bf(f),d=l[1],t.next=20,Zf(d,e);case 20:c.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),Hf.apply(this,arguments)}function Gf(t){return Yf.apply(this,arguments)}function Yf(){return(Yf=au(regeneratorRuntime.mark((function t(e){var r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(r=Bf(e.name),"xnb"===r[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return n=t.sent,t.abrupt("return",Kf(n));case 8:return t.abrupt("return",Kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Kf(t){return(new lf).load(t)}function Jf(t){var e=Nf(t.content,!0),r=e.data,n=e.extension;return new uf(r,n)}function qf(t){for(var e={},r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),tl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(Qf),el=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){for(var r=(new tl).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),rl=[55296,56320];function nl(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function il(t){var e=function(t){for(var e=ku({length:t.length},(function(e,r){return t.charCodeAt(r)})),r=[],n=0;n>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(Qf),hl=function(t){cu(r,t);var e=_u(r);function r(t,n){var i;if(ou(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return uu(r,[{key:"read",value:function(t,e){for(var r={},n=(new tl).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),cl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(Qf),fl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new tl).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new tl).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(Qf),ll=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(Qf),dl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){for(var r=(new tl).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),vl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new sl,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new sl,null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),pl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),yl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new ll;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new ll;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(Qf),wl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(Qf),_l=256;function gl(t,e,r,n){for(var i=Array(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),a=Array(r),o=0;o=Math.abs(i);){var c=h[0][0],f=h[0][1],l=gl(c,f,bl(t[c][c],t[f][f],t[c][f]),r);t=kl(l,t),a=xl(a,l),h=ml(t)}for(var d=0;d0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;ou(this,t),this._values=[e,r,n]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Ol(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;ou(this,t),this._values=[e,r,n,i]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new Al(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var a=0;a<4;a++)n[i+4+a]=r[4*a+0]|r[4*a+1]<<2|r[4*a+2]<<4|r[4*a+3]<<6}function Nl(t,e,r,n,i){var a,o=Ll(t),s=Ll(e);if(o<=s)a=r.slice();else{var u=[s,o];o=u[0],s=u[1],a=r.map((function(t){return 0===t?1:1===t?0:t}))}Pl(o,s,a,n,i)}function Cl(t,e,r,n,i){var a,o=Ll(t),s=Ll(e);if(o=128||!i)){var l=this._remap[s],d=(e[4*o+3]+1)/256;this._weights[l]+=a?d:1,this._remap[o]=l;break}}else this._remap[o]=-1}for(var v=0;v=n?t:(n=o,a)}),0);return i+=n,a}));if(is&&(a=r[h],s=c)}this.start=i.clampGrid().clone(),this.end=a.clampGrid().clone()}}}]),r}(jl),Vl=function(t){cu(r,t);var e=_u(r);function r(t){var n;ou(this,r);(n=e.call(this,t)).iterationCount=t.flags&_l?8:1,n.bestError=1/0,n.metric=new Ol(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,a=i.points,o=i.weights;return n.principle=Tl(a,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Ol(0),n}return uu(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Ol(.5,.5,.5,1/4),a=Ol.multiplyAdd(r,i,e),o=a.splatW,s=Ol.multiplyAdd(r,i,n);return{ax:a,aa:o,bx:s,bb:s.splatW,ab:Ol.multVector(r,i).splatW}}),(function(r,n,i){return Nl(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=new Ol(1/3,1/3,1/3,1/9),o=new Ol(2/3,2/3,2/3,4/9),s=new Ol(2/9),u=Ol.multiplyAdd(n,a,Ol.multiplyAdd(r,o,e)),h=u.splatW,c=Ol.multiplyAdd(r,a,Ol.multiplyAdd(n,o,i));return{ax:u,aa:h,bx:c,bb:c.splatW,ab:Ol.multVector(s,Ol.add(r,n)).splatW}}),(function(r,n,i){return Cl(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Ol(0),end:new Ol(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var a=function(e,n){var a=t(e),o=r.computeOptimalPoints(a);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var a={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(a.bestK=i),a},a=new Ol(0),o=0;o15?15:e}function Xl(t,e,r,n){var i=Wl(t,e,5),a=Wl(t,e,7);i.error<=a.error?function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Gl(i,n,a.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else Gl(n,i,a,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Gl(i,n,a.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else Gl(n,i,a,e,r)}(a,r,n)}function Wl(t,e,r){var n=function(t,e,r){for(var n=255,i=0,a=0;a<16;a++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*c&255;n[o]=f,o++}}}function Yl(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Kl(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function Jl(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,a=Yl(n),o=Yl(i);return[a,o,Kl(a,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Kl(a,o,2/3)]}(e,r,n),a=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var a=t[r+i];n[4*i+0]=3&a,n[4*i+1]=a>>2&3,n[4*i+2]=a>>4&3,n[4*i+3]=a>>6&3}return n}(e,r),o=0;o<16;o++)for(var s=0;s<4;s++)t[4*o+s]=i[a[o]][s]}function ql(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function $l(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_l&&(r=8),64!=n&&(n=32),e|r|n|128&t}function Ql(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,a=r.y,o=void 0===a?0:a,s=r.width,u=void 0===s?0:s,h=r.height,c=void 0===h?0:h,f=0;ql((function(r,n){var a=i+r,s=o+n;if(a>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],a=Hl(n,i,n<=i?5:7),o=new Uint8Array(16),s=0,u=2,h=0;h<2;h++){for(var c=0,f=0;f<3;f++)c|=e[r+u]<<8*f,u++;for(var l=0;l<8;l++){var d=c>>3*l&7;o[s]=d,s++}}for(var v=0;v<16;++v)t[4*v+3]=a[o[v]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function rd(t,e,r,n,i){var a=0!=(1&(i=$l(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,a=void 0===i?0:i,o=e.width,s=void 0===o?0:o,u=e.height,h=void 0===u?0:u,c=new Uint8Array(64),f=0,l=0;return ql((function(e,r){var i=n+e,o=a+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var s=r.read(t),u=t.read(s);if(4==n)u=sd(u,i,a,nd);else if(5==n)u=sd(u,i,a,id);else if(6==n)u=sd(u,i,a,ad);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var h=0;h","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(Qf),ld=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new ll).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ll).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(Qf),dd=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new wl;return{x:e.read(t),y:e.read(t)}}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}}]),r}(Qf),vd=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new wl;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}}]),r}(Qf),pd={ArrayReader:el,BaseReader:Qf,BmFontReader:ol,BooleanReader:sl,CharReader:ul,DictionaryReader:hl,DoubleReader:cl,EffectReader:fl,Int32Reader:ll,ListReader:dl,NullableReader:vl,RectangleReader:yl,ReflectiveReader:pl,SingleReader:wl,SpriteFontReader:fd,StringReader:al,TBinReader:ld,Texture2DReader:hd,UInt32Reader:tl,Vector2Reader:dd,Vector3Reader:cd,Vector4Reader:vd};ud=pd,Tc.setReaders(ud),t.Readers=pd,t.XnbContent=uf,t.XnbData=sf,t.addReaders=function(t){return Tc.addReaders(t)},t.bufferToContents=function(t){return Jf((new lf).load(t))},t.bufferToXnb=Kf,t.pack=function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=qf(t),n=[],i=Object.keys(r),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=Bf(s),h=u[0],c=function(t){return Cf(t,{yaml:n,contentOnly:a,fileName:h})};return Gf(t).then(c)},t.unpackToXnbData=Gf,t.xnbDataToContent=Jf,t.xnbDataToFiles=Cf,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/xnb.js b/dist/xnb.js index 409fbac..551691e 100644 --- a/dist/xnb.js +++ b/dist/xnb.js @@ -21,11 +21,152 @@ return Promise.all(mappedPromises); }; + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + + } + + class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + + } + + _defineProperty(TypeReader, "readers", {}); + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; const UTF8_SECOND_BITES = 0x80; const UTF8_MASK = 0b111111; - const UTF16_BITES = [0xD800, 0xDC00]; - const UTF16_MASK = 0b1111111111; + const UTF16_BITES$2 = [0xD800, 0xDC00]; + const UTF16_MASK$2 = 0b1111111111; function UTF8Encode(code) { if (code < 0x80) return [code]; @@ -37,7 +178,7 @@ function UTF16Encode(code) { if (code < 0xFFFF) return [code]; code -= 0x10000; - return [UTF16_BITES[0] | code >> 10 & UTF16_MASK, UTF16_BITES[1] | code & UTF16_MASK]; + return [UTF16_BITES$2[0] | code >> 10 & UTF16_MASK$2, UTF16_BITES$2[1] | code & UTF16_MASK$2]; } function UTF8Decode(codeSet) { @@ -56,17 +197,17 @@ return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); } - function UTF16Decode(codeSet) { + function UTF16Decode$2(codeSet) { var _codeSet2; if (typeof codeSet === "number") codeSet = [codeSet]; if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); const codeSetRange = codeSet.length; if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + return ((codeSet[0] & UTF16_MASK$2) << 10) + (codeSet[1] & UTF16_MASK$2) + 0x10000; } - function stringToUnicode(str) { + function stringToUnicode$2(str) { const utf16Map = Array.from({ length: str.length }, (_, i) => str.charCodeAt(i)); @@ -76,11 +217,11 @@ while (index < str.length) { let code = utf16Map[index]; - if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + if ((UTF16_BITES$2[0] & code) !== UTF16_BITES$2[0]) { result.push(code); index++; } else { - result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + result.push(UTF16Decode$2(utf16Map.slice(index, index + 2))); index += 2; } } @@ -142,7 +283,7 @@ } function stringToUTF8(str) { - return UnicodeToUTF8(stringToUnicode(str)); + return UnicodeToUTF8(stringToUnicode$2(str)); } function UTF8ToString(utf8Array) { @@ -574,17 +715,43 @@ } - class XnbError extends Error { - constructor() { - let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - super(message); - this.name = this.constructor.name; - this.message = message; - Error.captureStackTrace(this, XnbError); - } - - } - + /** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ const MIN_MATCH = 2; const NUM_CHARS = 256; const BLOCKTYPE = { @@ -1080,6 +1247,9 @@ } + /** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ const minMatch = 4; const minLength = 13; const searchLimit = 5; @@ -1294,56 +1464,43 @@ return compressBlock(src, dst, 0, src.length, hashTable); } - class ReaderResolver { - constructor(readers) { - this.readers = readers; - } - - read(buffer) { - let index = buffer.read7BitNumber() - 1; - if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); - return this.readers[index].read(buffer, this); - } - - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } + const UTF16_BITES$1 = [0xD800, 0xDC00]; + const UTF16_MASK$1 = 0b1111111111; - getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; - } + function UTF16Decode$1(codeSet) { + var _codeSet2; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; } - class BaseReader { - isValueType() { - return true; - } - - get type() { - return this.constructor.name.slice(0, -6); - } - - read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } + function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - writeIndex(buffer, resolver) { - if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); - } + while (index < str.length) { + let code = utf16Map[index]; - toString() { - return this.type; + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } } + return result; } - function UTF8Length(str) { - const codes = stringToUnicode(str); + function UTF8Length$1(str) { + const codes = stringToUnicode$1(str); return codes.reduce((sum, unicode) => { if (unicode < 0x80) return sum + 1; if (unicode < 0x800) return sum + 2; @@ -1352,6138 +1509,6442 @@ }, 0); } - class StringReader extends BaseReader { + class StringReaderCore { read(buffer) { let length = buffer.read7BitNumber(); return buffer.readString(length); } - write(buffer, string, resolver) { - this.writeIndex(buffer, resolver); - const size = UTF8Length(string); + write(buffer, string) { + const size = UTF8Length$1(string); buffer.write7BitNumber(size); buffer.writeString(string); } - isValueType() { - return false; - } - } - class UInt32Reader extends BaseReader { + class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + read(buffer) { - return buffer.readUInt32(); + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; } } - class ArrayReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; + class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - let size = uint32Reader.read(buffer); - let array = []; + get target() { + var _this$header; - for (let i = 0; i < size; i++) { - let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - array.push(value); - } + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; - return array; - } + case 'm': + return "Windows Phone 7"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, resolver); + case 'x': + return "Xbox 360"; - for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); - } + case 'a': + return "Android"; - isValueType() { - return false; - } + case 'i': + return "iOS"; - get type() { - return "Array<".concat(this.reader.type, ">"); + default: + return "Unknown"; + } } - } + get formatVersion() { + var _this$header2; - class BmFontReader extends BaseReader { - read(buffer) { - const stringReader = new StringReader(); - const xml = stringReader.read(buffer); - return { - export: { - type: this.type, - data: xml - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); - } - - isValueType() { - return false; - } - - } - - class BooleanReader extends BaseReader { - read(buffer) { - return Boolean(buffer.readInt()); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; - } + case 0x4: + return "XNA Game Studio 3.1"; - class CharReader extends BaseReader { - read(buffer) { - let charSize = this._getCharSize(buffer.peekInt()); + case 0x5: + return "XNA Game Studio 4.0"; - return buffer.readString(charSize); + default: + return "Unknown"; + } } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } + get hidef() { + var _this$header3; - _getCharSize(byte) { - return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); } - } + get compressed() { + var _this$header4; - class DictionaryReader extends BaseReader { - constructor(key, value) { - if (key == undefined || value == undefined) throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - super(); - this.key = key; - this.value = value; + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); } - read(buffer, resolver) { - let dictionary = {}; - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - for (let i = 0; i < size; i++) { - let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - dictionary[key] = value; - } - - return dictionary; + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(Object.keys(content).length); - - for (let key of Object.keys(content)) { - this.key.write(buffer, key, this.key.isValueType() ? null : resolver); - this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); - } + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); } - isValueType() { - return false; + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); } - get type() { - return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + toString() { + return this.stringify(); } } - class DoubleReader extends BaseReader { - read(buffer) { - return buffer.readDouble(); - } + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } + case "yaml": + return "yaml"; - } + case "png": + return "Texture2D"; - class EffectReader extends BaseReader { - read(buffer) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const bytecode = buffer.read(size); - return { - export: { - type: this.type, - data: bytecode - } - }; - } + case "cso": + return "Effect"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + case 'tbin': + return "TBin"; - isValueType() { - return false; + case 'xml': + return "BmFont"; } + return "Others"; } - class Int32Reader extends BaseReader { - read(buffer) { - return buffer.readInt32(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); + class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; } } - class ListReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; + const HIDEF_MASK = 0x1; + const COMPRESSED_LZ4_MASK = 0x40; + const COMPRESSED_LZX_MASK = 0x80; + const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + + class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const list = []; + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); - for (let i = 0; i < size; i++) { - const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } + this._validateHeader(); - return list; - } + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); - for (let data of Object.values(content)) { - this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock$1(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } } - } - - get type() { - return "List<".concat(this.reader.type, ">"); - } - } + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; - class NullableReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } - read(buffer, resolver) { - const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); - } - - isValueType() { - return false; - } - - get type() { - return "Nullable<".concat(this.reader.type, ">"); - } - - } + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); - class RectangleReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const x = int32Reader.read(buffer); - const y = int32Reader.read(buffer); - const width = int32Reader.read(buffer); - const height = int32Reader.read(buffer); - return { - x, - y, - width, - height - }; - } + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); - } + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); - } + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } - class SingleReader extends BaseReader { - read(buffer) { - return buffer.readSingle(); + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; } } - const kDxt1 = 1 << 0; - const kDxt3 = 1 << 1; - const kDxt5 = 1 << 2; - const kColourIterativeClusterFit = 1 << 8; - const kColourClusterFit = 1 << 3; - const kColourRangeFit = 1 << 4; - const kColourMetricPerceptual = 1 << 5; - const kColourMetricUniform = 1 << 6; - const kWeightColourByAlpha = 1 << 7; + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; - function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); - } + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } - return keys; - } + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); - function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } + for (; i < n;) { + let e = t.charCodeAt(i++); - return target; - } + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } - function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } + if (e >= 55296 && e <= 56319) continue; + } - return obj; - } + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } - function Rot(theta) { - let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; - return Mat; - } + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } - function Rij(k, l, theta, N) { - let Mat = Array(N); + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = (i === j) * 1.0; - } + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); } + }, + e = {}; - let Rotij = Rot(theta); - Mat[k][k] = Rotij[0][0]; - Mat[l][l] = Rotij[1][1]; - Mat[k][l] = Rotij[0][1]; - Mat[l][k] = Rotij[1][0]; - return Mat; + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; } - function getTheta(aii, ajj, aij) { - let th = 0.0; - let denom = ajj - aii; - - if (Math.abs(denom) <= 1E-12) { - th = Math.PI / 4.0; - } else { - th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); - } + i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + var n = {}; - return th; - } + (() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); - function getAij(Mij) { - let N = Mij.length; - let maxMij = 0.0; - let maxIJ = [0, 1]; + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } - for (let i = 0; i < N; i++) { - for (let j = i + 1; j < N; j++) { - if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { - maxMij = Math.abs(Mij[i][j]); - maxIJ = [i, j]; - } + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; } - } - return [maxIJ, maxMij]; - } + isLittleEndian() { + return this.littleEndian; + } - function unitary(U, H) { - let N = U.length; - let Mat = Array(N); + setLittleEndian() { + return this.littleEndian = !0, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + isBigEndian() { + return !this.littleEndian; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + setBigEndian() { + return this.littleEndian = !1, this; + } - for (let k = 0; k < N; k++) { - for (let l = 0; l < N; l++) { - Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; - } - } + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; } - } - return Mat; - } + seek(t) { + return this.offset = t, this; + } - function AxB(A, B) { - let N = A.length; - let Mat = Array(N); + mark() { + return this._mark = this.offset, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + reset() { + return this.offset = this._mark, this; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + pushMark() { + return this._marks.push(this.offset), this; + } - for (let k = 0; k < N; k++) { - Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; - } + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; } - } - return Mat; - } + rewind() { + return this.offset = 0, this; + } - function eigens(Hij) { - let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; - let N = Hij.length; - let Ei = Array(N); - let e0 = Math.abs(convergence / N); - let Sij = Array(N); + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - for (let i = 0; i < N; i++) { - Sij[i] = Array(N); - } + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Sij[i][j] = (i === j) * 1.0; + return this; } - } - let Vab = getAij(Hij); + readBoolean() { + return 0 !== this.readUint8(); + } - while (Math.abs(Vab[1]) >= Math.abs(e0)) { - let i = Vab[0][0]; - let j = Vab[0][1]; - let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); - let Gij = Rij(i, j, psi, N); - Hij = unitary(Gij, Hij); - Sij = AxB(Sij, Gij); - Vab = getAij(Hij); - } + readInt8() { + return this._data.getInt8(this.offset++); + } - for (let i = 0; i < N; i++) { - Ei[i] = Hij[i][i]; - } + readUint8() { + return this._data.getUint8(this.offset++); + } - return sorting(Ei, Sij); - } + readByte() { + return this.readUint8(); + } - function sorting(values, vectors) { - let eigsCount = values.length; - vectors.length; - let pairs = Array.from({ - length: eigsCount - }, (_, i) => { - let vector = vectors.map(v => v[i]); - return { - value: values[i], - vec: vector - }; - }); - pairs.sort((a, b) => b.value - a.value); - let sortedValues = pairs.map(_ref => { - let { - value - } = _ref; - return value; - }); - let sortedVectors = pairs.map(_ref2 => { - let { - vec - } = _ref2; - return vec; - }); - return [sortedValues, sortedVectors]; - } + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); - function dominentPrincipalVector(matrix) { - let [, [dominentVector]] = eigens(matrix); - return dominentVector; - } + for (let i = 0; i < t; i++) e[i] = this.readByte(); - class Vec3 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values = [x, y, z]; - } + return e; + } - get x() { - return this._values[0]; - } + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); - get y() { - return this._values[1]; - } + return this.offset += 2, t; + } - get z() { - return this._values[2]; - } + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); - set x(value) { - this._values[0] = value; - } + return this.offset += 2, t; + } - set y(value) { - this._values[1] = value; - } + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); - set z(value) { - this._values[2] = value; - } + return this.offset += 4, t; + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } + return this.offset += 4, t; + } - get normalized() { - if (this.length === 0) return null; - return Vec3.multScalar(this, 1 / this.length); - } + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); - get colorInt() { - const floatToInt = value => { - const result = parseInt(value * 255 + 0.5); - return Math.max(Math.min(result, 255), 0); - }; + return this.offset += 4, t; + } - return this._values.map(floatToInt); - } + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); - clone() { - return new Vec3(this.x, this.y, this.z); - } + return this.offset += 8, t; + } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - return this; - } + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); - toVec4() { - let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return new Vec4(this.x, this.y, this.z, w); - } + return this.offset += 8, t; + } - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - return this; - } + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - return this; - } + return this.offset += 8, t; + } - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - return this; - } + readChar() { + return String.fromCharCode(this.readInt8()); + } - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - return this; - } + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (let i = 0; i < t; i++) e += this.readChar(); - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - return this; - } + return e; + } - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - return this; - } + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - return this; - } + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } - toString() { - return "Vec3( ".concat(this._values.join(", "), " )"); - } + writeByte(t) { + return this.writeUint8(t); + } - static add(a, b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } + writeBytes(t) { + this.ensureAvailable(t.length); - static sub(a, b) { - return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); - } + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z; - } + return this._updateLastWrittenByte(), this; + } - static multScalar(a, scalar) { - return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); - } + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static multVector(a, b) { - return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); - } + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static interpolate(a, b, p) { - let a_ = Vec3.multScalar(a, 1 - p); - let b_ = Vec3.multScalar(b, p); - return Vec3.add(a_, b_); - } + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } - } + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } - class Vec4 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values = [x, y, z, w]; - } + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } - get x() { - return this._values[0]; - } + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get y() { - return this._values[1]; - } + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get z() { - return this._values[2]; - } + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get w() { - return this._values[3]; - } + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } - set x(value) { - this._values[0] = value; - } + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); - set y(value) { - this._values[1] = value; - } + return this; + } - set z(value) { - this._values[2] = value; - } + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } - set w(value) { - this._values[3] = value; - } + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); - } + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; } - get normalized() { - if (this.length === 0) return null; - return Vec4.multScalar(this, 1 / this.length); - } + function s(t) { + let e = t.length; - get xyz() { - return new Vec3(this.x, this.y, this.z); + for (; --e >= 0;) t[e] = 0; } - get splatX() { - return new Vec4(this.x); - } + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); - get splatY() { - return new Vec4(this.y); - } + const _ = new Array(60); - get splatZ() { - return new Vec4(this.z); - } + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); - get splatW() { - return new Vec4(this.w); + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; } - clone() { - return new Vec4(this.x, this.y, this.z, this.w); + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - this._values[3] = w; - return this; - } + s(w); - toVec3() { - return this.xyz; - } + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - return this; - } + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - return this; - } + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; - subVector(v) { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - return this; - } + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - return this; - } + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - return this; - } + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; - reciprocal() { - this._values[0] = 1 / this._values[0]; - this._values[1] = 1 / this._values[1]; - this._values[2] = 1 / this._values[2]; - this._values[3] = 1 / this._values[3]; - return this; - } + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - return this; - } + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - return this; - } + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; - truncate() { - this._values[0] = Math.trunc(this._values[0]); - this._values[1] = Math.trunc(this._values[1]); - this._values[2] = Math.trunc(this._values[2]); - this._values[3] = Math.trunc(this._values[3]); - return this; - } + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - return this; - } + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); - toString() { - return "Vec4( ".concat(this._values.join(", "), " )"); - } + h = s; - static add(a, b) { - return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); - } + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); - static sub(a, b) { - return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); - } + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; - } + let l, + d, + _, + f, + c, + u, + w = 0; - static multScalar(a, scalar) { - return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); - } + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; - static multVector(a, b) { - return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); - } + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); - static interpolate(a, b, p) { - let a_ = Vec4.multScalar(a, 1 - p); - let b_ = Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; - static multiplyAdd(a, b, c) { - return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); - } + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); - static negativeMultiplySubtract(a, b, c) { - return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); - } + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - static compareAnyLessThan(left, right) { - return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; - } + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - } + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; - function computeWeightedCovariance(values, weights) { - let total = 0; - let mean = values.reduce((sum, value, i) => { - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1 / total); - let covariance = values.reduce((sum, value, i) => { - let weight = weights[i]; - let v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; - sum[0][1] += v.x * v.y * weight; - sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; - sum[1][2] += v.y * v.z * weight; - sum[2][2] += v.z * v.z * weight; - return sum; - }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - return covariance; - } - - function computePCA(values, weights) { - const covariance = computeWeightedCovariance(values, weights); - return new Vec3(...dominentPrincipalVector(covariance)); - } - - const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; - const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; - const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - - function floatToInt(value, limit) { - const integer = parseInt(value + 0.5); - if (integer < 0) return 0; - if (integer > limit) return integer; - return integer; - } - - function floatTo565(color) { - const r = floatToInt(31.0 * color.x, 31); - const g = floatToInt(63.0 * color.y, 63); - const b = floatToInt(31.0 * color.z, 31); - return r << 11 | g << 5 | b; - } - - function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { - result[blockOffset + 0] = firstColor & 0xff; - result[blockOffset + 1] = firstColor >> 8; - result[blockOffset + 2] = secondColor & 0xff; - result[blockOffset + 3] = secondColor >> 8; - - for (let y = 0; y < 4; y++) { - result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; - } - } - - function writeColourBlock3(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + let D = !1; - if (firstColor <= secondColor) { - remapped = indices.slice(); - } else { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); - } + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); - } + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); - function writeColourBlock4(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; - if (firstColor < secondColor) { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => (index ^ 0x1) & 0x3); - } else if (firstColor == secondColor) { - remapped = new Array(16).fill(0); - } else { - remapped = indices.slice(); - } + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); - } + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; - class ColorSet { - constructor(rgba, mask, flags) { - this.flags = flags; - this._count = 0; - this._transparent = false; - this._remap = []; - this._weights = []; - this._points = []; - const isDxt1 = (this.flags & kDxt1) != 0; - const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + for (e = 0; e <= 15; e++) s[e] = 0; - for (let i = 0; i < 16; i++) { - const bit = 1 << i; + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; - if ((mask & bit) == 0) { - this._remap[i] = -1; - continue; - } + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; - if (isDxt1 && rgba[4 * i + 3] < 128) { - this._remap[i] = -1; - this._transparent = true; - continue; - } + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; - for (let j = 0;; j++) { - if (j == i) { - const r = rgba[4 * i] / 255.0; - const g = rgba[4 * i + 1] / 255.0; - const b = rgba[4 * i + 2] / 255.0; - const a = (rgba[4 * i + 3] + 1) / 256.0; - this._points[this._count] = new Vec3(r, g, b); - this._weights[this._count] = weightByAlpha ? a : 1.0; - this._remap[i] = this._count; - this._count++; - break; - } + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; - const oldbit = 1 << j; - const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); - if (match) { - const index = this._remap[j]; - const w = (rgba[4 * i + 3] + 1) / 256.0; - this._weights[index] += weightByAlpha ? w : 1.0; - this._remap[i] = index; - break; - } - } - } + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; - for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); - } + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; - get transparent() { - return this._transparent; - } + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; - get count() { - return this._count; - } + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; - get points() { - return Object.freeze(this._points.slice()); - } + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; - get weights() { - return Object.freeze(this._weights.slice()); - } + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); - remapIndicesSingle(singleIndex, target) { - const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; - target.forEach((_, i) => target[i] = result[i]); - } + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); - remapIndices(indexMap, target) { - const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; - target.forEach((_, i) => target[i] = result[i]); - } + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; - } + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); - class ColorFit { - constructor(colorSet) { - this.colors = colorSet; - this.flags = colorSet.flags; - } + r %= 65521, s %= 65521; + } - compress(result, offset) { - const isDxt1 = (this.flags & kDxt1) != 0; + return r | s << 16 | 0; + }; - if (isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } else this.compress4(result, offset); - } + const F = new Uint32Array((() => { + let t, + e = []; - compress3(result, offset) {} + for (var i = 0; i < 256; i++) { + t = i; - compress4(result, offset) {} + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; - } + e[i] = t; + } - class SingleColourFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const singleColor = colorSet.points[0]; - this.color = singleColor.colorInt; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.index = 0; - this.error = Infinity; - this.bestError = Infinity; - } + return e; + })()); - compressBase(lookups, saveFunc) { - this.computeEndPoints(lookups); + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; - if (this.error < this.bestError) { - const indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - this.bestError = this.error; - } - } + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; - compress3(result, offset) { - const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; - this.compressBase(lookups, saveFunc); - } + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; - compress4(result, offset) { - const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + for (; --e >= 0;) t[e] = 0; + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; - this.compressBase(lookups, saveFunc); - } + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); - computeEndPoints(lookups) { - this.error = Infinity; + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; - for (let index = 0; index < 2; index++) { - const sources = []; - let error = 0; + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); - for (let channel = 0; channel < 3; channel++) { - const lookup = lookups[channel]; - const target = this.color[channel]; - sources[channel] = lookup[target][index]; - const diff = sources[channel][2]; - error += diff * diff; + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } } + } while ((e = _[e & d]) > h && 0 != --r); - if (error < this.error) { - this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); - this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); - this.index = 2 * index; - this.error = error; - } - } - } + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; - } + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; - class RangeFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - this.metric = new Vec3(1); + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722); - } + n = e, i = n; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.bestError = Infinity; - this.computePoints(); - } + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); - compressBase(codes, saveFunc) { - const { - points: values - } = this.colors; - let error = 0; - const closest = values.map(color => { - let minDist = Infinity; - const packedIndex = codes.reduce((idx, code, j) => { - const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; - if (dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - error += minDist; - return packedIndex; - }); + s += e; + } - if (error < this.bestError) { - let indices = new Uint8Array(16); - this.colors.remapIndices(closest, indices); - saveFunc(this.start, this.end, indices); - this.bestError = error; - } - } + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; - compress3(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; - this.compressBase(codes, saveFunc); - } + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); - compress4(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; - this.compressBase(codes, saveFunc); - } + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - computePoints() { - const { - count, - points: values, - weights - } = this.colors; - if (count <= 0) return; - const principle = computePCA(values, weights); - let start, end, min, max; - start = end = values[0]; - min = max = Vec3.dot(start, principle); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; - for (let i = 1; i < count; i++) { - let value = Vec3.dot(values[i], principle); + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); - if (value < min) { - start = values[i]; - min = value; - } else if (value > max) { - end = values[i]; - max = value; - } + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; } - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; } - } + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; - class ClusterFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const kMaxIterations = 8; - this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; - this.bestError = Infinity; - this.metric = new Vec4(1); + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722, 0); + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - const { - points: values, - weights - } = this.colors; - this.principle = computePCA(values, weights); - this.order = new Uint8Array(16 * kMaxIterations); - this.pointsWeights = []; - this.xSum_wSum = new Vec4(0); - } - - constructOrdering(axis, iteration) { - const currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration); - const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if (!uniqueOrder) return false; - this.copyOrderWeight(currentOrder); - return true; - } - - compress3(result, offset) { - const aabbx = _ref => { - let [part0,, part1, part2] = _ref; - const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); - const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; - this.compressBase(aabbx, saveFunc, 2); + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; } - compress4(result, offset) { - const aabbx = _ref2 => { - let [part0, part1, part2, part3] = _ref2; - const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); - const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); - const const2_9 = new Vec4(2 / 9); - const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; - this.compressBase(aabbx, saveFunc, 3); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; - compressBase(aabbFunc, saveFunc) { - let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - this.constructOrdering(this.principle, 0); - let best = { - start: new Vec4(0), - end: new Vec4(0), - error: this.bestError, - iteration: 0, - bestI: 0, - bestJ: 0 - }; - if (repeater === 3) best.bestK = 0; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - const leastSquares = (parts, internalIndices) => { - const aabbx = aabbFunc(parts); - const internalBest = this.computeOptimalPoints(aabbx); + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (internalBest.error < best.error) { - best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); - return true; - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; - return false; - }; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - for (let iterationIndex = 0;;) { - this.clusterIterate(iterationIndex, leastSquares, repeater); - if (best.iteration != iterationIndex) break; - iterationIndex++; - if (iterationIndex == this.iterationCount) break; - const newAxis = Vec4.sub(best.end, best.start).xyz; - if (!this.constructOrdering(newAxis, iterationIndex)) break; - } + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (best.error < this.bestError) this.saveBlock(best, saveFunc); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; - makeOrder(axis) { - const { - count, - points: values - } = this.colors; - const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); - return Array.from({ - length: count - }, (_, i) => i).sort((a, b) => { - if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; - return a - b; - }); - } + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); - copyOrderToThisOrder(order, iteration) { - const orderOffset = iteration * 16; - order.forEach((ord, i) => { - this.order[orderOffset + i] = ord; - }); - } + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); - checkOrderUnique(order, iteration) { - const { - count - } = this.colors; + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; - for (let it = 0; it < iteration; it++) { - let prevOffset = it * 16; - let same = true; + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } - for (let i = 0; i < count; i++) { - if (order[i] !== this.order[prevOffset + i]) { - same = false; - break; + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - } - if (same) return false; - } + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; - return true; - } + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } - copyOrderWeight(order) { - const { - count, - points: unweighted, - weights - } = this.colors; - this.xSum_wSum.set(0); + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; - for (let i = 0; i < count; i++) { - const j = order[i]; - const p = unweighted[j].toVec4(1); - const w = new Vec4(weights[j]); - const x = Vec4.multVector(p, w); - this.pointsWeights[i] = x; - this.xSum_wSum.addVector(x); - } - } + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); - computeOptimalPoints(vectorPoint) { - const { - ax, - bx, - aa, - bb, - ab - } = vectorPoint; - const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); - let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); - let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); - a.clampGrid(); - b.clampGrid(); - let error = this.computeError(_objectSpread2({ - a, - b - }, vectorPoint)); - return { - start: a, - end: b, - error - }; - } + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } - computeError(_ref3) { - let { - a, - b, - ax, - bx, - aa, - bb, - ab - } = _ref3; - const two = new Vec4(2); - const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); - const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); - const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); - const e4 = Vec4.multiplyAdd(two, e3, e1); - const e5 = Vec4.multVector(e4, this.metric); - return e5.x + e5.y + e5.z; - } + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - saveBlock(best, writeFunc) { - const { - count - } = this.colors; - const { - start, - end, - iteration, - error, - bestI, - bestJ, - bestK = -1 - } = best; - const orderOffset = iteration * 16; - const unordered = new Uint8Array(16); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } - const mapper = m => { - if (m < bestI) return 0; - if (m < bestJ) return 2; - if (m < bestK) return 3; - return 1; - }; + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; - for (let i = 0; i < count; i++) { - unordered[this.order[orderOffset + i]] = mapper(i); + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; } - const bestIndices = new Uint8Array(16); - this.colors.remapIndices(unordered, bestIndices); - writeFunc(start.xyz, end.xyz, bestIndices); - this.bestError = error; - } + const s = t.avail_in, + a = t.next_in, + o = t.input; - clusterIterate(index, func) { - let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - const { - count - } = this.colors; + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; - const indexMapper = (i, j, k) => { - const mapper = { - bestI: i, - bestJ: iterCount === 2 ? k : j, - iteration: index - }; - if (iterCount === 3) mapper.bestK = k; - return mapper; - }; + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); - let part0 = new Vec4(0.0); + n.strstart = t, n.lookahead = 2, zt(n); + } - for (let i = 0; i < count; i++) { - let part1 = new Vec4(0.0); + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; - for (let j = i;;) { - let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); - const kmin = j == 0 ? 1 : j; + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); - for (let k = kmin;;) { - const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - if (k == count) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); - if (iterCount === 2) break; - if (j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; - } + for (; e.length;) { + const i = e.shift(); - part0.addVector(this.pointsWeights[i]); + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } } - } - } + return t; + }, + Wt = t => { + let e = 0; - function quantise(alpha) { - const GRID = 15; - let result = Math.floor(alpha * (GRID / 255) + 0.5); - if (result < 0) return 0; - if (result > GRID) return GRID; - return result; - } + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; - function compressAlphaDxt3(rgba, mask, result, offset) { - for (let i = 0; i < 8; i++) { - let quant1 = quantise(rgba[8 * i + 3]); - let quant2 = quantise(rgba[8 * i + 7]); - const bit1 = 1 << 2 * i; - const bit2 = 1 << 2 * i + 1; - if ((mask & bit1) == 0) quant1 = 0; - if ((mask & bit2) == 0) quant2 = 0; - result[offset + i] = quant1 | quant2 << 4; - } - } + const i = new Uint8Array(e); - function compressAlphaDxt5(rgba, mask, result, offset) { - let step5 = interpolateAlpha(rgba, mask, 5); - let step7 = interpolateAlpha(rgba, mask, 7); - if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); - } + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } - function interpolateAlpha(rgba, mask, steps) { - let { - min, - max - } = setAlphaRange(rgba, mask, steps); - let code = setAlphaCodeBook(min, max, steps); - let indices = new Uint8Array(16); - let error = fitCodes(rgba, mask, code, indices); - return { - min, - max, - indices, - error + return i; }; - } - - function setAlphaRange(rgba, mask, steps) { - let min = 255; - let max = 0; - for (let i = 0; i < 16; i++) { - let bit = 1 << i; - if ((mask & bit) == 0) continue; - let value = rgba[4 * i + 3]; + let Kt = !0; - if (steps === 5) { - if (value !== 0 && value < min) min = value; - if (value !== 255 && value > max) max = value; - } else { - if (value < min) min = value; - if (value > max) max = value; - } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; } - if (min > max) min = max; - if (max - min < steps) max = Math.min(min + steps, 255); - if (max - min < steps) min = Math.max(max - steps, 0); - return { - min, - max - }; - } + const $t = new Uint8Array(256); - function setAlphaCodeBook(min, max, steps) { - let codes = [min, max, ...Array.from({ - length: steps - 1 - }, (_, i) => { - return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); - })]; + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - if (steps === 5) { - codes[6] = 0; - codes[7] = 255; - } + $t[254] = $t[254] = 1; - return codes; - } + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; - function fitCodes(rgba, mask, codes, indices) { - let err = 0; + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (let i = 0; i < 16; ++i) { - let bit = 1 << i; + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); - if ((mask & bit) == 0) { - indices[i] = 0; - continue; - } + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); - let value = rgba[4 * i + 3]; - let least = Infinity; - let index = 0; + for (r = 0, n = 0; n < i;) { + let e = t[n++]; - for (let j = 0; j < 8; ++j) { - let dist = value - codes[j]; - dist *= dist; + if (e < 128) { + s[r++] = e; + continue; + } - if (dist < least) { - least = dist; - index = j; + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); } } - indices[i] = index; - err += least; - } - - return err; - } + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; - function writeAlphaBlock5(_ref, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref; + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - if (index <= 5) return 7 - index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); - } + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; - function writeAlphaBlock7(_ref2, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref2; + for (; i >= 0 && 128 == (192 & t[i]);) i--; - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - return 9 - index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); - } + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; - function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { - result[offset] = alpha0; - result[offset + 1] = alpha1; - let indicesPointer = 0; - let resultPointer = offset + 2; + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; - for (let i = 0; i < 2; i++) { - let value = 0; + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); - for (let j = 0; j < 8; ++j) { - let index = indices[indicesPointer]; - value |= index << 3 * j; - indicesPointer++; + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; } + } - for (let j = 0; j < 3; ++j) { - let byte = value >> 8 * j & 0xff; - result[resultPointer] = byte; - resultPointer++; - } + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; } - } - function unpack565(color16bit) { - const red = color16bit >> 11 & 0x1f; - const green = color16bit >> 5 & 0x3f; - const blue = color16bit & 0x1f; - return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; - } + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; - function interpolateColorArray(a, b, amount) { - const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); - result[3] = 255; - return result; - } + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; - function unpackColorCodes(block, offset, isDxt1) { - const color1 = block[offset] | block[offset + 1] << 8; - const color2 = block[offset + 2] | block[offset + 3] << 8; - const unpackedColor1 = unpack565(color1); - const unpackedColor2 = unpack565(color2); - return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; - } + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } - function unpackIndices(block, blockOffset) { - let offset = blockOffset + 4; - let result = new Uint8Array(16); + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; - for (let i = 0; i < 4; i++) { - let packedIndices = block[offset + i]; - result[i * 4 + 0] = packedIndices & 0x3; - result[i * 4 + 1] = packedIndices >> 2 & 0x3; - result[i * 4 + 2] = packedIndices >> 4 & 0x3; - result[i * 4 + 3] = packedIndices >> 6 & 0x3; - } + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; - return result; - } + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; - function decompressColor(rgba, block, offset, isDxt1) { - const colorCode = unpackColorCodes(block, offset, isDxt1); - const indices = unpackIndices(block, offset); + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; - for (let i = 0; i < 16; i++) { - for (let j = 0; j < 4; j++) { - rgba[4 * i + j] = colorCode[indices[i]][j]; - } - } - } + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } - function decompressAlphaDxt3(rgba, block, offset) { - for (let i = 0; i < 8; ++i) { - let quant = block[offset + i]; - let lo = quant & 0x0f; - let hi = quant & 0xf0; - rgba[8 * i + 3] = lo | lo << 4; - rgba[8 * i + 7] = hi | hi >> 4; - } - } + if (32 & m) { + U.mode = 12; + break t; + } - function decompressAlphaDxt5(rgba, block, offset) { - let alpha0 = block[offset + 0]; - let alpha1 = block[offset + 1]; - let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); - let indices = new Uint8Array(16); - let indicePointer = 0; - let bytePointer = 2; + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } - for (let i = 0; i < 2; i++) { - let value = 0; + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; - for (let j = 0; j < 3; j++) { - let byte = block[offset + bytePointer]; - value |= byte << 8 * j; - bytePointer++; - } + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } - for (let j = 0; j < 8; j++) { - let index = value >> 3 * j & 0x7; - indices[indicePointer] = index; - indicePointer++; - } - } + t.msg = "invalid distance code", U.mode = 30; + break t; + } - for (let i = 0; i < 16; ++i) { - rgba[4 * i + 3] = codes[indices[i]]; - } - } + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } - const DXT1_COMPRESSED_BYTES = 8; - const DXT5_COMPRESSED_BYTES = 16; - const COLORS = 4; - const DECOMPRESSED_BLOCK_SIZE = 16; + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } - function blockRepeat(width, height, func) { - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - func(x, y); - } - } - } + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; - function rectRepeat(func) { - for (let y = 0; y < 4; y++) { - for (let x = 0; x < 4; x++) { - func(x, y); - } - } - } + do { + x[r++] = _[v++]; + } while (--m); - function FixFlags(flags) { - let method = flags & (kDxt1 | kDxt3 | kDxt5); - let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); - let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); - const extra = flags & kWeightColourByAlpha; - if (method != kDxt3 && method != kDxt5) method = kDxt1; - if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; - if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; - return method | fit | metric | extra; - } + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; - function GetStorageRequirements(width, height, flags) { - flags = FixFlags(flags); - const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); - const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - return blockcount * blocksize; - } + do { + x[r++] = _[v++]; + } while (--m); - function extractColorBlock(img) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - let mask = 0; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + if (v = 0, d < k) { + m = d, k -= m; - if (sx < width && sy < height) { - let sourceColorOffset = COLORS * (width * sy + sx); + do { + x[r++] = _[v++]; + } while (--m); - for (let i = 0; i < COLORS; i++) { - block[blockColorOffset++] = img[sourceColorOffset++]; + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; } + } while (i < n && r < a); - mask |= 1 << 4 * py + px; - } else blockColorOffset += COLORS; - }); - return { - block, - mask + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; }; - } - function copyBuffer(result, block) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); - if (sx < width && sy < height) { - let resultColorOffset = COLORS * (width * sy + sx); + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; - for (let i = 0; i < COLORS; i++) { - result[resultColorOffset + i] = block[blockColorOffset++]; - } - } else blockColorOffset += COLORS; - }); - } + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; - function getCompressor(colorSet) { - if (colorSet.count === 1) return new SingleColourFit(colorSet); - if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); - return new ClusterFit(colorSet); - } + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; - function CompressMasked(rgba, mask, result, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - const colors = new ColorSet(rgba, mask, flags); - const compressor = getCompressor(colors); - compressor.compress(result, offset + colorOffset); - if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); - } + for (w = 0; w <= 15; w++) z[w] = 0; - function decompressBlock(result, block, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); - if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); - } + for (p = 0; p < n; p++) z[e[i + p]]++; - function compressImage(source, width, height, result, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let targetBlockPointer = 0; - blockRepeat(width, height, function (x, y) { - const { - block: sourceRGBA, - mask - } = extractColorBlock(source, { - x, - y, - width, - height - }); - CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); - targetBlockPointer += bytesPerBlock; - }); - } + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); - function decompressImage(result, width, height, source, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let sourceBlockPointer = 0; + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - decompressBlock(targetRGBA, source, sourceBlockPointer, flags); - copyBuffer(result, targetRGBA, { - x, - y, - width, - height - }); - sourceBlockPointer += bytesPerBlock; - } - } - } + for (g = 1; g < b && 0 === z[g]; g++); - const flags = { - DXT1: kDxt1, - DXT3: kDxt3, - DXT5: kDxt5, - ColourIterativeClusterFit: kColourIterativeClusterFit, - ColourClusterFit: kColourClusterFit, - ColourRangeFit: kColourRangeFit, - ColourMetricPerceptual: kColourMetricPerceptual, - ColourMetricUniform: kColourMetricUniform, - WeightColourByAlpha: kWeightColourByAlpha - }; + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; - function compress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = GetStorageRequirements(width, height, flags); - const result = new Uint8Array(targetSize); - compressImage(source, width, height, result, flags); - return result; - } + if (v > 0 && (0 === t || 1 !== b)) return -1; - function decompress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = width * height * 4; - const result = new Uint8Array(targetSize); - decompressImage(result, width, height, source, flags); - return result; - } + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; - class Texture2DReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - let format = int32Reader.read(buffer); - let width = uint32Reader.read(buffer); - let height = uint32Reader.read(buffer); - let mipCount = uint32Reader.read(buffer); - if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); - let dataSize = uint32Reader.read(buffer); - let data = buffer.read(dataSize); - if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } else if (format != 0) throw new XnbError("Non-implemented Texture2D format type (".concat(format, ") found.")); + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); - for (let i = 0; i < data.length; i += 4) { - let inverseAlpha = 255 / data[i + 3]; - data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); - } + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; - return { - format, - export: { - type: this.type, - data, - width, - height + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; } - }; - } - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - this.writeIndex(buffer, resolver); - const width = content.export.width; - const height = content.export.height; - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - let data = content.export.data; + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; - for (let i = 0; i < data.length; i += 4) { - const alpha = data[i + 3] / 255; - data[i] = Math.floor(data[i] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } } - if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); - } - - isValueType() { - return false; - } + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; - } + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); - class Vector3Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - return { - x, - y, - z - }; + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; - } + let Ce, + De, + Ie = !0; - class SpriteFontReader extends BaseReader { - read(buffer, resolver) { - const int32Reader = new Int32Reader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(new CharReader()); - const texture = resolver.read(buffer); - const glyphs = resolver.read(buffer); - const cropping = resolver.read(buffer); - const characterMap = resolver.read(buffer); - const verticalLineSpacing = int32Reader.read(buffer); - const horizontalSpacing = singleReader.read(buffer); - const kerning = resolver.read(buffer); - const defaultCharacter = nullableCharReader.read(buffer); - return { - texture, - glyphs, - cropping, - characterMap, - verticalLineSpacing, - horizontalSpacing, - kerning, - defaultCharacter - }; - } + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const charReader = new CharReader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(charReader); - const texture2DReader = new Texture2DReader(); - const rectangleListReader = new ListReader(new RectangleReader()); - const charListReader = new ListReader(charReader); - const vector3ListReader = new ListReader(new Vector3Reader()); - this.writeIndex(buffer, resolver); + for (; e < 144;) t.lens[e++] = 8; - try { - texture2DReader.write(buffer, content.texture, resolver); - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } catch (ex) { - throw ex; - } + for (; e < 256;) t.lens[e++] = 9; - console.log("writing complitd!"); - } + for (; e < 280;) t.lens[e++] = 7; - isValueType() { - return false; - } + for (; e < 288;) t.lens[e++] = 8; - } + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; - class TBinReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - let size = int32Reader.read(buffer); - let data = buffer.read(size); - return { - export: { - type: this.type, - data - } - }; - } + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; - isValueType() { - return false; - } + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; - } + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; - class Vector2Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - return { - x, - y - }; - } + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } - } + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - class Vector4Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - let w = singleReader.read(buffer); - return { - x, - y, - z, - w - }; - } + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } - } + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } - const Readers = { - ArrayReader, - BaseReader, - BmFontReader, - BooleanReader, - CharReader, - DictionaryReader, - DoubleReader, - EffectReader, - Int32Reader, - ListReader, - NullableReader, - RectangleReader, - SingleReader, - SpriteFontReader, - StringReader, - TBinReader, - Texture2DReader, - UInt32Reader, - Vector2Reader, - Vector3Reader, - Vector4Reader - }; + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - const simplifyType = type => { - let simple = type.split(/`|,/)[0]; - let isArray = simple.endsWith('[]'); - if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; - switch (simple) { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - let subtypes = parseSubtypes(type).map(simplifyType); - return "Dictionary<".concat(subtypes[0], ",").concat(subtypes[1], ">"); + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.ArrayReader': - let arrayType = parseSubtypes(type).map(simplifyType); - return "Array<".concat(arrayType, ">"); + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - let listType = parseSubtypes(type).map(simplifyType); - return "List<".concat(listType, ">"); + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; + i.mode = 6; - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); - case 'xTile.Pipeline.TideReader': - return 'TBin'; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); - case 'BmFont.XmlSourceReader': - return 'BmFont'; + i.length = 0, i.mode = 8; - default: - throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); - } - }; + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; - const parseSubtypes = type => { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); - return matches; - }; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); - const getTypeInfo = type => { - let mainType = type.match(/[^<]+/)[0]; - let subtypes = type.match(/<(.+)>/); - subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; - return { - type: mainType, - subtypes - }; - }; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); - const getReader = typeString => { - let { - type, - subtypes - } = getTypeInfo(typeString); - subtypes = subtypes.map(getReader); - if (Readers.hasOwnProperty("".concat(type, "Reader"))) return new Readers["".concat(type, "Reader")](...subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); - }; + i.mode = 9; - class XnbData { - constructor(header, readers, content) { - let { - target, - formatVersion, - hidef, - compressed - } = header; - this.header = { - target, - formatVersion, - hidef, - compressed - }; - this.readers = readers; - this.content = content; - } + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get target() { - var _this$header; + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } - switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { - case 'w': - return "Microsoft Windows"; + l = 0, d = 0; + } - case 'm': - return "Windows Phone 7"; + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; - case 'x': - return "Xbox 360"; + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'a': - return "Android"; + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; - case 'i': - return "iOS"; + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; - default: - return "Unknown"; - } - } + case Ue: + if (e === pe || e === ge) break t; - get formatVersion() { - var _this$header2; + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } - switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { - case 0x3: - return "XNA Game Studio 3.0"; + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 0x4: - return "XNA Game Studio 3.1"; + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; - case 0x5: - return "XNA Game Studio 4.0"; + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } - default: - return "Unknown"; - } - } + break; - get hidef() { - var _this$header3; + case 2: + i.mode = 17; + break; - return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); - } + case 3: + t.msg = "invalid block type", i.mode = ze; + } - get compressed() { - var _this$header4; + l >>>= 2, d -= 2; + break; - return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); - } + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get contentType() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.type; - return "JSON"; - } + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } - get rawContent() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.data; - return JSON.stringify(this.content, (key, value) => { - if (key === "export") return value.type; - return value; - }, 4); - } + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; - stringify() { - return JSON.stringify({ - header: this.header, - readers: this.readers, - content: this.content - }, null, 4); - } + case 15: + i.mode = 16; - toString() { - return this.stringify(); - } + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } - } + i.mode = Ue; + break; - function extensionToDatatype(extension) { - switch (extension) { - case "json": - return "JSON"; + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case "yaml": - return "yaml"; + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } - case "png": - return "Texture2D"; + i.have = 0, i.mode = 18; - case "cso": - return "Effect"; + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'tbin': - return "TBin"; + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } - case 'xml': - return "BmFont"; - } + for (; i.have < 19;) i.lens[R[i.have++]] = 0; - return "Others"; - } + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } - class XnbContent { - constructor(data, ext) { - this.type = extensionToDatatype(ext); - this.content = data; - } + i.have = 0, i.mode = 19; - } + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - const HIDEF_MASK = 0x1; - const COMPRESSED_LZ4_MASK = 0x40; - const COMPRESSED_LZX_MASK = 0x80; - const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - class XnbConverter { - constructor() { - this.target = ''; - this.formatVersion = 0; - this.hidef = false; - this.compressed = false; - this.compressionType = 0; - this.buffer = null; - this.fileSize = 0; - this.readers = []; - this.sharedResources = []; - } + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - load(arrayBuffer) { - this.buffer = new BufferReader(arrayBuffer); + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - this._validateHeader(); + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - console.info('XNB file validated successfully!'); - this.fileSize = this.buffer.readUInt32(); - if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } - if (this.compressed) { - const decompressedSize = this.buffer.readUInt32(); + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - if (this.compressionType == COMPRESSED_LZX_MASK) { - const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; - const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } else if (this.compressionType == COMPRESSED_LZ4_MASK) { - const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - const decompressed = new Uint8Array(decompressedSize); - decompressBlock$1(trimmedArray, decompressed); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - } + for (; c--;) i.lens[i.have++] = v; + } + } - let count = this.buffer.read7BitNumber(); - const stringReader = new StringReader(); - const readers = []; + if (i.mode === ze) break; - for (let i = 0; i < count; i++) { - const type = stringReader.read(this.buffer); - const version = this.buffer.readInt32(); - const simpleType = simplifyType(type); - const reader = getReader(simpleType); - this.readers.push(reader); - readers.push({ - type, - version - }); - } + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } - const shared = this.buffer.read7BitNumber(); - if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); - const content = new ReaderResolver(this.readers); - const result = content.read(this.buffer); - console.log('Successfuly read XNB file!'); - return new XnbData({ - target: this.target, - formatVersion: this.formatVersion, - hidef: this.hidef, - compressed: this.compressed - }, readers, result); - } + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } - convert(json) { - const buffer = new BufferWriter(); - const stringReader = new StringReader(); - let { - target, - formatVersion, - hidef, - compressed - } = json.header; - this.target = target; - this.formatVersion = formatVersion; - this.hidef = hidef; - const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; - this.compressed = lz4Compression ? true : false; - buffer.writeString("XNB"); - buffer.writeString(this.target); - buffer.writeByte(this.formatVersion); - buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); - buffer.writeUInt32(0); - if (lz4Compression) buffer.writeUInt32(0); - buffer.write7BitNumber(json.readers.length); + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } - for (let reader of json.readers) { - this.readers.push(getReader(simplifyType(reader.type))); - stringReader.write(buffer, reader.type); - buffer.writeUInt32(reader.version); - } + if (i.mode = 20, e === ge) break t; - buffer.write7BitNumber(0); - const content = new ReaderResolver(this.readers); - content.write(buffer, json.content); - buffer.trim(); + case 20: + i.mode = 21; - if (lz4Compression) { - const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - let compressedSize = compressBound(trimmedArray.length); - let compressed = new Uint8Array(compressedSize); - compressedSize = compressSingleBlock(trimmedArray, compressed); - compressed = compressed.slice(0, compressedSize); - buffer.bytePosition = 6; - buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - buffer.writeUInt32(trimmedArray.length); - buffer.concat(compressed); - let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - return returnBuffer; + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; } - let fileSize = buffer.bytePosition; - buffer.bytePosition = 6; - buffer.writeUInt32(fileSize, 6); - return buffer.buffer; + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); } - _validateHeader() { - if (this.buffer == null) throw new XnbError('Buffer is null'); - const magic = this.buffer.readString(3); - if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); - this.target = this.buffer.readString(1).toLowerCase(); - this.formatVersion = this.buffer.readByte(); - const flags = this.buffer.readByte(1); - this.hidef = (flags & HIDEF_MASK) != 0; - this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; - this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; } - } + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; - var t = { - 396: function _() { - !function (t) { - if (t.TextEncoder && t.TextDecoder) return !1; + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); - function e() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; } - function i() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - fatal: !1 - }; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); - if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; } + } - Object.defineProperty(e.prototype, "encoding", { - value: "utf-8" - }), e.prototype.encode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); - let i = 0; - const n = t.length; - let r = 0, - s = Math.max(32, n + (n >> 1) + 7), - a = new Uint8Array(s >> 3 << 3); + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; - for (; i < n;) { - let e = t.charCodeAt(i++); + for (let t = 0; t < 256; t++) { + let e = t; - if (e >= 55296 && e <= 56319) { - if (i < n) { - const n = t.charCodeAt(i); - 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); - } + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; - if (e >= 55296 && e <= 56319) continue; - } + pi[t] = e; + } - if (r + 4 > a.length) { - s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; - const e = new Uint8Array(s); - e.set(a), a = e; - } + const gi = 4294967295; - if (0 != (4294967168 & e)) { - if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { - if (0 != (4292870144 & e)) continue; - a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; - } - a[r++] = 63 & e | 128; - } else a[r++] = e; - } + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; - return a.slice(0, r); - }, Object.defineProperty(i.prototype, "encoding", { - value: "utf-8" - }), Object.defineProperty(i.prototype, "fatal", { - value: !1 - }), Object.defineProperty(i.prototype, "ignoreBOM", { - value: !1 - }), i.prototype.decode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); - const i = new Uint8Array(t); - let n = 0; - const r = i.length, - s = []; + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; - for (; n < r;) { - const t = i[n++]; - if (0 === t) break; - if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { - const e = 63 & i[n++]; - s.push((31 & t) << 6 | e); - } else if (224 == (240 & t)) { - const e = 63 & i[n++], - r = 63 & i[n++]; - s.push((31 & t) << 12 | e << 6 | r); - } else if (240 == (248 & t)) { - let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; - e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); - } - } + case "IDAT": + this.decodeIDAT(t); + break; - return String.fromCharCode.apply(null, s); - }, t.TextEncoder = e, t.TextDecoder = i; - }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); - } - }, - e = {}; + case "IEND": + this._end = !0; + break; - function i(n) { - var r = e[n]; - if (void 0 !== r) return r.exports; - var s = e[n] = { - exports: {} - }; - return t[n].call(s.exports, s, s.exports, i), s.exports; - } + case "tRNS": + this.decodetRNS(t); + break; - i.d = (t, e) => { - for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { - enumerable: !0, - get: e[n] - }); - }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); - var n = {}; + case "iCCP": + this.decodeiCCP(t); + break; - (() => { - i.d(n, { - P: () => Mi, - m: () => Fi - }), i(396); - const t = new TextDecoder("utf-8"), - e = new TextEncoder(); + case "tEXt": + this.decodetEXt(t); + break; - class r { - constructor() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let i = !1; - "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); - const n = e.offset ? e.offset >>> 0 : 0, - s = t.byteLength - n; - let a = n; - (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; - } + case "pHYs": + this.decodepHYs(); + break; - available() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset + t <= this.length; - } + default: + this.skip(t); + } - isLittleEndian() { - return this.littleEndian; - } + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); - setLittleEndian() { - return this.littleEndian = !0, this; + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); } - isBigEndian() { - return !this.littleEndian; - } + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; - setBigEndian() { - return this.littleEndian = !1, this; - } + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; - skip() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset += t, this; - } + case mi.TRUECOLOUR: + i = 3; + break; - seek(t) { - return this.offset = t, this; - } + case mi.INDEXED_COLOUR: + i = 1; + break; - mark() { - return this._mark = this.offset, this; - } + case mi.GREYSCALE_ALPHA: + i = 2; + break; - reset() { - return this.offset = this._mark, this; - } + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; - pushMark() { - return this._marks.push(this.offset), this; + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); } - popMark() { - const t = this._marks.pop(); + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; - if (void 0 === t) throw new Error("Mark stack empty"); - return this.seek(t), this; + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); } - rewind() { - return this.offset = 0, this; + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); } - ensureAvailable() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; - if (!this.available(t)) { - const e = 2 * (this.offset + t), - i = new Uint8Array(e); - i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); - } + for (; e < t; e++) { + const t = this.readByte(); - return this; + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } } - readBoolean() { - return 0 !== this.readUint8(); + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; } - readInt8() { - return this._data.getInt8(this.offset++); + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); } - readUint8() { - return this._data.getUint8(this.offset++); + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; } - readByte() { - return this.readUint8(); + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); } - readBytes() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - const e = new Uint8Array(t); + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; - for (let i = 0; i < t; i++) e[i] = this.readByte(); + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; - return e; - } + case 1: + Ri(s, a, n, i); + break; - readInt16() { - const t = this._data.getInt16(this.offset, this.littleEndian); + case 2: + Ni(s, a, o, n); + break; - return this.offset += 2, t; - } + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; - readUint16() { - const t = this._data.getUint16(this.offset, this.littleEndian); + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } - return this.offset += 2, t; - } + o = a, h += n + 1; + } - readInt32() { - const t = this._data.getInt32(this.offset, this.littleEndian); + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; - return this.offset += 4, t; + var l; } - readUint32() { - const t = this._data.getUint32(this.offset, this.littleEndian); + } - return this.offset += 4, t; - } + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } - readFloat32() { - const t = this._data.getFloat32(this.offset, this.littleEndian); + function Ri(t, e, i, n) { + let r = 0; - return this.offset += 4, t; - } + for (; r < n; r++) e[r] = t[r]; - readFloat64() { - const t = this._data.getFloat64(this.offset, this.littleEndian); + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } - return this.offset += 8, t; - } + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } - readBigInt64() { - const t = this._data.getBigInt64(this.offset, this.littleEndian); + function Ti(t, e, i, n, r) { + let s = 0; - return this.offset += 8, t; - } + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - readBigUint64() { - const t = this._data.getBigUint64(this.offset, this.littleEndian); + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; - return this.offset += 8, t; + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; } + } - readChar() { - return String.fromCharCode(this.readInt8()); - } + function Oi(t, e, i, n, r) { + let s = 0; - readChars() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - let e = ""; + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - for (let i = 0; i < t; i++) e += this.readChar(); + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; - return e; + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; } + } - readUtf8() { - let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return i = this.readBytes(e), t.decode(i); - var i; - } + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } - writeBoolean(t) { - return this.writeUint8(t ? 255 : 0), this; - } + const Bi = { + level: 3 + }; - writeInt8(t) { - return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); } - writeUint8(t) { - return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); } - writeByte(t) { - return this.writeUint8(t); + encodeSignature() { + this.writeBytes(wi); } - writeBytes(t) { - this.ensureAvailable(t.length); - - for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - - return this._updateLastWrittenByte(), this; + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); } - writeInt16(t) { - return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); } - writeUint16(t) { - return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); } - writeInt32(t) { - return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; - writeUint32(t) { - return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } - writeFloat32(t) { - return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); } - writeFloat64(t) { - return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; - writeBigInt64(t) { - return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; - writeBigUint64(t) { - return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + case 3: + n.colorType = mi.TRUECOLOUR; + break; - writeChar(t) { - return this.writeUint8(t.charCodeAt(0)); - } + case 1: + n.colorType = mi.GREYSCALE; + break; - writeChars(t) { - for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; - return this; - } + default: + throw new Error("unsupported number of channels"); + } - writeUtf8(t) { - return this.writeBytes(function (t) { - return e.encode(t); - }(t)); - } + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; - toArray() { - return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; } - _updateLastWrittenByte() { - this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); } } - function s(t) { - let e = t.length; - - for (; --e >= 0;) t[e] = 0; + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); } - const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), - o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), - h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), - l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), - d = new Array(576); - s(d); - - const _ = new Array(60); - - s(_); - const f = new Array(512); - s(f); - const c = new Array(256); - s(c); - const u = new Array(29); - s(u); - const w = new Array(30); + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); - function p(t, e, i, n, r) { - this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + return n; } - let g, b, m; + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); - function k(t, e) { - this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + return n; } - s(w); + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); - const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], - v = (t, e) => { - t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; - }, - E = (t, e, i) => { - t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); - }, - A = (t, e, i) => { - E(t, i[2 * e], i[2 * e + 1]); - }, - x = (t, e) => { - let i = 0; + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + })(); - do { - i |= 1 & t, t >>>= 1, i <<= 1; - } while (--e > 0); + var r = n.P, + s = n.m; - return i >>> 1; - }, - U = (t, e, i) => { - const n = new Array(16); - let r, - s, - a = 0; + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } - for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); - for (s = 0; s <= e; s++) { - let e = t[2 * s + 1]; - 0 !== e && (t[2 * s] = x(n[e]++, e)); + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; } - }, - z = t => { - let e; - - for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); - for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } - for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + let s = '\n'; - t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; - }, - R = t => { - t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; - }, - N = (t, e, i, n) => { - const r = 2 * e, - s = 2 * i; - return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; - }, - T = (t, e, i) => { - const n = t.heap[i]; - let r = i << 1; + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); - for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } - t.heap[i] = n; - }, - O = (t, e, i) => { - let n, - r, - s, - h, - l = 0; - if (0 !== t.last_lit) do { - n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); - } while (l < t.last_lit); - A(t, 256, e); - }, - L = (t, e) => { - const i = e.dyn_tree, - n = e.stat_desc.static_tree, - r = e.stat_desc.has_stree, - s = e.stat_desc.elems; - let a, - o, - h, - l = -1; + s += '\n'; + } + } - for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } - for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; - for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } - h = s; + return stringify(object, gap, -1); + } - do { - a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); - } while (t.heap_len >= 2); + class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; - t.heap[--t.heap_max] = t.heap[1], ((t, e) => { - const i = e.dyn_tree, - n = e.max_code, - r = e.stat_desc.static_tree, - s = e.stat_desc.has_stree, - a = e.stat_desc.extra_bits, - o = e.stat_desc.extra_base, - h = e.stat_desc.max_length; + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); - let l, - d, - _, - f, - c, - u, - w = 0; + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } - for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } - for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + getLineNumber() { + return this.startingLine + this.lineIndex; + } - if (0 !== w) { - do { - for (f = h - 1; 0 === t.bl_count[f];) f--; + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); - t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; - } while (w > 0); + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } - for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); - } - })(t, e), U(i, l, t.bl_count); - }, - B = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } - for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); - }, - C = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } - for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { - if (o < l) do { - A(t, r, t.bl_tree); - } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); - o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); - } - }; + peek() { + return this.getLine(this.lineIndex + 1); + } - let D = !1; + finished() { + return this.lineIndex == this.lines.length - 1; + } - const I = (t, e, i, n) => { - E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { - R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; - })(t, e, i); - }; + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } - var S = { - _tr_init: t => { - D || ((() => { - let t, e, i, n, r; - const s = new Array(16); + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } - for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + return ''; + } - for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); - for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } - for (e = 0; e <= 15; e++) s[e] = 0; + return indentLevel; + } - for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + } - for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); - for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; - for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } - for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } - g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); - })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); - }, - _tr_stored_block: I, - _tr_flush_block: (t, e, i, n) => { - let r, - s, - a = 0; - t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { - let e, - i = 4093624447; + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } - for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } - if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } - for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + if (type) { + object = { + type: type, + data: object + }; + } - return 0; - })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { - let e; + return object; + } - for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + function getValue(value, type) { + value = JSON.parse(value); - return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; - })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { - let r; + if (type) { + value = { + type: type, + data: value + }; + } - for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + return value; + } - C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); - })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); - }, - _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), - _tr_align: t => { - E(t, 2, 3), A(t, 256, d), (t => { - 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); - })(t); - } - }, - Z = (t, e, i, n) => { - let r = 65535 & t | 0, - s = t >>> 16 & 65535 | 0, - a = 0; + function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } - for (; 0 !== i;) { - a = i > 2e3 ? 2e3 : i, i -= a; + function deepCopy(obj) { + let newObj; - do { - r = r + e[n++] | 0, s = s + r | 0; - } while (--a); + if (Array.isArray(obj)) { + newObj = []; - r %= 65521, s %= 65521; + for (let item of obj) { + newObj.push(deepCopy(item)); } - return r | s << 16 | 0; - }; - - const F = new Uint32Array((() => { - let t, - e = []; - - for (var i = 0; i < 256; i++) { - t = i; + return newObj; + } - for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + if (!!obj && typeof obj === "object") { + newObj = {}; - e[i] = t; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); } - return e; - })()); + return newObj; + } - var M = (t, e, i, n) => { - const r = F, - s = n + i; - t ^= -1; + return obj; + } - for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; - return -1 ^ t; - }, - P = { - 2: "need dictionary", - 1: "stream end", - 0: "", - "-1": "file error", - "-2": "stream error", - "-3": "data error", - "-4": "insufficient memory", - "-5": "buffer error", - "-6": "incompatible version" - }, - H = { - Z_NO_FLUSH: 0, - Z_PARTIAL_FLUSH: 1, - Z_SYNC_FLUSH: 2, - Z_FULL_FLUSH: 3, - Z_FINISH: 4, - Z_BLOCK: 5, - Z_TREES: 6, - Z_OK: 0, - Z_STREAM_END: 1, - Z_NEED_DICT: 2, - Z_ERRNO: -1, - Z_STREAM_ERROR: -2, - Z_DATA_ERROR: -3, - Z_MEM_ERROR: -4, - Z_BUF_ERROR: -5, - Z_NO_COMPRESSION: 0, - Z_BEST_SPEED: 1, - Z_BEST_COMPRESSION: 9, - Z_DEFAULT_COMPRESSION: -1, - Z_FILTERED: 1, - Z_HUFFMAN_ONLY: 2, - Z_RLE: 3, - Z_FIXED: 4, - Z_DEFAULT_STRATEGY: 0, - Z_BINARY: 0, - Z_TEXT: 1, - Z_UNKNOWN: 2, - Z_DEFLATED: 8 - }; + default: + return false; + } + } - const { - _tr_init: W, - _tr_stored_block: K, - _tr_flush_block: $, - _tr_tally: Y, - _tr_align: j - } = S, - { - Z_NO_FLUSH: G, - Z_PARTIAL_FLUSH: X, - Z_FULL_FLUSH: V, - Z_FINISH: q, - Z_BLOCK: J, - Z_OK: Q, - Z_STREAM_END: tt, - Z_STREAM_ERROR: et, - Z_DATA_ERROR: it, - Z_BUF_ERROR: nt, - Z_DEFAULT_COMPRESSION: rt, - Z_FILTERED: st, - Z_HUFFMAN_ONLY: at, - Z_RLE: ot, - Z_FIXED: ht, - Z_DEFAULT_STRATEGY: lt, - Z_UNKNOWN: dt, - Z_DEFLATED: _t - } = H, - ft = 258, - ct = 262, - ut = 103, - wt = 113, - pt = 666, - gt = (t, e) => (t.msg = P[e], e), - bt = t => (t << 1) - (t > 4 ? 9 : 0), - mt = t => { - let e = t.length; + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; - for (; --e >= 0;) t[e] = 0; - }; + default: + return false; + } + } - let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; - const yt = t => { - const e = t.state; - let i = e.pending; - i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); - }, - vt = (t, e) => { - $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); - }, - Et = (t, e) => { - t.pending_buf[t.pending++] = e; - }, - At = (t, e) => { - t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; - }, - xt = (t, e, i, n) => { - let r = t.avail_in; - return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); - }, - Ut = (t, e) => { - let i, - n, - r = t.max_chain_length, - s = t.strstart, - a = t.prev_length, - o = t.nice_match; - const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, - l = t.window, - d = t.w_mask, - _ = t.prev, - f = t.strstart + ft; - let c = l[s + a - 1], - u = l[s + a]; - t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; - do { - if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { - s += 2, i++; + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } - do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } - if (n = ft - (f - s), s = f - ft, n > a) { - if (t.match_start = e, a = n, n >= o) break; - c = l[s + a - 1], u = l[s + a]; - } + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; } - } while ((e = _[e & d]) > h && 0 != --r); - return a <= t.lookahead ? a : t.lookahead; - }, - zt = t => { - const e = t.w_size; - let i, n, r, s, a; + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } - do { - if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { - t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } - do { - r = t.head[--i], t.head[i] = r >= e ? r - e : 0; - } while (--n); + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); - n = e, i = n; + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } - do { - r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; - } while (--n); + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); - s += e; - } + return { + converted, + extractedImages, + extractedMaps + }; + } - if (0 === t.strm.avail_in) break; - if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); - } while (t.lookahead < ct && 0 !== t.strm.avail_in); - }, - Rt = (t, e) => { - let i, n; + function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { - if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { - t.match_length--; + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } - do { - t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; - } while (0 != --t.match_length); + obj = deepCopy(data); + } - t.strstart++; - } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); - } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; - if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); } - return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }, - Nt = (t, e) => { - let i, n, r; + return newObj; + } - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (!!obj && typeof obj === "object") { + newObj = {}; - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { - r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } - do { - ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); - } while (0 != --t.prev_length); + return newObj; + } + + return null; + } + + function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } - if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } else if (t.match_available) { - if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; - } else t.match_available = 1, t.strstart++, t.lookahead--; - } + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } - return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); - function Tt(t, e, i, n, r) { - this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; } - const Ot = [new Tt(0, 0, 0, 0, (t, e) => { - let i = 65535; + return result; + } - for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { - if (t.lookahead <= 1) { - if (zt(t), 0 === t.lookahead && e === G) return 1; - if (0 === t.lookahead) break; - } + function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; - t.strstart += t.lookahead, t.lookahead = 0; - const n = t.block_start + i; - if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; - if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; } + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); - }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + return null; + } - function Lt() { - this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; - } + function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } - const Bt = t => { - if (!t || !t.state) return gt(t, et); - t.total_in = t.total_out = 0, t.data_type = dt; - const e = t.state; - return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; - }, - Ct = t => { - const e = Bt(t); - var i; - return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; - }, - Dt = (t, e, i, n, r, s) => { - if (!t) return et; - let a = 1; - if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); - 8 === n && (n = 9); - const o = new Lt(); - return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); - }; + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; - var It = Dt, - St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, - Zt = (t, e) => { - let i, n; - if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; - const r = t.state; - if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); - r.strm = t; - const s = r.last_flush; - if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { - let e = _t + (r.w_bits - 8 << 4) << 8, - i = -1; - i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; - } - if (69 === r.status) if (r.gzhead.extra) { - for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + case "yaml": + return "yaml"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); - } else r.status = 73; - if (73 === r.status) if (r.gzhead.name) { - i = r.pending; + case "Texture2D": + return "png"; - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + case "Effect": + return "cso"; - n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + case 'TBin': + return "tbin"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); - } else r.status = 91; - if (91 === r.status) if (r.gzhead.comment) { - i = r.pending; + case 'BmFont': + return "xml"; + } - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + return "bin"; + } - n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); - } else r.status = ut; + case "yaml": + return "text/plain"; - if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { - if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; - } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + case "Texture2D": + return "image/png"; - if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + case "Effect": + return "application/x-cso"; - if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { - let i = r.strategy === at ? ((t, e) => { - let i; + case 'BmFont': + return "application/xml"; + } - for (;;) { - if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { - if (e === G) return 1; - break; - } + return "application/octet-stream"; + } - if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : r.strategy === ot ? ((t, e) => { - let i, n, r, s; - const a = t.window; + function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); - for (;;) { - if (t.lookahead <= ft) { - if (zt(t), t.lookahead <= ft && e === G) return 1; - if (0 === t.lookahead) break; - } + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; - if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { - s = t.strstart + ft; + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } - do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + return makeBlob(data, dataType); + } - t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); - } + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } - if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + + function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : Ot[r.level].func(r, e); - if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; - if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + return "".concat(value.type, ".").concat(getExtension(value.type)); } - return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); - }, - Ft = t => { - if (!t || !t.state) return et; - const e = t.state.status; - return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); - }, - Mt = (t, e) => { - let i = e.length; - if (!t || !t.state) return et; - const n = t.state, - r = n.wrap; - if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } - if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { - 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); - let t = new Uint8Array(n.w_size); - t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; - } + function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } - const s = t.avail_in, - a = t.next_in, - o = t.input; + async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); + } - for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { - let t = n.strstart, - e = n.lookahead - 2; + async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; + } - do { - n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; - } while (--e); + async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } - n.strstart = t, n.lookahead = 2, zt(n); - } + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } - return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; - }; + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } - const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } + } - var Ht = function Ht(t) { - const e = Array.prototype.slice.call(arguments, 1); + async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; - for (; e.length;) { - const i = e.shift(); + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } - if (i) { - if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + const found = searchElement(jsonData.content, "export"); - for (const e in i) Pt(i, e) && (t[e] = i[e]); - } - } + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } - return t; - }, - Wt = t => { - let e = 0; + return jsonData; + } - for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ - const i = new Uint8Array(e); + async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); - for (let e = 0, n = 0, r = t.length; e < r; e++) { - let r = t[e]; - i.set(r, n), n += r.length; + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); } - return i; - }; - - let Kt = !0; - - try { - String.fromCharCode.apply(null, new Uint8Array(1)); - } catch (t) { - Kt = !1; + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); } - const $t = new Uint8Array(256); - - for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - - $t[254] = $t[254] = 1; - - var Yt = t => { - if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); - let e, - i, - n, - r, - s, - a = t.length, - o = 0; + return bufferToXnb(file.buffer); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ - for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ - return e; - }, - jt = (t, e) => { - const i = e || t.length; - if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); - let n, r; - const s = new Array(2 * i); - for (r = 0, n = 0; n < i;) { - let e = t[n++]; + function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); - if (e < 128) { - s[r++] = e; - continue; - } + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); - let a = $t[e]; - if (a > 4) s[r++] = 65533, n += a - 1;else { - for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ - a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); - } - } - return ((t, e) => { - if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); - let i = ""; + function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ - for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - return i; - })(s, r); - }, - Gt = (t, e) => { - (e = e || t.length) > t.length && (e = t.length); - let i = e - 1; + function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ - for (; i >= 0 && 128 == (192 & t[i]);) i--; - return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; - }, - Xt = function Xt() { - this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; - }; + function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ - const Vt = Object.prototype.toString, - { - Z_NO_FLUSH: qt, - Z_SYNC_FLUSH: Jt, - Z_FULL_FLUSH: Qt, - Z_FINISH: te, - Z_OK: ee, - Z_STREAM_END: ie, - Z_DEFAULT_COMPRESSION: ne, - Z_DEFAULT_STRATEGY: re, - Z_DEFLATED: se - } = H; - function ae(t) { - this.options = Ht({ - level: ne, - method: se, - chunkSize: 16384, - windowBits: 15, - memLevel: 8, - strategy: re - }, t || {}); - let e = this.options; - e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); - if (i !== ee) throw new Error(P[i]); + function fileMapper(files) { + let returnMap = {}; - if (e.header && St(this.strm, e.header), e.dictionary) { - let t; - if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); - this._dict_set = !0; - } + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; } - function oe(t, e) { - const i = new ae(e); - if (i.push(t, !0), i.err) throw i.msg || P[i.err]; - return i.result; - } + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ - ae.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize; - let r, s; - if (this.ended) return !1; - for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { - if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ - if (0 !== i.avail_out) { - if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; - } else this.onData(i.output); - } - return !0; - }, ae.prototype.onData = function (t) { - this.chunks.push(t); - }, ae.prototype.onEnd = function (t) { - t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; + function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; - var he = { - Deflate: ae, - deflate: oe, - deflateRaw: function deflateRaw(t, e) { - return (e = e || {}).raw = !0, oe(t, e); - }, - gzip: function gzip(t, e) { - return (e = e || {}).gzip = !0, oe(t, e); - }, - constants: H - }, - le = function le(t, e) { - let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } - const U = t.state; - i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); + } - t: do { - c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + function setReaders(readers) { + return TypeReader.setReaders(readers); + } - e: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { - if (!(16 & m)) { - if (0 == (64 & m)) { - b = u[(65535 & b) + (f & (1 << m) - 1)]; - continue e; - } + function addReaders(readers) { + return TypeReader.addReaders(readers); + } - if (32 & m) { - U.mode = 12; - break t; - } + class BaseReader { + static isTypeOf(type) { + return false; + } - t.msg = "invalid literal/length code", U.mode = 30; - break t; - } + static hasSubType() { + return false; + } - k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } - i: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { - if (0 == (64 & m)) { - b = w[(65535 & b) + (f & (1 << m) - 1)]; - continue i; - } + static type() { + return this.name.slice(0, -6); + } - t.msg = "invalid distance code", U.mode = 30; - break t; - } + isValueType() { + return true; + } - if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + get type() { + return this.constructor.type(); + } - if (f >>>= m, c -= m, m = r - s, y > m) { - if (m = y - m, m > l && U.sane) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - if (v = 0, E = _, 0 === d) { - if (v += h - m, m < k) { - k -= m; + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - do { - x[r++] = _[v++]; - } while (--m); + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } - v = r - y, E = x; - } - } else if (d < m) { - if (v += h + d - m, m -= d, m < k) { - k -= m; + toString() { + return this.type; + } - do { - x[r++] = _[v++]; - } while (--m); + } - if (v = 0, d < k) { - m = d, k -= m; + class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; - do { - x[r++] = _[v++]; - } while (--m); + default: + return false; + } + } - v = r - y, E = x; - } - } - } else if (v += d - m, m < k) { - k -= m; + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } - do { - x[r++] = _[v++]; - } while (--m); + } - v = r - y, E = x; - } + class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; - for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + default: + return false; + } + } - k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); - } else { - v = r - y; + static hasSubType() { + return true; + } - do { - x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; - } while (k > 2); + constructor(reader) { + super(); + this.reader = reader; + } - k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); - } + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; - break; - } - } - break; - } - } while (i < n && r < a); + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } - k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; - }; + return array; + } - const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), - _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), - fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), - ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); - var ue = (t, e, i, n, r, s, a, o) => { - const h = o.bits; + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } - let l, - d, - _, - f, - c, - u, - w = 0, - p = 0, - g = 0, - b = 0, - m = 0, - k = 0, - y = 0, - v = 0, - E = 0, - A = 0, - x = null, - U = 0; + isValueType() { + return false; + } - const z = new Uint16Array(16), - R = new Uint16Array(16); - let N, - T, - O, - L = null, - B = 0; + get type() { + return "Array<".concat(this.reader.type, ">"); + } - for (w = 0; w <= 15; w++) z[w] = 0; + } - for (p = 0; p < n; p++) z[e[i + p]]++; + const UTF16_BITES = [0xD800, 0xDC00]; + const UTF16_MASK = 0b1111111111; - for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + function UTF16Decode(codeSet) { + var _codeSet2; - if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } - for (g = 1; g < b && 0 === z[g]; g++); + function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + while (index < str.length) { + let code = utf16Map[index]; - if (v > 0 && (0 === t || 1 !== b)) return -1; + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } - for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + return result; + } - for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } - if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; - for (;;) { - N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + default: + return false; + } + } - do { - d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; - } while (0 !== d); + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } - for (l = 1 << w - 1; A & l;) l >>= 1; + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } - if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { - if (w === b) break; - w = e[i + a[p]]; - } + isValueType() { + return false; + } - if (w > m && (A & f) !== _) { - for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + } - if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; - _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; - } + class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; } + } - return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; - }; + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } - const { - Z_FINISH: we, - Z_BLOCK: pe, - Z_TREES: ge, - Z_OK: be, - Z_STREAM_END: me, - Z_NEED_DICT: ke, - Z_STREAM_ERROR: ye, - Z_DATA_ERROR: ve, - Z_MEM_ERROR: Ee, - Z_BUF_ERROR: Ae, - Z_DEFLATED: xe - } = H, - Ue = 12, - ze = 30, - Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } - function Ne() { - this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + isValueType() { + return false; } - const Te = t => { - if (!t || !t.state) return ye; - const e = t.state; - return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; - }, - Oe = t => { - if (!t || !t.state) return ye; - const e = t.state; - return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); - }, - Le = (t, e) => { - let i; - if (!t || !t.state) return ye; - const n = t.state; - return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); - }, - Be = (t, e) => { - if (!t) return ye; - const i = new Ne(); - t.state = i, i.window = null; - const n = Le(t, e); - return n !== be && (t.state = null), n; - }; + } - let Ce, - De, - Ie = !0; + class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; - const Se = t => { - if (Ie) { - Ce = new Int32Array(512), De = new Int32Array(32); - let e = 0; + default: + return false; + } + } - for (; e < 144;) t.lens[e++] = 8; + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } - for (; e < 256;) t.lens[e++] = 9; + } - for (; e < 280;) t.lens[e++] = 7; + class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; - for (; e < 288;) t.lens[e++] = 8; + default: + return false; + } + } - for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { - bits: 9 - }), e = 0; e < 32;) t.lens[e++] = 5; + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); - ue(2, t.lens, 0, 32, De, 0, t.work, { - bits: 5 - }), Ie = !1; - } + return buffer.readString(charSize); + } - t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; - }, - Ze = (t, e, i, n) => { - let r; - const s = t.state; - return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; - }; + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } - var Fe = Oe, - Me = Be, - Pe = (t, e) => { - let i, - n, - r, - s, - a, - o, - h, - l, - d, - _, - f, - c, - u, - w, - p, - g, - b, - m, - k, - y, - v, - E, - A = 0; + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } - const x = new Uint8Array(4); - let U, z; - const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; - i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + } - t: for (;;) switch (i.mode) { - case 1: - if (0 === i.wrap) { - i.mode = 13; - break; - } + class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + default: + return false; + } + } - if (2 & i.wrap && 35615 === l) { - i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; - break; - } + static hasSubType() { + return true; + } - if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { - t.msg = "incorrect header check", i.mode = ze; - break; - } + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } - if ((15 & l) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); - if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { - t.msg = "invalid window size", i.mode = ze; - break; - } - i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; - break; + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } - case 2: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return dictionary; + } - if (i.flags = l, (255 & i.flags) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); - if (57344 & i.flags) { - t.msg = "unknown header flags set", i.mode = ze; - break; - } + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } - i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + isValueType() { + return false; + } - case 3: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } - i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + } - case 4: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; - i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + default: + return false; + } + } - case 5: - if (1024 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + read(buffer) { + return buffer.readDouble(); + } - i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; - } else i.head && (i.head.extra = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } - i.mode = 6; + } - case 6: - if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; - i.length = 0, i.mode = 7; + class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; - case 7: - if (2048 & i.flags) { - if (0 === o) break t; - c = 0; + default: + return false; + } + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); - } while (v && c < o); + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.name = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } - i.length = 0, i.mode = 8; + isValueType() { + return false; + } - case 8: - if (4096 & i.flags) { - if (0 === o) break t; - c = 0; + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); - } while (v && c < o); + class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.comment = null); + default: + return false; + } + } - i.mode = 9; + read(buffer) { + return buffer.readInt32(); + } - case 9: - if (512 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } - if (l !== (65535 & i.check)) { - t.msg = "header crc mismatch", i.mode = ze; - break; - } + } - l = 0, d = 0; - } + class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; - i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; - break; + default: + return false; + } + } - case 10: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + constructor(reader) { + super(); + this.reader = reader; + } - case 11: - if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; - t.adler = i.check = 1, i.mode = Ue; + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; - case Ue: - if (e === pe || e === ge) break t; + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } - case 13: - if (i.last) { - l >>>= 7 & d, d -= 7 & d, i.mode = 27; - break; - } + return list; + } - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); - switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { - case 0: - i.mode = 14; - break; + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } - case 1: - if (Se(i), i.mode = 20, e === ge) { - l >>>= 2, d -= 2; - break t; - } + isValueType() { + return false; + } - break; + get type() { + return "List<".concat(this.reader.type, ">"); + } - case 2: - i.mode = 17; - break; + } - case 3: - t.msg = "invalid block type", i.mode = ze; - } + class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; - l >>>= 2, d -= 2; - break; + default: + return false; + } + } - case 14: - for (l >>>= 7 & d, d -= 7 & d; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if ((65535 & l) != (l >>> 16 ^ 65535)) { - t.msg = "invalid stored block lengths", i.mode = ze; - break; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); - case 15: - i.mode = 16; + if (!hasValue) { + booleanReader.read(buffer); + return null; + } - case 16: - if (c = i.length, c) { - if (c > o && (c = o), c > h && (c = h), 0 === c) break t; - r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; - break; - } + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } - i.mode = Ue; - break; + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } - case 17: - for (; d < 14;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { - t.msg = "too many length or distance symbols", i.mode = ze; - break; - } + if (content !== null) { + buffer.writeByte(0); + return; + } - i.have = 0, i.mode = 18; + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - case 18: - for (; i.have < i.ncode;) { - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; - } + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } - for (; i.have < 19;) i.lens[R[i.have++]] = 0; + } - if (i.lencode = i.lendyn, i.lenbits = 7, U = { - bits: i.lenbits - }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid code lengths set", i.mode = ze; - break; - } + class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; - i.have = 0, i.mode = 19; + default: + return false; + } + } - case 19: - for (; i.have < i.nlen + i.ndist;) { - for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { - if (16 === b) { - for (z = p + 2; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (l >>>= p, d -= p, 0 === i.have) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } - v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; - } else if (17 === b) { - for (z = p + 3; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; - } else { - for (z = p + 7; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; - } + get type() { + return "".concat(this.reader.type); + } - if (i.have + c > i.nlen + i.ndist) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + } - for (; c--;) i.lens[i.have++] = v; - } - } + class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; - if (i.mode === ze) break; + default: + return false; + } + } - if (0 === i.lens[256]) { - t.msg = "invalid code -- missing end-of-block", i.mode = ze; - break; - } + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } - if (i.lenbits = 9, U = { - bits: i.lenbits - }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid literal/lengths set", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } - if (i.distbits = 6, i.distcode = i.distdyn, U = { - bits: i.distbits - }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { - t.msg = "invalid distances set", i.mode = ze; - break; - } + } - if (i.mode = 20, e === ge) break t; + class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; - case 20: - i.mode = 21; + default: + return false; + } + } - case 21: - if (o >= 6 && h >= 258) { - t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); - break; - } + read(buffer) { + return buffer.readSingle(); + } - for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } - if (g && 0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + } - l >>>= m, d -= m, i.back += m; - } + const kDxt1 = 1 << 0; + const kDxt3 = 1 << 1; + const kDxt5 = 1 << 2; + const kColourIterativeClusterFit = 1 << 8; + const kColourClusterFit = 1 << 3; + const kColourRangeFit = 1 << 4; + const kColourMetricPerceptual = 1 << 5; + const kColourMetricUniform = 1 << 6; + const kWeightColourByAlpha = 1 << 7; - if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { - i.mode = 26; - break; - } + function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } - if (32 & g) { - i.back = -1, i.mode = Ue; - break; - } + function Rij(k, l, theta, N) { + let Mat = Array(N); - if (64 & g) { - t.msg = "invalid literal/length code", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.extra = 15 & g, i.mode = 22; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } - case 22: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } - i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; - i.was = i.length, i.mode = 23; + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } - case 23: - for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return th; + } - if (0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; - l >>>= m, d -= m, i.back += m; - } + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } - if (l >>>= p, d -= p, i.back += p, 64 & g) { - t.msg = "invalid distance code", i.mode = ze; - break; - } + return [maxIJ, maxMij]; + } - i.offset = b, i.extra = 15 & g, i.mode = 24; + function unitary(U, H) { + let N = U.length; + let Mat = Array(N); - case 24: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - if (i.offset > i.dmax) { - t.msg = "invalid distance too far back", i.mode = ze; - break; + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; } + } + } + } - i.mode = 25; - - case 25: - if (0 === h) break t; + return Mat; + } - if (c = f - h, i.offset > c) { - if (c = i.offset - c, c > i.whave && i.sane) { - t.msg = "invalid distance too far back", i.mode = ze; - break; - } + function AxB(A, B) { + let N = A.length; + let Mat = Array(N); - c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; - } else w = r, u = a - i.offset, c = i.length; + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - c > h && (c = h), h -= c, i.length -= c; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - do { - r[a++] = w[u++]; - } while (--c); + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } - 0 === i.length && (i.mode = 21); - break; + return Mat; + } - case 26: - if (0 === h) break t; - r[a++] = i.length, h--, i.mode = 21; - break; + function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); - case 27: - if (i.wrap) { - for (; d < 32;) { - if (0 === o) break t; - o--, l |= n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } - if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { - t.msg = "incorrect data check", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } - l = 0, d = 0; - } + let Vab = getAij(Hij); - i.mode = 28; + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } - case 28: - if (i.wrap && i.flags) { - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } - if (l !== (4294967295 & i.total)) { - t.msg = "incorrect length check", i.mode = ze; - break; - } + return sorting(Ei, Sij); + } - l = 0, d = 0; - } + function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; + } - i.mode = 29; + function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; + } - case 29: - E = me; - break t; + class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } - case ze: - E = ve; - break t; + get x() { + return this._values[0]; + } - case 31: - return Ee; + get y() { + return this._values[1]; + } - default: - return ye; - } + get z() { + return this._values[2]; + } - return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; - }, - He = t => { - if (!t || !t.state) return ye; - let e = t.state; - return e.window && (e.window = null), t.state = null, be; - }, - We = (t, e) => { - if (!t || !t.state) return ye; - const i = t.state; - return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); - }, - Ke = (t, e) => { - const i = e.length; - let n, r, s; - return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; - }, - $e = function $e() { - this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; - }; + set x(value) { + this._values[0] = value; + } - const Ye = Object.prototype.toString, - { - Z_NO_FLUSH: je, - Z_FINISH: Ge, - Z_OK: Xe, - Z_STREAM_END: Ve, - Z_NEED_DICT: qe, - Z_STREAM_ERROR: Je, - Z_DATA_ERROR: Qe, - Z_MEM_ERROR: ti - } = H; + set y(value) { + this._values[1] = value; + } - function ei(t) { - this.options = Ht({ - chunkSize: 65536, - windowBits: 15, - to: "" - }, t || {}); - const e = this.options; - e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = Me(this.strm, e.windowBits); - if (i !== Xe) throw new Error(P[i]); - if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + set z(value) { + this._values[2] = value; } - function ii(t, e) { - const i = new ei(e); - if (i.push(t), i.err) throw i.msg || P[i.err]; - return i.result; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } - ei.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize, - r = this.options.dictionary; - let s, a, o; - if (this.ended) return !1; + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } - for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { - for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } - switch (s) { - case Je: - case Qe: - case qe: - case ti: - return this.onEnd(s), this.ended = !0, !1; - } + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; - if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { - let t = Gt(i.output, i.next_out), - e = i.next_out - t, - r = jt(i.output, t); - i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); - } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + return this._values.map(floatToInt); + } - if (s !== Xe || 0 !== o) { - if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; - if (0 === i.avail_in) break; - } - } + clone() { + return new Vec3(this.x, this.y, this.z); + } - return !0; - }, ei.prototype.onData = function (t) { - this.chunks.push(t); - }, ei.prototype.onEnd = function (t) { - t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; - var ni = { - Inflate: ei, - inflate: ii, - inflateRaw: function inflateRaw(t, e) { - return (e = e || {}).raw = !0, ii(t, e); - }, - ungzip: ii, - constants: H - }; - const { - Deflate: ri, - deflate: si, - deflateRaw: ai, - gzip: oi - } = he, - { - Inflate: hi, - inflate: li, - inflateRaw: di, - ungzip: _i - } = ni; - var fi = si, - ci = hi, - ui = li; - const wi = [137, 80, 78, 71, 13, 10, 26, 10], - pi = []; + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } - for (let t = 0; t < 256; t++) { - let e = t; + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } - for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } - pi[t] = e; + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; } - const gi = 4294967295; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } - function bi(t, e) { - return (function (t, e, i) { - let n = 4294967295; + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } - for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - return n; - }(0, t, e) ^ gi) >>> 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; } - var mi, ki, yi, vi; - !function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; - }(mi || (mi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; - }(ki || (ki = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; - }(yi || (yi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; - }(vi || (vi = {})); - const Ei = new Uint8Array(0), - Ai = new Uint16Array([255]), - xi = 255 === new Uint8Array(Ai.buffer)[0]; - - class Ui extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(t); - const { - checkCrc: i = !1 - } = e; - this._checkCrc = i, this._inflator = new ci(), this._png = { - width: -1, - height: -1, - channels: -1, - data: new Uint8Array(0), - depth: 1, - text: {} - }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); - } + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - decode() { - for (this.decodeSignature(); !this._end;) this.decodeChunk(); + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - return this.decodeImage(), this._png; - } + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } - decodeSignature() { - for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); - } + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } - decodeChunk() { - const t = this.readUint32(), - e = this.readChars(4), - i = this.offset; + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } - switch (e) { - case "IHDR": - this.decodeIHDR(); - break; + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } - case "PLTE": - this.decodePLTE(t); - break; + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } - case "IDAT": - this.decodeIDAT(t); - break; + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } - case "IEND": - this._end = !0; - break; + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } - case "tRNS": - this.decodetRNS(t); - break; + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } - case "iCCP": - this.decodeiCCP(t); - break; + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } - case "tEXt": - this.decodetEXt(t); - break; + } - case "pHYs": - this.decodepHYs(); - break; + class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } - default: - this.skip(t); - } + get x() { + return this._values[0]; + } - if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + get y() { + return this._values[1]; + } - if (this._checkCrc) { - const i = this.readUint32(), - n = t + 4, - r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); - if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); - } else this.skip(4); - } + get z() { + return this._values[2]; + } - decodeIHDR() { - const t = this._png; - t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { - if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); - return t; - }(this.readUint8()); - const e = this.readUint8(); - let i; + get w() { + return this._values[3]; + } - switch (this._colorType = e, e) { - case mi.GREYSCALE: - i = 1; - break; + set x(value) { + this._values[0] = value; + } - case mi.TRUECOLOUR: - i = 3; - break; + set y(value) { + this._values[1] = value; + } - case mi.INDEXED_COLOUR: - i = 1; - break; + set z(value) { + this._values[2] = value; + } - case mi.GREYSCALE_ALPHA: - i = 2; - break; + set w(value) { + this._values[3] = value; + } - case mi.TRUECOLOUR_ALPHA: - i = 4; - break; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } - default: - throw new Error("Unknown color type: ".concat(e)); - } + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } - if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); - this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); - } + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } - decodePLTE(t) { - if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); - const e = t / 3; - this._hasPalette = !0; - const i = []; - this._palette = i; + get xyz() { + return new Vec3(this.x, this.y, this.z); + } - for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); - } + get splatX() { + return new Vec4(this.x); + } - decodeIDAT(t) { - this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); - } + get splatY() { + return new Vec4(this.y); + } - decodetRNS(t) { - if (3 === this._colorType) { - if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); - let e = 0; + get splatZ() { + return new Vec4(this.z); + } - for (; e < t; e++) { - const t = this.readByte(); + get splatW() { + return new Vec4(this.w); + } - this._palette[e].push(t); - } + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } - for (; e < this._palette.length; e++) this._palette[e].push(255); - } - } + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } - decodeiCCP(t) { - let e, - i = ""; + toVec3() { + return this.xyz; + } - for (; "\0" !== (e = this.readChar());) i += e; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } - const n = this.readUint8(); - if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); - const r = this.readBytes(t - i.length - 2); - this._png.iccEmbeddedProfile = { - name: i, - profile: ui(r) - }; - } + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } - decodetEXt(t) { - let e, - i = ""; + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } - for (; "\0" !== (e = this.readChar());) i += e; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } - this._png.text[i] = this.readChars(t - i.length - 1); - } + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } - decodepHYs() { - const t = this.readUint32(), - e = this.readUint32(), - i = this.readByte(); - this._png.resolution = { - x: t, - y: e, - unit: i - }; - } + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } - decodeImage() { - if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); - const t = this._inflator.result; - if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); - if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); - this.decodeInterlaceNull(t); - } + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - decodeInterlaceNull(t) { - const e = this._png.height, - i = this._png.channels * this._png.depth / 8, - n = this._png.width * i, - r = new Uint8Array(this._png.height * n); - let s, - a, - o = Ei, - h = 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } - for (let l = 0; l < e; l++) { - switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { - case 0: - zi(s, a, n); - break; + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - case 1: - Ri(s, a, n, i); - break; + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - case 2: - Ni(s, a, o, n); - break; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } - case 3: - Ti(s, a, o, n, i); - break; + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } - case 4: - Oi(s, a, o, n, i); - break; + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } - default: - throw new Error("Unsupported filter: ".concat(t[h])); - } + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } - o = a, h += n + 1; - } + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } - if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { - const t = new Uint16Array(r.buffer); - if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; - this._png.data = t; - } else this._png.data = r; + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } - var l; - } + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); } - function zi(t, e, i) { - for (let n = 0; n < i; n++) e[n] = t[n]; + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } - function Ri(t, e, i, n) { - let r = 0; + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } - for (; r < n; r++) e[r] = t[r]; + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } - for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); } - function Ni(t, e, i, n) { - let r = 0; - if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; } - function Ti(t, e, i, n, r) { - let s = 0; + } - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; + function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } - for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; - } else { - for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); + } - for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; - } - } + const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - function Oi(t, e, i, n, r) { - let s = 0; + function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; + function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } - for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; - } else { - for (; s < r; s++) e[s] = t[s] + i[s] & 255; + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; - for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; - } + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; } + } - function Li(t, e, i) { - const n = t + e - i, - r = Math.abs(n - t), - s = Math.abs(n - e), - a = Math.abs(n - i); - return r <= s && r <= a ? t : s <= a ? e : i; + function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); } - const Bi = { - level: 3 - }; + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } - class Ci extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); - } + function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; - encode() { - return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); - } + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - encodeSignature() { - this.writeBytes(wi); - } + for (let i = 0; i < 16; i++) { + const bit = 1 << i; - encodeIHDR() { - this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); - } + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } - encodeIEND() { - this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); - } + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } - encodeIDAT(t) { - this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); - } + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } - encodeData() { - const { - width: t, - height: e, - channels: i, - depth: n, - data: s - } = this._png, - a = i * t, - o = new r().setBigEndian(); - let h = 0; + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { - if (16 !== n) throw new Error("unreachable"); - h = Si(s, o, a, h); + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } } - - const l = o.toArray(), - d = fi(l, this._zlibOptions); - this.encodeIDAT(d); } - _checkData(t) { - const { - colorType: e, - channels: i, - depth: n - } = function (t) { - const { - channels: e = 4, - depth: i = 8 - } = t; - if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); - if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); - const n = { - channels: e, - depth: i, - colorType: mi.UNKNOWN - }; - - switch (e) { - case 4: - n.colorType = mi.TRUECOLOUR_ALPHA; - break; + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } - case 3: - n.colorType = mi.TRUECOLOUR; - break; + get transparent() { + return this._transparent; + } - case 1: - n.colorType = mi.GREYSCALE; - break; + get count() { + return this._count; + } - case 2: - n.colorType = mi.GREYSCALE_ALPHA; - break; + get points() { + return Object.freeze(this._points.slice()); + } - default: - throw new Error("unsupported number of channels"); - } + get weights() { + return Object.freeze(this._weights.slice()); + } - return n; - }(t), - r = { - width: Di(t.width, "width"), - height: Di(t.height, "height"), - channels: i, - data: t.data, - depth: n, - text: {} - }; + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); - this._colorType = e; - const s = r.width * r.height * i; - if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); - return r; - } + target.forEach((_, i) => target[i] = result[i]); + } - writeCrc(t) { - this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); - } + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + target.forEach((_, i) => target[i] = result[i]); } - function Di(t, e) { - if (Number.isInteger(t) && t > 0) return t; - throw new TypeError("".concat(e, " must be a positive integer")); + } + + class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; } - function Ii(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeByte(t[n++]); + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; - return n; + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); } - function Si(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + compress3(result, offset) {} - return n; + compress4(result, offset) {} + + } + + class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; } - var Zi; - !function (t) { - t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; - }(Zi || (Zi = {})); + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); - const Fi = (t, e, i) => new Ci({ - width: t, - height: e, - data: i - }, undefined).encode(), - Mi = t => function (t, e) { - return new Ui(t, void 0).decode(); - }(t); - })(); + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } - var r = n.P, - s = n.m; + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - function isTypeObject(object) { - return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - function stringify(o, gap, indentation) { - if (isTypeObject(o)) { - let s = stringify(o.data, gap, indentation); + this.compressBase(lookups, saveFunc); + } - if (s.includes('\n')) { - return ' #!' + o.type + s; - } else { - return s + ' #!' + o.type; - } - } else if (o && 'object' === typeof o) { - let isArray = Array.isArray(o); + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - if (Object.keys(o).length == 0) { - if (isArray) return '[]';else return '{}'; - } + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - let s = '\n'; + this.compressBase(lookups, saveFunc); + } - for (let k in o) { - if (Object.hasOwnProperty.call(o, k)) { - s += gap.repeat(indentation + 1); + computeEndPoints(lookups) { + this.error = Infinity; - if (isArray) { - s += '- ' + stringify(o[k], gap, indentation + 1); - } else { - if (k.includes(': ')) { - s += stringify(k, gap, indentation + 1); - s += ': ' + stringify(o[k], gap, indentation + 1); - } else { - s += k + ': ' + stringify(o[k], gap, indentation + 1); - } - } + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; - s += '\n'; + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; } } - - return s; - } else if ('string' === typeof o) { - return JSON.stringify(o); - } else if ('undefined' === typeof o || o === null) { - return 'null'; - } else if (!!o == o || +o == o) { - return JSON.stringify(o); - } else { - throw new Error('Non-implemented parsing for ' + o); } + } - function preStringify(object) { - let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; - var gap = ''; + class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); - if (typeof space == 'number') { - gap = ' '.repeat(Math.min(10, space)); - } else if (typeof space == 'string') { - gap = space.slice(0, 10); + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); } - return stringify(object, gap, -1); - } + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); - class LineGenerator { - constructor(lines, indentString, startingLine) { - this.startingLine = startingLine || 0; - this.lineIndex = -1; - let filteredLines = []; + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } - for (let i = 0; i < lines.length; i++) { - let trimmedLine = lines[i].trim(); + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; - if (trimmedLine !== '') { - filteredLines.push([lines[i], i]); - } - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - this.lines = filteredLines; - this.indentString = indentString || this.findIndentString(); + this.compressBase(codes, saveFunc); } - getLineNumber() { - return this.startingLine + this.lineIndex; + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); } - nextGroup() { - let lines = []; - let baseIndent = this.indentLevel(this.lineIndex + 1); + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); - while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { - lines.push(this.next()); + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } } - return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); } - next() { - if (this.finished()) throw new Error('Trying to next finished generator'); - this.lineIndex++; - return this.getLine(); - } + } - peek() { - return this.getLine(this.lineIndex + 1); - } + class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); - finished() { - return this.lineIndex == this.lines.length - 1; - } + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } - getLine(index) { - index = index !== undefined ? index : this.lineIndex; - if (index >= this.lines.length) return null; - return this.lines[index][0]; + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); } - findIndentString() { - for (let [line] of this.lines) { - if (!line.trim() || line.replace(/^\s+/, "") == line) continue; - return line.match(/^(\s+)/)[1]; - } - - return ''; + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; } - indentLevel(index) { - index = index !== undefined ? index : this.lineIndex; - if (index < 0) index = 0; - let indentLevel = 0; - let line = this.getLine(index); + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - while (line.startsWith(this.indentString)) { - line = line.slice(this.indentString.length); - indentLevel++; - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - return indentLevel; + this.compressBase(aabbx, saveFunc, 2); } - } + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - function getObject(lineGroup, type) { - let object; - lineGroup.indentLevel(); + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - while (!lineGroup.finished()) { - let line = lineGroup.next(); - let trimmedLine = line.trim(); - let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); - let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); - let key, value, type; + this.compressBase(aabbx, saveFunc, 3); + } - if (trimmedLine.startsWith('"')) { - keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); - } + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; - if (typeMatch) { - type = typeMatch[1]; - trimmedLine = trimmedLine.replace(typeMatch[0], ''); - } + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); - if (keyMatch) { - if (!object) object = {}; - key = keyMatch[1]; - value = trimmedLine.replace(keyMatch[0], '').trim(); - } else if (trimmedLine.startsWith('-')) { - if (!object) object = []; - value = trimmedLine.slice(1).trim(); - } + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; - if (value) { - value = getValue(value, type); - } else { - value = getObject(lineGroup.nextGroup(), type); + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; } - if (Array.isArray(object)) { - object.push(value); - } else { - object[key] = value; - } + if (best.error < this.bestError) this.saveBlock(best, saveFunc); } - if (type) { - object = { - type: type, - data: object - }; + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); } - return object; - } - - function getValue(value, type) { - value = JSON.parse(value); - - if (type) { - value = { - type: type, - data: value - }; + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); } - return value; - } - - function parse(str) { - let lines = str.replace(/\t/g, ' ').split('\n'); - let lineGenerator = new LineGenerator(lines); - return getObject(lineGenerator); - } + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; - function deepCopy(obj) { - let newObj; + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; - if (Array.isArray(obj)) { - newObj = []; + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } - for (let item of obj) { - newObj.push(deepCopy(item)); + if (same) return false; } - return newObj; + return true; } - if (!!obj && typeof obj === "object") { - newObj = {}; + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); - for (let [key, value] of Object.entries(obj)) { - newObj[key] = deepCopy(value); + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); } - - return newObj; } - return obj; - } - - function isPrimitiveReaderType(reader) { - switch (reader) { - case 'Boolean': - case 'Int32': - case 'Char': - case 'String': - case '': - case 'Vector2': - case 'Vector3': - case 'Vector4': - case 'Rectangle': - return true; - - default: - return false; + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; } - } - - function isExportReaderType(reader) { - switch (reader) { - case 'Texture2D': - case 'TBin': - case 'Effect': - case 'BmFont': - return true; - default: - return false; + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; } - } - - function convertJsonContentsToXnbNode(raw, readers) { - let extractedImages = []; - let extractedMaps = []; - - const { - converted - } = function recursiveConvert(obj, path) { - let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - const reader = readers[index]; - if (isPrimitiveReaderType(reader)) { - return { - converted: { - type: reader, - data: obj - }, - traversed: index - }; - } + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); - if (reader === null) { - return { - converted: obj, - traversed: index - }; - } + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; - if (reader.startsWith('Nullable')) { - return { - converted: { - type: reader, - data: { - data: { - type: readers[index + 1], - data: obj - } - } - }, - traversed: index + 1 - }; + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); } - if (isExportReaderType(reader)) { - if (reader === 'Texture2D') { - extractedImages.push({ - path: path.join('.') - }); - return { - converted: { - type: reader, - data: { - format: obj.format - } - }, - traversed: index - }; - } + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } - if (reader === 'TBin') { - extractedMaps.push({ - path: path.join('.') - }); - } + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; - return { - converted: { - type: reader, - data: {} - }, - traversed: index + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index }; - } + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; - let data; - if (Array.isArray(obj)) data = [];else data = {}; - let traversed = index; - let first = true; - let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + let part0 = new Vec4(0.0); - for (let [key, value] of Object.entries(obj)) { - let newIndex; + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; - if (reader.startsWith("Dictionary")) { - if (getTypeInfo(reader).subtypes[1] === readers[index + 2]) newIndex = index + 2;else newIndex = index + 1; - } else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } - const { - converted, - traversed: nexter - } = recursiveConvert(obj[key], [...path, key], newIndex); - data[key] = converted; - if (isComplex) traversed = nexter;else if (first) { - traversed = nexter; - first = false; + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; } + + part0.addVector(this.pointsWeights[i]); } + } - return { - converted: { - type: reader, - data - }, - traversed - }; - }(raw, []); + } + + function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; + } + + function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } + } + + function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } + function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); return { - converted, - extractedImages, - extractedMaps + min, + max, + indices, + error }; } - function convertJsonContentsFromXnbNode(obj) { - if (!obj || typeof obj !== "object") return obj; + function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; - if (typeof obj === "object" && obj.hasOwnProperty("data")) { - let { - type, - data - } = obj; - if (isPrimitiveReaderType(type)) return deepCopy(data); + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; - if (isExportReaderType(type)) { - data = deepCopy(data); - if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; - return data; + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; } + } - obj = deepCopy(data); + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; + } + + function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; } - let newObj; + return codes; + } - if (Array.isArray(obj)) { - newObj = []; + function fitCodes(rgba, mask, codes, indices) { + let err = 0; - for (let item of obj) { - newObj.push(convertJsonContentsFromXnbNode(item)); + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; } - return newObj; - } + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; - if (!!obj && typeof obj === "object") { - newObj = {}; + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; - for (let [key, value] of Object.entries(obj)) { - newObj[key] = convertJsonContentsFromXnbNode(value); + if (dist < least) { + least = dist; + index = j; + } } - return newObj; + indices[i] = index; + err += least; } - return null; + return err; } - function toXnbNodeData(json) { - const toYamlJson = {}; - const { - compressed, - formatVersion, - hidef: hiDef, - target - } = json.header; - let readerData = deepCopy(json.readers); - toYamlJson.xnbData = { - target, - compressed: !!compressed, - hiDef, - readerData, - numSharedResources: 0 - }; - const rawContent = deepCopy(json.content); - let readersTypeList = readerData.map(_ref => { - let { - type - } = _ref; - return simplifyType(type); - }); + function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } - if (readersTypeList[0] === 'SpriteFont') { - readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; - rawContent.verticalSpacing = rawContent.verticalLineSpacing; - delete rawContent.verticalLineSpacing; + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } } + } - const { - converted, - extractedImages, - extractedMaps - } = convertJsonContentsToXnbNode(rawContent, readersTypeList); - toYamlJson.content = converted; - if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; - if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; - return toYamlJson; + function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; } - function fromXnbNodeData(json) { - const result = {}; - const { - compressed, - readerData, - hiDef: hidef, - target - } = json.xnbData; - result.header = { - target, - formatVersion: 5, - compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, - hidef - }; - result.readers = deepCopy(readerData); - result.content = convertJsonContentsFromXnbNode(json.content); + function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; + } - if (simplifyType(result.readers[0].type) === 'SpriteFont') { - result.content.verticalLineSpacing = result.content.verticalSpacing; - delete result.content.verticalSpacing; + function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } + + function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; } return result; } - function searchElement(parent, element) { - if (!parent || typeof parent != 'object') return; - - if (parent.hasOwnProperty(element)) { - return { - parent, - value: parent[element] - }; - } + function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); - for (let child of Object.values(parent)) { - if (!!child || typeof child == 'object') { - let found = searchElement(child, element); - if (found) return found; + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; } } - - return null; } - function extractFileName(fullname) { - let matcher = fullname.match(/(.*)\.([^\s.]+)$/); - if (matcher === null) return [fullname, null]; - return [matcher[1], matcher[2]]; + function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } } - function getExtension(dataType) { - switch (dataType) { - case "JSON": - return "json"; - - case "yaml": - return "yaml"; + function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; - case "Texture2D": - return "png"; + for (let i = 0; i < 2; i++) { + let value = 0; - case "Effect": - return "cso"; + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } - case 'TBin': - return "tbin"; + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } - case 'BmFont': - return "xml"; + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; } + } - return "bin"; + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ + const DXT1_COMPRESSED_BYTES = 8; + const DXT5_COMPRESSED_BYTES = 16; + const COLORS = 4; + const DECOMPRESSED_BLOCK_SIZE = 16; + + function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } } - function getMimeType(dataType) { - switch (dataType) { - case "JSON": - return "application/json"; + function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } + } - case "yaml": - return "text/plain"; + function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; + } - case "Texture2D": - return "image/png"; + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } - case "Effect": - return "application/x-cso"; + function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - case 'BmFont': - return "application/xml"; - } + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); - return "application/octet-stream"; - } + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } - function makeBlob(data, dataType) { - if (typeof Blob === "function") return { - data: new Blob([data], { - type: getMimeType(dataType) - }), - extension: getExtension(dataType) - }; + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); return { - data: data, - extension: getExtension(dataType) + block, + mask }; } - function exportContent(content) { - let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - let found = searchElement(content, "export"); + function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - if (found) { - const { - value - } = found; - let { - type: dataType, - data - } = value; + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); - if (dataType === "Texture2D") { - data = s(value.width, value.height, new Uint8Array(data)); - } + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } - return makeBlob(data, dataType); - } + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } - if (jsonContent) { - let contentJson = JSON.stringify(content, null, 4); - return makeBlob(contentJson, "JSON"); - } + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } - return null; + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); } - /** @api - * decompressed xnb object to real file blobs. - * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) - * @param {Object} config (yaml:export file as yaml, - * contentOnly:export content file only, - * fileName:exported files's name) (optional) - */ + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } - function exportFiles(xnbObject) { - let { - yaml: isYaml = false, - contentOnly = false, - fileName = null - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (isYaml && contentOnly) isYaml = false; - if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); - const blobs = []; - const { - content - } = xnbObject; - const contentBlob = exportContent(content, contentOnly); - if (contentBlob !== null) blobs.push(contentBlob); - if (contentOnly) return blobs; - const resultJSON = JSON.stringify(xnbObject, (key, value) => { - if (key === "export") { - if (typeof fileName == "string" && fileName !== "") { - return "".concat(fileName, ".").concat(getExtension(value.type)); - } + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; - return "".concat(value.type, ".").concat(getExtension(value.type)); + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; } - - return value; - }, 4); - let result = resultJSON; - if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); - blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); - return blobs; + } } - function resolveCompression(compressionString) { - let str = compressionString.toLowerCase(); - if (str === "none") return 0; - if (str === "lz4") return 0x40; - return null; - } + const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; - async function readBlobasText(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); + function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; } - async function readBlobasArrayBuffer(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; + function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; } - async function readExternFiles(extension, files) { - if (extension === "png") { - const rawPng = await readBlobasArrayBuffer(files.png); - const png = r(new Uint8Array(rawPng)); - return { - type: "Texture2D", - data: png.data, - width: png.width, - height: png.height - }; + class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } } - if (extension === "cso") { - const data = await readBlobasArrayBuffer(files.cso); + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + return { - type: "Effect", - data + format, + export: { + type: this.type, + data, + width, + height + } }; } - if (extension === "tbin") { - const data = await readBlobasArrayBuffer(files.tbin); - return { - type: "TBin", - data - }; + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); } - if (extension === "xml") { - const data = await readBlobasText(files.xml); - return { - type: "BmFont", - data - }; + isValueType() { + return false; } + } - async function resolveImports(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const { - compression = "default" - } = configs; - const jsonFile = files.json || files.yaml; - if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); - const rawText = await readBlobasText(jsonFile); - let jsonData = null; - if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); - let compressBits = resolveCompression(compression); - if (compressBits !== null) jsonData.header.compressed = compressBits; + class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; - if (!jsonData.hasOwnProperty('content')) { - throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + default: + return false; + } } - const found = searchElement(jsonData.content, "export"); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } - if (found) { - const { - parent, - value - } = found; - const [, extension] = extractFileName(value); - parent.export = await readExternFiles(extension, files); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); } - return jsonData; } - /** @api - * Asynchronously reads the file into binary and then unpacks the json data. - * XNB -> arrayBuffer -> XnbData - * @param {File / Buffer} file - * @return {XnbData} JSON data with headers - */ - - async function unpackToXnbData(file) { - if (typeof window !== "undefined") { - const [, extension] = extractFileName(file.name); + class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; - if (extension !== "xnb") { - return new Error("Invalid XNB File!"); + default: + return false; } - - const buffer = await file.arrayBuffer(); - return bufferToXnb(buffer); } - return bufferToXnb(file.buffer); - } - /** @api - * Asynchronously reads the file into binary and then return content file. - * XNB -> arrayBuffer -> XnbData -> Content - * @param {File / Buffer} file - * @return {XnbContent} exported Content Object - */ + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } - function unpackToContent(file) { - return unpackToXnbData(file).then(xnbDataToContent); - } - /** @api - * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. - * XNB -> arrayBuffer -> XnbData -> Files - * @param {File / Buffer} file - * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) - * @return {Array} exported Files Blobs - */ + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } - function unpackToFiles(file) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let { - yaml = false, - contentOnly = false, - fileName: name = null - } = configs; - if (typeof window !== "undefined" && name === null) name = file.name; - let [fileName] = extractFileName(name); + console.log("writing complitd!"); + } - const exporter = xnbObject => exportFiles(xnbObject, { - yaml, - contentOnly, - fileName - }); + isValueType() { + return false; + } - return unpackToXnbData(file).then(exporter); } - /** @api - * reads the buffer and then unpacks. - * arrayBuffer -> XnbData - * @param {ArrayBuffer} buffer - * @return {XnbData} the loaded XNB json - */ + class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; - function bufferToXnb(buffer) { - const xnb = new XnbConverter(); - return xnb.load(buffer); - } - /** @api - * reads the buffer and then unpacks the contents. - * arrayBuffer -> XnbData -> Content - * @param {ArrayBuffer} buffer - * @return {XnbContent} exported Content Object - */ + default: + return false; + } + } + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } - function bufferToContents(buffer) { - const xnb = new XnbConverter(); - const xnbData = xnb.load(buffer); - return xnbDataToContent(xnbData); - } - /** @api - * remove header from the loaded XNB Object - * XnbData -> Content - * @param {XnbData} the loaded XNB object include headers - * @return {XnbContent} exported Content Object - */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + isValueType() { + return false; + } - function xnbDataToContent(loadedXnb) { - const { - content - } = loadedXnb; - const { - data, - extension - } = exportContent(content, true); - return new XnbContent(data, extension); } - /** @api - * reads the json and then unpacks the contents. - * @param {FileList/Array} to pack json data - * @return {Object/Object} packed XNB Array Buffer - */ - - function fileMapper(files) { - let returnMap = {}; + class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; - for (let i = 0; i < files.length; i++) { - const file = files[i]; - let [fileName, extension] = extractFileName(file.name); - if (extension === null) continue; - if (returnMap[fileName] === undefined) returnMap[fileName] = {}; - const namedFileObj = returnMap[fileName]; - if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + default: + return false; + } } - return returnMap; - } - /** @api - * reads the json and then unpacks the contents. - * @param {json} to pack json data - * @return {ArrayBuffer} packed XNB Array Buffer - */ - + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } - function packJsonToBinary(json) { - const xnb = new XnbConverter(); - const buffer = xnb.convert(json); - return buffer; } - /** @api - * Asynchronously reads the file into binary and then pack xnb files. - * @param {FlieList} files - * @param {Object} configs(compression:default, none, LZ4, LZX / debug) - * @return {Array(Blobs)} - */ + class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; - function pack(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const groupedFiles = fileMapper(files); - let promises = []; + default: + return false; + } + } - for (let [fileName, filePack] of Object.entries(groupedFiles)) { - promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { - if (typeof Blob === "function") return { - name: fileName, - data: new Blob([buffer], { - type: "application/octet-stream" - }) - }; - return { - name: fileName, - data: new Uint8Array(buffer) - }; - })); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; } - return __promise_allSettled(promises).then(blobArray => { - if (configs.debug === true) return blobArray; - return blobArray.filter(_ref => { - let { - status, - value - } = _ref; - return status === "fulfilled"; - }).map(_ref2 => { - let { - value - } = _ref2; - return value; - }); - }); } + const Readers = { + ArrayReader: ArrayReader, + BaseReader: BaseReader, + BmFontReader: BmFontReader, + BooleanReader: BooleanReader, + CharReader: CharReader, + DictionaryReader: DictionaryReader, + DoubleReader: DoubleReader, + EffectReader: EffectReader, + Int32Reader: Int32Reader, + ListReader: ListReader, + NullableReader: NullableReader, + RectangleReader: RectangleReader, + ReflectiveReader: ReflectiveReader, + SingleReader: SingleReader, + SpriteFontReader: SpriteFontReader, + StringReader: StringReader, + TBinReader: TBinReader, + Texture2DReader: Texture2DReader, + UInt32Reader: UInt32Reader, + Vector2Reader: Vector2Reader, + Vector3Reader: Vector3Reader, + Vector4Reader: Vector4Reader + }; + setReaders(Readers); + + exports.Readers = Readers; exports.XnbContent = XnbContent; exports.XnbData = XnbData; + exports.addReaders = addReaders; exports.bufferToContents = bufferToContents; exports.bufferToXnb = bufferToXnb; exports.pack = pack; diff --git a/dist/xnb.min.js b/dist/xnb.min.js index 3fb9778..b56b4ac 100644 --- a/dist/xnb.min.js +++ b/dist/xnb.min.js @@ -1,3 +1,64 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)},i=[192,224,240],r=128,n=63,s=[55296,56320],a=1023;function o(t){return t<128?[t]:t<2048?[i[0]|t>>6,r|t&n]:t<65536?[i[1]|t>>12,r|t>>6&n,r|t&n]:[i[2]|t>>18,r|t>>12&n,r|t>>6&n,r|t&n]}function h(t){return t<65535?[t]:[s[0]|(t-=65536)>>10&a,s[1]|t&a]}function l(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const n=t.length;return 1===n?t[0]:2===n?((t[0]^i[0])<<6)+(t[1]^r):3===n?((t[0]^i[1])<<12)+((t[1]^r)<<6)+(t[2]^r):((t[0]^i[2])<<18)+((t[1]^r)<<12)+((t[2]^r)<<6)+(t[3]^r)}function c(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&a)<<10)+(t[1]&a)+65536}function d(t){return function(t){const e=[];for(let i of t)e.push(...o(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let r=0;for(;r1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const n=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),r=Math.min(Math.max(e,0),16-this.bitPosition),n=16-this.bitPosition-r,s=(t&2**r-1<>n;e-=r,this.bitPosition+=r,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class _{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}class w extends Error{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name=this.constructor.name,this.message=t,Error.captureStackTrace(this,w)}}const p=256,g=0,b=1,m=2,y=3,v=656;class k{constructor(t){if(this.window_size=1<21)throw new w("Window size out of range!");if(!k.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)k.extra_bits[t]=k.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!k.position_base.length)for(let t=0,e=0;t<=50;t++)k.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case m:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case b:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(v,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case y:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new w("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&r>0;){if(e>r&&(e=r),r-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new w("Cannot run outside of window frame.");switch(this.block_type){case m:for(;e>0;){let i,r=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,v,12);if(r>3;if(s>2){let e=k.extra_bits[s];if(s=k.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case b:for(;e>0;){let i,r=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,v,12);if(r>3;if(s>2){if(3!=s){let e=k.extra_bits[s],i=t.readLZXBits(e);s=k.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case y:if(t.bytePosition+e>i)throw new w("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let o=1;o<=e;o++){for(let e=0;es)throw new w("Overrun table!");let i=a;for(;i-- >0;)r[t++]=e}a>>=1}if(n==s)return r;for(let t=n;t>1>1;n<<=16,s<<=16,a=32768;for(let h=e+1;h<=16;h++){for(let l=0;l>16;for(let i=0;i>15-i&1&&t++;if(r[t]=l,(n+=a)>s)throw new w("Overrun table during decoding.")}a>>=1}if(n==s)return r;throw new w("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,r,n){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(n)];if(a>=r){let t=1<<32-n;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=r)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}k.position_base=[],k.extra_bits=[];class x{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,r=65535&e;return i*r+((t>>>16)*r+i*(e>>>16)<<16)|0}}const A=65536,E=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),i=0;i=13)for(var f=67;i+4>>0;if(s=n[w=(w>>16^w)>>>0&65535]-1,n[w]=i+1,s<0||i-s>>>16>0||x.readU32(t,s)!==_)i+=f++>>6;else{for(f=67,l=i-a,h=i-s,s+=4,o=i+=4;i=E){for(e[c++]=240+p,u=l-E;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=(l<<4)+p;for(var g=0;g>8,o>=15){for(u=o-15;u>=255;u-=255)e[c++]=255;e[c++]=u}a=i}}if(0===a)return 0;if((l=d-a)>=E){for(e[c++]=240,u=l-E;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let r=0;for(;re<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class T extends B{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,i){this.writeIndex(t,i);const r=O(e);t.write7BitNumber(r),t.writeString(e)}isValueType(){return!1}}class L extends B{read(t){return t.readUInt32()}write(t,e,i){this.writeIndex(t,i),t.writeUInt32(e)}}class N extends B{read(t){return Boolean(t.readInt())}write(t,e,i){this.writeIndex(t,i),t.writeByte(e)}}class D extends B{read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,i){this.writeIndex(t,i),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class C extends B{read(t){return t.readInt32()}write(t,e,i){this.writeIndex(t,i),t.writeInt32(e)}}class V extends B{constructor(t){super(),this.reader=t}read(t,e){const i=(new L).read(t),r=[];for(let n=0;n")}}class P extends B{constructor(t){super(),this.reader=t}read(t,e){return(new N).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}write(t,e,i){t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:i)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class M extends B{read(t){const e=new C;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,i){this.writeIndex(t,i);const r=new C;r.write(t,e.x,null),r.write(t,e.y,null),r.write(t,e.width,null),r.write(t,e.height,null)}}class F extends B{read(t){return t.readSingle()}write(t,e,i){this.writeIndex(t,i),t.writeSingle(e)}}const Z=256;//! Use DXT1 compression. -//! Weight the colour by alpha during cluster fit (disabled by default). -function X(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,r)}return i}function W(t){for(var e=1;e{let n=e.map((t=>t[r]));return{value:t[r],vec:n}}));return r.sort(((t,e)=>e.value-t.value)),[r.map((t=>{let{value:e}=t;return e})),r.map((t=>{let{vec:e}=t;return e}))]}function $(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,i=t.length,r=Array(i),n=Math.abs(e/i),s=Array(i);for(let t=0;t=Math.abs(n);){let e=a[0][0],r=a[0][1],n=H(e,r,K(t[e][e],t[r][r],t[e][r]),i);t=Y(n,t),s=J(s,n),a=G(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,i]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:Q.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new Q(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=i,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new tt(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const i=i=>t>i?t:e{return Math.trunc((0>(i=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,i,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:tt.multScalar(this,1/this.length)}get xyz(){return new Q(this.x,this.y,this.z)}get splatX(){return new tt(this.x)}get splatY(){return new tt(this.y)}get splatZ(){return new tt(this.z)}get splatW(){return new tt(this.w)}clone(){return new tt(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=i,this._values[3]=r,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const i=i=>t>i?t:e0>t?0:1Math.trunc(t(e)*i+.5)/i;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new tt(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new tt(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new tt(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new tt(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,i){let r=tt.multScalar(t,1-i),n=tt.multScalar(e,i);return tt.add(r,n)}static multiplyAdd(t,e,i){return new tt(t.x*e.x+i.x,t.y*e.y+i.y,t.z*e.z+i.z,t.w*e.w+i.w)}static negativeMultiplySubtract(t,e,i){return new tt(i.x-t.x*e.x,i.y-t.y*e.y,i.z-t.z*e.z,i.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(i+=e[n],t.addScaledVector(r,e[n]),t)),new Q(0));r.mult(1/i);let n=t.reduce(((t,i,n)=>{let s=e[n],a=Q.sub(i,r);return t[0][0]+=a.x*a.x*s,t[0][1]+=a.x*a.y*s,t[0][2]+=a.x*a.z*s,t[1][1]+=a.y*a.y*s,t[1][2]+=a.y*a.z*s,t[2][2]+=a.z*a.z*s,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new Q(...$(i))}const it=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],rt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],nt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],st=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function at(t,e){const i=parseInt(t+.5);return i<0?0:i}function ot(t){return at(31*t.x)<<11|at(63*t.y)<<5|at(31*t.z)}function ht(t,e,i,r,n){r[n+0]=255&t,r[n+1]=t>>8,r[n+2]=255&e,r[n+3]=e>>8;for(let t=0;t<4;t++)r[n+4+t]=i[4*t+0]|i[4*t+1]<<2|i[4*t+2]<<4|i[4*t+3]<<6}function lt(t,e,i,r,n){let s,a=ot(t),o=ot(e);a<=o?s=i.slice():([a,o]=[o,a],s=i.map((t=>0===t?1:1===t?0:t))),ht(a,o,s,r,n)}function ct(t,e,i,r,n){let s,a=ot(t),o=ot(e);a3&(1^t)))):s=a==o?new Array(16).fill(0):i.slice(),ht(a,o,s,r,n)}class dt{constructor(t,e,i){this.flags=i,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const r=0!=(1&this.flags),n=0!=(128&this.flags);for(let i=0;i<16;i++){if(0!=(e&1<=128||!r)){const e=this._remap[s],r=(t[4*i+3]+1)/256;this._weights[e]+=n?r:1,this._remap[i]=e;break}}else this._remap[i]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,r)=>e[r]=i[r]))}remapIndices(t,e){const i=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,r)=>e[r]=i[r]))}}class ut{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class ft extends ut{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new Q(0),this.end=new Q(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorlt(i,r,n,t,e)))}compress4(t,e){const i=[nt,st,nt];this.compressBase(i,((i,r,n)=>ct(i,r,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const i=[];let r=0;for(let n=0;n<3;n++){const s=t[n],a=this.color[n];i[n]=s[a][e];const o=i[n][2];r+=o*o}r{let i=1/0;const n=t.reduce(((t,r,n)=>{const s=Q.sub(e,r).multVector(this.metric).lengthSq;return s>=i?t:(i=s,n)}),0);return r+=i,n}));if(rlt(i,r,n,t,e)))}compress4(t,e){const i=[this.start.clone(),this.end.clone(),Q.interpolate(this.start,this.end,1/3),Q.interpolate(this.start,this.end,2/3)];this.compressBase(i,((i,r,n)=>ct(i,r,n,t,e)))}computePoints(){const{count:t,points:e,weights:i}=this.colors;if(t<=0)return;const r=et(e,i);let n,s,a,o;n=s=e[0],a=o=Q.dot(n,r);for(let i=1;io&&(s=e[i],o=t)}this.start=n.clampGrid().clone(),this.end=s.clampGrid().clone()}}class wt extends ut{constructor(t){super(t);this.iterationCount=t.flags&Z?8:1,this.bestError=1/0,this.metric=new tt(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:i}=this.colors;this.principle=et(e,i),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new tt(0)}constructOrdering(t,e){const i=this.makeOrder(t);this.copyOrderToThisOrder(i,e);return!!this.checkOrderUnique(i,e)&&(this.copyOrderWeight(i),!0)}compress3(t,e){this.compressBase((t=>{let[e,,i,r]=t;const n=new tt(.5,.5,.5,1/4),s=tt.multiplyAdd(i,n,e),a=s.splatW,o=tt.multiplyAdd(i,n,r);return{ax:s,aa:a,bx:o,bb:o.splatW,ab:tt.multVector(i,n).splatW}}),((i,r,n)=>lt(i,r,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,i,r,n]=t;const s=new tt(1/3,1/3,1/3,1/9),a=new tt(2/3,2/3,2/3,4/9),o=new tt(2/9),h=tt.multiplyAdd(r,s,tt.multiplyAdd(i,a,e)),l=h.splatW,c=tt.multiplyAdd(i,s,tt.multiplyAdd(r,a,n));return{ax:h,aa:l,bx:c,bb:c.splatW,ab:tt.multVector(o,tt.add(i,r)).splatW}}),((i,r,n)=>ct(i,r,n,t,e)),3)}compressBase(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let r={start:new tt(0),end:new tt(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===i&&(r.bestK=0);const n=(e,i)=>{const n=t(e),s=this.computeOptimalPoints(n);return s.errorQ.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>r[t]-r[e]!=0?r[t]-r[e]:t-e))}copyOrderToThisOrder(t,e){const i=16*e;t.forEach(((t,e)=>{this.order[i+e]=t}))}checkOrderUnique(t,e){const{count:i}=this.colors;for(let r=0;r2&&void 0!==arguments[2]?arguments[2]:2;const{count:r}=this.colors,n=(e,r,n)=>{const s={bestI:e,bestJ:2===i?n:r,iteration:t};return 3===i&&(s.bestK=n),s};let s=new tt(0);for(let t=0;t15?15:e}function gt(t,e,i,r){let n=bt(t,e,5),s=bt(t,e,7);n.error<=s.error?function(t,e,i){let{min:r,max:n,indices:s}=t;if(r>n){yt(n,r,s.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,i)}else yt(r,n,s,e,i)}(n,i,r):function(t,e,i){let{min:r,max:n,indices:s}=t;if(r>n){yt(n,r,s.map((t=>0===t?1:1===t?0:9-t)),e,i)}else yt(r,n,s,e,i)}(s,i,r)}function bt(t,e,i){let{min:r,max:n}=function(t,e,i){let r=255,n=0;for(let s=0;s<16;s++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}r>n&&(r=n);n-rMath.floor(((i-(n+1))*t+(n+1)*e)/i)))];return 5===i&&(r[6]=0,r[7]=255),r}function yt(t,e,i,r,n){r[n]=t,r[n+1]=e;let s=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=i[s]<<3*e,s++}for(let e=0;e<3;++e){let i=t>>8*e&255;r[a]=i,a++}}}function vt(t){const e=t>>11&31,i=t>>5&63,r=31&t;return[e<<3|e>>2,i<<2|i>>4,r<<3|r>>2,255]}function kt(t,e,i){const r=t.map(((t,r)=>Math.floor(t*(1-i)+e[r]*i)));return r[3]=255,r}function xt(t,e,i,r){const n=function(t,e,i){const r=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,s=vt(r),a=vt(n);return[s,a,kt(s,a,i&&r<=n?.5:1/3),i&&r<=n?[0,0,0,0]:kt(s,a,2/3)]}(e,i,r),s=function(t,e){let i=e+4,r=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[i+e];r[4*e+0]=3&n,r[4*e+1]=n>>2&3,r[4*e+2]=n>>4&3,r[4*e+3]=n>>6&3}return r}(e,i);for(let e=0;e<16;e++)for(let i=0;i<4;i++)t[4*e+i]=n[s[e]][i]}function At(t){for(let e=0;e<4;e++)for(let i=0;i<4;i++)t(i,e)}function Et(t){let e=7&t,i=280&t,r=96&t;return 2!=e&&4!=e&&(e=1),16!=i&&i!=Z&&(i=8),64!=r&&(r=32),e|i|r|128&t}function Ut(t,e){let{x:i=0,y:r=0,width:n=0,height:s=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;At((function(o,h){let l=i+o,c=r+h;if(l>4}}(t,e,i):0!=(4&r)&&function(t,e,i){let r=e[i+0],n=e[i+1],s=mt(r,n,r<=n?5:7),a=new Uint8Array(16),o=0,h=2;for(let t=0;t<2;t++){let t=0;for(let r=0;r<3;r++)t|=e[i+h]<<8*r,h++;for(let e=0;e<8;e++){let i=t>>3*e&7;a[o]=i,o++}}for(let e=0;e<16;++e)t[4*e+3]=s[a[e]]}(t,e,i)}function Bt(t,e,i,r,n){const s=0!=(1&(n=Et(n)))?8:16;let a=0;!function(t,e,i){for(let r=0;r1&&void 0!==arguments[1]?arguments[1]:{};const s=new Uint8Array(64);let a=0,o=0;return At((function(h,l){let c=e+h,d=i+l;if(c1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));let o=i.read(t),h=t.read(o);if(4==r)h=Lt(h,n,s,It);else if(5==r)h=Lt(h,n,s,St);else if(6==r)h=Lt(h,n,s,Ot);else{if(2==r)throw new w("Texture2D format type ECT1 not implemented!");if(0!=r)throw new w("Non-implemented Texture2D format type (".concat(r,") found."))}for(let t=0;t")}},BaseReader:B,BmFontReader:class extends B{read(t){const e=(new T).read(t);return{export:{type:this.type,data:e}}}write(t,e,i){this.writeIndex(t,i);(new T).write(t,e.export.data,null)}isValueType(){return!1}},BooleanReader:N,CharReader:D,DictionaryReader:class extends B{constructor(t,e){if(null==t||null==e)throw new w("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let i={};const r=(new L).read(t);for(let n=0;n")}},DoubleReader:class extends B{read(t){return t.readDouble()}write(t,e,i){this.writeIndex(t,i),t.writeDouble(e)}},EffectReader:class extends B{read(t){const e=(new L).read(t),i=t.read(e);return{export:{type:this.type,data:i}}}write(t,e,i){this.writeIndex(t,i);const r=e.export.data;(new L).write(t,r.byteLength,null),t.concat(r)}isValueType(){return!1}},Int32Reader:C,ListReader:V,NullableReader:P,RectangleReader:M,SingleReader:F,SpriteFontReader:class extends B{read(t,e){const i=new C,r=new F,n=new P(new D);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:i.read(t),horizontalSpacing:r.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,i){const r=new C,n=new D,s=new F,a=new P(n),o=new Nt,h=new V(new M),l=new V(n),c=new V(new Dt);this.writeIndex(t,i);try{o.write(t,e.texture,i),t.alloc(1e5),h.write(t,e.glyphs,i),h.write(t,e.cropping,i),l.write(t,e.characterMap,i),r.write(t,e.verticalLineSpacing,null),s.write(t,e.horizontalSpacing,null),c.write(t,e.kerning,i),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},StringReader:T,TBinReader:class extends B{read(t){let e=(new C).read(t),i=t.read(e);return{export:{type:this.type,data:i}}}write(t,e,i){this.writeIndex(t,i);const r=e.export.data;(new C).write(t,r.byteLength,null),t.concat(r)}isValueType(){return!1}},Texture2DReader:Nt,UInt32Reader:L,Vector2Reader:class extends B{read(t){const e=new F;return{x:e.read(t),y:e.read(t)}}},Vector3Reader:Dt,Vector4Reader:class extends B{read(t){const e=new F;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}},Vt=t=>{let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(Vt(e.slice(0,-2)),">");switch(e){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return"Boolean";case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return"Char";case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return"Int32";case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return"String";case"Microsoft.Xna.Framework.Content.DictionaryReader":let i=Pt(t).map(Vt);return"Dictionary<".concat(i[0],",").concat(i[1],">");case"Microsoft.Xna.Framework.Content.ArrayReader":let r=Pt(t).map(Vt);return"Array<".concat(r,">");case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":let n=Pt(t).map(Vt);return"List<".concat(n,">");case"Microsoft.Xna.Framework.Content.Texture2DReader":return"Texture2D";case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return"Vector2";case"Microsoft.Xna.Framework.Content.Vector3Reader":case"Microsoft.Xna.Framework.Vector3":return"Vector3";case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return"Vector4";case"Microsoft.Xna.Framework.Content.SpriteFontReader":return"SpriteFont";case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return"Rectangle";case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return"Effect";case"xTile.Pipeline.TideReader":return"TBin";case"BmFont.XmlSourceReader":return"BmFont";default:throw new w('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}},Pt=t=>{let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let i=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return i},Mt=t=>{let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}},Ft=t=>{let{type:e,subtypes:i}=Mt(t);if(i=i.map(Ft),Ct.hasOwnProperty("".concat(e,"Reader")))return new(Ct["".concat(e,"Reader")])(...i);throw new w('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))};class Zt{constructor(t,e,i){let{target:r,formatVersion:n,hidef:s,compressed:a}=t;this.header={target:r,formatVersion:n,hidef:s,compressed:a},this.readers=e,this.content=i}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class Xt{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const Wt=64,jt=128,Ht=14;class Kt{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new f(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new w("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==jt){const e=this.fileSize-Ht,i=class{static decompress(t,e,i){let r,n,s=0;const a=new k(16);let o=new _(i);for(;s65536||n>65536)throw new w("Invalid size read in compression content.");o.write(a.decompress(t,n,r)),s+=r}return console.log("File has been successfully decompressed!"),o.trim(),o.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,Ht,0,t),this.buffer.bytePosition=Ht}else if(this.compressionType==Wt){const e=this.buffer.buffer.slice(Ht),i=new Uint8Array(e),r=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,c=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+r;i>4;if(u>0){if(15===u)for(;u+=t[i],255===t[i++];);for(h=i+u;i=o)break;if(s=15&d,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,c&&1===a)e.fill(0|e[n-1],n,n+s),n+=s;else if(c&&a>s&&s>31)e.copyWithin(n,n-a,n-a+s),n+=s;else for(h=(l=n-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const r=t.length;let n=0,s=Math.max(32,r+(r>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(n+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[n++]=e>>6&31|192;else if(0==(4294901760&e))a[n++]=e>>12&15|224,a[n++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[n++]=e>>18&7|240,a[n++]=e>>12&63|128,a[n++]=e>>6&63|128}a[n++]=63&e|128}else a[n++]=e}return a.slice(0,n)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let r=0;const n=i.length,s=[];for(;r65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Yt={};function Jt(t){var e=Yt[t];if(void 0!==e)return e.exports;var i=Yt[t]={exports:{}};return Gt[t].call(i.exports,i,i.exports,Jt),i.exports}Jt.d=(t,e)=>{for(var i in e)Jt.o(e,i)&&!Jt.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},Jt.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var qt={};(()=>{Jt.d(qt,{P:()=>Oi,m:()=>Si}),Jt(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=r?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const n=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),s=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),a=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),o=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h=new Array(576);r(h);const l=new Array(60);r(l);const c=new Array(512);r(c);const d=new Array(256);r(d);const u=new Array(29);r(u);const f=new Array(30);function _(t,e,i,r,n){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=r,this.max_length=n,this.has_stree=t&&t.length}let w,p,g;function b(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(f);const m=t=>t<256?c[t]:c[256+(t>>>7)],y=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},v=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{v(t,i[2*e],i[2*e+1])},x=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const r=new Array(16);let n,s,a=0;for(n=1;n<=15;n++)r[n]=a=a+i[n-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=x(r[e]++,e))}},E=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},U=t=>{t.bi_valid>8?y(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},R=(t,e,i,r)=>{const n=2*e,s=2*i;return t[n]{const r=t.heap[i];let n=i<<1;for(;n<=t.heap_len&&(n{let r,a,o,h,l=0;if(0!==t.last_lit)do{r=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],a=t.pending_buf[t.l_buf+l],l++,0===r?k(t,a,e):(o=d[a],k(t,o+256+1,e),h=n[o],0!==h&&(a-=u[o],v(t,a,h)),r--,o=m(r),k(t,o,i),h=s[o],0!==h&&(r-=f[o],v(t,r,h)))}while(l{const i=e.dyn_tree,r=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)z(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],z(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,z(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,r=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,d,u,f,_,w=0;for(u=0;u<=15;u++)t.bl_count[u]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],u=i[2*i[2*c+1]+1]+1,u>h&&(u=h,w++),i[2*c+1]=u,c>r||(t.bl_count[u]++,f=0,c>=o&&(f=a[c-o]),_=i[2*c],t.opt_len+=_*(u+f),s&&(t.static_len+=_*(n[2*c+1]+f)));if(0!==w){do{for(u=h-1;0===t.bl_count[u];)u--;t.bl_count[u]--,t.bl_count[u+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(u=h;0!==u;u--)for(c=t.bl_count[u];0!==c;)d=t.heap[--l],d>r||(i[2*d+1]!==u&&(t.opt_len+=(u-i[2*d+1])*i[2*d],i[2*d+1]=u),c--)}})(t,e),A(i,l,t.bl_count)},S=(t,e,i)=>{let r,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,r=0;r<=i;r++)n=a,a=e[2*(r+1)+1],++o{let r,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),r=0;r<=i;r++)if(n=a,a=e[2*(r+1)+1],!(++o{v(t,0+(r?1:0),3),((t,e,i,r)=>{U(t),y(t,i),y(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var N={_tr_init:t=>{T||((()=>{let t,e,i,r,o;const b=new Array(16);for(i=0,r=0;r<28;r++)for(u[r]=i,t=0;t<1<>=7;r<30;r++)for(f[r]=o<<7,t=0;t<1<{let n,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),I(t,t.l_desc),I(t,t.d_desc),a=(t=>{let e;for(S(t,t.dyn_ltree,t.l_desc.max_code),S(t,t.dyn_dtree,t.d_desc.max_code),I(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*o[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=n&&(n=s)):n=s=i+5,i+4<=n&&-1!==e?L(t,e,i,r):4===t.strategy||s===n?(v(t,2+(r?1:0),3),B(t,h,l)):(v(t,4+(r?1:0),3),((t,e,i,r)=>{let n;for(v(t,e-257,5),v(t,i-1,5),v(t,r-4,4),n=0;n(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(d[i]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{v(t,2,3),k(t,256,h),(t=>{16===t.bi_valid?(y(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},D=(t,e,i,r)=>{let n=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{n=n+e[r++]|0,s=s+n|0}while(--a);n%=65521,s%=65521}return n|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var V=(t,e,i,r)=>{const n=C,s=r+i;t^=-1;for(let i=r;i>>8^n[255&(t^e[i])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},M={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:F,_tr_stored_block:Z,_tr_flush_block:X,_tr_tally:j,_tr_align:H}=N,{Z_NO_FLUSH:K,Z_PARTIAL_FLUSH:G,Z_FULL_FLUSH:Y,Z_FINISH:J,Z_BLOCK:q,Z_OK:$,Z_STREAM_END:Q,Z_STREAM_ERROR:tt,Z_DATA_ERROR:et,Z_BUF_ERROR:it,Z_DEFAULT_COMPRESSION:rt,Z_FILTERED:nt,Z_HUFFMAN_ONLY:st,Z_RLE:at,Z_FIXED:ot,Z_DEFAULT_STRATEGY:ht,Z_UNKNOWN:lt,Z_DEFLATED:ct}=M,dt=258,ut=262,ft=103,_t=113,wt=666,pt=(t,e)=>(t.msg=P[e],e),gt=t=>(t<<1)-(t>4?9:0),bt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let mt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},vt=(t,e)=>{X(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,yt(t.strm)},kt=(t,e)=>{t.pending_buf[t.pending++]=e},xt=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},At=(t,e,i,r)=>{let n=t.avail_in;return n>r&&(n=r),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),i),1===t.state.wrap?t.adler=D(t.adler,e,n,i):2===t.state.wrap&&(t.adler=V(t.adler,e,n,i)),t.next_in+=n,t.total_in+=n,n)},Et=(t,e)=>{let i,r,n=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-ut?t.strstart-(t.w_size-ut):0,l=t.window,c=t.w_mask,d=t.prev,u=t.strstart+dt;let f=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===f&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=r,r>=o)break;f=l[s+a-1],_=l[s+a]}}}while((e=d[e&c])>h&&0!=--n);return a<=t.lookahead?a:t.lookahead},Ut=t=>{const e=t.w_size;let i,r,n,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-ut)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,r=t.hash_size,i=r;do{n=t.head[--i],t.head[i]=n>=e?n-e:0}while(--r);r=e,i=r;do{n=t.prev[--i],t.prev[i]=n>=e?n-e:0}while(--r);s+=e}if(0===t.strm.avail_in)break;if(r=At(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=r,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead{let i,r;for(;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-ut&&(t.match_length=Et(t,i)),t.match_length>=3)if(r=j(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===J?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2},zt=(t,e)=>{let i,r,n;for(;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,r=j(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(vt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(r=j(t,0,t.window[t.strstart-1]),r&&vt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=j(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===J?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2};function Bt(t,e,i,r,n){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=r,this.func=n}const It=[new Bt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===K)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const r=t.block_start+i;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,vt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-ut&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===J?(vt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(vt(t,!1),t.strm.avail_out),1)})),new Bt(4,4,8,4,Rt),new Bt(4,5,16,8,Rt),new Bt(4,6,32,32,Rt),new Bt(4,4,16,16,zt),new Bt(8,16,32,32,zt),new Bt(8,16,128,128,zt),new Bt(8,32,128,256,zt),new Bt(32,128,258,1024,zt),new Bt(32,258,258,4096,zt)];function St(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Ot=t=>{const e=(t=>{if(!t||!t.state)return pt(t,tt);t.total_in=t.total_out=0,t.data_type=lt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=K,F(e),$})(t);var i;return e===$&&((i=t.state).window_size=2*i.w_size,bt(i.head),i.max_lazy_match=It[i.level].max_lazy,i.good_match=It[i.level].good_length,i.nice_match=It[i.level].nice_length,i.max_chain_length=It[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var Tt=(t,e,i,r,n,s)=>{if(!t)return tt;let a=1;if(e===rt&&(e=6),r<0?(a=0,r=-r):r>15&&(a=2,r-=16),n<1||n>9||i!==ct||r<8||r>15||e<0||e>9||s<0||s>ot)return pt(t,tt);8===r&&(r=9);const o=new St;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=r,o.w_size=1<{let i,r;if(!t||!t.state||e>q||e<0)return t?pt(t,tt):tt;const n=t.state;if(!t.output||!t.input&&0!==t.avail_in||n.status===wt&&e!==J)return pt(t,0===t.avail_out?it:tt);n.strm=t;const s=n.last_flush;if(n.last_flush=e,42===n.status)if(2===n.wrap)t.adler=0,kt(n,31),kt(n,139),kt(n,8),n.gzhead?(kt(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),kt(n,255&n.gzhead.time),kt(n,n.gzhead.time>>8&255),kt(n,n.gzhead.time>>16&255),kt(n,n.gzhead.time>>24&255),kt(n,9===n.level?2:n.strategy>=st||n.level<2?4:0),kt(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(kt(n,255&n.gzhead.extra.length),kt(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=V(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(kt(n,0),kt(n,0),kt(n,0),kt(n,0),kt(n,0),kt(n,9===n.level?2:n.strategy>=st||n.level<2?4:0),kt(n,3),n.status=_t);else{let e=ct+(n.w_bits-8<<4)<<8,i=-1;i=n.strategy>=st||n.level<2?0:n.level<6?1:6===n.level?2:3,e|=i<<6,0!==n.strstart&&(e|=32),e+=31-e%31,n.status=_t,xt(n,e),0!==n.strstart&&(xt(n,t.adler>>>16),xt(n,65535&t.adler)),t.adler=1}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),yt(t),i=n.pending,n.pending!==n.pending_buf_size));)kt(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),yt(t),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindexi&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),yt(t),i=n.pending,n.pending===n.pending_buf_size)){r=1;break}r=n.gzindexi&&(t.adler=V(t.adler,n.pending_buf,n.pending-i,i)),0===r&&(n.status=ft)}else n.status=ft;if(n.status===ft&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&yt(t),n.pending+2<=n.pending_buf_size&&(kt(n,255&t.adler),kt(n,t.adler>>8&255),t.adler=0,n.status=_t)):n.status=_t),0!==n.pending){if(yt(t),0===t.avail_out)return n.last_flush=-1,$}else if(0===t.avail_in&>(e)<=gt(s)&&e!==J)return pt(t,it);if(n.status===wt&&0!==t.avail_in)return pt(t,it);if(0!==t.avail_in||0!==n.lookahead||e!==K&&n.status!==wt){let i=n.strategy===st?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===K)return 1;break}if(t.match_length=0,i=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===J?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(n,e):n.strategy===at?((t,e)=>{let i,r,n,s;const a=t.window;for(;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===K)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,r=a[n],r===a[++n]&&r===a[++n]&&r===a[++n])){s=t.strstart+dt;do{}while(r===a[++n]&&r===a[++n]&&r===a[++n]&&r===a[++n]&&r===a[++n]&&r===a[++n]&&r===a[++n]&&r===a[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=j(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===J?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(n,e):It[n.level].func(n,e);if(3!==i&&4!==i||(n.status=wt),1===i||3===i)return 0===t.avail_out&&(n.last_flush=-1),$;if(2===i&&(e===G?H(n):e!==q&&(Z(n,0,0,!1),e===Y&&(bt(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),yt(t),0===t.avail_out))return n.last_flush=-1,$}return e!==J?$:n.wrap<=0?Q:(2===n.wrap?(kt(n,255&t.adler),kt(n,t.adler>>8&255),kt(n,t.adler>>16&255),kt(n,t.adler>>24&255),kt(n,255&t.total_in),kt(n,t.total_in>>8&255),kt(n,t.total_in>>16&255),kt(n,t.total_in>>24&255)):(xt(n,t.adler>>>16),xt(n,65535&t.adler)),yt(t),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?$:Q)},Nt=t=>{if(!t||!t.state)return tt;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==ft&&e!==_t&&e!==wt?pt(t,tt):(t.state=null,e===_t?pt(t,et):$)};const Dt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Ct=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Dt(i,e)&&(t[e]=i[e])}}return t},Vt=t=>{let e=0;for(let i=0,r=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var Ft=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,r,n,s,a=t.length,o=0;for(n=0;n>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Zt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let r,n;const s=new Array(2*i);for(n=0,r=0;r4)s[n++]=65533,r+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&r1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Pt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let r=0;r{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Wt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const jt=Object.prototype.toString,{Z_NO_FLUSH:Ht,Z_SYNC_FLUSH:Kt,Z_FULL_FLUSH:Gt,Z_FINISH:Yt,Z_OK:$t,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=M;function re(t){this.options=Ct({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Wt,this.strm.avail_out=0;let i=Tt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==$t)throw new Error(P[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Ft(e.dictionary):"[object ArrayBuffer]"===jt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return tt;const r=t.state,n=r.wrap;if(2===n||1===n&&42!==r.status||r.lookahead)return tt;if(1===n&&(t.adler=D(t.adler,e,i,0)),r.wrap=0,i>=r.w_size){0===n&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);let t=new Uint8Array(r.w_size);t.set(e.subarray(i-r.w_size,i),0),e=t,i=r.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){let t=r.strstart,e=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[t+3-1]),r.prev[t&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=t,t++}while(--e);r.strstart=t,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,r.wrap=n,$})(this.strm,t),i!==$t)throw new Error(P[i]);this._dict_set=!0}}function ne(t,e){const i=new re(e);if(i.push(t,!0),i.err)throw i.msg||P[i.err];return i.result}re.prototype.push=function(t,e){const i=this.strm,r=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?Yt:Ht,"string"==typeof t?i.input=Ft(t):"[object ArrayBuffer]"===jt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),(s===Kt||s===Gt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(n=Lt(i,s),n===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=Nt(this.strm),this.onEnd(n),this.ended=!0,n===$t;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},re.prototype.onData=function(t){this.chunks.push(t)},re.prototype.onEnd=function(t){t===$t&&(this.result=Vt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:re,deflate:ne,deflateRaw:function(t,e){return(e=e||{}).raw=!0,ne(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,ne(t,e)},constants:M},ae=function(t,e){let i,r,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,m,y,v,k,x,A,E;const U=t.state;i=t.next_in,A=t.input,r=i+(t.avail_in-5),n=t.next_out,E=t.output,s=n-(e-t.avail_out),a=n+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,c=U.wnext,d=U.window,u=U.hold,f=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,u>>>=m,f-=m,m=b>>>16&255,0===m)E[n++]=65535&b;else{if(!(16&m)){if(0==(64&m)){b=_[(65535&b)+(u&(1<>>=m,f-=m),f<15&&(u+=A[i++]<>>24,u>>>=m,f-=m,m=b>>>16&255,!(16&m)){if(0==(64&m)){b=w[(65535&b)+(u&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(u>>>=m,f-=m,m=n-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=d,0===c){if(k+=h-m,m2;)E[n++]=x[k++],E[n++]=x[k++],E[n++]=x[k++],y-=3;y&&(E[n++]=x[k++],y>1&&(E[n++]=x[k++]))}else{k=n-v;do{E[n++]=E[k++],E[n++]=E[k++],E[n++]=E[k++],y-=3}while(y>2);y&&(E[n++]=E[k++],y>1&&(E[n++]=E[k++]))}break}}break}}while(i>3,i-=y,f-=y<<3,u&=(1<{const h=o.bits;let l,c,d,u,f,_,w=0,p=0,g=0,b=0,m=0,y=0,v=0,k=0,x=0,A=0,E=null,U=0;const R=new Uint16Array(16),z=new Uint16Array(16);let B,I,S,O=null,T=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[b];b--);if(m>b&&(m=b),0===b)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(z[1]=0,w=1;w<15;w++)z[w+1]=z[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){B=w-v,a[p]<_?(I=0,S=a[p]):a[p]>_?(I=O[T+a[p]],S=E[U+a[p]]):(I=96,S=0),l=1<>v)+c]=B<<24|I<<16|S|0}while(0!==c);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--R[w]){if(w===b)break;w=e[i+a[p]]}if(w>m&&(A&u)!==d){for(0===v&&(v=m),f+=g,y=w-v,k=1<852||2===t&&x>592)return 1;d=A&u,n[d]=m<<24|y<<16|f-s|0}}return 0!==A&&(n[f+A]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ue,Z_BLOCK:fe,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:ge,Z_STREAM_ERROR:be,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=M,xe=12,Ae=30,Ee=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return be;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return be;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let ze,Be,Ie=!0;const Se=t=>{if(Ie){ze=new Int32Array(512),Be=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(de(1,t.lens,0,288,ze,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;de(2,t.lens,0,32,Be,0,t.work,{bits:5}),Ie=!1}t.lencode=ze,t.lenbits=9,t.distcode=Be,t.distbits=5},Oe=(t,e,i,r)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>r&&(n=r),s.window.set(e.subarray(i-r,i-r+n),s.wnext),(r-=n)?(s.window.set(e.subarray(i-r,i),0),s.wnext=r,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return be;const i=new Ue;t.state=i,i.window=null;const r=((t,e)=>{let i;if(!t||!t.state)return be;const r=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?be:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=i,r.wbits=e,Re(t))})(t,e);return r!==we&&(t.state=null),r},Ne=(t,e)=>{let i,r,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,m,y,v,k,x,A=0;const E=new Uint8Array(4);let U,R;const z=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return be;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,r=t.input,o=t.avail_in,l=i.hold,c=i.bits,d=o,u=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;c<16;){if(0===o)break t;o--,l+=r[s++]<>>8&255,i.check=V(i.check,E,2,0),l=0,c=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ae;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ae;break}if(l>>>=4,c-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ae;break}i.dmax=1<>8&1),512&i.flags&&(E[0]=255&l,E[1]=l>>>8&255,i.check=V(i.check,E,2,0)),l=0,c=0,i.mode=3;case 3:for(;c<32;){if(0===o)break t;o--,l+=r[s++]<>>8&255,E[2]=l>>>16&255,E[3]=l>>>24&255,i.check=V(i.check,E,4,0)),l=0,c=0,i.mode=4;case 4:for(;c<16;){if(0===o)break t;o--,l+=r[s++]<>8),512&i.flags&&(E[0]=255&l,E[1]=l>>>8&255,i.check=V(i.check,E,2,0)),l=0,c=0,i.mode=5;case 5:if(1024&i.flags){for(;c<16;){if(0===o)break t;o--,l+=r[s++]<>>8&255,i.check=V(i.check,E,2,0)),l=0,c=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(f=i.length,f>o&&(f=o),f&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(s,s+f),k)),512&i.flags&&(i.check=V(i.check,r,f,s)),o-=f,s+=f,i.length-=f),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;f=0;do{k=r[s+f++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&f>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;c<32;){if(0===o)break t;o--,l+=r[s++]<>>=7&c,c-=7&c,i.mode=27;break}for(;c<3;){if(0===o)break t;o--,l+=r[s++]<>>=1,c-=1,3&l){case 0:i.mode=14;break;case 1:if(Se(i),i.mode=20,e===_e){l>>>=2,c-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ae}l>>>=2,c-=2;break;case 14:for(l>>>=7&c,c-=7&c;c<32;){if(0===o)break t;o--,l+=r[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ae;break}if(i.length=65535&l,l=0,c=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(f=i.length,f){if(f>o&&(f=o),f>h&&(f=h),0===f)break t;n.set(r.subarray(s,s+f),a),o-=f,s+=f,h-=f,a+=f,i.length-=f;break}i.mode=xe;break;case 17:for(;c<14;){if(0===o)break t;o--,l+=r[s++]<>>=5,c-=5,i.ndist=1+(31&l),l>>>=5,c-=5,i.ncode=4+(15&l),l>>>=4,c-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ae;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,c-=3}for(;i.have<19;)i.lens[z[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=de(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ae;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=r[s++]<>>=p,c-=p,i.lens[i.have++]=b;else{if(16===b){for(R=p+2;c>>=p,c-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ae;break}k=i.lens[i.have-1],f=3+(3&l),l>>>=2,c-=2}else if(17===b){for(R=p+3;c>>=p,c-=p,k=0,f=3+(7&l),l>>>=3,c-=3}else{for(R=p+7;c>>=p,c-=p,k=0,f=11+(127&l),l>>>=7,c-=7}if(i.have+f>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ae;break}for(;f--;)i.lens[i.have++]=k}}if(i.mode===Ae)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ae;break}if(i.lenbits=9,U={bits:i.lenbits},x=de(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ae;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=de(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ae;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=c,ae(t,u),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,r=t.input,o=t.avail_in,l=i.hold,c=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;A=i.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=r[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=c);){if(0===o)break t;o--,l+=r[s++]<>>=m,c-=m,i.back+=m}if(l>>>=p,c-=p,i.back+=p,i.length=b,0===g){i.mode=26;break}if(32&g){i.back=-1,i.mode=xe;break}if(64&g){t.msg="invalid literal/length code",i.mode=Ae;break}i.extra=15&g,i.mode=22;case 22:if(i.extra){for(R=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;A=i.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=r[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=c);){if(0===o)break t;o--,l+=r[s++]<>>=m,c-=m,i.back+=m}if(l>>>=p,c-=p,i.back+=p,64&g){t.msg="invalid distance code",i.mode=Ae;break}i.offset=b,i.extra=15&g,i.mode=24;case 24:if(i.extra){for(R=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ae;break}i.mode=25;case 25:if(0===h)break t;if(f=u-h,i.offset>f){if(f=i.offset-f,f>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ae;break}f>i.wnext?(f-=i.wnext,_=i.wsize-f):_=i.wnext-f,f>i.length&&(f=i.length),w=i.window}else w=n,_=a-i.offset,f=i.length;f>h&&(f=h),h-=f,i.length-=f;do{n[a++]=w[_++]}while(--f);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;n[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;c<32;){if(0===o)break t;o--,l|=r[s++]<{if(!t||!t.state)return be;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Ce=(t,e)=>{const i=e.length;let r,n,s;return t&&t.state?(r=t.state,0!==r.wrap&&11!==r.mode?be:11===r.mode&&(n=1,n=D(n,e,i,0),n!==r.check)?me:(s=Oe(t,e,i,i),s?(r.mode=31,ye):(r.havedict=1,we))):be},Ve=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Pe=Object.prototype.toString,{Z_NO_FLUSH:Me,Z_FINISH:Fe,Z_OK:Ze,Z_STREAM_END:Xe,Z_NEED_DICT:We,Z_STREAM_ERROR:je,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=M;function Ge(t){this.options=Ct({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Wt,this.strm.avail_out=0;let i=Le(this.strm,e.windowBits);if(i!==Ze)throw new Error(P[i]);if(this.header=new Ve,((t,e)=>{if(!t||!t.state)return be;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Ft(e.dictionary):"[object ArrayBuffer]"===Pe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Ce(this.strm,e.dictionary),i!==Ze)))throw new Error(P[i])}function Ye(t,e){const i=new Ge(e);if(i.push(t),i.err)throw i.msg||P[i.err];return i.result}Ge.prototype.push=function(t,e){const i=this.strm,r=this.options.chunkSize,n=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Fe:Me,"[object ArrayBuffer]"===Pe.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),s=Ne(i,a),s===We&&n&&(s=Ce(i,n),s===Ze?s=Ne(i,a):s===He&&(s=We));i.avail_in>0&&s===Xe&&i.state.wrap>0&&0!==t[i.next_in];)Te(i),s=Ne(i,a);switch(s){case je:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===Xe))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,n=Zt(i.output,t);i.next_out=e,i.avail_out=r-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(n)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Ze||0!==o){if(s===Xe)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ge.prototype.onData=function(t){this.chunks.push(t)},Ge.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Vt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ge,inflate:Ye,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ye(t,e)},ungzip:Ye,constants:M};const{Deflate:qe,deflate:$e,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ri,ungzip:ni}=Je;var si=$e,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function ci(t,e){return(4294967295^function(t,e,i){let r=4294967295;for(let t=0;t>>8;return r}(0,t,e))>>>0}var di,ui,fi,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(di||(di={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),gi=255===new Uint8Array(pi.buffer)[0];class bi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ui.UNKNOWN,this._filterMethod=fi.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=n;var l}}function mi(t,e,i){for(let r=0;r>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,r,n){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=di.UNKNOWN,this._zlibOptions=W(W({},Ei),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ui.DEFLATE),this.writeByte(fi.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:r,depth:n,data:s}=this._png,a=r*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function zi(t,e,i,r){for(let n=0;nnew Ui({width:t,height:e,data:i},void 0).encode(),Oi=t=>function(t,e){return new bi(t,void 0).decode()}(t)})();var $t=qt.P,Qt=qt.m;function te(t,e,i){if((r=t)&&r.hasOwnProperty("type")&&r.hasOwnProperty("data")){let r=te(t.data,e,i);return r.includes("\n")?" #!"+t.type+r:r+" #!"+t.type}if(t&&"object"==typeof t){let r=Array.isArray(t);if(0==Object.keys(t).length)return r?"[]":"{}";let n="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(n+=e.repeat(i+1),r?n+="- "+te(t[s],e,i+1):s.includes(": ")?(n+=te(s,e,i+1),n+=": "+te(t[s],e,i+1)):n+=s+": "+te(t[s],e,i+1),n+="\n");return n}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var r}function ee(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),te(t,i,-1)}class ie{constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let r=[];for(let e=0;e=e;)t.push(this.next());return new ie(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function re(t,e){let i;for(t.indentLevel();!t.finished();){let e,r,n,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(n=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],r=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),r=s.slice(1).trim()),r=r?ne(r,n):re(t.nextGroup(),n),Array.isArray(i)?i.push(r):i[e]=r}return e&&(i={type:e,data:i}),i}function ne(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function se(t){let e=t.replace(/\t/g,"\t").split("\n");return re(new ie(e))}function ae(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(ae(i));return e}if(t&&"object"==typeof t){e={};for(let[i,r]of Object.entries(t))e[i]=ae(r);return e}return t}function oe(t){switch(t){case"Boolean":case"Int32":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function he(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function le(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(oe(e))return ae(i);if(he(e))return i=ae(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;t=ae(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(le(i));return e}if(t&&"object"==typeof t){e={};for(let[i,r]of Object.entries(t))e[i]=le(r);return e}return null}function ce(t){const e={},{compressed:i,formatVersion:r,hidef:n,target:s}=t.header;let a=ae(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:n,readerData:a,numSharedResources:0};const o=ae(t.content);let h=a.map((t=>{let{type:e}=t;return Vt(e)}));"SpriteFont"===h[0]&&(h=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],o.verticalSpacing=o.verticalLineSpacing,delete o.verticalLineSpacing);const{converted:l,extractedImages:c,extractedMaps:d}=function(t,e){let i=[],r=[];const{converted:n}=function t(n,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(oe(o))return{converted:{type:o,data:n},traversed:a};if(null===o)return{converted:n,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:n}}},traversed:a+1};if(he(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:n.format}},traversed:a}):("TBin"===o&&r.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(n)?[]:{};let l=a,c=!0,d=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[i,r]of Object.entries(n)){let r;r=o.startsWith("Dictionary")?Mt(o).subtypes[1]===e[a+2]?a+2:a+1:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:u,traversed:f}=t(n[i],[...s,i],r);h[i]=u,d?l=f:c&&(l=f,c=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:n,extractedImages:i,extractedMaps:r}}(o,h);return e.content=l,c.length>0&&(e.extractedImages=c),d.length>0&&(e.extractedMaps=d),e}function de(t){const e={},{compressed:i,readerData:r,hiDef:n,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:n},e.readers=ae(r),e.content=le(t.content),"SpriteFont"===Vt(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ue(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ue(i,e);if(t)return t}return null}}function fe(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function _e(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function we(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function pe(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:we(e)}),extension:_e(e)}:{data:t,extension:_e(e)}}function ge(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ue(t,"export");if(i){const{value:t}=i;let{type:e,data:r}=t;return"Texture2D"===e&&(r=Qt(t.width,t.height,new Uint8Array(r))),pe(r,e)}if(e){return pe(JSON.stringify(t,null,4),"JSON")}return null}function be(t){let{yaml:e=!1,contentOnly:i=!1,fileName:r=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new w("Invalid object!");const n=[],{content:s}=t,a=ge(s,i);if(null!==a&&n.push(a),i)return n;const o=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof r&&""!==r?"".concat(r,".").concat(_e(e.type)):"".concat(e.type,".").concat(_e(e.type)):e),4);let h=o;return e&&(h=ee(ce(t))),n.unshift(pe(h,e?"yaml":"JSON")),n}function me(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function ye(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function ve(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function ke(t,e){if("png"===t){const t=await ve(e.png),i=$t(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await ve(e.cso)}}if("tbin"===t){return{type:"TBin",data:await ve(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await ye(e.xml)}}}async function xe(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,r=t.json||t.yaml;if(!r)throw new w("There is no JSON or YAML file to pack!");const n=await ye(r);let s=null;s=t.json?JSON.parse(n):de(se(n));let a=me(i);if(null!==a&&(s.header.compressed=a),!s.hasOwnProperty("content"))throw new w("".concat(r.name,' does not have "content".'));const o=ue(s.content,"export");if(o){const{parent:e,value:i}=o,[,r]=fe(i);e.export=await ke(r,t)}return s}async function Ae(t){if("undefined"!=typeof window){const[,e]=fe(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return Ee(await t.arrayBuffer())}return Ee(t.buffer)}function Ee(t){return(new Kt).load(t)}function Ue(t){const{content:e}=t,{data:i,extension:r}=ge(e,!0);return new Xt(i,r)}function Re(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const r=Re(t);let n=[];for(let[t,e]of Object.entries(r))n.push(xe(e,i).then(ze).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(n).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.unpackToContent=function(t){return Ae(t).then(Ue)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:r=!1,fileName:n=null}=e;"undefined"!=typeof window&&null===n&&(n=t.name);let[s]=fe(n);const a=t=>be(t,{yaml:i,contentOnly:r,fileName:s});return Ae(t).then(a)},t.unpackToXnbData=Ae,t.xnbDataToContent=Ue,t.xnbDataToFiles=be,Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function i(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=i({},t)}static addReaders(t){a.readers=i(i({},a.readers),t)}static makeSimplied(t,e){let r=t.split(/`|,/)[0];if(e.isTypeOf(r)){if(e.hasSubType()){let r=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(r.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e)}for(let e of Object.values(a.readers)){let r=a.makeSimplied(t,e);if(null!==r)return r}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let r=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return r}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],r=t.match(/<(.+)>/);return r=r?r[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:r}}static getReaderTypeList(t){let{type:e,subtypes:r}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(r);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:r}=a.getTypeInfo(t);if(r=r.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...r);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}n(a,"readers",{});const o=[192,224,240],h=128,l=63,c=[55296,56320],d=1023;function u(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function f(t){return t<65535?[t]:[c[0]|(t-=65536)>>10&d,c[1]|t&d]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const r=t.length;return 1===r?t[0]:2===r?((t[0]^o[0])<<6)+(t[1]^h):3===r?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&d)<<10)+(t[1]&d)+65536}function p(t){return function(t){const e=[];for(let r of t)e.push(...u(r));return e}(function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;i1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const r=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const n=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:0;const e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0;){const t=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),n=16-this.bitPosition-i,s=(t&2**i-1<>n;e-=i,this.bitPosition+=i,r|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */const m=256,v=0,k=1,x=2,A=3,E=656;class R{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!R.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)R.extra_bits[t]=R.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!R.position_base.length)for(let t=0,e=0;t<=50;t++)R.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),r=t.readLZXBits(8);switch(this.block_remaining=e<<8|r,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(E,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case A:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&i>0;){if(e>i&&(e=i),i-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,E,12);if(i>3;if(s>2){let e=R.extra_bits[s];if(s=R.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,E,12);if(i>3;if(s>2){if(3!=s){let e=R.extra_bits[s],r=t.readLZXBits(e);s=R.position_base[s]-2+r}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case A:if(t.bytePosition+e>r)throw new s("Overrun!"+r+" "+t.bytePosition+" "+e);for(let r=0;r>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let r=o;for(;r-- >0;)i[t++]=e}o>>=1}if(n==a)return i;for(let t=n;t>1>1;n<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let c=0;c>16;for(let r=0;r>15-r&1&&t++;if(i[t]=c,(n+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(n==a)return i;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,r,i,n){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(n)];if(a>=i){let t=1<<32-n;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=i)}return t.bitPosition+=r[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}R.position_base=[],R.extra_bits=[];class U{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}static readU32(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}static writeU32(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}static imul(t,e){var r=65535&t,i=65535&e;return r*i+((t>>>16)*i+r*(e>>>16)<<16)|0}} +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */const T=65536,S=15;!function(t){try{new Uint8Array(t)}catch(i){for(var e=new Array(t),r=0;r=13)for(var f=67;r+4>>0;if(s=n[w=(w>>16^w)>>>0&65535]-1,n[w]=r+1,s<0||r-s>>>16>0||U.readU32(t,s)!==_)r+=f++>>6;else{for(f=67,l=r-a,h=r-s,s+=4,o=r+=4;r=S){for(e[c++]=240+p,u=l-S;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=(l<<4)+p;for(var g=0;g>8,o>=15){for(u=o-15;u>=255;u-=255)e[c++]=255;e[c++]=u}a=r}}if(0===a)return 0;if((l=d-a)>=S){for(e[c++]=240,u=l-S;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=l<<4;for(r=a;rt.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class N{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const r=L(e);t.write7BitNumber(r),t.writeString(e)}}class C{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class D{constructor(t,e,r){let{target:i,formatVersion:n,hidef:s,compressed:a}=t;this.header={target:i,formatVersion:n,hidef:s,compressed:a},this.readers=e,this.content=r}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class V{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const M=64,P=128,F=14;class Z{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new b(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==P){const e=this.fileSize-F,r=class{static decompress(t,e,r){let i,n,a=0;const o=new R(16);let h=new y(r);for(;a65536||n>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,n,i)),a+=i}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(r,F,0,t),this.buffer.bytePosition=F}else if(this.compressionType==M){const e=this.buffer.buffer.slice(F),r=new Uint8Array(e),i=new Uint8Array(t);!function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*r,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,c=void 0!==e.copyWithin&&void 0!==e.fill;for(o=r+i;r>4;if(u>0){if(15===u)for(;u+=t[r],255===t[r++];);for(h=r+u;r=o)break;if(s=15&d,a=t[r++]|t[r++]<<8,15===s)for(;s+=t[r],255===t[r++];);if(s+=4,c&&1===a)e.fill(0|e[n-1],n,n+s),n+=s;else if(c&&a>s&&s>31)e.copyWithin(n,n-a,n-a+s),n+=s;else for(h=(l=n-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let r=0;const i=t.length;let n=0,s=Math.max(32,i+(i>>1)+7),a=new Uint8Array(s>>3<<3);for(;r=55296&&e<=56319){if(r=55296&&e<=56319)continue}if(n+4>a.length){s+=8,s*=1+r/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[n++]=e>>6&31|192;else if(0==(4294901760&e))a[n++]=e>>12&15|224,a[n++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[n++]=e>>18&7|240,a[n++]=e>>12&63|128,a[n++]=e>>6&63|128}a[n++]=63&e|128}else a[n++]=e}return a.slice(0,n)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const r=new Uint8Array(t);let i=0;const n=r.length,s=[];for(;i65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function j(t){var e=W[t];if(void 0!==e)return e.exports;var r=W[t]={exports:{}};return X[t].call(r.exports,r,r.exports,j),r.exports}j.d=(t,e)=>{for(var r in e)j.o(e,r)&&!j.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},j.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{j.d(H,{P:()=>Br,m:()=>Ir}),j(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class r{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=!1;"number"==typeof t?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=i?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return r=this.readBytes(e),t.decode(r);var r}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function n(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);n(l);const c=new Array(60);n(c);const d=new Array(512);n(d);const u=new Array(256);n(u);const f=new Array(29);n(f);const _=new Array(30);function w(t,e,r,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let p,g,b;function y(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(_);const m=t=>t<256?d[t]:d[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,r)=>{t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<{k(t,r[2*e],r[2*e+1])},A=(t,e)=>{let r=0;do{r|=1&t,t>>>=1,r<<=1}while(--e>0);return r>>>1},E=(t,e,r)=>{const i=new Array(16);let n,s,a=0;for(n=1;n<=15;n++)i[n]=a=a+r[n-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=A(i[e]++,e))}},R=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},U=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},T=(t,e,r,i)=>{const n=2*e,s=2*r;return t[n]{const i=t.heap[r];let n=r<<1;for(;n<=t.heap_len&&(n{let i,n,o,h,l=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],n=t.pending_buf[t.l_buf+l],l++,0===i?x(t,n,e):(o=u[n],x(t,o+256+1,e),h=s[o],0!==h&&(n-=f[o],k(t,n,h)),i--,o=m(i),x(t,o,r),h=a[o],0!==h&&(i-=_[o],k(t,i,h)))}while(l{const r=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)S(t,r,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],S(t,r,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,r[2*h]=r[2*a]+r[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,r[2*a+1]=r[2*o+1]=h,t.heap[1]=h++,S(t,r,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const r=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,d,u,f,_,w=0;for(u=0;u<=15;u++)t.bl_count[u]=0;for(r[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],u=r[2*r[2*c+1]+1]+1,u>h&&(u=h,w++),r[2*c+1]=u,c>i||(t.bl_count[u]++,f=0,c>=o&&(f=a[c-o]),_=r[2*c],t.opt_len+=_*(u+f),s&&(t.static_len+=_*(n[2*c+1]+f)));if(0!==w){do{for(u=h-1;0===t.bl_count[u];)u--;t.bl_count[u]--,t.bl_count[u+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(u=h;0!==u;u--)for(c=t.bl_count[u];0!==c;)d=t.heap[--l],d>i||(r[2*d+1]!==u&&(t.opt_len+=(u-r[2*d+1])*r[2*d],r[2*d+1]=u),c--)}})(t,e),E(r,l,t.bl_count)},B=(t,e,r)=>{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(r+1)+1]=65535,i=0;i<=r;i++)n=a,a=e[2*(i+1)+1],++o{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),i=0;i<=r;i++)if(n=a,a=e[2*(i+1)+1],!(++o{k(t,0+(i?1:0),3),((t,e,r,i)=>{U(t),v(t,r),v(t,~r),t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r})(t,e,r)};var C={_tr_init:t=>{L||((()=>{let t,e,r,i,n;const h=new Array(16);for(r=0,i=0;i<28;i++)for(f[i]=r,t=0;t<1<>=7;i<30;i++)for(_[i]=n<<7,t=0;t<1<{let n,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),I(t,t.l_desc),I(t,t.d_desc),a=(t=>{let e;for(B(t,t.dyn_ltree,t.l_desc.max_code),B(t,t.dyn_dtree,t.d_desc.max_code),I(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=n&&(n=s)):n=s=r+5,r+4<=n&&-1!==e?N(t,e,r,i):4===t.strategy||s===n?(k(t,2+(i?1:0),3),z(t,l,c)):(k(t,4+(i?1:0),3),((t,e,r,i)=>{let n;for(k(t,e-257,5),k(t,r-1,5),k(t,i-4,4),n=0;n(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(u[r]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},D=(t,e,r,i)=>{let n=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==r;){a=r>2e3?2e3:r,r-=a;do{n=n+e[i++]|0,s=s+n|0}while(--a);n%=65521,s%=65521}return n|s<<16|0};const V=new Uint32Array((()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e})());var M=(t,e,r,i)=>{const n=V,s=i+r;t^=-1;for(let r=i;r>>8^n[255&(t^e[r])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},F={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Z,_tr_stored_block:X,_tr_flush_block:W,_tr_tally:K,_tr_align:G}=C,{Z_NO_FLUSH:Y,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:q,Z_FINISH:$,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:rt,Z_DATA_ERROR:it,Z_BUF_ERROR:nt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:ct,Z_UNKNOWN:dt,Z_DEFLATED:ut}=F,ft=258,_t=262,wt=103,pt=113,gt=666,bt=(t,e)=>(t.msg=P[e],e),yt=t=>(t<<1)-(t>4?9:0),mt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,r)=>(e<{const e=t.state;let r=e.pending;r>t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},At=(t,e)=>{t.pending_buf[t.pending++]=e},Et=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=(t,e,r,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),r),1===t.state.wrap?t.adler=D(t.adler,e,n,r):2===t.state.wrap&&(t.adler=M(t.adler,e,n,r)),t.next_in+=n,t.total_in+=n,n)},Ut=(t,e)=>{let r,i,n=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,c=t.w_mask,d=t.prev,u=t.strstart+ft;let f=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(r=e,l[r+a]===_&&l[r+a-1]===f&&l[r]===l[s]&&l[++r]===l[s+1]){s+=2,r++;do{}while(l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&sa){if(t.match_start=e,a=i,i>=o)break;f=l[s+a-1],_=l[s+a]}}}while((e=d[e&c])>h&&0!=--n);return a<=t.lookahead?a:t.lookahead},Tt=t=>{const e=t.w_size;let r,i,n,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,r=i;do{n=t.head[--r],t.head[r]=n>=e?n-e:0}while(--i);i=e,r=i;do{n=t.prev[--r],t.prev[r]=n>=e?n-e:0}while(--i);s+=e}if(0===t.strm.avail_in)break;if(i=Rt(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=i,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},St=(t,e)=>{let r,i;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-_t&&(t.match_length=Ut(t,r)),t.match_length>=3)if(i=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},zt=(t,e)=>{let r,i,n;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,i=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=K(t,0,t.window[t.strstart-1]),i&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=i,this.func=n}const Bt=[new It(0,0,0,0,((t,e)=>{let r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===Y)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+r;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,St),new It(4,5,16,8,St),new It(4,6,32,32,St),new It(4,4,16,16,zt),new It(8,16,32,32,zt),new It(8,16,128,128,zt),new It(8,32,128,256,zt),new It(32,128,258,1024,zt),new It(32,258,258,4096,zt)];function Ot(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ut,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),mt(this.dyn_ltree),mt(this.dyn_dtree),mt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),mt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),mt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Lt=t=>{const e=(t=>{if(!t||!t.state)return bt(t,rt);t.total_in=t.total_out=0,t.data_type=dt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=Y,Z(e),tt})(t);var r;return e===tt&&((r=t.state).window_size=2*r.w_size,mt(r.head),r.max_lazy_match=Bt[r.level].max_lazy,r.good_match=Bt[r.level].good_length,r.nice_match=Bt[r.level].nice_length,r.max_chain_length=Bt[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),e};var Nt=(t,e,r,i,n,s)=>{if(!t)return rt;let a=1;if(e===st&&(e=6),i<0?(a=0,i=-i):i>15&&(a=2,i-=16),n<1||n>9||r!==ut||i<8||i>15||e<0||e>9||s<0||s>lt)return bt(t,rt);8===i&&(i=9);const o=new Ot;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=i,o.w_size=1<{let r,i;if(!t||!t.state||e>Q||e<0)return t?bt(t,rt):rt;const n=t.state;if(!t.output||!t.input&&0!==t.avail_in||n.status===gt&&e!==$)return bt(t,0===t.avail_out?nt:rt);n.strm=t;const s=n.last_flush;if(n.last_flush=e,42===n.status)if(2===n.wrap)t.adler=0,At(n,31),At(n,139),At(n,8),n.gzhead?(At(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),At(n,255&n.gzhead.time),At(n,n.gzhead.time>>8&255),At(n,n.gzhead.time>>16&255),At(n,n.gzhead.time>>24&255),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(At(n,255&n.gzhead.extra.length),At(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=M(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(At(n,0),At(n,0),At(n,0),At(n,0),At(n,0),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,3),n.status=pt);else{let e=ut+(n.w_bits-8<<4)<<8,r=-1;r=n.strategy>=ot||n.level<2?0:n.level<6?1:6===n.level?2:3,e|=r<<6,0!==n.strstart&&(e|=32),e+=31-e%31,n.status=pt,Et(n,e),0!==n.strstart&&(Et(n,t.adler>>>16),Et(n,65535&t.adler)),t.adler=1}if(69===n.status)if(n.gzhead.extra){for(r=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending!==n.pending_buf_size));)At(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.status=wt)}else n.status=wt;if(n.status===wt&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&kt(t),n.pending+2<=n.pending_buf_size&&(At(n,255&t.adler),At(n,t.adler>>8&255),t.adler=0,n.status=pt)):n.status=pt),0!==n.pending){if(kt(t),0===t.avail_out)return n.last_flush=-1,tt}else if(0===t.avail_in&&yt(e)<=yt(s)&&e!==$)return bt(t,nt);if(n.status===gt&&0!==t.avail_in)return bt(t,nt);if(0!==t.avail_in||0!==n.lookahead||e!==Y&&n.status!==gt){let r=n.strategy===ot?((t,e)=>{let r;for(;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===Y)return 1;break}if(t.match_length=0,r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):n.strategy===ht?((t,e)=>{let r,i,n,s;const a=t.window;for(;;){if(t.lookahead<=ft){if(Tt(t),t.lookahead<=ft&&e===Y)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,i=a[n],i===a[++n]&&i===a[++n]&&i===a[++n])){s=t.strstart+ft;do{}while(i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):Bt[n.level].func(n,e);if(3!==r&&4!==r||(n.status=gt),1===r||3===r)return 0===t.avail_out&&(n.last_flush=-1),tt;if(2===r&&(e===J?G(n):e!==Q&&(X(n,0,0,!1),e===q&&(mt(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),kt(t),0===t.avail_out))return n.last_flush=-1,tt}return e!==$?tt:n.wrap<=0?et:(2===n.wrap?(At(n,255&t.adler),At(n,t.adler>>8&255),At(n,t.adler>>16&255),At(n,t.adler>>24&255),At(n,255&t.total_in),At(n,t.total_in>>8&255),At(n,t.total_in>>16&255),At(n,t.total_in>>24&255)):(Et(n,t.adler>>>16),Et(n,65535&t.adler)),kt(t),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?tt:et)},Dt=t=>{if(!t||!t.state)return rt;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==gt?bt(t,rt):(t.state=null,e===pt?bt(t,it):tt)};const Vt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Mt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const r=e.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const e in r)Vt(r,e)&&(t[e]=r[e])}}return t},Pt=t=>{let e=0;for(let r=0,i=t.length;r=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Zt[254]=Zt[254]=1;var Xt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,r,i,n,s,a=t.length,o=0;for(n=0;n>>6,e[s++]=128|63&r):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|63&r):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|63&r);return e},Wt=(t,e)=>{const r=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,n;const s=new Array(2*r);for(n=0,i=0;i4)s[n++]=65533,i+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&i1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let i=0;i{(e=e||t.length)>t.length&&(e=t.length);let r=e-1;for(;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Zt[t[r]]>e?r:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Gt,Z_SYNC_FLUSH:Yt,Z_FULL_FLUSH:Jt,Z_FINISH:qt,Z_OK:$t,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:re}=F;function ie(t){this.options=Mt({level:te,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Nt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==$t)throw new Error(P[r]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=((t,e)=>{let r=e.length;if(!t||!t.state)return rt;const i=t.state,n=i.wrap;if(2===n||1===n&&42!==i.status||i.lookahead)return rt;if(1===n&&(t.adler=D(t.adler,e,r,0)),i.wrap=0,r>=i.w_size){0===n&&(mt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(r-i.w_size,r),0),e=t,r=i.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Tt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=vt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Tt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,i.wrap=n,tt})(this.strm,t),r!==$t)throw new Error(P[r]);this._dict_set=!0}}function ne(t,e){const r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||P[r.err];return r.result}ie.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?qt:Gt,"string"==typeof t?r.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),(s===Yt||s===Jt)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(n=Ct(r,s),n===Qt)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),n=Dt(this.strm),this.onEnd(n),this.ended=!0,n===$t;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===$t&&(this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ie,deflate:ne,deflateRaw:function(t,e){return(e=e||{}).raw=!0,ne(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,ne(t,e)},constants:F},ae=function(t,e){let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A,E;const R=t.state;r=t.next_in,A=t.input,i=r+(t.avail_in-5),n=t.next_out,E=t.output,s=n-(e-t.avail_out),a=n+(t.avail_out-257),o=R.dmax,h=R.wsize,l=R.whave,c=R.wnext,d=R.window,u=R.hold,f=R.bits,_=R.lencode,w=R.distcode,p=(1<>>24,u>>>=y,f-=y,y=b>>>16&255,0===y)E[n++]=65535&b;else{if(!(16&y)){if(0==(64&y)){b=_[(65535&b)+(u&(1<>>=y,f-=y),f<15&&(u+=A[r++]<>>24,u>>>=y,f-=y,y=b>>>16&255,!(16&y)){if(0==(64&y)){b=w[(65535&b)+(u&(1<o){t.msg="invalid distance too far back",R.mode=30;break t}if(u>>>=y,f-=y,y=n-s,v>y){if(y=v-y,y>l&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=d,0===c){if(k+=h-y,y2;)E[n++]=x[k++],E[n++]=x[k++],E[n++]=x[k++],m-=3;m&&(E[n++]=x[k++],m>1&&(E[n++]=x[k++]))}else{k=n-v;do{E[n++]=E[k++],E[n++]=E[k++],E[n++]=E[k++],m-=3}while(m>2);m&&(E[n++]=E[k++],m>1&&(E[n++]=E[k++]))}break}}break}}while(r>3,r-=m,f-=m<<3,u&=(1<{const h=o.bits;let l,c,d,u,f,_,w=0,p=0,g=0,b=0,y=0,m=0,v=0,k=0,x=0,A=0,E=null,R=0;const U=new Uint16Array(16),T=new Uint16Array(16);let S,z,I,B=null,O=0;for(w=0;w<=15;w++)U[w]=0;for(p=0;p=1&&0===U[b];b--);if(y>b&&(y=b),0===b)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(T[1]=0,w=1;w<15;w++)T[w+1]=T[w]+U[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){S=w-v,a[p]<_?(z=0,I=a[p]):a[p]>_?(z=B[O+a[p]],I=E[R+a[p]]):(z=96,I=0),l=1<>v)+c]=S<<24|z<<16|I|0}while(0!==c);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--U[w]){if(w===b)break;w=e[r+a[p]]}if(w>y&&(A&u)!==d){for(0===v&&(v=y),f+=g,m=w-v,k=1<852||2===t&&x>592)return 1;d=A&u,n[d]=y<<24|m<<16|f-s|0}}return 0!==A&&(n[f+A]=w-v<<24|64<<16|0),o.bits=y,0};const{Z_FINISH:ue,Z_BLOCK:fe,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:ge,Z_STREAM_ERROR:be,Z_DATA_ERROR:ye,Z_MEM_ERROR:me,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=F,xe=12,Ae=30,Ee=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Re(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Ue=t=>{if(!t||!t.state)return be;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return be;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Te,Se,ze=!0;const Ie=t=>{if(ze){Te=new Int32Array(512),Se=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(de(1,t.lens,0,288,Te,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;de(2,t.lens,0,32,Se,0,t.work,{bits:5}),ze=!1}t.lencode=Te,t.lenbits=9,t.distcode=Se,t.distbits=5},Be=(t,e,r,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(r-i,r-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(r-i,r),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return be;const r=new Re;t.state=r,r.window=null;const i=((t,e)=>{let r;if(!t||!t.state)return be;const i=t.state;return e<0?(r=0,e=-e):(r=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?be:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=r,i.wbits=e,Ue(t))})(t,e);return i!==we&&(t.state=null),i},Ne=(t,e)=>{let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A=0;const E=new Uint8Array(4);let R,U;const T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return be;r=t.state,r.mode===xe&&(r.mode=13),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,d=o,u=h,x=we;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0),l=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=Ae;break}if((15&l)!==ke){t.msg="unknown compression method",r.mode=Ae;break}if(l>>>=4,c-=4,k=8+(15&l),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Ae;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>8&255,E[2]=l>>>16&255,E[3]=l>>>24&255,r.check=M(r.check,E,4,0)),l=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>8),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(f=r.length,f>o&&(f=o),f&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(i.subarray(s,s+f),k)),512&r.flags&&(r.check=M(r.check,i,f,s)),o-=f,s+=f,r.length-=f),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break t;f=0;do{k=i[s+f++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&f>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=xe;break;case 10:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===o)break t;o--,l+=i[s++]<>>=1,c-=1,3&l){case 0:r.mode=14;break;case 1:if(Ie(r),r.mode=20,e===_e){l>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Ae}l>>>=2,c-=2;break;case 14:for(l>>>=7&c,c-=7&c;c<32;){if(0===o)break t;o--,l+=i[s++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Ae;break}if(r.length=65535&l,l=0,c=0,r.mode=15,e===_e)break t;case 15:r.mode=16;case 16:if(f=r.length,f){if(f>o&&(f=o),f>h&&(f=h),0===f)break t;n.set(i.subarray(s,s+f),a),o-=f,s+=f,h-=f,a+=f,r.length-=f;break}r.mode=xe;break;case 17:for(;c<14;){if(0===o)break t;o--,l+=i[s++]<>>=5,c-=5,r.ndist=1+(31&l),l>>>=5,c-=5,r.ncode=4+(15&l),l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Ae;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,R={bits:r.lenbits},x=de(0,r.lens,0,19,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid code lengths set",r.mode=Ae;break}r.have=0,r.mode=19;case 19:for(;r.have>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=p,c-=p,r.lens[r.have++]=b;else{if(16===b){for(U=p+2;c>>=p,c-=p,0===r.have){t.msg="invalid bit length repeat",r.mode=Ae;break}k=r.lens[r.have-1],f=3+(3&l),l>>>=2,c-=2}else if(17===b){for(U=p+3;c>>=p,c-=p,k=0,f=3+(7&l),l>>>=3,c-=3}else{for(U=p+7;c>>=p,c-=p,k=0,f=11+(127&l),l>>>=7,c-=7}if(r.have+f>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Ae;break}for(;f--;)r.lens[r.have++]=k}}if(r.mode===Ae)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Ae;break}if(r.lenbits=9,R={bits:r.lenbits},x=de(1,r.lens,0,r.nlen,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid literal/lengths set",r.mode=Ae;break}if(r.distbits=6,r.distcode=r.distdyn,R={bits:r.distbits},x=de(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,R),r.distbits=R.bits,x){t.msg="invalid distances set",r.mode=Ae;break}if(r.mode=20,e===_e)break t;case 20:r.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,ae(t,u),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,r.mode===xe&&(r.back=-1);break}for(r.back=0;A=r.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=xe;break}if(64&g){t.msg="invalid literal/length code",r.mode=Ae;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;A=r.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,64&g){t.msg="invalid distance code",r.mode=Ae;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Ae;break}r.mode=25;case 25:if(0===h)break t;if(f=u-h,r.offset>f){if(f=r.offset-f,f>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Ae;break}f>r.wnext?(f-=r.wnext,_=r.wsize-f):_=r.wnext-f,f>r.length&&(f=r.length),w=r.window}else w=n,_=a-r.offset,f=r.length;f>h&&(f=h),h-=f,r.length-=f;do{n[a++]=w[_++]}while(--f);0===r.length&&(r.mode=21);break;case 26:if(0===h)break t;n[a++]=r.length,h--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===o)break t;o--,l|=i[s++]<{if(!t||!t.state)return be;let e=t.state;return e.window&&(e.window=null),t.state=null,we},De=(t,e)=>{const r=e.length;let i,n,s;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?be:11===i.mode&&(n=1,n=D(n,e,r,0),n!==i.check)?ye:(s=Be(t,e,r,r),s?(i.mode=31,me):(i.havedict=1,we))):be},Ve=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Me=Object.prototype.toString,{Z_NO_FLUSH:Pe,Z_FINISH:Fe,Z_OK:Ze,Z_STREAM_END:Xe,Z_NEED_DICT:We,Z_STREAM_ERROR:je,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=F;function Ge(t){this.options=Mt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Le(this.strm,e.windowBits);if(r!==Ze)throw new Error(P[r]);if(this.header=new Ve,((t,e)=>{if(!t||!t.state)return be;const r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Me.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary),r!==Ze)))throw new Error(P[r])}function Ye(t,e){const r=new Ge(e);if(r.push(t),r.err)throw r.msg||P[r.err];return r.result}Ge.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Fe:Pe,"[object ArrayBuffer]"===Me.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),s=Ne(r,a),s===We&&n&&(s=De(r,n),s===Ze?s=Ne(r,a):s===He&&(s=We));r.avail_in>0&&s===Xe&&r.state.wrap>0&&0!==t[r.next_in];)Oe(r),s=Ne(r,a);switch(s){case je:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=r.avail_out,r.next_out&&(0===r.avail_out||s===Xe))if("string"===this.options.to){let t=jt(r.output,r.next_out),e=r.next_out-t,n=Wt(r.output,t);r.next_out=e,r.avail_out=i-e,e&&r.output.set(r.output.subarray(t,t+e),0),this.onData(n)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(s!==Ze||0!==o){if(s===Xe)return s=Ce(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Ge.prototype.onData=function(t){this.chunks.push(t)},Ge.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ge,inflate:Ye,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ye(t,e)},ungzip:Ye,constants:F};const{Deflate:qe,deflate:$e,deflateRaw:Qe,gzip:tr}=se,{Inflate:er,inflate:rr,inflateRaw:ir,ungzip:nr}=Je;var sr=$e,ar=er,or=rr;const hr=[137,80,78,71,13,10,26,10],lr=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;lr[t]=e}function cr(t,e){return(4294967295^function(t,e,r){let i=4294967295;for(let t=0;t>>8;return i}(0,t,e))>>>0}var dr,ur,fr,_r;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(dr||(dr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ur||(ur={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(fr||(fr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_r||(_r={}));const wr=new Uint8Array(0),pr=new Uint16Array([255]),gr=255===new Uint8Array(pr.buffer)[0];class br extends r{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:r=!1}=e;this._checkCrc=r,this._inflator=new ar,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ur.UNKNOWN,this._filterMethod=fr.UNKNOWN,this._interlaceMethod=_r.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=n;var l}}function yr(t,e,r){for(let i=0;i>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xr(t,e,r,i,n){let s=0;if(0===r.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=dr.UNKNOWN,this._zlibOptions=i(i({},Er),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hr)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ur.DEFLATE),this.writeByte(fr.ADAPTIVE),this.writeByte(_r.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:i,depth:n,data:s}=this._png,a=i*t,o=(new r).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Tr(t,e,r,i){for(let n=0;nnew Rr({width:t,height:e,data:r},void 0).encode(),Br=t=>function(t,e){return new br(t,void 0).decode()}(t)})();var K=H.P,G=H.m;function Y(t,e,r){if((i=t)&&i.hasOwnProperty("type")&&i.hasOwnProperty("data")){let i=Y(t.data,e,r);return i.includes("\n")?" #!"+t.type+i:i+" #!"+t.type}if(t&&"object"==typeof t){let i=Array.isArray(t);if(0==Object.keys(t).length)return i?"[]":"{}";let n="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(n+=e.repeat(r+1),i?n+="- "+Y(t[s],e,r+1):s.includes(": ")?(n+=Y(s,e,r+1),n+=": "+Y(t[s],e,r+1)):n+=s+": "+Y(t[s],e,r+1),n+="\n");return n}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var i}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var r="";return"number"==typeof e?r=" ".repeat(Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),Y(t,r,-1)}class q{constructor(t,e,r){this.startingLine=r||0,this.lineIndex=-1;let i=[];for(let e=0;e=e;)t.push(this.next());return new q(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,r=this.getLine(t);for(;r.startsWith(this.indentString);)r=r.slice(this.indentString.length),e++;return e}}function $(t,e){let r;for(t.indentLevel();!t.finished();){let e,i,n,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(n=o[1],s=s.replace(o[0],"")),a?(r||(r={}),e=a[1],i=s.replace(a[0],"").trim()):s.startsWith("-")&&(r||(r=[]),i=s.slice(1).trim()),i=i?Q(i,n):$(t.nextGroup(),n),Array.isArray(r)?r.push(i):r[e]=i}return e&&(r={type:e,data:r}),r}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return $(new q(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(et(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=et(i);return e}return t}function rt(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function it(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function nt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:r}=t;if(rt(e))return et(r);if(it(e))return r=et(r),"Texture2D"===e?r.export="Texture2D.png":"Effect"===e?r.export="Effect.cso":"TBin"===e?r.export="TBin.tbin":"BmFont"===e&&(r.export="BmFont.xml"),r;t=et(r)}let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(nt(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=nt(i);return e}return null}function st(t){const e={},{compressed:r,formatVersion:i,hidef:n,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!r,hiDef:n,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let c=a.getReaderTypeList(l);"SpriteFont"===c[0]&&(c=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:d,extractedImages:u,extractedMaps:f}=function(t,e){let r=[],i=[];const{converted:n}=function t(n,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(rt(o))return{converted:{type:o,data:n},traversed:a};if(null===o)return{converted:n,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:n}}},traversed:a+1};if(it(o))return"Texture2D"===o?(r.push({path:s.join(".")}),{converted:{type:o,data:{format:n.format}},traversed:a}):("TBin"===o&&i.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(n)?[]:{};let l=a,c=!0,d=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,r]of Object.entries(n)){let r;r=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:i,traversed:u}=t(n[e],[...s,e],r);h[e]=i,d?l=u:c&&(l=u,c=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:n,extractedImages:r,extractedMaps:i}}(h,c);return e.content=d,u.length>0&&(e.extractedImages=u),f.length>0&&(e.extractedMaps=f),e}function at(t){const e={},{compressed:r,readerData:i,hiDef:n,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:r?"a"===s||"i"===s?64:128:0,hidef:n},e.readers=et(i),e.content=nt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let r of Object.values(t))if(r||"object"==typeof r){let t=ot(r,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function ct(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function dt(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:ct(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ut(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=ot(t,"export");if(r){const{value:t}=r;let{type:e,data:i}=t;return"Texture2D"===e&&(i=G(t.width,t.height,new Uint8Array(i))),dt(i,e)}if(e){return dt(JSON.stringify(t,null,4),"JSON")}return null}function ft(t){let{yaml:e=!1,contentOnly:r=!1,fileName:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&r&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const n=[],{content:a}=t,o=ut(a,r);if(null!==o&&n.push(o),r)return n;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof i&&""!==i?"".concat(i,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),n.unshift(dt(l,e?"yaml":"JSON")),n}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function gt(t,e){if("png"===t){const t=await pt(e.png),r=K(new Uint8Array(t));return{type:"Texture2D",data:r.data,width:r.width,height:r.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function bt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:r="default"}=e,i=t.json||t.yaml;if(!i)throw new s("There is no JSON or YAML file to pack!");const n=await wt(i);let a=null;a=t.json?JSON.parse(n):at(tt(n));let o=_t(r);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(i.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:r}=h,[,i]=ht(r);e.export=await gt(i,t)}return a}async function yt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return mt(await t.arrayBuffer())}return mt(t.buffer)}function mt(t){return(new Z).load(t)}function vt(t){const{content:e}=t,{data:r,extension:i}=ut(e,!0);return new V(r,i)}function kt(t){let e={};for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class Et extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const Rt=[55296,56320];function Ut(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function Tt(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class St extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const i=Tt(e);t.write7BitNumber(i),t.writeString(e)}isValueType(){return!1}}class zt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class It extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class Bt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class Ot extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const r=(new Et).read(t),i=[];for(let n=0;n")}}class Lt extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new zt;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class Nt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new Bt;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const i=new Bt;i.write(t,e.x,null),i.write(t,e.y,null),i.write(t,e.width,null),i.write(t,e.height,null)}}class Ct extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const Dt=256;//! Use DXT1 compression. +function Vt(t,e,r,i){let n=Array(i);for(let t=0;t{let n=e.map((t=>t[i]));return{value:t[i],vec:n}}));return i.sort(((t,e)=>e.value-t.value)),[i.map((t=>{let{value:e}=t;return e})),i.map((t=>{let{vec:e}=t;return e}))]}function Wt(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,i=Array(r),n=Math.abs(e/r),s=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],i=a[0][1],n=Vt(e,i,Mt(t[e][e],t[i][i],t[e][i]),r);t=Ft(n,t),s=Zt(s,n),a=Pt(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:jt.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new jt(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Ht(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,i]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:Ht.multScalar(this,1/this.length)}get xyz(){return new jt(this.x,this.y,this.z)}get splatX(){return new Ht(this.x)}get splatY(){return new Ht(this.y)}get splatZ(){return new Ht(this.z)}get splatW(){return new Ht(this.w)}clone(){return new Ht(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=i,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new Ht(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new Ht(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new Ht(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new Ht(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let i=Ht.multScalar(t,1-r),n=Ht.multScalar(e,r);return Ht.add(i,n)}static multiplyAdd(t,e,r){return new Ht(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new Ht(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(i,e[n]),t)),new jt(0));i.mult(1/r);let n=t.reduce(((t,r,n)=>{let s=e[n],a=jt.sub(r,i);return t[0][0]+=a.x*a.x*s,t[0][1]+=a.x*a.y*s,t[0][2]+=a.x*a.z*s,t[1][1]+=a.y*a.y*s,t[1][2]+=a.y*a.z*s,t[2][2]+=a.z*a.z*s,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new jt(...Wt(r))}const Gt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],Yt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],Jt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],qt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function $t(t,e){const r=parseInt(t+.5);return r<0?0:r}function Qt(t){return $t(31*t.x)<<11|$t(63*t.y)<<5|$t(31*t.z)}function te(t,e,r,i,n){i[n+0]=255&t,i[n+1]=t>>8,i[n+2]=255&e,i[n+3]=e>>8;for(let t=0;t<4;t++)i[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function ee(t,e,r,i,n){let s,a=Qt(t),o=Qt(e);a<=o?s=r.slice():([a,o]=[o,a],s=r.map((t=>0===t?1:1===t?0:t))),te(a,o,s,i,n)}function re(t,e,r,i,n){let s,a=Qt(t),o=Qt(e);a3&(1^t)))):s=a==o?new Array(16).fill(0):r.slice(),te(a,o,s,i,n)}class ie{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const i=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!i)){const e=this._remap[s],i=(t[4*r+3]+1)/256;this._weights[e]+=n?i:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,i)=>e[i]=r[i]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,i)=>e[i]=r[i]))}}class ne{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class se extends ne{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new jt(0),this.end=new jt(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.erroree(r,i,n,t,e)))}compress4(t,e){const r=[Jt,qt,Jt];this.compressBase(r,((r,i,n)=>re(r,i,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let i=0;for(let n=0;n<3;n++){const s=t[n],a=this.color[n];r[n]=s[a][e];const o=r[n][2];i+=o*o}i{let r=1/0;const n=t.reduce(((t,i,n)=>{const s=jt.sub(e,i).multVector(this.metric).lengthSq;return s>=r?t:(r=s,n)}),0);return i+=r,n}));if(iee(r,i,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),jt.interpolate(this.start,this.end,1/3),jt.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,i,n)=>re(r,i,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const i=Kt(e,r);let n,s,a,o;n=s=e[0],a=o=jt.dot(n,i);for(let r=1;ro&&(s=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=s.clampGrid().clone()}}class oe extends ne{constructor(t){super(t);this.iterationCount=t.flags&Dt?8:1,this.bestError=1/0,this.metric=new Ht(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=Kt(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new Ht(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,i]=t;const n=new Ht(.5,.5,.5,1/4),s=Ht.multiplyAdd(r,n,e),a=s.splatW,o=Ht.multiplyAdd(r,n,i);return{ax:s,aa:a,bx:o,bb:o.splatW,ab:Ht.multVector(r,n).splatW}}),((r,i,n)=>ee(r,i,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,i,n]=t;const s=new Ht(1/3,1/3,1/3,1/9),a=new Ht(2/3,2/3,2/3,4/9),o=new Ht(2/9),h=Ht.multiplyAdd(i,s,Ht.multiplyAdd(r,a,e)),l=h.splatW,c=Ht.multiplyAdd(r,s,Ht.multiplyAdd(i,a,n));return{ax:h,aa:l,bx:c,bb:c.splatW,ab:Ht.multVector(o,Ht.add(r,i)).splatW}}),((r,i,n)=>re(r,i,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let n={start:new Ht(0),end:new Ht(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(n.bestK=0);const s=(e,r)=>{const s=t(e),a=this.computeOptimalPoints(s);return a.errorjt.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>i[t]-i[e]!=0?i[t]-i[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let i=0;i2&&void 0!==arguments[2]?arguments[2]:2;const{count:i}=this.colors,n=(e,i,n)=>{const s={bestI:e,bestJ:2===r?n:i,iteration:t};return 3===r&&(s.bestK=n),s};let s=new Ht(0);for(let t=0;t15?15:e}function le(t,e,r,i){let n=ce(t,e,5),s=ce(t,e,7);n.error<=s.error?function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){ue(n,i,s.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else ue(i,n,s,e,r)}(n,r,i):function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){ue(n,i,s.map((t=>0===t?1:1===t?0:9-t)),e,r)}else ue(i,n,s,e,r)}(s,r,i)}function ce(t,e,r){let{min:i,max:n}=function(t,e,r){let i=255,n=0;for(let s=0;s<16;s++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}i>n&&(i=n);n-iMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(i[6]=0,i[7]=255),i}function ue(t,e,r,i,n){i[n]=t,i[n+1]=e;let s=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[s]<<3*e,s++}for(let e=0;e<3;++e){let r=t>>8*e&255;i[a]=r,a++}}}function fe(t){const e=t>>11&31,r=t>>5&63,i=31&t;return[e<<3|e>>2,r<<2|r>>4,i<<3|i>>2,255]}function _e(t,e,r){const i=t.map(((t,i)=>Math.floor(t*(1-r)+e[i]*r)));return i[3]=255,i}function we(t,e,r,i){const n=function(t,e,r){const i=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,s=fe(i),a=fe(n);return[s,a,_e(s,a,r&&i<=n?.5:1/3),r&&i<=n?[0,0,0,0]:_e(s,a,2/3)]}(e,r,i),s=function(t,e){let r=e+4,i=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];i[4*e+0]=3&n,i[4*e+1]=n>>2&3,i[4*e+2]=n>>4&3,i[4*e+3]=n>>6&3}return i}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[s[e]][r]}function pe(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function ge(t){let e=7&t,r=280&t,i=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=Dt&&(r=8),64!=i&&(i=32),e|r|i|128&t}function be(t,e){let{x:r=0,y:i=0,width:n=0,height:s=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;pe((function(o,h){let l=r+o,c=i+h;if(l>4}}(t,e,r):0!=(4&i)&&function(t,e,r){let i=e[r+0],n=e[r+1],s=de(i,n,i<=n?5:7),a=new Uint8Array(16),o=0,h=2;for(let t=0;t<2;t++){let t=0;for(let i=0;i<3;i++)t|=e[r+h]<<8*i,h++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=s[a[e]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function ve(t,e,r,i,n){const s=0!=(1&(n=ge(n)))?8:16;let a=0;!function(t,e,r){for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const s=new Uint8Array(64);let a=0,o=0;return pe((function(h,l){let c=e+h,d=r+l;if(c1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));let o=r.read(t),h=t.read(o);if(4==i)h=Re(h,n,s,ke);else if(5==i)h=Re(h,n,s,xe);else if(6==i)h=Re(h,n,s,Ae);else{if(2==i)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=i)throw new Error("Non-implemented Texture2D format type (".concat(i,") found."))}for(let t=0;t")}},BaseReader:At,BmFontReader:class extends At{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new St).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new St).write(t,e.export.data,null)}isValueType(){return!1}},BooleanReader:zt,CharReader:It,DictionaryReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let r={};const i=(new Et).read(t);for(let n=0;n")}},DoubleReader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},EffectReader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new Et).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Et).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Int32Reader:Bt,ListReader:Ot,NullableReader:Lt,RectangleReader:Nt,ReflectiveReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){return this.reader.read(t,e)}write(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}isValueType(){return!1}get type(){return"".concat(this.reader.type)}},SingleReader:Ct,SpriteFontReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.SpriteFontReader"===t}static parseTypeList(){return["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new Bt,i=new Ct,n=new Lt(new It);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:i.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const i=new Bt,n=new It,s=new Ct,a=new Lt(n),o=new Ue,h=new Ot(new Nt),l=new Ot(n),c=new Ot(new Te);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),h.write(t,e.glyphs,r),h.write(t,e.cropping,r),l.write(t,e.characterMap,r),i.write(t,e.verticalLineSpacing,null),s.write(t,e.horizontalSpacing,null),c.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},StringReader:St,TBinReader:class extends At{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new Bt).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Bt).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Texture2DReader:Ue,UInt32Reader:Et,Vector2Reader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new Ct;return{x:e.read(t),y:e.read(t)}}},Vector3Reader:Te,Vector4Reader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new Ct;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}};var ze;ze=Se,a.setReaders(ze),t.Readers=Se,t.XnbContent=V,t.XnbData=D,t.addReaders=function(t){return a.addReaders(t)},t.bufferToContents=function(t){return vt((new Z).load(t))},t.bufferToXnb=mt,t.pack=function(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=kt(t);let n=[];for(let[t,e]of Object.entries(i))n.push(bt(e,r).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(n).then((t=>!0===r.debug?t:t.filter((t=>{let{status:e,value:r}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.unpackToContent=function(t){return yt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:r=!1,contentOnly:i=!1,fileName:n=null}=e;"undefined"!=typeof window&&null===n&&(n=t.name);let[s]=ht(n);const a=t=>ft(t,{yaml:r,contentOnly:i,fileName:s});return yt(t).then(a)},t.unpackToXnbData=yt,t.xnbDataToContent=vt,t.xnbDataToFiles=ft,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/xnb.module.js b/dist/xnb.module.js index b0071d8..e062c28 100644 --- a/dist/xnb.module.js +++ b/dist/xnb.module.js @@ -15,11 +15,152 @@ const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettl return Promise.all(mappedPromises); }; +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; const UTF8_SECOND_BITES = 0x80; const UTF8_MASK = 0b111111; -const UTF16_BITES = [0xD800, 0xDC00]; -const UTF16_MASK = 0b1111111111; +const UTF16_BITES$2 = [0xD800, 0xDC00]; +const UTF16_MASK$2 = 0b1111111111; function UTF8Encode(code) { if (code < 0x80) return [code]; @@ -31,7 +172,7 @@ function UTF8Encode(code) { function UTF16Encode(code) { if (code < 0xFFFF) return [code]; code -= 0x10000; - return [UTF16_BITES[0] | code >> 10 & UTF16_MASK, UTF16_BITES[1] | code & UTF16_MASK]; + return [UTF16_BITES$2[0] | code >> 10 & UTF16_MASK$2, UTF16_BITES$2[1] | code & UTF16_MASK$2]; } function UTF8Decode(codeSet) { @@ -50,17 +191,17 @@ function UTF8Decode(codeSet) { return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); } -function UTF16Decode(codeSet) { +function UTF16Decode$2(codeSet) { var _codeSet2; if (typeof codeSet === "number") codeSet = [codeSet]; if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); const codeSetRange = codeSet.length; if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + return ((codeSet[0] & UTF16_MASK$2) << 10) + (codeSet[1] & UTF16_MASK$2) + 0x10000; } -function stringToUnicode(str) { +function stringToUnicode$2(str) { const utf16Map = Array.from({ length: str.length }, (_, i) => str.charCodeAt(i)); @@ -70,11 +211,11 @@ function stringToUnicode(str) { while (index < str.length) { let code = utf16Map[index]; - if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + if ((UTF16_BITES$2[0] & code) !== UTF16_BITES$2[0]) { result.push(code); index++; } else { - result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + result.push(UTF16Decode$2(utf16Map.slice(index, index + 2))); index += 2; } } @@ -136,7 +277,7 @@ function UnicodeToString(unicodeArr) { } function stringToUTF8(str) { - return UnicodeToUTF8(stringToUnicode(str)); + return UnicodeToUTF8(stringToUnicode$2(str)); } function UTF8ToString(utf8Array) { @@ -568,17 +709,43 @@ class BufferWriter { } -class XnbError extends Error { - constructor() { - let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - super(message); - this.name = this.constructor.name; - this.message = message; - Error.captureStackTrace(this, XnbError); - } - -} - +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ const MIN_MATCH = 2; const NUM_CHARS = 256; const BLOCKTYPE = { @@ -1074,6 +1241,9 @@ class LZ4Utils { } +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ const minMatch = 4; const minLength = 13; const searchLimit = 5; @@ -1288,56 +1458,43 @@ function compressSingleBlock(src, dst) { return compressBlock(src, dst, 0, src.length, hashTable); } -class ReaderResolver { - constructor(readers) { - this.readers = readers; - } - - read(buffer) { - let index = buffer.read7BitNumber() - 1; - if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); - return this.readers[index].read(buffer, this); - } - - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; - getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; - } +function UTF16Decode$1(codeSet) { + var _codeSet2; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; } -class BaseReader { - isValueType() { - return true; - } - - get type() { - return this.constructor.name.slice(0, -6); - } - - read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - writeIndex(buffer, resolver) { - if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); - } + while (index < str.length) { + let code = utf16Map[index]; - toString() { - return this.type; + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } } + return result; } -function UTF8Length(str) { - const codes = stringToUnicode(str); +function UTF8Length$1(str) { + const codes = stringToUnicode$1(str); return codes.reduce((sum, unicode) => { if (unicode < 0x80) return sum + 1; if (unicode < 0x800) return sum + 2; @@ -1346,6134 +1503,6436 @@ function UTF8Length(str) { }, 0); } -class StringReader extends BaseReader { +class StringReaderCore { read(buffer) { let length = buffer.read7BitNumber(); return buffer.readString(length); } - write(buffer, string, resolver) { - this.writeIndex(buffer, resolver); - const size = UTF8Length(string); + write(buffer, string) { + const size = UTF8Length$1(string); buffer.write7BitNumber(size); buffer.writeString(string); } - isValueType() { - return false; - } - } -class UInt32Reader extends BaseReader { +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + read(buffer) { - return buffer.readUInt32(); + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; } } -class ArrayReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - let size = uint32Reader.read(buffer); - let array = []; + get target() { + var _this$header; - for (let i = 0; i < size; i++) { - let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - array.push(value); - } + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; - return array; - } + case 'm': + return "Windows Phone 7"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, resolver); + case 'x': + return "Xbox 360"; - for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); - } + case 'a': + return "Android"; - isValueType() { - return false; - } + case 'i': + return "iOS"; - get type() { - return "Array<".concat(this.reader.type, ">"); + default: + return "Unknown"; + } } -} + get formatVersion() { + var _this$header2; -class BmFontReader extends BaseReader { - read(buffer) { - const stringReader = new StringReader(); - const xml = stringReader.read(buffer); - return { - export: { - type: this.type, - data: xml - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); - } - - isValueType() { - return false; - } - -} - -class BooleanReader extends BaseReader { - read(buffer) { - return Boolean(buffer.readInt()); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; -} + case 0x4: + return "XNA Game Studio 3.1"; -class CharReader extends BaseReader { - read(buffer) { - let charSize = this._getCharSize(buffer.peekInt()); + case 0x5: + return "XNA Game Studio 4.0"; - return buffer.readString(charSize); + default: + return "Unknown"; + } } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } + get hidef() { + var _this$header3; - _getCharSize(byte) { - return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); } -} + get compressed() { + var _this$header4; -class DictionaryReader extends BaseReader { - constructor(key, value) { - if (key == undefined || value == undefined) throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - super(); - this.key = key; - this.value = value; + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); } - read(buffer, resolver) { - let dictionary = {}; - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - for (let i = 0; i < size; i++) { - let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - dictionary[key] = value; - } - - return dictionary; + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(Object.keys(content).length); - - for (let key of Object.keys(content)) { - this.key.write(buffer, key, this.key.isValueType() ? null : resolver); - this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); - } + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); } - isValueType() { - return false; + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); } - get type() { - return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + toString() { + return this.stringify(); } } -class DoubleReader extends BaseReader { - read(buffer) { - return buffer.readDouble(); - } +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } + case "yaml": + return "yaml"; -} + case "png": + return "Texture2D"; -class EffectReader extends BaseReader { - read(buffer) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const bytecode = buffer.read(size); - return { - export: { - type: this.type, - data: bytecode - } - }; - } + case "cso": + return "Effect"; - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + case 'tbin': + return "TBin"; - isValueType() { - return false; + case 'xml': + return "BmFont"; } + return "Others"; } -class Int32Reader extends BaseReader { - read(buffer) { - return buffer.readInt32(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; } } -class ListReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; } - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const list = []; + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); - for (let i = 0; i < size; i++) { - const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } + this._validateHeader(); - return list; - } + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); - for (let data of Object.values(content)) { - this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock$1(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } } - } - - get type() { - return "List<".concat(this.reader.type, ">"); - } -} + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; -class NullableReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } - read(buffer, resolver) { - const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); - } - - isValueType() { - return false; - } - - get type() { - return "Nullable<".concat(this.reader.type, ">"); - } - -} + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); -class RectangleReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const x = int32Reader.read(buffer); - const y = int32Reader.read(buffer); - const width = int32Reader.read(buffer); - const height = int32Reader.read(buffer); - return { - x, - y, - width, - height - }; - } + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); - } + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); -} + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } -class SingleReader extends BaseReader { - read(buffer) { - return buffer.readSingle(); + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; } } -const kDxt1 = 1 << 0; -const kDxt3 = 1 << 1; -const kDxt5 = 1 << 2; -const kColourIterativeClusterFit = 1 << 8; -const kColourClusterFit = 1 << 3; -const kColourRangeFit = 1 << 4; -const kColourMetricPerceptual = 1 << 5; -const kColourMetricUniform = 1 << 6; -const kWeightColourByAlpha = 1 << 7; +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; -function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); - } + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } - return keys; -} + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } + for (; i < n;) { + let e = t.charCodeAt(i++); - return target; -} + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } + if (e >= 55296 && e <= 56319) continue; + } - return obj; -} + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } -function Rot(theta) { - let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; - return Mat; -} + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } -function Rij(k, l, theta, N) { - let Mat = Array(N); + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = (i === j) * 1.0; - } + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); } +}, + e = {}; - let Rotij = Rot(theta); - Mat[k][k] = Rotij[0][0]; - Mat[l][l] = Rotij[1][1]; - Mat[k][l] = Rotij[0][1]; - Mat[l][k] = Rotij[1][0]; - return Mat; +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; } -function getTheta(aii, ajj, aij) { - let th = 0.0; - let denom = ajj - aii; - - if (Math.abs(denom) <= 1E-12) { - th = Math.PI / 4.0; - } else { - th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); - } +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; - return th; -} +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); -function getAij(Mij) { - let N = Mij.length; - let maxMij = 0.0; - let maxIJ = [0, 1]; + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } - for (let i = 0; i < N; i++) { - for (let j = i + 1; j < N; j++) { - if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { - maxMij = Math.abs(Mij[i][j]); - maxIJ = [i, j]; - } + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; } - } - return [maxIJ, maxMij]; -} + isLittleEndian() { + return this.littleEndian; + } -function unitary(U, H) { - let N = U.length; - let Mat = Array(N); + setLittleEndian() { + return this.littleEndian = !0, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + isBigEndian() { + return !this.littleEndian; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + setBigEndian() { + return this.littleEndian = !1, this; + } - for (let k = 0; k < N; k++) { - for (let l = 0; l < N; l++) { - Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; - } - } + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; } - } - return Mat; -} + seek(t) { + return this.offset = t, this; + } -function AxB(A, B) { - let N = A.length; - let Mat = Array(N); + mark() { + return this._mark = this.offset, this; + } - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } + reset() { + return this.offset = this._mark, this; + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; + pushMark() { + return this._marks.push(this.offset), this; + } - for (let k = 0; k < N; k++) { - Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; - } + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; } - } - return Mat; -} + rewind() { + return this.offset = 0, this; + } -function eigens(Hij) { - let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; - let N = Hij.length; - let Ei = Array(N); - let e0 = Math.abs(convergence / N); - let Sij = Array(N); + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - for (let i = 0; i < N; i++) { - Sij[i] = Array(N); - } + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Sij[i][j] = (i === j) * 1.0; + return this; } - } - let Vab = getAij(Hij); + readBoolean() { + return 0 !== this.readUint8(); + } - while (Math.abs(Vab[1]) >= Math.abs(e0)) { - let i = Vab[0][0]; - let j = Vab[0][1]; - let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); - let Gij = Rij(i, j, psi, N); - Hij = unitary(Gij, Hij); - Sij = AxB(Sij, Gij); - Vab = getAij(Hij); - } + readInt8() { + return this._data.getInt8(this.offset++); + } - for (let i = 0; i < N; i++) { - Ei[i] = Hij[i][i]; - } + readUint8() { + return this._data.getUint8(this.offset++); + } - return sorting(Ei, Sij); -} + readByte() { + return this.readUint8(); + } -function sorting(values, vectors) { - let eigsCount = values.length; - vectors.length; - let pairs = Array.from({ - length: eigsCount - }, (_, i) => { - let vector = vectors.map(v => v[i]); - return { - value: values[i], - vec: vector - }; - }); - pairs.sort((a, b) => b.value - a.value); - let sortedValues = pairs.map(_ref => { - let { - value - } = _ref; - return value; - }); - let sortedVectors = pairs.map(_ref2 => { - let { - vec - } = _ref2; - return vec; - }); - return [sortedValues, sortedVectors]; -} + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); -function dominentPrincipalVector(matrix) { - let [, [dominentVector]] = eigens(matrix); - return dominentVector; -} + for (let i = 0; i < t; i++) e[i] = this.readByte(); -class Vec3 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values = [x, y, z]; - } + return e; + } - get x() { - return this._values[0]; - } + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); - get y() { - return this._values[1]; - } + return this.offset += 2, t; + } - get z() { - return this._values[2]; - } + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); - set x(value) { - this._values[0] = value; - } + return this.offset += 2, t; + } - set y(value) { - this._values[1] = value; - } + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); - set z(value) { - this._values[2] = value; - } + return this.offset += 4, t; + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } + return this.offset += 4, t; + } - get normalized() { - if (this.length === 0) return null; - return Vec3.multScalar(this, 1 / this.length); - } + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); - get colorInt() { - const floatToInt = value => { - const result = parseInt(value * 255 + 0.5); - return Math.max(Math.min(result, 255), 0); - }; + return this.offset += 4, t; + } - return this._values.map(floatToInt); - } + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); - clone() { - return new Vec3(this.x, this.y, this.z); - } + return this.offset += 8, t; + } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - return this; - } + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); - toVec4() { - let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return new Vec4(this.x, this.y, this.z, w); - } + return this.offset += 8, t; + } - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - return this; - } + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - return this; - } + return this.offset += 8, t; + } - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - return this; - } + readChar() { + return String.fromCharCode(this.readInt8()); + } - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - return this; - } + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (let i = 0; i < t; i++) e += this.readChar(); - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - return this; - } + return e; + } - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - return this; - } + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - return this; - } + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } - toString() { - return "Vec3( ".concat(this._values.join(", "), " )"); - } + writeByte(t) { + return this.writeUint8(t); + } - static add(a, b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } + writeBytes(t) { + this.ensureAvailable(t.length); - static sub(a, b) { - return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); - } + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z; - } + return this._updateLastWrittenByte(), this; + } - static multScalar(a, scalar) { - return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); - } + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static multVector(a, b) { - return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); - } + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } - static interpolate(a, b, p) { - let a_ = Vec3.multScalar(a, 1 - p); - let b_ = Vec3.multScalar(b, p); - return Vec3.add(a_, b_); - } + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } -} + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } -class Vec4 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values = [x, y, z, w]; - } + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } - get x() { - return this._values[0]; - } + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get y() { - return this._values[1]; - } + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get z() { - return this._values[2]; - } + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } - get w() { - return this._values[3]; - } + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } - set x(value) { - this._values[0] = value; - } + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); - set y(value) { - this._values[1] = value; - } + return this; + } - set z(value) { - this._values[2] = value; - } + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } - set w(value) { - this._values[3] = value; - } + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); - } + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; } - get normalized() { - if (this.length === 0) return null; - return Vec4.multScalar(this, 1 / this.length); - } + function s(t) { + let e = t.length; - get xyz() { - return new Vec3(this.x, this.y, this.z); + for (; --e >= 0;) t[e] = 0; } - get splatX() { - return new Vec4(this.x); - } + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); - get splatY() { - return new Vec4(this.y); - } + const _ = new Array(60); - get splatZ() { - return new Vec4(this.z); - } + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); - get splatW() { - return new Vec4(this.w); + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; } - clone() { - return new Vec4(this.x, this.y, this.z, this.w); + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; } - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - this._values[3] = w; - return this; - } + s(w); - toVec3() { - return this.xyz; - } + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - return this; - } + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - return this; - } + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; - subVector(v) { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - return this; - } + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - return this; - } + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - return this; - } + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; - reciprocal() { - this._values[0] = 1 / this._values[0]; - this._values[1] = 1 / this._values[1]; - this._values[2] = 1 / this._values[2]; - this._values[3] = 1 / this._values[3]; - return this; - } + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - return this; - } + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - return this; - } + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; - truncate() { - this._values[0] = Math.trunc(this._values[0]); - this._values[1] = Math.trunc(this._values[1]); - this._values[2] = Math.trunc(this._values[2]); - this._values[3] = Math.trunc(this._values[3]); - return this; - } + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - return this; - } + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); - toString() { - return "Vec4( ".concat(this._values.join(", "), " )"); - } + h = s; - static add(a, b) { - return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); - } + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); - static sub(a, b) { - return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); - } + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; - } + let l, + d, + _, + f, + c, + u, + w = 0; - static multScalar(a, scalar) { - return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); - } + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; - static multVector(a, b) { - return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); - } + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); - static interpolate(a, b, p) { - let a_ = Vec4.multScalar(a, 1 - p); - let b_ = Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; - static multiplyAdd(a, b, c) { - return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); - } + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); - static negativeMultiplySubtract(a, b, c) { - return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); - } + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; - static compareAnyLessThan(left, right) { - return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; - } + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; -} + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; -function computeWeightedCovariance(values, weights) { - let total = 0; - let mean = values.reduce((sum, value, i) => { - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1 / total); - let covariance = values.reduce((sum, value, i) => { - let weight = weights[i]; - let v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; - sum[0][1] += v.x * v.y * weight; - sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; - sum[1][2] += v.y * v.z * weight; - sum[2][2] += v.z * v.z * weight; - return sum; - }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - return covariance; -} - -function computePCA(values, weights) { - const covariance = computeWeightedCovariance(values, weights); - return new Vec3(...dominentPrincipalVector(covariance)); -} - -const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; -const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - -function floatToInt(value, limit) { - const integer = parseInt(value + 0.5); - if (integer < 0) return 0; - if (integer > limit) return integer; - return integer; -} - -function floatTo565(color) { - const r = floatToInt(31.0 * color.x, 31); - const g = floatToInt(63.0 * color.y, 63); - const b = floatToInt(31.0 * color.z, 31); - return r << 11 | g << 5 | b; -} - -function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { - result[blockOffset + 0] = firstColor & 0xff; - result[blockOffset + 1] = firstColor >> 8; - result[blockOffset + 2] = secondColor & 0xff; - result[blockOffset + 3] = secondColor >> 8; - - for (let y = 0; y < 4; y++) { - result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; - } -} - -function writeColourBlock3(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + let D = !1; - if (firstColor <= secondColor) { - remapped = indices.slice(); - } else { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); - } + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); -function writeColourBlock4(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; - if (firstColor < secondColor) { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => (index ^ 0x1) & 0x3); - } else if (firstColor == secondColor) { - remapped = new Array(16).fill(0); - } else { - remapped = indices.slice(); - } + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; -class ColorSet { - constructor(rgba, mask, flags) { - this.flags = flags; - this._count = 0; - this._transparent = false; - this._remap = []; - this._weights = []; - this._points = []; - const isDxt1 = (this.flags & kDxt1) != 0; - const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + for (e = 0; e <= 15; e++) s[e] = 0; - for (let i = 0; i < 16; i++) { - const bit = 1 << i; + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; - if ((mask & bit) == 0) { - this._remap[i] = -1; - continue; - } + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; - if (isDxt1 && rgba[4 * i + 3] < 128) { - this._remap[i] = -1; - this._transparent = true; - continue; - } + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; - for (let j = 0;; j++) { - if (j == i) { - const r = rgba[4 * i] / 255.0; - const g = rgba[4 * i + 1] / 255.0; - const b = rgba[4 * i + 2] / 255.0; - const a = (rgba[4 * i + 3] + 1) / 256.0; - this._points[this._count] = new Vec3(r, g, b); - this._weights[this._count] = weightByAlpha ? a : 1.0; - this._remap[i] = this._count; - this._count++; - break; - } + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; - const oldbit = 1 << j; - const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); - if (match) { - const index = this._remap[j]; - const w = (rgba[4 * i + 3] + 1) / 256.0; - this._weights[index] += weightByAlpha ? w : 1.0; - this._remap[i] = index; - break; - } - } - } + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; - for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); - } + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; - get transparent() { - return this._transparent; - } + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; - get count() { - return this._count; - } + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; - get points() { - return Object.freeze(this._points.slice()); - } + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; - get weights() { - return Object.freeze(this._weights.slice()); - } + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); - remapIndicesSingle(singleIndex, target) { - const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; - target.forEach((_, i) => target[i] = result[i]); - } + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); - remapIndices(indexMap, target) { - const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; - target.forEach((_, i) => target[i] = result[i]); - } + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; -} + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); -class ColorFit { - constructor(colorSet) { - this.colors = colorSet; - this.flags = colorSet.flags; - } + r %= 65521, s %= 65521; + } - compress(result, offset) { - const isDxt1 = (this.flags & kDxt1) != 0; + return r | s << 16 | 0; + }; - if (isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } else this.compress4(result, offset); - } + const F = new Uint32Array((() => { + let t, + e = []; - compress3(result, offset) {} + for (var i = 0; i < 256; i++) { + t = i; - compress4(result, offset) {} + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; -} + e[i] = t; + } -class SingleColourFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const singleColor = colorSet.points[0]; - this.color = singleColor.colorInt; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.index = 0; - this.error = Infinity; - this.bestError = Infinity; - } + return e; + })()); - compressBase(lookups, saveFunc) { - this.computeEndPoints(lookups); + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; - if (this.error < this.bestError) { - const indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - this.bestError = this.error; - } - } + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; - compress3(result, offset) { - const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; - this.compressBase(lookups, saveFunc); - } + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; - compress4(result, offset) { - const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + for (; --e >= 0;) t[e] = 0; + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; - this.compressBase(lookups, saveFunc); - } + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); - computeEndPoints(lookups) { - this.error = Infinity; + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; - for (let index = 0; index < 2; index++) { - const sources = []; - let error = 0; + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); - for (let channel = 0; channel < 3; channel++) { - const lookup = lookups[channel]; - const target = this.color[channel]; - sources[channel] = lookup[target][index]; - const diff = sources[channel][2]; - error += diff * diff; + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } } + } while ((e = _[e & d]) > h && 0 != --r); - if (error < this.error) { - this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); - this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); - this.index = 2 * index; - this.error = error; - } - } - } + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; -} + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; -class RangeFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - this.metric = new Vec3(1); + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722); - } + n = e, i = n; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.bestError = Infinity; - this.computePoints(); - } + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); - compressBase(codes, saveFunc) { - const { - points: values - } = this.colors; - let error = 0; - const closest = values.map(color => { - let minDist = Infinity; - const packedIndex = codes.reduce((idx, code, j) => { - const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; - if (dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - error += minDist; - return packedIndex; - }); + s += e; + } - if (error < this.bestError) { - let indices = new Uint8Array(16); - this.colors.remapIndices(closest, indices); - saveFunc(this.start, this.end, indices); - this.bestError = error; - } - } + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; - compress3(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; - this.compressBase(codes, saveFunc); - } + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); - compress4(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; - this.compressBase(codes, saveFunc); - } + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } - computePoints() { - const { - count, - points: values, - weights - } = this.colors; - if (count <= 0) return; - const principle = computePCA(values, weights); - let start, end, min, max; - start = end = values[0]; - min = max = Vec3.dot(start, principle); + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; - for (let i = 1; i < count; i++) { - let value = Vec3.dot(values[i], principle); + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); - if (value < min) { - start = values[i]; - min = value; - } else if (value > max) { - end = values[i]; - max = value; - } + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; } - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; } -} + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; -class ClusterFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const kMaxIterations = 8; - this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; - this.bestError = Infinity; - this.metric = new Vec4(1); + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722, 0); + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - const { - points: values, - weights - } = this.colors; - this.principle = computePCA(values, weights); - this.order = new Uint8Array(16 * kMaxIterations); - this.pointsWeights = []; - this.xSum_wSum = new Vec4(0); - } - - constructOrdering(axis, iteration) { - const currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration); - const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if (!uniqueOrder) return false; - this.copyOrderWeight(currentOrder); - return true; - } - - compress3(result, offset) { - const aabbx = _ref => { - let [part0,, part1, part2] = _ref; - const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); - const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; - this.compressBase(aabbx, saveFunc, 2); + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; } - compress4(result, offset) { - const aabbx = _ref2 => { - let [part0, part1, part2, part3] = _ref2; - const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); - const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); - const const2_9 = new Vec4(2 / 9); - const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; - this.compressBase(aabbx, saveFunc, 3); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; - compressBase(aabbFunc, saveFunc) { - let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - this.constructOrdering(this.principle, 0); - let best = { - start: new Vec4(0), - end: new Vec4(0), - error: this.bestError, - iteration: 0, - bestI: 0, - bestJ: 0 - }; - if (repeater === 3) best.bestK = 0; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - const leastSquares = (parts, internalIndices) => { - const aabbx = aabbFunc(parts); - const internalBest = this.computeOptimalPoints(aabbx); + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (internalBest.error < best.error) { - best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); - return true; - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; - return false; - }; + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } - for (let iterationIndex = 0;;) { - this.clusterIterate(iterationIndex, leastSquares, repeater); - if (best.iteration != iterationIndex) break; - iterationIndex++; - if (iterationIndex == this.iterationCount) break; - const newAxis = Vec4.sub(best.end, best.start).xyz; - if (!this.constructOrdering(newAxis, iterationIndex)) break; - } + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); - if (best.error < this.bestError) this.saveBlock(best, saveFunc); - } + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; - makeOrder(axis) { - const { - count, - points: values - } = this.colors; - const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); - return Array.from({ - length: count - }, (_, i) => i).sort((a, b) => { - if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; - return a - b; - }); - } + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); - copyOrderToThisOrder(order, iteration) { - const orderOffset = iteration * 16; - order.forEach((ord, i) => { - this.order[orderOffset + i] = ord; - }); - } + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); - checkOrderUnique(order, iteration) { - const { - count - } = this.colors; + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; - for (let it = 0; it < iteration; it++) { - let prevOffset = it * 16; - let same = true; + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } - for (let i = 0; i < count; i++) { - if (order[i] !== this.order[prevOffset + i]) { - same = false; - break; + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; } - } - if (same) return false; - } + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; - return true; - } + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } - copyOrderWeight(order) { - const { - count, - points: unweighted, - weights - } = this.colors; - this.xSum_wSum.set(0); + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; - for (let i = 0; i < count; i++) { - const j = order[i]; - const p = unweighted[j].toVec4(1); - const w = new Vec4(weights[j]); - const x = Vec4.multVector(p, w); - this.pointsWeights[i] = x; - this.xSum_wSum.addVector(x); - } - } + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); - computeOptimalPoints(vectorPoint) { - const { - ax, - bx, - aa, - bb, - ab - } = vectorPoint; - const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); - let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); - let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); - a.clampGrid(); - b.clampGrid(); - let error = this.computeError(_objectSpread2({ - a, - b - }, vectorPoint)); - return { - start: a, - end: b, - error - }; - } + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } - computeError(_ref3) { - let { - a, - b, - ax, - bx, - aa, - bb, - ab - } = _ref3; - const two = new Vec4(2); - const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); - const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); - const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); - const e4 = Vec4.multiplyAdd(two, e3, e1); - const e5 = Vec4.multVector(e4, this.metric); - return e5.x + e5.y + e5.z; - } + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } - saveBlock(best, writeFunc) { - const { - count - } = this.colors; - const { - start, - end, - iteration, - error, - bestI, - bestJ, - bestK = -1 - } = best; - const orderOffset = iteration * 16; - const unordered = new Uint8Array(16); + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } - const mapper = m => { - if (m < bestI) return 0; - if (m < bestJ) return 2; - if (m < bestK) return 3; - return 1; - }; + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; - for (let i = 0; i < count; i++) { - unordered[this.order[orderOffset + i]] = mapper(i); + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; } - const bestIndices = new Uint8Array(16); - this.colors.remapIndices(unordered, bestIndices); - writeFunc(start.xyz, end.xyz, bestIndices); - this.bestError = error; - } + const s = t.avail_in, + a = t.next_in, + o = t.input; - clusterIterate(index, func) { - let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - const { - count - } = this.colors; + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; - const indexMapper = (i, j, k) => { - const mapper = { - bestI: i, - bestJ: iterCount === 2 ? k : j, - iteration: index - }; - if (iterCount === 3) mapper.bestK = k; - return mapper; - }; + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); - let part0 = new Vec4(0.0); + n.strstart = t, n.lookahead = 2, zt(n); + } - for (let i = 0; i < count; i++) { - let part1 = new Vec4(0.0); + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; - for (let j = i;;) { - let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); - const kmin = j == 0 ? 1 : j; + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); - for (let k = kmin;;) { - const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - if (k == count) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); - if (iterCount === 2) break; - if (j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; - } + for (; e.length;) { + const i = e.shift(); - part0.addVector(this.pointsWeights[i]); + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } } - } -} + return t; + }, + Wt = t => { + let e = 0; -function quantise(alpha) { - const GRID = 15; - let result = Math.floor(alpha * (GRID / 255) + 0.5); - if (result < 0) return 0; - if (result > GRID) return GRID; - return result; -} + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; -function compressAlphaDxt3(rgba, mask, result, offset) { - for (let i = 0; i < 8; i++) { - let quant1 = quantise(rgba[8 * i + 3]); - let quant2 = quantise(rgba[8 * i + 7]); - const bit1 = 1 << 2 * i; - const bit2 = 1 << 2 * i + 1; - if ((mask & bit1) == 0) quant1 = 0; - if ((mask & bit2) == 0) quant2 = 0; - result[offset + i] = quant1 | quant2 << 4; - } -} + const i = new Uint8Array(e); -function compressAlphaDxt5(rgba, mask, result, offset) { - let step5 = interpolateAlpha(rgba, mask, 5); - let step7 = interpolateAlpha(rgba, mask, 7); - if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); -} + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } -function interpolateAlpha(rgba, mask, steps) { - let { - min, - max - } = setAlphaRange(rgba, mask, steps); - let code = setAlphaCodeBook(min, max, steps); - let indices = new Uint8Array(16); - let error = fitCodes(rgba, mask, code, indices); - return { - min, - max, - indices, - error + return i; }; -} - -function setAlphaRange(rgba, mask, steps) { - let min = 255; - let max = 0; - for (let i = 0; i < 16; i++) { - let bit = 1 << i; - if ((mask & bit) == 0) continue; - let value = rgba[4 * i + 3]; + let Kt = !0; - if (steps === 5) { - if (value !== 0 && value < min) min = value; - if (value !== 255 && value > max) max = value; - } else { - if (value < min) min = value; - if (value > max) max = value; - } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; } - if (min > max) min = max; - if (max - min < steps) max = Math.min(min + steps, 255); - if (max - min < steps) min = Math.max(max - steps, 0); - return { - min, - max - }; -} + const $t = new Uint8Array(256); -function setAlphaCodeBook(min, max, steps) { - let codes = [min, max, ...Array.from({ - length: steps - 1 - }, (_, i) => { - return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); - })]; + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - if (steps === 5) { - codes[6] = 0; - codes[7] = 255; - } + $t[254] = $t[254] = 1; - return codes; -} + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; -function fitCodes(rgba, mask, codes, indices) { - let err = 0; + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (let i = 0; i < 16; ++i) { - let bit = 1 << i; + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); - if ((mask & bit) == 0) { - indices[i] = 0; - continue; - } + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); - let value = rgba[4 * i + 3]; - let least = Infinity; - let index = 0; + for (r = 0, n = 0; n < i;) { + let e = t[n++]; - for (let j = 0; j < 8; ++j) { - let dist = value - codes[j]; - dist *= dist; + if (e < 128) { + s[r++] = e; + continue; + } - if (dist < least) { - least = dist; - index = j; + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); } } - indices[i] = index; - err += least; - } - - return err; -} + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; -function writeAlphaBlock5(_ref, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref; + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - if (index <= 5) return 7 - index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; -function writeAlphaBlock7(_ref2, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref2; + for (; i >= 0 && 128 == (192 & t[i]);) i--; - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - return 9 - index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; -function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { - result[offset] = alpha0; - result[offset + 1] = alpha1; - let indicesPointer = 0; - let resultPointer = offset + 2; + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; - for (let i = 0; i < 2; i++) { - let value = 0; + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); - for (let j = 0; j < 8; ++j) { - let index = indices[indicesPointer]; - value |= index << 3 * j; - indicesPointer++; + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; } + } - for (let j = 0; j < 3; ++j) { - let byte = value >> 8 * j & 0xff; - result[resultPointer] = byte; - resultPointer++; - } + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; } -} -function unpack565(color16bit) { - const red = color16bit >> 11 & 0x1f; - const green = color16bit >> 5 & 0x3f; - const blue = color16bit & 0x1f; - return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; -} + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; -function interpolateColorArray(a, b, amount) { - const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); - result[3] = 255; - return result; -} + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; -function unpackColorCodes(block, offset, isDxt1) { - const color1 = block[offset] | block[offset + 1] << 8; - const color2 = block[offset + 2] | block[offset + 3] << 8; - const unpackedColor1 = unpack565(color1); - const unpackedColor2 = unpack565(color2); - return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; -} + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } -function unpackIndices(block, blockOffset) { - let offset = blockOffset + 4; - let result = new Uint8Array(16); + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; - for (let i = 0; i < 4; i++) { - let packedIndices = block[offset + i]; - result[i * 4 + 0] = packedIndices & 0x3; - result[i * 4 + 1] = packedIndices >> 2 & 0x3; - result[i * 4 + 2] = packedIndices >> 4 & 0x3; - result[i * 4 + 3] = packedIndices >> 6 & 0x3; - } + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; - return result; -} + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; -function decompressColor(rgba, block, offset, isDxt1) { - const colorCode = unpackColorCodes(block, offset, isDxt1); - const indices = unpackIndices(block, offset); + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; - for (let i = 0; i < 16; i++) { - for (let j = 0; j < 4; j++) { - rgba[4 * i + j] = colorCode[indices[i]][j]; - } - } -} + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } -function decompressAlphaDxt3(rgba, block, offset) { - for (let i = 0; i < 8; ++i) { - let quant = block[offset + i]; - let lo = quant & 0x0f; - let hi = quant & 0xf0; - rgba[8 * i + 3] = lo | lo << 4; - rgba[8 * i + 7] = hi | hi >> 4; - } -} + if (32 & m) { + U.mode = 12; + break t; + } -function decompressAlphaDxt5(rgba, block, offset) { - let alpha0 = block[offset + 0]; - let alpha1 = block[offset + 1]; - let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); - let indices = new Uint8Array(16); - let indicePointer = 0; - let bytePointer = 2; + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } - for (let i = 0; i < 2; i++) { - let value = 0; + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; - for (let j = 0; j < 3; j++) { - let byte = block[offset + bytePointer]; - value |= byte << 8 * j; - bytePointer++; - } + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } - for (let j = 0; j < 8; j++) { - let index = value >> 3 * j & 0x7; - indices[indicePointer] = index; - indicePointer++; - } - } + t.msg = "invalid distance code", U.mode = 30; + break t; + } - for (let i = 0; i < 16; ++i) { - rgba[4 * i + 3] = codes[indices[i]]; - } -} + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } -const DXT1_COMPRESSED_BYTES = 8; -const DXT5_COMPRESSED_BYTES = 16; -const COLORS = 4; -const DECOMPRESSED_BLOCK_SIZE = 16; + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } -function blockRepeat(width, height, func) { - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - func(x, y); - } - } -} + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; -function rectRepeat(func) { - for (let y = 0; y < 4; y++) { - for (let x = 0; x < 4; x++) { - func(x, y); - } - } -} + do { + x[r++] = _[v++]; + } while (--m); -function FixFlags(flags) { - let method = flags & (kDxt1 | kDxt3 | kDxt5); - let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); - let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); - const extra = flags & kWeightColourByAlpha; - if (method != kDxt3 && method != kDxt5) method = kDxt1; - if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; - if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; - return method | fit | metric | extra; -} + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; -function GetStorageRequirements(width, height, flags) { - flags = FixFlags(flags); - const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); - const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - return blockcount * blocksize; -} + do { + x[r++] = _[v++]; + } while (--m); -function extractColorBlock(img) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - let mask = 0; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + if (v = 0, d < k) { + m = d, k -= m; - if (sx < width && sy < height) { - let sourceColorOffset = COLORS * (width * sy + sx); + do { + x[r++] = _[v++]; + } while (--m); - for (let i = 0; i < COLORS; i++) { - block[blockColorOffset++] = img[sourceColorOffset++]; + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; } + } while (i < n && r < a); - mask |= 1 << 4 * py + px; - } else blockColorOffset += COLORS; - }); - return { - block, - mask + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; }; -} -function copyBuffer(result, block) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); - if (sx < width && sy < height) { - let resultColorOffset = COLORS * (width * sy + sx); + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; - for (let i = 0; i < COLORS; i++) { - result[resultColorOffset + i] = block[blockColorOffset++]; - } - } else blockColorOffset += COLORS; - }); -} + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; -function getCompressor(colorSet) { - if (colorSet.count === 1) return new SingleColourFit(colorSet); - if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); - return new ClusterFit(colorSet); -} + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; -function CompressMasked(rgba, mask, result, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - const colors = new ColorSet(rgba, mask, flags); - const compressor = getCompressor(colors); - compressor.compress(result, offset + colorOffset); - if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); -} + for (w = 0; w <= 15; w++) z[w] = 0; -function decompressBlock(result, block, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); - if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); -} + for (p = 0; p < n; p++) z[e[i + p]]++; -function compressImage(source, width, height, result, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let targetBlockPointer = 0; - blockRepeat(width, height, function (x, y) { - const { - block: sourceRGBA, - mask - } = extractColorBlock(source, { - x, - y, - width, - height - }); - CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); - targetBlockPointer += bytesPerBlock; - }); -} + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); -function decompressImage(result, width, height, source, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let sourceBlockPointer = 0; + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - decompressBlock(targetRGBA, source, sourceBlockPointer, flags); - copyBuffer(result, targetRGBA, { - x, - y, - width, - height - }); - sourceBlockPointer += bytesPerBlock; - } - } -} + for (g = 1; g < b && 0 === z[g]; g++); -const flags = { - DXT1: kDxt1, - DXT3: kDxt3, - DXT5: kDxt5, - ColourIterativeClusterFit: kColourIterativeClusterFit, - ColourClusterFit: kColourClusterFit, - ColourRangeFit: kColourRangeFit, - ColourMetricPerceptual: kColourMetricPerceptual, - ColourMetricUniform: kColourMetricUniform, - WeightColourByAlpha: kWeightColourByAlpha -}; + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; -function compress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = GetStorageRequirements(width, height, flags); - const result = new Uint8Array(targetSize); - compressImage(source, width, height, result, flags); - return result; -} + if (v > 0 && (0 === t || 1 !== b)) return -1; -function decompress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = width * height * 4; - const result = new Uint8Array(targetSize); - decompressImage(result, width, height, source, flags); - return result; -} + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; -class Texture2DReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - let format = int32Reader.read(buffer); - let width = uint32Reader.read(buffer); - let height = uint32Reader.read(buffer); - let mipCount = uint32Reader.read(buffer); - if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); - let dataSize = uint32Reader.read(buffer); - let data = buffer.read(dataSize); - if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } else if (format != 0) throw new XnbError("Non-implemented Texture2D format type (".concat(format, ") found.")); + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); - for (let i = 0; i < data.length; i += 4) { - let inverseAlpha = 255 / data[i + 3]; - data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); - } + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; - return { - format, - export: { - type: this.type, - data, - width, - height + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; } - }; - } - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - this.writeIndex(buffer, resolver); - const width = content.export.width; - const height = content.export.height; - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - let data = content.export.data; + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; - for (let i = 0; i < data.length; i += 4) { - const alpha = data[i + 3] / 255; - data[i] = Math.floor(data[i] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } } - if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); - } - - isValueType() { - return false; - } + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; -} + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); -class Vector3Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - return { - x, - y, - z - }; + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; -} + let Ce, + De, + Ie = !0; -class SpriteFontReader extends BaseReader { - read(buffer, resolver) { - const int32Reader = new Int32Reader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(new CharReader()); - const texture = resolver.read(buffer); - const glyphs = resolver.read(buffer); - const cropping = resolver.read(buffer); - const characterMap = resolver.read(buffer); - const verticalLineSpacing = int32Reader.read(buffer); - const horizontalSpacing = singleReader.read(buffer); - const kerning = resolver.read(buffer); - const defaultCharacter = nullableCharReader.read(buffer); - return { - texture, - glyphs, - cropping, - characterMap, - verticalLineSpacing, - horizontalSpacing, - kerning, - defaultCharacter - }; - } + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const charReader = new CharReader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(charReader); - const texture2DReader = new Texture2DReader(); - const rectangleListReader = new ListReader(new RectangleReader()); - const charListReader = new ListReader(charReader); - const vector3ListReader = new ListReader(new Vector3Reader()); - this.writeIndex(buffer, resolver); + for (; e < 144;) t.lens[e++] = 8; - try { - texture2DReader.write(buffer, content.texture, resolver); - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } catch (ex) { - throw ex; - } + for (; e < 256;) t.lens[e++] = 9; - console.log("writing complitd!"); - } + for (; e < 280;) t.lens[e++] = 7; - isValueType() { - return false; - } + for (; e < 288;) t.lens[e++] = 8; -} + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; -class TBinReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - let size = int32Reader.read(buffer); - let data = buffer.read(size); - return { - export: { - type: this.type, - data - } - }; - } + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; - isValueType() { - return false; - } + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; -} + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; -class Vector2Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - return { - x, - y - }; - } + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } -} + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -class Vector4Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - let w = singleReader.read(buffer); - return { - x, - y, - z, - w - }; - } + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } -} + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } -const Readers = { - ArrayReader, - BaseReader, - BmFontReader, - BooleanReader, - CharReader, - DictionaryReader, - DoubleReader, - EffectReader, - Int32Reader, - ListReader, - NullableReader, - RectangleReader, - SingleReader, - SpriteFontReader, - StringReader, - TBinReader, - Texture2DReader, - UInt32Reader, - Vector2Reader, - Vector3Reader, - Vector4Reader -}; + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } -const simplifyType = type => { - let simple = type.split(/`|,/)[0]; - let isArray = simple.endsWith('[]'); - if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; - switch (simple) { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - let subtypes = parseSubtypes(type).map(simplifyType); - return "Dictionary<".concat(subtypes[0], ",").concat(subtypes[1], ">"); + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.ArrayReader': - let arrayType = parseSubtypes(type).map(simplifyType); - return "Array<".concat(arrayType, ">"); + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - let listType = parseSubtypes(type).map(simplifyType); - return "List<".concat(listType, ">"); + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; + i.mode = 6; - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); - case 'xTile.Pipeline.TideReader': - return 'TBin'; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); - case 'BmFont.XmlSourceReader': - return 'BmFont'; + i.length = 0, i.mode = 8; - default: - throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); - } -}; + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; -const parseSubtypes = type => { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); - return matches; -}; + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); -const getTypeInfo = type => { - let mainType = type.match(/[^<]+/)[0]; - let subtypes = type.match(/<(.+)>/); - subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; - return { - type: mainType, - subtypes - }; -}; + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); -const getReader = typeString => { - let { - type, - subtypes - } = getTypeInfo(typeString); - subtypes = subtypes.map(getReader); - if (Readers.hasOwnProperty("".concat(type, "Reader"))) return new Readers["".concat(type, "Reader")](...subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); -}; + i.mode = 9; -class XnbData { - constructor(header, readers, content) { - let { - target, - formatVersion, - hidef, - compressed - } = header; - this.header = { - target, - formatVersion, - hidef, - compressed - }; - this.readers = readers; - this.content = content; - } + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get target() { - var _this$header; + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } - switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { - case 'w': - return "Microsoft Windows"; + l = 0, d = 0; + } - case 'm': - return "Windows Phone 7"; + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; - case 'x': - return "Xbox 360"; + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'a': - return "Android"; + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; - case 'i': - return "iOS"; + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; - default: - return "Unknown"; - } - } + case Ue: + if (e === pe || e === ge) break t; - get formatVersion() { - var _this$header2; + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } - switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { - case 0x3: - return "XNA Game Studio 3.0"; + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 0x4: - return "XNA Game Studio 3.1"; + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; - case 0x5: - return "XNA Game Studio 4.0"; + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } - default: - return "Unknown"; - } - } + break; - get hidef() { - var _this$header3; + case 2: + i.mode = 17; + break; - return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); - } + case 3: + t.msg = "invalid block type", i.mode = ze; + } - get compressed() { - var _this$header4; + l >>>= 2, d -= 2; + break; - return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); - } + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - get contentType() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.type; - return "JSON"; - } + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } - get rawContent() { - let { - export: raw - } = this.content; - if (raw !== undefined) return raw.data; - return JSON.stringify(this.content, (key, value) => { - if (key === "export") return value.type; - return value; - }, 4); - } + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; - stringify() { - return JSON.stringify({ - header: this.header, - readers: this.readers, - content: this.content - }, null, 4); - } + case 15: + i.mode = 16; - toString() { - return this.stringify(); - } + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } -} + i.mode = Ue; + break; -function extensionToDatatype(extension) { - switch (extension) { - case "json": - return "JSON"; + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case "yaml": - return "yaml"; + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } - case "png": - return "Texture2D"; + i.have = 0, i.mode = 18; - case "cso": - return "Effect"; + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - case 'tbin': - return "TBin"; + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } - case 'xml': - return "BmFont"; - } + for (; i.have < 19;) i.lens[R[i.have++]] = 0; - return "Others"; -} + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } -class XnbContent { - constructor(data, ext) { - this.type = extensionToDatatype(ext); - this.content = data; - } + i.have = 0, i.mode = 19; -} + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -const HIDEF_MASK = 0x1; -const COMPRESSED_LZ4_MASK = 0x40; -const COMPRESSED_LZX_MASK = 0x80; -const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } -class XnbConverter { - constructor() { - this.target = ''; - this.formatVersion = 0; - this.hidef = false; - this.compressed = false; - this.compressionType = 0; - this.buffer = null; - this.fileSize = 0; - this.readers = []; - this.sharedResources = []; - } + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - load(arrayBuffer) { - this.buffer = new BufferReader(arrayBuffer); + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - this._validateHeader(); + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } - console.info('XNB file validated successfully!'); - this.fileSize = this.buffer.readUInt32(); - if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } - if (this.compressed) { - const decompressedSize = this.buffer.readUInt32(); + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } - if (this.compressionType == COMPRESSED_LZX_MASK) { - const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; - const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } else if (this.compressionType == COMPRESSED_LZ4_MASK) { - const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - const decompressed = new Uint8Array(decompressedSize); - decompressBlock$1(trimmedArray, decompressed); - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - } + for (; c--;) i.lens[i.have++] = v; + } + } - let count = this.buffer.read7BitNumber(); - const stringReader = new StringReader(); - const readers = []; + if (i.mode === ze) break; - for (let i = 0; i < count; i++) { - const type = stringReader.read(this.buffer); - const version = this.buffer.readInt32(); - const simpleType = simplifyType(type); - const reader = getReader(simpleType); - this.readers.push(reader); - readers.push({ - type, - version - }); - } + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } - const shared = this.buffer.read7BitNumber(); - if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); - const content = new ReaderResolver(this.readers); - const result = content.read(this.buffer); - console.log('Successfuly read XNB file!'); - return new XnbData({ - target: this.target, - formatVersion: this.formatVersion, - hidef: this.hidef, - compressed: this.compressed - }, readers, result); - } + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } - convert(json) { - const buffer = new BufferWriter(); - const stringReader = new StringReader(); - let { - target, - formatVersion, - hidef, - compressed - } = json.header; - this.target = target; - this.formatVersion = formatVersion; - this.hidef = hidef; - const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; - this.compressed = lz4Compression ? true : false; - buffer.writeString("XNB"); - buffer.writeString(this.target); - buffer.writeByte(this.formatVersion); - buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); - buffer.writeUInt32(0); - if (lz4Compression) buffer.writeUInt32(0); - buffer.write7BitNumber(json.readers.length); + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } - for (let reader of json.readers) { - this.readers.push(getReader(simplifyType(reader.type))); - stringReader.write(buffer, reader.type); - buffer.writeUInt32(reader.version); - } + if (i.mode = 20, e === ge) break t; - buffer.write7BitNumber(0); - const content = new ReaderResolver(this.readers); - content.write(buffer, json.content); - buffer.trim(); + case 20: + i.mode = 21; - if (lz4Compression) { - const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - let compressedSize = compressBound(trimmedArray.length); - let compressed = new Uint8Array(compressedSize); - compressedSize = compressSingleBlock(trimmedArray, compressed); - compressed = compressed.slice(0, compressedSize); - buffer.bytePosition = 6; - buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - buffer.writeUInt32(trimmedArray.length); - buffer.concat(compressed); - let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - return returnBuffer; + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; } - let fileSize = buffer.bytePosition; - buffer.bytePosition = 6; - buffer.writeUInt32(fileSize, 6); - return buffer.buffer; + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); } - _validateHeader() { - if (this.buffer == null) throw new XnbError('Buffer is null'); - const magic = this.buffer.readString(3); - if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); - this.target = this.buffer.readString(1).toLowerCase(); - this.formatVersion = this.buffer.readByte(); - const flags = this.buffer.readByte(1); - this.hidef = (flags & HIDEF_MASK) != 0; - this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; - this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; } -} + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; -var t = { - 396: function _() { - !function (t) { - if (t.TextEncoder && t.TextDecoder) return !1; + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); - function e() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; } - function i() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - fatal: !1 - }; - if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); - if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; } + } - Object.defineProperty(e.prototype, "encoding", { - value: "utf-8" - }), e.prototype.encode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); - let i = 0; - const n = t.length; - let r = 0, - s = Math.max(32, n + (n >> 1) + 7), - a = new Uint8Array(s >> 3 << 3); + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; - for (; i < n;) { - let e = t.charCodeAt(i++); + for (let t = 0; t < 256; t++) { + let e = t; - if (e >= 55296 && e <= 56319) { - if (i < n) { - const n = t.charCodeAt(i); - 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); - } + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; - if (e >= 55296 && e <= 56319) continue; - } + pi[t] = e; + } - if (r + 4 > a.length) { - s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; - const e = new Uint8Array(s); - e.set(a), a = e; - } + const gi = 4294967295; - if (0 != (4294967168 & e)) { - if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { - if (0 != (4292870144 & e)) continue; - a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; - } - a[r++] = 63 & e | 128; - } else a[r++] = e; - } + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; - return a.slice(0, r); - }, Object.defineProperty(i.prototype, "encoding", { - value: "utf-8" - }), Object.defineProperty(i.prototype, "fatal", { - value: !1 - }), Object.defineProperty(i.prototype, "ignoreBOM", { - value: !1 - }), i.prototype.decode = function (t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - stream: !1 - }; - if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); - const i = new Uint8Array(t); - let n = 0; - const r = i.length, - s = []; + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; - for (; n < r;) { - const t = i[n++]; - if (0 === t) break; - if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { - const e = 63 & i[n++]; - s.push((31 & t) << 6 | e); - } else if (224 == (240 & t)) { - const e = 63 & i[n++], - r = 63 & i[n++]; - s.push((31 & t) << 12 | e << 6 | r); - } else if (240 == (248 & t)) { - let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; - e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); - } - } + case "IDAT": + this.decodeIDAT(t); + break; - return String.fromCharCode.apply(null, s); - }, t.TextEncoder = e, t.TextDecoder = i; - }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); - } -}, - e = {}; + case "IEND": + this._end = !0; + break; -function i(n) { - var r = e[n]; - if (void 0 !== r) return r.exports; - var s = e[n] = { - exports: {} - }; - return t[n].call(s.exports, s, s.exports, i), s.exports; -} + case "tRNS": + this.decodetRNS(t); + break; -i.d = (t, e) => { - for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { - enumerable: !0, - get: e[n] - }); -}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); -var n = {}; + case "iCCP": + this.decodeiCCP(t); + break; -(() => { - i.d(n, { - P: () => Mi, - m: () => Fi - }), i(396); - const t = new TextDecoder("utf-8"), - e = new TextEncoder(); + case "tEXt": + this.decodetEXt(t); + break; - class r { - constructor() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let i = !1; - "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); - const n = e.offset ? e.offset >>> 0 : 0, - s = t.byteLength - n; - let a = n; - (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; - } + case "pHYs": + this.decodepHYs(); + break; - available() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset + t <= this.length; - } + default: + this.skip(t); + } - isLittleEndian() { - return this.littleEndian; - } + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); - setLittleEndian() { - return this.littleEndian = !0, this; + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); } - isBigEndian() { - return !this.littleEndian; - } + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; - setBigEndian() { - return this.littleEndian = !1, this; - } + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; - skip() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return this.offset += t, this; - } + case mi.TRUECOLOUR: + i = 3; + break; - seek(t) { - return this.offset = t, this; - } + case mi.INDEXED_COLOUR: + i = 1; + break; - mark() { - return this._mark = this.offset, this; - } + case mi.GREYSCALE_ALPHA: + i = 2; + break; - reset() { - return this.offset = this._mark, this; - } + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; - pushMark() { - return this._marks.push(this.offset), this; + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); } - popMark() { - const t = this._marks.pop(); + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; - if (void 0 === t) throw new Error("Mark stack empty"); - return this.seek(t), this; + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); } - rewind() { - return this.offset = 0, this; + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); } - ensureAvailable() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; - if (!this.available(t)) { - const e = 2 * (this.offset + t), - i = new Uint8Array(e); - i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); - } + for (; e < t; e++) { + const t = this.readByte(); - return this; + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } } - readBoolean() { - return 0 !== this.readUint8(); + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; } - readInt8() { - return this._data.getInt8(this.offset++); + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); } - readUint8() { - return this._data.getUint8(this.offset++); + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; } - readByte() { - return this.readUint8(); + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); } - readBytes() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - const e = new Uint8Array(t); + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; - for (let i = 0; i < t; i++) e[i] = this.readByte(); + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; - return e; - } + case 1: + Ri(s, a, n, i); + break; - readInt16() { - const t = this._data.getInt16(this.offset, this.littleEndian); + case 2: + Ni(s, a, o, n); + break; - return this.offset += 2, t; - } + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; - readUint16() { - const t = this._data.getUint16(this.offset, this.littleEndian); + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } - return this.offset += 2, t; - } + o = a, h += n + 1; + } - readInt32() { - const t = this._data.getInt32(this.offset, this.littleEndian); + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; - return this.offset += 4, t; + var l; } - readUint32() { - const t = this._data.getUint32(this.offset, this.littleEndian); + } - return this.offset += 4, t; - } + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } - readFloat32() { - const t = this._data.getFloat32(this.offset, this.littleEndian); + function Ri(t, e, i, n) { + let r = 0; - return this.offset += 4, t; - } + for (; r < n; r++) e[r] = t[r]; - readFloat64() { - const t = this._data.getFloat64(this.offset, this.littleEndian); + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } - return this.offset += 8, t; - } + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } - readBigInt64() { - const t = this._data.getBigInt64(this.offset, this.littleEndian); + function Ti(t, e, i, n, r) { + let s = 0; - return this.offset += 8, t; - } + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - readBigUint64() { - const t = this._data.getBigUint64(this.offset, this.littleEndian); + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; - return this.offset += 8, t; + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; } + } - readChar() { - return String.fromCharCode(this.readInt8()); - } + function Oi(t, e, i, n, r) { + let s = 0; - readChars() { - let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - let e = ""; + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; - for (let i = 0; i < t; i++) e += this.readChar(); + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; - return e; + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; } + } - readUtf8() { - let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return i = this.readBytes(e), t.decode(i); - var i; - } + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } - writeBoolean(t) { - return this.writeUint8(t ? 255 : 0), this; - } + const Bi = { + level: 3 + }; - writeInt8(t) { - return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); } - writeUint8(t) { - return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); } - writeByte(t) { - return this.writeUint8(t); + encodeSignature() { + this.writeBytes(wi); } - writeBytes(t) { - this.ensureAvailable(t.length); - - for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); - - return this._updateLastWrittenByte(), this; + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); } - writeInt16(t) { - return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); } - writeUint16(t) { - return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); } - writeInt32(t) { - return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; - writeUint32(t) { - return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; - } + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } - writeFloat32(t) { - return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); } - writeFloat64(t) { - return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; - writeBigInt64(t) { - return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; - writeBigUint64(t) { - return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; - } + case 3: + n.colorType = mi.TRUECOLOUR; + break; - writeChar(t) { - return this.writeUint8(t.charCodeAt(0)); - } + case 1: + n.colorType = mi.GREYSCALE; + break; - writeChars(t) { - for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; - return this; - } + default: + throw new Error("unsupported number of channels"); + } - writeUtf8(t) { - return this.writeBytes(function (t) { - return e.encode(t); - }(t)); - } + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; - toArray() { - return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; } - _updateLastWrittenByte() { - this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); } } - function s(t) { - let e = t.length; - - for (; --e >= 0;) t[e] = 0; + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); } - const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), - o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), - h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), - l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), - d = new Array(576); - s(d); - - const _ = new Array(60); - - s(_); - const f = new Array(512); - s(f); - const c = new Array(256); - s(c); - const u = new Array(29); - s(u); - const w = new Array(30); + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); - function p(t, e, i, n, r) { - this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + return n; } - let g, b, m; + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); - function k(t, e) { - this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + return n; } - s(w); + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); - const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], - v = (t, e) => { - t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; - }, - E = (t, e, i) => { - t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); - }, - A = (t, e, i) => { - E(t, i[2 * e], i[2 * e + 1]); - }, - x = (t, e) => { - let i = 0; + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); - do { - i |= 1 & t, t >>>= 1, i <<= 1; - } while (--e > 0); +var r = n.P, + s = n.m; - return i >>> 1; - }, - U = (t, e, i) => { - const n = new Array(16); - let r, - s, - a = 0; +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} - for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); - for (s = 0; s <= e; s++) { - let e = t[2 * s + 1]; - 0 !== e && (t[2 * s] = x(n[e]++, e)); + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; } - }, - z = t => { - let e; - - for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); - for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } - for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + let s = '\n'; - t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; - }, - R = t => { - t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; - }, - N = (t, e, i, n) => { - const r = 2 * e, - s = 2 * i; - return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; - }, - T = (t, e, i) => { - const n = t.heap[i]; - let r = i << 1; + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); - for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } - t.heap[i] = n; - }, - O = (t, e, i) => { - let n, - r, - s, - h, - l = 0; - if (0 !== t.last_lit) do { - n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); - } while (l < t.last_lit); - A(t, 256, e); - }, - L = (t, e) => { - const i = e.dyn_tree, - n = e.stat_desc.static_tree, - r = e.stat_desc.has_stree, - s = e.stat_desc.elems; - let a, - o, - h, - l = -1; + s += '\n'; + } + } - for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} - for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; - for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } - h = s; + return stringify(object, gap, -1); +} - do { - a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); - } while (t.heap_len >= 2); +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; - t.heap[--t.heap_max] = t.heap[1], ((t, e) => { - const i = e.dyn_tree, - n = e.max_code, - r = e.stat_desc.static_tree, - s = e.stat_desc.has_stree, - a = e.stat_desc.extra_bits, - o = e.stat_desc.extra_base, - h = e.stat_desc.max_length; + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); - let l, - d, - _, - f, - c, - u, - w = 0; + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } - for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } - for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + getLineNumber() { + return this.startingLine + this.lineIndex; + } - if (0 !== w) { - do { - for (f = h - 1; 0 === t.bl_count[f];) f--; + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); - t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; - } while (w > 0); + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } - for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); - } - })(t, e), U(i, l, t.bl_count); - }, - B = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } - for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); - }, - C = (t, e, i) => { - let n, - r, - s = -1, - a = e[1], - o = 0, - h = 7, - l = 4; + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } - for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { - if (o < l) do { - A(t, r, t.bl_tree); - } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); - o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); - } - }; + peek() { + return this.getLine(this.lineIndex + 1); + } - let D = !1; + finished() { + return this.lineIndex == this.lines.length - 1; + } - const I = (t, e, i, n) => { - E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { - R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; - })(t, e, i); - }; + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } - var S = { - _tr_init: t => { - D || ((() => { - let t, e, i, n, r; - const s = new Array(16); + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } - for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + return ''; + } - for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); - for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } - for (e = 0; e <= 15; e++) s[e] = 0; + return indentLevel; + } - for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; +} - for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); - for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; - for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } - for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } - g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); - })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); - }, - _tr_stored_block: I, - _tr_flush_block: (t, e, i, n) => { - let r, - s, - a = 0; - t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { - let e, - i = 4093624447; + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } - for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } - if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } - for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + if (type) { + object = { + type: type, + data: object + }; + } - return 0; - })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { - let e; + return object; +} - for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); +function getValue(value, type) { + value = JSON.parse(value); - return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; - })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { - let r; + if (type) { + value = { + type: type, + data: value + }; + } - for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + return value; +} - C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); - })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); - }, - _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), - _tr_align: t => { - E(t, 2, 3), A(t, 256, d), (t => { - 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); - })(t); - } - }, - Z = (t, e, i, n) => { - let r = 65535 & t | 0, - s = t >>> 16 & 65535 | 0, - a = 0; +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} - for (; 0 !== i;) { - a = i > 2e3 ? 2e3 : i, i -= a; +function deepCopy(obj) { + let newObj; - do { - r = r + e[n++] | 0, s = s + r | 0; - } while (--a); + if (Array.isArray(obj)) { + newObj = []; - r %= 65521, s %= 65521; + for (let item of obj) { + newObj.push(deepCopy(item)); } - return r | s << 16 | 0; - }; - - const F = new Uint32Array((() => { - let t, - e = []; - - for (var i = 0; i < 256; i++) { - t = i; + return newObj; + } - for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + if (!!obj && typeof obj === "object") { + newObj = {}; - e[i] = t; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); } - return e; - })()); + return newObj; + } - var M = (t, e, i, n) => { - const r = F, - s = n + i; - t ^= -1; + return obj; +} - for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; - return -1 ^ t; - }, - P = { - 2: "need dictionary", - 1: "stream end", - 0: "", - "-1": "file error", - "-2": "stream error", - "-3": "data error", - "-4": "insufficient memory", - "-5": "buffer error", - "-6": "incompatible version" - }, - H = { - Z_NO_FLUSH: 0, - Z_PARTIAL_FLUSH: 1, - Z_SYNC_FLUSH: 2, - Z_FULL_FLUSH: 3, - Z_FINISH: 4, - Z_BLOCK: 5, - Z_TREES: 6, - Z_OK: 0, - Z_STREAM_END: 1, - Z_NEED_DICT: 2, - Z_ERRNO: -1, - Z_STREAM_ERROR: -2, - Z_DATA_ERROR: -3, - Z_MEM_ERROR: -4, - Z_BUF_ERROR: -5, - Z_NO_COMPRESSION: 0, - Z_BEST_SPEED: 1, - Z_BEST_COMPRESSION: 9, - Z_DEFAULT_COMPRESSION: -1, - Z_FILTERED: 1, - Z_HUFFMAN_ONLY: 2, - Z_RLE: 3, - Z_FIXED: 4, - Z_DEFAULT_STRATEGY: 0, - Z_BINARY: 0, - Z_TEXT: 1, - Z_UNKNOWN: 2, - Z_DEFLATED: 8 - }; + default: + return false; + } +} - const { - _tr_init: W, - _tr_stored_block: K, - _tr_flush_block: $, - _tr_tally: Y, - _tr_align: j - } = S, - { - Z_NO_FLUSH: G, - Z_PARTIAL_FLUSH: X, - Z_FULL_FLUSH: V, - Z_FINISH: q, - Z_BLOCK: J, - Z_OK: Q, - Z_STREAM_END: tt, - Z_STREAM_ERROR: et, - Z_DATA_ERROR: it, - Z_BUF_ERROR: nt, - Z_DEFAULT_COMPRESSION: rt, - Z_FILTERED: st, - Z_HUFFMAN_ONLY: at, - Z_RLE: ot, - Z_FIXED: ht, - Z_DEFAULT_STRATEGY: lt, - Z_UNKNOWN: dt, - Z_DEFLATED: _t - } = H, - ft = 258, - ct = 262, - ut = 103, - wt = 113, - pt = 666, - gt = (t, e) => (t.msg = P[e], e), - bt = t => (t << 1) - (t > 4 ? 9 : 0), - mt = t => { - let e = t.length; +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; - for (; --e >= 0;) t[e] = 0; - }; + default: + return false; + } +} - let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; - const yt = t => { - const e = t.state; - let i = e.pending; - i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); - }, - vt = (t, e) => { - $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); - }, - Et = (t, e) => { - t.pending_buf[t.pending++] = e; - }, - At = (t, e) => { - t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; - }, - xt = (t, e, i, n) => { - let r = t.avail_in; - return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); - }, - Ut = (t, e) => { - let i, - n, - r = t.max_chain_length, - s = t.strstart, - a = t.prev_length, - o = t.nice_match; - const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, - l = t.window, - d = t.w_mask, - _ = t.prev, - f = t.strstart + ft; - let c = l[s + a - 1], - u = l[s + a]; - t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; - do { - if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { - s += 2, i++; + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } - do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } - if (n = ft - (f - s), s = f - ft, n > a) { - if (t.match_start = e, a = n, n >= o) break; - c = l[s + a - 1], u = l[s + a]; - } + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; } - } while ((e = _[e & d]) > h && 0 != --r); - return a <= t.lookahead ? a : t.lookahead; - }, - zt = t => { - const e = t.w_size; - let i, n, r, s, a; + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } - do { - if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { - t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } - do { - r = t.head[--i], t.head[i] = r >= e ? r - e : 0; - } while (--n); + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); - n = e, i = n; + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } - do { - r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; - } while (--n); + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); - s += e; - } + return { + converted, + extractedImages, + extractedMaps + }; +} - if (0 === t.strm.avail_in) break; - if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); - } while (t.lookahead < ct && 0 !== t.strm.avail_in); - }, - Rt = (t, e) => { - let i, n; +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { - if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { - t.match_length--; + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } - do { - t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; - } while (0 != --t.match_length); + obj = deepCopy(data); + } - t.strstart++; - } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); - } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; - if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); } - return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - }, - Nt = (t, e) => { - let i, n, r; + return newObj; + } - for (;;) { - if (t.lookahead < ct) { - if (zt(t), t.lookahead < ct && e === G) return 1; - if (0 === t.lookahead) break; - } + if (!!obj && typeof obj === "object") { + newObj = {}; - if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { - r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } - do { - ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); - } while (0 != --t.prev_length); + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } - if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } else if (t.match_available) { - if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; - } else t.match_available = 1, t.strstart++, t.lookahead--; - } + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} - return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); - function Tt(t, e, i, n, r) { - this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; } - const Ot = [new Tt(0, 0, 0, 0, (t, e) => { - let i = 65535; + return result; +} - for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { - if (t.lookahead <= 1) { - if (zt(t), 0 === t.lookahead && e === G) return 1; - if (0 === t.lookahead) break; - } +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; - t.strstart += t.lookahead, t.lookahead = 0; - const n = t.block_start + i; - if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; - if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; } + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); - }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + return null; +} - function Lt() { - this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; - } +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} - const Bt = t => { - if (!t || !t.state) return gt(t, et); - t.total_in = t.total_out = 0, t.data_type = dt; - const e = t.state; - return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; - }, - Ct = t => { - const e = Bt(t); - var i; - return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; - }, - Dt = (t, e, i, n, r, s) => { - if (!t) return et; - let a = 1; - if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); - 8 === n && (n = 9); - const o = new Lt(); - return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); - }; +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; - var It = Dt, - St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, - Zt = (t, e) => { - let i, n; - if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; - const r = t.state; - if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); - r.strm = t; - const s = r.last_flush; - if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { - let e = _t + (r.w_bits - 8 << 4) << 8, - i = -1; - i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; - } - if (69 === r.status) if (r.gzhead.extra) { - for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + case "yaml": + return "yaml"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); - } else r.status = 73; - if (73 === r.status) if (r.gzhead.name) { - i = r.pending; + case "Texture2D": + return "png"; - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + case "Effect": + return "cso"; - n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); + case 'TBin': + return "tbin"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); - } else r.status = 91; - if (91 === r.status) if (r.gzhead.comment) { - i = r.pending; + case 'BmFont': + return "xml"; + } - do { - if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { - n = 1; - break; - } + return "bin"; +} - n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); - } while (0 !== n); +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; - r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); - } else r.status = ut; + case "yaml": + return "text/plain"; - if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { - if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; - } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + case "Texture2D": + return "image/png"; - if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + case "Effect": + return "application/x-cso"; - if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { - let i = r.strategy === at ? ((t, e) => { - let i; + case 'BmFont': + return "application/xml"; + } - for (;;) { - if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { - if (e === G) return 1; - break; - } + return "application/octet-stream"; +} - if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : r.strategy === ot ? ((t, e) => { - let i, n, r, s; - const a = t.window; +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); - for (;;) { - if (t.lookahead <= ft) { - if (zt(t), t.lookahead <= ft && e === G) return 1; - if (0 === t.lookahead) break; - } + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; - if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { - s = t.strstart + ft; + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } - do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + return makeBlob(data, dataType); + } - t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); - } + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } - if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; - } + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } - return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; - })(r, e) : Ot[r.level].func(r, e); - if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; - if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + return "".concat(value.type, ".").concat(getExtension(value.type)); } - return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); - }, - Ft = t => { - if (!t || !t.state) return et; - const e = t.state.status; - return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); - }, - Mt = (t, e) => { - let i = e.length; - if (!t || !t.state) return et; - const n = t.state, - r = n.wrap; - if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} - if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { - 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); - let t = new Uint8Array(n.w_size); - t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; - } +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} - const s = t.avail_in, - a = t.next_in, - o = t.input; +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} - for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { - let t = n.strstart, - e = n.lookahead - 2; +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} - do { - n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; - } while (--e); +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } - n.strstart = t, n.lookahead = 2, zt(n); - } + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } - return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; - }; + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } - const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} - var Ht = function Ht(t) { - const e = Array.prototype.slice.call(arguments, 1); +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; - for (; e.length;) { - const i = e.shift(); + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } - if (i) { - if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + const found = searchElement(jsonData.content, "export"); - for (const e in i) Pt(i, e) && (t[e] = i[e]); - } - } + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } - return t; - }, - Wt = t => { - let e = 0; + return jsonData; +} - for (let i = 0, n = t.length; i < n; i++) e += t[i].length; +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ - const i = new Uint8Array(e); +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); - for (let e = 0, n = 0, r = t.length; e < r; e++) { - let r = t[e]; - i.set(r, n), n += r.length; + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); } - return i; - }; - - let Kt = !0; - - try { - String.fromCharCode.apply(null, new Uint8Array(1)); - } catch (t) { - Kt = !1; + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); } - const $t = new Uint8Array(256); - - for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; - - $t[254] = $t[254] = 1; - - var Yt = t => { - if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); - let e, - i, - n, - r, - s, - a = t.length, - o = 0; + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ - for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; - for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ - return e; - }, - jt = (t, e) => { - const i = e || t.length; - if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); - let n, r; - const s = new Array(2 * i); - for (r = 0, n = 0; n < i;) { - let e = t[n++]; +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); - if (e < 128) { - s[r++] = e; - continue; - } + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); - let a = $t[e]; - if (a > 4) s[r++] = 65533, n += a - 1;else { - for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ - a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); - } - } - return ((t, e) => { - if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); - let i = ""; +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ - for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); - return i; - })(s, r); - }, - Gt = (t, e) => { - (e = e || t.length) > t.length && (e = t.length); - let i = e - 1; +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ - for (; i >= 0 && 128 == (192 & t[i]);) i--; - return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; - }, - Xt = function Xt() { - this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; - }; +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ - const Vt = Object.prototype.toString, - { - Z_NO_FLUSH: qt, - Z_SYNC_FLUSH: Jt, - Z_FULL_FLUSH: Qt, - Z_FINISH: te, - Z_OK: ee, - Z_STREAM_END: ie, - Z_DEFAULT_COMPRESSION: ne, - Z_DEFAULT_STRATEGY: re, - Z_DEFLATED: se - } = H; - function ae(t) { - this.options = Ht({ - level: ne, - method: se, - chunkSize: 16384, - windowBits: 15, - memLevel: 8, - strategy: re - }, t || {}); - let e = this.options; - e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); - if (i !== ee) throw new Error(P[i]); +function fileMapper(files) { + let returnMap = {}; - if (e.header && St(this.strm, e.header), e.dictionary) { - let t; - if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); - this._dict_set = !0; - } + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; } - function oe(t, e) { - const i = new ae(e); - if (i.push(t, !0), i.err) throw i.msg || P[i.err]; - return i.result; - } + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ - ae.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize; - let r, s; - if (this.ended) return !1; - for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { - if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ - if (0 !== i.avail_out) { - if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; - } else this.onData(i.output); - } - return !0; - }, ae.prototype.onData = function (t) { - this.chunks.push(t); - }, ae.prototype.onEnd = function (t) { - t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; - var he = { - Deflate: ae, - deflate: oe, - deflateRaw: function deflateRaw(t, e) { - return (e = e || {}).raw = !0, oe(t, e); - }, - gzip: function gzip(t, e) { - return (e = e || {}).gzip = !0, oe(t, e); - }, - constants: H - }, - le = function le(t, e) { - let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } - const U = t.state; - i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} - t: do { - c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; +function setReaders(readers) { + return TypeReader.setReaders(readers); +} - e: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { - if (!(16 & m)) { - if (0 == (64 & m)) { - b = u[(65535 & b) + (f & (1 << m) - 1)]; - continue e; - } +function addReaders(readers) { + return TypeReader.addReaders(readers); +} - if (32 & m) { - U.mode = 12; - break t; - } +class BaseReader { + static isTypeOf(type) { + return false; + } - t.msg = "invalid literal/length code", U.mode = 30; - break t; - } + static hasSubType() { + return false; + } - k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } - i: for (;;) { - if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { - if (0 == (64 & m)) { - b = w[(65535 & b) + (f & (1 << m) - 1)]; - continue i; - } + static type() { + return this.name.slice(0, -6); + } - t.msg = "invalid distance code", U.mode = 30; - break t; - } + isValueType() { + return true; + } - if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + get type() { + return this.constructor.type(); + } - if (f >>>= m, c -= m, m = r - s, y > m) { - if (m = y - m, m > l && U.sane) { - t.msg = "invalid distance too far back", U.mode = 30; - break t; - } + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - if (v = 0, E = _, 0 === d) { - if (v += h - m, m < k) { - k -= m; + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } - do { - x[r++] = _[v++]; - } while (--m); + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } - v = r - y, E = x; - } - } else if (d < m) { - if (v += h + d - m, m -= d, m < k) { - k -= m; + toString() { + return this.type; + } - do { - x[r++] = _[v++]; - } while (--m); +} - if (v = 0, d < k) { - m = d, k -= m; +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; - do { - x[r++] = _[v++]; - } while (--m); + default: + return false; + } + } - v = r - y, E = x; - } - } - } else if (v += d - m, m < k) { - k -= m; + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } - do { - x[r++] = _[v++]; - } while (--m); +} - v = r - y, E = x; - } +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; - for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + default: + return false; + } + } - k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); - } else { - v = r - y; + static hasSubType() { + return true; + } - do { - x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; - } while (k > 2); + constructor(reader) { + super(); + this.reader = reader; + } - k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); - } + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; - break; - } - } - break; - } - } while (i < n && r < a); + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } - k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; - }; + return array; + } - const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), - _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), - fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), - ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); - var ue = (t, e, i, n, r, s, a, o) => { - const h = o.bits; + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } - let l, - d, - _, - f, - c, - u, - w = 0, - p = 0, - g = 0, - b = 0, - m = 0, - k = 0, - y = 0, - v = 0, - E = 0, - A = 0, - x = null, - U = 0; + isValueType() { + return false; + } - const z = new Uint16Array(16), - R = new Uint16Array(16); - let N, - T, - O, - L = null, - B = 0; + get type() { + return "Array<".concat(this.reader.type, ">"); + } - for (w = 0; w <= 15; w++) z[w] = 0; +} - for (p = 0; p < n; p++) z[e[i + p]]++; +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; - for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); +function UTF16Decode(codeSet) { + var _codeSet2; - if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} - for (g = 1; g < b && 0 === z[g]; g++); +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + while (index < str.length) { + let code = utf16Map[index]; - if (v > 0 && (0 === t || 1 !== b)) return -1; + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } - for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + return result; +} - for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} - if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; - for (;;) { - N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + default: + return false; + } + } - do { - d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; - } while (0 !== d); + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } - for (l = 1 << w - 1; A & l;) l >>= 1; + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } - if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { - if (w === b) break; - w = e[i + a[p]]; - } + isValueType() { + return false; + } - if (w > m && (A & f) !== _) { - for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; +} - if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; - _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; - } +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; } + } - return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; - }; + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } - const { - Z_FINISH: we, - Z_BLOCK: pe, - Z_TREES: ge, - Z_OK: be, - Z_STREAM_END: me, - Z_NEED_DICT: ke, - Z_STREAM_ERROR: ye, - Z_DATA_ERROR: ve, - Z_MEM_ERROR: Ee, - Z_BUF_ERROR: Ae, - Z_DEFLATED: xe - } = H, - Ue = 12, - ze = 30, - Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } - function Ne() { - this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + isValueType() { + return false; } - const Te = t => { - if (!t || !t.state) return ye; - const e = t.state; - return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; - }, - Oe = t => { - if (!t || !t.state) return ye; - const e = t.state; - return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); - }, - Le = (t, e) => { - let i; - if (!t || !t.state) return ye; - const n = t.state; - return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); - }, - Be = (t, e) => { - if (!t) return ye; - const i = new Ne(); - t.state = i, i.window = null; - const n = Le(t, e); - return n !== be && (t.state = null), n; - }; +} - let Ce, - De, - Ie = !0; +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; - const Se = t => { - if (Ie) { - Ce = new Int32Array(512), De = new Int32Array(32); - let e = 0; + default: + return false; + } + } - for (; e < 144;) t.lens[e++] = 8; + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } - for (; e < 256;) t.lens[e++] = 9; +} - for (; e < 280;) t.lens[e++] = 7; +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; - for (; e < 288;) t.lens[e++] = 8; + default: + return false; + } + } - for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { - bits: 9 - }), e = 0; e < 32;) t.lens[e++] = 5; + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); - ue(2, t.lens, 0, 32, De, 0, t.work, { - bits: 5 - }), Ie = !1; - } + return buffer.readString(charSize); + } - t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; - }, - Ze = (t, e, i, n) => { - let r; - const s = t.state; - return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; - }; + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } - var Fe = Oe, - Me = Be, - Pe = (t, e) => { - let i, - n, - r, - s, - a, - o, - h, - l, - d, - _, - f, - c, - u, - w, - p, - g, - b, - m, - k, - y, - v, - E, - A = 0; + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } - const x = new Uint8Array(4); - let U, z; - const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; - i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; +} - t: for (;;) switch (i.mode) { - case 1: - if (0 === i.wrap) { - i.mode = 13; - break; - } +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + default: + return false; + } + } - if (2 & i.wrap && 35615 === l) { - i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; - break; - } + static hasSubType() { + return true; + } - if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { - t.msg = "incorrect header check", i.mode = ze; - break; - } + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } - if ((15 & l) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); - if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { - t.msg = "invalid window size", i.mode = ze; - break; - } - i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; - break; + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } - case 2: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return dictionary; + } - if (i.flags = l, (255 & i.flags) !== xe) { - t.msg = "unknown compression method", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); - if (57344 & i.flags) { - t.msg = "unknown header flags set", i.mode = ze; - break; - } + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } - i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + isValueType() { + return false; + } - case 3: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } - i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; +} - case 4: - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; - i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + default: + return false; + } + } - case 5: - if (1024 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + read(buffer) { + return buffer.readDouble(); + } - i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; - } else i.head && (i.head.extra = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } - i.mode = 6; +} - case 6: - if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; - i.length = 0, i.mode = 7; +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; - case 7: - if (2048 & i.flags) { - if (0 === o) break t; - c = 0; + default: + return false; + } + } - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); - } while (v && c < o); + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.name = null); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } - i.length = 0, i.mode = 8; + isValueType() { + return false; + } - case 8: - if (4096 & i.flags) { - if (0 === o) break t; - c = 0; +} - do { - v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); - } while (v && c < o); +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; - if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; - } else i.head && (i.head.comment = null); + default: + return false; + } + } - i.mode = 9; + read(buffer) { + return buffer.readInt32(); + } - case 9: - if (512 & i.flags) { - for (; d < 16;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } - if (l !== (65535 & i.check)) { - t.msg = "header crc mismatch", i.mode = ze; - break; - } +} - l = 0, d = 0; - } +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; - i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; - break; + default: + return false; + } + } - case 10: - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + constructor(reader) { + super(); + this.reader = reader; + } - case 11: - if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; - t.adler = i.check = 1, i.mode = Ue; + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; - case Ue: - if (e === pe || e === ge) break t; + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } - case 13: - if (i.last) { - l >>>= 7 & d, d -= 7 & d, i.mode = 27; - break; - } + return list; + } - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); - switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { - case 0: - i.mode = 14; - break; + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } - case 1: - if (Se(i), i.mode = 20, e === ge) { - l >>>= 2, d -= 2; - break t; - } + isValueType() { + return false; + } - break; + get type() { + return "List<".concat(this.reader.type, ">"); + } - case 2: - i.mode = 17; - break; +} - case 3: - t.msg = "invalid block type", i.mode = ze; - } +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; - l >>>= 2, d -= 2; - break; + default: + return false; + } + } - case 14: - for (l >>>= 7 & d, d -= 7 & d; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if ((65535 & l) != (l >>> 16 ^ 65535)) { - t.msg = "invalid stored block lengths", i.mode = ze; - break; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); - case 15: - i.mode = 16; + if (!hasValue) { + booleanReader.read(buffer); + return null; + } - case 16: - if (c = i.length, c) { - if (c > o && (c = o), c > h && (c = h), 0 === c) break t; - r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; - break; - } + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } - i.mode = Ue; - break; + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } - case 17: - for (; d < 14;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { - t.msg = "too many length or distance symbols", i.mode = ze; - break; - } + if (content !== null) { + buffer.writeByte(0); + return; + } - i.have = 0, i.mode = 18; + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - case 18: - for (; i.have < i.ncode;) { - for (; d < 3;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; - } + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } - for (; i.have < 19;) i.lens[R[i.have++]] = 0; +} - if (i.lencode = i.lendyn, i.lenbits = 7, U = { - bits: i.lenbits - }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid code lengths set", i.mode = ze; - break; - } +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; - i.have = 0, i.mode = 19; + default: + return false; + } + } - case 19: - for (; i.have < i.nlen + i.ndist;) { - for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + static hasSubType() { + return true; + } - if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { - if (16 === b) { - for (z = p + 2; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + constructor(reader) { + super(); + this.reader = reader; + } - if (l >>>= p, d -= p, 0 === i.have) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } - v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; - } else if (17 === b) { - for (z = p + 3; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } - l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; - } else { - for (z = p + 7; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + isValueType() { + return false; + } - l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; - } + get type() { + return "".concat(this.reader.type); + } - if (i.have + c > i.nlen + i.ndist) { - t.msg = "invalid bit length repeat", i.mode = ze; - break; - } +} - for (; c--;) i.lens[i.have++] = v; - } - } +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; - if (i.mode === ze) break; + default: + return false; + } + } - if (0 === i.lens[256]) { - t.msg = "invalid code -- missing end-of-block", i.mode = ze; - break; - } + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } - if (i.lenbits = 9, U = { - bits: i.lenbits - }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { - t.msg = "invalid literal/lengths set", i.mode = ze; - break; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } - if (i.distbits = 6, i.distcode = i.distdyn, U = { - bits: i.distbits - }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { - t.msg = "invalid distances set", i.mode = ze; - break; - } +} - if (i.mode = 20, e === ge) break t; +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; - case 20: - i.mode = 21; + default: + return false; + } + } - case 21: - if (o >= 6 && h >= 258) { - t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); - break; - } + read(buffer) { + return buffer.readSingle(); + } - for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } - if (g && 0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +} - l >>>= m, d -= m, i.back += m; - } +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; - if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { - i.mode = 26; - break; - } +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} - if (32 & g) { - i.back = -1, i.mode = Ue; - break; - } +function Rij(k, l, theta, N) { + let Mat = Array(N); - if (64 & g) { - t.msg = "invalid literal/length code", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.extra = 15 & g, i.mode = 22; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } - case 22: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} - i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; - i.was = i.length, i.mode = 23; + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } - case 23: - for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + return th; +} - if (0 == (240 & g)) { - for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; - l >>>= m, d -= m, i.back += m; - } + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } - if (l >>>= p, d -= p, i.back += p, 64 & g) { - t.msg = "invalid distance code", i.mode = ze; - break; - } + return [maxIJ, maxMij]; +} - i.offset = b, i.extra = 15 & g, i.mode = 24; +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); - case 24: - if (i.extra) { - for (z = i.extra; d < z;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - if (i.offset > i.dmax) { - t.msg = "invalid distance too far back", i.mode = ze; - break; + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; } + } + } + } - i.mode = 25; - - case 25: - if (0 === h) break t; + return Mat; +} - if (c = f - h, i.offset > c) { - if (c = i.offset - c, c > i.whave && i.sane) { - t.msg = "invalid distance too far back", i.mode = ze; - break; - } +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); - c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; - } else w = r, u = a - i.offset, c = i.length; + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } - c > h && (c = h), h -= c, i.length -= c; + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; - do { - r[a++] = w[u++]; - } while (--c); + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } - 0 === i.length && (i.mode = 21); - break; + return Mat; +} - case 26: - if (0 === h) break t; - r[a++] = i.length, h--, i.mode = 21; - break; +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); - case 27: - if (i.wrap) { - for (; d < 32;) { - if (0 === o) break t; - o--, l |= n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } - if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { - t.msg = "incorrect data check", i.mode = ze; - break; - } + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } - l = 0, d = 0; - } + let Vab = getAij(Hij); - i.mode = 28; + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } - case 28: - if (i.wrap && i.flags) { - for (; d < 32;) { - if (0 === o) break t; - o--, l += n[s++] << d, d += 8; - } + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } - if (l !== (4294967295 & i.total)) { - t.msg = "incorrect length check", i.mode = ze; - break; - } + return sorting(Ei, Sij); +} - l = 0, d = 0; - } +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} - i.mode = 29; +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} - case 29: - E = me; - break t; +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } - case ze: - E = ve; - break t; + get x() { + return this._values[0]; + } - case 31: - return Ee; + get y() { + return this._values[1]; + } - default: - return ye; - } + get z() { + return this._values[2]; + } - return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; - }, - He = t => { - if (!t || !t.state) return ye; - let e = t.state; - return e.window && (e.window = null), t.state = null, be; - }, - We = (t, e) => { - if (!t || !t.state) return ye; - const i = t.state; - return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); - }, - Ke = (t, e) => { - const i = e.length; - let n, r, s; - return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; - }, - $e = function $e() { - this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; - }; + set x(value) { + this._values[0] = value; + } - const Ye = Object.prototype.toString, - { - Z_NO_FLUSH: je, - Z_FINISH: Ge, - Z_OK: Xe, - Z_STREAM_END: Ve, - Z_NEED_DICT: qe, - Z_STREAM_ERROR: Je, - Z_DATA_ERROR: Qe, - Z_MEM_ERROR: ti - } = H; + set y(value) { + this._values[1] = value; + } - function ei(t) { - this.options = Ht({ - chunkSize: 65536, - windowBits: 15, - to: "" - }, t || {}); - const e = this.options; - e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; - let i = Me(this.strm, e.windowBits); - if (i !== Xe) throw new Error(P[i]); - if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + set z(value) { + this._values[2] = value; } - function ii(t, e) { - const i = new ei(e); - if (i.push(t), i.err) throw i.msg || P[i.err]; - return i.result; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } - ei.prototype.push = function (t, e) { - const i = this.strm, - n = this.options.chunkSize, - r = this.options.dictionary; - let s, a, o; - if (this.ended) return !1; + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } - for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { - for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } - switch (s) { - case Je: - case Qe: - case qe: - case ti: - return this.onEnd(s), this.ended = !0, !1; - } + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; - if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { - let t = Gt(i.output, i.next_out), - e = i.next_out - t, - r = jt(i.output, t); - i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); - } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + return this._values.map(floatToInt); + } - if (s !== Xe || 0 !== o) { - if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; - if (0 === i.avail_in) break; - } - } + clone() { + return new Vec3(this.x, this.y, this.z); + } - return !0; - }, ei.prototype.onData = function (t) { - this.chunks.push(t); - }, ei.prototype.onEnd = function (t) { - t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; - }; - var ni = { - Inflate: ei, - inflate: ii, - inflateRaw: function inflateRaw(t, e) { - return (e = e || {}).raw = !0, ii(t, e); - }, - ungzip: ii, - constants: H - }; - const { - Deflate: ri, - deflate: si, - deflateRaw: ai, - gzip: oi - } = he, - { - Inflate: hi, - inflate: li, - inflateRaw: di, - ungzip: _i - } = ni; - var fi = si, - ci = hi, - ui = li; - const wi = [137, 80, 78, 71, 13, 10, 26, 10], - pi = []; + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } - for (let t = 0; t < 256; t++) { - let e = t; + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } - for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } - pi[t] = e; + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; } - const gi = 4294967295; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } - function bi(t, e) { - return (function (t, e, i) { - let n = 4294967295; + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } - for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - return n; - }(0, t, e) ^ gi) >>> 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; } - var mi, ki, yi, vi; - !function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; - }(mi || (mi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; - }(ki || (ki = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; - }(yi || (yi = {})), function (t) { - t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; - }(vi || (vi = {})); - const Ei = new Uint8Array(0), - Ai = new Uint16Array([255]), - xi = 255 === new Uint8Array(Ai.buffer)[0]; - - class Ui extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(t); - const { - checkCrc: i = !1 - } = e; - this._checkCrc = i, this._inflator = new ci(), this._png = { - width: -1, - height: -1, - channels: -1, - data: new Uint8Array(0), - depth: 1, - text: {} - }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); - } + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - decode() { - for (this.decodeSignature(); !this._end;) this.decodeChunk(); + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - return this.decodeImage(), this._png; - } + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } - decodeSignature() { - for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); - } + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } - decodeChunk() { - const t = this.readUint32(), - e = this.readChars(4), - i = this.offset; + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } - switch (e) { - case "IHDR": - this.decodeIHDR(); - break; + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } - case "PLTE": - this.decodePLTE(t); - break; + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } - case "IDAT": - this.decodeIDAT(t); - break; + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } - case "IEND": - this._end = !0; - break; + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } - case "tRNS": - this.decodetRNS(t); - break; + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } - case "iCCP": - this.decodeiCCP(t); - break; + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } - case "tEXt": - this.decodetEXt(t); - break; +} - case "pHYs": - this.decodepHYs(); - break; +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } - default: - this.skip(t); - } + get x() { + return this._values[0]; + } - if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + get y() { + return this._values[1]; + } - if (this._checkCrc) { - const i = this.readUint32(), - n = t + 4, - r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); - if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); - } else this.skip(4); - } + get z() { + return this._values[2]; + } - decodeIHDR() { - const t = this._png; - t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { - if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); - return t; - }(this.readUint8()); - const e = this.readUint8(); - let i; + get w() { + return this._values[3]; + } - switch (this._colorType = e, e) { - case mi.GREYSCALE: - i = 1; - break; + set x(value) { + this._values[0] = value; + } - case mi.TRUECOLOUR: - i = 3; - break; + set y(value) { + this._values[1] = value; + } - case mi.INDEXED_COLOUR: - i = 1; - break; + set z(value) { + this._values[2] = value; + } - case mi.GREYSCALE_ALPHA: - i = 2; - break; + set w(value) { + this._values[3] = value; + } - case mi.TRUECOLOUR_ALPHA: - i = 4; - break; + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } - default: - throw new Error("Unknown color type: ".concat(e)); - } + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } - if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); - this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); - } + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } - decodePLTE(t) { - if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); - const e = t / 3; - this._hasPalette = !0; - const i = []; - this._palette = i; + get xyz() { + return new Vec3(this.x, this.y, this.z); + } - for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); - } + get splatX() { + return new Vec4(this.x); + } - decodeIDAT(t) { - this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); - } + get splatY() { + return new Vec4(this.y); + } - decodetRNS(t) { - if (3 === this._colorType) { - if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); - let e = 0; + get splatZ() { + return new Vec4(this.z); + } - for (; e < t; e++) { - const t = this.readByte(); + get splatW() { + return new Vec4(this.w); + } - this._palette[e].push(t); - } + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } - for (; e < this._palette.length; e++) this._palette[e].push(255); - } - } + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } - decodeiCCP(t) { - let e, - i = ""; + toVec3() { + return this.xyz; + } - for (; "\0" !== (e = this.readChar());) i += e; + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } - const n = this.readUint8(); - if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); - const r = this.readBytes(t - i.length - 2); - this._png.iccEmbeddedProfile = { - name: i, - profile: ui(r) - }; - } + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } - decodetEXt(t) { - let e, - i = ""; + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } - for (; "\0" !== (e = this.readChar());) i += e; + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } - this._png.text[i] = this.readChars(t - i.length - 1); - } + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } - decodepHYs() { - const t = this.readUint32(), - e = this.readUint32(), - i = this.readByte(); - this._png.resolution = { - x: t, - y: e, - unit: i - }; - } + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } - decodeImage() { - if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); - const t = this._inflator.result; - if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); - if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); - this.decodeInterlaceNull(t); - } + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; - decodeInterlaceNull(t) { - const e = this._png.height, - i = this._png.channels * this._png.depth / 8, - n = this._png.width * i, - r = new Uint8Array(this._png.height * n); - let s, - a, - o = Ei, - h = 0; + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } - for (let l = 0; l < e; l++) { - switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { - case 0: - zi(s, a, n); - break; + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - case 1: - Ri(s, a, n, i); - break; + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - case 2: - Ni(s, a, o, n); - break; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } - case 3: - Ti(s, a, o, n, i); - break; + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } - case 4: - Oi(s, a, o, n, i); - break; + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } - default: - throw new Error("Unsupported filter: ".concat(t[h])); - } + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } - o = a, h += n + 1; - } + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } - if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { - const t = new Uint16Array(r.buffer); - if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; - this._png.data = t; - } else this._png.data = r; + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } - var l; - } + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); } - function zi(t, e, i) { - for (let n = 0; n < i; n++) e[n] = t[n]; + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } - function Ri(t, e, i, n) { - let r = 0; + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } - for (; r < n; r++) e[r] = t[r]; + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } - for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); } - function Ni(t, e, i, n) { - let r = 0; - if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; } - function Ti(t, e, i, n, r) { - let s = 0; +} - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} - for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; - } else { - for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} - for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; - } - } +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - function Oi(t, e, i, n, r) { - let s = 0; +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} - if (0 === i.length) { - for (; s < r; s++) e[s] = t[s]; +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} - for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; - } else { - for (; s < r; s++) e[s] = t[s] + i[s] & 255; +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; - for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; - } + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; } +} - function Li(t, e, i) { - const n = t + e - i, - r = Math.abs(n - t), - s = Math.abs(n - e), - a = Math.abs(n - i); - return r <= s && r <= a ? t : s <= a ? e : i; +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); } - const Bi = { - level: 3 - }; + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} - class Ci extends r { - constructor(t) { - let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); - } +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; - encode() { - return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); - } + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - encodeSignature() { - this.writeBytes(wi); - } + for (let i = 0; i < 16; i++) { + const bit = 1 << i; - encodeIHDR() { - this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); - } + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } - encodeIEND() { - this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); - } + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } - encodeIDAT(t) { - this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); - } + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } - encodeData() { - const { - width: t, - height: e, - channels: i, - depth: n, - data: s - } = this._png, - a = i * t, - o = new r().setBigEndian(); - let h = 0; + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { - if (16 !== n) throw new Error("unreachable"); - h = Si(s, o, a, h); + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } } - - const l = o.toArray(), - d = fi(l, this._zlibOptions); - this.encodeIDAT(d); } - _checkData(t) { - const { - colorType: e, - channels: i, - depth: n - } = function (t) { - const { - channels: e = 4, - depth: i = 8 - } = t; - if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); - if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); - const n = { - channels: e, - depth: i, - colorType: mi.UNKNOWN - }; - - switch (e) { - case 4: - n.colorType = mi.TRUECOLOUR_ALPHA; - break; + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } - case 3: - n.colorType = mi.TRUECOLOUR; - break; + get transparent() { + return this._transparent; + } - case 1: - n.colorType = mi.GREYSCALE; - break; + get count() { + return this._count; + } - case 2: - n.colorType = mi.GREYSCALE_ALPHA; - break; + get points() { + return Object.freeze(this._points.slice()); + } - default: - throw new Error("unsupported number of channels"); - } + get weights() { + return Object.freeze(this._weights.slice()); + } - return n; - }(t), - r = { - width: Di(t.width, "width"), - height: Di(t.height, "height"), - channels: i, - data: t.data, - depth: n, - text: {} - }; + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); - this._colorType = e; - const s = r.width * r.height * i; - if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); - return r; - } + target.forEach((_, i) => target[i] = result[i]); + } - writeCrc(t) { - this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); - } + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + target.forEach((_, i) => target[i] = result[i]); } - function Di(t, e) { - if (Number.isInteger(t) && t > 0) return t; - throw new TypeError("".concat(e, " must be a positive integer")); +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; } - function Ii(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeByte(t[n++]); + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; - return n; + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); } - function Si(t, e, i, n) { - for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + compress3(result, offset) {} - return n; + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; } - var Zi; - !function (t) { - t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; - }(Zi || (Zi = {})); + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); - const Fi = (t, e, i) => new Ci({ - width: t, - height: e, - data: i - }, undefined).encode(), - Mi = t => function (t, e) { - return new Ui(t, void 0).decode(); - }(t); -})(); + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } -var r = n.P, - s = n.m; + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; -function isTypeObject(object) { - return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); -} + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); -function stringify(o, gap, indentation) { - if (isTypeObject(o)) { - let s = stringify(o.data, gap, indentation); + this.compressBase(lookups, saveFunc); + } - if (s.includes('\n')) { - return ' #!' + o.type + s; - } else { - return s + ' #!' + o.type; - } - } else if (o && 'object' === typeof o) { - let isArray = Array.isArray(o); + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - if (Object.keys(o).length == 0) { - if (isArray) return '[]';else return '{}'; - } + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - let s = '\n'; + this.compressBase(lookups, saveFunc); + } - for (let k in o) { - if (Object.hasOwnProperty.call(o, k)) { - s += gap.repeat(indentation + 1); + computeEndPoints(lookups) { + this.error = Infinity; - if (isArray) { - s += '- ' + stringify(o[k], gap, indentation + 1); - } else { - if (k.includes(': ')) { - s += stringify(k, gap, indentation + 1); - s += ': ' + stringify(o[k], gap, indentation + 1); - } else { - s += k + ': ' + stringify(o[k], gap, indentation + 1); - } - } + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; - s += '\n'; + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; } } - - return s; - } else if ('string' === typeof o) { - return JSON.stringify(o); - } else if ('undefined' === typeof o || o === null) { - return 'null'; - } else if (!!o == o || +o == o) { - return JSON.stringify(o); - } else { - throw new Error('Non-implemented parsing for ' + o); } + } -function preStringify(object) { - let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; - var gap = ''; +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); - if (typeof space == 'number') { - gap = ' '.repeat(Math.min(10, space)); - } else if (typeof space == 'string') { - gap = space.slice(0, 10); + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); } - return stringify(object, gap, -1); -} + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); -class LineGenerator { - constructor(lines, indentString, startingLine) { - this.startingLine = startingLine || 0; - this.lineIndex = -1; - let filteredLines = []; + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } - for (let i = 0; i < lines.length; i++) { - let trimmedLine = lines[i].trim(); + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; - if (trimmedLine !== '') { - filteredLines.push([lines[i], i]); - } - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - this.lines = filteredLines; - this.indentString = indentString || this.findIndentString(); + this.compressBase(codes, saveFunc); } - getLineNumber() { - return this.startingLine + this.lineIndex; + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); } - nextGroup() { - let lines = []; - let baseIndent = this.indentLevel(this.lineIndex + 1); + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); - while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { - lines.push(this.next()); + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } } - return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); } - next() { - if (this.finished()) throw new Error('Trying to next finished generator'); - this.lineIndex++; - return this.getLine(); - } +} - peek() { - return this.getLine(this.lineIndex + 1); - } +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); - finished() { - return this.lineIndex == this.lines.length - 1; - } + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } - getLine(index) { - index = index !== undefined ? index : this.lineIndex; - if (index >= this.lines.length) return null; - return this.lines[index][0]; + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); } - findIndentString() { - for (let [line] of this.lines) { - if (!line.trim() || line.replace(/^\s+/, "") == line) continue; - return line.match(/^(\s+)/)[1]; - } - - return ''; + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; } - indentLevel(index) { - index = index !== undefined ? index : this.lineIndex; - if (index < 0) index = 0; - let indentLevel = 0; - let line = this.getLine(index); + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; - while (line.startsWith(this.indentString)) { - line = line.slice(this.indentString.length); - indentLevel++; - } + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - return indentLevel; + this.compressBase(aabbx, saveFunc, 2); } -} + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; -function getObject(lineGroup, type) { - let object; - lineGroup.indentLevel(); + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - while (!lineGroup.finished()) { - let line = lineGroup.next(); - let trimmedLine = line.trim(); - let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); - let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); - let key, value, type; + this.compressBase(aabbx, saveFunc, 3); + } - if (trimmedLine.startsWith('"')) { - keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); - } + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; - if (typeMatch) { - type = typeMatch[1]; - trimmedLine = trimmedLine.replace(typeMatch[0], ''); - } + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); - if (keyMatch) { - if (!object) object = {}; - key = keyMatch[1]; - value = trimmedLine.replace(keyMatch[0], '').trim(); - } else if (trimmedLine.startsWith('-')) { - if (!object) object = []; - value = trimmedLine.slice(1).trim(); - } + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; - if (value) { - value = getValue(value, type); - } else { - value = getObject(lineGroup.nextGroup(), type); + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; } - if (Array.isArray(object)) { - object.push(value); - } else { - object[key] = value; - } + if (best.error < this.bestError) this.saveBlock(best, saveFunc); } - if (type) { - object = { - type: type, - data: object - }; + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); } - return object; -} - -function getValue(value, type) { - value = JSON.parse(value); - - if (type) { - value = { - type: type, - data: value - }; + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); } - return value; -} - -function parse(str) { - let lines = str.replace(/\t/g, ' ').split('\n'); - let lineGenerator = new LineGenerator(lines); - return getObject(lineGenerator); -} + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; -function deepCopy(obj) { - let newObj; + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; - if (Array.isArray(obj)) { - newObj = []; + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } - for (let item of obj) { - newObj.push(deepCopy(item)); + if (same) return false; } - return newObj; + return true; } - if (!!obj && typeof obj === "object") { - newObj = {}; + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); - for (let [key, value] of Object.entries(obj)) { - newObj[key] = deepCopy(value); + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); } - - return newObj; } - return obj; -} - -function isPrimitiveReaderType(reader) { - switch (reader) { - case 'Boolean': - case 'Int32': - case 'Char': - case 'String': - case '': - case 'Vector2': - case 'Vector3': - case 'Vector4': - case 'Rectangle': - return true; - - default: - return false; + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; } -} - -function isExportReaderType(reader) { - switch (reader) { - case 'Texture2D': - case 'TBin': - case 'Effect': - case 'BmFont': - return true; - default: - return false; + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; } -} - -function convertJsonContentsToXnbNode(raw, readers) { - let extractedImages = []; - let extractedMaps = []; - - const { - converted - } = function recursiveConvert(obj, path) { - let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - const reader = readers[index]; - if (isPrimitiveReaderType(reader)) { - return { - converted: { - type: reader, - data: obj - }, - traversed: index - }; - } + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); - if (reader === null) { - return { - converted: obj, - traversed: index - }; - } + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; - if (reader.startsWith('Nullable')) { - return { - converted: { - type: reader, - data: { - data: { - type: readers[index + 1], - data: obj - } - } - }, - traversed: index + 1 - }; + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); } - if (isExportReaderType(reader)) { - if (reader === 'Texture2D') { - extractedImages.push({ - path: path.join('.') - }); - return { - converted: { - type: reader, - data: { - format: obj.format - } - }, - traversed: index - }; - } + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } - if (reader === 'TBin') { - extractedMaps.push({ - path: path.join('.') - }); - } + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; - return { - converted: { - type: reader, - data: {} - }, - traversed: index + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index }; - } + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; - let data; - if (Array.isArray(obj)) data = [];else data = {}; - let traversed = index; - let first = true; - let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + let part0 = new Vec4(0.0); - for (let [key, value] of Object.entries(obj)) { - let newIndex; + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; - if (reader.startsWith("Dictionary")) { - if (getTypeInfo(reader).subtypes[1] === readers[index + 2]) newIndex = index + 2;else newIndex = index + 1; - } else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } - const { - converted, - traversed: nexter - } = recursiveConvert(obj[key], [...path, key], newIndex); - data[key] = converted; - if (isComplex) traversed = nexter;else if (first) { - traversed = nexter; - first = false; + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; } + + part0.addVector(this.pointsWeights[i]); } + } - return { - converted: { - type: reader, - data - }, - traversed - }; - }(raw, []); +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); return { - converted, - extractedImages, - extractedMaps + min, + max, + indices, + error }; } -function convertJsonContentsFromXnbNode(obj) { - if (!obj || typeof obj !== "object") return obj; +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; - if (typeof obj === "object" && obj.hasOwnProperty("data")) { - let { - type, - data - } = obj; - if (isPrimitiveReaderType(type)) return deepCopy(data); + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; - if (isExportReaderType(type)) { - data = deepCopy(data); - if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; - return data; + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; } + } - obj = deepCopy(data); + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; } - let newObj; + return codes; +} - if (Array.isArray(obj)) { - newObj = []; +function fitCodes(rgba, mask, codes, indices) { + let err = 0; - for (let item of obj) { - newObj.push(convertJsonContentsFromXnbNode(item)); + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; } - return newObj; - } + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; - if (!!obj && typeof obj === "object") { - newObj = {}; + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; - for (let [key, value] of Object.entries(obj)) { - newObj[key] = convertJsonContentsFromXnbNode(value); + if (dist < least) { + least = dist; + index = j; + } } - return newObj; + indices[i] = index; + err += least; } - return null; + return err; } -function toXnbNodeData(json) { - const toYamlJson = {}; - const { - compressed, - formatVersion, - hidef: hiDef, - target - } = json.header; - let readerData = deepCopy(json.readers); - toYamlJson.xnbData = { - target, - compressed: !!compressed, - hiDef, - readerData, - numSharedResources: 0 - }; - const rawContent = deepCopy(json.content); - let readersTypeList = readerData.map(_ref => { - let { - type - } = _ref; - return simplifyType(type); - }); +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } - if (readersTypeList[0] === 'SpriteFont') { - readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; - rawContent.verticalSpacing = rawContent.verticalLineSpacing; - delete rawContent.verticalLineSpacing; + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } } +} - const { - converted, - extractedImages, - extractedMaps - } = convertJsonContentsToXnbNode(rawContent, readersTypeList); - toYamlJson.content = converted; - if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; - if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; - return toYamlJson; +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; } -function fromXnbNodeData(json) { - const result = {}; - const { - compressed, - readerData, - hiDef: hidef, - target - } = json.xnbData; - result.header = { - target, - formatVersion: 5, - compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, - hidef - }; - result.readers = deepCopy(readerData); - result.content = convertJsonContentsFromXnbNode(json.content); +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} - if (simplifyType(result.readers[0].type) === 'SpriteFont') { - result.content.verticalLineSpacing = result.content.verticalSpacing; - delete result.content.verticalSpacing; +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; } return result; } -function searchElement(parent, element) { - if (!parent || typeof parent != 'object') return; - - if (parent.hasOwnProperty(element)) { - return { - parent, - value: parent[element] - }; - } +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); - for (let child of Object.values(parent)) { - if (!!child || typeof child == 'object') { - let found = searchElement(child, element); - if (found) return found; + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; } } - - return null; } -function extractFileName(fullname) { - let matcher = fullname.match(/(.*)\.([^\s.]+)$/); - if (matcher === null) return [fullname, null]; - return [matcher[1], matcher[2]]; +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } } -function getExtension(dataType) { - switch (dataType) { - case "JSON": - return "json"; - - case "yaml": - return "yaml"; +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; - case "Texture2D": - return "png"; + for (let i = 0; i < 2; i++) { + let value = 0; - case "Effect": - return "cso"; + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } - case 'TBin': - return "tbin"; + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } - case 'BmFont': - return "xml"; + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; } +} - return "bin"; +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } } -function getMimeType(dataType) { - switch (dataType) { - case "JSON": - return "application/json"; +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} - case "yaml": - return "text/plain"; +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} - case "Texture2D": - return "image/png"; +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} - case "Effect": - return "application/x-cso"; +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - case 'BmFont': - return "application/xml"; - } + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); - return "application/octet-stream"; -} + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } -function makeBlob(data, dataType) { - if (typeof Blob === "function") return { - data: new Blob([data], { - type: getMimeType(dataType) - }), - extension: getExtension(dataType) - }; + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); return { - data: data, - extension: getExtension(dataType) + block, + mask }; } -function exportContent(content) { - let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - let found = searchElement(content, "export"); +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; - if (found) { - const { - value - } = found; - let { - type: dataType, - data - } = value; + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); - if (dataType === "Texture2D") { - data = s(value.width, value.height, new Uint8Array(data)); - } + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} - return makeBlob(data, dataType); - } +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} - if (jsonContent) { - let contentJson = JSON.stringify(content, null, 4); - return makeBlob(contentJson, "JSON"); - } +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} - return null; +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); } -/** @api - * decompressed xnb object to real file blobs. - * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) - * @param {Object} config (yaml:export file as yaml, - * contentOnly:export content file only, - * fileName:exported files's name) (optional) - */ +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} -function exportFiles(xnbObject) { - let { - yaml: isYaml = false, - contentOnly = false, - fileName = null - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - if (isYaml && contentOnly) isYaml = false; - if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); - const blobs = []; - const { - content - } = xnbObject; - const contentBlob = exportContent(content, contentOnly); - if (contentBlob !== null) blobs.push(contentBlob); - if (contentOnly) return blobs; - const resultJSON = JSON.stringify(xnbObject, (key, value) => { - if (key === "export") { - if (typeof fileName == "string" && fileName !== "") { - return "".concat(fileName, ".").concat(getExtension(value.type)); - } +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; - return "".concat(value.type, ".").concat(getExtension(value.type)); + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; } - - return value; - }, 4); - let result = resultJSON; - if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); - blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); - return blobs; + } } -function resolveCompression(compressionString) { - let str = compressionString.toLowerCase(); - if (str === "none") return 0; - if (str === "lz4") return 0x40; - return null; -} +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; -async function readBlobasText(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; } -async function readBlobasArrayBuffer(blob) { - if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; } -async function readExternFiles(extension, files) { - if (extension === "png") { - const rawPng = await readBlobasArrayBuffer(files.png); - const png = r(new Uint8Array(rawPng)); - return { - type: "Texture2D", - data: png.data, - width: png.width, - height: png.height - }; +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } } - if (extension === "cso") { - const data = await readBlobasArrayBuffer(files.cso); + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + return { - type: "Effect", - data + format, + export: { + type: this.type, + data, + width, + height + } }; } - if (extension === "tbin") { - const data = await readBlobasArrayBuffer(files.tbin); - return { - type: "TBin", - data - }; + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); } - if (extension === "xml") { - const data = await readBlobasText(files.xml); - return { - type: "BmFont", - data - }; + isValueType() { + return false; } + } -async function resolveImports(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const { - compression = "default" - } = configs; - const jsonFile = files.json || files.yaml; - if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); - const rawText = await readBlobasText(jsonFile); - let jsonData = null; - if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); - let compressBits = resolveCompression(compression); - if (compressBits !== null) jsonData.header.compressed = compressBits; +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; - if (!jsonData.hasOwnProperty('content')) { - throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + default: + return false; + } } - const found = searchElement(jsonData.content, "export"); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } - if (found) { - const { - parent, - value - } = found; - const [, extension] = extractFileName(value); - parent.export = await readExternFiles(extension, files); + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); } - return jsonData; } -/** @api - * Asynchronously reads the file into binary and then unpacks the json data. - * XNB -> arrayBuffer -> XnbData - * @param {File / Buffer} file - * @return {XnbData} JSON data with headers - */ - -async function unpackToXnbData(file) { - if (typeof window !== "undefined") { - const [, extension] = extractFileName(file.name); +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; - if (extension !== "xnb") { - return new Error("Invalid XNB File!"); + default: + return false; } - - const buffer = await file.arrayBuffer(); - return bufferToXnb(buffer); } - return bufferToXnb(file.buffer); -} -/** @api - * Asynchronously reads the file into binary and then return content file. - * XNB -> arrayBuffer -> XnbData -> Content - * @param {File / Buffer} file - * @return {XnbContent} exported Content Object - */ + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } -function unpackToContent(file) { - return unpackToXnbData(file).then(xnbDataToContent); -} -/** @api - * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. - * XNB -> arrayBuffer -> XnbData -> Files - * @param {File / Buffer} file - * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) - * @return {Array} exported Files Blobs - */ + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } -function unpackToFiles(file) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - let { - yaml = false, - contentOnly = false, - fileName: name = null - } = configs; - if (typeof window !== "undefined" && name === null) name = file.name; - let [fileName] = extractFileName(name); + console.log("writing complitd!"); + } - const exporter = xnbObject => exportFiles(xnbObject, { - yaml, - contentOnly, - fileName - }); + isValueType() { + return false; + } - return unpackToXnbData(file).then(exporter); } -/** @api - * reads the buffer and then unpacks. - * arrayBuffer -> XnbData - * @param {ArrayBuffer} buffer - * @return {XnbData} the loaded XNB json - */ +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; -function bufferToXnb(buffer) { - const xnb = new XnbConverter(); - return xnb.load(buffer); -} -/** @api - * reads the buffer and then unpacks the contents. - * arrayBuffer -> XnbData -> Content - * @param {ArrayBuffer} buffer - * @return {XnbContent} exported Content Object - */ + default: + return false; + } + } + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } -function bufferToContents(buffer) { - const xnb = new XnbConverter(); - const xnbData = xnb.load(buffer); - return xnbDataToContent(xnbData); -} -/** @api - * remove header from the loaded XNB Object - * XnbData -> Content - * @param {XnbData} the loaded XNB object include headers - * @return {XnbContent} exported Content Object - */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + isValueType() { + return false; + } -function xnbDataToContent(loadedXnb) { - const { - content - } = loadedXnb; - const { - data, - extension - } = exportContent(content, true); - return new XnbContent(data, extension); } -/** @api - * reads the json and then unpacks the contents. - * @param {FileList/Array} to pack json data - * @return {Object/Object} packed XNB Array Buffer - */ - -function fileMapper(files) { - let returnMap = {}; +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; - for (let i = 0; i < files.length; i++) { - const file = files[i]; - let [fileName, extension] = extractFileName(file.name); - if (extension === null) continue; - if (returnMap[fileName] === undefined) returnMap[fileName] = {}; - const namedFileObj = returnMap[fileName]; - if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + default: + return false; + } } - return returnMap; -} -/** @api - * reads the json and then unpacks the contents. - * @param {json} to pack json data - * @return {ArrayBuffer} packed XNB Array Buffer - */ - + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } -function packJsonToBinary(json) { - const xnb = new XnbConverter(); - const buffer = xnb.convert(json); - return buffer; } -/** @api - * Asynchronously reads the file into binary and then pack xnb files. - * @param {FlieList} files - * @param {Object} configs(compression:default, none, LZ4, LZX / debug) - * @return {Array(Blobs)} - */ +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; -function pack(files) { - let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const groupedFiles = fileMapper(files); - let promises = []; + default: + return false; + } + } - for (let [fileName, filePack] of Object.entries(groupedFiles)) { - promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { - if (typeof Blob === "function") return { - name: fileName, - data: new Blob([buffer], { - type: "application/octet-stream" - }) - }; - return { - name: fileName, - data: new Uint8Array(buffer) - }; - })); + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; } - return __promise_allSettled(promises).then(blobArray => { - if (configs.debug === true) return blobArray; - return blobArray.filter(_ref => { - let { - status, - value - } = _ref; - return status === "fulfilled"; - }).map(_ref2 => { - let { - value - } = _ref2; - return value; - }); - }); } -export { XnbContent, XnbData, bufferToContents, bufferToXnb, pack, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; +const Readers = { + ArrayReader: ArrayReader, + BaseReader: BaseReader, + BmFontReader: BmFontReader, + BooleanReader: BooleanReader, + CharReader: CharReader, + DictionaryReader: DictionaryReader, + DoubleReader: DoubleReader, + EffectReader: EffectReader, + Int32Reader: Int32Reader, + ListReader: ListReader, + NullableReader: NullableReader, + RectangleReader: RectangleReader, + ReflectiveReader: ReflectiveReader, + SingleReader: SingleReader, + SpriteFontReader: SpriteFontReader, + StringReader: StringReader, + TBinReader: TBinReader, + Texture2DReader: Texture2DReader, + UInt32Reader: UInt32Reader, + Vector2Reader: Vector2Reader, + Vector3Reader: Vector3Reader, + Vector4Reader: Vector4Reader +}; +setReaders(Readers); + +export { Readers, XnbContent, XnbData, addReaders, bufferToContents, bufferToXnb, pack, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; diff --git a/src/App/BufferReader.js b/docs/js/libs/src/App/BufferReader.js similarity index 100% rename from src/App/BufferReader.js rename to docs/js/libs/src/App/BufferReader.js diff --git a/src/App/BufferWriter.js b/docs/js/libs/src/App/BufferWriter.js similarity index 100% rename from src/App/BufferWriter.js rename to docs/js/libs/src/App/BufferWriter.js diff --git a/src/App/Decompressor/LZXDecompressor.js b/docs/js/libs/src/App/Decompressor/LZXDecompressor.js similarity index 100% rename from src/App/Decompressor/LZXDecompressor.js rename to docs/js/libs/src/App/Decompressor/LZXDecompressor.js diff --git a/src/App/Decompressor/Lz4.js b/docs/js/libs/src/App/Decompressor/Lz4.js similarity index 100% rename from src/App/Decompressor/Lz4.js rename to docs/js/libs/src/App/Decompressor/Lz4.js diff --git a/src/App/Decompressor/Lzx.js b/docs/js/libs/src/App/Decompressor/Lzx.js similarity index 100% rename from src/App/Decompressor/Lzx.js rename to docs/js/libs/src/App/Decompressor/Lzx.js diff --git a/src/App/Decompressor/dxt.js b/docs/js/libs/src/App/Decompressor/dxt.js similarity index 100% rename from src/App/Decompressor/dxt.js rename to docs/js/libs/src/App/Decompressor/dxt.js diff --git a/src/App/Decompressor/dxt/alphaCompressor.js b/docs/js/libs/src/App/Decompressor/dxt/alphaCompressor.js similarity index 100% rename from src/App/Decompressor/dxt/alphaCompressor.js rename to docs/js/libs/src/App/Decompressor/dxt/alphaCompressor.js diff --git a/src/App/Decompressor/dxt/colorBlock.js b/docs/js/libs/src/App/Decompressor/dxt/colorBlock.js similarity index 100% rename from src/App/Decompressor/dxt/colorBlock.js rename to docs/js/libs/src/App/Decompressor/dxt/colorBlock.js diff --git a/src/App/Decompressor/dxt/colorFits.js b/docs/js/libs/src/App/Decompressor/dxt/colorFits.js similarity index 100% rename from src/App/Decompressor/dxt/colorFits.js rename to docs/js/libs/src/App/Decompressor/dxt/colorFits.js diff --git a/src/App/Decompressor/dxt/constant.js b/docs/js/libs/src/App/Decompressor/dxt/constant.js similarity index 100% rename from src/App/Decompressor/dxt/constant.js rename to docs/js/libs/src/App/Decompressor/dxt/constant.js diff --git a/src/App/Decompressor/dxt/decompressor.js b/docs/js/libs/src/App/Decompressor/dxt/decompressor.js similarity index 100% rename from src/App/Decompressor/dxt/decompressor.js rename to docs/js/libs/src/App/Decompressor/dxt/decompressor.js diff --git a/src/App/Decompressor/dxt/eigs.js b/docs/js/libs/src/App/Decompressor/dxt/eigs.js similarity index 100% rename from src/App/Decompressor/dxt/eigs.js rename to docs/js/libs/src/App/Decompressor/dxt/eigs.js diff --git a/src/App/Decompressor/dxt/lookup.js b/docs/js/libs/src/App/Decompressor/dxt/lookup.js similarity index 100% rename from src/App/Decompressor/dxt/lookup.js rename to docs/js/libs/src/App/Decompressor/dxt/lookup.js diff --git a/src/App/Decompressor/dxt/math.js b/docs/js/libs/src/App/Decompressor/dxt/math.js similarity index 100% rename from src/App/Decompressor/dxt/math.js rename to docs/js/libs/src/App/Decompressor/dxt/math.js diff --git a/src/App/Decompressor/lz4/utils.js b/docs/js/libs/src/App/Decompressor/lz4/utils.js similarity index 100% rename from src/App/Decompressor/lz4/utils.js rename to docs/js/libs/src/App/Decompressor/lz4/utils.js diff --git a/src/App/Decompressor/lz4/xxh32.js b/docs/js/libs/src/App/Decompressor/lz4/xxh32.js similarity index 100% rename from src/App/Decompressor/lz4/xxh32.js rename to docs/js/libs/src/App/Decompressor/lz4/xxh32.js diff --git a/src/App/ReaderResolver.js b/docs/js/libs/src/App/ReaderResolver.js similarity index 100% rename from src/App/ReaderResolver.js rename to docs/js/libs/src/App/ReaderResolver.js diff --git a/docs/js/libs/src/App/Readers/ArrayReader.js b/docs/js/libs/src/App/Readers/ArrayReader.js new file mode 100644 index 0000000..6c52d78 --- /dev/null +++ b/docs/js/libs/src/App/Readers/ArrayReader.js @@ -0,0 +1,87 @@ +import BaseReader from "./BaseReader.js"; +import BufferReader from "../BufferReader.js"; +import UInt32Reader from "./UInt32Reader.js"; + +/** + * Array Reader + * @class + * @extends BaseReader + */ +export default class ArrayReader extends BaseReader { + + /** + * Constructor for the ArrayReader + * @param {BaseReader} reader The reader used for the array elements + */ + constructor(reader) { + super(); + /** @type {BaseReader} */ + this.reader = reader; + } + + static checkTypeIs(rawReader) + { + switch(rawReader) + { + case 'Microsoft.Xna.Framework.Content.ArrayReader': return true; + default return false; + } + } + static hasSubType() + { + return true; + } + + /** + * Reads Array from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {Array} + */ + read(buffer, resolver) { + // create a uint32 reader + const uint32Reader = new UInt32Reader(); + // read the number of elements in the array + let size = uint32Reader.read(buffer); + // create local array + let array = []; + + // loop size number of times for the array elements + for (let i = 0; i < size; i++) { + // get value from buffer + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + // push into local array + array.push(value); + } + + // return the array + return array; + } + + /** + * Writes Array into buffer + * @param {BufferWriter} buffer + * @param {Array} data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + // write the index + this.writeIndex(buffer, resolver); + // create a uint32 reader + const uint32Reader = new UInt32Reader(); + // write the number of elements in the array + uint32Reader.write(buffer, content.length, resolver); + + // loop over array to write array contents + for (let i = 0; i < content.length; i++) + this.reader.write(buffer, content[i], (this.reader.isValueType() ? null : resolver)); + } + + isValueType() { + return false; + } + + get type() { + return `Array<${this.reader.type}>`; + } +} diff --git a/src/App/Readers/BaseReader.js b/docs/js/libs/src/App/Readers/BaseReader.js similarity index 94% rename from src/App/Readers/BaseReader.js rename to docs/js/libs/src/App/Readers/BaseReader.js index 0a896c6..8b160b0 100644 --- a/src/App/Readers/BaseReader.js +++ b/docs/js/libs/src/App/Readers/BaseReader.js @@ -9,6 +9,16 @@ import ReaderResolver from "../ReaderResolver.js"; * @class */ export default class BaseReader { + + static checkTypeIs(rawReader) + { + return false; + } + static hasSubType() + { + return false; + } + /** * Returns if type normally requires a special reader. * @public diff --git a/src/App/Readers/BmFontReader.js b/docs/js/libs/src/App/Readers/BmFontReader.js similarity index 86% rename from src/App/Readers/BmFontReader.js rename to docs/js/libs/src/App/Readers/BmFontReader.js index 996b67e..d1adce6 100644 --- a/src/App/Readers/BmFontReader.js +++ b/docs/js/libs/src/App/Readers/BmFontReader.js @@ -9,6 +9,15 @@ import StringReader from "./StringReader.js"; * @extends BaseReader */ export default class BmFontReader extends BaseReader { + static checkTypeIs(rawReader) + { + switch(rawReader) + { + case 'BmFont.XmlSourceReader': return true; + default return false; + } + } + /** * Reads BmFont from buffer. * @param {BufferReader} buffer diff --git a/src/App/Readers/BooleanReader.js b/docs/js/libs/src/App/Readers/BooleanReader.js similarity index 77% rename from src/App/Readers/BooleanReader.js rename to docs/js/libs/src/App/Readers/BooleanReader.js index 6279de9..4d58c6b 100644 --- a/src/App/Readers/BooleanReader.js +++ b/docs/js/libs/src/App/Readers/BooleanReader.js @@ -8,6 +8,16 @@ import BufferWriter from "../BufferWriter.js"; * @extends BaseReader */ export default class BooleanReader extends BaseReader { + static checkTypeIs(rawReader) + { + switch(rawReader) + { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': return true; + default return false; + } + } + /** * Reads Boolean from buffer. * @param {BufferReader} buffer diff --git a/src/App/Readers/CharReader.js b/docs/js/libs/src/App/Readers/CharReader.js similarity index 83% rename from src/App/Readers/CharReader.js rename to docs/js/libs/src/App/Readers/CharReader.js index 3f00d26..cfa5351 100644 --- a/src/App/Readers/CharReader.js +++ b/docs/js/libs/src/App/Readers/CharReader.js @@ -8,6 +8,16 @@ import BufferWriter from "../BufferWriter.js"; * @extends BaseReader */ export default class CharReader extends BaseReader { + static checkTypeIs(rawReader) + { + switch(rawReader) + { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': return true; + default return false; + } + } + /** * Reads Char from the buffer. * @param {BufferReader} buffer diff --git a/src/App/Readers/DictionaryReader.js b/docs/js/libs/src/App/Readers/DictionaryReader.js similarity index 92% rename from src/App/Readers/DictionaryReader.js rename to docs/js/libs/src/App/Readers/DictionaryReader.js index 17132dc..124ce13 100644 --- a/src/App/Readers/DictionaryReader.js +++ b/docs/js/libs/src/App/Readers/DictionaryReader.js @@ -11,6 +11,18 @@ import XnbError from "../../Utils/XnbError.js"; * @extends BaseReader */ export default class DictionaryReader extends BaseReader { + static checkTypeIs(rawReader) + { + switch(rawReader) + { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': return true; + default return false; + } + } + static hasSubType() + { + return true; + } /** * Constructor for DictionaryReader. diff --git a/src/App/Readers/DoubleReader.js b/docs/js/libs/src/App/Readers/DoubleReader.js similarity index 100% rename from src/App/Readers/DoubleReader.js rename to docs/js/libs/src/App/Readers/DoubleReader.js diff --git a/src/App/Readers/EffectReader.js b/docs/js/libs/src/App/Readers/EffectReader.js similarity index 100% rename from src/App/Readers/EffectReader.js rename to docs/js/libs/src/App/Readers/EffectReader.js diff --git a/src/App/Readers/Int32Reader.js b/docs/js/libs/src/App/Readers/Int32Reader.js similarity index 100% rename from src/App/Readers/Int32Reader.js rename to docs/js/libs/src/App/Readers/Int32Reader.js diff --git a/src/App/Readers/ListReader.js b/docs/js/libs/src/App/Readers/ListReader.js similarity index 100% rename from src/App/Readers/ListReader.js rename to docs/js/libs/src/App/Readers/ListReader.js diff --git a/src/App/Readers/NullableReader.js b/docs/js/libs/src/App/Readers/NullableReader.js similarity index 100% rename from src/App/Readers/NullableReader.js rename to docs/js/libs/src/App/Readers/NullableReader.js diff --git a/src/App/Readers/Readers.js b/docs/js/libs/src/App/Readers/Readers.js similarity index 100% rename from src/App/Readers/Readers.js rename to docs/js/libs/src/App/Readers/Readers.js diff --git a/src/App/Readers/RectangleReader.js b/docs/js/libs/src/App/Readers/RectangleReader.js similarity index 100% rename from src/App/Readers/RectangleReader.js rename to docs/js/libs/src/App/Readers/RectangleReader.js diff --git a/src/App/Readers/ReflectiveReader.js b/docs/js/libs/src/App/Readers/ReflectiveReader.js similarity index 100% rename from src/App/Readers/ReflectiveReader.js rename to docs/js/libs/src/App/Readers/ReflectiveReader.js diff --git a/src/App/Readers/SingleReader.js b/docs/js/libs/src/App/Readers/SingleReader.js similarity index 100% rename from src/App/Readers/SingleReader.js rename to docs/js/libs/src/App/Readers/SingleReader.js diff --git a/src/App/Readers/SpriteFontReader.js b/docs/js/libs/src/App/Readers/SpriteFontReader.js similarity index 100% rename from src/App/Readers/SpriteFontReader.js rename to docs/js/libs/src/App/Readers/SpriteFontReader.js diff --git a/src/App/Readers/StringReader.js b/docs/js/libs/src/App/Readers/StringReader.js similarity index 100% rename from src/App/Readers/StringReader.js rename to docs/js/libs/src/App/Readers/StringReader.js diff --git a/src/App/Readers/TBinReader.js b/docs/js/libs/src/App/Readers/TBinReader.js similarity index 100% rename from src/App/Readers/TBinReader.js rename to docs/js/libs/src/App/Readers/TBinReader.js diff --git a/src/App/Readers/Texture2DReader.js b/docs/js/libs/src/App/Readers/Texture2DReader.js similarity index 100% rename from src/App/Readers/Texture2DReader.js rename to docs/js/libs/src/App/Readers/Texture2DReader.js diff --git a/src/App/Readers/UInt32Reader.js b/docs/js/libs/src/App/Readers/UInt32Reader.js similarity index 100% rename from src/App/Readers/UInt32Reader.js rename to docs/js/libs/src/App/Readers/UInt32Reader.js diff --git a/src/App/Readers/Vector2Reader.js b/docs/js/libs/src/App/Readers/Vector2Reader.js similarity index 100% rename from src/App/Readers/Vector2Reader.js rename to docs/js/libs/src/App/Readers/Vector2Reader.js diff --git a/src/App/Readers/Vector3Reader.js b/docs/js/libs/src/App/Readers/Vector3Reader.js similarity index 100% rename from src/App/Readers/Vector3Reader.js rename to docs/js/libs/src/App/Readers/Vector3Reader.js diff --git a/src/App/Readers/Vector4Reader.js b/docs/js/libs/src/App/Readers/Vector4Reader.js similarity index 100% rename from src/App/Readers/Vector4Reader.js rename to docs/js/libs/src/App/Readers/Vector4Reader.js diff --git a/src/App/TypeReader.js b/docs/js/libs/src/App/TypeReader.js similarity index 100% rename from src/App/TypeReader.js rename to docs/js/libs/src/App/TypeReader.js diff --git a/src/App/Xnb.js b/docs/js/libs/src/App/Xnb.js similarity index 99% rename from src/App/Xnb.js rename to docs/js/libs/src/App/Xnb.js index 3e14c26..aea13f6 100644 --- a/src/App/Xnb.js +++ b/docs/js/libs/src/App/Xnb.js @@ -141,6 +141,8 @@ class XnbConverter { // a local copy of readers for the export const readers = []; + + console.log(this.buffer); // loop over the number of readers we have for (let i = 0; i < count; i++) { diff --git a/src/App/XnbData.js b/docs/js/libs/src/App/XnbData.js similarity index 100% rename from src/App/XnbData.js rename to docs/js/libs/src/App/XnbData.js diff --git a/src/Files.js b/docs/js/libs/src/Files.js similarity index 100% rename from src/Files.js rename to docs/js/libs/src/Files.js diff --git a/src/Utils/Debug.js b/docs/js/libs/src/Utils/Debug.js similarity index 100% rename from src/Utils/Debug.js rename to docs/js/libs/src/Utils/Debug.js diff --git a/src/Utils/UTF8ToString.js b/docs/js/libs/src/Utils/UTF8ToString.js similarity index 100% rename from src/Utils/UTF8ToString.js rename to docs/js/libs/src/Utils/UTF8ToString.js diff --git a/src/Utils/XnbError.js b/docs/js/libs/src/Utils/XnbError.js similarity index 100% rename from src/Utils/XnbError.js rename to docs/js/libs/src/Utils/XnbError.js diff --git a/src/Utils/xnbNodeConverter.js b/docs/js/libs/src/Utils/xnbNodeConverter.js similarity index 100% rename from src/Utils/xnbNodeConverter.js rename to docs/js/libs/src/Utils/xnbNodeConverter.js diff --git a/src/XnbUnpacker.js b/docs/js/libs/src/XnbUnpacker.js similarity index 95% rename from src/XnbUnpacker.js rename to docs/js/libs/src/XnbUnpacker.js index b563403..997d8fe 100644 --- a/src/XnbUnpacker.js +++ b/docs/js/libs/src/XnbUnpacker.js @@ -2,6 +2,7 @@ import XnbConverter from "./App/Xnb.js"; import {XnbData, XnbContent} from "./App/XnbData.js"; import {exportFiles, exportContent, resolveImports, extractFileName} from "./Files.js"; +const xnb = new XnbConverterMaker(); /*----------------------------------------------------------------------------*/ /*................................Unpack XNB..................................*/ @@ -177,6 +178,10 @@ function pack(files, configs={}) }); } +/*----------------------------------------------------------------------------*/ +/*.........................Additional Reader Plugin...........................*/ +/*----------------------------------------------------------------------------*/ + export {unpackToXnbData, unpackToContent, unpackToFiles, diff --git a/docs/js/libs/src/es5.js b/docs/js/libs/src/es5.js new file mode 100644 index 0000000..08c2d94 --- /dev/null +++ b/docs/js/libs/src/es5.js @@ -0,0 +1,7 @@ +import "core-js/modules/es.promise.js"; +import "regenerator-runtime/runtime.js"; +import "core-js/modules/es.object.get-own-property-descriptors.js"; +import "core-js/modules/es.function.name.js"; +import "core-js/modules/es.typed-array.map.js"; + +export * from "./XnbUnpacker.js"; \ No newline at end of file diff --git a/src/libs/jsonToYaml.js b/docs/js/libs/src/libs/jsonToYaml.js similarity index 100% rename from src/libs/jsonToYaml.js rename to docs/js/libs/src/libs/jsonToYaml.js diff --git a/src/libs/png.js b/docs/js/libs/src/libs/png.js similarity index 100% rename from src/libs/png.js rename to docs/js/libs/src/libs/png.js diff --git a/docs/js/libs/unpackWorker.js b/docs/js/libs/unpackWorker.js index aa0dabe..58063f2 100644 --- a/docs/js/libs/unpackWorker.js +++ b/docs/js/libs/unpackWorker.js @@ -1,4 +1,4 @@ -import {bufferToXnb} from "./xnb.module.js"; +import {bufferToXnb} from "./src/xnbUnpacker.js"; onmessage = function(e) { console.log(e.data); diff --git a/package.json b/package.json index 12b94c9..8d8b946 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xnb", - "version": "1.0.5", + "version": "1.1.0", "description": "Javascript XNB packing & unpacking library for es6.", "main": "./dist/xnb.js", "module": "./dist/xnb.module.js", @@ -15,7 +15,10 @@ "api.md" ], "scripts": { - "build": "rollup -c builder/rollup.config.js" + "build": "rollup -c builder/rollup.config.js", + "build-core": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:1", + "build-readers": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:2", + "build-stardew": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:3" }, "keywords": [ "xnb", diff --git a/readme.md b/readme.md index a2b32be..f319b99 100644 --- a/readme.md +++ b/readme.md @@ -87,6 +87,66 @@ readFile("./Abigail.xnb") // read xnb file as Buffer ## API See this [link](https://github.com/lybell-art/xnb-js/blob/main/api.md). +## Customs +After 1.1 update, you can load and use only a portion of the existing readers, or you can add a custom reader to use it. + +### Load only part of existing readers +```js +import * as XNB from "@xnb/core"; +import { LightweightTexture2DReader as Texture2DReader } from "@xnb/readers"; + +XNB.setReaders({Texture2DReader}); + +xnb.unpackToXnbData(file); +``` + +### Add custom plugins +```js +import * as XNB from "xnb"; + +// Your class must inherit the basereader, and the class name must end with "Reader". +class CustomReader extends XNB.readers.BaseReader{ + static isTypeOf(type) { + // The name of the reader or data type used in the XNA game studio. + // Returns true or false if you want the name to be read from this reader. + } + static hasSubType() { + // Returns if the data type this reader will read has sub-types. + // For example, array, list, and dictionary have sub-types. + } + static parseTypeList() { + // Used to insert type data in the process of converting a json file to a yaml file. + // Return the array in the order in which the sub-readers are actually used. + } + static type() + { + // Simplified data type. In default, returns the first part except Reader. + // If the class name differs from the actual simplified data type name, it should returns that of actual. + } + isValueType() { + // Returns true if the data type is primitive data type. + } + get type() { + // Returns string type of reader. + } + read(buffer, resolver) { + // Reads the buffer by the specification of the type reader. + } + write(buffer, content, resolver) { + // Writes into the buffer. + } + parseTypeList() { + // for have sub-types readers + // Used to insert type data in the process of converting a json file to a yaml file. + // Return the array in the order in which the sub-readers are actually used. + } +} + +XNB.addReaders({CustomReader}); + +... +``` + ## External resource xnb.js contains dxt.js, lz4.js, and png.js as bundle. libsquish(=dxt.js) and lz4.js were rewritten for es6 module system. The licenses for the original libraries are as follows. diff --git a/src/core/App/BufferReader.js b/src/core/App/BufferReader.js new file mode 100644 index 0000000..cca9e6a --- /dev/null +++ b/src/core/App/BufferReader.js @@ -0,0 +1,556 @@ +import {UTF8ToString} from "../utils/UTF8ToString.js"; + +const LITTLE_ENDIAN = true; +const BIG_ENDIAN = false; + +class BufferReader { + + /** + * Creates instance of Reader class. + * @constructor + * @param {ArrayBuffer} target buffer to trace + */ + constructor(buffer, endianus = LITTLE_ENDIAN) { + /** + * Sets the endianness of the buffer stream + * @private + * @type {Number} + */ + this._endianus = endianus; + + /** + * internal buffer for the reader + * @private + * @type {ArrayBuffer} + */ + this._buffer = buffer.slice(); + + /** + * internal buffer for the reader + * @private + * @type {DataView} + */ + this._dataView = new DataView(this._buffer); + + /** + * Seek index for the internal buffer. + * @private + * @type {Number} + */ + this._offset = 0; + + /** + * Bit offset for bit reading. + * @private + * @type {Number} + */ + this._bitOffset = 0; + } + + /** + * Seeks to a specific index in the buffer. + * @public + * @param {Number} index Sets the buffer seek index. + * @param {Number} origin Location to seek from + */ + seek(index, origin = this._offset) { + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) + throw new RangeError(`Buffer seek out of bounds! ${this._offset} ${this.buffer.length}`); + return this._offset - offset; + } + + /** + * Gets the seek index of the buffer. + * @public + * @property bytePosition + * @return {Number} Reurns the buffer seek index. + */ + get bytePosition() { + return Number.parseInt(this._offset); + } + + /** + * Sets the seek index of the buffer. + * @public + * @property bytePosition + * @param {Number} value + */ + set bytePosition(value) { + this._offset = value; + } + + /** + * Gets the current position for bit reading. + * @public + * @property _bitPosition + * @returns {Number} + */ + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + /** + * Sets the bit position clamped at 16-bit frames + * @public + * @property bitPosition + * @param {Number} offset + */ + set bitPosition(offset) { + // when rewinding, reset it back to + if (offset < 0) offset = 16 - offset; + // set the offset and clamp to 16-bit frame + this._bitOffset = offset % 16; + // get byte seek for bit ranges that wrap past 16-bit frames + const byteSeek = ((offset - (Math.abs(offset) % 16)) / 16) * 2; + // seek ahead for overflow on 16-bit frames + this.seek(byteSeek); + } + + /** + * Get the buffer size. + * @public + * @property size + * @return {Number} Returns the size of the buffer. + */ + get size() { + return this.buffer.byteLength; + } + + /** + * Returns the buffer. + * @public + * @property buffer + * @returns {Buffer} Returns the internal buffer. + */ + get buffer() { + return this._buffer; + } + + /** + * Writes another buffer into this buffer. + * @public + * @method write + * @param {Buffer} buffer + * @param {Number} targetIndex + * @param {Number} sourceIndex + * @param {Number} length + */ + + copyFrom(buffer, targetIndex = 0, sourceIndex = 0, length = buffer.byteLength) { + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + + let targetBuffer = this.buffer; + let targetView = this._dataView; + + // we need to resize the buffer to fit the contents + if (isOverflow) { + // create a temporary buffer of the new size + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + // copy our buffer into the temp buffer + for(let i=0; i 0) { + // peek in a 16-bit value + const peek = this._dataView.getUint16(this._offset, true); + + // clamp bits into the 16-bit frame we have left only read in as much as we have left + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + // set the offset based on current position in and bit count + const offset = 16 - this.bitPosition - bitsInFrame; + + // create mask and shift the mask up to the offset << + // and then shift the return back down into mask space >> + const value = (peek & (2 ** bitsInFrame - 1 << offset)) >> offset; + + // remove the bits we read from what we have left + bitsLeft -= bitsInFrame; + // add the bits read to the bit position + this.bitPosition += bitsInFrame; + + // assign read with the value shifted over for reading in loops + read |= value << bitsLeft; + } + + // return the read bits + return read; + } + + /** + * Used to peek bits. + * @public + * @method peekLZXBits + * @param {Number} bits + * @returns {Number} + */ + peekLZXBits(bits) { + // get the current bit position to store + let bitPosition = this.bitPosition; + // get the current byte position to store + let bytePosition = this.bytePosition; + + // read the bits like normal + const read = this.readLZXBits(bits); + + // just rewind the bit position, this will also rewind bytes where needed + this.bitPosition = bitPosition; + // restore the byte position + this.bytePosition = bytePosition; + + // return the peeked value + return read; + } + + /** + * Reads a 16-bit integer from a LZX bitstream + * + * bytes are reverse as the bitstream sequences 16 bit integers stored as LSB -> MSB (bytes) + * abc[...]xyzABCDEF as bits would be stored as: + * [ijklmnop][abcdefgh][yzABCDEF][qrstuvwx] + * + * @public + * @method readLZXInt16 + * @param {Boolean} seek + * @returns {Number} + */ + readLZXInt16(seek = true) { + // read in the next two bytes worth of data + const lsB = this.readByte(); + const msB = this.readByte(); + + // rewind the seek head + if (!seek) + this.seek(-2); + + // set the value + return (lsB << 8) | msB; + } + + /** + * Aligns to 16-bit offset. + * @public + * @method align + */ + align() { + if (this.bitPosition > 0) + this.bitPosition += 16 - this.bitPosition; + } +} + +// export the BufferReader class +export default BufferReader; diff --git a/src/core/App/BufferWriter.js b/src/core/App/BufferWriter.js new file mode 100644 index 0000000..5453e12 --- /dev/null +++ b/src/core/App/BufferWriter.js @@ -0,0 +1,208 @@ +import {stringToUTF8} from "../utils/UTF8ToString.js"; +const PENDING = true; + +class BufferWriter { + + constructor(size = 2048) { + /** + * internal buffer for the writer + * @private + * @type {ArrayBuffer} + */ + this._buffer = new ArrayBuffer(size); + /** + * internal buffer for the reader + * @private + * @type {DataView} + */ + this._dataView = new DataView(this._buffer); + + /** + * Seek index for the internal buffer. + * @private + * @type {Number} + */ + this.bytePosition = 0; + } + + /** + * Returns the buffer. + * @public + * @property buffer + * @returns {Buffer} Returns the internal buffer. + */ + get buffer() { + return this._buffer; + } + + //Reconnect the DataView to the current ArrayBuffer + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + // trim the buffer to the byte position + trim(pending = false) { + this._buffer = this.buffer.slice(0,this.bytePosition); + if(!pending) this.reconnectDataView(); + } + + /** + * Allocates number of bytes into the buffer and assigns more space if needed + * @param {Number} bytes Number of bytes to allocate into the buffer + */ + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for(let i=0; i> 7; + if (number) byte |= 0x80; + this._dataView.setUint8(this.bytePosition, byte); + this.bytePosition++; + } + while (number); + } + +} + +// export the BufferWriter class +export default BufferWriter; diff --git a/src/core/App/Decompressor/LZXDecompressor.js b/src/core/App/Decompressor/LZXDecompressor.js new file mode 100644 index 0000000..784929c --- /dev/null +++ b/src/core/App/Decompressor/LZXDecompressor.js @@ -0,0 +1,88 @@ +import Lzx from "./Lzx.js"; +import BufferReader from "../BufferReader.js"; +import BufferWriter from "../BufferWriter.js"; + +import Debug from "../../Utils/Debug.js"; +import XnbError from "../../Utils/XnbError.js"; + +/** + * Used to compress and decompress LZX. + * @class + * @public + */ +class Presser { + + /** + * Decompress a certain amount of bytes. + * @public + * @static + * @param {BufferReader} buffer + * @returns {Buffer} + */ + static decompress(buffer, compressedTodo, decompressedTodo) { + // current index into the buffer + let pos = 0; + + // allocate variables for block and frame size + let block_size; + let frame_size; + + // create the LZX instance with 16-bit window frame + const lzx = new Lzx(16); + + // the full decompressed array + let decompressed = new BufferWriter(decompressedTodo); + let z = 0; + + // loop over the bytes left + while (pos < compressedTodo) { + // flag is for determining if frame_size is fixed or not + const flag = buffer.readByte(); + + // if flag is set to 0xFF that means we will read in frame size + if (flag == 0xFF) { + // read in the frame size + frame_size = buffer.readLZXInt16(); + // read in the block size + block_size = buffer.readLZXInt16(); + // advance the byte position forward + pos += 5; + } + else { + // rewind the buffer + buffer.seek(-1); + // read in the block size + block_size = buffer.readLZXInt16(this.buffer); + // set the frame size + frame_size = 0x8000; + // advance byte position forward + pos += 2; + } + + // ensure the block and frame size aren't empty + if (block_size == 0 || frame_size == 0) + break; + + // ensure the block and frame size don't exceed size of integers + if (block_size > 0x10000 || frame_size > 0x10000) + throw new XnbError('Invalid size read in compression content.'); + + Debug(`Block Size: ${block_size}, Frame Size: ${frame_size}`); + + // decompress the file based on frame and block size + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + + // increase position counter + pos += block_size; + } + + // we have finished decompressing the file + console.log('File has been successfully decompressed!'); + + // return a decompressed buffer + decompressed.trim(); + return decompressed.buffer; + } +} + +export default Presser; \ No newline at end of file diff --git a/src/core/App/Decompressor/Lz4.js b/src/core/App/Decompressor/Lz4.js new file mode 100644 index 0000000..8fb0a68 --- /dev/null +++ b/src/core/App/Decompressor/Lz4.js @@ -0,0 +1,574 @@ +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ + +// lz4.js - An implementation of Lz4 in plain JavaScript. + +import xxh_hash from './lz4/xxh32.js'; +import util from './lz4/utils.js'; + +// Constants +// -- + +// Compression format parameters/constants. +const minMatch = 4; +const minLength = 13; +const searchLimit = 5; +const skipTrigger = 6; +const hashSize = 1 << 16; + +// Token constants. +const mlBits = 4; +const mlMask = (1 << mlBits) - 1; +const runBits = 4; +const runMask = (1 << runBits) - 1; + +// Shared buffers +const blockBuf = makeBuffer(5 << 20); +const hashTable = makeHashTable(); + +// Frame constants. +const magicNum = 0x184D2204; + +// Frame descriptor flags. +const fdContentChksum = 0x4; +const fdContentSize = 0x8; +const fdBlockChksum = 0x10; +// const fdBlockIndep = 0x20; +const fdVersion = 0x40; +const fdVersionMask = 0xC0; + +// Block sizes. +const bsUncompressed = 0x80000000; +const bsDefault = 7; +const bsShift = 4; +const bsMask = 7; +const bsMap = { + 4: 0x10000, + 5: 0x40000, + 6: 0x100000, + 7: 0x400000 +}; + +// Utility functions/primitives +// -- + +// Makes our hashtable. On older browsers, may return a plain array. +function makeHashTable () { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } +} + +// Clear hashtable. +function clearHashTable (table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } +} + +// Makes a byte buffer. On older browsers, may return a plain array. +function makeBuffer (size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } +} + +function sliceArray (array, start, end) { + if (typeof array.buffer !== undefined) { + if (Uint8Array.prototype.slice) { + return array.slice(start, end); + } else { + // Uint8Array#slice polyfill. + var len = array.length; + + // Calculate start. + start = start | 0; + start = (start < 0) ? Math.max(len + start, 0) : Math.min(start, len); + + // Calculate end. + end = (end === undefined) ? len : end | 0; + end = (end < 0) ? Math.max(len + end, 0) : Math.min(end, len); + + // Copy into new array. + var arraySlice = new Uint8Array(end - start); + for (var i = start, n = 0; i < end;) { + arraySlice[n++] = array[i++]; + } + + return arraySlice; + } + } else { + // Assume normal array. + return array.slice(start, end); + } +} + +// Implementation +// -- + +// Calculates an upper bound for lz4 compression. +function compressBound (n) { + return (n + (n / 255) + 16) | 0; +}; + +// Calculates an upper bound for lz4 decompression, by reading the data. +function decompressBound (src) { + var sIndex = 0; + + // Read magic number + if (util.readU32(src, sIndex) !== magicNum) { + throw new Error('invalid magic number'); + } + + sIndex += 4; + + // Read descriptor + var descriptor = src[sIndex++]; + + // Check version + if ((descriptor & fdVersionMask) !== fdVersion) { + throw new Error('incompatible descriptor version ' + (descriptor & fdVersionMask)); + } + + // Read flags + var useBlockSum = (descriptor & fdBlockChksum) !== 0; + var useContentSize = (descriptor & fdContentSize) !== 0; + + // Read block size + var bsIdx = (src[sIndex++] >> bsShift) & bsMask; + + if (bsMap[bsIdx] === undefined) { + throw new Error('invalid block size ' + bsIdx); + } + + var maxBlockSize = bsMap[bsIdx]; + + // Get content size + if (useContentSize) { + return util.readU64(src, sIndex); + } + + // Checksum + sIndex++; + + // Read blocks. + var maxSize = 0; + while (true) { + var blockSize = util.readU32(src, sIndex); + sIndex += 4; + + if (blockSize & bsUncompressed) { + blockSize &= ~bsUncompressed; + maxSize += blockSize; + } else if (blockSize > 0) { + maxSize += maxBlockSize; + } + + if (blockSize === 0) { + return maxSize; + } + + if (useBlockSum) { + sIndex += 4; + } + + sIndex += blockSize; + } +}; + +// Decompresses a block of Lz4. +function decompressBlock (src, dst, sIndex=0, sLength=src.length-2*sIndex, dIndex=0) { + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + + // Setup initial state. + sEnd = sIndex + sLength; + + // Consume entire input block. + while (sIndex < sEnd) { + var token = src[sIndex++]; + + // Copy literals. + var literalCount = (token >> 4); + if (literalCount > 0) { + // Parse length. + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + // Copy literals + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + // Copy match. + mLength = (token & 0xf); + + // Parse offset. + mOffset = src[sIndex++] | (src[sIndex++] << 8); + + // Parse length. + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + // Copy match + // prefer to use typedarray.copyWithin for larger matches + // NOTE: copyWithin doesn't work as required by LZ4 for overlapping sequences + // e.g. mOffset=1, mLength=30 (repeach char 30 times) + // we special case the repeat char w/ array.fill + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; +}; + +// Compresses a block with Lz4. +function compressBlock (src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + + // Setup initial state. + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + // Process only if block is large enough. + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + // Consume until last n literals (Lz4 spec limitation.) + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = util.readU32(src, sIndex); + var hash = util.hashU32(seq) >>> 0; + + // Crush hash to 16 bits. + hash = ((hash >> 16) ^ hash) >>> 0 & 0xffff; + + // Look for a match in the hashtable. NOTE: remove one; see below. + mIndex = hashTable[hash] - 1; + + // Put pos in hash table. NOTE: add one so that zero = invalid. + hashTable[hash] = sIndex + 1; + + // Determine if there is a match (within range.) + if (mIndex < 0 || ((sIndex - mIndex) >>> 16) > 0 || util.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + + // Calculate literal count and offset. + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + + // We've already matched one word, so get that out of the way. + sIndex += minMatch; + mIndex += minMatch; + + // Determine match length. + // N.B.: mLength does not include minMatch, Lz4 adds it back + // in decoding. + mLength = sIndex; + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + mLength = sIndex - mLength; + + // Write token + literal count. + var token = mLength < mlMask ? mLength : mlMask; + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + // Write literals. + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + // Write offset. + dst[dIndex++] = mOffset; + dst[dIndex++] = (mOffset >> 8); + + // Write match length. + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + dst[dIndex++] = n; + } + + // Move the anchor. + mAnchor = sIndex; + } + } + + // Nothing was encoded. + if (mAnchor === 0) { + return 0; + } + + // Write remaining literals. + // Write literal token+count. + literalCount = sEnd - mAnchor; + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits); + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits); + } + + // Write literals. + sIndex = mAnchor; + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; +}; + +function compressSingleBlock (src, dst) { + // Clear the hashtable. + clearHashTable(hashTable); + + return compressBlock(src, dst, 0, src.length, hashTable); +} + +// Decompresses a frame of Lz4 data. +function decompressFrame (src, dst) { + var useBlockSum, useContentSum, useContentSize, descriptor; + var sIndex = 0; + var dIndex = 0; + + // Read magic number + if (util.readU32(src, sIndex) !== magicNum) { + throw new Error('invalid magic number'); + } + + sIndex += 4; + + // Read descriptor + descriptor = src[sIndex++]; + + // Check version + if ((descriptor & fdVersionMask) !== fdVersion) { + throw new Error('incompatible descriptor version'); + } + + // Read flags + useBlockSum = (descriptor & fdBlockChksum) !== 0; + useContentSum = (descriptor & fdContentChksum) !== 0; + useContentSize = (descriptor & fdContentSize) !== 0; + + // Read block size + var bsIdx = (src[sIndex++] >> bsShift) & bsMask; + + if (bsMap[bsIdx] === undefined) { + throw new Error('invalid block size'); + } + + if (useContentSize) { + // TODO: read content size + sIndex += 8; + } + + sIndex++; + + // Read blocks. + while (true) { + var compSize; + + compSize = util.readU32(src, sIndex); + sIndex += 4; + + if (compSize === 0) { + break; + } + + if (useBlockSum) { + // TODO: read block checksum + sIndex += 4; + } + + // Check if block is compressed + if ((compSize & bsUncompressed) !== 0) { + // Mask off the 'uncompressed' bit + compSize &= ~bsUncompressed; + + // Copy uncompressed data into destination buffer. + for (var j = 0; j < compSize; j++) { + dst[dIndex++] = src[sIndex++]; + } + } else { + // Decompress into blockBuf + dIndex = decompressBlock(src, dst, sIndex, compSize, dIndex); + sIndex += compSize; + } + } + + if (useContentSum) { + // TODO: read content checksum + sIndex += 4; + } + + return dIndex; +}; + +// Compresses data to an Lz4 frame. +function compressFrame (src, dst) { + var dIndex = 0; + + // Write magic number. + util.writeU32(dst, dIndex, magicNum); + dIndex += 4; + + // Descriptor flags. + dst[dIndex++] = fdVersion; + dst[dIndex++] = bsDefault << bsShift; + + // Descriptor checksum. + dst[dIndex] = xxh_hash(0, dst, 4, dIndex - 4) >> 8; + dIndex++; + + // Write blocks. + var maxBlockSize = bsMap[bsDefault]; + var remaining = src.length; + var sIndex = 0; + + // Clear the hashtable. + clearHashTable(hashTable); + + // Split input into blocks and write. + while (remaining > 0) { + var compSize = 0; + var blockSize = remaining > maxBlockSize ? maxBlockSize : remaining; + + compSize = compressBlock(src, blockBuf, sIndex, blockSize, hashTable); + + if (compSize > blockSize || compSize === 0) { + // Output uncompressed. + util.writeU32(dst, dIndex, 0x80000000 | blockSize); + dIndex += 4; + + for (var z = sIndex + blockSize; sIndex < z;) { + dst[dIndex++] = src[sIndex++]; + } + + remaining -= blockSize; + } else { + // Output compressed. + util.writeU32(dst, dIndex, compSize); + dIndex += 4; + + for (var j = 0; j < compSize;) { + dst[dIndex++] = blockBuf[j++]; + } + + sIndex += blockSize; + remaining -= blockSize; + } + } + + // Write blank end block. + util.writeU32(dst, dIndex, 0); + dIndex += 4; + + return dIndex; +}; + +// Decompresses a buffer containing an Lz4 frame. maxSize is optional; if not +// provided, a maximum size will be determined by examining the data. The +// buffer returned will always be perfectly-sized. +function decompress (src, maxSize) { + var dst, size; + + if (maxSize === undefined) { + maxSize = decompressBound(src); + } + dst = makeBuffer(maxSize); + size = decompressFrame(src, dst); + + if (size !== maxSize) { + dst = sliceArray(dst, 0, size); + } + + return dst; +}; + +// Compresses a buffer to an Lz4 frame. maxSize is optional; if not provided, +// a buffer will be created based on the theoretical worst output size for a +// given input size. The buffer returned will always be perfectly-sized. +function compress (src, maxSize) { + var dst, size; + + if (maxSize === undefined) { + maxSize = compressBound(src.length); + } + + dst = makeBuffer(maxSize); + size = compressFrame(src, dst); + + if (size !== maxSize) { + dst = sliceArray(dst, 0, size); + } + + return dst; +}; + +export {makeBuffer, compressBound, decompressBound, decompressBlock, compressBlock, compressSingleBlock, decompressFrame, compressFrame, decompress, compress}; \ No newline at end of file diff --git a/src/core/App/Decompressor/Lzx.js b/src/core/App/Decompressor/Lzx.js new file mode 100644 index 0000000..69b8c9f --- /dev/null +++ b/src/core/App/Decompressor/Lzx.js @@ -0,0 +1,763 @@ +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ + +import BufferReader from "../BufferReader.js"; +import Debug from "../../Utils/Debug.js"; +import XnbError from "../../Utils/XnbError.js"; + + +// LZX Constants +const MIN_MATCH = 2; // smallest allowable match length +const MAX_MATCH = 257; // largest allowable match length +const NUM_CHARS = 256; // number of uncompressed character types +const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 +}; +const PRETREE_NUM_ELEMENTS = 20; +const ALIGNED_NUM_ELEMENTS = 8; // aligned offset tree elements +const NUM_PRIMARY_LENGTHS = 7; +const NUM_SECONDARY_LENGTHS = 249; // number of elements in length tree + +// LZX Huffman Constants +const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; +const PRETREE_TABLEBITS = 6; +const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; +const MAINTREE_TABLEBITS = 12; +const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; +const LENGTH_TABLEBITS = 12; +const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; +const ALIGNED_TABLEBITS = 7; +const LENTABLE_SAFETY = 64; // table decoding overruns are allowed + +/** + * LZX Static Data Tables + * + * LZX uses 'position slots' to represent match offsets. For every match, + * a small 'position slot' number and a small offset from that slot are + * encoded instead of one large offset. + * + * Lzx.position_base[] is an index to the position slot bases + * + * Lzx.extra_bits[] states how many bits of offset-from-base data is needed. + */ + +/** + * Used to compress and decompress LZX format buffer. + * @class + * @public + */ +class Lzx { + + /** + * Creates an instance of LZX with a given window frame. + * @constructor + * @param {Number} window_bits + */ + constructor(window_bits) { + // get the window size from window bits + this.window_size = 1 << window_bits; + + // LZX supports window sizes of 2^15 (32 KB) to 2^21 (2 MB) + if (window_bits < 15 || window_bits > 21) + throw new XnbError('Window size out of range!'); + + // initialize static tables + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) + j++; + } + } + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + Debug(`Extra Bits:`); + Debug(JSON.stringify(Lzx.extra_bits)); + Debug(`Position Base:`); + Debug(JSON.stringify(Lzx.position_base)); + + /** + * calculate required position slots + * + * window bits: 15 16 17 18 19 20 21 + * position slots: 30 32 34 36 38 42 50 + */ + const posn_slots = (window_bits == 21 ? 50 : (window_bits == 20 ? 42 : window_bits << 1)); + + // repeated offsets + this.R0 = this.R1 = this.R2 = 1; + // set the number of main elements + this.main_elements = NUM_CHARS + (posn_slots << 3); + // state of header being read used for when looping over multiple blocks + this.header_read = false; + // set the block remaining + this.block_remaining = 0; + // set the default block type + this.block_type = BLOCKTYPE.INVALID; + // window position + this.window_posn = 0; + + // frequently used tables + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + // initialize main tree and length tree for use with delta operations + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) + this.maintree_len[i] = 0; + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) + this.length_len[i] = 0; + + // the decompression window + this.win = []; + } + + /** + * Decompress the buffer with given frame and block size + * @param {BufferReader} buffer + * @param {Number} frame_size + * @param {Number} block_size + * @returns {Number[]} + */ + decompress(buffer, frame_size, block_size) { + + // read header if we haven't already + if (!this.header_read) { + // read the intel call + const intel = buffer.readLZXBits(1); + + Debug(`Intel: 0b${intel.toString(2)} = ${intel}`); + + // don't care about intel e8 + if (intel != 0) + throw new XnbError(`Intel E8 Call found, invalid for XNB files.`); + + // the header has been read + this.header_read = true; + } + + // set what's left to go to the frame size + let togo = frame_size; + + // loop over what's left of the frame + while (togo > 0) { + + // this is a new block + if (this.block_remaining == 0) { + // read in the block type + this.block_type = buffer.readLZXBits(3); + + Debug(`Blocktype: 0b${this.block_type.toString(2).padStart(3,'0')} = ${this.block_type}`); + + // read 24-bit value for uncompressed bytes in this block + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + // number of uncompressed bytes for this block left + this.block_remaining = (hi << 8) | lo; + + Debug(`Block Remaining: ${this.block_remaining}`); + + // switch over the valid block types + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + // aligned offset tree + for (let i = 0; i < 8; i++) + this.aligned_len[i] = buffer.readLZXBits(3); + // decode table for aligned tree + this.aligned_table = this.decodeTable( + ALIGNED_MAXSYMBOLS, + ALIGNED_TABLEBITS, + this.aligned_len + ); + // NOTE: rest of aligned block type is the same as verbatim block type + case BLOCKTYPE.VERBATIM: + // read the first 256 elements for main tree + this.readLengths(buffer, this.maintree_len, 0, 256); + // read the rest of the elements for the main tree + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + // decode the main tree into a table + this.maintree_table = this.decodeTable( + MAINTREE_MAXSYMBOLS, + MAINTREE_TABLEBITS, + this.maintree_len + ); + // read path lengths for the length tree + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + // decode the length tree + this.length_table = this.decodeTable( + LENGTH_MAXSYMBOLS, + LENGTH_TABLEBITS, + this.length_len + ); + break; + case BLOCKTYPE.UNCOMPRESSED: + // align the bit buffer to byte range + buffer.align(); + // read the offsets + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + default: + throw new XnbError(`Invalid Blocktype Found: ${this.block_type}`); + break; + } + } + + // iterate over the block remaining + let this_run = this.block_remaining; + + // loop over the bytes left in the buffer to run out our output + while ((this_run = this.block_remaining) > 0 && togo > 0) { + // if this run is somehow higher than togo then just cap it + if (this_run > togo) + this_run = togo; + + // reduce togo and block remaining by this iteration + togo -= this_run; + this.block_remaining -= this_run; + + // apply 2^x-1 mask + this.window_posn &= this.window_size - 1; + // run cannot exceed frame size + if (this.window_posn + this_run > this.window_size) + throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + // get the element of this run + let main_element = this.readHuffSymbol( + buffer, + this.maintree_table, + this.maintree_len, + MAINTREE_MAXSYMBOLS, + MAINTREE_TABLEBITS + ); + + // main element is an unmatched character + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + + let length_footer; + + let match_length = main_element & NUM_PRIMARY_LENGTHS; + if (match_length == NUM_PRIMARY_LENGTHS) { + // get the length footer + length_footer = this.readHuffSymbol( + buffer, + this.length_table, + this.length_len, + LENGTH_MAXSYMBOLS, + LENGTH_TABLEBITS + ); + // increase match length by the footer + match_length += length_footer; + } + match_length += MIN_MATCH; + + let match_offset = main_element >> 3; + + if (match_offset > 2) { + // not repeated offset + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + if (extra > 3) { + // verbatim and aligned bits + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol( + buffer, + this.aligned_table, + this.aligned_len, + ALIGNED_MAXSYMBOLS, + ALIGNED_TABLEBITS + ); + match_offset += aligned_bits; + } + else if (extra == 3) { + // aligned bits only + match_offset += this.readHuffSymbol( + buffer, + this.aligned_table, + this.aligned_len, + ALIGNED_MAXSYMBOLS, + ALIGNED_TABLEBITS + ); + } + else if (extra > 0) + // verbatim bits only + match_offset += buffer.readLZXBits(extra); + else + match_offset = 1; // ??? + + // update repeated offset LRU queue + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } + else if (match_offset === 0) { + match_offset = this.R0; + } + else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } + else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + + // copy any wrapped around source data + if (this.window_posn >= match_offset) + runsrc = rundest - match_offset; // no wrap + else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + while (copy_length-- > 0) + this.win[rundest++] = this.win[runsrc++]; + runsrc = 0; + } + } + this.window_posn += match_length; + + // copy match data - no worrries about destination wraps + while (match_length-- > 0) + this.win[rundest++] = this.win[runsrc++]; + } + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + // get the element of this run + let main_element = this.readHuffSymbol( + buffer, + this.maintree_table, + this.maintree_len, + MAINTREE_MAXSYMBOLS, + MAINTREE_TABLEBITS + ); + + // main element is an unmatched character + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + // match: NUM_CHARS + ((slot << 3) | length_header (3 bits)) + + main_element -= NUM_CHARS; + + let length_footer; + + let match_length = main_element & NUM_PRIMARY_LENGTHS; + if (match_length == NUM_PRIMARY_LENGTHS) { + // read the length footer + length_footer = this.readHuffSymbol( + buffer, + this.length_table, + this.length_len, + LENGTH_MAXSYMBOLS, + LENGTH_TABLEBITS + ); + match_length += length_footer; + } + match_length += MIN_MATCH; + + let match_offset = main_element >> 3; + + if (match_offset > 2) { + // not repeated offset + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } + else + match_offset = 1; + + // update repeated offset LRU queue + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } + else if (match_offset === 0) { + match_offset = this.R0; + } + else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } + else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + + // copy any wrapped around source data + if (this.window_posn >= match_offset) + runsrc = rundest - match_offset; // no wrap + else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + while (copy_length-- > 0) + this.win[rundest++] = this.win[runsrc++]; + runsrc = 0; + } + } + this.window_posn += match_length; + + // copy match data - no worrries about destination wraps + while (match_length-- > 0) + this.win[rundest++] = this.win[runsrc++]; + } + break; + + case BLOCKTYPE.UNCOMPRESSED: + if ((buffer.bytePosition + this_run) > block_size) + throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + for (let i = 0; i < this_run; i++) + this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + // there is still more left + if (togo != 0) + throw new XnbError('EOF reached with data left to go.'); + + // ensure the buffer is aligned + buffer.align(); + + // get the start window position + const start_window_pos = ((this.window_posn == 0) ? this.window_size : this.window_posn) - frame_size; + + // return the window + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + /** + * Reads in code lengths for symbols first to last in the given table + * The code lengths are stored in their own special LZX way. + * @public + * @method readLengths + * @param {BufferReader} buffer + * @param {Array} table + * @param {Number} first + * @param {Number} last + * @returns {Array} + */ + readLengths(buffer, table, first, last) { + // read in the 4-bit pre-tree deltas + for (let i = 0; i < 20; i++) + this.pretree_len[i] = buffer.readLZXBits(4); + + // create pre-tree table from lengths + this.pretree_table = this.decodeTable( + PRETREE_MAXSYMBOLS, + PRETREE_TABLEBITS, + this.pretree_len + ); + + // loop through the lengths from first to last + for (let i = first; i < last;) { + + // read in the huffman symbol + let symbol = this.readHuffSymbol( + buffer, + this.pretree_table, + this.pretree_len, + PRETREE_MAXSYMBOLS, + PRETREE_TABLEBITS + ); + + // code = 17, run of ([read 4 bits] + 4) zeros + if (symbol == 17) { + // read in number of zeros as a 4-bit number + 4 + let zeros = buffer.readLZXBits(4) + 4; + // iterate over zeros counter and add them to the table + while (zeros-- != 0) + table[i++] = 0; + } + // code = 18, run of ([read 5 bits] + 20) zeros + else if (symbol == 18) { + // read in number of zeros as a 5-bit number + 20 + let zeros = buffer.readLZXBits(5) + 20; + // add the number of zeros into the table array + while (zeros-- != 0) + table[i++] = 0; + } + // code = 19 run of ([read 1 bit] + 4) [read huffman symbol] + else if (symbol == 19) { + // read for how many of the same huffman symbol to repeat + let same = buffer.readLZXBits(1) + 4; + // read another huffman symbol + symbol = this.readHuffSymbol( + buffer, + this.pretree_table, + this.pretree_len, + PRETREE_MAXSYMBOLS, + PRETREE_TABLEBITS + ); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + while (same-- != 0) + table[i++] = symbol; + } + // code 0 -> 16, delta current length entry + else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + // return the table created + return table; + } + + /** + * Build a decode table from a canonical huffman lengths table + * @public + * @method makeDecodeTable + * @param {Number} symbols Total number of symbols in tree. + * @param {Number} bits Any symbols less than this can be decoded in one lookup of table. + * @param {Number[]} length Table for lengths of given table to decode. + * @returns {Number[]} Decoded table, length should be ((1<> 1; + + // loop across all bit positions + for (let bit_num = 1; bit_num <= bits; bit_num++) { + // loop over the symbols we're decoding + for (let symbol = 0; symbol < symbols; symbol++) { + // if the symbol isn't in this iteration of length then just ignore + if (length[symbol] == bit_num) { + let leaf = pos; + // if the position has gone past the table mask then we're overrun + if ((pos += bit_mask) > table_mask) { + Debug(length[symbol]); + Debug(`pos: ${pos}, bit_mask: ${bit_mask}, table_mask: ${table_mask}`); + Debug(`bit_num: ${bit_num}, bits: ${bits}`); + Debug(`symbol: ${symbol}, symbols: ${symbols}`); + throw new XnbError('Overrun table!'); + } + // fill all possible lookups of this symbol with the symbol itself + let fill = bit_mask; + while (fill-- > 0) + table[leaf++] = symbol; + } + } + // advance bit mask down the bit positions + bit_mask >>= 1; + } + + // exit with success if table is complete + if (pos == table_mask) + return table; + + // mark all remaining table entries as unused + for (let symbol = pos; symbol < table_mask; symbol++) + table[symbol] = 0xFFFF; + + // next_symbol = base of allocation for long codes + let next_symbol = ((table_mask >> 1) < symbols) ? symbols : (table_mask >> 1); + + // allocate space for 16-bit values + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + // loop again over the bits + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + // loop over the symbol range + for (let symbol = 0; symbol < symbols; symbol++) { + // if the current length iteration doesn't mach our bit then just ignore + if (length[symbol] != bit_num) + continue; + + // get leaf shifted away from 16 bit padding + let leaf = pos >> 16; + + // loop over fill to flood table with + for (let fill = 0; fill < (bit_num - bits); fill++) { + // if this path hasn't been taken yet, 'allocate' two entries + if (table[leaf] == 0xFFFF) { + table[(next_symbol << 1)] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + // follow the path and select either left or right for the next bit + leaf = table[leaf] << 1; + if ((pos >> (15 - fill)) & 1) + leaf++; + } + table[leaf] = symbol + + // bit position has overun the table mask + if ((pos += bit_mask) > table_mask) + throw new XnbError('Overrun table during decoding.'); + } + bit_mask >>= 1; + } + + // we have reached table mask + if (pos == table_mask) + return table; + + // something else went wrong + throw new XnbError('Decode table did not reach table mask.'); + } + + /** + * Decodes the next huffman symbol from the bitstream. + * @public + * @method readHuffSymbol + * @param {BufferReader} buffer + * @param {Number[]} table + * @param {Number[]} length + * @param {Number} symbols + * @param {Number} bits + * @returns {Number} + */ + readHuffSymbol(buffer, table, length, symbols, bits) { + // peek the specified bits ahead + let bit = (buffer.peekLZXBits(32) >>> 0); // (>>> 0) allows us to get a 32-bit uint + let i = table[buffer.peekLZXBits(bits)]; + + // if our table is accessing a symbol beyond our range + if (i >= symbols) { + let j = 1 << (32 - bits); + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) + return 0; + } + while ((i = table[i]) >= symbols) + } + + // seek past this many bits + buffer.bitPosition += length[i]; + + // return the symbol + return i; + } + + /** + * Sets the shortest match. + * @param {Number} X + */ + set RRR(X) { + // No match, R2 <- R1, R1 <- R0, R0 <- X + if (this.R0 != X && this.R1 != X && this.R2 != X) { + // shift all offsets down + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } + // X = R1, Swap R0 <-> R1 + else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } + // X = R2, Swap R0 <-> R2 + else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } +} + +Lzx.position_base = []; +Lzx.extra_bits = []; + +export default Lzx; diff --git a/src/core/App/Decompressor/lz4/utils.js b/src/core/App/Decompressor/lz4/utils.js new file mode 100644 index 0000000..948b515 --- /dev/null +++ b/src/core/App/Decompressor/lz4/utils.js @@ -0,0 +1,59 @@ +// Original Code by: https://github.com/Benzinga/lz4js/ + +export default class LZ4Utils +{ + // Simple hash function, from: http://burtleburtle.net/bob/hash/integer.html. + // Chosen because it doesn't use multiply and achieves full avalanche. + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + // Reads a 64-bit little-endian integer from an array. + static readU64(b, n){ + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + // Reads a 32-bit little-endian integer from an array. + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + // Writes a 32-bit little-endian integer from an array. + static writeU32(b, n, x) { + b[n++] = (x >> 0) & 0xff; + b[n++] = (x >> 8) & 0xff; + b[n++] = (x >> 16) & 0xff; + b[n++] = (x >> 24) & 0xff; + } + + // Multiplies two numbers using 32-bit integer multiplication. + // Algorithm from Emscripten. + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + + return al * bl + (ah * bl + al * bh << 16) | 0; + }; +} \ No newline at end of file diff --git a/src/core/App/Decompressor/lz4/xxh32.js b/src/core/App/Decompressor/lz4/xxh32.js new file mode 100644 index 0000000..91cbfdc --- /dev/null +++ b/src/core/App/Decompressor/lz4/xxh32.js @@ -0,0 +1,102 @@ +// xxh32.js - implementation of xxhash32 in plain JavaScript +import util from './utils.js'; + +// xxhash32 primes +const prime1 = 0x9e3779b1; +const prime2 = 0x85ebca77; +const prime3 = 0xc2b2ae3d; +const prime4 = 0x27d4eb2f; +const prime5 = 0x165667b1; + +// Utility functions/primitives +// -- + +function rotl32 (x, r) { + x = x | 0; + r = r | 0; + + return x >>> (32 - r | 0) | x << r | 0; +} + +function rotmul32 (h, r, m) { + h = h | 0; + r = r | 0; + m = m | 0; + + return util.imul(h >>> (32 - r | 0) | h << r, m) | 0; +} + +function shiftxor32 (h, s) { + h = h | 0; + s = s | 0; + + return h >>> s ^ h | 0; +} + +// Implementation +// -- + +function xxhapply (h, src, m0, s, m1) { + return rotmul32(util.imul(src, m0) + h, s, m1); +} + +function xxh1 (h, src, index) { + return rotmul32((h + util.imul(src[index], prime5)), 11, prime1); +} + +function xxh4 (h, src, index) { + return xxhapply(h, util.readU32(src, index), prime3, 17, prime4); +} + +function xxh16 (h, src, index) { + return [ + xxhapply(h[0], util.readU32(src, index + 0), prime2, 13, prime1), + xxhapply(h[1], util.readU32(src, index + 4), prime2, 13, prime1), + xxhapply(h[2], util.readU32(src, index + 8), prime2, 13, prime1), + xxhapply(h[3], util.readU32(src, index + 12), prime2, 13, prime1) + ]; +} + +function xxh32 (seed, src, index, len) { + var h, l; + l = len; + if (len >= 16) { + h = [ + seed + prime1 + prime2, + seed + prime2, + seed, + seed - prime1 + ]; + + while (len >= 16) { + h = xxh16(h, src, index); + + index += 16; + len -= 16; + } + + h = rotl32(h[0], 1) + rotl32(h[1], 7) + rotl32(h[2], 12) + rotl32(h[3], 18) + l; + } else { + h = (seed + prime5 + len) >>> 0; + } + + while (len >= 4) { + h = xxh4(h, src, index); + + index += 4; + len -= 4; + } + + while (len > 0) { + h = xxh1(h, src, index); + + index++; + len--; + } + + h = shiftxor32(util.imul(shiftxor32(util.imul(shiftxor32(h, 15), prime2), 13), prime3), 16); + + return h >>> 0; +} + +export default xxh32; \ No newline at end of file diff --git a/src/core/App/ReaderResolver.js b/src/core/App/ReaderResolver.js new file mode 100644 index 0000000..ebccefc --- /dev/null +++ b/src/core/App/ReaderResolver.js @@ -0,0 +1,58 @@ +import BufferReader from "./BufferReader.js"; +import XnbError from "../Utils/XnbError.js"; + +/** + * Class used to read the XNB types using the readers + * @class + */ +class ReaderResolver { + /** + * Creating a new instance of ReaderResolver + * @constructor + * @param {BaseReader[]} readers Array of BaseReaders + */ + constructor(readers) { + /** + * Array of base readers + * @type {BaseReader[]} + */ + this.readers = readers; + } + + /** + * Read the XNB file contents + * @method read + * @public + * @param {BufferReader} buffer The buffer to read from. + */ + read(buffer) { + // read the index of which reader to use + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) + throw new XnbError(`Invalid reader index ${index}`); + // read the buffer using the selected reader + return this.readers[index].read(buffer, this); + } + + /** + * Writes the XNB file contents + * @param {BufferWriter} buffer + * @param {Object} content + */ + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + /** + * Returns the index of the reader + * @param {BaseReader} reader + * @param {Number} + */ + getIndex(reader) { + for (let i in this.readers) + if (reader.toString() == this.readers[i].toString()) + return i; + } +} + +export default ReaderResolver; \ No newline at end of file diff --git a/src/core/App/Readers/StringReader.js b/src/core/App/Readers/StringReader.js new file mode 100644 index 0000000..76fad68 --- /dev/null +++ b/src/core/App/Readers/StringReader.js @@ -0,0 +1,36 @@ +import BufferReader from "../BufferReader.js"; +import BufferWriter from "../BufferWriter.js"; +import {UTF8Length} from "../../Utils/UTF8ToString.js"; + +/** + * Lightweight String Reader in @xnb/core + * @class + * @extends BaseReader + */ +export default class StringReaderCore { + /** + * Reads String from buffer. + * @param {BufferReader} buffer + * @returns {String} + */ + read(buffer) { + // read in the length of the string + let length = buffer.read7BitNumber(); + // read in the UTF-8 encoded string + return buffer.readString(length); + } + + /** + * Writes the string to the buffer. + * @param {BufferWriter} buffer + * @param {String} string + */ + write(buffer, string) { + // get the size of UTF-8 encoded string + const size = UTF8Length(string); + // write the length of the string + buffer.write7BitNumber(size); + // write the string + buffer.writeString(string); + } +} diff --git a/src/core/App/Readers/TypeReader.js b/src/core/App/Readers/TypeReader.js new file mode 100644 index 0000000..7b09dab --- /dev/null +++ b/src/core/App/Readers/TypeReader.js @@ -0,0 +1,174 @@ +import XnbError from "../../Utils/XnbError.js"; + +class TypeReader +{ + static readers = {}; + /** + * Used to set readers plugin. + * @function setReaders + * @param {Object} BaseReader Class object + */ + static setReaders(readers) + { + TypeReader.readers = {...readers}; + } + /** + * Used to add readers plugin. + * @function setReaders + * @param {Object} BaseReader Class object + */ + static addReaders(readers) + { + TypeReader.readers = {...(TypeReader.readers), ...readers}; + } + static makeSimplied(type, reader) + { + let simple = type.split(/`|,/)[0]; + if(reader.isTypeOf(simple)) + { + if(reader.hasSubType()) + { + let subtypes = TypeReader.parseSubtypes(type).map( TypeReader.simplifyType.bind(TypeReader) ); + return `${reader.type()}<${subtypes.join(",")}>`; + } + else return reader.type(); + } + return null; + } + + + /** + * Used to simplify type from XNB file. + * @function simplifyType + * @param {String} type The long verbose type read from XNB file. + * @returns {String} returns shorthand simplified type for use within this tool. + */ + static simplifyType(type) + { + // gets the first part of the type + let simple = type.split(/`|,/)[0]; + + // check if its an array or not + let isArray = simple.endsWith('[]'); + // if its an array then get the array type + if (isArray) + return `Array<${simplifyType(simple.slice(0, -2))}>`; + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') //reflective + { + let reflectiveType = TypeReader.parseSubtypes(type).map( TypeReader.simplifyType.bind(TypeReader) ); + return `${reflectiveType}`; + } + + for(let reader of Object.values(TypeReader.readers)) + { + let result = TypeReader.makeSimplied(type, reader); + if(result !== null) return result; + } + + throw new XnbError(`Non-implemented type found, cannot resolve type "${simple}", "${type}".`); + } + + + /** + * Parses subtypes from a type like Dictionary or List + * @function parseSubtypes + * @param {String} type The type to parse with subtypes in. + * @returns {String[]} returns an array of subtypes + */ + static parseSubtypes(type){ + + // split the string by the ` after the type + let subtype = type.split('`')[1]; + // get the number of types following the ` in type string + let count = subtype.slice(0, 1); + + // get the contents of the wrapped array + subtype = subtype.slice(2, -1); + + // regex pattern to match the subtypes + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + // get matches + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + + // return the matches + return matches; + } + + + /** + * Get type info from simple type + * @param {String} type Simple type to get info from. + * @returns {Object} returns an object containing information about the type. + */ + static getTypeInfo(type){ + // get type before angle brackets for complex types + let mainType = type.match(/[^<]+/)[0]; + // get the subtypes within brackets + let subtypes = type.match(/<(.+)>/); + + // if we do have subtypes then split and trim them + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + + // return info object + return { type: mainType, subtypes }; + } + + + /** + * Gets an type structure array for yaml convertion. + * @function getReaderTypeList + * @param {String} type The simplified type to get reader based off of. + * @returns {Array} returns an type structure array for yaml convertion. + */ + static getReaderTypeList(typeString){ + // get type info for complex types + let {type, subtypes} = TypeReader.getTypeInfo(typeString); +// // loop over subtypes and resolve readers for them +// subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + + // if we have a reader then use one + if (TypeReader.readers.hasOwnProperty(`${type}Reader`)) + return TypeReader.readers[`${type}Reader`].parseTypeList(subtypes); + + // throw an error as type is not supported + throw new XnbError(`Invalid reader type "${typeString}" passed, unable to resolve!`); + } + + + /** + * Gets an XnbReader instance based on type. + * @function getReader + * @param {String} type The simplified type to get reader based off of. + * @returns {BaseReader} returns an instance of BaseReader for given type. + */ + static getReader(typeString){ + // get type info for complex types + let {type, subtypes} = TypeReader.getTypeInfo(typeString); + // loop over subtypes and resolve readers for them + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + + // if we have a reader then use one + if (TypeReader.readers.hasOwnProperty(`${type}Reader`)) + return new (TypeReader.readers[`${type}Reader`])(...subtypes); + + // throw an error as type is not supported + throw new XnbError(`Invalid reader type "${typeString}" passed, unable to resolve!`); + } + + /** + * Gets an XnbReader instance based on type. + * @function getReader + * @param {String} The raw type to get reader based off of. + * @returns {BaseReader} returns an instance of BaseReader for given type. + */ + static getReaderFromRaw(typeString){ + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } +} + + + +export default TypeReader; \ No newline at end of file diff --git a/src/core/App/XnbConverter.js b/src/core/App/XnbConverter.js new file mode 100644 index 0000000..de03a7d --- /dev/null +++ b/src/core/App/XnbConverter.js @@ -0,0 +1,375 @@ +import BufferReader from "./BufferReader.js"; +import BufferWriter from "./BufferWriter.js"; + +import Presser from "./Decompressor/LZXDecompressor.js"; +import {decompressBlock as LZ4_decompressBlock, + compressBound as LZ4_compressBound, + compressSingleBlock as LZ4_compressBlock} from "./Decompressor/Lz4.js"; + +import StringReader from "./Readers/StringReader.js"; +import TypeReader from "./Readers/TypeReader.js"; +import ReaderResolver from './ReaderResolver.js'; + +import XnbError from "../Utils/XnbError.js"; +import Debug from "../Utils/Debug.js"; + +import {XnbData} from "./XnbData.js"; + +// "constants" for this class +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +/** + * XNB file class used to read and write XNB files + * @class + * @public + */ +class XnbConverter { + + /** + * Creates new instance of Xnb class + * @constructor + */ + constructor() { + // target platform + this.target = ''; + // format version + this.formatVersion = 0; + // HiDef flag + this.hidef = false; + // Compressed flag + this.compressed = false; + // compression type + this.compressionType = 0; + // the XNB buffer reader + this.buffer = null; + // the file size + this.fileSize = 0; + + /** + * Array of readers that are used by the XNB file. + * @type {BaseReader[]} + */ + this.readers = []; + + /** + * Array of shared resources + * @type {Array} + */ + this.sharedResources = []; + } + + /** + * Loads a file into the XNB class. + * @param {ArrayBuffer} XNB file's array buffer + */ + load(arrayBuffer) { + + // create a new instance of reader + this.buffer = new BufferReader(arrayBuffer); + + + // validate the XNB file header + this._validateHeader(); + + // we validated the file successfully + console.info('XNB file validated successfully!'); + + + // read the file size + this.fileSize = this.buffer.readUInt32(); + + // verify the size + if (this.buffer.size != this.fileSize) + throw new XnbError('XNB file has been truncated!'); + + // print out the file size + Debug(`File size: ${this.fileSize} bytes.`); + + + + // if the file is compressed then we need to decompress it + if (this.compressed) { + // get the decompressed size + const decompressedSize = this.buffer.readUInt32(); + Debug(`Uncompressed size: ${decompressedSize} bytes.`); + + // decompress LZX format + if (this.compressionType == COMPRESSED_LZX_MASK) { + // get the amount of data to compress + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + // decompress the buffer based on the file size + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + // copy the decompressed buffer into the file buffer + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + // reset the byte seek head to read content + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + // decompress LZ4 format + + else if (this.compressionType == COMPRESSED_LZ4_MASK) { + // allocate Uint8 Array for LZ4 decode + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + + // decode the trimmed buffer into decompressed buffer + const decompressed = new Uint8Array(decompressedSize); + LZ4_decompressBlock(trimmedArray, decompressed); + // copy the decompressed buffer into our buffer + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + // reset the byte seek head to read content + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + Debug(`Reading from byte position: ${this.buffer.bytePosition}`); + + + // NOTE: assuming the buffer is now decompressed + + // get the 7-bit value for readers + let count = this.buffer.read7BitNumber(); + // log how many readers there are + Debug(`Readers: ${count}`); + + + // create an instance of string reader + const stringReader = new StringReader(); + + // a local copy of readers for the export + const readers = []; + + + // loop over the number of readers we have + for (let i = 0; i < count; i++) { + // read the type + const type = stringReader.read(this.buffer); + // read the version + const version = this.buffer.readInt32(); + + // get the reader for this type + const reader = TypeReader.getReaderFromRaw(type); + + // add reader to the list + this.readers.push(reader); + // add local reader + readers.push({ type, version }); + } + + // get the 7-bit value for shared resources + const shared = this.buffer.read7BitNumber(); + + // log the shared resources count + Debug(`Shared Resources: ${shared}`); + + // don't accept shared resources since SDV XNB files don't have any + if (shared != 0) + throw new XnbError(`Unexpected (${shared}) shared resources.`); + + // create content reader from the readers loaded + const content = new ReaderResolver(this.readers); + // read the content in + const result = content.read(this.buffer); + + // we loaded the XNB file successfully + console.log('Successfuly read XNB file!'); + + // return the loaded XNB object + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, + readers, result); + } + + /** + * Converts JSON into XNB file structure + * @param {Object} The JSON to convert into a XNB file + */ + + convert(json) { + // the output buffer for this file + const buffer = new BufferWriter(); + + // create an instance of string reader + const stringReader = new StringReader(); + + // set the header information + let {target, formatVersion, hidef, compressed} = json.header; + + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + + const lz4Compression = (this.target == 'a' || this.target == 'i') || ((compressed & COMPRESSED_LZ4_MASK) != 0); + this.compressed = lz4Compression ? true : false; // support android LZ4 compression + + // write the header into the buffer + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + // write the LZ4 mask for android compression only + // todo:LZX compression. There are currently NO open source libraries implementing the LZX compression algorithm. + buffer.writeByte(this.hidef | ((this.compressed && lz4Compression) ? COMPRESSED_LZ4_MASK : 0)); + + // write temporary filesize + buffer.writeUInt32(0); + + // write the decompression size temporarily if android + if (lz4Compression) + buffer.writeUInt32(0); + + Debug("Header data written successfully!"); + + // write the amount of readers + buffer.write7BitNumber(json.readers.length); + + // loop over the readers and load the types + for (let reader of json.readers) { + + this.readers.push( TypeReader.getReaderFromRaw(reader.type) ); // get the reader of it + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + Debug("Reader data written successfully!"); + + // write 0 shared resources + buffer.write7BitNumber(0); + + // create reader resolver for content and write it + const content = new ReaderResolver(this.readers); + + // write the content to the reader resolver + content.write(buffer, json.content); + + Debug("Content data written successfully!"); + + // trim excess space in the buffer + // NOTE: this buffer allocates default with 500 bytes + buffer.trim(); + + // LZ4 compression + if (lz4Compression) { + // allocate Uint8 Array for LZ4 encode + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + + let compressedSize = LZ4_compressBound(trimmedArray.length); + + // create a buffer for the compressed data + let compressed = new Uint8Array(compressedSize); + + // compress the data into the buffer + compressedSize = LZ4_compressBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + + // write the file size & decompressed size into the buffer + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + + // write compressed data + buffer.concat(compressed); + + // slice off the excess + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + + // return the buffer + return returnBuffer; + } + + // write the file size into the buffer + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + + // return the buffer + return buffer.buffer; + } + + /** + * Ensures the XNB file header is valid. + * @private + * @method _validateHeader + */ + _validateHeader() { + // ensure buffer isn't null + if (this.buffer == null) + throw new XnbError('Buffer is null'); + + // get the magic from the beginning of the file + const magic = this.buffer.readString(3); + // check to see if the magic is correct + if (magic != 'XNB') + throw new XnbError(`Invalid file magic found, expecting "XNB", found "${magic}"`); + + // debug print that valid XNB magic was found + Debug('Valid XNB magic found!'); + + // load the target platform + this.target = this.buffer.readString(1).toLowerCase(); + + // read the target platform + switch (this.target) { + case 'w': + Debug('Target platform: Microsoft Windows'); + break; + case 'm': + Debug('Target platform: Windows Phone 7'); + break; + case 'x': + Debug('Target platform: Xbox 360'); + break; + case 'a': + Debug('Target platform: Android'); + break; + case 'i': + Debug('Target platform: iOS'); + break; + default: + console.warn(`Invalid target platform "${this.target}" found.`); + break; + } + + // read the format version + this.formatVersion = this.buffer.readByte(); + + // read the XNB format version + switch (this.formatVersion) { + case 0x3: + Debug('XNB Format Version: XNA Game Studio 3.0'); + break; + case 0x4: + Debug('XNB Format Version: XNA Game Studio 3.1'); + break; + case 0x5: + Debug('XNB Format Version: XNA Game Studio 4.0'); + break; + default: + console.warn(`XNB Format Version 0x${this.formatVersion.toString(16)} unknown.`); + break; + } + + // read the flag bits + const flags = this.buffer.readByte(1); + // get the HiDef flag + this.hidef = (flags & HIDEF_MASK) != 0; + // get the compressed flag + this.compressed = (flags & COMPRESSED_LZX_MASK) || (flags & COMPRESSED_LZ4_MASK) != 0; + // set the compression type + // NOTE: probably a better way to do both lines but sticking with this for now + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : ((flags & COMPRESSED_LZ4_MASK) ? COMPRESSED_LZ4_MASK : 0); + // debug content information + Debug(`Content: ${(this.hidef ? 'HiDef' : 'Reach')}`); + // log compressed state + Debug(`Compressed: ${this.compressed}, ${this.compressionType == COMPRESSED_LZX_MASK ? 'LZX' : 'LZ4'}`); + } + +} + +export default XnbConverter; \ No newline at end of file diff --git a/src/core/App/XnbData.js b/src/core/App/XnbData.js new file mode 100644 index 0000000..2555fa1 --- /dev/null +++ b/src/core/App/XnbData.js @@ -0,0 +1,90 @@ +class XnbData { + constructor(header, readers, content) + { + let {target, formatVersion, hidef, compressed} = header; + this.header = {target, formatVersion, hidef, compressed}; + this.readers = readers; + this.content = content; + } + get target() + { + switch(this.header?.target){ + case 'w': return "Microsoft Windows"; + case 'm': return "Windows Phone 7"; + case 'x': return "Xbox 360"; + case 'a': return "Android"; + case 'i': return "iOS"; + default: return "Unknown"; + } + + } + get formatVersion() + { + switch (this.header?.formatVersion) { + case 0x3: return "XNA Game Studio 3.0"; + case 0x4: return "XNA Game Studio 3.1"; + case 0x5: return "XNA Game Studio 4.0"; + default: return "Unknown"; + } + } + get hidef() + { + return !!(this.header?.hidef); + } + get compressed() + { + return !!(this.header?.compressed); + } + + get contentType() + { + let {export:raw} = this.content; + if(raw !== undefined) return raw.type; + return "JSON"; + } + get rawContent() + { + let {export:raw} = this.content; + if(raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value)=>{ + if(key === "export") return value.type; + return value; + }, 4); + } + stringify() + { + return JSON.stringify({ + header:this.header, + readers:this.readers, + content:this.content + }, null, 4); + } + toString() + { + return this.stringify(); + } +} + +function extensionToDatatype(extension) +{ + switch(extension) + { + case "json": return "JSON"; + case "yaml": return "yaml"; + case "png": return "Texture2D"; + case "cso": return "Effect"; + case 'tbin': return "TBin"; + case 'xml': return "BmFont"; + } + return "Others"; +} + +class XnbContent { + constructor(data, ext) + { + this.type = extensionToDatatype(ext); + this.content = data; + } +} + +export {XnbData, XnbContent}; \ No newline at end of file diff --git a/src/core/Files.js b/src/core/Files.js new file mode 100644 index 0000000..1096567 --- /dev/null +++ b/src/core/Files.js @@ -0,0 +1,280 @@ +import XnbError from "./Utils/XnbError.js"; +import {toPNG, fromPNG} from "./libs/png.js"; +import {stringifyYaml, parseYaml} from "./libs/jsonToYaml.js"; +import {toXnbNodeData, fromXnbNodeData} from "./Utils/xnbNodeConverter.js"; + + +function searchElement(parent, element) +{ + // ensure object is defined and is an object + if (!parent || typeof parent != 'object') return; + + // if property exists then return it + if (parent.hasOwnProperty(element)) { + return { parent, value: parent[element] }; + } + + // search the objects for keys + for(let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if(found) return found; + } + } + + return null; +} + +function extractFileName(fullname) +{ + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if(matcher === null) return [fullname,null]; + return [ matcher[1], matcher[2] ]; +} + +function getExtension(dataType) +{ + switch(dataType) + { + // json data + case "JSON": return "json"; + // yaml data + case "yaml": return "yaml"; + // png image + case "Texture2D": return "png"; + // compiled effects + case "Effect": return "cso"; + // tbin map file + case 'TBin': return "tbin"; + // BmFont Xml + case 'BmFont': return "xml"; + } + return "bin"; +} + +function getMimeType(dataType) +{ + switch(dataType) + { + // json data + case "JSON": return "application/json"; + // yaml data + case "yaml": return "text/plain"; + // png image + case "Texture2D": return "image/png"; + // compiled effects + case "Effect": return "application/x-cso"; + // BmFont Xml + case 'BmFont': return "application/xml"; + } + return "application/octet-stream"; +} + +function makeBlob(data, dataType) +{ + //blob is avaliable + if(typeof Blob === "function") return { + data : new Blob([data], {type : getMimeType(dataType)}), + extension : getExtension(dataType) + }; + return { + data : data, + extension : getExtension(dataType) + }; +} + +function exportContent(content, jsonContent=false) +{ + let found = searchElement(content, "export"); + if (found) + { + const {value} = found; + let {type:dataType, data} = value; + + // transform to png + if(dataType === "Texture2D") + { + data = toPNG( value.width, value.height, new Uint8Array(data) ); + } + + return makeBlob(data, dataType); + } + + // if contentOnly == true, export json data file + if(jsonContent) + { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; +} + + +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ +function exportFiles(xnbObject, {yaml:isYaml=false, contentOnly=false, fileName=null}={}) +{ + // set config + if(isYaml && contentOnly) isYaml = false; + + // ensure we have content field + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + + const blobs = []; + const {content} = xnbObject; + + // export content files + const contentBlob = exportContent(content, contentOnly); + if(contentBlob !== null) blobs.push(contentBlob); + + if(contentOnly) return blobs; + + // export json/yaml header files + const resultJSON = JSON.stringify(xnbObject, (key, value)=>{ + if(key === "export") + { + if(typeof fileName == "string" && fileName !== "") + { + return `${fileName}.${getExtension(value.type)}`; + } + return `${value.type}.${getExtension(value.type)}`; + } + return value; + }, 4); + + let result = resultJSON; + if(isYaml) result=stringifyYaml( toXnbNodeData(xnbObject) ); + + blobs.unshift( makeBlob(result, isYaml ? "yaml" : "JSON") ); + + return blobs; +} + + +function resolveCompression(compressionString) +{ + let str=compressionString.toLowerCase(); + if(str === "none") return 0; + if(str === "lz4") return 0x40; +// if(str === "lzx") return 0x80; + return null; +} + +/** + * @param {Blob/Buffer} input Blob/Buffer + * @return {Promise} promise returns text + */ +async function readBlobasText(blob) +{ + if(typeof Blob === "function" && blob instanceof Blob) return blob.text(); + else if(typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} + +/** + * @param {Blob/Buffer} input Blob/Buffer + * @return {Promise} promise returns text + */ +async function readBlobasArrayBuffer(blob) +{ + if(typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer(); + else if(typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} + + +async function readExternFiles(extension, files) +{ + // Texture2D to PNG + if(extension === "png") + { + // get binary file + const rawPng = await readBlobasArrayBuffer(files.png); + // get the png data + const png = fromPNG(new Uint8Array(rawPng) ); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + // Compiled Effects + if(extension === "cso") + { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + // TBin Map + if(extension === "tbin") + { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + // BmFont Xml + if(extension === "xml") + { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} + + +/** + * file objects to json file to compress. + * @param {Object} to compress files + * @param {Object} config (compression:default, none, LZ4, LZX(currently unsupported)) (optional) + */ +async function resolveImports(files, configs={}) +{ + const {compression="default"} = configs; + + const jsonFile = files.json || files.yaml; + if(!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + + //parse json/yaml data + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if(files.json) jsonData = JSON.parse(rawText); + else jsonData = fromXnbNodeData( parseYaml(rawText) ); + + // apply configuration data + let compressBits = resolveCompression(compression); + if(compressBits !== null) jsonData.header.compressed = compressBits; + + // need content + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError(`${jsonFile.name} does not have "content".`); + } + + const found = searchElement(jsonData.content, "export"); + + if(found) + { + const {parent, value} = found; + const [,extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; +} + + + +export { exportContent, exportFiles, resolveImports, extractFileName, makeBlob }; \ No newline at end of file diff --git a/src/core/Utils/Debug.js b/src/core/Utils/Debug.js new file mode 100644 index 0000000..4093f29 --- /dev/null +++ b/src/core/Utils/Debug.js @@ -0,0 +1,16 @@ +function Debug(str, ...args) +{ + if(Debug.__isVisible) console.log(str, ...args); +} + +Debug.__isVisible=false; + +Debug.setVisible=function(state) { + Debug.__isVisible=state; +} + +if(globalThis !== undefined) globalThis.Debug = Debug; // ES2020 +else if(window !== undefined) window.Debug = Debug; // Browser +else if(global !== undefined) global.Debug = Debug; // Node.js + +export default Debug; \ No newline at end of file diff --git a/src/core/Utils/UTF8ToString.js b/src/core/Utils/UTF8ToString.js new file mode 100644 index 0000000..7ab013c --- /dev/null +++ b/src/core/Utils/UTF8ToString.js @@ -0,0 +1,183 @@ +const UTF8_FIRST_BITES=[0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES=0x80; +const UTF8_MASK=0b111111; + +const UTF16_BITES=[0xD800, 0xDC00]; +const UTF16_MASK=0b1111111111; + +function UTF8Encode(code) +{ + //0x0000 ~ 0x007F + if(code < 0x80) return [code]; + + //0x0080 ~ 0x07FF + if(code < 0x800) return [ + UTF8_FIRST_BITES[0] | (code >> 6), + UTF8_SECOND_BITES | (code & UTF8_MASK) + ]; + + //0x0800 ~ 0xFFFF + if(code < 0x10000) return [ + UTF8_FIRST_BITES[1] | (code >> 12), + UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), + UTF8_SECOND_BITES | (code & UTF8_MASK) + ]; + + //0x10000 ~ + return [ + UTF8_FIRST_BITES[2] | (code >> 18), + UTF8_SECOND_BITES | ( (code >> 12) & UTF8_MASK ), + UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), + UTF8_SECOND_BITES | ( code & UTF8_MASK ) + ]; +} + +function UTF16Encode(code) +{ + //0x0000 ~ 0xFFFF + if(code < 0xFFFF) return [code]; + + //0x10000 ~ + code -= 0x10000; + return [ + UTF16_BITES[0] | ( (code >> 10) & UTF16_MASK ), + UTF16_BITES[1] | ( code & UTF16_MASK ) + ]; +} + +function UTF8Decode(codeSet) +{ + if(typeof codeSet === "number") codeSet=[codeSet]; + if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); + + const codeSetRange = codeSet.length; + + //0x0000 ~ 0x007F + if(codeSetRange === 1) return codeSet[0]; + + //0x0080 ~ 0x07FF + if(codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + //0x0800 ~ 0xFFFF + if(codeSetRange === 3) { + return ( ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + + (codeSet[2] ^ UTF8_SECOND_BITES) ); + } + + //0x10000 ~ + return ( ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + + (codeSet[3] ^ UTF8_SECOND_BITES) ); +} + +function UTF16Decode(codeSet) +{ + if(typeof codeSet === "number") codeSet=[codeSet]; + if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); + + const codeSetRange = codeSet.length; + + //0x0000 ~ 0xFFFF + if(codeSetRange === 1) return codeSet[0]; + + //0x10000 ~ + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) +{ + const utf16Map = Array.from({length:str.length}, (_,i)=>str.charCodeAt(i)); + const result=[]; + let index=0; + while(index < str.length) { + let code = utf16Map[index]; + if( (UTF16_BITES[0] & code) !== UTF16_BITES[0] ) { + result.push( code ); + index++; + } + else { + result.push( UTF16Decode(utf16Map.slice(index, index+2)) ); + index+=2; + } + } + return result; +} + +function UTF8ToUnicode(codes) +{ + const dataArray = (codes instanceof ArrayBuffer) ? new Uint8Array(codes) : codes; + + const result=[]; + let index=0; + while(index < dataArray.length) { + let headerCode = dataArray[index]; + if((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } + else if(headerCode < UTF8_FIRST_BITES[1]) { + result.push( UTF8Decode(dataArray.slice(index, index+2)) ); + index+=2; + } + else if(headerCode < UTF8_FIRST_BITES[2]) { + result.push( UTF8Decode(dataArray.slice(index, index+3)) ); + index+=3; + } + else{ + result.push( UTF8Decode(dataArray.slice(index, index+4)) ); + index+=4; + } + } + return result; +} + +function UnicodeToUTF8(unicodeArr) +{ + const result = []; + for(let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + return result; +} + +function UnicodeToString(unicodeArr) +{ + const result = []; + for(let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + //for bigger strings + const blockSize = 32768; + let resultStr = ""; + for(let i=0; i{ + if(unicode < 0x80) return sum+1; + if(unicode < 0x800) return sum+2; + if(unicode < 0x10000) return sum+3; + return sum+4; + }, 0); +} + +export {stringToUTF8, UTF8ToString, UTF8Length}; \ No newline at end of file diff --git a/src/core/Utils/XnbError.js b/src/core/Utils/XnbError.js new file mode 100644 index 0000000..661f4db --- /dev/null +++ b/src/core/Utils/XnbError.js @@ -0,0 +1,8 @@ +export default class XnbError extends Error { + constructor(message = '') { + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } +} \ No newline at end of file diff --git a/src/core/Utils/xnbNodeConverter.js b/src/core/Utils/xnbNodeConverter.js new file mode 100644 index 0000000..c749ef2 --- /dev/null +++ b/src/core/Utils/xnbNodeConverter.js @@ -0,0 +1,281 @@ +import TypeReader from "../App/Readers/TypeReader.js"; + +function deepCopy(obj) +{ + let newObj; + if(Array.isArray(obj)) + { + newObj=[]; + for(let item of obj) + { + newObj.push(deepCopy(item)); + } + return newObj; + } + + if(!!obj && typeof obj === "object") + { + newObj={}; + for(let [key, value] of Object.entries(obj)) + { + newObj[key] = deepCopy(value); + } + return newObj; + } + + return obj; +} + +function isPrimitiveReaderType(reader) +{ + switch(reader) + { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + default: return false; + } +} + +function isExportReaderType(reader) +{ + switch(reader) + { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + default: return false; + } +} + +function convertJsonContentsToXnbNode(raw, readers) +{ + let extractedImages = []; + let extractedMaps = []; + + const {converted} = (function recursiveConvert(obj, path, index=0) + { + const reader = readers[index]; + + //primitive + if(isPrimitiveReaderType(reader)) + { + return { + converted : { type:reader, data:obj }, + traversed : index + }; + } + + //null reader + if(reader === null) + { + return { + converted : obj, + traversed : index + }; + } + + //nullable + if(reader.startsWith('Nullable')) + { + return { + converted: { + type: reader, + data: {data:{ type:readers[index+1], data:obj } } + }, + traversed: index + 1 + }; + } + + //exportable + if(isExportReaderType(reader)) + { + //texture2D + if(reader === 'Texture2D') + { + extractedImages.push( {path:path.join('.')} ); + return { + converted : { type:reader, data:{format : obj.format} }, + traversed : index + }; + } + //tbin + if(reader === 'TBin') + { + extractedMaps.push( {path:path.join('.')} ); + } + return { + converted: { type:reader, data:{} }, + traversed: index + }; + } + + // complex data(list, dictionary, spritefont, etc...) + let data; + if(Array.isArray(obj)) data=[]; + else data={}; + + let traversed = index; + let first = true; + let isComplex = ( !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List") ); + + for(let [key, value] of Object.entries(obj)) + { + let newIndex; + if( reader.startsWith("Dictionary") ) newIndex = index+2; + else if( reader.startsWith("Array") || reader.startsWith("List")) newIndex = index+1; + else newIndex = traversed + 1; + + const {converted, traversed:nexter} = recursiveConvert( obj[key], [...path, key], newIndex ); + data[key] = converted; + if(isComplex) traversed = nexter; + else if(first) + { + traversed = nexter; + first = false; + } + } + + return { + converted : { type:reader, data }, + traversed + }; + })(raw, []); + + return { converted, extractedImages, extractedMaps }; +} + +// convert from inner json content of XnbExtract +// remove {type:"aaa" data:"..."} and pick only "..." +function convertJsonContentsFromXnbNode(obj) +{ + if( !obj || typeof obj !== "object" ) return obj; + if(typeof obj === "object" && obj.hasOwnProperty("data")) + { + let {type, data} = obj; + + if(isPrimitiveReaderType(type)) return deepCopy(data); + if(isExportReaderType(type)) + { + data = deepCopy(data); + if(type === "Texture2D") data.export = "Texture2D.png"; + else if(type === "Effect") data.export = "Effect.cso"; + else if(type === "TBin") data.export = "TBin.tbin"; + else if(type === "BmFont") data.export = "BmFont.xml"; + + return data; + } + obj = deepCopy(data); + } + + let newObj; + if(Array.isArray(obj)) + { + newObj=[]; + for(let item of obj) + { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + return newObj; + } + + if(!!obj && typeof obj === "object") + { + newObj={}; + for(let [key, value] of Object.entries(obj)) + { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + return newObj; + } + + return null; +} + +// convert json file to yaml compatible with XnbExtract +function toXnbNodeData(json) +{ + const toYamlJson = {}; + const {compressed, formatVersion, hidef:hiDef, target} = json.header; + let readerData = deepCopy(json.readers); + + // set header + toYamlJson.xnbData = { + target, + compressed:!!compressed, + hiDef, + readerData, + numSharedResources : 0 + }; + + // set contents + const rawContent = deepCopy(json.content); + + const mainReader = TypeReader.simplifyType( readerData[0].type ); + let readersTypeList = TypeReader.getReaderTypeList( mainReader ); + if(readersTypeList[0] === 'SpriteFont') + { + readersTypeList = ['SpriteFont', + 'Texture2D', + 'List', 'Rectangle', + 'List', 'Rectangle', + 'List', 'Char', + null, + 'List', 'Vector3', + 'Nullable', 'Char', + null]; + + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { converted, extractedImages, extractedMaps } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + + toYamlJson.content = converted; + if(extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if(extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + + return toYamlJson; +} + +function fromXnbNodeData(json) +{ + const result = {}; + + // set header data + const {compressed, readerData, hiDef:hidef, target} = json.xnbData; + result.header = { + target, + formatVersion : 5, + compressed : compressed ? ( (target === 'a' || target === 'i') ? 0x40 : 0x80 ) : 0, + hidef + } + result.readers = deepCopy(readerData); + + // set content data + result.content = convertJsonContentsFromXnbNode(json.content); + + // this program uses verticalLineSpacing, not verticalSpacing + if( TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont' ) + { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; +} + +export {toXnbNodeData, fromXnbNodeData}; \ No newline at end of file diff --git a/src/core/Xnb.js b/src/core/Xnb.js new file mode 100644 index 0000000..0c94930 --- /dev/null +++ b/src/core/Xnb.js @@ -0,0 +1,210 @@ +import TypeReader from "./App/Readers/TypeReader.js"; +import XnbConverter from "./App/XnbConverter.js"; +import {XnbData, XnbContent} from "./App/XnbData.js"; +import {exportFiles, exportContent, resolveImports, extractFileName} from "./Files.js"; + +/*----------------------------------------------------------------------------*/ +/*................................Unpack XNB..................................*/ +/*----------------------------------------------------------------------------*/ + +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ +async function unpackToXnbData(file) +{ + // browser + if( typeof window !== "undefined" ) { + // ensure that the input file has the right extension + const [,extension] = extractFileName(file.name); + + if(extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + //read the file as a binary file + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + // node.js + return bufferToXnb(file.buffer); +} + +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ +function unpackToContent(file) +{ + return unpackToXnbData(file).then(xnbDataToContent); +} + +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ +function unpackToFiles(file, configs={}) +{ + let {yaml=false, contentOnly=false, fileName:name=null} = configs; + if(typeof window !== "undefined" && name === null) name = file.name; + + let [fileName] = extractFileName(name); + const exporter = xnbObject => exportFiles(xnbObject, {yaml, contentOnly, fileName}); + return unpackToXnbData(file).then(exporter); +} + + +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ +function bufferToXnb(buffer) +{ + const xnb = new XnbConverter(); + return xnb.load(buffer); +} + +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ +function bufferToContents(buffer) +{ + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} + +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ +function xnbDataToContent(loadedXnb) +{ + const {content} = loadedXnb; + const {data, extension} = exportContent(content, true); + return new XnbContent(data, extension); +} + + + +/*----------------------------------------------------------------------------*/ +/*.................................Pack XNB...................................*/ +/*----------------------------------------------------------------------------*/ + +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ +function fileMapper(files) +{ + let returnMap = {}; + for(let i=0; i{ + //blob is avaliable + if(typeof Blob === "function") return { + name:fileName, + data:new Blob([buffer], {type : "application/octet-stream"}) + }; + return { + name:fileName, + data:new Uint8Array(buffer) + }; + }) + ); + } + return Promise.allSettled(promises).then(blobArray => { + if(configs.debug === true) return blobArray; + + return blobArray.filter( ({status, value})=>status === "fulfilled" ) + .map( ({value})=>value ); + }); +} + + +/*----------------------------------------------------------------------------*/ +/*..............................Readers Plugins...............................*/ +/*----------------------------------------------------------------------------*/ + +function setReaders(readers) +{ + return TypeReader.setReaders(readers); +} +function addReaders(readers) +{ + return TypeReader.addReaders(readers); +} + +export { + setReaders, + addReaders, + + unpackToXnbData, + unpackToContent, + unpackToFiles, + + bufferToXnb, + bufferToContents, + + xnbDataToContent, + exportFiles as xnbDataToFiles, + pack, + XnbData, + XnbContent +}; diff --git a/src/core/dist/core.cjs b/src/core/dist/core.cjs new file mode 100644 index 0000000..24ea9cb --- /dev/null +++ b/src/core/dist/core.cjs @@ -0,0 +1,5356 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); +}; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + +const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES = 0x80; +const UTF8_MASK = 0b111111; +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; + +function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; +} + +function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; +} + +function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); +} + +function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; +} + +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; +} + +function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; +} + +function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; +} + +function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); +} + +function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); +} + +const LITTLE_ENDIAN = true; + +class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + +} + +class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + +} + +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ +const MIN_MATCH = 2; +const NUM_CHARS = 256; +const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 +}; +const PRETREE_NUM_ELEMENTS = 20; +const ALIGNED_NUM_ELEMENTS = 8; +const NUM_PRIMARY_LENGTHS = 7; +const NUM_SECONDARY_LENGTHS = 249; +const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; +const PRETREE_TABLEBITS = 6; +const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; +const MAINTREE_TABLEBITS = 12; +const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; +const LENGTH_TABLEBITS = 12; +const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; +const ALIGNED_TABLEBITS = 7; + +class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + +} + +Lzx.position_base = []; +Lzx.extra_bits = []; + +class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + +} + +class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + +} + +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ +const minMatch = 4; +const minLength = 13; +const searchLimit = 5; +const skipTrigger = 6; +const hashSize = 1 << 16; +const mlBits = 4; +const mlMask = (1 << mlBits) - 1; +const runBits = 4; +const runMask = (1 << runBits) - 1; +makeBuffer(5 << 20); +const hashTable = makeHashTable(); + +function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } +} + +function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } +} + +function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } +} + +function compressBound(n) { + return n + n / 255 + 16 | 0; +} + +function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; +} + +function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; +} + +function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + +} + +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + +} + +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + +} + +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; +} + +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + +} + +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + +} + +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } +}, + e = {}; + +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; +} + +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; + +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); + +var r = n.P, + s = n.m; + +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} + +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} + +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); +} + +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + +} + +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; +} + +function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; +} + +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} + +function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; +} + +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } +} + +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } +} + +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; +} + +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} + +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; +} + +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; +} + +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} + +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; +} + +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; +} + +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} + +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} + +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} + +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} + +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} + +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} + +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; +} + +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + +function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} + +function setReaders(readers) { + return TypeReader.setReaders(readers); +} + +function addReaders(readers) { + return TypeReader.addReaders(readers); +} + +exports.XnbContent = XnbContent; +exports.XnbData = XnbData; +exports.addReaders = addReaders; +exports.bufferToContents = bufferToContents; +exports.bufferToXnb = bufferToXnb; +exports.pack = pack; +exports.setReaders = setReaders; +exports.unpackToContent = unpackToContent; +exports.unpackToFiles = unpackToFiles; +exports.unpackToXnbData = unpackToXnbData; +exports.xnbDataToContent = xnbDataToContent; +exports.xnbDataToFiles = exportFiles; diff --git a/src/core/dist/core.es5.js b/src/core/dist/core.es5.js new file mode 100644 index 0000000..d35782b --- /dev/null +++ b/src/core/dist/core.es5.js @@ -0,0 +1,9250 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + var check = function (it) { + return it && it.Math == Math && it; + }; + + // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + var global$A = + // eslint-disable-next-line es-x/no-global-this -- safe + check(typeof globalThis == 'object' && globalThis) || + check(typeof window == 'object' && window) || + // eslint-disable-next-line no-restricted-globals -- safe + check(typeof self == 'object' && self) || + check(typeof commonjsGlobal == 'object' && commonjsGlobal) || + // eslint-disable-next-line no-new-func -- fallback + (function () { return this; })() || Function('return this')(); + + var objectGetOwnPropertyDescriptor = {}; + + var fails$a = function (exec) { + try { + return !!exec(); + } catch (error) { + return true; + } + }; + + var fails$9 = fails$a; + + // Detect IE8's incomplete defineProperty implementation + var descriptors = !fails$9(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7; + }); + + var fails$8 = fails$a; + + var functionBindNative = !fails$8(function () { + // eslint-disable-next-line es-x/no-function-prototype-bind -- safe + var test = (function () { /* empty */ }).bind(); + // eslint-disable-next-line no-prototype-builtins -- safe + return typeof test != 'function' || test.hasOwnProperty('prototype'); + }); + + var NATIVE_BIND$3 = functionBindNative; + + var call$c = Function.prototype.call; + + var functionCall = NATIVE_BIND$3 ? call$c.bind(call$c) : function () { + return call$c.apply(call$c, arguments); + }; + + var objectPropertyIsEnumerable = {}; + + var $propertyIsEnumerable = {}.propertyIsEnumerable; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getOwnPropertyDescriptor$2 = Object.getOwnPropertyDescriptor; + + // Nashorn ~ JDK8 bug + var NASHORN_BUG = getOwnPropertyDescriptor$2 && !$propertyIsEnumerable.call({ 1: 2 }, 1); + + // `Object.prototype.propertyIsEnumerable` method implementation + // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable + objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) { + var descriptor = getOwnPropertyDescriptor$2(this, V); + return !!descriptor && descriptor.enumerable; + } : $propertyIsEnumerable; + + var createPropertyDescriptor$2 = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; + }; + + var NATIVE_BIND$2 = functionBindNative; + + var FunctionPrototype$2 = Function.prototype; + var bind$5 = FunctionPrototype$2.bind; + var call$b = FunctionPrototype$2.call; + var uncurryThis$d = NATIVE_BIND$2 && bind$5.bind(call$b, call$b); + + var functionUncurryThis = NATIVE_BIND$2 ? function (fn) { + return fn && uncurryThis$d(fn); + } : function (fn) { + return fn && function () { + return call$b.apply(fn, arguments); + }; + }; + + var uncurryThis$c = functionUncurryThis; + + var toString$1 = uncurryThis$c({}.toString); + var stringSlice = uncurryThis$c(''.slice); + + var classofRaw$1 = function (it) { + return stringSlice(toString$1(it), 8, -1); + }; + + var global$z = global$A; + var uncurryThis$b = functionUncurryThis; + var fails$7 = fails$a; + var classof$4 = classofRaw$1; + + var Object$4 = global$z.Object; + var split = uncurryThis$b(''.split); + + // fallback for non-array-like ES3 and non-enumerable old V8 strings + var indexedObject = fails$7(function () { + // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 + // eslint-disable-next-line no-prototype-builtins -- safe + return !Object$4('z').propertyIsEnumerable(0); + }) ? function (it) { + return classof$4(it) == 'String' ? split(it, '') : Object$4(it); + } : Object$4; + + var global$y = global$A; + + var TypeError$e = global$y.TypeError; + + // `RequireObjectCoercible` abstract operation + // https://tc39.es/ecma262/#sec-requireobjectcoercible + var requireObjectCoercible$2 = function (it) { + if (it == undefined) throw TypeError$e("Can't call method on " + it); + return it; + }; + + // toObject with fallback for non-array-like ES3 strings + var IndexedObject = indexedObject; + var requireObjectCoercible$1 = requireObjectCoercible$2; + + var toIndexedObject$3 = function (it) { + return IndexedObject(requireObjectCoercible$1(it)); + }; + + // `IsCallable` abstract operation + // https://tc39.es/ecma262/#sec-iscallable + var isCallable$h = function (argument) { + return typeof argument == 'function'; + }; + + var isCallable$g = isCallable$h; + + var isObject$7 = function (it) { + return typeof it == 'object' ? it !== null : isCallable$g(it); + }; + + var global$x = global$A; + var isCallable$f = isCallable$h; + + var aFunction = function (argument) { + return isCallable$f(argument) ? argument : undefined; + }; + + var getBuiltIn$8 = function (namespace, method) { + return arguments.length < 2 ? aFunction(global$x[namespace]) : global$x[namespace] && global$x[namespace][method]; + }; + + var uncurryThis$a = functionUncurryThis; + + var objectIsPrototypeOf = uncurryThis$a({}.isPrototypeOf); + + var getBuiltIn$7 = getBuiltIn$8; + + var engineUserAgent = getBuiltIn$7('navigator', 'userAgent') || ''; + + var global$w = global$A; + var userAgent$3 = engineUserAgent; + + var process$3 = global$w.process; + var Deno$1 = global$w.Deno; + var versions = process$3 && process$3.versions || Deno$1 && Deno$1.version; + var v8 = versions && versions.v8; + var match, version; + + if (v8) { + match = v8.split('.'); + // in old Chrome, versions of V8 isn't V8 = Chrome / 10 + // but their correct versions are not interesting for us + version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); + } + + // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` + // so check `userAgent` even if `.v8` exists, but 0 + if (!version && userAgent$3) { + match = userAgent$3.match(/Edge\/(\d+)/); + if (!match || match[1] >= 74) { + match = userAgent$3.match(/Chrome\/(\d+)/); + if (match) version = +match[1]; + } + } + + var engineV8Version = version; + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var V8_VERSION$1 = engineV8Version; + var fails$6 = fails$a; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- required for testing + var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$6(function () { + var symbol = Symbol(); + // Chrome 38 Symbol has incorrect toString conversion + // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances + return !String(symbol) || !(Object(symbol) instanceof Symbol) || + // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances + !Symbol.sham && V8_VERSION$1 && V8_VERSION$1 < 41; + }); + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var NATIVE_SYMBOL$1 = nativeSymbol; + + var useSymbolAsUid = NATIVE_SYMBOL$1 + && !Symbol.sham + && typeof Symbol.iterator == 'symbol'; + + var global$v = global$A; + var getBuiltIn$6 = getBuiltIn$8; + var isCallable$e = isCallable$h; + var isPrototypeOf$2 = objectIsPrototypeOf; + var USE_SYMBOL_AS_UID$1 = useSymbolAsUid; + + var Object$3 = global$v.Object; + + var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) { + return typeof it == 'symbol'; + } : function (it) { + var $Symbol = getBuiltIn$6('Symbol'); + return isCallable$e($Symbol) && isPrototypeOf$2($Symbol.prototype, Object$3(it)); + }; + + var global$u = global$A; + + var String$4 = global$u.String; + + var tryToString$4 = function (argument) { + try { + return String$4(argument); + } catch (error) { + return 'Object'; + } + }; + + var global$t = global$A; + var isCallable$d = isCallable$h; + var tryToString$3 = tryToString$4; + + var TypeError$d = global$t.TypeError; + + // `Assert: IsCallable(argument) is true` + var aCallable$7 = function (argument) { + if (isCallable$d(argument)) return argument; + throw TypeError$d(tryToString$3(argument) + ' is not a function'); + }; + + var aCallable$6 = aCallable$7; + + // `GetMethod` abstract operation + // https://tc39.es/ecma262/#sec-getmethod + var getMethod$3 = function (V, P) { + var func = V[P]; + return func == null ? undefined : aCallable$6(func); + }; + + var global$s = global$A; + var call$a = functionCall; + var isCallable$c = isCallable$h; + var isObject$6 = isObject$7; + + var TypeError$c = global$s.TypeError; + + // `OrdinaryToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-ordinarytoprimitive + var ordinaryToPrimitive$1 = function (input, pref) { + var fn, val; + if (pref === 'string' && isCallable$c(fn = input.toString) && !isObject$6(val = call$a(fn, input))) return val; + if (isCallable$c(fn = input.valueOf) && !isObject$6(val = call$a(fn, input))) return val; + if (pref !== 'string' && isCallable$c(fn = input.toString) && !isObject$6(val = call$a(fn, input))) return val; + throw TypeError$c("Can't convert object to primitive value"); + }; + + var shared$3 = {exports: {}}; + + var global$r = global$A; + + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var defineProperty$2 = Object.defineProperty; + + var setGlobal$3 = function (key, value) { + try { + defineProperty$2(global$r, key, { value: value, configurable: true, writable: true }); + } catch (error) { + global$r[key] = value; + } return value; + }; + + var global$q = global$A; + var setGlobal$2 = setGlobal$3; + + var SHARED = '__core-js_shared__'; + var store$3 = global$q[SHARED] || setGlobal$2(SHARED, {}); + + var sharedStore = store$3; + + var store$2 = sharedStore; + + (shared$3.exports = function (key, value) { + return store$2[key] || (store$2[key] = value !== undefined ? value : {}); + })('versions', []).push({ + version: '3.22.4', + mode: 'global', + copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)', + license: 'https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE', + source: 'https://github.com/zloirock/core-js' + }); + + var global$p = global$A; + var requireObjectCoercible = requireObjectCoercible$2; + + var Object$2 = global$p.Object; + + // `ToObject` abstract operation + // https://tc39.es/ecma262/#sec-toobject + var toObject$1 = function (argument) { + return Object$2(requireObjectCoercible(argument)); + }; + + var uncurryThis$9 = functionUncurryThis; + var toObject = toObject$1; + + var hasOwnProperty = uncurryThis$9({}.hasOwnProperty); + + // `HasOwnProperty` abstract operation + // https://tc39.es/ecma262/#sec-hasownproperty + // eslint-disable-next-line es-x/no-object-hasown -- safe + var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) { + return hasOwnProperty(toObject(it), key); + }; + + var uncurryThis$8 = functionUncurryThis; + + var id = 0; + var postfix = Math.random(); + var toString = uncurryThis$8(1.0.toString); + + var uid$2 = function (key) { + return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36); + }; + + var global$o = global$A; + var shared$2 = shared$3.exports; + var hasOwn$8 = hasOwnProperty_1; + var uid$1 = uid$2; + var NATIVE_SYMBOL = nativeSymbol; + var USE_SYMBOL_AS_UID = useSymbolAsUid; + + var WellKnownSymbolsStore = shared$2('wks'); + var Symbol$1 = global$o.Symbol; + var symbolFor = Symbol$1 && Symbol$1['for']; + var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1; + + var wellKnownSymbol$a = function (name) { + if (!hasOwn$8(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) { + var description = 'Symbol.' + name; + if (NATIVE_SYMBOL && hasOwn$8(Symbol$1, name)) { + WellKnownSymbolsStore[name] = Symbol$1[name]; + } else if (USE_SYMBOL_AS_UID && symbolFor) { + WellKnownSymbolsStore[name] = symbolFor(description); + } else { + WellKnownSymbolsStore[name] = createWellKnownSymbol(description); + } + } return WellKnownSymbolsStore[name]; + }; + + var global$n = global$A; + var call$9 = functionCall; + var isObject$5 = isObject$7; + var isSymbol$1 = isSymbol$2; + var getMethod$2 = getMethod$3; + var ordinaryToPrimitive = ordinaryToPrimitive$1; + var wellKnownSymbol$9 = wellKnownSymbol$a; + + var TypeError$b = global$n.TypeError; + var TO_PRIMITIVE = wellKnownSymbol$9('toPrimitive'); + + // `ToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-toprimitive + var toPrimitive$1 = function (input, pref) { + if (!isObject$5(input) || isSymbol$1(input)) return input; + var exoticToPrim = getMethod$2(input, TO_PRIMITIVE); + var result; + if (exoticToPrim) { + if (pref === undefined) pref = 'default'; + result = call$9(exoticToPrim, input, pref); + if (!isObject$5(result) || isSymbol$1(result)) return result; + throw TypeError$b("Can't convert object to primitive value"); + } + if (pref === undefined) pref = 'number'; + return ordinaryToPrimitive(input, pref); + }; + + var toPrimitive = toPrimitive$1; + var isSymbol = isSymbol$2; + + // `ToPropertyKey` abstract operation + // https://tc39.es/ecma262/#sec-topropertykey + var toPropertyKey$2 = function (argument) { + var key = toPrimitive(argument, 'string'); + return isSymbol(key) ? key : key + ''; + }; + + var global$m = global$A; + var isObject$4 = isObject$7; + + var document$2 = global$m.document; + // typeof document.createElement is 'object' in old IE + var EXISTS$1 = isObject$4(document$2) && isObject$4(document$2.createElement); + + var documentCreateElement = function (it) { + return EXISTS$1 ? document$2.createElement(it) : {}; + }; + + var DESCRIPTORS$6 = descriptors; + var fails$5 = fails$a; + var createElement$1 = documentCreateElement; + + // Thanks to IE8 for its funny defineProperty + var ie8DomDefine = !DESCRIPTORS$6 && !fails$5(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(createElement$1('div'), 'a', { + get: function () { return 7; } + }).a != 7; + }); + + var DESCRIPTORS$5 = descriptors; + var call$8 = functionCall; + var propertyIsEnumerableModule = objectPropertyIsEnumerable; + var createPropertyDescriptor$1 = createPropertyDescriptor$2; + var toIndexedObject$2 = toIndexedObject$3; + var toPropertyKey$1 = toPropertyKey$2; + var hasOwn$7 = hasOwnProperty_1; + var IE8_DOM_DEFINE$1 = ie8DomDefine; + + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor; + + // `Object.getOwnPropertyDescriptor` method + // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor + objectGetOwnPropertyDescriptor.f = DESCRIPTORS$5 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) { + O = toIndexedObject$2(O); + P = toPropertyKey$1(P); + if (IE8_DOM_DEFINE$1) try { + return $getOwnPropertyDescriptor$1(O, P); + } catch (error) { /* empty */ } + if (hasOwn$7(O, P)) return createPropertyDescriptor$1(!call$8(propertyIsEnumerableModule.f, O, P), O[P]); + }; + + var objectDefineProperty = {}; + + var DESCRIPTORS$4 = descriptors; + var fails$4 = fails$a; + + // V8 ~ Chrome 36- + // https://bugs.chromium.org/p/v8/issues/detail?id=3334 + var v8PrototypeDefineBug = DESCRIPTORS$4 && fails$4(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(function () { /* empty */ }, 'prototype', { + value: 42, + writable: false + }).prototype != 42; + }); + + var global$l = global$A; + var isObject$3 = isObject$7; + + var String$3 = global$l.String; + var TypeError$a = global$l.TypeError; + + // `Assert: Type(argument) is Object` + var anObject$8 = function (argument) { + if (isObject$3(argument)) return argument; + throw TypeError$a(String$3(argument) + ' is not an object'); + }; + + var global$k = global$A; + var DESCRIPTORS$3 = descriptors; + var IE8_DOM_DEFINE = ie8DomDefine; + var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; + var anObject$7 = anObject$8; + var toPropertyKey = toPropertyKey$2; + + var TypeError$9 = global$k.TypeError; + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var $defineProperty = Object.defineProperty; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ENUMERABLE = 'enumerable'; + var CONFIGURABLE$1 = 'configurable'; + var WRITABLE = 'writable'; + + // `Object.defineProperty` method + // https://tc39.es/ecma262/#sec-object.defineproperty + objectDefineProperty.f = DESCRIPTORS$3 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { + anObject$7(O); + P = toPropertyKey(P); + anObject$7(Attributes); + if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { + var current = $getOwnPropertyDescriptor(O, P); + if (current && current[WRITABLE]) { + O[P] = Attributes.value; + Attributes = { + configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1], + enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], + writable: false + }; + } + } return $defineProperty(O, P, Attributes); + } : $defineProperty : function defineProperty(O, P, Attributes) { + anObject$7(O); + P = toPropertyKey(P); + anObject$7(Attributes); + if (IE8_DOM_DEFINE) try { + return $defineProperty(O, P, Attributes); + } catch (error) { /* empty */ } + if ('get' in Attributes || 'set' in Attributes) throw TypeError$9('Accessors not supported'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; + }; + + var DESCRIPTORS$2 = descriptors; + var definePropertyModule$2 = objectDefineProperty; + var createPropertyDescriptor = createPropertyDescriptor$2; + + var createNonEnumerableProperty$3 = DESCRIPTORS$2 ? function (object, key, value) { + return definePropertyModule$2.f(object, key, createPropertyDescriptor(1, value)); + } : function (object, key, value) { + object[key] = value; + return object; + }; + + var makeBuiltIn$2 = {exports: {}}; + + var DESCRIPTORS$1 = descriptors; + var hasOwn$6 = hasOwnProperty_1; + + var FunctionPrototype$1 = Function.prototype; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getDescriptor = DESCRIPTORS$1 && Object.getOwnPropertyDescriptor; + + var EXISTS = hasOwn$6(FunctionPrototype$1, 'name'); + // additional protection from minified / mangled / dropped function names + var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; + var CONFIGURABLE = EXISTS && (!DESCRIPTORS$1 || (DESCRIPTORS$1 && getDescriptor(FunctionPrototype$1, 'name').configurable)); + + var functionName = { + EXISTS: EXISTS, + PROPER: PROPER, + CONFIGURABLE: CONFIGURABLE + }; + + var uncurryThis$7 = functionUncurryThis; + var isCallable$b = isCallable$h; + var store$1 = sharedStore; + + var functionToString = uncurryThis$7(Function.toString); + + // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper + if (!isCallable$b(store$1.inspectSource)) { + store$1.inspectSource = function (it) { + return functionToString(it); + }; + } + + var inspectSource$4 = store$1.inspectSource; + + var global$j = global$A; + var isCallable$a = isCallable$h; + var inspectSource$3 = inspectSource$4; + + var WeakMap$1 = global$j.WeakMap; + + var nativeWeakMap = isCallable$a(WeakMap$1) && /native code/.test(inspectSource$3(WeakMap$1)); + + var shared$1 = shared$3.exports; + var uid = uid$2; + + var keys = shared$1('keys'); + + var sharedKey$1 = function (key) { + return keys[key] || (keys[key] = uid(key)); + }; + + var hiddenKeys$3 = {}; + + var NATIVE_WEAK_MAP = nativeWeakMap; + var global$i = global$A; + var uncurryThis$6 = functionUncurryThis; + var isObject$2 = isObject$7; + var createNonEnumerableProperty$2 = createNonEnumerableProperty$3; + var hasOwn$5 = hasOwnProperty_1; + var shared = sharedStore; + var sharedKey = sharedKey$1; + var hiddenKeys$2 = hiddenKeys$3; + + var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; + var TypeError$8 = global$i.TypeError; + var WeakMap = global$i.WeakMap; + var set$1, get, has; + + var enforce = function (it) { + return has(it) ? get(it) : set$1(it, {}); + }; + + var getterFor = function (TYPE) { + return function (it) { + var state; + if (!isObject$2(it) || (state = get(it)).type !== TYPE) { + throw TypeError$8('Incompatible receiver, ' + TYPE + ' required'); + } return state; + }; + }; + + if (NATIVE_WEAK_MAP || shared.state) { + var store = shared.state || (shared.state = new WeakMap()); + var wmget = uncurryThis$6(store.get); + var wmhas = uncurryThis$6(store.has); + var wmset = uncurryThis$6(store.set); + set$1 = function (it, metadata) { + if (wmhas(store, it)) throw new TypeError$8(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + wmset(store, it, metadata); + return metadata; + }; + get = function (it) { + return wmget(store, it) || {}; + }; + has = function (it) { + return wmhas(store, it); + }; + } else { + var STATE = sharedKey('state'); + hiddenKeys$2[STATE] = true; + set$1 = function (it, metadata) { + if (hasOwn$5(it, STATE)) throw new TypeError$8(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + createNonEnumerableProperty$2(it, STATE, metadata); + return metadata; + }; + get = function (it) { + return hasOwn$5(it, STATE) ? it[STATE] : {}; + }; + has = function (it) { + return hasOwn$5(it, STATE); + }; + } + + var internalState = { + set: set$1, + get: get, + has: has, + enforce: enforce, + getterFor: getterFor + }; + + var fails$3 = fails$a; + var isCallable$9 = isCallable$h; + var hasOwn$4 = hasOwnProperty_1; + var defineProperty$1 = objectDefineProperty.f; + var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE; + var inspectSource$2 = inspectSource$4; + var InternalStateModule$1 = internalState; + + var enforceInternalState = InternalStateModule$1.enforce; + var getInternalState = InternalStateModule$1.get; + + var CONFIGURABLE_LENGTH = !fails$3(function () { + return defineProperty$1(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; + }); + + var TEMPLATE = String(String).split('String'); + + var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) { + if (String(name).slice(0, 7) === 'Symbol(') { + name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']'; + } + if (options && options.getter) name = 'get ' + name; + if (options && options.setter) name = 'set ' + name; + if (!hasOwn$4(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { + defineProperty$1(value, 'name', { value: name, configurable: true }); + } + if (CONFIGURABLE_LENGTH && options && hasOwn$4(options, 'arity') && value.length !== options.arity) { + defineProperty$1(value, 'length', { value: options.arity }); + } + var state = enforceInternalState(value); + if (!hasOwn$4(state, 'source')) { + state.source = TEMPLATE.join(typeof name == 'string' ? name : ''); + } return value; + }; + + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + // eslint-disable-next-line no-extend-native -- required + Function.prototype.toString = makeBuiltIn$1(function toString() { + return isCallable$9(this) && getInternalState(this).source || inspectSource$2(this); + }, 'toString'); + + var global$h = global$A; + var isCallable$8 = isCallable$h; + var createNonEnumerableProperty$1 = createNonEnumerableProperty$3; + var makeBuiltIn = makeBuiltIn$2.exports; + var setGlobal$1 = setGlobal$3; + + var defineBuiltIn$3 = function (O, key, value, options) { + var unsafe = options ? !!options.unsafe : false; + var simple = options ? !!options.enumerable : false; + var noTargetGet = options ? !!options.noTargetGet : false; + var name = options && options.name !== undefined ? options.name : key; + if (isCallable$8(value)) makeBuiltIn(value, name, options); + if (O === global$h) { + if (simple) O[key] = value; + else setGlobal$1(key, value); + return O; + } else if (!unsafe) { + delete O[key]; + } else if (!noTargetGet && O[key]) { + simple = true; + } + if (simple) O[key] = value; + else createNonEnumerableProperty$1(O, key, value); + return O; + }; + + var objectGetOwnPropertyNames = {}; + + var ceil = Math.ceil; + var floor = Math.floor; + + // `ToIntegerOrInfinity` abstract operation + // https://tc39.es/ecma262/#sec-tointegerorinfinity + var toIntegerOrInfinity$2 = function (argument) { + var number = +argument; + // eslint-disable-next-line no-self-compare -- safe + return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil)(number); + }; + + var toIntegerOrInfinity$1 = toIntegerOrInfinity$2; + + var max = Math.max; + var min$1 = Math.min; + + // Helper for a popular repeating case of the spec: + // Let integer be ? ToInteger(index). + // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). + var toAbsoluteIndex$1 = function (index, length) { + var integer = toIntegerOrInfinity$1(index); + return integer < 0 ? max(integer + length, 0) : min$1(integer, length); + }; + + var toIntegerOrInfinity = toIntegerOrInfinity$2; + + var min = Math.min; + + // `ToLength` abstract operation + // https://tc39.es/ecma262/#sec-tolength + var toLength$1 = function (argument) { + return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 + }; + + var toLength = toLength$1; + + // `LengthOfArrayLike` abstract operation + // https://tc39.es/ecma262/#sec-lengthofarraylike + var lengthOfArrayLike$2 = function (obj) { + return toLength(obj.length); + }; + + var toIndexedObject$1 = toIndexedObject$3; + var toAbsoluteIndex = toAbsoluteIndex$1; + var lengthOfArrayLike$1 = lengthOfArrayLike$2; + + // `Array.prototype.{ indexOf, includes }` methods implementation + var createMethod = function (IS_INCLUDES) { + return function ($this, el, fromIndex) { + var O = toIndexedObject$1($this); + var length = lengthOfArrayLike$1(O); + var index = toAbsoluteIndex(fromIndex, length); + var value; + // Array#includes uses SameValueZero equality algorithm + // eslint-disable-next-line no-self-compare -- NaN check + if (IS_INCLUDES && el != el) while (length > index) { + value = O[index++]; + // eslint-disable-next-line no-self-compare -- NaN check + if (value != value) return true; + // Array#indexOf ignores holes, Array#includes - not + } else for (;length > index; index++) { + if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; + } return !IS_INCLUDES && -1; + }; + }; + + var arrayIncludes = { + // `Array.prototype.includes` method + // https://tc39.es/ecma262/#sec-array.prototype.includes + includes: createMethod(true), + // `Array.prototype.indexOf` method + // https://tc39.es/ecma262/#sec-array.prototype.indexof + indexOf: createMethod(false) + }; + + var uncurryThis$5 = functionUncurryThis; + var hasOwn$3 = hasOwnProperty_1; + var toIndexedObject = toIndexedObject$3; + var indexOf = arrayIncludes.indexOf; + var hiddenKeys$1 = hiddenKeys$3; + + var push = uncurryThis$5([].push); + + var objectKeysInternal = function (object, names) { + var O = toIndexedObject(object); + var i = 0; + var result = []; + var key; + for (key in O) !hasOwn$3(hiddenKeys$1, key) && hasOwn$3(O, key) && push(result, key); + // Don't enum bug & hidden keys + while (names.length > i) if (hasOwn$3(O, key = names[i++])) { + ~indexOf(result, key) || push(result, key); + } + return result; + }; + + // IE8- don't enum bug keys + var enumBugKeys$1 = [ + 'constructor', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'valueOf' + ]; + + var internalObjectKeys = objectKeysInternal; + var enumBugKeys = enumBugKeys$1; + + var hiddenKeys = enumBugKeys.concat('length', 'prototype'); + + // `Object.getOwnPropertyNames` method + // https://tc39.es/ecma262/#sec-object.getownpropertynames + // eslint-disable-next-line es-x/no-object-getownpropertynames -- safe + objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { + return internalObjectKeys(O, hiddenKeys); + }; + + var objectGetOwnPropertySymbols = {}; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- safe + objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols; + + var getBuiltIn$5 = getBuiltIn$8; + var uncurryThis$4 = functionUncurryThis; + var getOwnPropertyNamesModule = objectGetOwnPropertyNames; + var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols; + var anObject$6 = anObject$8; + + var concat = uncurryThis$4([].concat); + + // all object keys, includes non-enumerable and symbols + var ownKeys$2 = getBuiltIn$5('Reflect', 'ownKeys') || function ownKeys(it) { + var keys = getOwnPropertyNamesModule.f(anObject$6(it)); + var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; + return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys; + }; + + var hasOwn$2 = hasOwnProperty_1; + var ownKeys$1 = ownKeys$2; + var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor; + var definePropertyModule$1 = objectDefineProperty; + + var copyConstructorProperties$1 = function (target, source, exceptions) { + var keys = ownKeys$1(source); + var defineProperty = definePropertyModule$1.f; + var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (!hasOwn$2(target, key) && !(exceptions && hasOwn$2(exceptions, key))) { + defineProperty(target, key, getOwnPropertyDescriptor(source, key)); + } + } + }; + + var fails$2 = fails$a; + var isCallable$7 = isCallable$h; + + var replacement = /#|\.prototype\./; + + var isForced$2 = function (feature, detection) { + var value = data[normalize(feature)]; + return value == POLYFILL ? true + : value == NATIVE ? false + : isCallable$7(detection) ? fails$2(detection) + : !!detection; + }; + + var normalize = isForced$2.normalize = function (string) { + return String(string).replace(replacement, '.').toLowerCase(); + }; + + var data = isForced$2.data = {}; + var NATIVE = isForced$2.NATIVE = 'N'; + var POLYFILL = isForced$2.POLYFILL = 'P'; + + var isForced_1 = isForced$2; + + var global$g = global$A; + var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f; + var createNonEnumerableProperty = createNonEnumerableProperty$3; + var defineBuiltIn$2 = defineBuiltIn$3; + var setGlobal = setGlobal$3; + var copyConstructorProperties = copyConstructorProperties$1; + var isForced$1 = isForced_1; + + /* + options.target - name of the target object + options.global - target is the global object + options.stat - export as static methods of target + options.proto - export as prototype methods of target + options.real - real prototype method for the `pure` version + options.forced - export even if the native feature is available + options.bind - bind methods to the target, required for the `pure` version + options.wrap - wrap constructors to preventing global pollution, required for the `pure` version + options.unsafe - use the simple assignment of property instead of delete + defineProperty + options.sham - add a flag to not completely full polyfills + options.enumerable - export as enumerable property + options.noTargetGet - prevent calling a getter on target + options.name - the .name of the function if it does not match the key + */ + var _export = function (options, source) { + var TARGET = options.target; + var GLOBAL = options.global; + var STATIC = options.stat; + var FORCED, target, key, targetProperty, sourceProperty, descriptor; + if (GLOBAL) { + target = global$g; + } else if (STATIC) { + target = global$g[TARGET] || setGlobal(TARGET, {}); + } else { + target = (global$g[TARGET] || {}).prototype; + } + if (target) for (key in source) { + sourceProperty = source[key]; + if (options.noTargetGet) { + descriptor = getOwnPropertyDescriptor$1(target, key); + targetProperty = descriptor && descriptor.value; + } else targetProperty = target[key]; + FORCED = isForced$1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); + // contained in target + if (!FORCED && targetProperty !== undefined) { + if (typeof sourceProperty == typeof targetProperty) continue; + copyConstructorProperties(sourceProperty, targetProperty); + } + // add a flag to not completely full polyfills + if (options.sham || (targetProperty && targetProperty.sham)) { + createNonEnumerableProperty(sourceProperty, 'sham', true); + } + defineBuiltIn$2(target, key, sourceProperty, options); + } + }; + + var classof$3 = classofRaw$1; + var global$f = global$A; + + var engineIsNode = classof$3(global$f.process) == 'process'; + + var global$e = global$A; + var isCallable$6 = isCallable$h; + + var String$2 = global$e.String; + var TypeError$7 = global$e.TypeError; + + var aPossiblePrototype$1 = function (argument) { + if (typeof argument == 'object' || isCallable$6(argument)) return argument; + throw TypeError$7("Can't set " + String$2(argument) + ' as a prototype'); + }; + + /* eslint-disable no-proto -- safe */ + + var uncurryThis$3 = functionUncurryThis; + var anObject$5 = anObject$8; + var aPossiblePrototype = aPossiblePrototype$1; + + // `Object.setPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.setprototypeof + // Works with __proto__ only. Old v8 can't work with null proto objects. + // eslint-disable-next-line es-x/no-object-setprototypeof -- safe + var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + setter = uncurryThis$3(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); + setter(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { /* empty */ } + return function setPrototypeOf(O, proto) { + anObject$5(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) setter(O, proto); + else O.__proto__ = proto; + return O; + }; + }() : undefined); + + var defineProperty = objectDefineProperty.f; + var hasOwn$1 = hasOwnProperty_1; + var wellKnownSymbol$8 = wellKnownSymbol$a; + + var TO_STRING_TAG$2 = wellKnownSymbol$8('toStringTag'); + + var setToStringTag$1 = function (target, TAG, STATIC) { + if (target && !STATIC) target = target.prototype; + if (target && !hasOwn$1(target, TO_STRING_TAG$2)) { + defineProperty(target, TO_STRING_TAG$2, { configurable: true, value: TAG }); + } + }; + + var getBuiltIn$4 = getBuiltIn$8; + var definePropertyModule = objectDefineProperty; + var wellKnownSymbol$7 = wellKnownSymbol$a; + var DESCRIPTORS = descriptors; + + var SPECIES$2 = wellKnownSymbol$7('species'); + + var setSpecies$1 = function (CONSTRUCTOR_NAME) { + var Constructor = getBuiltIn$4(CONSTRUCTOR_NAME); + var defineProperty = definePropertyModule.f; + + if (DESCRIPTORS && Constructor && !Constructor[SPECIES$2]) { + defineProperty(Constructor, SPECIES$2, { + configurable: true, + get: function () { return this; } + }); + } + }; + + var global$d = global$A; + var isPrototypeOf$1 = objectIsPrototypeOf; + + var TypeError$6 = global$d.TypeError; + + var anInstance$1 = function (it, Prototype) { + if (isPrototypeOf$1(Prototype, it)) return it; + throw TypeError$6('Incorrect invocation'); + }; + + var wellKnownSymbol$6 = wellKnownSymbol$a; + + var TO_STRING_TAG$1 = wellKnownSymbol$6('toStringTag'); + var test = {}; + + test[TO_STRING_TAG$1] = 'z'; + + var toStringTagSupport = String(test) === '[object z]'; + + var global$c = global$A; + var TO_STRING_TAG_SUPPORT = toStringTagSupport; + var isCallable$5 = isCallable$h; + var classofRaw = classofRaw$1; + var wellKnownSymbol$5 = wellKnownSymbol$a; + + var TO_STRING_TAG = wellKnownSymbol$5('toStringTag'); + var Object$1 = global$c.Object; + + // ES3 wrong here + var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments'; + + // fallback for IE11 Script Access Denied error + var tryGet = function (it, key) { + try { + return it[key]; + } catch (error) { /* empty */ } + }; + + // getting tag from ES6+ `Object.prototype.toString` + var classof$2 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (tag = tryGet(O = Object$1(it), TO_STRING_TAG)) == 'string' ? tag + // builtinTag case + : CORRECT_ARGUMENTS ? classofRaw(O) + // ES3 arguments fallback + : (result = classofRaw(O)) == 'Object' && isCallable$5(O.callee) ? 'Arguments' : result; + }; + + var uncurryThis$2 = functionUncurryThis; + var fails$1 = fails$a; + var isCallable$4 = isCallable$h; + var classof$1 = classof$2; + var getBuiltIn$3 = getBuiltIn$8; + var inspectSource$1 = inspectSource$4; + + var noop = function () { /* empty */ }; + var empty = []; + var construct = getBuiltIn$3('Reflect', 'construct'); + var constructorRegExp = /^\s*(?:class|function)\b/; + var exec = uncurryThis$2(constructorRegExp.exec); + var INCORRECT_TO_STRING = !constructorRegExp.exec(noop); + + var isConstructorModern = function isConstructor(argument) { + if (!isCallable$4(argument)) return false; + try { + construct(noop, empty, argument); + return true; + } catch (error) { + return false; + } + }; + + var isConstructorLegacy = function isConstructor(argument) { + if (!isCallable$4(argument)) return false; + switch (classof$1(argument)) { + case 'AsyncFunction': + case 'GeneratorFunction': + case 'AsyncGeneratorFunction': return false; + } + try { + // we can't check .prototype since constructors produced by .bind haven't it + // `Function#toString` throws on some built-it function in some legacy engines + // (for example, `DOMQuad` and similar in FF41-) + return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource$1(argument)); + } catch (error) { + return true; + } + }; + + isConstructorLegacy.sham = true; + + // `IsConstructor` abstract operation + // https://tc39.es/ecma262/#sec-isconstructor + var isConstructor$1 = !construct || fails$1(function () { + var called; + return isConstructorModern(isConstructorModern.call) + || !isConstructorModern(Object) + || !isConstructorModern(function () { called = true; }) + || called; + }) ? isConstructorLegacy : isConstructorModern; + + var global$b = global$A; + var isConstructor = isConstructor$1; + var tryToString$2 = tryToString$4; + + var TypeError$5 = global$b.TypeError; + + // `Assert: IsConstructor(argument) is true` + var aConstructor$1 = function (argument) { + if (isConstructor(argument)) return argument; + throw TypeError$5(tryToString$2(argument) + ' is not a constructor'); + }; + + var anObject$4 = anObject$8; + var aConstructor = aConstructor$1; + var wellKnownSymbol$4 = wellKnownSymbol$a; + + var SPECIES$1 = wellKnownSymbol$4('species'); + + // `SpeciesConstructor` abstract operation + // https://tc39.es/ecma262/#sec-speciesconstructor + var speciesConstructor$1 = function (O, defaultConstructor) { + var C = anObject$4(O).constructor; + var S; + return C === undefined || (S = anObject$4(C)[SPECIES$1]) == undefined ? defaultConstructor : aConstructor(S); + }; + + var NATIVE_BIND$1 = functionBindNative; + + var FunctionPrototype = Function.prototype; + var apply$1 = FunctionPrototype.apply; + var call$7 = FunctionPrototype.call; + + // eslint-disable-next-line es-x/no-reflect -- safe + var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$1 ? call$7.bind(apply$1) : function () { + return call$7.apply(apply$1, arguments); + }); + + var uncurryThis$1 = functionUncurryThis; + var aCallable$5 = aCallable$7; + var NATIVE_BIND = functionBindNative; + + var bind$4 = uncurryThis$1(uncurryThis$1.bind); + + // optional / simple context binding + var functionBindContext = function (fn, that) { + aCallable$5(fn); + return that === undefined ? fn : NATIVE_BIND ? bind$4(fn, that) : function (/* ...args */) { + return fn.apply(that, arguments); + }; + }; + + var getBuiltIn$2 = getBuiltIn$8; + + var html$1 = getBuiltIn$2('document', 'documentElement'); + + var uncurryThis = functionUncurryThis; + + var arraySlice$1 = uncurryThis([].slice); + + var global$a = global$A; + + var TypeError$4 = global$a.TypeError; + + var validateArgumentsLength$1 = function (passed, required) { + if (passed < required) throw TypeError$4('Not enough arguments'); + return passed; + }; + + var userAgent$2 = engineUserAgent; + + var engineIsIos = /(?:ipad|iphone|ipod).*applewebkit/i.test(userAgent$2); + + var global$9 = global$A; + var apply = functionApply; + var bind$3 = functionBindContext; + var isCallable$3 = isCallable$h; + var hasOwn = hasOwnProperty_1; + var fails = fails$a; + var html = html$1; + var arraySlice = arraySlice$1; + var createElement = documentCreateElement; + var validateArgumentsLength = validateArgumentsLength$1; + var IS_IOS$1 = engineIsIos; + var IS_NODE$2 = engineIsNode; + + var set = global$9.setImmediate; + var clear = global$9.clearImmediate; + var process$2 = global$9.process; + var Dispatch = global$9.Dispatch; + var Function$1 = global$9.Function; + var MessageChannel = global$9.MessageChannel; + var String$1 = global$9.String; + var counter = 0; + var queue$1 = {}; + var ONREADYSTATECHANGE = 'onreadystatechange'; + var location, defer, channel, port; + + try { + // Deno throws a ReferenceError on `location` access without `--location` flag + location = global$9.location; + } catch (error) { /* empty */ } + + var run = function (id) { + if (hasOwn(queue$1, id)) { + var fn = queue$1[id]; + delete queue$1[id]; + fn(); + } + }; + + var runner = function (id) { + return function () { + run(id); + }; + }; + + var listener = function (event) { + run(event.data); + }; + + var post = function (id) { + // old engines have not location.origin + global$9.postMessage(String$1(id), location.protocol + '//' + location.host); + }; + + // Node.js 0.9+ & IE10+ has setImmediate, otherwise: + if (!set || !clear) { + set = function setImmediate(handler) { + validateArgumentsLength(arguments.length, 1); + var fn = isCallable$3(handler) ? handler : Function$1(handler); + var args = arraySlice(arguments, 1); + queue$1[++counter] = function () { + apply(fn, undefined, args); + }; + defer(counter); + return counter; + }; + clear = function clearImmediate(id) { + delete queue$1[id]; + }; + // Node.js 0.8- + if (IS_NODE$2) { + defer = function (id) { + process$2.nextTick(runner(id)); + }; + // Sphere (JS game engine) Dispatch API + } else if (Dispatch && Dispatch.now) { + defer = function (id) { + Dispatch.now(runner(id)); + }; + // Browsers with MessageChannel, includes WebWorkers + // except iOS - https://github.com/zloirock/core-js/issues/624 + } else if (MessageChannel && !IS_IOS$1) { + channel = new MessageChannel(); + port = channel.port2; + channel.port1.onmessage = listener; + defer = bind$3(port.postMessage, port); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if ( + global$9.addEventListener && + isCallable$3(global$9.postMessage) && + !global$9.importScripts && + location && location.protocol !== 'file:' && + !fails(post) + ) { + defer = post; + global$9.addEventListener('message', listener, false); + // IE8- + } else if (ONREADYSTATECHANGE in createElement('script')) { + defer = function (id) { + html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () { + html.removeChild(this); + run(id); + }; + }; + // Rest old browsers + } else { + defer = function (id) { + setTimeout(runner(id), 0); + }; + } + } + + var task$1 = { + set: set, + clear: clear + }; + + var userAgent$1 = engineUserAgent; + var global$8 = global$A; + + var engineIsIosPebble = /ipad|iphone|ipod/i.test(userAgent$1) && global$8.Pebble !== undefined; + + var userAgent = engineUserAgent; + + var engineIsWebosWebkit = /web0s(?!.*chrome)/i.test(userAgent); + + var global$7 = global$A; + var bind$2 = functionBindContext; + var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f; + var macrotask = task$1.set; + var IS_IOS = engineIsIos; + var IS_IOS_PEBBLE = engineIsIosPebble; + var IS_WEBOS_WEBKIT = engineIsWebosWebkit; + var IS_NODE$1 = engineIsNode; + + var MutationObserver = global$7.MutationObserver || global$7.WebKitMutationObserver; + var document$1 = global$7.document; + var process$1 = global$7.process; + var Promise$1 = global$7.Promise; + // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask` + var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global$7, 'queueMicrotask'); + var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; + + var flush, head, last, notify$1, toggle, node, promise, then; + + // modern engines have queueMicrotask method + if (!queueMicrotask) { + flush = function () { + var parent, fn; + if (IS_NODE$1 && (parent = process$1.domain)) parent.exit(); + while (head) { + fn = head.fn; + head = head.next; + try { + fn(); + } catch (error) { + if (head) notify$1(); + else last = undefined; + throw error; + } + } last = undefined; + if (parent) parent.enter(); + }; + + // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339 + // also except WebOS Webkit https://github.com/zloirock/core-js/issues/898 + if (!IS_IOS && !IS_NODE$1 && !IS_WEBOS_WEBKIT && MutationObserver && document$1) { + toggle = true; + node = document$1.createTextNode(''); + new MutationObserver(flush).observe(node, { characterData: true }); + notify$1 = function () { + node.data = toggle = !toggle; + }; + // environments with maybe non-completely correct, but existent Promise + } else if (!IS_IOS_PEBBLE && Promise$1 && Promise$1.resolve) { + // Promise.resolve without an argument throws an error in LG WebOS 2 + promise = Promise$1.resolve(undefined); + // workaround of WebKit ~ iOS Safari 10.1 bug + promise.constructor = Promise$1; + then = bind$2(promise.then, promise); + notify$1 = function () { + then(flush); + }; + // Node.js without promises + } else if (IS_NODE$1) { + notify$1 = function () { + process$1.nextTick(flush); + }; + // for other environments - macrotask based on: + // - setImmediate + // - MessageChannel + // - window.postMessage + // - onreadystatechange + // - setTimeout + } else { + // strange IE + webpack dev server bug - use .bind(global) + macrotask = bind$2(macrotask, global$7); + notify$1 = function () { + macrotask(flush); + }; + } + } + + var microtask$1 = queueMicrotask || function (fn) { + var task = { fn: fn, next: undefined }; + if (last) last.next = task; + if (!head) { + head = task; + notify$1(); + } last = task; + }; + + var global$6 = global$A; + + var hostReportErrors$1 = function (a, b) { + var console = global$6.console; + if (console && console.error) { + arguments.length == 1 ? console.error(a) : console.error(a, b); + } + }; + + var perform$3 = function (exec) { + try { + return { error: false, value: exec() }; + } catch (error) { + return { error: true, value: error }; + } + }; + + var Queue$1 = function () { + this.head = null; + this.tail = null; + }; + + Queue$1.prototype = { + add: function (item) { + var entry = { item: item, next: null }; + if (this.head) this.tail.next = entry; + else this.head = entry; + this.tail = entry; + }, + get: function () { + var entry = this.head; + if (entry) { + this.head = entry.next; + if (this.tail === entry) this.tail = null; + return entry.item; + } + } + }; + + var queue = Queue$1; + + var global$5 = global$A; + + var promiseNativeConstructor = global$5.Promise; + + var engineIsBrowser = typeof window == 'object' && typeof Deno != 'object'; + + var global$4 = global$A; + var NativePromiseConstructor$3 = promiseNativeConstructor; + var isCallable$2 = isCallable$h; + var isForced = isForced_1; + var inspectSource = inspectSource$4; + var wellKnownSymbol$3 = wellKnownSymbol$a; + var IS_BROWSER = engineIsBrowser; + var V8_VERSION = engineV8Version; + + NativePromiseConstructor$3 && NativePromiseConstructor$3.prototype; + var SPECIES = wellKnownSymbol$3('species'); + var SUBCLASSING = false; + var NATIVE_PROMISE_REJECTION_EVENT$1 = isCallable$2(global$4.PromiseRejectionEvent); + + var FORCED_PROMISE_CONSTRUCTOR$5 = isForced('Promise', function () { + var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(NativePromiseConstructor$3); + var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(NativePromiseConstructor$3); + // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables + // https://bugs.chromium.org/p/chromium/issues/detail?id=830565 + // We can't detect it synchronously, so just check versions + if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true; + // We can't use @@species feature detection in V8 since it causes + // deoptimization and performance degradation + // https://github.com/zloirock/core-js/issues/679 + if (V8_VERSION >= 51 && /native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) return false; + // Detect correctness of subclassing with @@species support + var promise = new NativePromiseConstructor$3(function (resolve) { resolve(1); }); + var FakePromise = function (exec) { + exec(function () { /* empty */ }, function () { /* empty */ }); + }; + var constructor = promise.constructor = {}; + constructor[SPECIES] = FakePromise; + SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise; + if (!SUBCLASSING) return true; + // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test + return !GLOBAL_CORE_JS_PROMISE && IS_BROWSER && !NATIVE_PROMISE_REJECTION_EVENT$1; + }); + + var promiseConstructorDetection = { + CONSTRUCTOR: FORCED_PROMISE_CONSTRUCTOR$5, + REJECTION_EVENT: NATIVE_PROMISE_REJECTION_EVENT$1, + SUBCLASSING: SUBCLASSING + }; + + var newPromiseCapability$2 = {}; + + var aCallable$4 = aCallable$7; + + var PromiseCapability = function (C) { + var resolve, reject; + this.promise = new C(function ($$resolve, $$reject) { + if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = aCallable$4(resolve); + this.reject = aCallable$4(reject); + }; + + // `NewPromiseCapability` abstract operation + // https://tc39.es/ecma262/#sec-newpromisecapability + newPromiseCapability$2.f = function (C) { + return new PromiseCapability(C); + }; + + var $$5 = _export; + var IS_NODE = engineIsNode; + var global$3 = global$A; + var call$6 = functionCall; + var defineBuiltIn$1 = defineBuiltIn$3; + var setPrototypeOf = objectSetPrototypeOf; + var setToStringTag = setToStringTag$1; + var setSpecies = setSpecies$1; + var aCallable$3 = aCallable$7; + var isCallable$1 = isCallable$h; + var isObject$1 = isObject$7; + var anInstance = anInstance$1; + var speciesConstructor = speciesConstructor$1; + var task = task$1.set; + var microtask = microtask$1; + var hostReportErrors = hostReportErrors$1; + var perform$2 = perform$3; + var Queue = queue; + var InternalStateModule = internalState; + var NativePromiseConstructor$2 = promiseNativeConstructor; + var PromiseConstructorDetection = promiseConstructorDetection; + var newPromiseCapabilityModule$3 = newPromiseCapability$2; + + var PROMISE = 'Promise'; + var FORCED_PROMISE_CONSTRUCTOR$4 = PromiseConstructorDetection.CONSTRUCTOR; + var NATIVE_PROMISE_REJECTION_EVENT = PromiseConstructorDetection.REJECTION_EVENT; + var NATIVE_PROMISE_SUBCLASSING = PromiseConstructorDetection.SUBCLASSING; + var getInternalPromiseState = InternalStateModule.getterFor(PROMISE); + var setInternalState = InternalStateModule.set; + var NativePromisePrototype$1 = NativePromiseConstructor$2 && NativePromiseConstructor$2.prototype; + var PromiseConstructor = NativePromiseConstructor$2; + var PromisePrototype = NativePromisePrototype$1; + var TypeError$3 = global$3.TypeError; + var document = global$3.document; + var process = global$3.process; + var newPromiseCapability$1 = newPromiseCapabilityModule$3.f; + var newGenericPromiseCapability = newPromiseCapability$1; + + var DISPATCH_EVENT = !!(document && document.createEvent && global$3.dispatchEvent); + var UNHANDLED_REJECTION = 'unhandledrejection'; + var REJECTION_HANDLED = 'rejectionhandled'; + var PENDING = 0; + var FULFILLED = 1; + var REJECTED = 2; + var HANDLED = 1; + var UNHANDLED = 2; + + var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen; + + // helpers + var isThenable = function (it) { + var then; + return isObject$1(it) && isCallable$1(then = it.then) ? then : false; + }; + + var callReaction = function (reaction, state) { + var value = state.value; + var ok = state.state == FULFILLED; + var handler = ok ? reaction.ok : reaction.fail; + var resolve = reaction.resolve; + var reject = reaction.reject; + var domain = reaction.domain; + var result, then, exited; + try { + if (handler) { + if (!ok) { + if (state.rejection === UNHANDLED) onHandleUnhandled(state); + state.rejection = HANDLED; + } + if (handler === true) result = value; + else { + if (domain) domain.enter(); + result = handler(value); // can throw + if (domain) { + domain.exit(); + exited = true; + } + } + if (result === reaction.promise) { + reject(TypeError$3('Promise-chain cycle')); + } else if (then = isThenable(result)) { + call$6(then, result, resolve, reject); + } else resolve(result); + } else reject(value); + } catch (error) { + if (domain && !exited) domain.exit(); + reject(error); + } + }; + + var notify = function (state, isReject) { + if (state.notified) return; + state.notified = true; + microtask(function () { + var reactions = state.reactions; + var reaction; + while (reaction = reactions.get()) { + callReaction(reaction, state); + } + state.notified = false; + if (isReject && !state.rejection) onUnhandled(state); + }); + }; + + var dispatchEvent = function (name, promise, reason) { + var event, handler; + if (DISPATCH_EVENT) { + event = document.createEvent('Event'); + event.promise = promise; + event.reason = reason; + event.initEvent(name, false, true); + global$3.dispatchEvent(event); + } else event = { promise: promise, reason: reason }; + if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = global$3['on' + name])) handler(event); + else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason); + }; + + var onUnhandled = function (state) { + call$6(task, global$3, function () { + var promise = state.facade; + var value = state.value; + var IS_UNHANDLED = isUnhandled(state); + var result; + if (IS_UNHANDLED) { + result = perform$2(function () { + if (IS_NODE) { + process.emit('unhandledRejection', value, promise); + } else dispatchEvent(UNHANDLED_REJECTION, promise, value); + }); + // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should + state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED; + if (result.error) throw result.value; + } + }); + }; + + var isUnhandled = function (state) { + return state.rejection !== HANDLED && !state.parent; + }; + + var onHandleUnhandled = function (state) { + call$6(task, global$3, function () { + var promise = state.facade; + if (IS_NODE) { + process.emit('rejectionHandled', promise); + } else dispatchEvent(REJECTION_HANDLED, promise, state.value); + }); + }; + + var bind$1 = function (fn, state, unwrap) { + return function (value) { + fn(state, value, unwrap); + }; + }; + + var internalReject = function (state, value, unwrap) { + if (state.done) return; + state.done = true; + if (unwrap) state = unwrap; + state.value = value; + state.state = REJECTED; + notify(state, true); + }; + + var internalResolve = function (state, value, unwrap) { + if (state.done) return; + state.done = true; + if (unwrap) state = unwrap; + try { + if (state.facade === value) throw TypeError$3("Promise can't be resolved itself"); + var then = isThenable(value); + if (then) { + microtask(function () { + var wrapper = { done: false }; + try { + call$6(then, value, + bind$1(internalResolve, wrapper, state), + bind$1(internalReject, wrapper, state) + ); + } catch (error) { + internalReject(wrapper, error, state); + } + }); + } else { + state.value = value; + state.state = FULFILLED; + notify(state, false); + } + } catch (error) { + internalReject({ done: false }, error, state); + } + }; + + // constructor polyfill + if (FORCED_PROMISE_CONSTRUCTOR$4) { + // 25.4.3.1 Promise(executor) + PromiseConstructor = function Promise(executor) { + anInstance(this, PromisePrototype); + aCallable$3(executor); + call$6(Internal, this); + var state = getInternalPromiseState(this); + try { + executor(bind$1(internalResolve, state), bind$1(internalReject, state)); + } catch (error) { + internalReject(state, error); + } + }; + + PromisePrototype = PromiseConstructor.prototype; + + // eslint-disable-next-line no-unused-vars -- required for `.length` + Internal = function Promise(executor) { + setInternalState(this, { + type: PROMISE, + done: false, + notified: false, + parent: false, + reactions: new Queue(), + rejection: false, + state: PENDING, + value: undefined + }); + }; + + // `Promise.prototype.then` method + // https://tc39.es/ecma262/#sec-promise.prototype.then + Internal.prototype = defineBuiltIn$1(PromisePrototype, 'then', function then(onFulfilled, onRejected) { + var state = getInternalPromiseState(this); + var reaction = newPromiseCapability$1(speciesConstructor(this, PromiseConstructor)); + state.parent = true; + reaction.ok = isCallable$1(onFulfilled) ? onFulfilled : true; + reaction.fail = isCallable$1(onRejected) && onRejected; + reaction.domain = IS_NODE ? process.domain : undefined; + if (state.state == PENDING) state.reactions.add(reaction); + else microtask(function () { + callReaction(reaction, state); + }); + return reaction.promise; + }); + + OwnPromiseCapability = function () { + var promise = new Internal(); + var state = getInternalPromiseState(promise); + this.promise = promise; + this.resolve = bind$1(internalResolve, state); + this.reject = bind$1(internalReject, state); + }; + + newPromiseCapabilityModule$3.f = newPromiseCapability$1 = function (C) { + return C === PromiseConstructor || C === PromiseWrapper + ? new OwnPromiseCapability(C) + : newGenericPromiseCapability(C); + }; + + if (isCallable$1(NativePromiseConstructor$2) && NativePromisePrototype$1 !== Object.prototype) { + nativeThen = NativePromisePrototype$1.then; + + if (!NATIVE_PROMISE_SUBCLASSING) { + // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs + defineBuiltIn$1(NativePromisePrototype$1, 'then', function then(onFulfilled, onRejected) { + var that = this; + return new PromiseConstructor(function (resolve, reject) { + call$6(nativeThen, that, resolve, reject); + }).then(onFulfilled, onRejected); + // https://github.com/zloirock/core-js/issues/640 + }, { unsafe: true }); + } + + // make `.constructor === Promise` work for native promise-based APIs + try { + delete NativePromisePrototype$1.constructor; + } catch (error) { /* empty */ } + + // make `instanceof Promise` work for native promise-based APIs + if (setPrototypeOf) { + setPrototypeOf(NativePromisePrototype$1, PromisePrototype); + } + } + } + + $$5({ global: true, wrap: true, forced: FORCED_PROMISE_CONSTRUCTOR$4 }, { + Promise: PromiseConstructor + }); + + setToStringTag(PromiseConstructor, PROMISE, false); + setSpecies(PROMISE); + + var iterators = {}; + + var wellKnownSymbol$2 = wellKnownSymbol$a; + var Iterators$1 = iterators; + + var ITERATOR$2 = wellKnownSymbol$2('iterator'); + var ArrayPrototype = Array.prototype; + + // check on default Array iterator + var isArrayIteratorMethod$1 = function (it) { + return it !== undefined && (Iterators$1.Array === it || ArrayPrototype[ITERATOR$2] === it); + }; + + var classof = classof$2; + var getMethod$1 = getMethod$3; + var Iterators = iterators; + var wellKnownSymbol$1 = wellKnownSymbol$a; + + var ITERATOR$1 = wellKnownSymbol$1('iterator'); + + var getIteratorMethod$2 = function (it) { + if (it != undefined) return getMethod$1(it, ITERATOR$1) + || getMethod$1(it, '@@iterator') + || Iterators[classof(it)]; + }; + + var global$2 = global$A; + var call$5 = functionCall; + var aCallable$2 = aCallable$7; + var anObject$3 = anObject$8; + var tryToString$1 = tryToString$4; + var getIteratorMethod$1 = getIteratorMethod$2; + + var TypeError$2 = global$2.TypeError; + + var getIterator$1 = function (argument, usingIterator) { + var iteratorMethod = arguments.length < 2 ? getIteratorMethod$1(argument) : usingIterator; + if (aCallable$2(iteratorMethod)) return anObject$3(call$5(iteratorMethod, argument)); + throw TypeError$2(tryToString$1(argument) + ' is not iterable'); + }; + + var call$4 = functionCall; + var anObject$2 = anObject$8; + var getMethod = getMethod$3; + + var iteratorClose$1 = function (iterator, kind, value) { + var innerResult, innerError; + anObject$2(iterator); + try { + innerResult = getMethod(iterator, 'return'); + if (!innerResult) { + if (kind === 'throw') throw value; + return value; + } + innerResult = call$4(innerResult, iterator); + } catch (error) { + innerError = true; + innerResult = error; + } + if (kind === 'throw') throw value; + if (innerError) throw innerResult; + anObject$2(innerResult); + return value; + }; + + var global$1 = global$A; + var bind = functionBindContext; + var call$3 = functionCall; + var anObject$1 = anObject$8; + var tryToString = tryToString$4; + var isArrayIteratorMethod = isArrayIteratorMethod$1; + var lengthOfArrayLike = lengthOfArrayLike$2; + var isPrototypeOf = objectIsPrototypeOf; + var getIterator = getIterator$1; + var getIteratorMethod = getIteratorMethod$2; + var iteratorClose = iteratorClose$1; + + var TypeError$1 = global$1.TypeError; + + var Result = function (stopped, result) { + this.stopped = stopped; + this.result = result; + }; + + var ResultPrototype = Result.prototype; + + var iterate$2 = function (iterable, unboundFunction, options) { + var that = options && options.that; + var AS_ENTRIES = !!(options && options.AS_ENTRIES); + var IS_ITERATOR = !!(options && options.IS_ITERATOR); + var INTERRUPTED = !!(options && options.INTERRUPTED); + var fn = bind(unboundFunction, that); + var iterator, iterFn, index, length, result, next, step; + + var stop = function (condition) { + if (iterator) iteratorClose(iterator, 'normal', condition); + return new Result(true, condition); + }; + + var callFn = function (value) { + if (AS_ENTRIES) { + anObject$1(value); + return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]); + } return INTERRUPTED ? fn(value, stop) : fn(value); + }; + + if (IS_ITERATOR) { + iterator = iterable; + } else { + iterFn = getIteratorMethod(iterable); + if (!iterFn) throw TypeError$1(tryToString(iterable) + ' is not iterable'); + // optimisation for array iterators + if (isArrayIteratorMethod(iterFn)) { + for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) { + result = callFn(iterable[index]); + if (result && isPrototypeOf(ResultPrototype, result)) return result; + } return new Result(false); + } + iterator = getIterator(iterable, iterFn); + } + + next = iterator.next; + while (!(step = call$3(next, iterator)).done) { + try { + result = callFn(step.value); + } catch (error) { + iteratorClose(iterator, 'throw', error); + } + if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result; + } return new Result(false); + }; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); + } + + function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } + } + + function _asyncToGenerator(fn) { + return function () { + var self = this, + args = arguments; + return new Promise(function (resolve, reject) { + var gen = fn.apply(self, args); + + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + + _next(undefined); + }); + }; + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } else if (call !== void 0) { + throw new TypeError("Derived constructors may only return object or undefined"); + } + + return _assertThisInitialized(self); + } + + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; + } + + function __repeatConcat(str, num) { + if (!!str && typeof str.repeat === "function") return str.repeat(num); + + if (typeof str === "string") { + var result = ""; + + for (var i = 0; i < num; i++) { + result += str; + } + + return result; + } + + if (str instanceof Array) { + var result = []; + + for (var i = 0; i < num; i++) { + result.concat(str); + } + + return result; + } + + throw new Error("Invalid Data!"); + } + + function __includes(str, token) { + if (!!str && typeof str.includes === "function") return str.includes(token); + return str.indexOf(token) !== -1; + } + + function __startsWithString(str, token) { + if (!!str && typeof str.startsWith === "function") return str.startsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp("^" + token); + return regexp.test(str); + } + + function __endsWithString(str, token) { + if (typeof str.endsWith === "function") return str.endsWith(token); + if (typeof str !== "string" || typeof token !== "string") throw new Error("Invalid Data!"); + var regexp = new RegExp(token + "$"); + return regexp.test(str); + } + + function __arrayMaker(obj, func) { + if (!obj || _typeof(obj) !== "object") throw new Error("Invalid Data!"); + var result = []; + var length = obj.length; + + for (var i = 0; i < length; i++) { + result[i] = func(obj[i], i); + } + + return result; + } + + var __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + var mappedPromises = promises.map(function (p) { + return p.then(function (value) { + return { + status: 'fulfilled', + value: value + }; + }).catch(function (reason) { + return { + status: 'rejected', + reason: reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + var wellKnownSymbol = wellKnownSymbol$a; + + var ITERATOR = wellKnownSymbol('iterator'); + var SAFE_CLOSING = false; + + try { + var called = 0; + var iteratorWithReturn = { + next: function () { + return { done: !!called++ }; + }, + 'return': function () { + SAFE_CLOSING = true; + } + }; + iteratorWithReturn[ITERATOR] = function () { + return this; + }; + // eslint-disable-next-line es-x/no-array-from, no-throw-literal -- required for testing + __arrayMaker(iteratorWithReturn, function () { throw 2; }); + } catch (error) { /* empty */ } + + var checkCorrectnessOfIteration$1 = function (exec, SKIP_CLOSING) { + if (!SKIP_CLOSING && !SAFE_CLOSING) return false; + var ITERATION_SUPPORT = false; + try { + var object = {}; + object[ITERATOR] = function () { + return { + next: function () { + return { done: ITERATION_SUPPORT = true }; + } + }; + }; + exec(object); + } catch (error) { /* empty */ } + return ITERATION_SUPPORT; + }; + + var NativePromiseConstructor$1 = promiseNativeConstructor; + var checkCorrectnessOfIteration = checkCorrectnessOfIteration$1; + var FORCED_PROMISE_CONSTRUCTOR$3 = promiseConstructorDetection.CONSTRUCTOR; + + var promiseStaticsIncorrectIteration = FORCED_PROMISE_CONSTRUCTOR$3 || !checkCorrectnessOfIteration(function (iterable) { + NativePromiseConstructor$1.all(iterable).then(undefined, function () { /* empty */ }); + }); + + var $$4 = _export; + var call$2 = functionCall; + var aCallable$1 = aCallable$7; + var newPromiseCapabilityModule$2 = newPromiseCapability$2; + var perform$1 = perform$3; + var iterate$1 = iterate$2; + var PROMISE_STATICS_INCORRECT_ITERATION$1 = promiseStaticsIncorrectIteration; + + // `Promise.all` method + // https://tc39.es/ecma262/#sec-promise.all + $$4({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION$1 }, { + all: function all(iterable) { + var C = this; + var capability = newPromiseCapabilityModule$2.f(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform$1(function () { + var $promiseResolve = aCallable$1(C.resolve); + var values = []; + var counter = 0; + var remaining = 1; + iterate$1(iterable, function (promise) { + var index = counter++; + var alreadyCalled = false; + remaining++; + call$2($promiseResolve, C, promise).then(function (value) { + if (alreadyCalled) return; + alreadyCalled = true; + values[index] = value; + --remaining || resolve(values); + }, reject); + }); + --remaining || resolve(values); + }); + if (result.error) reject(result.value); + return capability.promise; + } + }); + + var $$3 = _export; + var FORCED_PROMISE_CONSTRUCTOR$2 = promiseConstructorDetection.CONSTRUCTOR; + var NativePromiseConstructor = promiseNativeConstructor; + var getBuiltIn$1 = getBuiltIn$8; + var isCallable = isCallable$h; + var defineBuiltIn = defineBuiltIn$3; + + var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype; + + // `Promise.prototype.catch` method + // https://tc39.es/ecma262/#sec-promise.prototype.catch + $$3({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR$2, real: true }, { + 'catch': function (onRejected) { + return this.then(undefined, onRejected); + } + }); + + // makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then` + if (isCallable(NativePromiseConstructor)) { + var method = getBuiltIn$1('Promise').prototype['catch']; + if (NativePromisePrototype['catch'] !== method) { + defineBuiltIn(NativePromisePrototype, 'catch', method, { unsafe: true }); + } + } + + var $$2 = _export; + var call$1 = functionCall; + var aCallable = aCallable$7; + var newPromiseCapabilityModule$1 = newPromiseCapability$2; + var perform = perform$3; + var iterate = iterate$2; + var PROMISE_STATICS_INCORRECT_ITERATION = promiseStaticsIncorrectIteration; + + // `Promise.race` method + // https://tc39.es/ecma262/#sec-promise.race + $$2({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { + race: function race(iterable) { + var C = this; + var capability = newPromiseCapabilityModule$1.f(C); + var reject = capability.reject; + var result = perform(function () { + var $promiseResolve = aCallable(C.resolve); + iterate(iterable, function (promise) { + call$1($promiseResolve, C, promise).then(capability.resolve, reject); + }); + }); + if (result.error) reject(result.value); + return capability.promise; + } + }); + + var $$1 = _export; + var call = functionCall; + var newPromiseCapabilityModule = newPromiseCapability$2; + var FORCED_PROMISE_CONSTRUCTOR$1 = promiseConstructorDetection.CONSTRUCTOR; + + // `Promise.reject` method + // https://tc39.es/ecma262/#sec-promise.reject + $$1({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR$1 }, { + reject: function reject(r) { + var capability = newPromiseCapabilityModule.f(this); + call(capability.reject, undefined, r); + return capability.promise; + } + }); + + var anObject = anObject$8; + var isObject = isObject$7; + var newPromiseCapability = newPromiseCapability$2; + + var promiseResolve$1 = function (C, x) { + anObject(C); + if (isObject(x) && x.constructor === C) return x; + var promiseCapability = newPromiseCapability.f(C); + var resolve = promiseCapability.resolve; + resolve(x); + return promiseCapability.promise; + }; + + var $ = _export; + var getBuiltIn = getBuiltIn$8; + var FORCED_PROMISE_CONSTRUCTOR = promiseConstructorDetection.CONSTRUCTOR; + var promiseResolve = promiseResolve$1; + + getBuiltIn('Promise'); + + // `Promise.resolve` method + // https://tc39.es/ecma262/#sec-promise.resolve + $({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, { + resolve: function resolve(x) { + return promiseResolve(this, x); + } + }); + + var runtime = {exports: {}}; + + /** + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + (function (module) { + var runtime = (function (exports) { + + var Op = Object.prototype; + var hasOwn = Op.hasOwnProperty; + var undefined$1; // More compressible than void 0. + var $Symbol = typeof Symbol === "function" ? Symbol : {}; + var iteratorSymbol = $Symbol.iterator || "@@iterator"; + var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; + var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; + + function define(obj, key, value) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + return obj[key]; + } + try { + // IE 8 has a broken Object.defineProperty that only works on DOM objects. + define({}, ""); + } catch (err) { + define = function(obj, key, value) { + return obj[key] = value; + }; + } + + function wrap(innerFn, outerFn, self, tryLocsList) { + // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. + var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; + var generator = Object.create(protoGenerator.prototype); + var context = new Context(tryLocsList || []); + + // The ._invoke method unifies the implementations of the .next, + // .throw, and .return methods. + generator._invoke = makeInvokeMethod(innerFn, self, context); + + return generator; + } + exports.wrap = wrap; + + // Try/catch helper to minimize deoptimizations. Returns a completion + // record like context.tryEntries[i].completion. This interface could + // have been (and was previously) designed to take a closure to be + // invoked without arguments, but in all the cases we care about we + // already have an existing method we want to call, so there's no need + // to create a new function object. We can even get away with assuming + // the method takes exactly one argument, since that happens to be true + // in every case, so we don't have to touch the arguments object. The + // only additional allocation required is the completion record, which + // has a stable shape and so hopefully should be cheap to allocate. + function tryCatch(fn, obj, arg) { + try { + return { type: "normal", arg: fn.call(obj, arg) }; + } catch (err) { + return { type: "throw", arg: err }; + } + } + + var GenStateSuspendedStart = "suspendedStart"; + var GenStateSuspendedYield = "suspendedYield"; + var GenStateExecuting = "executing"; + var GenStateCompleted = "completed"; + + // Returning this object from the innerFn has the same effect as + // breaking out of the dispatch switch statement. + var ContinueSentinel = {}; + + // Dummy constructor functions that we use as the .constructor and + // .constructor.prototype properties for functions that return Generator + // objects. For full spec compliance, you may wish to configure your + // minifier not to mangle the names of these two functions. + function Generator() {} + function GeneratorFunction() {} + function GeneratorFunctionPrototype() {} + + // This is a polyfill for %IteratorPrototype% for environments that + // don't natively support it. + var IteratorPrototype = {}; + define(IteratorPrototype, iteratorSymbol, function () { + return this; + }); + + var getProto = Object.getPrototypeOf; + var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); + if (NativeIteratorPrototype && + NativeIteratorPrototype !== Op && + hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { + // This environment has a native %IteratorPrototype%; use it instead + // of the polyfill. + IteratorPrototype = NativeIteratorPrototype; + } + + var Gp = GeneratorFunctionPrototype.prototype = + Generator.prototype = Object.create(IteratorPrototype); + GeneratorFunction.prototype = GeneratorFunctionPrototype; + define(Gp, "constructor", GeneratorFunctionPrototype); + define(GeneratorFunctionPrototype, "constructor", GeneratorFunction); + GeneratorFunction.displayName = define( + GeneratorFunctionPrototype, + toStringTagSymbol, + "GeneratorFunction" + ); + + // Helper for defining the .next, .throw, and .return methods of the + // Iterator interface in terms of a single ._invoke method. + function defineIteratorMethods(prototype) { + ["next", "throw", "return"].forEach(function(method) { + define(prototype, method, function(arg) { + return this._invoke(method, arg); + }); + }); + } + + exports.isGeneratorFunction = function(genFun) { + var ctor = typeof genFun === "function" && genFun.constructor; + return ctor + ? ctor === GeneratorFunction || + // For the native GeneratorFunction constructor, the best we can + // do is to check its .name property. + (ctor.displayName || ctor.name) === "GeneratorFunction" + : false; + }; + + exports.mark = function(genFun) { + if (Object.setPrototypeOf) { + Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); + } else { + genFun.__proto__ = GeneratorFunctionPrototype; + define(genFun, toStringTagSymbol, "GeneratorFunction"); + } + genFun.prototype = Object.create(Gp); + return genFun; + }; + + // Within the body of any async function, `await x` is transformed to + // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test + // `hasOwn.call(value, "__await")` to determine if the yielded value is + // meant to be awaited. + exports.awrap = function(arg) { + return { __await: arg }; + }; + + function AsyncIterator(generator, PromiseImpl) { + function invoke(method, arg, resolve, reject) { + var record = tryCatch(generator[method], generator, arg); + if (record.type === "throw") { + reject(record.arg); + } else { + var result = record.arg; + var value = result.value; + if (value && + typeof value === "object" && + hasOwn.call(value, "__await")) { + return PromiseImpl.resolve(value.__await).then(function(value) { + invoke("next", value, resolve, reject); + }, function(err) { + invoke("throw", err, resolve, reject); + }); + } + + return PromiseImpl.resolve(value).then(function(unwrapped) { + // When a yielded Promise is resolved, its final value becomes + // the .value of the Promise<{value,done}> result for the + // current iteration. + result.value = unwrapped; + resolve(result); + }, function(error) { + // If a rejected Promise was yielded, throw the rejection back + // into the async generator function so it can be handled there. + return invoke("throw", error, resolve, reject); + }); + } + } + + var previousPromise; + + function enqueue(method, arg) { + function callInvokeWithMethodAndArg() { + return new PromiseImpl(function(resolve, reject) { + invoke(method, arg, resolve, reject); + }); + } + + return previousPromise = + // If enqueue has been called before, then we want to wait until + // all previous Promises have been resolved before calling invoke, + // so that results are always delivered in the correct order. If + // enqueue has not been called before, then it is important to + // call invoke immediately, without waiting on a callback to fire, + // so that the async generator function has the opportunity to do + // any necessary setup in a predictable way. This predictability + // is why the Promise constructor synchronously invokes its + // executor callback, and why async functions synchronously + // execute code before the first await. Since we implement simple + // async functions in terms of async generators, it is especially + // important to get this right, even though it requires care. + previousPromise ? previousPromise.then( + callInvokeWithMethodAndArg, + // Avoid propagating failures to Promises returned by later + // invocations of the iterator. + callInvokeWithMethodAndArg + ) : callInvokeWithMethodAndArg(); + } + + // Define the unified helper method that is used to implement .next, + // .throw, and .return (see defineIteratorMethods). + this._invoke = enqueue; + } + + defineIteratorMethods(AsyncIterator.prototype); + define(AsyncIterator.prototype, asyncIteratorSymbol, function () { + return this; + }); + exports.AsyncIterator = AsyncIterator; + + // Note that simple async functions are implemented on top of + // AsyncIterator objects; they just return a Promise for the value of + // the final result produced by the iterator. + exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { + if (PromiseImpl === void 0) PromiseImpl = Promise; + + var iter = new AsyncIterator( + wrap(innerFn, outerFn, self, tryLocsList), + PromiseImpl + ); + + return exports.isGeneratorFunction(outerFn) + ? iter // If outerFn is a generator, return the full iterator. + : iter.next().then(function(result) { + return result.done ? result.value : iter.next(); + }); + }; + + function makeInvokeMethod(innerFn, self, context) { + var state = GenStateSuspendedStart; + + return function invoke(method, arg) { + if (state === GenStateExecuting) { + throw new Error("Generator is already running"); + } + + if (state === GenStateCompleted) { + if (method === "throw") { + throw arg; + } + + // Be forgiving, per 25.3.3.3.3 of the spec: + // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume + return doneResult(); + } + + context.method = method; + context.arg = arg; + + while (true) { + var delegate = context.delegate; + if (delegate) { + var delegateResult = maybeInvokeDelegate(delegate, context); + if (delegateResult) { + if (delegateResult === ContinueSentinel) continue; + return delegateResult; + } + } + + if (context.method === "next") { + // Setting context._sent for legacy support of Babel's + // function.sent implementation. + context.sent = context._sent = context.arg; + + } else if (context.method === "throw") { + if (state === GenStateSuspendedStart) { + state = GenStateCompleted; + throw context.arg; + } + + context.dispatchException(context.arg); + + } else if (context.method === "return") { + context.abrupt("return", context.arg); + } + + state = GenStateExecuting; + + var record = tryCatch(innerFn, self, context); + if (record.type === "normal") { + // If an exception is thrown from innerFn, we leave state === + // GenStateExecuting and loop back for another invocation. + state = context.done + ? GenStateCompleted + : GenStateSuspendedYield; + + if (record.arg === ContinueSentinel) { + continue; + } + + return { + value: record.arg, + done: context.done + }; + + } else if (record.type === "throw") { + state = GenStateCompleted; + // Dispatch the exception by looping back around to the + // context.dispatchException(context.arg) call above. + context.method = "throw"; + context.arg = record.arg; + } + } + }; + } + + // Call delegate.iterator[context.method](context.arg) and handle the + // result, either by returning a { value, done } result from the + // delegate iterator, or by modifying context.method and context.arg, + // setting context.delegate to null, and returning the ContinueSentinel. + function maybeInvokeDelegate(delegate, context) { + var method = delegate.iterator[context.method]; + if (method === undefined$1) { + // A .throw or .return when the delegate iterator has no .throw + // method always terminates the yield* loop. + context.delegate = null; + + if (context.method === "throw") { + // Note: ["return"] must be used for ES3 parsing compatibility. + if (delegate.iterator["return"]) { + // If the delegate iterator has a return method, give it a + // chance to clean up. + context.method = "return"; + context.arg = undefined$1; + maybeInvokeDelegate(delegate, context); + + if (context.method === "throw") { + // If maybeInvokeDelegate(context) changed context.method from + // "return" to "throw", let that override the TypeError below. + return ContinueSentinel; + } + } + + context.method = "throw"; + context.arg = new TypeError( + "The iterator does not provide a 'throw' method"); + } + + return ContinueSentinel; + } + + var record = tryCatch(method, delegate.iterator, context.arg); + + if (record.type === "throw") { + context.method = "throw"; + context.arg = record.arg; + context.delegate = null; + return ContinueSentinel; + } + + var info = record.arg; + + if (! info) { + context.method = "throw"; + context.arg = new TypeError("iterator result is not an object"); + context.delegate = null; + return ContinueSentinel; + } + + if (info.done) { + // Assign the result of the finished delegate to the temporary + // variable specified by delegate.resultName (see delegateYield). + context[delegate.resultName] = info.value; + + // Resume execution at the desired location (see delegateYield). + context.next = delegate.nextLoc; + + // If context.method was "throw" but the delegate handled the + // exception, let the outer generator proceed normally. If + // context.method was "next", forget context.arg since it has been + // "consumed" by the delegate iterator. If context.method was + // "return", allow the original .return call to continue in the + // outer generator. + if (context.method !== "return") { + context.method = "next"; + context.arg = undefined$1; + } + + } else { + // Re-yield the result returned by the delegate method. + return info; + } + + // The delegate iterator is finished, so forget it and continue with + // the outer generator. + context.delegate = null; + return ContinueSentinel; + } + + // Define Generator.prototype.{next,throw,return} in terms of the + // unified ._invoke helper method. + defineIteratorMethods(Gp); + + define(Gp, toStringTagSymbol, "Generator"); + + // A Generator should always return itself as the iterator object when the + // @@iterator function is called on it. Some browsers' implementations of the + // iterator prototype chain incorrectly implement this, causing the Generator + // object to not be returned from this call. This ensures that doesn't happen. + // See https://github.com/facebook/regenerator/issues/274 for more details. + define(Gp, iteratorSymbol, function() { + return this; + }); + + define(Gp, "toString", function() { + return "[object Generator]"; + }); + + function pushTryEntry(locs) { + var entry = { tryLoc: locs[0] }; + + if (1 in locs) { + entry.catchLoc = locs[1]; + } + + if (2 in locs) { + entry.finallyLoc = locs[2]; + entry.afterLoc = locs[3]; + } + + this.tryEntries.push(entry); + } + + function resetTryEntry(entry) { + var record = entry.completion || {}; + record.type = "normal"; + delete record.arg; + entry.completion = record; + } + + function Context(tryLocsList) { + // The root entry object (effectively a try statement without a catch + // or a finally block) gives us a place to store values thrown from + // locations where there is no enclosing try statement. + this.tryEntries = [{ tryLoc: "root" }]; + tryLocsList.forEach(pushTryEntry, this); + this.reset(true); + } + + exports.keys = function(object) { + var keys = []; + for (var key in object) { + keys.push(key); + } + keys.reverse(); + + // Rather than returning an object with a next method, we keep + // things simple and return the next function itself. + return function next() { + while (keys.length) { + var key = keys.pop(); + if (key in object) { + next.value = key; + next.done = false; + return next; + } + } + + // To avoid creating an additional object, we just hang the .value + // and .done properties off the next function object itself. This + // also ensures that the minifier will not anonymize the function. + next.done = true; + return next; + }; + }; + + function values(iterable) { + if (iterable) { + var iteratorMethod = iterable[iteratorSymbol]; + if (iteratorMethod) { + return iteratorMethod.call(iterable); + } + + if (typeof iterable.next === "function") { + return iterable; + } + + if (!isNaN(iterable.length)) { + var i = -1, next = function next() { + while (++i < iterable.length) { + if (hasOwn.call(iterable, i)) { + next.value = iterable[i]; + next.done = false; + return next; + } + } + + next.value = undefined$1; + next.done = true; + + return next; + }; + + return next.next = next; + } + } + + // Return an iterator with no values. + return { next: doneResult }; + } + exports.values = values; + + function doneResult() { + return { value: undefined$1, done: true }; + } + + Context.prototype = { + constructor: Context, + + reset: function(skipTempReset) { + this.prev = 0; + this.next = 0; + // Resetting context._sent for legacy support of Babel's + // function.sent implementation. + this.sent = this._sent = undefined$1; + this.done = false; + this.delegate = null; + + this.method = "next"; + this.arg = undefined$1; + + this.tryEntries.forEach(resetTryEntry); + + if (!skipTempReset) { + for (var name in this) { + // Not sure about the optimal order of these conditions: + if (name.charAt(0) === "t" && + hasOwn.call(this, name) && + !isNaN(+name.slice(1))) { + this[name] = undefined$1; + } + } + } + }, + + stop: function() { + this.done = true; + + var rootEntry = this.tryEntries[0]; + var rootRecord = rootEntry.completion; + if (rootRecord.type === "throw") { + throw rootRecord.arg; + } + + return this.rval; + }, + + dispatchException: function(exception) { + if (this.done) { + throw exception; + } + + var context = this; + function handle(loc, caught) { + record.type = "throw"; + record.arg = exception; + context.next = loc; + + if (caught) { + // If the dispatched exception was caught by a catch block, + // then let that catch block handle the exception normally. + context.method = "next"; + context.arg = undefined$1; + } + + return !! caught; + } + + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + var record = entry.completion; + + if (entry.tryLoc === "root") { + // Exception thrown outside of any try block that could handle + // it, so set the completion value of the entire function to + // throw the exception. + return handle("end"); + } + + if (entry.tryLoc <= this.prev) { + var hasCatch = hasOwn.call(entry, "catchLoc"); + var hasFinally = hasOwn.call(entry, "finallyLoc"); + + if (hasCatch && hasFinally) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } else if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else if (hasCatch) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } + + } else if (hasFinally) { + if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else { + throw new Error("try statement without catch or finally"); + } + } + } + }, + + abrupt: function(type, arg) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc <= this.prev && + hasOwn.call(entry, "finallyLoc") && + this.prev < entry.finallyLoc) { + var finallyEntry = entry; + break; + } + } + + if (finallyEntry && + (type === "break" || + type === "continue") && + finallyEntry.tryLoc <= arg && + arg <= finallyEntry.finallyLoc) { + // Ignore the finally entry if control is not jumping to a + // location outside the try/catch block. + finallyEntry = null; + } + + var record = finallyEntry ? finallyEntry.completion : {}; + record.type = type; + record.arg = arg; + + if (finallyEntry) { + this.method = "next"; + this.next = finallyEntry.finallyLoc; + return ContinueSentinel; + } + + return this.complete(record); + }, + + complete: function(record, afterLoc) { + if (record.type === "throw") { + throw record.arg; + } + + if (record.type === "break" || + record.type === "continue") { + this.next = record.arg; + } else if (record.type === "return") { + this.rval = this.arg = record.arg; + this.method = "return"; + this.next = "end"; + } else if (record.type === "normal" && afterLoc) { + this.next = afterLoc; + } + + return ContinueSentinel; + }, + + finish: function(finallyLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.finallyLoc === finallyLoc) { + this.complete(entry.completion, entry.afterLoc); + resetTryEntry(entry); + return ContinueSentinel; + } + } + }, + + "catch": function(tryLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc === tryLoc) { + var record = entry.completion; + if (record.type === "throw") { + var thrown = record.arg; + resetTryEntry(entry); + } + return thrown; + } + } + + // The context.catch method must only be called with a location + // argument that corresponds to a known catch block. + throw new Error("illegal catch attempt"); + }, + + delegateYield: function(iterable, resultName, nextLoc) { + this.delegate = { + iterator: values(iterable), + resultName: resultName, + nextLoc: nextLoc + }; + + if (this.method === "next") { + // Deliberately forget the last sent value so that we don't + // accidentally pass it on to the delegate. + this.arg = undefined$1; + } + + return ContinueSentinel; + } + }; + + // Regardless of whether this script is executing as a CommonJS module + // or not, return the runtime object so that we can declare the variable + // regeneratorRuntime in the outer scope, which allows this module to be + // injected easily by `bin/regenerator --include-runtime script.js`. + return exports; + + }( + // If this script is executing as a CommonJS module, use module.exports + // as the regeneratorRuntime namespace. Otherwise create a new empty + // object. Either way, the resulting object will be used to initialize + // the regeneratorRuntime variable at the top of this file. + module.exports + )); + + try { + regeneratorRuntime = runtime; + } catch (accidentalStrictMode) { + // This module should not be running in strict mode, so the above + // assignment should always work unless something is misconfigured. Just + // in case runtime.js accidentally runs in strict mode, in modern engines + // we can explicitly access globalThis. In older engines we can escape + // strict mode using a global Function call. This could conceivably fail + // if a Content Security Policy forbids using Function, but in that case + // the proper solution is to fix the accidental strict mode problem. If + // you've misconfigured your bundler to force strict mode and applied a + // CSP to forbid Function, and you're not willing to fix either of those + // problems, please detail your unique predicament in a GitHub issue. + if (typeof globalThis === "object") { + globalThis.regeneratorRuntime = runtime; + } else { + Function("r", "regeneratorRuntime = r")(runtime); + } + } + } (runtime)); + + var XnbError = function (_Error) { + _inherits(XnbError, _Error); + + var _super = _createSuper(XnbError); + + function XnbError() { + var _this; + + var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + + _classCallCheck(this, XnbError); + + _this = _super.call(this, message); + _this.name = "XnbError"; + _this.message = message; + Error.captureStackTrace(_assertThisInitialized(_this), XnbError); + return _this; + } + + return _createClass(XnbError); + }(_wrapNativeSuper(Error)); + + var TypeReader = function () { + function TypeReader() { + _classCallCheck(this, TypeReader); + } + + _createClass(TypeReader, null, [{ + key: "setReaders", + value: function setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + }, { + key: "addReaders", + value: function addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + }, { + key: "makeSimplied", + value: function makeSimplied(type, reader) { + var simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + var subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + }, { + key: "simplifyType", + value: function (_simplifyType) { + function simplifyType(_x) { + return _simplifyType.apply(this, arguments); + } + + simplifyType.toString = function () { + return _simplifyType.toString(); + }; + + return simplifyType; + }(function (type) { + var simple = type.split(/`|,/)[0]; + + var isArray = __endsWithString(simple, '[]'); + + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + var reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (var _i2 = 0, _Object$values2 = Object.values(TypeReader.readers); _i2 < _Object$values2.length; _i2++) { + var reader = _Object$values2[_i2]; + var result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + }) + }, { + key: "parseSubtypes", + value: function parseSubtypes(type) { + var subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + var matches = subtype.match(pattern).map(function (e) { + return e.slice(1, -1); + }); + return matches; + } + }, { + key: "getTypeInfo", + value: function getTypeInfo(type) { + var mainType = type.match(/[^<]+/)[0]; + var subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(function (type) { + return type.trim(); + }) : []; + return { + type: mainType, + subtypes: subtypes + }; + } + }, { + key: "getReaderTypeList", + value: function getReaderTypeList(typeString) { + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; + + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReader", + value: function getReader(typeString) { + var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn2.type, + subtypes = _TypeReader$getTypeIn2.subtypes; + + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + }, { + key: "getReaderFromRaw", + value: function getReaderFromRaw(typeString) { + var simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + }]); + + return TypeReader; + }(); + + _defineProperty(TypeReader, "readers", {}); + + var UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; + var UTF8_SECOND_BITES = 0x80; + var UTF8_MASK = 63; + var UTF16_BITES$1 = [0xD800, 0xDC00]; + var UTF16_MASK$1 = 1023; + + function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + } + + function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; + } + + function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); + } + + function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + } + + function stringToUnicode$1(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8ToUnicode(codes) { + var dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + var result = []; + var index = 0; + + while (index < dataArray.length) { + var headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; + } + + function UnicodeToUTF8(unicodeArr) { + var result = []; + + for (var _i2 = 0; _i2 < unicodeArr.length; _i2++) { + var code = unicodeArr[_i2]; + result.push.apply(result, UTF8Encode(code)); + } + + return result; + } + + function UnicodeToString(unicodeArr) { + var result = []; + + for (var _i4 = 0; _i4 < unicodeArr.length; _i4++) { + var code = unicodeArr[_i4]; + result.push.apply(result, UTF16Encode(code)); + } + + var blockSize = 32768; + var resultStr = ""; + + for (var i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode.apply(String, result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; + } + + function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); + } + + function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); + } + + var LITTLE_ENDIAN = true; + + var BufferReader = function () { + function BufferReader(buffer) { + var endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + + _classCallCheck(this, BufferReader); + + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + _createClass(BufferReader, [{ + key: "seek", + value: function seek(index) { + var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + var offset = this._offset; + this._offset = Math.max(origin + parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + }, { + key: "bytePosition", + get: function get() { + return parseInt(this._offset); + }, + set: function set(value) { + this._offset = value; + } + }, { + key: "bitPosition", + get: function get() { + return parseInt(this._bitOffset); + }, + set: function set(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + var byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + }, { + key: "size", + get: function get() { + return this.buffer.byteLength; + } + }, { + key: "buffer", + get: function get() { + return this._buffer; + } + }, { + key: "copyFrom", + value: function copyFrom(buffer) { + var targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + var sourceView = new Uint8Array(buffer); + var isOverflow = this.buffer.byteLength < length + targetIndex; + var targetBuffer = this.buffer; + var targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (var i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (var _i = sourceIndex, j = targetIndex; _i < length; _i++, j++) { + targetView.setUint8(j, sourceView[_i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + }, { + key: "read", + value: function read(count) { + var buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + }, { + key: "readByte", + value: function readByte() { + return this.readUInt(); + } + }, { + key: "readInt", + value: function readInt() { + var value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + }, { + key: "readUInt", + value: function readUInt() { + var value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + }, { + key: "readUInt16", + value: function readUInt16() { + var value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + }, { + key: "readUInt32", + value: function readUInt32() { + var value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readInt16", + value: function readInt16() { + var value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + }, { + key: "readInt32", + value: function readInt32() { + var value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readSingle", + value: function readSingle() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + }, { + key: "readDouble", + value: function readDouble() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + }, { + key: "readString", + value: function readString() { + var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + var chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) { + chars.push(this.readByte()); + } + } else { + for (var i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + }, { + key: "peek", + value: function peek(count) { + var buffer = this.read(count); + this.seek(-count); + return buffer; + } + }, { + key: "peekByte", + value: function peekByte() { + return this.peekUInt(); + } + }, { + key: "peekInt", + value: function peekInt() { + var value = this._dataView.getInt8(this._offset); + + return value; + } + }, { + key: "peekUInt", + value: function peekUInt() { + var value = this._dataView.getUint8(this._offset); + + return value; + } + }, { + key: "peekUInt16", + value: function peekUInt16() { + var value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + }, { + key: "peekUInt32", + value: function peekUInt32() { + var value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekInt16", + value: function peekInt16() { + var value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + }, { + key: "peekInt32", + value: function peekInt32() { + var value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekSingle", + value: function peekSingle() { + var value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + }, { + key: "peekDouble", + value: function peekDouble() { + var value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + }, { + key: "peekString", + value: function peekString() { + var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var chars = []; + var startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) { + chars.push(this.readByte()); + } + } else { + for (var i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + }, { + key: "read7BitNumber", + value: function read7BitNumber() { + var result = 0; + var bitsRead = 0; + var value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + }, { + key: "readLZXBits", + value: function readLZXBits(bits) { + var bitsLeft = bits; + var read = 0; + + while (bitsLeft > 0) { + var peek = this._dataView.getUint16(this._offset, true); + + var bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + var offset = 16 - this.bitPosition - bitsInFrame; + var value = (peek & Math.pow(2, bitsInFrame) - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + }, { + key: "peekLZXBits", + value: function peekLZXBits(bits) { + var bitPosition = this.bitPosition; + var bytePosition = this.bytePosition; + var read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + }, { + key: "readLZXInt16", + value: function readLZXInt16() { + var seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + var lsB = this.readByte(); + var msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + }, { + key: "align", + value: function align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + }]); + + return BufferReader; + }(); + + var BufferWriter = function () { + function BufferWriter() { + var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + + _classCallCheck(this, BufferWriter); + + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + _createClass(BufferWriter, [{ + key: "buffer", + get: function get() { + return this._buffer; + } + }, { + key: "reconnectDataView", + value: function reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + }, { + key: "trim", + value: function trim() { + var pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + }, { + key: "alloc", + value: function alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + var tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + var tDataView = new DataView(tBuffer); + + for (var i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + }, { + key: "concat", + value: function concat(buffer) { + var targetBufferView = new Uint8Array(buffer); + var newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (var i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + }, { + key: "write", + value: function write(bytes) { + var targetBufferView = new Uint8Array(bytes); + var newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (var i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + }, { + key: "writeString", + value: function writeString(str) { + var utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + }, { + key: "writeByte", + value: function writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + }, { + key: "writeInt", + value: function writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + }, { + key: "writeUInt", + value: function writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + }, { + key: "writeInt16", + value: function writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + }, { + key: "writeUInt16", + value: function writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + }, { + key: "writeInt32", + value: function writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeUInt32", + value: function writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeSingle", + value: function writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + }, { + key: "writeDouble", + value: function writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + }, { + key: "write7BitNumber", + value: function write7BitNumber(number) { + this.alloc(2); + + do { + var byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + }]); + + return BufferWriter; + }(); + + var MIN_MATCH = 2; + var NUM_CHARS = 256; + var BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 + }; + var PRETREE_NUM_ELEMENTS = 20; + var ALIGNED_NUM_ELEMENTS = 8; + var NUM_PRIMARY_LENGTHS = 7; + var NUM_SECONDARY_LENGTHS = 249; + var PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; + var PRETREE_TABLEBITS = 6; + var MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; + var MAINTREE_TABLEBITS = 12; + var LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; + var LENGTH_TABLEBITS = 12; + var ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; + var ALIGNED_TABLEBITS = 7; + + var Lzx = function () { + function Lzx(window_bits) { + _classCallCheck(this, Lzx); + + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (var i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (var _i = 0, _j = 0; _i <= 50; _i++) { + Lzx.position_base[_i] = _j; + _j += 1 << Lzx.extra_bits[_i]; + } + } + + var posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (var _i2 = 0; _i2 < MAINTREE_MAXSYMBOLS; _i2++) { + this.maintree_len[_i2] = 0; + } + + for (var _i3 = 0; _i3 < NUM_SECONDARY_LENGTHS; _i3++) { + this.length_len[_i3] = 0; + } + + this.win = []; + } + + _createClass(Lzx, [{ + key: "decompress", + value: function decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + var intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + var togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + var hi = buffer.readLZXBits(16); + var lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (var i = 0; i < 8; i++) { + this.aligned_len[i] = buffer.readLZXBits(3); + } + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + var this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + var main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + var length_footer = void 0; + var match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + var match_offset = main_element >> 3; + + if (match_offset > 2) { + var extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + var verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + var aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + var rundest = this.window_posn; + var runsrc = void 0; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + var copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) { + this.win[rundest++] = this.win[runsrc++]; + } + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) { + this.win[rundest++] = this.win[runsrc++]; + } + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + var _main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (_main_element < NUM_CHARS) { + this.win[this.window_posn++] = _main_element; + this_run--; + continue; + } + + _main_element -= NUM_CHARS; + + var _length_footer = void 0; + + var _match_length = _main_element & NUM_PRIMARY_LENGTHS; + + if (_match_length == NUM_PRIMARY_LENGTHS) { + _length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + _match_length += _length_footer; + } + + _match_length += MIN_MATCH; + + var _match_offset = _main_element >> 3; + + if (_match_offset > 2) { + if (_match_offset != 3) { + var _extra = Lzx.extra_bits[_match_offset]; + + var _verbatim_bits = buffer.readLZXBits(_extra); + + _match_offset = Lzx.position_base[_match_offset] - 2 + _verbatim_bits; + } else _match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = _match_offset; + } else if (_match_offset === 0) { + _match_offset = this.R0; + } else if (_match_offset == 1) { + _match_offset = this.R1; + this.R1 = this.R0; + this.R0 = _match_offset; + } else { + _match_offset = this.R2; + this.R2 = this.R0; + this.R0 = _match_offset; + } + + var _rundest = this.window_posn; + + var _runsrc = void 0; + + this_run -= _match_length; + if (this.window_posn >= _match_offset) _runsrc = _rundest - _match_offset;else { + _runsrc = _rundest + (this.window_size - _match_offset); + + var _copy_length = _match_offset - this.window_posn; + + if (_copy_length < _match_length) { + _match_length -= _copy_length; + this.window_posn += _copy_length; + + while (_copy_length-- > 0) { + this.win[_rundest++] = this.win[_runsrc++]; + } + + _runsrc = 0; + } + } + this.window_posn += _match_length; + + while (_match_length-- > 0) { + this.win[_rundest++] = this.win[_runsrc++]; + } + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (var _i4 = 0; _i4 < this_run; _i4++) { + this.win[window_posn + _i4] = buffer.buffer[buffer.bytePosition + _i4]; + } + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + var start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + }, { + key: "readLengths", + value: function readLengths(buffer, table, first, last) { + for (var i = 0; i < 20; i++) { + this.pretree_len[i] = buffer.readLZXBits(4); + } + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (var _i5 = first; _i5 < last;) { + var symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + var zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) { + table[_i5++] = 0; + } + } else if (symbol == 18) { + var _zeros = buffer.readLZXBits(5) + 20; + + while (_zeros-- != 0) { + table[_i5++] = 0; + } + } else if (symbol == 19) { + var same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[_i5] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) { + table[_i5++] = symbol; + } + } else { + symbol = table[_i5] - symbol; + if (symbol < 0) symbol += 17; + table[_i5++] = symbol; + } + } + + return table; + } + }, { + key: "decodeTable", + value: function decodeTable(symbols, bits, length) { + var table = []; + var pos = 0; + var table_mask = 1 << bits; + var bit_mask = table_mask >> 1; + + for (var bit_num = 1; bit_num <= bits; bit_num++) { + for (var symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + var leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + var fill = bit_mask; + + while (fill-- > 0) { + table[leaf++] = symbol; + } + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (var _symbol = pos; _symbol < table_mask; _symbol++) { + table[_symbol] = 0xFFFF; + } + + var next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (var _bit_num = bits + 1; _bit_num <= 16; _bit_num++) { + for (var _symbol2 = 0; _symbol2 < symbols; _symbol2++) { + if (length[_symbol2] != _bit_num) continue; + + var _leaf = pos >> 16; + + for (var _fill = 0; _fill < _bit_num - bits; _fill++) { + if (table[_leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[_leaf] = next_symbol++; + } + + _leaf = table[_leaf] << 1; + if (pos >> 15 - _fill & 1) _leaf++; + } + + table[_leaf] = _symbol2; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + }, { + key: "readHuffSymbol", + value: function readHuffSymbol(buffer, table, length, symbols, bits) { + var bit = buffer.peekLZXBits(32) >>> 0; + var i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + var j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + }, { + key: "RRR", + set: function set(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + var R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + var R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + }]); + + return Lzx; + }(); + + Lzx.position_base = []; + Lzx.extra_bits = []; + + var Presser = function () { + function Presser() { + _classCallCheck(this, Presser); + } + + _createClass(Presser, null, [{ + key: "decompress", + value: function decompress(buffer, compressedTodo, decompressedTodo) { + var pos = 0; + var block_size; + var frame_size; + var lzx = new Lzx(16); + var decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + var flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + }]); + + return Presser; + }(); + + var LZ4Utils = function () { + function LZ4Utils() { + _classCallCheck(this, LZ4Utils); + } + + _createClass(LZ4Utils, null, [{ + key: "hashU32", + value: function hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + }, { + key: "readU64", + value: function readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + }, { + key: "readU32", + value: function readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + }, { + key: "writeU32", + value: function writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + }, { + key: "imul", + value: function imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + }]); + + return LZ4Utils; + }(); + + var minMatch = 4; + var minLength = 13; + var searchLimit = 5; + var skipTrigger = 6; + var hashSize = 1 << 16; + var mlBits = 4; + var mlMask = (1 << mlBits) - 1; + var runBits = 4; + var runMask = (1 << runBits) - 1; + makeBuffer(5 << 20); + var hashTable = makeHashTable(); + + function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + var _hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + _hashTable[i] = 0; + } + + return _hashTable; + } + } + + function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + } + + function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } + } + + function compressBound(n) { + return n + n / 255 + 16 | 0; + } + + function decompressBlock(src, dst) { + var sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + var dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; + } + + function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; + } + + function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); + } + + var UTF16_BITES = [0xD800, 0xDC00]; + var UTF16_MASK = 1023; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + var codes = stringToUnicode(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + var StringReaderCore = function () { + function StringReaderCore() { + _classCallCheck(this, StringReaderCore); + } + + _createClass(StringReaderCore, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string) { + var size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }]); + + return StringReaderCore; + }(); + + var ReaderResolver = function () { + function ReaderResolver(readers) { + _classCallCheck(this, ReaderResolver); + + this.readers = readers; + } + + _createClass(ReaderResolver, [{ + key: "read", + value: function read(buffer) { + var index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + }, { + key: "write", + value: function write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + }, { + key: "getIndex", + value: function getIndex(reader) { + for (var i in this.readers) { + if (reader.toString() == this.readers[i].toString()) return i; + } + } + }]); + + return ReaderResolver; + }(); + + var XnbData = function () { + function XnbData(header, readers, content) { + _classCallCheck(this, XnbData); + + var target = header.target, + formatVersion = header.formatVersion, + hidef = header.hidef, + compressed = header.compressed; + this.header = { + target: target, + formatVersion: formatVersion, + hidef: hidef, + compressed: compressed + }; + this.readers = readers; + this.content = content; + } + + _createClass(XnbData, [{ + key: "target", + get: function get() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + }, { + key: "formatVersion", + get: function get() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + }, { + key: "hidef", + get: function get() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + }, { + key: "compressed", + get: function get() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + }, { + key: "contentType", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.type; + return "JSON"; + } + }, { + key: "rawContent", + get: function get() { + var raw = this.content.export; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, function (key, value) { + if (key === "export") return value.type; + return value; + }, 4); + } + }, { + key: "stringify", + value: function stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + }, { + key: "toString", + value: function toString() { + return this.stringify(); + } + }]); + + return XnbData; + }(); + + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; + } + + var XnbContent = _createClass(function XnbContent(data, ext) { + _classCallCheck(this, XnbContent); + + this.type = extensionToDatatype(ext); + this.content = data; + }); + + var HIDEF_MASK = 0x1; + var COMPRESSED_LZ4_MASK = 0x40; + var COMPRESSED_LZX_MASK = 0x80; + var XNB_COMPRESSED_PROLOGUE_SIZE = 14; + + var XnbConverter = function () { + function XnbConverter() { + _classCallCheck(this, XnbConverter); + + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + _createClass(XnbConverter, [{ + key: "load", + value: function load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + var decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + var compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + var decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + var trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); + + var _decompressed = new Uint8Array(decompressedSize); + + decompressBlock(trimmedArray, _decompressed); + this.buffer.copyFrom(_decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + var count = this.buffer.read7BitNumber(); + var stringReader = new StringReaderCore(); + var readers = []; + + for (var i = 0; i < count; i++) { + var type = stringReader.read(this.buffer); + var version = this.buffer.readInt32(); + var reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type: type, + version: version + }); + } + + var shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + var content = new ReaderResolver(this.readers); + var result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + }, { + key: "convert", + value: function convert(json) { + var buffer = new BufferWriter(); + var stringReader = new StringReaderCore(); + var _json$header = json.header, + target = _json$header.target, + formatVersion = _json$header.formatVersion, + hidef = _json$header.hidef, + compressed = _json$header.compressed; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + var lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (var _i2 = 0, _json$readers2 = json.readers; _i2 < _json$readers2.length; _i2++) { + var reader = _json$readers2[_i2]; + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + var content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + var trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + var trimmedArray = new Uint8Array(trimmed); + var compressedSize = compressBound(trimmedArray.length); + + var _compressed = new Uint8Array(compressedSize); + + compressedSize = compressSingleBlock(trimmedArray, _compressed); + _compressed = _compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(_compressed); + var returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + var fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + }, { + key: "_validateHeader", + value: function _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + var magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + var flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + }]); + + return XnbConverter; + }(); + + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + var i = 0; + var n = t.length; + var r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + var _e2 = t.charCodeAt(i++); + + if (_e2 >= 55296 && _e2 <= 56319) { + if (i < n) { + var _n = t.charCodeAt(i); + + 56320 == (64512 & _n) && (++i, _e2 = ((1023 & _e2) << 10) + (1023 & _n) + 65536); + } + + if (_e2 >= 55296 && _e2 <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + + var _e3 = new Uint8Array(s); + + _e3.set(a), a = _e3; + } + + if (0 != (4294967168 & _e2)) { + if (0 == (4294965248 & _e2)) a[r++] = _e2 >> 6 & 31 | 192;else if (0 == (4294901760 & _e2)) a[r++] = _e2 >> 12 & 15 | 224, a[r++] = _e2 >> 6 & 63 | 128;else { + if (0 != (4292870144 & _e2)) continue; + a[r++] = _e2 >> 18 & 7 | 240, a[r++] = _e2 >> 12 & 63 | 128, a[r++] = _e2 >> 6 & 63 | 128; + } + a[r++] = 63 & _e2 | 128; + } else a[r++] = _e2; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + var i = new Uint8Array(t); + var n = 0; + var r = i.length, + s = []; + + for (; n < r;) { + var _t2 = i[n++]; + if (0 === _t2) break; + if (0 == (128 & _t2)) s.push(_t2);else if (192 == (224 & _t2)) { + var _e4 = 63 & i[n++]; + + s.push((31 & _t2) << 6 | _e4); + } else if (224 == (240 & _t2)) { + var _e5 = 63 & i[n++], + _r = 63 & i[n++]; + + s.push((31 & _t2) << 12 | _e5 << 6 | _r); + } else if (240 == (248 & _t2)) { + var _e6 = (7 & _t2) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + + _e6 > 65535 && (_e6 -= 65536, s.push(_e6 >>> 10 & 1023 | 55296), _e6 = 56320 | 1023 & _e6), s.push(_e6); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } + }, + e = {}; + + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; + } + + i.d = function (t, e) { + for (var n in e) { + i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + } + }, i.o = function (t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; + var n = {}; + + (function () { + i.d(n, { + P: function P() { + return Mi; + }, + m: function m() { + return Fi; + } + }), i(396); + var t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + var r = function () { + function r() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, r); + + var i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + var n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + var a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + _createClass(r, [{ + key: "available", + value: function available() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + }, { + key: "isLittleEndian", + value: function isLittleEndian() { + return this.littleEndian; + } + }, { + key: "setLittleEndian", + value: function setLittleEndian() { + return this.littleEndian = !0, this; + } + }, { + key: "isBigEndian", + value: function isBigEndian() { + return !this.littleEndian; + } + }, { + key: "setBigEndian", + value: function setBigEndian() { + return this.littleEndian = !1, this; + } + }, { + key: "skip", + value: function skip() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + }, { + key: "seek", + value: function seek(t) { + return this.offset = t, this; + } + }, { + key: "mark", + value: function mark() { + return this._mark = this.offset, this; + } + }, { + key: "reset", + value: function reset() { + return this.offset = this._mark, this; + } + }, { + key: "pushMark", + value: function pushMark() { + return this._marks.push(this.offset), this; + } + }, { + key: "popMark", + value: function popMark() { + var t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + }, { + key: "rewind", + value: function rewind() { + return this.offset = 0, this; + } + }, { + key: "ensureAvailable", + value: function ensureAvailable() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + var _e7 = 2 * (this.offset + t), + _i2 = new Uint8Array(_e7); + + _i2.set(new Uint8Array(this.buffer)), this.buffer = _i2.buffer, this.length = this.byteLength = _e7, this._data = new DataView(this.buffer); + } + + return this; + } + }, { + key: "readBoolean", + value: function readBoolean() { + return 0 !== this.readUint8(); + } + }, { + key: "readInt8", + value: function readInt8() { + return this._data.getInt8(this.offset++); + } + }, { + key: "readUint8", + value: function readUint8() { + return this._data.getUint8(this.offset++); + } + }, { + key: "readByte", + value: function readByte() { + return this.readUint8(); + } + }, { + key: "readBytes", + value: function readBytes() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = new Uint8Array(t); + + for (var _i3 = 0; _i3 < t; _i3++) { + e[_i3] = this.readByte(); + } + + return e; + } + }, { + key: "readInt16", + value: function readInt16() { + var t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + }, { + key: "readUint16", + value: function readUint16() { + var t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + }, { + key: "readInt32", + value: function readInt32() { + var t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readUint32", + value: function readUint32() { + var t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readFloat32", + value: function readFloat32() { + var t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + }, { + key: "readFloat64", + value: function readFloat64() { + var t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readBigInt64", + value: function readBigInt64() { + var t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readBigUint64", + value: function readBigUint64() { + var t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + }, { + key: "readChar", + value: function readChar() { + return String.fromCharCode(this.readInt8()); + } + }, { + key: "readChars", + value: function readChars() { + var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + var e = ""; + + for (var _i4 = 0; _i4 < t; _i4++) { + e += this.readChar(); + } + + return e; + } + }, { + key: "readUtf8", + value: function readUtf8() { + var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + }, { + key: "writeBoolean", + value: function writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + }, { + key: "writeInt8", + value: function writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint8", + value: function writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + }, { + key: "writeByte", + value: function writeByte(t) { + return this.writeUint8(t); + } + }, { + key: "writeBytes", + value: function writeBytes(t) { + this.ensureAvailable(t.length); + + for (var _e8 = 0; _e8 < t.length; _e8++) { + this._data.setUint8(this.offset++, t[_e8]); + } + + return this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt16", + value: function writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint16", + value: function writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + }, { + key: "writeInt32", + value: function writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeUint32", + value: function writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat32", + value: function writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + }, { + key: "writeFloat64", + value: function writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigInt64", + value: function writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeBigUint64", + value: function writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + }, { + key: "writeChar", + value: function writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + }, { + key: "writeChars", + value: function writeChars(t) { + for (var _e9 = 0; _e9 < t.length; _e9++) { + this.writeUint8(t.charCodeAt(_e9)); + } + + return this; + } + }, { + key: "writeUtf8", + value: function writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + }, { + key: "toArray", + value: function toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + }, { + key: "_updateLastWrittenByte", + value: function _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + }]); + + return r; + }(); + + function s(t) { + var e = t.length; + + for (; --e >= 0;) { + t[e] = 0; + } + } + + var a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + var _ = new Array(60); + + s(_); + var f = new Array(512); + s(f); + var c = new Array(256); + s(c); + var u = new Array(29); + s(u); + var w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + var g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + var y = function y(t) { + return t < 256 ? f[t] : f[256 + (t >>> 7)]; + }, + v = function v(t, e) { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = function E(t, e, i) { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = function A(t, e, i) { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = function x(t, e) { + var i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = function U(t, e, i) { + var n = new Array(16); + var r, + s, + a = 0; + + for (r = 1; r <= 15; r++) { + n[r] = a = a + i[r - 1] << 1; + } + + for (s = 0; s <= e; s++) { + var _e10 = t[2 * s + 1]; + 0 !== _e10 && (t[2 * s] = x(n[_e10]++, _e10)); + } + }, + z = function z(t) { + var e; + + for (e = 0; e < 286; e++) { + t.dyn_ltree[2 * e] = 0; + } + + for (e = 0; e < 30; e++) { + t.dyn_dtree[2 * e] = 0; + } + + for (e = 0; e < 19; e++) { + t.bl_tree[2 * e] = 0; + } + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = function R(t) { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = function N(t, e, i, n) { + var r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = function T(t, e, i) { + var n = t.heap[i]; + var r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) { + t.heap[i] = t.heap[r], i = r, r <<= 1; + } + + t.heap[i] = n; + }, + O = function O(t, e, i) { + var n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = function L(t, e) { + var i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + var a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) { + 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + } + + for (; t.heap_len < 2;) { + h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + } + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) { + T(t, i, a); + } + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], function (t, e) { + var i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + var l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) { + t.bl_count[f] = 0; + } + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) { + d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + } + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) { + f--; + } + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) { + for (d = t.bl_count[f]; 0 !== d;) { + _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + } + } + }(t, e), U(i, l, t.bl_count); + }, + B = function B(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) { + r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + } + }, + C = function C(t, e, i) { + var n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) { + if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + } + }; + + var D = !1; + + var I = function I(t, e, i, n) { + E(t, 0 + (n ? 1 : 0), 3), function (t, e, i, n) { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + }(t, e, i); + }; + + var S = { + _tr_init: function _tr_init(t) { + D || (function () { + var t, e, i, n, r; + var s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) { + for (u[n] = i, t = 0; t < 1 << a[n]; t++) { + c[i++] = n; + } + } + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) { + for (w[n] = r, t = 0; t < 1 << o[n]; t++) { + f[r++] = n; + } + } + + for (r >>= 7; n < 30; n++) { + for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) { + f[256 + r++] = n; + } + } + + for (e = 0; e <= 15; e++) { + s[e] = 0; + } + + for (t = 0; t <= 143;) { + d[2 * t + 1] = 8, t++, s[8]++; + } + + for (; t <= 255;) { + d[2 * t + 1] = 9, t++, s[9]++; + } + + for (; t <= 279;) { + d[2 * t + 1] = 7, t++, s[7]++; + } + + for (; t <= 287;) { + d[2 * t + 1] = 8, t++, s[8]++; + } + + for (U(d, 287, s), t = 0; t < 30; t++) { + _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + } + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + }(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: function _tr_flush_block(t, e, i, n) { + var r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = function (t) { + var e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) { + if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + } + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) { + if (0 !== t.dyn_ltree[2 * e]) return 1; + } + + return 0; + }(t)), L(t, t.l_desc), L(t, t.d_desc), a = function (t) { + var e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--) { + } + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + }(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), function (t, e, i, n) { + var r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) { + E(t, t.bl_tree[2 * l[r] + 1], 3); + } + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + }(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: function _tr_tally(t, e, i) { + return t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1; + }, + _tr_align: function _tr_align(t) { + E(t, 2, 3), A(t, 256, d), function (t) { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + }(t); + } + }, + Z = function Z(t, e, i, n) { + var r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + var F = new Uint32Array(function () { + var t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) { + t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + } + + e[i] = t; + } + + return e; + }()); + + var M = function M(t, e, i, n) { + var r = F, + s = n + i; + t ^= -1; + + for (var _i5 = n; _i5 < s; _i5++) { + t = t >>> 8 ^ r[255 & (t ^ e[_i5])]; + } + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + var W = S._tr_init, + K = S._tr_stored_block, + $ = S._tr_flush_block, + Y = S._tr_tally, + j = S._tr_align, + G = H.Z_NO_FLUSH, + X = H.Z_PARTIAL_FLUSH, + V = H.Z_FULL_FLUSH, + q = H.Z_FINISH, + J = H.Z_BLOCK, + Q = H.Z_OK, + tt = H.Z_STREAM_END, + et = H.Z_STREAM_ERROR, + it = H.Z_DATA_ERROR, + nt = H.Z_BUF_ERROR, + rt = H.Z_DEFAULT_COMPRESSION, + st = H.Z_FILTERED, + at = H.Z_HUFFMAN_ONLY, + ot = H.Z_RLE, + ht = H.Z_FIXED, + dt = H.Z_UNKNOWN, + _t = H.Z_DEFLATED, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = function gt(t, e) { + return t.msg = P[e], e; + }, + bt = function bt(t) { + return (t << 1) - (t > 4 ? 9 : 0); + }, + mt = function mt(t) { + var e = t.length; + + for (; --e >= 0;) { + t[e] = 0; + } + }; + + var kt = function kt(t, e, i) { + return (e << t.hash_shift ^ i) & t.hash_mask; + }; + + var yt = function yt(t) { + var e = t.state; + var i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = function vt(t, e) { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = function Et(t, e) { + t.pending_buf[t.pending++] = e; + }, + At = function At(t, e) { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = function xt(t, e, i, n) { + var r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = function Ut(t, e) { + var i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + var h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + var c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = function zt(t) { + var e = t.w_size; + var i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));) { + } + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = function Rt(t, e) { + var i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = function Nt(t, e) { + var i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + var Ot = [new Tt(0, 0, 0, 0, function (t, e) { + var i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + + var _n2 = t.block_start + i; + + if ((0 === t.strstart || t.strstart >= _n2) && (t.lookahead = t.strstart - _n2, t.strstart = _n2, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + var Bt = function Bt(t) { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + var e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = function Ct(t) { + var e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = function Dt(t, e, i, n, r, s) { + if (!t) return et; + var a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + var o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = function St(t, e) { + return t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et; + }, + Zt = function Zt(t, e) { + var i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + var r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + var s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + var _e11 = _t + (r.w_bits - 8 << 4) << 8, + _i6 = -1; + + _i6 = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, _e11 |= _i6 << 6, 0 !== r.strstart && (_e11 |= 32), _e11 += 31 - _e11 % 31, r.status = wt, At(r, _e11), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) { + Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + } + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + var _i7 = r.strategy === at ? function (t, e) { + var i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : r.strategy === ot ? function (t, e) { + var i, n, r, s; + var a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }(r, e) : Ot[r.level].func(r, e); + + if (3 !== _i7 && 4 !== _i7 || (r.status = pt), 1 === _i7 || 3 === _i7) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === _i7 && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = function Ft(t) { + if (!t || !t.state) return et; + var e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = function Mt(t, e) { + var i = e.length; + if (!t || !t.state) return et; + var n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + + var _t3 = new Uint8Array(n.w_size); + + _t3.set(e.subarray(i - n.w_size, i), 0), e = _t3, i = n.w_size; + } + + var s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + var _t4 = n.strstart, + _e12 = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[_t4 + 3 - 1]), n.prev[_t4 & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = _t4, _t4++; + } while (--_e12); + + n.strstart = _t4, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + var Pt = function Pt(t, e) { + return Object.prototype.hasOwnProperty.call(t, e); + }; + + var Ht = function Ht(t) { + var e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + var _i8 = e.shift(); + + if (_i8) { + if ("object" != _typeof(_i8)) throw new TypeError(_i8 + "must be non-object"); + + for (var _e13 in _i8) { + Pt(_i8, _e13) && (t[_e13] = _i8[_e13]); + } + } + } + + return t; + }, + Wt = function Wt(t) { + var e = 0; + + for (var _i9 = 0, _n3 = t.length; _i9 < _n3; _i9++) { + e += t[_i9].length; + } + + var i = new Uint8Array(e); + + for (var _e14 = 0, _n4 = 0, _r2 = t.length; _e14 < _r2; _e14++) { + var _r3 = t[_e14]; + i.set(_r3, _n4), _n4 += _r3.length; + } + + return i; + }; + + var Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + var $t = new Uint8Array(256); + + for (var _t5 = 0; _t5 < 256; _t5++) { + $t[_t5] = _t5 >= 252 ? 6 : _t5 >= 248 ? 5 : _t5 >= 240 ? 4 : _t5 >= 224 ? 3 : _t5 >= 192 ? 2 : 1; + } + + $t[254] = $t[254] = 1; + + var Yt = function Yt(t) { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + var e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + } + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) { + i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + } + + return e; + }, + jt = function jt(t, e) { + var i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + var n, r; + var s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + var _e15 = t[n++]; + + if (_e15 < 128) { + s[r++] = _e15; + continue; + } + + var _a = $t[_e15]; + if (_a > 4) s[r++] = 65533, n += _a - 1;else { + for (_e15 &= 2 === _a ? 31 : 3 === _a ? 15 : 7; _a > 1 && n < i;) { + _e15 = _e15 << 6 | 63 & t[n++], _a--; + } + + _a > 1 ? s[r++] = 65533 : _e15 < 65536 ? s[r++] = _e15 : (_e15 -= 65536, s[r++] = 55296 | _e15 >> 10 & 1023, s[r++] = 56320 | 1023 & _e15); + } + } + + return function (t, e) { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + var i = ""; + + for (var _n5 = 0; _n5 < e; _n5++) { + i += String.fromCharCode(t[_n5]); + } + + return i; + }(s, r); + }, + Gt = function Gt(t, e) { + (e = e || t.length) > t.length && (e = t.length); + var i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) { + i--; + } + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + var Vt = Object.prototype.toString, + qt = H.Z_NO_FLUSH, + Jt = H.Z_SYNC_FLUSH, + Qt = H.Z_FULL_FLUSH, + te = H.Z_FINISH, + ee = H.Z_OK, + ie = H.Z_STREAM_END, + ne = H.Z_DEFAULT_COMPRESSION, + re = H.Z_DEFAULT_STRATEGY, + se = H.Z_DEFLATED; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + var e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + var _t6; + + if (_t6 = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, _t6), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + var i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize; + var r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + var i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + var U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) { + x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + } + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + var de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = function ue(t, e, i, n, r, s, a, o) { + var h = o.bits; + + var l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + var z = new Uint16Array(16), + R = new Uint16Array(16); + var N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) { + z[w] = 0; + } + + for (p = 0; p < n; p++) { + z[e[i + p]]++; + } + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--) { + } + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++) { + } + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) { + if (v <<= 1, v -= z[w], v < 0) return -1; + } + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) { + R[w + 1] = R[w] + z[w]; + } + + for (p = 0; p < n; p++) { + 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + } + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) { + l >>= 1; + } + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) { + k++, v <<= 1; + } + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + var we = H.Z_FINISH, + pe = H.Z_BLOCK, + ge = H.Z_TREES, + be = H.Z_OK, + me = H.Z_STREAM_END, + ke = H.Z_NEED_DICT, + ye = H.Z_STREAM_ERROR, + ve = H.Z_DATA_ERROR, + Ee = H.Z_MEM_ERROR, + Ae = H.Z_BUF_ERROR, + xe = H.Z_DEFLATED, + Ue = 12, + ze = 30, + Re = function Re(t) { + return (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + }; + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + var Te = function Te(t) { + if (!t || !t.state) return ye; + var e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = function Oe(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = function Le(t, e) { + var i; + if (!t || !t.state) return ye; + var n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = function Be(t, e) { + if (!t) return ye; + var i = new Ne(); + t.state = i, i.window = null; + var n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + var Ce, + De, + Ie = !0; + + var Se = function Se(t) { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + var _e16 = 0; + + for (; _e16 < 144;) { + t.lens[_e16++] = 8; + } + + for (; _e16 < 256;) { + t.lens[_e16++] = 9; + } + + for (; _e16 < 280;) { + t.lens[_e16++] = 7; + } + + for (; _e16 < 288;) { + t.lens[_e16++] = 8; + } + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), _e16 = 0; _e16 < 32;) { + t.lens[_e16++] = 5; + } + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = function Ze(t, e, i, n) { + var r; + var s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = function Pe(t, e) { + var i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + var x = new Uint8Array(4); + var U, z; + var R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) { + switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) { + i.lens[R[i.have++]] = 0; + } + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) { + i.lens[i.have++] = v; + } + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = function He(t) { + if (!t || !t.state) return ye; + var e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = function We(t, e) { + if (!t || !t.state) return ye; + var i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = function Ke(t, e) { + var i = e.length; + var n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + var Ye = Object.prototype.toString, + je = H.Z_NO_FLUSH, + Ge = H.Z_FINISH, + Xe = H.Z_OK, + Ve = H.Z_STREAM_END, + qe = H.Z_NEED_DICT, + Je = H.Z_STREAM_ERROR, + Qe = H.Z_DATA_ERROR, + ti = H.Z_MEM_ERROR; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + var e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + var i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + var i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + var i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + var s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) { + Fe(i), s = Pe(i, a); + } + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + var _t7 = Gt(i.output, i.next_out), + _e17 = i.next_out - _t7, + _r4 = jt(i.output, _t7); + + i.next_out = _e17, i.avail_out = n - _e17, _e17 && i.output.set(i.output.subarray(_t7, _t7 + _e17), 0), this.onData(_r4); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + var si = he.deflate, + hi = ni.Inflate, + li = ni.inflate; + var fi = si, + ci = hi, + ui = li; + var wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (var _t8 = 0; _t8 < 256; _t8++) { + var _e18 = _t8; + + for (var _t9 = 0; _t9 < 8; _t9++) { + 1 & _e18 ? _e18 = 3988292384 ^ _e18 >>> 1 : _e18 >>>= 1; + } + + pi[_t8] = _e18; + } + + var gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + var n = 4294967295; + + for (var _t10 = 0; _t10 < i; _t10++) { + n = pi[255 & (n ^ e[_t10])] ^ n >>> 8; + } + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + var Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + var Ui = function (_r5) { + _inherits(Ui, _r5); + + var _super = _createSuper(Ui); + + function Ui(t) { + var _this; + + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Ui); + + _this = _super.call(this, t); + var _e$checkCrc = e.checkCrc, + i = _e$checkCrc === void 0 ? !1 : _e$checkCrc; + _this._checkCrc = i, _this._inflator = new ci(), _this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, _this._end = !1, _this._hasPalette = !1, _this._palette = [], _this._compressionMethod = ki.UNKNOWN, _this._filterMethod = yi.UNKNOWN, _this._interlaceMethod = vi.UNKNOWN, _this._colorType = -1, _this.setBigEndian(); + return _this; + } + + _createClass(Ui, [{ + key: "decode", + value: function decode() { + for (this.decodeSignature(); !this._end;) { + this.decodeChunk(); + } + + return this.decodeImage(), this._png; + } + }, { + key: "decodeSignature", + value: function decodeSignature() { + for (var _t11 = 0; _t11 < wi.length; _t11++) { + if (this.readUint8() !== wi[_t11]) throw new Error("wrong PNG signature. Byte at ".concat(_t11, " should be ").concat(wi[_t11], ".")); + } + } + }, { + key: "decodeChunk", + value: function decodeChunk() { + var t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + var _i10 = this.readUint32(), + _n6 = t + 4, + _r6 = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - _n6 - 4, _n6), _n6); + + if (_r6 !== _i10) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(_i10, ", found ").concat(_r6)); + } else this.skip(4); + } + }, { + key: "decodeIHDR", + value: function decodeIHDR() { + var t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + var e = this.readUint8(); + var i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + }, { + key: "decodePLTE", + value: function decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + var e = t / 3; + this._hasPalette = !0; + var i = []; + this._palette = i; + + for (var _t12 = 0; _t12 < e; _t12++) { + i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + } + }, { + key: "decodeIDAT", + value: function decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + }, { + key: "decodetRNS", + value: function decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + var _e19 = 0; + + for (; _e19 < t; _e19++) { + var _t13 = this.readByte(); + + this._palette[_e19].push(_t13); + } + + for (; _e19 < this._palette.length; _e19++) { + this._palette[_e19].push(255); + } + } + } + }, { + key: "decodeiCCP", + value: function decodeiCCP(t) { + var e, + i = ""; + + for (; "\0" !== (e = this.readChar());) { + i += e; + } + + var n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + var r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + }, { + key: "decodetEXt", + value: function decodetEXt(t) { + var e, + i = ""; + + for (; "\0" !== (e = this.readChar());) { + i += e; + } + + this._png.text[i] = this.readChars(t - i.length - 1); + } + }, { + key: "decodepHYs", + value: function decodepHYs() { + var t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + }, { + key: "decodeImage", + value: function decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + var t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + }, { + key: "decodeInterlaceNull", + value: function decodeInterlaceNull(t) { + var e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + var s, + a, + o = Ei, + h = 0; + + for (var _l = 0; _l < e; _l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(_l * n, (_l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + var _t14 = new Uint16Array(r.buffer); + + if (xi) for (var _e20 = 0; _e20 < _t14.length; _e20++) { + _t14[_e20] = (255 & (l = _t14[_e20])) << 8 | l >> 8 & 255; + } + this._png.data = _t14; + } else this._png.data = r; + + var l; + } + }]); + + return Ui; + }(r); + + function zi(t, e, i) { + for (var _n7 = 0; _n7 < i; _n7++) { + e[_n7] = t[_n7]; + } + } + + function Ri(t, e, i, n) { + var r = 0; + + for (; r < n; r++) { + e[r] = t[r]; + } + + for (; r < i; r++) { + e[r] = t[r] + e[r - n] & 255; + } + } + + function Ni(t, e, i, n) { + var r = 0; + if (0 === i.length) for (; r < n; r++) { + e[r] = t[r]; + } else for (; r < n; r++) { + e[r] = t[r] + i[r] & 255; + } + } + + function Ti(t, e, i, n, r) { + var s = 0; + + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; + } + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] >> 1) & 255; + } + } else { + for (; s < r; s++) { + e[s] = t[s] + (i[s] >> 1) & 255; + } + + for (; s < n; s++) { + e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + } + + function Oi(t, e, i, n, r) { + var s = 0; + + if (0 === i.length) { + for (; s < r; s++) { + e[s] = t[s]; + } + + for (; s < n; s++) { + e[s] = t[s] + e[s - r] & 255; + } + } else { + for (; s < r; s++) { + e[s] = t[s] + i[s] & 255; + } + + for (; s < n; s++) { + e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + } + + function Li(t, e, i) { + var n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + var Bi = { + level: 3 + }; + + var Ci = function (_r7) { + _inherits(Ci, _r7); + + var _super2 = _createSuper(Ci); + + function Ci(t) { + var _this2; + + var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Ci); + + _this2 = _super2.call(this), _this2._colorType = mi.UNKNOWN, _this2._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), _this2._png = _this2._checkData(t), _this2.setBigEndian(); + return _this2; + } + + _createClass(Ci, [{ + key: "encode", + value: function encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + }, { + key: "encodeSignature", + value: function encodeSignature() { + this.writeBytes(wi); + } + }, { + key: "encodeIHDR", + value: function encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + }, { + key: "encodeIEND", + value: function encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + }, { + key: "encodeIDAT", + value: function encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + }, { + key: "encodeData", + value: function encodeData() { + var _this$_png = this._png, + t = _this$_png.width, + e = _this$_png.height, + i = _this$_png.channels, + n = _this$_png.depth, + s = _this$_png.data, + a = i * t, + o = new r().setBigEndian(); + var h = 0; + + for (var _t15 = 0; _t15 < e; _t15++) { + if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + } + + var l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + }, { + key: "_checkData", + value: function _checkData(t) { + var _ref = function (t) { + var _t$channels = t.channels, + e = _t$channels === void 0 ? 4 : _t$channels, + _t$depth = t.depth, + i = _t$depth === void 0 ? 8 : _t$depth; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + var n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + e = _ref.colorType, + i = _ref.channels, + n = _ref.depth, + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + var s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + }, { + key: "writeCrc", + value: function writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + }]); + + return Ci; + }(r); + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (var _r8 = 0; _r8 < i; _r8++) { + e.writeByte(t[n++]); + } + + return n; + } + + function Si(t, e, i, n) { + for (var _r9 = 0; _r9 < i; _r9++) { + e.writeUint16(t[n++]); + } + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + var Fi = function Fi(t, e, i) { + return new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(); + }, + Mi = function Mi(t) { + return function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + }; + })(); + + var r = n.P, + s = n.m; + + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } + + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + var s = stringify(o.data, gap, indentation); + + if (__includes(s, '\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === _typeof(o)) { + var isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + var _s = '\n'; + + for (var k in o) { + if (Object.hasOwnProperty.call(o, k)) { + _s += __repeatConcat(gap, indentation + 1); + + if (isArray) { + _s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (__includes(k, ': ')) { + _s += stringify(k, gap, indentation + 1); + _s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + _s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + _s += '\n'; + } + } + + return _s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } + + function preStringify(object) { + var space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = __repeatConcat(' ', Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); + } + + var LineGenerator = function () { + function LineGenerator(lines, indentString, startingLine) { + _classCallCheck(this, LineGenerator); + + this.startingLine = startingLine || 0; + this.lineIndex = -1; + var filteredLines = []; + + for (var i = 0; i < lines.length; i++) { + var trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + _createClass(LineGenerator, [{ + key: "getLineNumber", + value: function getLineNumber() { + return this.startingLine + this.lineIndex; + } + }, { + key: "nextGroup", + value: function nextGroup() { + var lines = []; + var baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + }, { + key: "next", + value: function next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + }, { + key: "peek", + value: function peek() { + return this.getLine(this.lineIndex + 1); + } + }, { + key: "finished", + value: function finished() { + return this.lineIndex == this.lines.length - 1; + } + }, { + key: "getLine", + value: function getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + }, { + key: "findIndentString", + value: function findIndentString() { + for (var _i2 = 0, _this$lines2 = this.lines; _i2 < _this$lines2.length; _i2++) { + var _this$lines2$_i = _this$lines2[_i2], + line = _this$lines2$_i[0]; + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + }, { + key: "indentLevel", + value: function indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + var indentLevel = 0; + var line = this.getLine(index); + + while (__startsWithString(line, this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + }]); + + return LineGenerator; + }(); + + function getObject(lineGroup, type) { + var object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + var line = lineGroup.next(); + var trimmedLine = line.trim(); + var keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + var typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + + var key = void 0, + value = void 0, + _type = void 0; + + if (__startsWithString(trimmedLine, '"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + _type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (__startsWithString(trimmedLine, '-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, _type); + } else { + value = getObject(lineGroup.nextGroup(), _type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; + } + + function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; + } + + function parse(str) { + var lines = str.replace(/\t/g, ' ').split('\n'); + var lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } + + function deepCopy(obj) { + var newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (var _i2 = 0; _i2 < obj.length; _i2++) { + var item = obj[_i2]; + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && _typeof(obj) === "object") { + newObj = {}; + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; + } + + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } + } + + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } + } + + function convertJsonContentsToXnbNode(raw, readers) { + var extractedImages = []; + var extractedMaps = []; + + var _recursiveConvert = function recursiveConvert(obj, path) { + var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + var reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (__startsWithString(reader, 'Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + var data; + if (Array.isArray(obj)) data = [];else data = {}; + var traversed = index; + var first = true; + var isComplex = !__startsWithString(reader, "Dictionary") && !__startsWithString(reader, "Array") && !__startsWithString(reader, "List"); + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i]; + obj[key]; + var newIndex = void 0; + if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; + + var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted = _recursiveConvert2.converted, + nexter = _recursiveConvert2.traversed; + + data[key] = _converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data: data + }, + traversed: traversed + }; + }(raw, []), + converted = _recursiveConvert.converted; + + return { + converted: converted, + extractedImages: extractedImages, + extractedMaps: extractedMaps + }; + } + + function convertJsonContentsFromXnbNode(obj) { + if (!obj || _typeof(obj) !== "object") return obj; + + if (_typeof(obj) === "object" && obj.hasOwnProperty("data")) { + var _obj = obj, + type = _obj.type, + data = _obj.data; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + var newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (var _i4 = 0, _obj3 = obj; _i4 < _obj3.length; _i4++) { + var item = _obj3[_i4]; + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && _typeof(obj) === "object") { + newObj = {}; + + var __keys = Object.keys(obj); + + for (var __i = 0; __i < __keys.length; __i++) { + var key = __keys[__i], + value = obj[key]; + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; + } + + function toXnbNodeData(json) { + var toYamlJson = {}; + var _json$header = json.header, + compressed = _json$header.compressed; + _json$header.formatVersion; + var hiDef = _json$header.hidef, + target = _json$header.target; + var readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target: target, + compressed: !!compressed, + hiDef: hiDef, + readerData: readerData, + numSharedResources: 0 + }; + var rawContent = deepCopy(json.content); + var mainReader = TypeReader.simplifyType(readerData[0].type); + var readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + var _convertJsonContentsT = convertJsonContentsToXnbNode(rawContent, readersTypeList), + converted = _convertJsonContentsT.converted, + extractedImages = _convertJsonContentsT.extractedImages, + extractedMaps = _convertJsonContentsT.extractedMaps; + + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } + + function fromXnbNodeData(json) { + var result = {}; + var _json$xnbData = json.xnbData, + compressed = _json$xnbData.compressed, + readerData = _json$xnbData.readerData, + hidef = _json$xnbData.hiDef, + target = _json$xnbData.target; + result.header = { + target: target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef: hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; + } + + function searchElement(parent, element) { + if (!parent || _typeof(parent) != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent: parent, + value: parent[element] + }; + } + + var __keys = Object.keys(parent); + + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + child = parent[__key]; + + if (!!child || _typeof(child) == 'object') { + var found = searchElement(child, element); + if (found) return found; + } + } + + return null; + } + + function extractFileName(fullname) { + var matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } + + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; + } + + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; + } + + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } + + function exportContent(content) { + var jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var found = searchElement(content, "export"); + + if (found) { + var value = found.value; + var dataType = value.type, + data = value.data; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + var contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + + function exportFiles(xnbObject) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$yaml = _ref.yaml, + isYaml = _ref$yaml === void 0 ? false : _ref$yaml, + _ref$contentOnly = _ref.contentOnly, + contentOnly = _ref$contentOnly === void 0 ? false : _ref$contentOnly, + _ref$fileName = _ref.fileName, + fileName = _ref$fileName === void 0 ? null : _ref$fileName; + + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + var blobs = []; + var content = xnbObject.content; + var contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + var resultJSON = JSON.stringify(xnbObject, function (key, value) { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + var result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } + + function resolveCompression(compressionString) { + var str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } + + function readBlobasText(_x) { + return _readBlobasText.apply(this, arguments); + } + + function _readBlobasText() { + _readBlobasText = _asyncToGenerator(regeneratorRuntime.mark(function _callee(blob) { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context.next = 4; + break; + } + + return _context.abrupt("return", blob.text()); + + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context.next = 6; + break; + } + + return _context.abrupt("return", blob.toString()); + + case 6: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _readBlobasText.apply(this, arguments); + } + + function readBlobasArrayBuffer(_x2) { + return _readBlobasArrayBuffer.apply(this, arguments); + } + + function _readBlobasArrayBuffer() { + _readBlobasArrayBuffer = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(blob) { + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!(typeof Blob === "function" && blob instanceof Blob)) { + _context2.next = 4; + break; + } + + return _context2.abrupt("return", blob.arrayBuffer()); + + case 4: + if (!(typeof Buffer === "function" && blob instanceof Buffer)) { + _context2.next = 6; + break; + } + + return _context2.abrupt("return", blob.buffer); + + case 6: + case "end": + return _context2.stop(); + } + } + }, _callee2); + })); + return _readBlobasArrayBuffer.apply(this, arguments); + } + + function readExternFiles(_x3, _x4) { + return _readExternFiles.apply(this, arguments); + } + + function _readExternFiles() { + _readExternFiles = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(extension, files) { + var rawPng, png, data, _data, _data2; + + return regeneratorRuntime.wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + if (!(extension === "png")) { + _context3.next = 6; + break; + } + + _context3.next = 3; + return readBlobasArrayBuffer(files.png); + + case 3: + rawPng = _context3.sent; + png = r(new Uint8Array(rawPng)); + return _context3.abrupt("return", { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }); + + case 6: + if (!(extension === "cso")) { + _context3.next = 11; + break; + } + + _context3.next = 9; + return readBlobasArrayBuffer(files.cso); + + case 9: + data = _context3.sent; + return _context3.abrupt("return", { + type: "Effect", + data: data + }); + + case 11: + if (!(extension === "tbin")) { + _context3.next = 16; + break; + } + + _context3.next = 14; + return readBlobasArrayBuffer(files.tbin); + + case 14: + _data = _context3.sent; + return _context3.abrupt("return", { + type: "TBin", + data: _data + }); + + case 16: + if (!(extension === "xml")) { + _context3.next = 21; + break; + } + + _context3.next = 19; + return readBlobasText(files.xml); + + case 19: + _data2 = _context3.sent; + return _context3.abrupt("return", { + type: "BmFont", + data: _data2 + }); + + case 21: + case "end": + return _context3.stop(); + } + } + }, _callee3); + })); + return _readExternFiles.apply(this, arguments); + } + + function resolveImports(_x5) { + return _resolveImports.apply(this, arguments); + } + + function _resolveImports() { + _resolveImports = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(files) { + var configs, + _configs$compression, + compression, + jsonFile, + rawText, + jsonData, + compressBits, + found, + parent, + value, + _extractFileName, + extension, + _args4 = arguments; + + return regeneratorRuntime.wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + configs = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}; + _configs$compression = configs.compression, compression = _configs$compression === void 0 ? "default" : _configs$compression; + jsonFile = files.json || files.yaml; + + if (jsonFile) { + _context4.next = 5; + break; + } + + throw new XnbError("There is no JSON or YAML file to pack!"); + + case 5: + _context4.next = 7; + return readBlobasText(jsonFile); + + case 7: + rawText = _context4.sent; + jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (jsonData.hasOwnProperty('content')) { + _context4.next = 14; + break; + } + + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + + case 14: + found = searchElement(jsonData.content, "export"); + + if (!found) { + _context4.next = 21; + break; + } + + parent = found.parent, value = found.value; + _extractFileName = extractFileName(value), extension = _extractFileName[1]; + _context4.next = 20; + return readExternFiles(extension, files); + + case 20: + parent.export = _context4.sent; + + case 21: + return _context4.abrupt("return", jsonData); + + case 22: + case "end": + return _context4.stop(); + } + } + }, _callee4); + })); + return _resolveImports.apply(this, arguments); + } + + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + + function unpackToXnbData(_x) { + return _unpackToXnbData.apply(this, arguments); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + + function _unpackToXnbData() { + _unpackToXnbData = _asyncToGenerator(regeneratorRuntime.mark(function _callee(file) { + var _extractFileName3, extension, buffer; + + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(typeof window !== "undefined")) { + _context.next = 8; + break; + } + + _extractFileName3 = extractFileName(file.name), extension = _extractFileName3[1]; + + if (!(extension !== "xnb")) { + _context.next = 4; + break; + } + + return _context.abrupt("return", new Error("Invalid XNB File!")); + + case 4: + _context.next = 6; + return file.arrayBuffer(); + + case 6: + buffer = _context.sent; + return _context.abrupt("return", bufferToXnb(buffer)); + + case 8: + return _context.abrupt("return", bufferToXnb(file.buffer)); + + case 9: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _unpackToXnbData.apply(this, arguments); + } + + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + + function unpackToFiles(file) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var _configs$yaml = configs.yaml, + yaml = _configs$yaml === void 0 ? false : _configs$yaml, + _configs$contentOnly = configs.contentOnly, + contentOnly = _configs$contentOnly === void 0 ? false : _configs$contentOnly, + _configs$fileName = configs.fileName, + name = _configs$fileName === void 0 ? null : _configs$fileName; + if (typeof window !== "undefined" && name === null) name = file.name; + + var _extractFileName = extractFileName(name), + fileName = _extractFileName[0]; + + var exporter = function exporter(xnbObject) { + return exportFiles(xnbObject, { + yaml: yaml, + contentOnly: contentOnly, + fileName: fileName + }); + }; + + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + + function bufferToXnb(buffer) { + var xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + + function bufferToContents(buffer) { + var xnb = new XnbConverter(); + var xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + + function xnbDataToContent(loadedXnb) { + var content = loadedXnb.content; + + var _exportContent = exportContent(content, true), + data = _exportContent.data, + extension = _exportContent.extension; + + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + + function fileMapper(files) { + var returnMap = {}; + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + + var _extractFileName2 = extractFileName(file.name), + fileName = _extractFileName2[0], + extension = _extractFileName2[1]; + + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + var namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + + function packJsonToBinary(json) { + var xnb = new XnbConverter(); + var buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + + function pack(files) { + var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var groupedFiles = fileMapper(files); + var promises = []; + + var __keys = Object.keys(groupedFiles); + + for (var __i = 0; __i < __keys.length; __i++) { + var fileName = __keys[__i], + filePack = groupedFiles[fileName]; + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(function (buffer) { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(function (blobArray) { + if (configs.debug === true) return blobArray; + return blobArray.filter(function (_ref) { + var status = _ref.status; + _ref.value; + return status === "fulfilled"; + }).map(function (_ref2) { + var value = _ref2.value; + return value; + }); + }); + } + + function setReaders(readers) { + return TypeReader.setReaders(readers); + } + + function addReaders(readers) { + return TypeReader.addReaders(readers); + } + + exports.XnbContent = XnbContent; + exports.XnbData = XnbData; + exports.addReaders = addReaders; + exports.bufferToContents = bufferToContents; + exports.bufferToXnb = bufferToXnb; + exports.pack = pack; + exports.setReaders = setReaders; + exports.unpackToContent = unpackToContent; + exports.unpackToFiles = unpackToFiles; + exports.unpackToXnbData = unpackToXnbData; + exports.xnbDataToContent = xnbDataToContent; + exports.xnbDataToFiles = exportFiles; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/src/core/dist/core.es5.min.js b/src/core/dist/core.es5.min.js new file mode 100644 index 0000000..12be656 --- /dev/null +++ b/src/core/dist/core.es5.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},z=I,j=P,D=function(t){return z(j(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},zt=x,jt=0,Dt=Math.random(),Ct=zt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++jt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,ze=r.TypeError,je=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return je(t,e,n)}:je:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return je(t,e,n)}catch(t){}if("get"in n||"set"in n)throw ze("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,zn=$e.CONFIGURABLE,jn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||zn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||jn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==zr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",zr=Br.POLYFILL="P",jr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,zo=C,jo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=za.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!jo(t)||!zo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!zo(t)||t,r.fail=zo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},zo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,zs=Te,js=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;zs(t);try{if(!(r=js(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return zs(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error)),eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"setReaders",value:function(e){t.readers=Qs({},e)}},{key:"addReaders",value:function(e){t.readers=Qs(Qs({},t.readers),e)}},{key:"makeSimplied",value:function(e,n){var r=e.split(/`|,/)[0];if(n.isTypeOf(r)){if(n.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n.type(),"<").concat(i.join(","),">")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(t.readers.hasOwnProperty("".concat(r,"Reader")))return t.readers["".concat(r,"Reader")].parseTypeList(i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(eh,"readers",{});var nh=[192,224,240],rh=128,ih=63,ah=[55296,56320],oh=1023;function sh(t){return t<128?[t]:t<2048?[nh[0]|t>>6,rh|t&ih]:t<65536?[nh[1]|t>>12,rh|t>>6&ih,rh|t&ih]:[nh[2]|t>>18,rh|t>>12&ih,rh|t>>6&ih,rh|t&ih]}function uh(t){return t<65535?[t]:[ah[0]|(t-=65536)>>10&oh,ah[1]|t&oh]}function hh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^nh[0])<<6)+(t[1]^rh):3===n?((t[0]^nh[1])<<12)+((t[1]^rh)<<6)+(t[2]^rh):((t[0]^nh[2])<<18)+((t[1]^rh)<<12)+((t[2]^rh)<<6)+(t[3]^rh)}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&oh)<<10)+(t[1]&oh)+65536}function ch(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),ph=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),vh=256,_h=0,yh=1,wh=2,gh=3,bh=656,mh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case wh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case yh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(bh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case gh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case wh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(h>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case yh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(_>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case gh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();mh.position_base=[],mh.extra_bits=[];var kh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new mh(16),s=new ph(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Eh=65536,Oh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||xh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Oh){for(e[f++]=240+_,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Oh){for(e[f++]=240,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Fh={};function Zh(t){var e=Fh[t];if(void 0!==e)return e.exports;var n=Fh[t]={exports:{}};return Ch[t].call(n.exports,n,n.exports,Zh),n.exports}Zh.d=function(t,e){for(var n in e)Zh.o(e,n)&&!Zh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Zh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Mh={};!function(){Zh.d(Mh,{P:function(){return Un},m:function(){return An}}),Zh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=z,G=j,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},jt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=zt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=jt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},ze=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=ze(a,r))===He&&s&&((n=De(a,s))===Ve?n=ze(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=ze(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=je(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Hh(t,n,-1)}var Gh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Yh(s,u):Kh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Yh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Jh(t){var e=t.replace(/\t/g,"\t").split("\n");return Kh(new Gh(e))}function $h(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Qh(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,f=!0,c=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function nf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=$h(i),e.content=tf(t.content),"SpriteFont"===eh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function rf(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=rf(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Xh(r.width,r.height,new Uint8Array(a))),uf(a,i)}if(e){var o=JSON.stringify(t,null,4);return uf(o,"JSON")}return null}function ff(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=hf(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(of(e.type)):"".concat(e.type,".").concat(of(e.type)):e}),4),l=c;return r&&(l=Wh(ef(t))),u.unshift(uf(l,r?"yaml":"JSON")),u}function cf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function lf(t){return df.apply(this,arguments)}function df(){return(df=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pf(t){return vf.apply(this,arguments)}function vf(){return(vf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _f(t,e){return yf.apply(this,arguments)}function yf(){return yf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,pf(n.png);case 3:return r=t.sent,i=Vh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,pf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,pf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,lf(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),yf.apply(this,arguments)}function wf(t){return gf.apply(this,arguments)}function gf(){return gf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,lf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):nf(Jh(o)),null!==(u=cf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=rf(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=af(c),d=l[1],t.next=20,_f(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),gf.apply(this,arguments)}function bf(t){return mf.apply(this,arguments)}function mf(){return(mf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=af(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",kf(r));case 8:return t.abrupt("return",kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kf(t){return(new Dh).load(t)}function xf(t){var e=hf(t.content,!0),n=e.data,r=e.extension;return new Nh(n,r)}function Ef(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Ef(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=af(s),h=u[0],f=function(t){return ff(t,{yaml:r,contentOnly:a,fileName:h})};return bf(t).then(f)},t.unpackToXnbData=bf,t.xnbDataToContent=xf,t.xnbDataToFiles=ff,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/core/dist/core.js b/src/core/dist/core.js new file mode 100644 index 0000000..4c94e26 --- /dev/null +++ b/src/core/dist/core.js @@ -0,0 +1,5362 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + + } + + class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + + } + + _defineProperty(TypeReader, "readers", {}); + + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; + const UTF8_SECOND_BITES = 0x80; + const UTF8_MASK = 0b111111; + const UTF16_BITES$1 = [0xD800, 0xDC00]; + const UTF16_MASK$1 = 0b1111111111; + + function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + } + + function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; + } + + function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); + } + + function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; + } + + function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; + } + + function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; + } + + function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; + } + + function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); + } + + function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); + } + + const LITTLE_ENDIAN = true; + + class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + + } + + class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + + } + + /** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ + const MIN_MATCH = 2; + const NUM_CHARS = 256; + const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 + }; + const PRETREE_NUM_ELEMENTS = 20; + const ALIGNED_NUM_ELEMENTS = 8; + const NUM_PRIMARY_LENGTHS = 7; + const NUM_SECONDARY_LENGTHS = 249; + const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; + const PRETREE_TABLEBITS = 6; + const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; + const MAINTREE_TABLEBITS = 12; + const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; + const LENGTH_TABLEBITS = 12; + const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; + const ALIGNED_TABLEBITS = 7; + + class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + + } + + Lzx.position_base = []; + Lzx.extra_bits = []; + + class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + + } + + class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + + } + + /** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ + const minMatch = 4; + const minLength = 13; + const searchLimit = 5; + const skipTrigger = 6; + const hashSize = 1 << 16; + const mlBits = 4; + const mlMask = (1 << mlBits) - 1; + const runBits = 4; + const runMask = (1 << runBits) - 1; + makeBuffer(5 << 20); + const hashTable = makeHashTable(); + + function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } + } + + function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + } + + function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } + } + + function compressBound(n) { + return n + n / 255 + 16 | 0; + } + + function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; + } + + function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; + } + + function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); + } + + const UTF16_BITES = [0xD800, 0xDC00]; + const UTF16_MASK = 0b1111111111; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + } + + class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + + } + + class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + + } + + function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; + } + + class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + + } + + const HIDEF_MASK = 0x1; + const COMPRESSED_LZ4_MASK = 0x40; + const COMPRESSED_LZX_MASK = 0x80; + const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + + class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + + } + + var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } + }, + e = {}; + + function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; + } + + i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); + }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + var n = {}; + + (() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); + })(); + + var r = n.P, + s = n.m; + + function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); + } + + function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } + } + + function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); + } + + class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + + } + + function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; + } + + function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; + } + + function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); + } + + function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; + } + + function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } + } + + function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } + } + + function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; + } + + function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; + } + + function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; + } + + function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; + } + + function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; + } + + function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; + } + + function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; + } + + function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; + } + + function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; + } + + function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; + } + /** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + + function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; + } + + function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; + } + + async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); + } + + async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; + } + + async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } + } + + async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; + } + + /** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + + async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); + } + /** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + + function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); + } + /** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + + function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); + } + /** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + + function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); + } + /** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + + function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); + } + /** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + + function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); + } + /** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + + function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; + } + /** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + + function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; + } + /** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + + function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); + } + + function setReaders(readers) { + return TypeReader.setReaders(readers); + } + + function addReaders(readers) { + return TypeReader.addReaders(readers); + } + + exports.XnbContent = XnbContent; + exports.XnbData = XnbData; + exports.addReaders = addReaders; + exports.bufferToContents = bufferToContents; + exports.bufferToXnb = bufferToXnb; + exports.pack = pack; + exports.setReaders = setReaders; + exports.unpackToContent = unpackToContent; + exports.unpackToFiles = unpackToFiles; + exports.unpackToXnbData = unpackToXnbData; + exports.xnbDataToContent = xnbDataToContent; + exports.xnbDataToFiles = exportFiles; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/src/core/dist/core.min.js b/src/core/dist/core.min.js new file mode 100644 index 0000000..9cc559a --- /dev/null +++ b/src/core/dist/core.min.js @@ -0,0 +1,41 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=n({},t)}static addReaders(t){a.readers=n(n({},a.readers),t)}static makeSimplied(t,e){let i=t.split(/`|,/)[0];if(e.isTypeOf(i)){if(e.hasSubType()){let i=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(i.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e)}for(let e of Object.values(a.readers)){let i=a.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let i=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return i}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(i=i.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}r(a,"readers",{});const o=[192,224,240],h=128,l=63,d=[55296,56320],f=1023;function c(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function u(t){return t<65535?[t]:[d[0]|(t-=65536)>>10&f,d[1]|t&f]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^o[0])<<6)+(t[1]^h):3===i?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&f)<<10)+(t[1]&f)+65536}function p(t){return function(t){const e=[];for(let i of t)e.push(...c(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class m{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */const y=256,v=0,k=1,x=2,E=3,A=656;class U{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!U.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)U.extra_bits[t]=U.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!U.position_base.length)for(let t=0,e=0;t<=50;t++)U.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(A,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case E:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){let e=U.extra_bits[s];if(s=U.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){if(3!=s){let e=U.extra_bits[s],i=t.readLZXBits(e);s=U.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case E:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}U.position_base=[],U.extra_bits=[];class R{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}} +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */const B=65536,O=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||R.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=O){for(e[d++]=240+p,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=O){for(e[d++]=240,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class z{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=S(e);t.write7BitNumber(i),t.writeString(e)}}class D{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class P{constructor(t,e,i){let{target:n,formatVersion:r,hidef:s,compressed:a}=t;this.header={target:n,formatVersion:r,hidef:s,compressed:a},this.readers=e,this.content=i}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class C{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const Z=64,F=128,V=14;class M{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new g(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==F){const e=this.fileSize-V,i=class{static decompress(t,e,i){let n,r,a=0;const o=new U(16);let h=new m(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,V,0,t),this.buffer.bytePosition=V}else if(this.compressionType==Z){const e=this.buffer.buffer.slice(V),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function X(t){var e=W[t];if(void 0!==e)return e.exports;var i=W[t]={exports:{}};return j[t].call(i.exports,i,i.exports,X),i.exports}X.d=(t,e)=>{for(var i in e)X.o(e,i)&&!X.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},X.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{X.d(H,{P:()=>Ti,m:()=>Li}),X(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),I(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:K,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},It=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=K(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new Lt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Ot),new Lt(4,5,16,8,Ot),new Lt(4,6,32,32,Ot),new Lt(4,4,16,16,It),new Lt(8,16,32,32,It),new Lt(8,16,128,128,It),new Lt(8,32,128,256,It),new Lt(32,128,258,1024,It),new Lt(32,258,258,4096,It)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,I,L,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(I=0,L=a[p]):a[p]>_?(I=T[N+a[p]],L=A[U+a[p]]):(I=96,L=0),l=1<>v)+d]=O<<24|I<<16|L|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Ie=!0;const Le=t=>{if(Ie){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Ie=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Le(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var K=H.P,Y=H.m;function G(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=G(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+G(t[s],e,i+1):s.includes(": ")?(r+=G(s,e,i+1),r+=": "+G(t[s],e,i+1)):r+=s+": "+G(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),G(t,i,-1)}class ${constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new $(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?Q(n,r):q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return q(new $(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(et(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=et(n);return e}return t}function it(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function nt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function rt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(it(e))return et(i);if(nt(e))return i=et(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;t=et(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(rt(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=rt(n);return e}return null}function st(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let d=a.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(it(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:r}}},traversed:a+1};if(nt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function at(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=et(n),e.content=rt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ot(i,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function dt(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ft(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:dt(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ct(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ot(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=Y(t.width,t.height,new Uint8Array(n))),ft(n,e)}if(e){return ft(JSON.stringify(t,null,4),"JSON")}return null}function ut(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ct(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),r.unshift(ft(l,e?"yaml":"JSON")),r}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function bt(t,e){if("png"===t){const t=await pt(e.png),i=K(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function gt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await wt(n);let a=null;a=t.json?JSON.parse(r):at(tt(r));let o=_t(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=ht(i);e.export=await bt(n,t)}return a}async function mt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return yt(await t.arrayBuffer())}return yt(t.buffer)}function yt(t){return(new M).load(t)}function vt(t){const{content:e}=t,{data:i,extension:n}=ct(e,!0);return new C(i,n)}function kt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=kt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(gt(e,i).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return a.setReaders(t)},t.unpackToContent=function(t){return mt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=ht(r);const a=t=>ut(t,{yaml:i,contentOnly:n,fileName:s});return mt(t).then(a)},t.unpackToXnbData=mt,t.xnbDataToContent=vt,t.xnbDataToFiles=ut,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/core/dist/core.module.js b/src/core/dist/core.module.js new file mode 100644 index 0000000..8c40cc2 --- /dev/null +++ b/src/core/dist/core.module.js @@ -0,0 +1,5341 @@ +const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + let mappedPromises = promises.map(p => { + return p.then(value => { + return { + status: 'fulfilled', + value + }; + }).catch(reason => { + return { + status: 'rejected', + reason + }; + }); + }); + return Promise.all(mappedPromises); +}; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.split('`')[1]; + subtype.slice(0, 1); + subtype = subtype.slice(2, -1); + let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; + let matches = subtype.match(pattern).map(e => { + return e.slice(1, -1); + }); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + +const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES = 0x80; +const UTF8_MASK = 0b111111; +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; + +function UTF8Encode(code) { + if (code < 0x80) return [code]; + if (code < 0x800) return [UTF8_FIRST_BITES[0] | code >> 6, UTF8_SECOND_BITES | code & UTF8_MASK]; + if (code < 0x10000) return [UTF8_FIRST_BITES[1] | code >> 12, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; + return [UTF8_FIRST_BITES[2] | code >> 18, UTF8_SECOND_BITES | code >> 12 & UTF8_MASK, UTF8_SECOND_BITES | code >> 6 & UTF8_MASK, UTF8_SECOND_BITES | code & UTF8_MASK]; +} + +function UTF16Encode(code) { + if (code < 0xFFFF) return [code]; + code -= 0x10000; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; +} + +function UTF8Decode(codeSet) { + var _codeSet; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet = codeSet) !== null && _codeSet !== void 0 && _codeSet.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + if (codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + if (codeSetRange === 3) { + return ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + (codeSet[2] ^ UTF8_SECOND_BITES); + } + + return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); +} + +function UTF16Decode$1(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; +} + +function stringToUnicode$1(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8ToUnicode(codes) { + const dataArray = codes instanceof ArrayBuffer ? new Uint8Array(codes) : codes; + const result = []; + let index = 0; + + while (index < dataArray.length) { + let headerCode = dataArray[index]; + + if ((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } else if (headerCode < UTF8_FIRST_BITES[1]) { + result.push(UTF8Decode(dataArray.slice(index, index + 2))); + index += 2; + } else if (headerCode < UTF8_FIRST_BITES[2]) { + result.push(UTF8Decode(dataArray.slice(index, index + 3))); + index += 3; + } else { + result.push(UTF8Decode(dataArray.slice(index, index + 4))); + index += 4; + } + } + + return result; +} + +function UnicodeToUTF8(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + + return result; +} + +function UnicodeToString(unicodeArr) { + const result = []; + + for (let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + const blockSize = 32768; + let resultStr = ""; + + for (let i = 0; i < result.length / blockSize; i++) { + resultStr += String.fromCharCode(...result.slice(i * blockSize, (i + 1) * blockSize)); + } + + return resultStr; +} + +function stringToUTF8(str) { + return UnicodeToUTF8(stringToUnicode$1(str)); +} + +function UTF8ToString(utf8Array) { + return UnicodeToString(UTF8ToUnicode(utf8Array)); +} + +const LITTLE_ENDIAN = true; + +class BufferReader { + constructor(buffer) { + let endianus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LITTLE_ENDIAN; + this._endianus = endianus; + this._buffer = buffer.slice(); + this._dataView = new DataView(this._buffer); + this._offset = 0; + this._bitOffset = 0; + } + + seek(index) { + let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._offset; + const offset = this._offset; + this._offset = Math.max(origin + Number.parseInt(index), 0); + if (this._offset < 0 || this._offset > this.buffer.length) throw new RangeError("Buffer seek out of bounds! ".concat(this._offset, " ").concat(this.buffer.length)); + return this._offset - offset; + } + + get bytePosition() { + return Number.parseInt(this._offset); + } + + set bytePosition(value) { + this._offset = value; + } + + get bitPosition() { + return Number.parseInt(this._bitOffset); + } + + set bitPosition(offset) { + if (offset < 0) offset = 16 - offset; + this._bitOffset = offset % 16; + const byteSeek = (offset - Math.abs(offset) % 16) / 16 * 2; + this.seek(byteSeek); + } + + get size() { + return this.buffer.byteLength; + } + + get buffer() { + return this._buffer; + } + + copyFrom(buffer) { + let targetIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let sourceIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let length = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : buffer.byteLength; + const sourceView = new Uint8Array(buffer); + const isOverflow = this.buffer.byteLength < length + targetIndex; + let targetBuffer = this.buffer; + let targetView = this._dataView; + + if (isOverflow) { + targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); + targetView = new DataView(targetBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + targetView.setUint8(i, this._dataView.getUint8(i)); + } + } + + for (let i = sourceIndex, j = targetIndex; i < length; i++, j++) { + targetView.setUint8(j, sourceView[i]); + } + + if (isOverflow) { + this._buffer = targetBuffer; + this._dataView = targetView; + } + } + + read(count) { + const buffer = this.buffer.slice(this._offset, this._offset + count); + this.seek(count); + return buffer; + } + + readByte() { + return this.readUInt(); + } + + readInt() { + const value = this._dataView.getInt8(this._offset); + + this.seek(1); + return value; + } + + readUInt() { + const value = this._dataView.getUint8(this._offset); + + this.seek(1); + return value; + } + + readUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + this.seek(2); + return value; + } + + readInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(4); + return value; + } + + readDouble() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + this.seek(8); + return value; + } + + readString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; + const chars = []; + this._offset; + + if (count === -1) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + return UTF8ToString(chars); + } + + peek(count) { + const buffer = this.read(count); + this.seek(-count); + return buffer; + } + + peekByte() { + return this.peekUInt(); + } + + peekInt() { + const value = this._dataView.getInt8(this._offset); + + return value; + } + + peekUInt() { + const value = this._dataView.getUint8(this._offset); + + return value; + } + + peekUInt16() { + const value = this._dataView.getUint16(this._offset, this._endianus); + + return value; + } + + peekUInt32() { + const value = this._dataView.getUint32(this._offset, this._endianus); + + return value; + } + + peekInt16() { + const value = this._dataView.getInt16(this._offset, this._endianus); + + return value; + } + + peekInt32() { + const value = this._dataView.getInt32(this._offset, this._endianus); + + return value; + } + + peekSingle() { + const value = this._dataView.getFloat32(this._offset, this._endianus); + + return value; + } + + peekDouble() { + const value = this._dataView.getFloat64(this._offset, this._endianus); + + return value; + } + + peekString() { + let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const chars = []; + const startOffset = this._offset; + + if (count === 0) { + while (this.peekByte(1) != 0x0) chars.push(this.readByte()); + } else { + for (let i = 0; i < count; i++) { + chars.push(this.readByte()); + } + } + + this.bytePosition = startOffset; + return UTF8ToString(chars); + } + + read7BitNumber() { + let result = 0; + let bitsRead = 0; + let value; + + do { + value = this.readByte(); + result |= (value & 0x7F) << bitsRead; + bitsRead += 7; + } while (value & 0x80); + + return result; + } + + readLZXBits(bits) { + let bitsLeft = bits; + let read = 0; + + while (bitsLeft > 0) { + const peek = this._dataView.getUint16(this._offset, true); + + const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); + const offset = 16 - this.bitPosition - bitsInFrame; + const value = (peek & 2 ** bitsInFrame - 1 << offset) >> offset; + bitsLeft -= bitsInFrame; + this.bitPosition += bitsInFrame; + read |= value << bitsLeft; + } + + return read; + } + + peekLZXBits(bits) { + let bitPosition = this.bitPosition; + let bytePosition = this.bytePosition; + const read = this.readLZXBits(bits); + this.bitPosition = bitPosition; + this.bytePosition = bytePosition; + return read; + } + + readLZXInt16() { + let seek = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const lsB = this.readByte(); + const msB = this.readByte(); + if (!seek) this.seek(-2); + return lsB << 8 | msB; + } + + align() { + if (this.bitPosition > 0) this.bitPosition += 16 - this.bitPosition; + } + +} + +class BufferWriter { + constructor() { + let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2048; + this._buffer = new ArrayBuffer(size); + this._dataView = new DataView(this._buffer); + this.bytePosition = 0; + } + + get buffer() { + return this._buffer; + } + + reconnectDataView() { + this._dataView = new DataView(this._buffer); + } + + trim() { + let pending = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + this._buffer = this.buffer.slice(0, this.bytePosition); + if (!pending) this.reconnectDataView(); + } + + alloc(bytes) { + if (this._buffer.byteLength <= this.bytePosition + bytes) { + const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); + const tDataView = new DataView(tBuffer); + + for (let i = 0; i < this.buffer.byteLength; i++) { + tDataView.setUint8(i, this._dataView.getUint8(i)); + } + + this._buffer = tBuffer; + this._dataView = tDataView; + } + + return this; + } + + concat(buffer) { + const targetBufferView = new Uint8Array(buffer); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + this.trim(); + } + + write(bytes) { + const targetBufferView = new Uint8Array(bytes); + const newPosition = this.bytePosition + targetBufferView.length; + this.alloc(targetBufferView.length); + + for (let i = this.bytePosition; i < newPosition; i++) { + this._dataView.setUint8(i, targetBufferView[i - this.bytePosition]); + } + + this.bytePosition = newPosition; + } + + writeString(str) { + let utf8Data = stringToUTF8(str); + this.write(utf8Data); + } + + writeByte(byte) { + this.alloc(1)._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } + + writeInt(number) { + this.alloc(1)._dataView.setInt8(this.bytePosition, number); + + this.bytePosition++; + } + + writeUInt(number) { + this.alloc(1)._dataView.setUint8(this.bytePosition, number); + + this.bytePosition++; + } + + writeInt16(number) { + this.alloc(2)._dataView.setInt16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeUInt16(number) { + this.alloc(2)._dataView.setUint16(this.bytePosition, number, true); + + this.bytePosition += 2; + } + + writeInt32(number) { + this.alloc(4)._dataView.setInt32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeUInt32(number) { + this.alloc(4)._dataView.setUint32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeSingle(number) { + this.alloc(4)._dataView.setFloat32(this.bytePosition, number, true); + + this.bytePosition += 4; + } + + writeDouble(number) { + this.alloc(8)._dataView.setFloat64(this.bytePosition, number, true); + + this.bytePosition += 8; + } + + write7BitNumber(number) { + this.alloc(2); + + do { + let byte = number & 0x7F; + number = number >> 7; + if (number) byte |= 0x80; + + this._dataView.setUint8(this.bytePosition, byte); + + this.bytePosition++; + } while (number); + } + +} + +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ +const MIN_MATCH = 2; +const NUM_CHARS = 256; +const BLOCKTYPE = { + INVALID: 0, + VERBATIM: 1, + ALIGNED: 2, + UNCOMPRESSED: 3 +}; +const PRETREE_NUM_ELEMENTS = 20; +const ALIGNED_NUM_ELEMENTS = 8; +const NUM_PRIMARY_LENGTHS = 7; +const NUM_SECONDARY_LENGTHS = 249; +const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; +const PRETREE_TABLEBITS = 6; +const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; +const MAINTREE_TABLEBITS = 12; +const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; +const LENGTH_TABLEBITS = 12; +const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; +const ALIGNED_TABLEBITS = 7; + +class Lzx { + constructor(window_bits) { + this.window_size = 1 << window_bits; + if (window_bits < 15 || window_bits > 21) throw new XnbError('Window size out of range!'); + + if (!Lzx.extra_bits.length) { + for (let i = 0, j = 0; i <= 50; i += 2) { + Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; + if (i != 0 && j < 17) j++; + } + } + + if (!Lzx.position_base.length) { + for (let i = 0, j = 0; i <= 50; i++) { + Lzx.position_base[i] = j; + j += 1 << Lzx.extra_bits[i]; + } + } + + const posn_slots = window_bits == 21 ? 50 : window_bits == 20 ? 42 : window_bits << 1; + this.R0 = this.R1 = this.R2 = 1; + this.main_elements = NUM_CHARS + (posn_slots << 3); + this.header_read = false; + this.block_remaining = 0; + this.block_type = BLOCKTYPE.INVALID; + this.window_posn = 0; + this.pretree_table = []; + this.pretree_len = []; + this.aligned_table = []; + this.aligned_len = []; + this.length_table = []; + this.length_len = []; + this.maintree_table = []; + this.maintree_len = []; + + for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) this.maintree_len[i] = 0; + + for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) this.length_len[i] = 0; + + this.win = []; + } + + decompress(buffer, frame_size, block_size) { + if (!this.header_read) { + const intel = buffer.readLZXBits(1); + if (intel != 0) throw new XnbError("Intel E8 Call found, invalid for XNB files."); + this.header_read = true; + } + + let togo = frame_size; + + while (togo > 0) { + if (this.block_remaining == 0) { + this.block_type = buffer.readLZXBits(3); + const hi = buffer.readLZXBits(16); + const lo = buffer.readLZXBits(8); + this.block_remaining = hi << 8 | lo; + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + for (let i = 0; i < 8; i++) this.aligned_len[i] = buffer.readLZXBits(3); + + this.aligned_table = this.decodeTable(ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS, this.aligned_len); + + case BLOCKTYPE.VERBATIM: + this.readLengths(buffer, this.maintree_len, 0, 256); + this.readLengths(buffer, this.maintree_len, 256, this.main_elements); + this.maintree_table = this.decodeTable(MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS, this.maintree_len); + this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); + this.length_table = this.decodeTable(LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS, this.length_len); + break; + + case BLOCKTYPE.UNCOMPRESSED: + buffer.align(); + this.R0 = buffer.readInt32(); + this.R1 = buffer.readInt32(); + this.R2 = buffer.readInt32(); + break; + + default: + throw new XnbError("Invalid Blocktype Found: ".concat(this.block_type)); + } + } + + let this_run = this.block_remaining; + + while ((this_run = this.block_remaining) > 0 && togo > 0) { + if (this_run > togo) this_run = togo; + togo -= this_run; + this.block_remaining -= this_run; + this.window_posn &= this.window_size - 1; + if (this.window_posn + this_run > this.window_size) throw new XnbError('Cannot run outside of window frame.'); + + switch (this.block_type) { + case BLOCKTYPE.ALIGNED: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + let extra = Lzx.extra_bits[match_offset]; + match_offset = Lzx.position_base[match_offset] - 2; + + if (extra > 3) { + extra -= 3; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset += verbatim_bits << 3; + let aligned_bits = this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + match_offset += aligned_bits; + } else if (extra == 3) { + match_offset += this.readHuffSymbol(buffer, this.aligned_table, this.aligned_len, ALIGNED_MAXSYMBOLS, ALIGNED_TABLEBITS); + } else if (extra > 0) match_offset += buffer.readLZXBits(extra);else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.VERBATIM: + while (this_run > 0) { + let main_element = this.readHuffSymbol(buffer, this.maintree_table, this.maintree_len, MAINTREE_MAXSYMBOLS, MAINTREE_TABLEBITS); + + if (main_element < NUM_CHARS) { + this.win[this.window_posn++] = main_element; + this_run--; + continue; + } + + main_element -= NUM_CHARS; + let length_footer; + let match_length = main_element & NUM_PRIMARY_LENGTHS; + + if (match_length == NUM_PRIMARY_LENGTHS) { + length_footer = this.readHuffSymbol(buffer, this.length_table, this.length_len, LENGTH_MAXSYMBOLS, LENGTH_TABLEBITS); + match_length += length_footer; + } + + match_length += MIN_MATCH; + let match_offset = main_element >> 3; + + if (match_offset > 2) { + if (match_offset != 3) { + let extra = Lzx.extra_bits[match_offset]; + let verbatim_bits = buffer.readLZXBits(extra); + match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; + } else match_offset = 1; + + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else if (match_offset === 0) { + match_offset = this.R0; + } else if (match_offset == 1) { + match_offset = this.R1; + this.R1 = this.R0; + this.R0 = match_offset; + } else { + match_offset = this.R2; + this.R2 = this.R0; + this.R0 = match_offset; + } + + let rundest = this.window_posn; + let runsrc; + this_run -= match_length; + if (this.window_posn >= match_offset) runsrc = rundest - match_offset;else { + runsrc = rundest + (this.window_size - match_offset); + let copy_length = match_offset - this.window_posn; + + if (copy_length < match_length) { + match_length -= copy_length; + this.window_posn += copy_length; + + while (copy_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + + runsrc = 0; + } + } + this.window_posn += match_length; + + while (match_length-- > 0) this.win[rundest++] = this.win[runsrc++]; + } + + break; + + case BLOCKTYPE.UNCOMPRESSED: + if (buffer.bytePosition + this_run > block_size) throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); + + for (let i = 0; i < this_run; i++) this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; + + buffer.bytePosition += this_run; + this.window_posn += this_run; + break; + + default: + throw new XnbError('Invalid blocktype specified!'); + } + } + } + + if (togo != 0) throw new XnbError('EOF reached with data left to go.'); + buffer.align(); + const start_window_pos = (this.window_posn == 0 ? this.window_size : this.window_posn) - frame_size; + return this.win.slice(start_window_pos, start_window_pos + frame_size); + } + + readLengths(buffer, table, first, last) { + for (let i = 0; i < 20; i++) this.pretree_len[i] = buffer.readLZXBits(4); + + this.pretree_table = this.decodeTable(PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS, this.pretree_len); + + for (let i = first; i < last;) { + let symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + + if (symbol == 17) { + let zeros = buffer.readLZXBits(4) + 4; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 18) { + let zeros = buffer.readLZXBits(5) + 20; + + while (zeros-- != 0) table[i++] = 0; + } else if (symbol == 19) { + let same = buffer.readLZXBits(1) + 4; + symbol = this.readHuffSymbol(buffer, this.pretree_table, this.pretree_len, PRETREE_MAXSYMBOLS, PRETREE_TABLEBITS); + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + + while (same-- != 0) table[i++] = symbol; + } else { + symbol = table[i] - symbol; + if (symbol < 0) symbol += 17; + table[i++] = symbol; + } + } + + return table; + } + + decodeTable(symbols, bits, length) { + let table = []; + let pos = 0; + let table_mask = 1 << bits; + let bit_mask = table_mask >> 1; + + for (let bit_num = 1; bit_num <= bits; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] == bit_num) { + let leaf = pos; + + if ((pos += bit_mask) > table_mask) { + throw new XnbError('Overrun table!'); + } + + let fill = bit_mask; + + while (fill-- > 0) table[leaf++] = symbol; + } + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + + for (let symbol = pos; symbol < table_mask; symbol++) table[symbol] = 0xFFFF; + + let next_symbol = table_mask >> 1 < symbols ? symbols : table_mask >> 1; + pos <<= 16; + table_mask <<= 16; + bit_mask = 1 << 15; + + for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { + for (let symbol = 0; symbol < symbols; symbol++) { + if (length[symbol] != bit_num) continue; + let leaf = pos >> 16; + + for (let fill = 0; fill < bit_num - bits; fill++) { + if (table[leaf] == 0xFFFF) { + table[next_symbol << 1] = 0xFFFF; + table[(next_symbol << 1) + 1] = 0xFFFF; + table[leaf] = next_symbol++; + } + + leaf = table[leaf] << 1; + if (pos >> 15 - fill & 1) leaf++; + } + + table[leaf] = symbol; + if ((pos += bit_mask) > table_mask) throw new XnbError('Overrun table during decoding.'); + } + + bit_mask >>= 1; + } + + if (pos == table_mask) return table; + throw new XnbError('Decode table did not reach table mask.'); + } + + readHuffSymbol(buffer, table, length, symbols, bits) { + let bit = buffer.peekLZXBits(32) >>> 0; + let i = table[buffer.peekLZXBits(bits)]; + + if (i >= symbols) { + let j = 1 << 32 - bits; + + do { + j >>= 1; + i <<= 1; + i |= (bit & j) != 0 ? 1 : 0; + if (j == 0) return 0; + } while ((i = table[i]) >= symbols); + } + + buffer.bitPosition += length[i]; + return i; + } + + set RRR(X) { + if (this.R0 != X && this.R1 != X && this.R2 != X) { + this.R2 = this.R1; + this.R1 = this.R0; + this.R0 = X; + } else if (this.R1 == X) { + let R1 = this.R1; + this.R1 = this.R0; + this.R0 = R1; + } else if (this.R2 == X) { + let R2 = this.R2; + this.R2 = this.R0; + this.R0 = R2; + } + } + +} + +Lzx.position_base = []; +Lzx.extra_bits = []; + +class Presser { + static decompress(buffer, compressedTodo, decompressedTodo) { + let pos = 0; + let block_size; + let frame_size; + const lzx = new Lzx(16); + let decompressed = new BufferWriter(decompressedTodo); + + while (pos < compressedTodo) { + const flag = buffer.readByte(); + + if (flag == 0xFF) { + frame_size = buffer.readLZXInt16(); + block_size = buffer.readLZXInt16(); + pos += 5; + } else { + buffer.seek(-1); + block_size = buffer.readLZXInt16(this.buffer); + frame_size = 0x8000; + pos += 2; + } + + if (block_size == 0 || frame_size == 0) break; + if (block_size > 0x10000 || frame_size > 0x10000) throw new XnbError('Invalid size read in compression content.'); + decompressed.write(lzx.decompress(buffer, frame_size, block_size)); + pos += block_size; + } + + console.log('File has been successfully decompressed!'); + decompressed.trim(); + return decompressed.buffer; + } + +} + +class LZ4Utils { + static hashU32(a) { + a = a | 0; + a = a + 2127912214 + (a << 12) | 0; + a = a ^ -949894596 ^ a >>> 19; + a = a + 374761393 + (a << 5) | 0; + a = a + -744332180 ^ a << 9; + a = a + -42973499 + (a << 3) | 0; + return a ^ -1252372727 ^ a >>> 16 | 0; + } + + static readU64(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + x |= b[n++] << 32; + x |= b[n++] << 40; + x |= b[n++] << 48; + x |= b[n++] << 56; + return x; + } + + static readU32(b, n) { + var x = 0; + x |= b[n++] << 0; + x |= b[n++] << 8; + x |= b[n++] << 16; + x |= b[n++] << 24; + return x; + } + + static writeU32(b, n, x) { + b[n++] = x >> 0 & 0xff; + b[n++] = x >> 8 & 0xff; + b[n++] = x >> 16 & 0xff; + b[n++] = x >> 24 & 0xff; + } + + static imul(a, b) { + var ah = a >>> 16; + var al = a & 65535; + var bh = b >>> 16; + var bl = b & 65535; + return al * bl + (ah * bl + al * bh << 16) | 0; + } + +} + +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ +const minMatch = 4; +const minLength = 13; +const searchLimit = 5; +const skipTrigger = 6; +const hashSize = 1 << 16; +const mlBits = 4; +const mlMask = (1 << mlBits) - 1; +const runBits = 4; +const runMask = (1 << runBits) - 1; +makeBuffer(5 << 20); +const hashTable = makeHashTable(); + +function makeHashTable() { + try { + return new Uint32Array(hashSize); + } catch (error) { + const hashTable = new Array(hashSize); + + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } + + return hashTable; + } +} + +function clearHashTable(table) { + for (var i = 0; i < hashSize; i++) { + hashTable[i] = 0; + } +} + +function makeBuffer(size) { + try { + return new Uint8Array(size); + } catch (error) { + var buf = new Array(size); + + for (var i = 0; i < size; i++) { + buf[i] = 0; + } + + return buf; + } +} + +function compressBound(n) { + return n + n / 255 + 16 | 0; +} + +function decompressBlock(src, dst) { + let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; + let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var mLength, mOffset, sEnd, n, i; + var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; + sEnd = sIndex + sLength; + + while (sIndex < sEnd) { + var token = src[sIndex++]; + var literalCount = token >> 4; + + if (literalCount > 0) { + if (literalCount === 0xf) { + while (true) { + literalCount += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + for (n = sIndex + literalCount; sIndex < n;) { + dst[dIndex++] = src[sIndex++]; + } + } + + if (sIndex >= sEnd) { + break; + } + + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; + + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; + + if (src[sIndex++] !== 0xff) { + break; + } + } + } + + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } + } + } + + return dIndex; +} + +function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; + + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; + } + + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; + + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; + } + + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; + + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } + + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } + + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; + + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } + + mAnchor = sIndex; + } + } + + if (mAnchor === 0) { + return 0; + } + + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; + + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } + + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; + } + + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; + } + + return dIndex; +} + +function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReaderCore { + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + +} + +class ReaderResolver { + constructor(readers) { + this.readers = readers; + } + + read(buffer) { + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); + } + + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } + + getIndex(reader) { + for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + } + +} + +class XnbData { + constructor(header, readers, content) { + let { + target, + formatVersion, + hidef, + compressed + } = header; + this.header = { + target, + formatVersion, + hidef, + compressed + }; + this.readers = readers; + this.content = content; + } + + get target() { + var _this$header; + + switch ((_this$header = this.header) === null || _this$header === void 0 ? void 0 : _this$header.target) { + case 'w': + return "Microsoft Windows"; + + case 'm': + return "Windows Phone 7"; + + case 'x': + return "Xbox 360"; + + case 'a': + return "Android"; + + case 'i': + return "iOS"; + + default: + return "Unknown"; + } + } + + get formatVersion() { + var _this$header2; + + switch ((_this$header2 = this.header) === null || _this$header2 === void 0 ? void 0 : _this$header2.formatVersion) { + case 0x3: + return "XNA Game Studio 3.0"; + + case 0x4: + return "XNA Game Studio 3.1"; + + case 0x5: + return "XNA Game Studio 4.0"; + + default: + return "Unknown"; + } + } + + get hidef() { + var _this$header3; + + return !!((_this$header3 = this.header) !== null && _this$header3 !== void 0 && _this$header3.hidef); + } + + get compressed() { + var _this$header4; + + return !!((_this$header4 = this.header) !== null && _this$header4 !== void 0 && _this$header4.compressed); + } + + get contentType() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.type; + return "JSON"; + } + + get rawContent() { + let { + export: raw + } = this.content; + if (raw !== undefined) return raw.data; + return JSON.stringify(this.content, (key, value) => { + if (key === "export") return value.type; + return value; + }, 4); + } + + stringify() { + return JSON.stringify({ + header: this.header, + readers: this.readers, + content: this.content + }, null, 4); + } + + toString() { + return this.stringify(); + } + +} + +function extensionToDatatype(extension) { + switch (extension) { + case "json": + return "JSON"; + + case "yaml": + return "yaml"; + + case "png": + return "Texture2D"; + + case "cso": + return "Effect"; + + case 'tbin': + return "TBin"; + + case 'xml': + return "BmFont"; + } + + return "Others"; +} + +class XnbContent { + constructor(data, ext) { + this.type = extensionToDatatype(ext); + this.content = data; + } + +} + +const HIDEF_MASK = 0x1; +const COMPRESSED_LZ4_MASK = 0x40; +const COMPRESSED_LZX_MASK = 0x80; +const XNB_COMPRESSED_PROLOGUE_SIZE = 14; + +class XnbConverter { + constructor() { + this.target = ''; + this.formatVersion = 0; + this.hidef = false; + this.compressed = false; + this.compressionType = 0; + this.buffer = null; + this.fileSize = 0; + this.readers = []; + this.sharedResources = []; + } + + load(arrayBuffer) { + this.buffer = new BufferReader(arrayBuffer); + + this._validateHeader(); + + console.info('XNB file validated successfully!'); + this.fileSize = this.buffer.readUInt32(); + if (this.buffer.size != this.fileSize) throw new XnbError('XNB file has been truncated!'); + + if (this.compressed) { + const decompressedSize = this.buffer.readUInt32(); + + if (this.compressionType == COMPRESSED_LZX_MASK) { + const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; + const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } else if (this.compressionType == COMPRESSED_LZ4_MASK) { + const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + const decompressed = new Uint8Array(decompressedSize); + decompressBlock(trimmedArray, decompressed); + this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); + this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; + } + } + + let count = this.buffer.read7BitNumber(); + const stringReader = new StringReaderCore(); + const readers = []; + + for (let i = 0; i < count; i++) { + const type = stringReader.read(this.buffer); + const version = this.buffer.readInt32(); + const reader = TypeReader.getReaderFromRaw(type); + this.readers.push(reader); + readers.push({ + type, + version + }); + } + + const shared = this.buffer.read7BitNumber(); + if (shared != 0) throw new XnbError("Unexpected (".concat(shared, ") shared resources.")); + const content = new ReaderResolver(this.readers); + const result = content.read(this.buffer); + console.log('Successfuly read XNB file!'); + return new XnbData({ + target: this.target, + formatVersion: this.formatVersion, + hidef: this.hidef, + compressed: this.compressed + }, readers, result); + } + + convert(json) { + const buffer = new BufferWriter(); + const stringReader = new StringReaderCore(); + let { + target, + formatVersion, + hidef, + compressed + } = json.header; + this.target = target; + this.formatVersion = formatVersion; + this.hidef = hidef; + const lz4Compression = this.target == 'a' || this.target == 'i' || (compressed & COMPRESSED_LZ4_MASK) != 0; + this.compressed = lz4Compression ? true : false; + buffer.writeString("XNB"); + buffer.writeString(this.target); + buffer.writeByte(this.formatVersion); + buffer.writeByte(this.hidef | (this.compressed && lz4Compression ? COMPRESSED_LZ4_MASK : 0)); + buffer.writeUInt32(0); + if (lz4Compression) buffer.writeUInt32(0); + buffer.write7BitNumber(json.readers.length); + + for (let reader of json.readers) { + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); + stringReader.write(buffer, reader.type); + buffer.writeUInt32(reader.version); + } + + buffer.write7BitNumber(0); + const content = new ReaderResolver(this.readers); + content.write(buffer, json.content); + buffer.trim(); + + if (lz4Compression) { + const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); + const trimmedArray = new Uint8Array(trimmed); + let compressedSize = compressBound(trimmedArray.length); + let compressed = new Uint8Array(compressedSize); + compressedSize = compressSingleBlock(trimmedArray, compressed); + compressed = compressed.slice(0, compressedSize); + buffer.bytePosition = 6; + buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + buffer.writeUInt32(trimmedArray.length); + buffer.concat(compressed); + let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); + return returnBuffer; + } + + let fileSize = buffer.bytePosition; + buffer.bytePosition = 6; + buffer.writeUInt32(fileSize, 6); + return buffer.buffer; + } + + _validateHeader() { + if (this.buffer == null) throw new XnbError('Buffer is null'); + const magic = this.buffer.readString(3); + if (magic != 'XNB') throw new XnbError("Invalid file magic found, expecting \"XNB\", found \"".concat(magic, "\"")); + this.target = this.buffer.readString(1).toLowerCase(); + this.formatVersion = this.buffer.readByte(); + const flags = this.buffer.readByte(1); + this.hidef = (flags & HIDEF_MASK) != 0; + this.compressed = flags & COMPRESSED_LZX_MASK || (flags & COMPRESSED_LZ4_MASK) != 0; + this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : flags & COMPRESSED_LZ4_MASK ? COMPRESSED_LZ4_MASK : 0; + } + +} + +var t = { + 396: function _() { + !function (t) { + if (t.TextEncoder && t.TextDecoder) return !1; + + function e() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t, "') is invalid.")); + } + + function i() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "utf-8"; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + fatal: !1 + }; + if ("utf-8" !== t) throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t, "') is invalid.")); + if (e.fatal) throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported."); + } + + Object.defineProperty(e.prototype, "encoding", { + value: "utf-8" + }), e.prototype.encode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to encode: the 'stream' option is unsupported."); + let i = 0; + const n = t.length; + let r = 0, + s = Math.max(32, n + (n >> 1) + 7), + a = new Uint8Array(s >> 3 << 3); + + for (; i < n;) { + let e = t.charCodeAt(i++); + + if (e >= 55296 && e <= 56319) { + if (i < n) { + const n = t.charCodeAt(i); + 56320 == (64512 & n) && (++i, e = ((1023 & e) << 10) + (1023 & n) + 65536); + } + + if (e >= 55296 && e <= 56319) continue; + } + + if (r + 4 > a.length) { + s += 8, s *= 1 + i / t.length * 2, s = s >> 3 << 3; + const e = new Uint8Array(s); + e.set(a), a = e; + } + + if (0 != (4294967168 & e)) { + if (0 == (4294965248 & e)) a[r++] = e >> 6 & 31 | 192;else if (0 == (4294901760 & e)) a[r++] = e >> 12 & 15 | 224, a[r++] = e >> 6 & 63 | 128;else { + if (0 != (4292870144 & e)) continue; + a[r++] = e >> 18 & 7 | 240, a[r++] = e >> 12 & 63 | 128, a[r++] = e >> 6 & 63 | 128; + } + a[r++] = 63 & e | 128; + } else a[r++] = e; + } + + return a.slice(0, r); + }, Object.defineProperty(i.prototype, "encoding", { + value: "utf-8" + }), Object.defineProperty(i.prototype, "fatal", { + value: !1 + }), Object.defineProperty(i.prototype, "ignoreBOM", { + value: !1 + }), i.prototype.decode = function (t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + stream: !1 + }; + if (e.stream) throw new Error("Failed to decode: the 'stream' option is unsupported."); + const i = new Uint8Array(t); + let n = 0; + const r = i.length, + s = []; + + for (; n < r;) { + const t = i[n++]; + if (0 === t) break; + if (0 == (128 & t)) s.push(t);else if (192 == (224 & t)) { + const e = 63 & i[n++]; + s.push((31 & t) << 6 | e); + } else if (224 == (240 & t)) { + const e = 63 & i[n++], + r = 63 & i[n++]; + s.push((31 & t) << 12 | e << 6 | r); + } else if (240 == (248 & t)) { + let e = (7 & t) << 18 | (63 & i[n++]) << 12 | (63 & i[n++]) << 6 | 63 & i[n++]; + e > 65535 && (e -= 65536, s.push(e >>> 10 & 1023 | 55296), e = 56320 | 1023 & e), s.push(e); + } + } + + return String.fromCharCode.apply(null, s); + }, t.TextEncoder = e, t.TextDecoder = i; + }("undefined" != typeof window ? window : "undefined" != typeof self ? self : this); + } +}, + e = {}; + +function i(n) { + var r = e[n]; + if (void 0 !== r) return r.exports; + var s = e[n] = { + exports: {} + }; + return t[n].call(s.exports, s, s.exports, i), s.exports; +} + +i.d = (t, e) => { + for (var n in e) i.o(e, n) && !i.o(t, n) && Object.defineProperty(t, n, { + enumerable: !0, + get: e[n] + }); +}, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e); +var n = {}; + +(() => { + i.d(n, { + P: () => Mi, + m: () => Fi + }), i(396); + const t = new TextDecoder("utf-8"), + e = new TextEncoder(); + + class r { + constructor() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8192; + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let i = !1; + "number" == typeof t ? t = new ArrayBuffer(t) : (i = !0, this.lastWrittenByte = t.byteLength); + const n = e.offset ? e.offset >>> 0 : 0, + s = t.byteLength - n; + let a = n; + (ArrayBuffer.isView(t) || t instanceof r) && (t.byteLength !== t.buffer.byteLength && (a = t.byteOffset + n), t = t.buffer), this.lastWrittenByte = i ? s : 0, this.buffer = t, this.length = s, this.byteLength = s, this.byteOffset = a, this.offset = 0, this.littleEndian = !0, this._data = new DataView(this.buffer, a, s), this._mark = 0, this._marks = []; + } + + available() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset + t <= this.length; + } + + isLittleEndian() { + return this.littleEndian; + } + + setLittleEndian() { + return this.littleEndian = !0, this; + } + + isBigEndian() { + return !this.littleEndian; + } + + setBigEndian() { + return this.littleEndian = !1, this; + } + + skip() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return this.offset += t, this; + } + + seek(t) { + return this.offset = t, this; + } + + mark() { + return this._mark = this.offset, this; + } + + reset() { + return this.offset = this._mark, this; + } + + pushMark() { + return this._marks.push(this.offset), this; + } + + popMark() { + const t = this._marks.pop(); + + if (void 0 === t) throw new Error("Mark stack empty"); + return this.seek(t), this; + } + + rewind() { + return this.offset = 0, this; + } + + ensureAvailable() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + + if (!this.available(t)) { + const e = 2 * (this.offset + t), + i = new Uint8Array(e); + i.set(new Uint8Array(this.buffer)), this.buffer = i.buffer, this.length = this.byteLength = e, this._data = new DataView(this.buffer); + } + + return this; + } + + readBoolean() { + return 0 !== this.readUint8(); + } + + readInt8() { + return this._data.getInt8(this.offset++); + } + + readUint8() { + return this._data.getUint8(this.offset++); + } + + readByte() { + return this.readUint8(); + } + + readBytes() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + const e = new Uint8Array(t); + + for (let i = 0; i < t; i++) e[i] = this.readByte(); + + return e; + } + + readInt16() { + const t = this._data.getInt16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readUint16() { + const t = this._data.getUint16(this.offset, this.littleEndian); + + return this.offset += 2, t; + } + + readInt32() { + const t = this._data.getInt32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readUint32() { + const t = this._data.getUint32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat32() { + const t = this._data.getFloat32(this.offset, this.littleEndian); + + return this.offset += 4, t; + } + + readFloat64() { + const t = this._data.getFloat64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigInt64() { + const t = this._data.getBigInt64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readBigUint64() { + const t = this._data.getBigUint64(this.offset, this.littleEndian); + + return this.offset += 8, t; + } + + readChar() { + return String.fromCharCode(this.readInt8()); + } + + readChars() { + let t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + let e = ""; + + for (let i = 0; i < t; i++) e += this.readChar(); + + return e; + } + + readUtf8() { + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return i = this.readBytes(e), t.decode(i); + var i; + } + + writeBoolean(t) { + return this.writeUint8(t ? 255 : 0), this; + } + + writeInt8(t) { + return this.ensureAvailable(1), this._data.setInt8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeUint8(t) { + return this.ensureAvailable(1), this._data.setUint8(this.offset++, t), this._updateLastWrittenByte(), this; + } + + writeByte(t) { + return this.writeUint8(t); + } + + writeBytes(t) { + this.ensureAvailable(t.length); + + for (let e = 0; e < t.length; e++) this._data.setUint8(this.offset++, t[e]); + + return this._updateLastWrittenByte(), this; + } + + writeInt16(t) { + return this.ensureAvailable(2), this._data.setInt16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeUint16(t) { + return this.ensureAvailable(2), this._data.setUint16(this.offset, t, this.littleEndian), this.offset += 2, this._updateLastWrittenByte(), this; + } + + writeInt32(t) { + return this.ensureAvailable(4), this._data.setInt32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeUint32(t) { + return this.ensureAvailable(4), this._data.setUint32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat32(t) { + return this.ensureAvailable(4), this._data.setFloat32(this.offset, t, this.littleEndian), this.offset += 4, this._updateLastWrittenByte(), this; + } + + writeFloat64(t) { + return this.ensureAvailable(8), this._data.setFloat64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigInt64(t) { + return this.ensureAvailable(8), this._data.setBigInt64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeBigUint64(t) { + return this.ensureAvailable(8), this._data.setBigUint64(this.offset, t, this.littleEndian), this.offset += 8, this._updateLastWrittenByte(), this; + } + + writeChar(t) { + return this.writeUint8(t.charCodeAt(0)); + } + + writeChars(t) { + for (let e = 0; e < t.length; e++) this.writeUint8(t.charCodeAt(e)); + + return this; + } + + writeUtf8(t) { + return this.writeBytes(function (t) { + return e.encode(t); + }(t)); + } + + toArray() { + return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte); + } + + _updateLastWrittenByte() { + this.offset > this.lastWrittenByte && (this.lastWrittenByte = this.offset); + } + + } + + function s(t) { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + } + + const a = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]), + o = new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]), + h = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]), + l = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), + d = new Array(576); + s(d); + + const _ = new Array(60); + + s(_); + const f = new Array(512); + s(f); + const c = new Array(256); + s(c); + const u = new Array(29); + s(u); + const w = new Array(30); + + function p(t, e, i, n, r) { + this.static_tree = t, this.extra_bits = e, this.extra_base = i, this.elems = n, this.max_length = r, this.has_stree = t && t.length; + } + + let g, b, m; + + function k(t, e) { + this.dyn_tree = t, this.max_code = 0, this.stat_desc = e; + } + + s(w); + + const y = t => t < 256 ? f[t] : f[256 + (t >>> 7)], + v = (t, e) => { + t.pending_buf[t.pending++] = 255 & e, t.pending_buf[t.pending++] = e >>> 8 & 255; + }, + E = (t, e, i) => { + t.bi_valid > 16 - i ? (t.bi_buf |= e << t.bi_valid & 65535, v(t, t.bi_buf), t.bi_buf = e >> 16 - t.bi_valid, t.bi_valid += i - 16) : (t.bi_buf |= e << t.bi_valid & 65535, t.bi_valid += i); + }, + A = (t, e, i) => { + E(t, i[2 * e], i[2 * e + 1]); + }, + x = (t, e) => { + let i = 0; + + do { + i |= 1 & t, t >>>= 1, i <<= 1; + } while (--e > 0); + + return i >>> 1; + }, + U = (t, e, i) => { + const n = new Array(16); + let r, + s, + a = 0; + + for (r = 1; r <= 15; r++) n[r] = a = a + i[r - 1] << 1; + + for (s = 0; s <= e; s++) { + let e = t[2 * s + 1]; + 0 !== e && (t[2 * s] = x(n[e]++, e)); + } + }, + z = t => { + let e; + + for (e = 0; e < 286; e++) t.dyn_ltree[2 * e] = 0; + + for (e = 0; e < 30; e++) t.dyn_dtree[2 * e] = 0; + + for (e = 0; e < 19; e++) t.bl_tree[2 * e] = 0; + + t.dyn_ltree[512] = 1, t.opt_len = t.static_len = 0, t.last_lit = t.matches = 0; + }, + R = t => { + t.bi_valid > 8 ? v(t, t.bi_buf) : t.bi_valid > 0 && (t.pending_buf[t.pending++] = t.bi_buf), t.bi_buf = 0, t.bi_valid = 0; + }, + N = (t, e, i, n) => { + const r = 2 * e, + s = 2 * i; + return t[r] < t[s] || t[r] === t[s] && n[e] <= n[i]; + }, + T = (t, e, i) => { + const n = t.heap[i]; + let r = i << 1; + + for (; r <= t.heap_len && (r < t.heap_len && N(e, t.heap[r + 1], t.heap[r], t.depth) && r++, !N(e, n, t.heap[r], t.depth));) t.heap[i] = t.heap[r], i = r, r <<= 1; + + t.heap[i] = n; + }, + O = (t, e, i) => { + let n, + r, + s, + h, + l = 0; + if (0 !== t.last_lit) do { + n = t.pending_buf[t.d_buf + 2 * l] << 8 | t.pending_buf[t.d_buf + 2 * l + 1], r = t.pending_buf[t.l_buf + l], l++, 0 === n ? A(t, r, e) : (s = c[r], A(t, s + 256 + 1, e), h = a[s], 0 !== h && (r -= u[s], E(t, r, h)), n--, s = y(n), A(t, s, i), h = o[s], 0 !== h && (n -= w[s], E(t, n, h))); + } while (l < t.last_lit); + A(t, 256, e); + }, + L = (t, e) => { + const i = e.dyn_tree, + n = e.stat_desc.static_tree, + r = e.stat_desc.has_stree, + s = e.stat_desc.elems; + let a, + o, + h, + l = -1; + + for (t.heap_len = 0, t.heap_max = 573, a = 0; a < s; a++) 0 !== i[2 * a] ? (t.heap[++t.heap_len] = l = a, t.depth[a] = 0) : i[2 * a + 1] = 0; + + for (; t.heap_len < 2;) h = t.heap[++t.heap_len] = l < 2 ? ++l : 0, i[2 * h] = 1, t.depth[h] = 0, t.opt_len--, r && (t.static_len -= n[2 * h + 1]); + + for (e.max_code = l, a = t.heap_len >> 1; a >= 1; a--) T(t, i, a); + + h = s; + + do { + a = t.heap[1], t.heap[1] = t.heap[t.heap_len--], T(t, i, 1), o = t.heap[1], t.heap[--t.heap_max] = a, t.heap[--t.heap_max] = o, i[2 * h] = i[2 * a] + i[2 * o], t.depth[h] = (t.depth[a] >= t.depth[o] ? t.depth[a] : t.depth[o]) + 1, i[2 * a + 1] = i[2 * o + 1] = h, t.heap[1] = h++, T(t, i, 1); + } while (t.heap_len >= 2); + + t.heap[--t.heap_max] = t.heap[1], ((t, e) => { + const i = e.dyn_tree, + n = e.max_code, + r = e.stat_desc.static_tree, + s = e.stat_desc.has_stree, + a = e.stat_desc.extra_bits, + o = e.stat_desc.extra_base, + h = e.stat_desc.max_length; + + let l, + d, + _, + f, + c, + u, + w = 0; + + for (f = 0; f <= 15; f++) t.bl_count[f] = 0; + + for (i[2 * t.heap[t.heap_max] + 1] = 0, l = t.heap_max + 1; l < 573; l++) d = t.heap[l], f = i[2 * i[2 * d + 1] + 1] + 1, f > h && (f = h, w++), i[2 * d + 1] = f, d > n || (t.bl_count[f]++, c = 0, d >= o && (c = a[d - o]), u = i[2 * d], t.opt_len += u * (f + c), s && (t.static_len += u * (r[2 * d + 1] + c))); + + if (0 !== w) { + do { + for (f = h - 1; 0 === t.bl_count[f];) f--; + + t.bl_count[f]--, t.bl_count[f + 1] += 2, t.bl_count[h]--, w -= 2; + } while (w > 0); + + for (f = h; 0 !== f; f--) for (d = t.bl_count[f]; 0 !== d;) _ = t.heap[--l], _ > n || (i[2 * _ + 1] !== f && (t.opt_len += (f - i[2 * _ + 1]) * i[2 * _], i[2 * _ + 1] = f), d--); + } + })(t, e), U(i, l, t.bl_count); + }, + B = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), e[2 * (i + 1) + 1] = 65535, n = 0; n <= i; n++) r = a, a = e[2 * (n + 1) + 1], ++o < h && r === a || (o < l ? t.bl_tree[2 * r] += o : 0 !== r ? (r !== s && t.bl_tree[2 * r]++, t.bl_tree[32]++) : o <= 10 ? t.bl_tree[34]++ : t.bl_tree[36]++, o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4)); + }, + C = (t, e, i) => { + let n, + r, + s = -1, + a = e[1], + o = 0, + h = 7, + l = 4; + + for (0 === a && (h = 138, l = 3), n = 0; n <= i; n++) if (r = a, a = e[2 * (n + 1) + 1], !(++o < h && r === a)) { + if (o < l) do { + A(t, r, t.bl_tree); + } while (0 != --o);else 0 !== r ? (r !== s && (A(t, r, t.bl_tree), o--), A(t, 16, t.bl_tree), E(t, o - 3, 2)) : o <= 10 ? (A(t, 17, t.bl_tree), E(t, o - 3, 3)) : (A(t, 18, t.bl_tree), E(t, o - 11, 7)); + o = 0, s = r, 0 === a ? (h = 138, l = 3) : r === a ? (h = 6, l = 3) : (h = 7, l = 4); + } + }; + + let D = !1; + + const I = (t, e, i, n) => { + E(t, 0 + (n ? 1 : 0), 3), ((t, e, i, n) => { + R(t), v(t, i), v(t, ~i), t.pending_buf.set(t.window.subarray(e, e + i), t.pending), t.pending += i; + })(t, e, i); + }; + + var S = { + _tr_init: t => { + D || ((() => { + let t, e, i, n, r; + const s = new Array(16); + + for (i = 0, n = 0; n < 28; n++) for (u[n] = i, t = 0; t < 1 << a[n]; t++) c[i++] = n; + + for (c[i - 1] = n, r = 0, n = 0; n < 16; n++) for (w[n] = r, t = 0; t < 1 << o[n]; t++) f[r++] = n; + + for (r >>= 7; n < 30; n++) for (w[n] = r << 7, t = 0; t < 1 << o[n] - 7; t++) f[256 + r++] = n; + + for (e = 0; e <= 15; e++) s[e] = 0; + + for (t = 0; t <= 143;) d[2 * t + 1] = 8, t++, s[8]++; + + for (; t <= 255;) d[2 * t + 1] = 9, t++, s[9]++; + + for (; t <= 279;) d[2 * t + 1] = 7, t++, s[7]++; + + for (; t <= 287;) d[2 * t + 1] = 8, t++, s[8]++; + + for (U(d, 287, s), t = 0; t < 30; t++) _[2 * t + 1] = 5, _[2 * t] = x(t, 5); + + g = new p(d, a, 257, 286, 15), b = new p(_, o, 0, 30, 15), m = new p(new Array(0), h, 0, 19, 7); + })(), D = !0), t.l_desc = new k(t.dyn_ltree, g), t.d_desc = new k(t.dyn_dtree, b), t.bl_desc = new k(t.bl_tree, m), t.bi_buf = 0, t.bi_valid = 0, z(t); + }, + _tr_stored_block: I, + _tr_flush_block: (t, e, i, n) => { + let r, + s, + a = 0; + t.level > 0 ? (2 === t.strm.data_type && (t.strm.data_type = (t => { + let e, + i = 4093624447; + + for (e = 0; e <= 31; e++, i >>>= 1) if (1 & i && 0 !== t.dyn_ltree[2 * e]) return 0; + + if (0 !== t.dyn_ltree[18] || 0 !== t.dyn_ltree[20] || 0 !== t.dyn_ltree[26]) return 1; + + for (e = 32; e < 256; e++) if (0 !== t.dyn_ltree[2 * e]) return 1; + + return 0; + })(t)), L(t, t.l_desc), L(t, t.d_desc), a = (t => { + let e; + + for (B(t, t.dyn_ltree, t.l_desc.max_code), B(t, t.dyn_dtree, t.d_desc.max_code), L(t, t.bl_desc), e = 18; e >= 3 && 0 === t.bl_tree[2 * l[e] + 1]; e--); + + return t.opt_len += 3 * (e + 1) + 5 + 5 + 4, e; + })(t), r = t.opt_len + 3 + 7 >>> 3, s = t.static_len + 3 + 7 >>> 3, s <= r && (r = s)) : r = s = i + 5, i + 4 <= r && -1 !== e ? I(t, e, i, n) : 4 === t.strategy || s === r ? (E(t, 2 + (n ? 1 : 0), 3), O(t, d, _)) : (E(t, 4 + (n ? 1 : 0), 3), ((t, e, i, n) => { + let r; + + for (E(t, e - 257, 5), E(t, i - 1, 5), E(t, n - 4, 4), r = 0; r < n; r++) E(t, t.bl_tree[2 * l[r] + 1], 3); + + C(t, t.dyn_ltree, e - 1), C(t, t.dyn_dtree, i - 1); + })(t, t.l_desc.max_code + 1, t.d_desc.max_code + 1, a + 1), O(t, t.dyn_ltree, t.dyn_dtree)), z(t), n && R(t); + }, + _tr_tally: (t, e, i) => (t.pending_buf[t.d_buf + 2 * t.last_lit] = e >>> 8 & 255, t.pending_buf[t.d_buf + 2 * t.last_lit + 1] = 255 & e, t.pending_buf[t.l_buf + t.last_lit] = 255 & i, t.last_lit++, 0 === e ? t.dyn_ltree[2 * i]++ : (t.matches++, e--, t.dyn_ltree[2 * (c[i] + 256 + 1)]++, t.dyn_dtree[2 * y(e)]++), t.last_lit === t.lit_bufsize - 1), + _tr_align: t => { + E(t, 2, 3), A(t, 256, d), (t => { + 16 === t.bi_valid ? (v(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : t.bi_valid >= 8 && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8); + })(t); + } + }, + Z = (t, e, i, n) => { + let r = 65535 & t | 0, + s = t >>> 16 & 65535 | 0, + a = 0; + + for (; 0 !== i;) { + a = i > 2e3 ? 2e3 : i, i -= a; + + do { + r = r + e[n++] | 0, s = s + r | 0; + } while (--a); + + r %= 65521, s %= 65521; + } + + return r | s << 16 | 0; + }; + + const F = new Uint32Array((() => { + let t, + e = []; + + for (var i = 0; i < 256; i++) { + t = i; + + for (var n = 0; n < 8; n++) t = 1 & t ? 3988292384 ^ t >>> 1 : t >>> 1; + + e[i] = t; + } + + return e; + })()); + + var M = (t, e, i, n) => { + const r = F, + s = n + i; + t ^= -1; + + for (let i = n; i < s; i++) t = t >>> 8 ^ r[255 & (t ^ e[i])]; + + return -1 ^ t; + }, + P = { + 2: "need dictionary", + 1: "stream end", + 0: "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version" + }, + H = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8 + }; + + const { + _tr_init: W, + _tr_stored_block: K, + _tr_flush_block: $, + _tr_tally: Y, + _tr_align: j + } = S, + { + Z_NO_FLUSH: G, + Z_PARTIAL_FLUSH: X, + Z_FULL_FLUSH: V, + Z_FINISH: q, + Z_BLOCK: J, + Z_OK: Q, + Z_STREAM_END: tt, + Z_STREAM_ERROR: et, + Z_DATA_ERROR: it, + Z_BUF_ERROR: nt, + Z_DEFAULT_COMPRESSION: rt, + Z_FILTERED: st, + Z_HUFFMAN_ONLY: at, + Z_RLE: ot, + Z_FIXED: ht, + Z_DEFAULT_STRATEGY: lt, + Z_UNKNOWN: dt, + Z_DEFLATED: _t + } = H, + ft = 258, + ct = 262, + ut = 103, + wt = 113, + pt = 666, + gt = (t, e) => (t.msg = P[e], e), + bt = t => (t << 1) - (t > 4 ? 9 : 0), + mt = t => { + let e = t.length; + + for (; --e >= 0;) t[e] = 0; + }; + + let kt = (t, e, i) => (e << t.hash_shift ^ i) & t.hash_mask; + + const yt = t => { + const e = t.state; + let i = e.pending; + i > t.avail_out && (i = t.avail_out), 0 !== i && (t.output.set(e.pending_buf.subarray(e.pending_out, e.pending_out + i), t.next_out), t.next_out += i, e.pending_out += i, t.total_out += i, t.avail_out -= i, e.pending -= i, 0 === e.pending && (e.pending_out = 0)); + }, + vt = (t, e) => { + $(t, t.block_start >= 0 ? t.block_start : -1, t.strstart - t.block_start, e), t.block_start = t.strstart, yt(t.strm); + }, + Et = (t, e) => { + t.pending_buf[t.pending++] = e; + }, + At = (t, e) => { + t.pending_buf[t.pending++] = e >>> 8 & 255, t.pending_buf[t.pending++] = 255 & e; + }, + xt = (t, e, i, n) => { + let r = t.avail_in; + return r > n && (r = n), 0 === r ? 0 : (t.avail_in -= r, e.set(t.input.subarray(t.next_in, t.next_in + r), i), 1 === t.state.wrap ? t.adler = Z(t.adler, e, r, i) : 2 === t.state.wrap && (t.adler = M(t.adler, e, r, i)), t.next_in += r, t.total_in += r, r); + }, + Ut = (t, e) => { + let i, + n, + r = t.max_chain_length, + s = t.strstart, + a = t.prev_length, + o = t.nice_match; + const h = t.strstart > t.w_size - ct ? t.strstart - (t.w_size - ct) : 0, + l = t.window, + d = t.w_mask, + _ = t.prev, + f = t.strstart + ft; + let c = l[s + a - 1], + u = l[s + a]; + t.prev_length >= t.good_match && (r >>= 2), o > t.lookahead && (o = t.lookahead); + + do { + if (i = e, l[i + a] === u && l[i + a - 1] === c && l[i] === l[s] && l[++i] === l[s + 1]) { + s += 2, i++; + + do {} while (l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && l[++s] === l[++i] && s < f); + + if (n = ft - (f - s), s = f - ft, n > a) { + if (t.match_start = e, a = n, n >= o) break; + c = l[s + a - 1], u = l[s + a]; + } + } + } while ((e = _[e & d]) > h && 0 != --r); + + return a <= t.lookahead ? a : t.lookahead; + }, + zt = t => { + const e = t.w_size; + let i, n, r, s, a; + + do { + if (s = t.window_size - t.lookahead - t.strstart, t.strstart >= e + (e - ct)) { + t.window.set(t.window.subarray(e, e + e), 0), t.match_start -= e, t.strstart -= e, t.block_start -= e, n = t.hash_size, i = n; + + do { + r = t.head[--i], t.head[i] = r >= e ? r - e : 0; + } while (--n); + + n = e, i = n; + + do { + r = t.prev[--i], t.prev[i] = r >= e ? r - e : 0; + } while (--n); + + s += e; + } + + if (0 === t.strm.avail_in) break; + if (n = xt(t.strm, t.window, t.strstart + t.lookahead, s), t.lookahead += n, t.lookahead + t.insert >= 3) for (a = t.strstart - t.insert, t.ins_h = t.window[a], t.ins_h = kt(t, t.ins_h, t.window[a + 1]); t.insert && (t.ins_h = kt(t, t.ins_h, t.window[a + 3 - 1]), t.prev[a & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = a, a++, t.insert--, !(t.lookahead + t.insert < 3));); + } while (t.lookahead < ct && 0 !== t.strm.avail_in); + }, + Rt = (t, e) => { + let i, n; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), 0 !== i && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i)), t.match_length >= 3) { + if (n = Y(t, t.strstart - t.match_start, t.match_length - 3), t.lookahead -= t.match_length, t.match_length <= t.max_lazy_match && t.lookahead >= 3) { + t.match_length--; + + do { + t.strstart++, t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart; + } while (0 != --t.match_length); + + t.strstart++; + } else t.strstart += t.match_length, t.match_length = 0, t.ins_h = t.window[t.strstart], t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 1]); + } else n = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++; + if (n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }, + Nt = (t, e) => { + let i, n, r; + + for (;;) { + if (t.lookahead < ct) { + if (zt(t), t.lookahead < ct && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (i = 0, t.lookahead >= 3 && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart), t.prev_length = t.match_length, t.prev_match = t.match_start, t.match_length = 2, 0 !== i && t.prev_length < t.max_lazy_match && t.strstart - i <= t.w_size - ct && (t.match_length = Ut(t, i), t.match_length <= 5 && (t.strategy === st || 3 === t.match_length && t.strstart - t.match_start > 4096) && (t.match_length = 2)), t.prev_length >= 3 && t.match_length <= t.prev_length) { + r = t.strstart + t.lookahead - 3, n = Y(t, t.strstart - 1 - t.prev_match, t.prev_length - 3), t.lookahead -= t.prev_length - 1, t.prev_length -= 2; + + do { + ++t.strstart <= r && (t.ins_h = kt(t, t.ins_h, t.window[t.strstart + 3 - 1]), i = t.prev[t.strstart & t.w_mask] = t.head[t.ins_h], t.head[t.ins_h] = t.strstart); + } while (0 != --t.prev_length); + + if (t.match_available = 0, t.match_length = 2, t.strstart++, n && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } else if (t.match_available) { + if (n = Y(t, 0, t.window[t.strstart - 1]), n && vt(t, !1), t.strstart++, t.lookahead--, 0 === t.strm.avail_out) return 1; + } else t.match_available = 1, t.strstart++, t.lookahead--; + } + + return t.match_available && (n = Y(t, 0, t.window[t.strstart - 1]), t.match_available = 0), t.insert = t.strstart < 2 ? t.strstart : 2, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + }; + + function Tt(t, e, i, n, r) { + this.good_length = t, this.max_lazy = e, this.nice_length = i, this.max_chain = n, this.func = r; + } + + const Ot = [new Tt(0, 0, 0, 0, (t, e) => { + let i = 65535; + + for (i > t.pending_buf_size - 5 && (i = t.pending_buf_size - 5);;) { + if (t.lookahead <= 1) { + if (zt(t), 0 === t.lookahead && e === G) return 1; + if (0 === t.lookahead) break; + } + + t.strstart += t.lookahead, t.lookahead = 0; + const n = t.block_start + i; + if ((0 === t.strstart || t.strstart >= n) && (t.lookahead = t.strstart - n, t.strstart = n, vt(t, !1), 0 === t.strm.avail_out)) return 1; + if (t.strstart - t.block_start >= t.w_size - ct && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : (t.strstart > t.block_start && (vt(t, !1), t.strm.avail_out), 1); + }), new Tt(4, 4, 8, 4, Rt), new Tt(4, 5, 16, 8, Rt), new Tt(4, 6, 32, 32, Rt), new Tt(4, 4, 16, 16, Nt), new Tt(8, 16, 32, 32, Nt), new Tt(8, 16, 128, 128, Nt), new Tt(8, 32, 128, 256, Nt), new Tt(32, 128, 258, 1024, Nt), new Tt(32, 258, 258, 4096, Nt)]; + + function Lt() { + this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _t, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new Uint16Array(1146), this.dyn_dtree = new Uint16Array(122), this.bl_tree = new Uint16Array(78), mt(this.dyn_ltree), mt(this.dyn_dtree), mt(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new Uint16Array(16), this.heap = new Uint16Array(573), mt(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new Uint16Array(573), mt(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0; + } + + const Bt = t => { + if (!t || !t.state) return gt(t, et); + t.total_in = t.total_out = 0, t.data_type = dt; + const e = t.state; + return e.pending = 0, e.pending_out = 0, e.wrap < 0 && (e.wrap = -e.wrap), e.status = e.wrap ? 42 : wt, t.adler = 2 === e.wrap ? 0 : 1, e.last_flush = G, W(e), Q; + }, + Ct = t => { + const e = Bt(t); + var i; + return e === Q && ((i = t.state).window_size = 2 * i.w_size, mt(i.head), i.max_lazy_match = Ot[i.level].max_lazy, i.good_match = Ot[i.level].good_length, i.nice_match = Ot[i.level].nice_length, i.max_chain_length = Ot[i.level].max_chain, i.strstart = 0, i.block_start = 0, i.lookahead = 0, i.insert = 0, i.match_length = i.prev_length = 2, i.match_available = 0, i.ins_h = 0), e; + }, + Dt = (t, e, i, n, r, s) => { + if (!t) return et; + let a = 1; + if (e === rt && (e = 6), n < 0 ? (a = 0, n = -n) : n > 15 && (a = 2, n -= 16), r < 1 || r > 9 || i !== _t || n < 8 || n > 15 || e < 0 || e > 9 || s < 0 || s > ht) return gt(t, et); + 8 === n && (n = 9); + const o = new Lt(); + return t.state = o, o.strm = t, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = r + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + 3 - 1) / 3), o.window = new Uint8Array(2 * o.w_size), o.head = new Uint16Array(o.hash_size), o.prev = new Uint16Array(o.w_size), o.lit_bufsize = 1 << r + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new Uint8Array(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = e, o.strategy = s, o.method = i, Ct(t); + }; + + var It = Dt, + St = (t, e) => t && t.state ? 2 !== t.state.wrap ? et : (t.state.gzhead = e, Q) : et, + Zt = (t, e) => { + let i, n; + if (!t || !t.state || e > J || e < 0) return t ? gt(t, et) : et; + const r = t.state; + if (!t.output || !t.input && 0 !== t.avail_in || r.status === pt && e !== q) return gt(t, 0 === t.avail_out ? nt : et); + r.strm = t; + const s = r.last_flush; + if (r.last_flush = e, 42 === r.status) if (2 === r.wrap) t.adler = 0, Et(r, 31), Et(r, 139), Et(r, 8), r.gzhead ? (Et(r, (r.gzhead.text ? 1 : 0) + (r.gzhead.hcrc ? 2 : 0) + (r.gzhead.extra ? 4 : 0) + (r.gzhead.name ? 8 : 0) + (r.gzhead.comment ? 16 : 0)), Et(r, 255 & r.gzhead.time), Et(r, r.gzhead.time >> 8 & 255), Et(r, r.gzhead.time >> 16 & 255), Et(r, r.gzhead.time >> 24 & 255), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 255 & r.gzhead.os), r.gzhead.extra && r.gzhead.extra.length && (Et(r, 255 & r.gzhead.extra.length), Et(r, r.gzhead.extra.length >> 8 & 255)), r.gzhead.hcrc && (t.adler = M(t.adler, r.pending_buf, r.pending, 0)), r.gzindex = 0, r.status = 69) : (Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 0), Et(r, 9 === r.level ? 2 : r.strategy >= at || r.level < 2 ? 4 : 0), Et(r, 3), r.status = wt);else { + let e = _t + (r.w_bits - 8 << 4) << 8, + i = -1; + i = r.strategy >= at || r.level < 2 ? 0 : r.level < 6 ? 1 : 6 === r.level ? 2 : 3, e |= i << 6, 0 !== r.strstart && (e |= 32), e += 31 - e % 31, r.status = wt, At(r, e), 0 !== r.strstart && (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), t.adler = 1; + } + if (69 === r.status) if (r.gzhead.extra) { + for (i = r.pending; r.gzindex < (65535 & r.gzhead.extra.length) && (r.pending !== r.pending_buf_size || (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending !== r.pending_buf_size));) Et(r, 255 & r.gzhead.extra[r.gzindex]), r.gzindex++; + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), r.gzindex === r.gzhead.extra.length && (r.gzindex = 0, r.status = 73); + } else r.status = 73; + if (73 === r.status) if (r.gzhead.name) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.name.length ? 255 & r.gzhead.name.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.gzindex = 0, r.status = 91); + } else r.status = 91; + if (91 === r.status) if (r.gzhead.comment) { + i = r.pending; + + do { + if (r.pending === r.pending_buf_size && (r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), yt(t), i = r.pending, r.pending === r.pending_buf_size)) { + n = 1; + break; + } + + n = r.gzindex < r.gzhead.comment.length ? 255 & r.gzhead.comment.charCodeAt(r.gzindex++) : 0, Et(r, n); + } while (0 !== n); + + r.gzhead.hcrc && r.pending > i && (t.adler = M(t.adler, r.pending_buf, r.pending - i, i)), 0 === n && (r.status = ut); + } else r.status = ut; + + if (r.status === ut && (r.gzhead.hcrc ? (r.pending + 2 > r.pending_buf_size && yt(t), r.pending + 2 <= r.pending_buf_size && (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), t.adler = 0, r.status = wt)) : r.status = wt), 0 !== r.pending) { + if (yt(t), 0 === t.avail_out) return r.last_flush = -1, Q; + } else if (0 === t.avail_in && bt(e) <= bt(s) && e !== q) return gt(t, nt); + + if (r.status === pt && 0 !== t.avail_in) return gt(t, nt); + + if (0 !== t.avail_in || 0 !== r.lookahead || e !== G && r.status !== pt) { + let i = r.strategy === at ? ((t, e) => { + let i; + + for (;;) { + if (0 === t.lookahead && (zt(t), 0 === t.lookahead)) { + if (e === G) return 1; + break; + } + + if (t.match_length = 0, i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++, i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : r.strategy === ot ? ((t, e) => { + let i, n, r, s; + const a = t.window; + + for (;;) { + if (t.lookahead <= ft) { + if (zt(t), t.lookahead <= ft && e === G) return 1; + if (0 === t.lookahead) break; + } + + if (t.match_length = 0, t.lookahead >= 3 && t.strstart > 0 && (r = t.strstart - 1, n = a[r], n === a[++r] && n === a[++r] && n === a[++r])) { + s = t.strstart + ft; + + do {} while (n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && n === a[++r] && r < s); + + t.match_length = ft - (s - r), t.match_length > t.lookahead && (t.match_length = t.lookahead); + } + + if (t.match_length >= 3 ? (i = Y(t, 1, t.match_length - 3), t.lookahead -= t.match_length, t.strstart += t.match_length, t.match_length = 0) : (i = Y(t, 0, t.window[t.strstart]), t.lookahead--, t.strstart++), i && (vt(t, !1), 0 === t.strm.avail_out)) return 1; + } + + return t.insert = 0, e === q ? (vt(t, !0), 0 === t.strm.avail_out ? 3 : 4) : t.last_lit && (vt(t, !1), 0 === t.strm.avail_out) ? 1 : 2; + })(r, e) : Ot[r.level].func(r, e); + if (3 !== i && 4 !== i || (r.status = pt), 1 === i || 3 === i) return 0 === t.avail_out && (r.last_flush = -1), Q; + if (2 === i && (e === X ? j(r) : e !== J && (K(r, 0, 0, !1), e === V && (mt(r.head), 0 === r.lookahead && (r.strstart = 0, r.block_start = 0, r.insert = 0))), yt(t), 0 === t.avail_out)) return r.last_flush = -1, Q; + } + + return e !== q ? Q : r.wrap <= 0 ? tt : (2 === r.wrap ? (Et(r, 255 & t.adler), Et(r, t.adler >> 8 & 255), Et(r, t.adler >> 16 & 255), Et(r, t.adler >> 24 & 255), Et(r, 255 & t.total_in), Et(r, t.total_in >> 8 & 255), Et(r, t.total_in >> 16 & 255), Et(r, t.total_in >> 24 & 255)) : (At(r, t.adler >>> 16), At(r, 65535 & t.adler)), yt(t), r.wrap > 0 && (r.wrap = -r.wrap), 0 !== r.pending ? Q : tt); + }, + Ft = t => { + if (!t || !t.state) return et; + const e = t.state.status; + return 42 !== e && 69 !== e && 73 !== e && 91 !== e && e !== ut && e !== wt && e !== pt ? gt(t, et) : (t.state = null, e === wt ? gt(t, it) : Q); + }, + Mt = (t, e) => { + let i = e.length; + if (!t || !t.state) return et; + const n = t.state, + r = n.wrap; + if (2 === r || 1 === r && 42 !== n.status || n.lookahead) return et; + + if (1 === r && (t.adler = Z(t.adler, e, i, 0)), n.wrap = 0, i >= n.w_size) { + 0 === r && (mt(n.head), n.strstart = 0, n.block_start = 0, n.insert = 0); + let t = new Uint8Array(n.w_size); + t.set(e.subarray(i - n.w_size, i), 0), e = t, i = n.w_size; + } + + const s = t.avail_in, + a = t.next_in, + o = t.input; + + for (t.avail_in = i, t.next_in = 0, t.input = e, zt(n); n.lookahead >= 3;) { + let t = n.strstart, + e = n.lookahead - 2; + + do { + n.ins_h = kt(n, n.ins_h, n.window[t + 3 - 1]), n.prev[t & n.w_mask] = n.head[n.ins_h], n.head[n.ins_h] = t, t++; + } while (--e); + + n.strstart = t, n.lookahead = 2, zt(n); + } + + return n.strstart += n.lookahead, n.block_start = n.strstart, n.insert = n.lookahead, n.lookahead = 0, n.match_length = n.prev_length = 2, n.match_available = 0, t.next_in = a, t.input = o, t.avail_in = s, n.wrap = r, Q; + }; + + const Pt = (t, e) => Object.prototype.hasOwnProperty.call(t, e); + + var Ht = function Ht(t) { + const e = Array.prototype.slice.call(arguments, 1); + + for (; e.length;) { + const i = e.shift(); + + if (i) { + if ("object" != typeof i) throw new TypeError(i + "must be non-object"); + + for (const e in i) Pt(i, e) && (t[e] = i[e]); + } + } + + return t; + }, + Wt = t => { + let e = 0; + + for (let i = 0, n = t.length; i < n; i++) e += t[i].length; + + const i = new Uint8Array(e); + + for (let e = 0, n = 0, r = t.length; e < r; e++) { + let r = t[e]; + i.set(r, n), n += r.length; + } + + return i; + }; + + let Kt = !0; + + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (t) { + Kt = !1; + } + + const $t = new Uint8Array(256); + + for (let t = 0; t < 256; t++) $t[t] = t >= 252 ? 6 : t >= 248 ? 5 : t >= 240 ? 4 : t >= 224 ? 3 : t >= 192 ? 2 : 1; + + $t[254] = $t[254] = 1; + + var Yt = t => { + if ("function" == typeof TextEncoder && TextEncoder.prototype.encode) return new TextEncoder().encode(t); + let e, + i, + n, + r, + s, + a = t.length, + o = 0; + + for (r = 0; r < a; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), o += i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4; + + for (e = new Uint8Array(o), s = 0, r = 0; s < o; r++) i = t.charCodeAt(r), 55296 == (64512 & i) && r + 1 < a && (n = t.charCodeAt(r + 1), 56320 == (64512 & n) && (i = 65536 + (i - 55296 << 10) + (n - 56320), r++)), i < 128 ? e[s++] = i : i < 2048 ? (e[s++] = 192 | i >>> 6, e[s++] = 128 | 63 & i) : i < 65536 ? (e[s++] = 224 | i >>> 12, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i) : (e[s++] = 240 | i >>> 18, e[s++] = 128 | i >>> 12 & 63, e[s++] = 128 | i >>> 6 & 63, e[s++] = 128 | 63 & i); + + return e; + }, + jt = (t, e) => { + const i = e || t.length; + if ("function" == typeof TextDecoder && TextDecoder.prototype.decode) return new TextDecoder().decode(t.subarray(0, e)); + let n, r; + const s = new Array(2 * i); + + for (r = 0, n = 0; n < i;) { + let e = t[n++]; + + if (e < 128) { + s[r++] = e; + continue; + } + + let a = $t[e]; + if (a > 4) s[r++] = 65533, n += a - 1;else { + for (e &= 2 === a ? 31 : 3 === a ? 15 : 7; a > 1 && n < i;) e = e << 6 | 63 & t[n++], a--; + + a > 1 ? s[r++] = 65533 : e < 65536 ? s[r++] = e : (e -= 65536, s[r++] = 55296 | e >> 10 & 1023, s[r++] = 56320 | 1023 & e); + } + } + + return ((t, e) => { + if (e < 65534 && t.subarray && Kt) return String.fromCharCode.apply(null, t.length === e ? t : t.subarray(0, e)); + let i = ""; + + for (let n = 0; n < e; n++) i += String.fromCharCode(t[n]); + + return i; + })(s, r); + }, + Gt = (t, e) => { + (e = e || t.length) > t.length && (e = t.length); + let i = e - 1; + + for (; i >= 0 && 128 == (192 & t[i]);) i--; + + return i < 0 || 0 === i ? e : i + $t[t[i]] > e ? i : e; + }, + Xt = function Xt() { + this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0; + }; + + const Vt = Object.prototype.toString, + { + Z_NO_FLUSH: qt, + Z_SYNC_FLUSH: Jt, + Z_FULL_FLUSH: Qt, + Z_FINISH: te, + Z_OK: ee, + Z_STREAM_END: ie, + Z_DEFAULT_COMPRESSION: ne, + Z_DEFAULT_STRATEGY: re, + Z_DEFLATED: se + } = H; + + function ae(t) { + this.options = Ht({ + level: ne, + method: se, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: re + }, t || {}); + let e = this.options; + e.raw && e.windowBits > 0 ? e.windowBits = -e.windowBits : e.gzip && e.windowBits > 0 && e.windowBits < 16 && (e.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = It(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy); + if (i !== ee) throw new Error(P[i]); + + if (e.header && St(this.strm, e.header), e.dictionary) { + let t; + if (t = "string" == typeof e.dictionary ? Yt(e.dictionary) : "[object ArrayBuffer]" === Vt.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary, i = Mt(this.strm, t), i !== ee) throw new Error(P[i]); + this._dict_set = !0; + } + } + + function oe(t, e) { + const i = new ae(e); + if (i.push(t, !0), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ae.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize; + let r, s; + if (this.ended) return !1; + + for (s = e === ~~e ? e : !0 === e ? te : qt, "string" == typeof t ? i.input = Yt(t) : "[object ArrayBuffer]" === Vt.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) if (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), (s === Jt || s === Qt) && i.avail_out <= 6) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else { + if (r = Zt(i, s), r === ie) return i.next_out > 0 && this.onData(i.output.subarray(0, i.next_out)), r = Ft(this.strm), this.onEnd(r), this.ended = !0, r === ee; + + if (0 !== i.avail_out) { + if (s > 0 && i.next_out > 0) this.onData(i.output.subarray(0, i.next_out)), i.avail_out = 0;else if (0 === i.avail_in) break; + } else this.onData(i.output); + } + + return !0; + }, ae.prototype.onData = function (t) { + this.chunks.push(t); + }, ae.prototype.onEnd = function (t) { + t === ee && (this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + + var he = { + Deflate: ae, + deflate: oe, + deflateRaw: function deflateRaw(t, e) { + return (e = e || {}).raw = !0, oe(t, e); + }, + gzip: function gzip(t, e) { + return (e = e || {}).gzip = !0, oe(t, e); + }, + constants: H + }, + le = function le(t, e) { + let i, n, r, s, a, o, h, l, d, _, f, c, u, w, p, g, b, m, k, y, v, E, A, x; + + const U = t.state; + i = t.next_in, A = t.input, n = i + (t.avail_in - 5), r = t.next_out, x = t.output, s = r - (e - t.avail_out), a = r + (t.avail_out - 257), o = U.dmax, h = U.wsize, l = U.whave, d = U.wnext, _ = U.window, f = U.hold, c = U.bits, u = U.lencode, w = U.distcode, p = (1 << U.lenbits) - 1, g = (1 << U.distbits) - 1; + + t: do { + c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = u[f & p]; + + e: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, 0 === m) x[r++] = 65535 & b;else { + if (!(16 & m)) { + if (0 == (64 & m)) { + b = u[(65535 & b) + (f & (1 << m) - 1)]; + continue e; + } + + if (32 & m) { + U.mode = 12; + break t; + } + + t.msg = "invalid literal/length code", U.mode = 30; + break t; + } + + k = 65535 & b, m &= 15, m && (c < m && (f += A[i++] << c, c += 8), k += f & (1 << m) - 1, f >>>= m, c -= m), c < 15 && (f += A[i++] << c, c += 8, f += A[i++] << c, c += 8), b = w[f & g]; + + i: for (;;) { + if (m = b >>> 24, f >>>= m, c -= m, m = b >>> 16 & 255, !(16 & m)) { + if (0 == (64 & m)) { + b = w[(65535 & b) + (f & (1 << m) - 1)]; + continue i; + } + + t.msg = "invalid distance code", U.mode = 30; + break t; + } + + if (y = 65535 & b, m &= 15, c < m && (f += A[i++] << c, c += 8, c < m && (f += A[i++] << c, c += 8)), y += f & (1 << m) - 1, y > o) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (f >>>= m, c -= m, m = r - s, y > m) { + if (m = y - m, m > l && U.sane) { + t.msg = "invalid distance too far back", U.mode = 30; + break t; + } + + if (v = 0, E = _, 0 === d) { + if (v += h - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } else if (d < m) { + if (v += h + d - m, m -= d, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + if (v = 0, d < k) { + m = d, k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + } + } else if (v += d - m, m < k) { + k -= m; + + do { + x[r++] = _[v++]; + } while (--m); + + v = r - y, E = x; + } + + for (; k > 2;) x[r++] = E[v++], x[r++] = E[v++], x[r++] = E[v++], k -= 3; + + k && (x[r++] = E[v++], k > 1 && (x[r++] = E[v++])); + } else { + v = r - y; + + do { + x[r++] = x[v++], x[r++] = x[v++], x[r++] = x[v++], k -= 3; + } while (k > 2); + + k && (x[r++] = x[v++], k > 1 && (x[r++] = x[v++])); + } + + break; + } + } + break; + } + } while (i < n && r < a); + + k = c >> 3, i -= k, c -= k << 3, f &= (1 << c) - 1, t.next_in = i, t.next_out = r, t.avail_in = i < n ? n - i + 5 : 5 - (i - n), t.avail_out = r < a ? a - r + 257 : 257 - (r - a), U.hold = f, U.bits = c; + }; + + const de = new Uint16Array([3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]), + _e = new Uint8Array([16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]), + fe = new Uint16Array([1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]), + ce = new Uint8Array([16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]); + + var ue = (t, e, i, n, r, s, a, o) => { + const h = o.bits; + + let l, + d, + _, + f, + c, + u, + w = 0, + p = 0, + g = 0, + b = 0, + m = 0, + k = 0, + y = 0, + v = 0, + E = 0, + A = 0, + x = null, + U = 0; + + const z = new Uint16Array(16), + R = new Uint16Array(16); + let N, + T, + O, + L = null, + B = 0; + + for (w = 0; w <= 15; w++) z[w] = 0; + + for (p = 0; p < n; p++) z[e[i + p]]++; + + for (m = h, b = 15; b >= 1 && 0 === z[b]; b--); + + if (m > b && (m = b), 0 === b) return r[s++] = 20971520, r[s++] = 20971520, o.bits = 1, 0; + + for (g = 1; g < b && 0 === z[g]; g++); + + for (m < g && (m = g), v = 1, w = 1; w <= 15; w++) if (v <<= 1, v -= z[w], v < 0) return -1; + + if (v > 0 && (0 === t || 1 !== b)) return -1; + + for (R[1] = 0, w = 1; w < 15; w++) R[w + 1] = R[w] + z[w]; + + for (p = 0; p < n; p++) 0 !== e[i + p] && (a[R[e[i + p]]++] = p); + + if (0 === t ? (x = L = a, u = 19) : 1 === t ? (x = de, U -= 257, L = _e, B -= 257, u = 256) : (x = fe, L = ce, u = -1), A = 0, p = 0, w = g, c = s, k = m, y = 0, _ = -1, E = 1 << m, f = E - 1, 1 === t && E > 852 || 2 === t && E > 592) return 1; + + for (;;) { + N = w - y, a[p] < u ? (T = 0, O = a[p]) : a[p] > u ? (T = L[B + a[p]], O = x[U + a[p]]) : (T = 96, O = 0), l = 1 << w - y, d = 1 << k, g = d; + + do { + d -= l, r[c + (A >> y) + d] = N << 24 | T << 16 | O | 0; + } while (0 !== d); + + for (l = 1 << w - 1; A & l;) l >>= 1; + + if (0 !== l ? (A &= l - 1, A += l) : A = 0, p++, 0 == --z[w]) { + if (w === b) break; + w = e[i + a[p]]; + } + + if (w > m && (A & f) !== _) { + for (0 === y && (y = m), c += g, k = w - y, v = 1 << k; k + y < b && (v -= z[k + y], !(v <= 0));) k++, v <<= 1; + + if (E += 1 << k, 1 === t && E > 852 || 2 === t && E > 592) return 1; + _ = A & f, r[_] = m << 24 | k << 16 | c - s | 0; + } + } + + return 0 !== A && (r[c + A] = w - y << 24 | 64 << 16 | 0), o.bits = m, 0; + }; + + const { + Z_FINISH: we, + Z_BLOCK: pe, + Z_TREES: ge, + Z_OK: be, + Z_STREAM_END: me, + Z_NEED_DICT: ke, + Z_STREAM_ERROR: ye, + Z_DATA_ERROR: ve, + Z_MEM_ERROR: Ee, + Z_BUF_ERROR: Ae, + Z_DEFLATED: xe + } = H, + Ue = 12, + ze = 30, + Re = t => (t >>> 24 & 255) + (t >>> 8 & 65280) + ((65280 & t) << 8) + ((255 & t) << 24); + + function Ne() { + this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new Uint16Array(320), this.work = new Uint16Array(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0; + } + + const Te = t => { + if (!t || !t.state) return ye; + const e = t.state; + return t.total_in = t.total_out = e.total = 0, t.msg = "", e.wrap && (t.adler = 1 & e.wrap), e.mode = 1, e.last = 0, e.havedict = 0, e.dmax = 32768, e.head = null, e.hold = 0, e.bits = 0, e.lencode = e.lendyn = new Int32Array(852), e.distcode = e.distdyn = new Int32Array(592), e.sane = 1, e.back = -1, be; + }, + Oe = t => { + if (!t || !t.state) return ye; + const e = t.state; + return e.wsize = 0, e.whave = 0, e.wnext = 0, Te(t); + }, + Le = (t, e) => { + let i; + if (!t || !t.state) return ye; + const n = t.state; + return e < 0 ? (i = 0, e = -e) : (i = 1 + (e >> 4), e < 48 && (e &= 15)), e && (e < 8 || e > 15) ? ye : (null !== n.window && n.wbits !== e && (n.window = null), n.wrap = i, n.wbits = e, Oe(t)); + }, + Be = (t, e) => { + if (!t) return ye; + const i = new Ne(); + t.state = i, i.window = null; + const n = Le(t, e); + return n !== be && (t.state = null), n; + }; + + let Ce, + De, + Ie = !0; + + const Se = t => { + if (Ie) { + Ce = new Int32Array(512), De = new Int32Array(32); + let e = 0; + + for (; e < 144;) t.lens[e++] = 8; + + for (; e < 256;) t.lens[e++] = 9; + + for (; e < 280;) t.lens[e++] = 7; + + for (; e < 288;) t.lens[e++] = 8; + + for (ue(1, t.lens, 0, 288, Ce, 0, t.work, { + bits: 9 + }), e = 0; e < 32;) t.lens[e++] = 5; + + ue(2, t.lens, 0, 32, De, 0, t.work, { + bits: 5 + }), Ie = !1; + } + + t.lencode = Ce, t.lenbits = 9, t.distcode = De, t.distbits = 5; + }, + Ze = (t, e, i, n) => { + let r; + const s = t.state; + return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new Uint8Array(s.wsize)), n >= s.wsize ? (s.window.set(e.subarray(i - s.wsize, i), 0), s.wnext = 0, s.whave = s.wsize) : (r = s.wsize - s.wnext, r > n && (r = n), s.window.set(e.subarray(i - n, i - n + r), s.wnext), (n -= r) ? (s.window.set(e.subarray(i - n, i), 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += r, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += r))), 0; + }; + + var Fe = Oe, + Me = Be, + Pe = (t, e) => { + let i, + n, + r, + s, + a, + o, + h, + l, + d, + _, + f, + c, + u, + w, + p, + g, + b, + m, + k, + y, + v, + E, + A = 0; + + const x = new Uint8Array(4); + let U, z; + const R = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + if (!t || !t.state || !t.output || !t.input && 0 !== t.avail_in) return ye; + i = t.state, i.mode === Ue && (i.mode = 13), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, _ = o, f = h, E = be; + + t: for (;;) switch (i.mode) { + case 1: + if (0 === i.wrap) { + i.mode = 13; + break; + } + + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (2 & i.wrap && 35615 === l) { + i.check = 0, x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0), l = 0, d = 0, i.mode = 2; + break; + } + + if (i.flags = 0, i.head && (i.head.done = !1), !(1 & i.wrap) || (((255 & l) << 8) + (l >> 8)) % 31) { + t.msg = "incorrect header check", i.mode = ze; + break; + } + + if ((15 & l) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (l >>>= 4, d -= 4, v = 8 + (15 & l), 0 === i.wbits) i.wbits = v;else if (v > i.wbits) { + t.msg = "invalid window size", i.mode = ze; + break; + } + i.dmax = 1 << i.wbits, t.adler = i.check = 1, i.mode = 512 & l ? 10 : Ue, l = 0, d = 0; + break; + + case 2: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.flags = l, (255 & i.flags) !== xe) { + t.msg = "unknown compression method", i.mode = ze; + break; + } + + if (57344 & i.flags) { + t.msg = "unknown header flags set", i.mode = ze; + break; + } + + i.head && (i.head.text = l >> 8 & 1), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 3; + + case 3: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.time = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, x[2] = l >>> 16 & 255, x[3] = l >>> 24 & 255, i.check = M(i.check, x, 4, 0)), l = 0, d = 0, i.mode = 4; + + case 4: + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.head && (i.head.xflags = 255 & l, i.head.os = l >> 8), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0, i.mode = 5; + + case 5: + if (1024 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length = l, i.head && (i.head.extra_len = l), 512 & i.flags && (x[0] = 255 & l, x[1] = l >>> 8 & 255, i.check = M(i.check, x, 2, 0)), l = 0, d = 0; + } else i.head && (i.head.extra = null); + + i.mode = 6; + + case 6: + if (1024 & i.flags && (c = i.length, c > o && (c = o), c && (i.head && (v = i.head.extra_len - i.length, i.head.extra || (i.head.extra = new Uint8Array(i.head.extra_len)), i.head.extra.set(n.subarray(s, s + c), v)), 512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, i.length -= c), i.length)) break t; + i.length = 0, i.mode = 7; + + case 7: + if (2048 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.name += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.name = null); + + i.length = 0, i.mode = 8; + + case 8: + if (4096 & i.flags) { + if (0 === o) break t; + c = 0; + + do { + v = n[s + c++], i.head && v && i.length < 65536 && (i.head.comment += String.fromCharCode(v)); + } while (v && c < o); + + if (512 & i.flags && (i.check = M(i.check, n, c, s)), o -= c, s += c, v) break t; + } else i.head && (i.head.comment = null); + + i.mode = 9; + + case 9: + if (512 & i.flags) { + for (; d < 16;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (65535 & i.check)) { + t.msg = "header crc mismatch", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.head && (i.head.hcrc = i.flags >> 9 & 1, i.head.done = !0), t.adler = i.check = 0, i.mode = Ue; + break; + + case 10: + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + t.adler = i.check = Re(l), l = 0, d = 0, i.mode = 11; + + case 11: + if (0 === i.havedict) return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, ke; + t.adler = i.check = 1, i.mode = Ue; + + case Ue: + if (e === pe || e === ge) break t; + + case 13: + if (i.last) { + l >>>= 7 & d, d -= 7 & d, i.mode = 27; + break; + } + + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + switch (i.last = 1 & l, l >>>= 1, d -= 1, 3 & l) { + case 0: + i.mode = 14; + break; + + case 1: + if (Se(i), i.mode = 20, e === ge) { + l >>>= 2, d -= 2; + break t; + } + + break; + + case 2: + i.mode = 17; + break; + + case 3: + t.msg = "invalid block type", i.mode = ze; + } + + l >>>= 2, d -= 2; + break; + + case 14: + for (l >>>= 7 & d, d -= 7 & d; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if ((65535 & l) != (l >>> 16 ^ 65535)) { + t.msg = "invalid stored block lengths", i.mode = ze; + break; + } + + if (i.length = 65535 & l, l = 0, d = 0, i.mode = 15, e === ge) break t; + + case 15: + i.mode = 16; + + case 16: + if (c = i.length, c) { + if (c > o && (c = o), c > h && (c = h), 0 === c) break t; + r.set(n.subarray(s, s + c), a), o -= c, s += c, h -= c, a += c, i.length -= c; + break; + } + + i.mode = Ue; + break; + + case 17: + for (; d < 14;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (i.nlen = 257 + (31 & l), l >>>= 5, d -= 5, i.ndist = 1 + (31 & l), l >>>= 5, d -= 5, i.ncode = 4 + (15 & l), l >>>= 4, d -= 4, i.nlen > 286 || i.ndist > 30) { + t.msg = "too many length or distance symbols", i.mode = ze; + break; + } + + i.have = 0, i.mode = 18; + + case 18: + for (; i.have < i.ncode;) { + for (; d < 3;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.lens[R[i.have++]] = 7 & l, l >>>= 3, d -= 3; + } + + for (; i.have < 19;) i.lens[R[i.have++]] = 0; + + if (i.lencode = i.lendyn, i.lenbits = 7, U = { + bits: i.lenbits + }, E = ue(0, i.lens, 0, 19, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid code lengths set", i.mode = ze; + break; + } + + i.have = 0, i.mode = 19; + + case 19: + for (; i.have < i.nlen + i.ndist;) { + for (; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (b < 16) l >>>= p, d -= p, i.lens[i.have++] = b;else { + if (16 === b) { + for (z = p + 2; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l >>>= p, d -= p, 0 === i.have) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + v = i.lens[i.have - 1], c = 3 + (3 & l), l >>>= 2, d -= 2; + } else if (17 === b) { + for (z = p + 3; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 3 + (7 & l), l >>>= 3, d -= 3; + } else { + for (z = p + 7; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= p, d -= p, v = 0, c = 11 + (127 & l), l >>>= 7, d -= 7; + } + + if (i.have + c > i.nlen + i.ndist) { + t.msg = "invalid bit length repeat", i.mode = ze; + break; + } + + for (; c--;) i.lens[i.have++] = v; + } + } + + if (i.mode === ze) break; + + if (0 === i.lens[256]) { + t.msg = "invalid code -- missing end-of-block", i.mode = ze; + break; + } + + if (i.lenbits = 9, U = { + bits: i.lenbits + }, E = ue(1, i.lens, 0, i.nlen, i.lencode, 0, i.work, U), i.lenbits = U.bits, E) { + t.msg = "invalid literal/lengths set", i.mode = ze; + break; + } + + if (i.distbits = 6, i.distcode = i.distdyn, U = { + bits: i.distbits + }, E = ue(2, i.lens, i.nlen, i.ndist, i.distcode, 0, i.work, U), i.distbits = U.bits, E) { + t.msg = "invalid distances set", i.mode = ze; + break; + } + + if (i.mode = 20, e === ge) break t; + + case 20: + i.mode = 21; + + case 21: + if (o >= 6 && h >= 258) { + t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, le(t, f), a = t.next_out, r = t.output, h = t.avail_out, s = t.next_in, n = t.input, o = t.avail_in, l = i.hold, d = i.bits, i.mode === Ue && (i.back = -1); + break; + } + + for (i.back = 0; A = i.lencode[l & (1 << i.lenbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (g && 0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.lencode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, i.length = b, 0 === g) { + i.mode = 26; + break; + } + + if (32 & g) { + i.back = -1, i.mode = Ue; + break; + } + + if (64 & g) { + t.msg = "invalid literal/length code", i.mode = ze; + break; + } + + i.extra = 15 & g, i.mode = 22; + + case 22: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.length += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + i.was = i.length, i.mode = 23; + + case 23: + for (; A = i.distcode[l & (1 << i.distbits) - 1], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (0 == (240 & g)) { + for (m = p, k = g, y = b; A = i.distcode[y + ((l & (1 << m + k) - 1) >> m)], p = A >>> 24, g = A >>> 16 & 255, b = 65535 & A, !(m + p <= d);) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + l >>>= m, d -= m, i.back += m; + } + + if (l >>>= p, d -= p, i.back += p, 64 & g) { + t.msg = "invalid distance code", i.mode = ze; + break; + } + + i.offset = b, i.extra = 15 & g, i.mode = 24; + + case 24: + if (i.extra) { + for (z = i.extra; d < z;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + i.offset += l & (1 << i.extra) - 1, l >>>= i.extra, d -= i.extra, i.back += i.extra; + } + + if (i.offset > i.dmax) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + i.mode = 25; + + case 25: + if (0 === h) break t; + + if (c = f - h, i.offset > c) { + if (c = i.offset - c, c > i.whave && i.sane) { + t.msg = "invalid distance too far back", i.mode = ze; + break; + } + + c > i.wnext ? (c -= i.wnext, u = i.wsize - c) : u = i.wnext - c, c > i.length && (c = i.length), w = i.window; + } else w = r, u = a - i.offset, c = i.length; + + c > h && (c = h), h -= c, i.length -= c; + + do { + r[a++] = w[u++]; + } while (--c); + + 0 === i.length && (i.mode = 21); + break; + + case 26: + if (0 === h) break t; + r[a++] = i.length, h--, i.mode = 21; + break; + + case 27: + if (i.wrap) { + for (; d < 32;) { + if (0 === o) break t; + o--, l |= n[s++] << d, d += 8; + } + + if (f -= h, t.total_out += f, i.total += f, f && (t.adler = i.check = i.flags ? M(i.check, r, f, a - f) : Z(i.check, r, f, a - f)), f = h, (i.flags ? l : Re(l)) !== i.check) { + t.msg = "incorrect data check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 28; + + case 28: + if (i.wrap && i.flags) { + for (; d < 32;) { + if (0 === o) break t; + o--, l += n[s++] << d, d += 8; + } + + if (l !== (4294967295 & i.total)) { + t.msg = "incorrect length check", i.mode = ze; + break; + } + + l = 0, d = 0; + } + + i.mode = 29; + + case 29: + E = me; + break t; + + case ze: + E = ve; + break t; + + case 31: + return Ee; + + default: + return ye; + } + + return t.next_out = a, t.avail_out = h, t.next_in = s, t.avail_in = o, i.hold = l, i.bits = d, (i.wsize || f !== t.avail_out && i.mode < ze && (i.mode < 27 || e !== we)) && Ze(t, t.output, t.next_out, f - t.avail_out), _ -= t.avail_in, f -= t.avail_out, t.total_in += _, t.total_out += f, i.total += f, i.wrap && f && (t.adler = i.check = i.flags ? M(i.check, r, f, t.next_out - f) : Z(i.check, r, f, t.next_out - f)), t.data_type = i.bits + (i.last ? 64 : 0) + (i.mode === Ue ? 128 : 0) + (20 === i.mode || 15 === i.mode ? 256 : 0), (0 === _ && 0 === f || e === we) && E === be && (E = Ae), E; + }, + He = t => { + if (!t || !t.state) return ye; + let e = t.state; + return e.window && (e.window = null), t.state = null, be; + }, + We = (t, e) => { + if (!t || !t.state) return ye; + const i = t.state; + return 0 == (2 & i.wrap) ? ye : (i.head = e, e.done = !1, be); + }, + Ke = (t, e) => { + const i = e.length; + let n, r, s; + return t && t.state ? (n = t.state, 0 !== n.wrap && 11 !== n.mode ? ye : 11 === n.mode && (r = 1, r = Z(r, e, i, 0), r !== n.check) ? ve : (s = Ze(t, e, i, i), s ? (n.mode = 31, Ee) : (n.havedict = 1, be))) : ye; + }, + $e = function $e() { + this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1; + }; + + const Ye = Object.prototype.toString, + { + Z_NO_FLUSH: je, + Z_FINISH: Ge, + Z_OK: Xe, + Z_STREAM_END: Ve, + Z_NEED_DICT: qe, + Z_STREAM_ERROR: Je, + Z_DATA_ERROR: Qe, + Z_MEM_ERROR: ti + } = H; + + function ei(t) { + this.options = Ht({ + chunkSize: 65536, + windowBits: 15, + to: "" + }, t || {}); + const e = this.options; + e.raw && e.windowBits >= 0 && e.windowBits < 16 && (e.windowBits = -e.windowBits, 0 === e.windowBits && (e.windowBits = -15)), !(e.windowBits >= 0 && e.windowBits < 16) || t && t.windowBits || (e.windowBits += 32), e.windowBits > 15 && e.windowBits < 48 && 0 == (15 & e.windowBits) && (e.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new Xt(), this.strm.avail_out = 0; + let i = Me(this.strm, e.windowBits); + if (i !== Xe) throw new Error(P[i]); + if (this.header = new $e(), We(this.strm, this.header), e.dictionary && ("string" == typeof e.dictionary ? e.dictionary = Yt(e.dictionary) : "[object ArrayBuffer]" === Ye.call(e.dictionary) && (e.dictionary = new Uint8Array(e.dictionary)), e.raw && (i = Ke(this.strm, e.dictionary), i !== Xe))) throw new Error(P[i]); + } + + function ii(t, e) { + const i = new ei(e); + if (i.push(t), i.err) throw i.msg || P[i.err]; + return i.result; + } + + ei.prototype.push = function (t, e) { + const i = this.strm, + n = this.options.chunkSize, + r = this.options.dictionary; + let s, a, o; + if (this.ended) return !1; + + for (a = e === ~~e ? e : !0 === e ? Ge : je, "[object ArrayBuffer]" === Ye.call(t) ? i.input = new Uint8Array(t) : i.input = t, i.next_in = 0, i.avail_in = i.input.length;;) { + for (0 === i.avail_out && (i.output = new Uint8Array(n), i.next_out = 0, i.avail_out = n), s = Pe(i, a), s === qe && r && (s = Ke(i, r), s === Xe ? s = Pe(i, a) : s === Qe && (s = qe)); i.avail_in > 0 && s === Ve && i.state.wrap > 0 && 0 !== t[i.next_in];) Fe(i), s = Pe(i, a); + + switch (s) { + case Je: + case Qe: + case qe: + case ti: + return this.onEnd(s), this.ended = !0, !1; + } + + if (o = i.avail_out, i.next_out && (0 === i.avail_out || s === Ve)) if ("string" === this.options.to) { + let t = Gt(i.output, i.next_out), + e = i.next_out - t, + r = jt(i.output, t); + i.next_out = e, i.avail_out = n - e, e && i.output.set(i.output.subarray(t, t + e), 0), this.onData(r); + } else this.onData(i.output.length === i.next_out ? i.output : i.output.subarray(0, i.next_out)); + + if (s !== Xe || 0 !== o) { + if (s === Ve) return s = He(this.strm), this.onEnd(s), this.ended = !0, !0; + if (0 === i.avail_in) break; + } + } + + return !0; + }, ei.prototype.onData = function (t) { + this.chunks.push(t); + }, ei.prototype.onEnd = function (t) { + t === Xe && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = Wt(this.chunks)), this.chunks = [], this.err = t, this.msg = this.strm.msg; + }; + var ni = { + Inflate: ei, + inflate: ii, + inflateRaw: function inflateRaw(t, e) { + return (e = e || {}).raw = !0, ii(t, e); + }, + ungzip: ii, + constants: H + }; + const { + Deflate: ri, + deflate: si, + deflateRaw: ai, + gzip: oi + } = he, + { + Inflate: hi, + inflate: li, + inflateRaw: di, + ungzip: _i + } = ni; + var fi = si, + ci = hi, + ui = li; + const wi = [137, 80, 78, 71, 13, 10, 26, 10], + pi = []; + + for (let t = 0; t < 256; t++) { + let e = t; + + for (let t = 0; t < 8; t++) 1 & e ? e = 3988292384 ^ e >>> 1 : e >>>= 1; + + pi[t] = e; + } + + const gi = 4294967295; + + function bi(t, e) { + return (function (t, e, i) { + let n = 4294967295; + + for (let t = 0; t < i; t++) n = pi[255 & (n ^ e[t])] ^ n >>> 8; + + return n; + }(0, t, e) ^ gi) >>> 0; + } + + var mi, ki, yi, vi; + !function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.GREYSCALE = 0] = "GREYSCALE", t[t.TRUECOLOUR = 2] = "TRUECOLOUR", t[t.INDEXED_COLOUR = 3] = "INDEXED_COLOUR", t[t.GREYSCALE_ALPHA = 4] = "GREYSCALE_ALPHA", t[t.TRUECOLOUR_ALPHA = 6] = "TRUECOLOUR_ALPHA"; + }(mi || (mi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.DEFLATE = 0] = "DEFLATE"; + }(ki || (ki = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.ADAPTIVE = 0] = "ADAPTIVE"; + }(yi || (yi = {})), function (t) { + t[t.UNKNOWN = -1] = "UNKNOWN", t[t.NO_INTERLACE = 0] = "NO_INTERLACE", t[t.ADAM7 = 1] = "ADAM7"; + }(vi || (vi = {})); + const Ei = new Uint8Array(0), + Ai = new Uint16Array([255]), + xi = 255 === new Uint8Array(Ai.buffer)[0]; + + class Ui extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(t); + const { + checkCrc: i = !1 + } = e; + this._checkCrc = i, this._inflator = new ci(), this._png = { + width: -1, + height: -1, + channels: -1, + data: new Uint8Array(0), + depth: 1, + text: {} + }, this._end = !1, this._hasPalette = !1, this._palette = [], this._compressionMethod = ki.UNKNOWN, this._filterMethod = yi.UNKNOWN, this._interlaceMethod = vi.UNKNOWN, this._colorType = -1, this.setBigEndian(); + } + + decode() { + for (this.decodeSignature(); !this._end;) this.decodeChunk(); + + return this.decodeImage(), this._png; + } + + decodeSignature() { + for (let t = 0; t < wi.length; t++) if (this.readUint8() !== wi[t]) throw new Error("wrong PNG signature. Byte at ".concat(t, " should be ").concat(wi[t], ".")); + } + + decodeChunk() { + const t = this.readUint32(), + e = this.readChars(4), + i = this.offset; + + switch (e) { + case "IHDR": + this.decodeIHDR(); + break; + + case "PLTE": + this.decodePLTE(t); + break; + + case "IDAT": + this.decodeIDAT(t); + break; + + case "IEND": + this._end = !0; + break; + + case "tRNS": + this.decodetRNS(t); + break; + + case "iCCP": + this.decodeiCCP(t); + break; + + case "tEXt": + this.decodetEXt(t); + break; + + case "pHYs": + this.decodepHYs(); + break; + + default: + this.skip(t); + } + + if (this.offset - i !== t) throw new Error("Length mismatch while decoding chunk ".concat(e)); + + if (this._checkCrc) { + const i = this.readUint32(), + n = t + 4, + r = bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - n - 4, n), n); + if (r !== i) throw new Error("CRC mismatch for chunk ".concat(e, ". Expected ").concat(i, ", found ").concat(r)); + } else this.skip(4); + } + + decodeIHDR() { + const t = this._png; + t.width = this.readUint32(), t.height = this.readUint32(), t.depth = function (t) { + if (1 !== t && 2 !== t && 4 !== t && 8 !== t && 16 !== t) throw new Error("invalid bit depth: ".concat(t)); + return t; + }(this.readUint8()); + const e = this.readUint8(); + let i; + + switch (this._colorType = e, e) { + case mi.GREYSCALE: + i = 1; + break; + + case mi.TRUECOLOUR: + i = 3; + break; + + case mi.INDEXED_COLOUR: + i = 1; + break; + + case mi.GREYSCALE_ALPHA: + i = 2; + break; + + case mi.TRUECOLOUR_ALPHA: + i = 4; + break; + + default: + throw new Error("Unknown color type: ".concat(e)); + } + + if (this._png.channels = i, this._compressionMethod = this.readUint8(), this._compressionMethod !== ki.DEFLATE) throw new Error("Unsupported compression method: ".concat(this._compressionMethod)); + this._filterMethod = this.readUint8(), this._interlaceMethod = this.readUint8(); + } + + decodePLTE(t) { + if (t % 3 != 0) throw new RangeError("PLTE field length must be a multiple of 3. Got ".concat(t)); + const e = t / 3; + this._hasPalette = !0; + const i = []; + this._palette = i; + + for (let t = 0; t < e; t++) i.push([this.readUint8(), this.readUint8(), this.readUint8()]); + } + + decodeIDAT(t) { + this._inflator.push(new Uint8Array(this.buffer, this.offset + this.byteOffset, t)), this.skip(t); + } + + decodetRNS(t) { + if (3 === this._colorType) { + if (t > this._palette.length) throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t, " vs ").concat(this._palette.length, ")")); + let e = 0; + + for (; e < t; e++) { + const t = this.readByte(); + + this._palette[e].push(t); + } + + for (; e < this._palette.length; e++) this._palette[e].push(255); + } + } + + decodeiCCP(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + const n = this.readUint8(); + if (n !== ki.DEFLATE) throw new Error("Unsupported iCCP compression method: ".concat(n)); + const r = this.readBytes(t - i.length - 2); + this._png.iccEmbeddedProfile = { + name: i, + profile: ui(r) + }; + } + + decodetEXt(t) { + let e, + i = ""; + + for (; "\0" !== (e = this.readChar());) i += e; + + this._png.text[i] = this.readChars(t - i.length - 1); + } + + decodepHYs() { + const t = this.readUint32(), + e = this.readUint32(), + i = this.readByte(); + this._png.resolution = { + x: t, + y: e, + unit: i + }; + } + + decodeImage() { + if (this._inflator.err) throw new Error("Error while decompressing the data: ".concat(this._inflator.err)); + const t = this._inflator.result; + if (this._filterMethod !== yi.ADAPTIVE) throw new Error("Filter method ".concat(this._filterMethod, " not supported")); + if (this._interlaceMethod !== vi.NO_INTERLACE) throw new Error("Interlace method ".concat(this._interlaceMethod, " not supported")); + this.decodeInterlaceNull(t); + } + + decodeInterlaceNull(t) { + const e = this._png.height, + i = this._png.channels * this._png.depth / 8, + n = this._png.width * i, + r = new Uint8Array(this._png.height * n); + let s, + a, + o = Ei, + h = 0; + + for (let l = 0; l < e; l++) { + switch (s = t.subarray(h + 1, h + 1 + n), a = r.subarray(l * n, (l + 1) * n), t[h]) { + case 0: + zi(s, a, n); + break; + + case 1: + Ri(s, a, n, i); + break; + + case 2: + Ni(s, a, o, n); + break; + + case 3: + Ti(s, a, o, n, i); + break; + + case 4: + Oi(s, a, o, n, i); + break; + + default: + throw new Error("Unsupported filter: ".concat(t[h])); + } + + o = a, h += n + 1; + } + + if (this._hasPalette && (this._png.palette = this._palette), 16 === this._png.depth) { + const t = new Uint16Array(r.buffer); + if (xi) for (let e = 0; e < t.length; e++) t[e] = (255 & (l = t[e])) << 8 | l >> 8 & 255; + this._png.data = t; + } else this._png.data = r; + + var l; + } + + } + + function zi(t, e, i) { + for (let n = 0; n < i; n++) e[n] = t[n]; + } + + function Ri(t, e, i, n) { + let r = 0; + + for (; r < n; r++) e[r] = t[r]; + + for (; r < i; r++) e[r] = t[r] + e[r - n] & 255; + } + + function Ni(t, e, i, n) { + let r = 0; + if (0 === i.length) for (; r < n; r++) e[r] = t[r];else for (; r < n; r++) e[r] = t[r] + i[r] & 255; + } + + function Ti(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] >> 1) & 255; + } else { + for (; s < r; s++) e[s] = t[s] + (i[s] >> 1) & 255; + + for (; s < n; s++) e[s] = t[s] + (e[s - r] + i[s] >> 1) & 255; + } + } + + function Oi(t, e, i, n, r) { + let s = 0; + + if (0 === i.length) { + for (; s < r; s++) e[s] = t[s]; + + for (; s < n; s++) e[s] = t[s] + e[s - r] & 255; + } else { + for (; s < r; s++) e[s] = t[s] + i[s] & 255; + + for (; s < n; s++) e[s] = t[s] + Li(e[s - r], i[s], i[s - r]) & 255; + } + } + + function Li(t, e, i) { + const n = t + e - i, + r = Math.abs(n - t), + s = Math.abs(n - e), + a = Math.abs(n - i); + return r <= s && r <= a ? t : s <= a ? e : i; + } + + const Bi = { + level: 3 + }; + + class Ci extends r { + constructor(t) { + let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + super(), this._colorType = mi.UNKNOWN, this._zlibOptions = _objectSpread2(_objectSpread2({}, Bi), e.zlib), this._png = this._checkData(t), this.setBigEndian(); + } + + encode() { + return this.encodeSignature(), this.encodeIHDR(), this.encodeData(), this.encodeIEND(), this.toArray(); + } + + encodeSignature() { + this.writeBytes(wi); + } + + encodeIHDR() { + this.writeUint32(13), this.writeChars("IHDR"), this.writeUint32(this._png.width), this.writeUint32(this._png.height), this.writeByte(this._png.depth), this.writeByte(this._colorType), this.writeByte(ki.DEFLATE), this.writeByte(yi.ADAPTIVE), this.writeByte(vi.NO_INTERLACE), this.writeCrc(17); + } + + encodeIEND() { + this.writeUint32(0), this.writeChars("IEND"), this.writeCrc(4); + } + + encodeIDAT(t) { + this.writeUint32(t.length), this.writeChars("IDAT"), this.writeBytes(t), this.writeCrc(t.length + 4); + } + + encodeData() { + const { + width: t, + height: e, + channels: i, + depth: n, + data: s + } = this._png, + a = i * t, + o = new r().setBigEndian(); + let h = 0; + + for (let t = 0; t < e; t++) if (o.writeByte(0), 8 === n) h = Ii(s, o, a, h);else { + if (16 !== n) throw new Error("unreachable"); + h = Si(s, o, a, h); + } + + const l = o.toArray(), + d = fi(l, this._zlibOptions); + this.encodeIDAT(d); + } + + _checkData(t) { + const { + colorType: e, + channels: i, + depth: n + } = function (t) { + const { + channels: e = 4, + depth: i = 8 + } = t; + if (4 !== e && 3 !== e && 2 !== e && 1 !== e) throw new RangeError("unsupported number of channels: ".concat(e)); + if (8 !== i && 16 !== i) throw new RangeError("unsupported bit depth: ".concat(i)); + const n = { + channels: e, + depth: i, + colorType: mi.UNKNOWN + }; + + switch (e) { + case 4: + n.colorType = mi.TRUECOLOUR_ALPHA; + break; + + case 3: + n.colorType = mi.TRUECOLOUR; + break; + + case 1: + n.colorType = mi.GREYSCALE; + break; + + case 2: + n.colorType = mi.GREYSCALE_ALPHA; + break; + + default: + throw new Error("unsupported number of channels"); + } + + return n; + }(t), + r = { + width: Di(t.width, "width"), + height: Di(t.height, "height"), + channels: i, + data: t.data, + depth: n, + text: {} + }; + + this._colorType = e; + const s = r.width * r.height * i; + if (r.data.length !== s) throw new RangeError("wrong data size. Found ".concat(r.data.length, ", expected ").concat(s)); + return r; + } + + writeCrc(t) { + this.writeUint32(bi(new Uint8Array(this.buffer, this.byteOffset + this.offset - t, t), t)); + } + + } + + function Di(t, e) { + if (Number.isInteger(t) && t > 0) return t; + throw new TypeError("".concat(e, " must be a positive integer")); + } + + function Ii(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeByte(t[n++]); + + return n; + } + + function Si(t, e, i, n) { + for (let r = 0; r < i; r++) e.writeUint16(t[n++]); + + return n; + } + + var Zi; + !function (t) { + t[t.UNKNOWN = 0] = "UNKNOWN", t[t.METRE = 1] = "METRE"; + }(Zi || (Zi = {})); + + const Fi = (t, e, i) => new Ci({ + width: t, + height: e, + data: i + }, undefined).encode(), + Mi = t => function (t, e) { + return new Ui(t, void 0).decode(); + }(t); +})(); + +var r = n.P, + s = n.m; + +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} + +function stringify(o, gap, indentation) { + if (isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + + if (s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if (o && 'object' === typeof o) { + let isArray = Array.isArray(o); + + if (Object.keys(o).length == 0) { + if (isArray) return '[]';else return '{}'; + } + + let s = '\n'; + + for (let k in o) { + if (Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if (k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} + +function preStringify(object) { + let space = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; + var gap = ''; + + if (typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)); + } else if (typeof space == 'string') { + gap = space.slice(0, 10); + } + + return stringify(object, gap, -1); +} + +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + let filteredLines = []; + + for (let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + + if (trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while (!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if (this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = index !== undefined ? index : this.lineIndex; + if (index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for (let [line] of this.lines) { + if (!line.trim() || line.replace(/^\s+/, "") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = index !== undefined ? index : this.lineIndex; + if (index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while (line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } + +} + +function getObject(lineGroup, type) { + let object; + lineGroup.indentLevel(); + + while (!lineGroup.finished()) { + let line = lineGroup.next(); + let trimmedLine = line.trim(); + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if (trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if (typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if (keyMatch) { + if (!object) object = {}; + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if (trimmedLine.startsWith('-')) { + if (!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if (value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if (Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if (type) { + object = { + type: type, + data: object + }; + } + + return object; +} + +function getValue(value, type) { + value = JSON.parse(value); + + if (type) { + value = { + type: type, + data: value + }; + } + + return value; +} + +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + return getObject(lineGenerator); +} + +function deepCopy(obj) { + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(deepCopy(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = deepCopy(value); + } + + return newObj; + } + + return obj; +} + +function isPrimitiveReaderType(reader) { + switch (reader) { + case 'Boolean': + case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': + case 'Char': + case 'String': + case '': + case 'Vector2': + case 'Vector3': + case 'Vector4': + case 'Rectangle': + return true; + + default: + return false; + } +} + +function isExportReaderType(reader) { + switch (reader) { + case 'Texture2D': + case 'TBin': + case 'Effect': + case 'BmFont': + return true; + + default: + return false; + } +} + +function convertJsonContentsToXnbNode(raw, readers) { + let extractedImages = []; + let extractedMaps = []; + + const { + converted + } = function recursiveConvert(obj, path) { + let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const reader = readers[index]; + + if (isPrimitiveReaderType(reader)) { + return { + converted: { + type: reader, + data: obj + }, + traversed: index + }; + } + + if (reader === null) { + return { + converted: obj, + traversed: index + }; + } + + if (reader.startsWith('Nullable')) { + return { + converted: { + type: reader, + data: { + data: { + type: readers[index + 1], + data: obj + } + } + }, + traversed: index + 1 + }; + } + + if (isExportReaderType(reader)) { + if (reader === 'Texture2D') { + extractedImages.push({ + path: path.join('.') + }); + return { + converted: { + type: reader, + data: { + format: obj.format + } + }, + traversed: index + }; + } + + if (reader === 'TBin') { + extractedMaps.push({ + path: path.join('.') + }); + } + + return { + converted: { + type: reader, + data: {} + }, + traversed: index + }; + } + + let data; + if (Array.isArray(obj)) data = [];else data = {}; + let traversed = index; + let first = true; + let isComplex = !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List"); + + for (let [key, value] of Object.entries(obj)) { + let newIndex; + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; + const { + converted, + traversed: nexter + } = recursiveConvert(obj[key], [...path, key], newIndex); + data[key] = converted; + if (isComplex) traversed = nexter;else if (first) { + traversed = nexter; + first = false; + } + } + + return { + converted: { + type: reader, + data + }, + traversed + }; + }(raw, []); + + return { + converted, + extractedImages, + extractedMaps + }; +} + +function convertJsonContentsFromXnbNode(obj) { + if (!obj || typeof obj !== "object") return obj; + + if (typeof obj === "object" && obj.hasOwnProperty("data")) { + let { + type, + data + } = obj; + if (isPrimitiveReaderType(type)) return deepCopy(data); + + if (isExportReaderType(type)) { + data = deepCopy(data); + if (type === "Texture2D") data.export = "Texture2D.png";else if (type === "Effect") data.export = "Effect.cso";else if (type === "TBin") data.export = "TBin.tbin";else if (type === "BmFont") data.export = "BmFont.xml"; + return data; + } + + obj = deepCopy(data); + } + + let newObj; + + if (Array.isArray(obj)) { + newObj = []; + + for (let item of obj) { + newObj.push(convertJsonContentsFromXnbNode(item)); + } + + return newObj; + } + + if (!!obj && typeof obj === "object") { + newObj = {}; + + for (let [key, value] of Object.entries(obj)) { + newObj[key] = convertJsonContentsFromXnbNode(value); + } + + return newObj; + } + + return null; +} + +function toXnbNodeData(json) { + const toYamlJson = {}; + const { + compressed, + formatVersion, + hidef: hiDef, + target + } = json.header; + let readerData = deepCopy(json.readers); + toYamlJson.xnbData = { + target, + compressed: !!compressed, + hiDef, + readerData, + numSharedResources: 0 + }; + const rawContent = deepCopy(json.content); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); + + if (readersTypeList[0] === 'SpriteFont') { + readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; + rawContent.verticalSpacing = rawContent.verticalLineSpacing; + delete rawContent.verticalLineSpacing; + } + + const { + converted, + extractedImages, + extractedMaps + } = convertJsonContentsToXnbNode(rawContent, readersTypeList); + toYamlJson.content = converted; + if (extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; + if (extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; + return toYamlJson; +} + +function fromXnbNodeData(json) { + const result = {}; + const { + compressed, + readerData, + hiDef: hidef, + target + } = json.xnbData; + result.header = { + target, + formatVersion: 5, + compressed: compressed ? target === 'a' || target === 'i' ? 0x40 : 0x80 : 0, + hidef + }; + result.readers = deepCopy(readerData); + result.content = convertJsonContentsFromXnbNode(json.content); + + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { + result.content.verticalLineSpacing = result.content.verticalSpacing; + delete result.content.verticalSpacing; + } + + return result; +} + +function searchElement(parent, element) { + if (!parent || typeof parent != 'object') return; + + if (parent.hasOwnProperty(element)) { + return { + parent, + value: parent[element] + }; + } + + for (let child of Object.values(parent)) { + if (!!child || typeof child == 'object') { + let found = searchElement(child, element); + if (found) return found; + } + } + + return null; +} + +function extractFileName(fullname) { + let matcher = fullname.match(/(.*)\.([^\s.]+)$/); + if (matcher === null) return [fullname, null]; + return [matcher[1], matcher[2]]; +} + +function getExtension(dataType) { + switch (dataType) { + case "JSON": + return "json"; + + case "yaml": + return "yaml"; + + case "Texture2D": + return "png"; + + case "Effect": + return "cso"; + + case 'TBin': + return "tbin"; + + case 'BmFont': + return "xml"; + } + + return "bin"; +} + +function getMimeType(dataType) { + switch (dataType) { + case "JSON": + return "application/json"; + + case "yaml": + return "text/plain"; + + case "Texture2D": + return "image/png"; + + case "Effect": + return "application/x-cso"; + + case 'BmFont': + return "application/xml"; + } + + return "application/octet-stream"; +} + +function makeBlob(data, dataType) { + if (typeof Blob === "function") return { + data: new Blob([data], { + type: getMimeType(dataType) + }), + extension: getExtension(dataType) + }; + return { + data: data, + extension: getExtension(dataType) + }; +} + +function exportContent(content) { + let jsonContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + let found = searchElement(content, "export"); + + if (found) { + const { + value + } = found; + let { + type: dataType, + data + } = value; + + if (dataType === "Texture2D") { + data = s(value.width, value.height, new Uint8Array(data)); + } + + return makeBlob(data, dataType); + } + + if (jsonContent) { + let contentJson = JSON.stringify(content, null, 4); + return makeBlob(contentJson, "JSON"); + } + + return null; +} +/** @api + * decompressed xnb object to real file blobs. + * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) + * @param {Object} config (yaml:export file as yaml, + * contentOnly:export content file only, + * fileName:exported files's name) (optional) + */ + + +function exportFiles(xnbObject) { + let { + yaml: isYaml = false, + contentOnly = false, + fileName = null + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + if (isYaml && contentOnly) isYaml = false; + if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); + const blobs = []; + const { + content + } = xnbObject; + const contentBlob = exportContent(content, contentOnly); + if (contentBlob !== null) blobs.push(contentBlob); + if (contentOnly) return blobs; + const resultJSON = JSON.stringify(xnbObject, (key, value) => { + if (key === "export") { + if (typeof fileName == "string" && fileName !== "") { + return "".concat(fileName, ".").concat(getExtension(value.type)); + } + + return "".concat(value.type, ".").concat(getExtension(value.type)); + } + + return value; + }, 4); + let result = resultJSON; + if (isYaml) result = preStringify(toXnbNodeData(xnbObject)); + blobs.unshift(makeBlob(result, isYaml ? "yaml" : "JSON")); + return blobs; +} + +function resolveCompression(compressionString) { + let str = compressionString.toLowerCase(); + if (str === "none") return 0; + if (str === "lz4") return 0x40; + return null; +} + +async function readBlobasText(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.text();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); +} + +async function readBlobasArrayBuffer(blob) { + if (typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer();else if (typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; +} + +async function readExternFiles(extension, files) { + if (extension === "png") { + const rawPng = await readBlobasArrayBuffer(files.png); + const png = r(new Uint8Array(rawPng)); + return { + type: "Texture2D", + data: png.data, + width: png.width, + height: png.height + }; + } + + if (extension === "cso") { + const data = await readBlobasArrayBuffer(files.cso); + return { + type: "Effect", + data + }; + } + + if (extension === "tbin") { + const data = await readBlobasArrayBuffer(files.tbin); + return { + type: "TBin", + data + }; + } + + if (extension === "xml") { + const data = await readBlobasText(files.xml); + return { + type: "BmFont", + data + }; + } +} + +async function resolveImports(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + compression = "default" + } = configs; + const jsonFile = files.json || files.yaml; + if (!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); + const rawText = await readBlobasText(jsonFile); + let jsonData = null; + if (files.json) jsonData = JSON.parse(rawText);else jsonData = fromXnbNodeData(parse(rawText)); + let compressBits = resolveCompression(compression); + if (compressBits !== null) jsonData.header.compressed = compressBits; + + if (!jsonData.hasOwnProperty('content')) { + throw new XnbError("".concat(jsonFile.name, " does not have \"content\".")); + } + + const found = searchElement(jsonData.content, "export"); + + if (found) { + const { + parent, + value + } = found; + const [, extension] = extractFileName(value); + parent.export = await readExternFiles(extension, files); + } + + return jsonData; +} + +/** @api + * Asynchronously reads the file into binary and then unpacks the json data. + * XNB -> arrayBuffer -> XnbData + * @param {File / Buffer} file + * @return {XnbData} JSON data with headers + */ + +async function unpackToXnbData(file) { + if (typeof window !== "undefined") { + const [, extension] = extractFileName(file.name); + + if (extension !== "xnb") { + return new Error("Invalid XNB File!"); + } + + const buffer = await file.arrayBuffer(); + return bufferToXnb(buffer); + } + + return bufferToXnb(file.buffer); +} +/** @api + * Asynchronously reads the file into binary and then return content file. + * XNB -> arrayBuffer -> XnbData -> Content + * @param {File / Buffer} file + * @return {XnbContent} exported Content Object + */ + + +function unpackToContent(file) { + return unpackToXnbData(file).then(xnbDataToContent); +} +/** @api + * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. + * XNB -> arrayBuffer -> XnbData -> Files + * @param {File / Buffer} file + * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) + * @return {Array} exported Files Blobs + */ + + +function unpackToFiles(file) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let { + yaml = false, + contentOnly = false, + fileName: name = null + } = configs; + if (typeof window !== "undefined" && name === null) name = file.name; + let [fileName] = extractFileName(name); + + const exporter = xnbObject => exportFiles(xnbObject, { + yaml, + contentOnly, + fileName + }); + + return unpackToXnbData(file).then(exporter); +} +/** @api + * reads the buffer and then unpacks. + * arrayBuffer -> XnbData + * @param {ArrayBuffer} buffer + * @return {XnbData} the loaded XNB json + */ + + +function bufferToXnb(buffer) { + const xnb = new XnbConverter(); + return xnb.load(buffer); +} +/** @api + * reads the buffer and then unpacks the contents. + * arrayBuffer -> XnbData -> Content + * @param {ArrayBuffer} buffer + * @return {XnbContent} exported Content Object + */ + + +function bufferToContents(buffer) { + const xnb = new XnbConverter(); + const xnbData = xnb.load(buffer); + return xnbDataToContent(xnbData); +} +/** @api + * remove header from the loaded XNB Object + * XnbData -> Content + * @param {XnbData} the loaded XNB object include headers + * @return {XnbContent} exported Content Object + */ + + +function xnbDataToContent(loadedXnb) { + const { + content + } = loadedXnb; + const { + data, + extension + } = exportContent(content, true); + return new XnbContent(data, extension); +} +/** @api + * reads the json and then unpacks the contents. + * @param {FileList/Array} to pack json data + * @return {Object/Object} packed XNB Array Buffer + */ + + +function fileMapper(files) { + let returnMap = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let [fileName, extension] = extractFileName(file.name); + if (extension === null) continue; + if (returnMap[fileName] === undefined) returnMap[fileName] = {}; + const namedFileObj = returnMap[fileName]; + if (typeof Blob === "function" && file instanceof Blob) namedFileObj[extension] = file;else namedFileObj[extension] = file.data; + } + + return returnMap; +} +/** @api + * reads the json and then unpacks the contents. + * @param {json} to pack json data + * @return {ArrayBuffer} packed XNB Array Buffer + */ + + +function packJsonToBinary(json) { + const xnb = new XnbConverter(); + const buffer = xnb.convert(json); + return buffer; +} +/** @api + * Asynchronously reads the file into binary and then pack xnb files. + * @param {FlieList} files + * @param {Object} configs(compression:default, none, LZ4, LZX / debug) + * @return {Array(Blobs)} + */ + + +function pack(files) { + let configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const groupedFiles = fileMapper(files); + let promises = []; + + for (let [fileName, filePack] of Object.entries(groupedFiles)) { + promises.push(resolveImports(filePack, configs).then(packJsonToBinary).then(buffer => { + if (typeof Blob === "function") return { + name: fileName, + data: new Blob([buffer], { + type: "application/octet-stream" + }) + }; + return { + name: fileName, + data: new Uint8Array(buffer) + }; + })); + } + + return __promise_allSettled(promises).then(blobArray => { + if (configs.debug === true) return blobArray; + return blobArray.filter(_ref => { + let { + status, + value + } = _ref; + return status === "fulfilled"; + }).map(_ref2 => { + let { + value + } = _ref2; + return value; + }); + }); +} + +function setReaders(readers) { + return TypeReader.setReaders(readers); +} + +function addReaders(readers) { + return TypeReader.addReaders(readers); +} + +export { XnbContent, XnbData, addReaders, bufferToContents, bufferToXnb, pack, setReaders, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; diff --git a/src/core/es5.js b/src/core/es5.js new file mode 100644 index 0000000..be99c7f --- /dev/null +++ b/src/core/es5.js @@ -0,0 +1,4 @@ +import "core-js/modules/es.promise.js"; +import "regenerator-runtime/runtime.js"; + +export * from "./Xnb.js"; \ No newline at end of file diff --git a/src/core/libs/jsonToYaml.js b/src/core/libs/jsonToYaml.js new file mode 100644 index 0000000..34f4109 --- /dev/null +++ b/src/core/libs/jsonToYaml.js @@ -0,0 +1,220 @@ +/** + * from https://github.com/draivin/XNBNode + * XnbExtract is using this code to parse yaml + */ + + +function isTypeObject(object) { + return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); +} +function stringify (o, gap, indentation) { + if(isTypeObject(o)) { + let s = stringify(o.data, gap, indentation); + if(s.includes('\n')) { + return ' #!' + o.type + s; + } else { + return s + ' #!' + o.type; + } + } else if(o && 'object' === typeof o) { + + let isArray = Array.isArray(o); + if(Object.keys(o).length == 0) { + if(isArray) return '[]'; + else return '{}'; + } + + let s = '\n'; + + + for(let k in o) { + if(Object.hasOwnProperty.call(o, k)) { + s += gap.repeat(indentation + 1); + if (isArray) { + s += '- ' + stringify(o[k], gap, indentation + 1); + } else { + if(k.includes(': ')) { + s += stringify(k, gap, indentation + 1); + s += ': ' + stringify(o[k], gap, indentation + 1); + } else { + s += k + ': ' + stringify(o[k], gap, indentation + 1); + } + } + s += '\n'; + } + } + + return s; + } else if ('string' === typeof o) { + return JSON.stringify(o); + } else if ('undefined' === typeof o || o === null) { + return 'null'; + } else if (!!o == o || +o == o) { //boolean & number + return JSON.stringify(o); + } else { + throw new Error('Non-implemented parsing for ' + o); + } +} + +function preStringify(object, space=4) { + var gap = '' + if(typeof space == 'number') { + gap = ' '.repeat(Math.min(10, space)) + } else if(typeof space == 'string') { + gap = space.slice(0, 10) + } + + return stringify(object, gap, -1) +} + +class LineGenerator { + constructor(lines, indentString, startingLine) { + this.startingLine = startingLine || 0; + this.lineIndex = -1; + + let filteredLines = []; + for(let i = 0; i < lines.length; i++) { + let trimmedLine = lines[i].trim(); + if(trimmedLine !== '') { + filteredLines.push([lines[i], i]); + } + } + + this.lines = filteredLines; + + this.indentString = indentString || this.findIndentString(); + } + + getLineNumber() { + return this.startingLine + this.lineIndex; + } + + nextGroup() { + let lines = []; + let baseIndent = this.indentLevel(this.lineIndex + 1); + + while(!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { + lines.push(this.next()); + } + + return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); + } + + next() { + if(this.finished()) throw new Error('Trying to next finished generator'); + this.lineIndex++; + return this.getLine(); + } + + peek() { + return this.getLine(this.lineIndex + 1); + } + + finished() { + return this.lineIndex == this.lines.length - 1; + } + + getLine(index) { + index = (index !== undefined) ? index : this.lineIndex; + if(index >= this.lines.length) return null; + return this.lines[index][0]; + } + + findIndentString() { + for(let [line] of this.lines) { + if(!line.trim() || line.replace(/^\s+/,"") == line) continue; + return line.match(/^(\s+)/)[1]; + } + + return ''; + } + + indentLevel(index) { + index = (index !== undefined) ? index : this.lineIndex; + if(index < 0) index = 0; + let indentLevel = 0; + let line = this.getLine(index); + + while(line.startsWith(this.indentString)) { + line = line.slice(this.indentString.length); + indentLevel++; + } + + return indentLevel; + } +} + +function getObject(lineGroup, type) { + let object; + + let baseIndent = lineGroup.indentLevel(); + + while(!lineGroup.finished()) { + let line = lineGroup.next() + let trimmedLine = line.trim(); + + let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); + let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; + + if(trimmedLine.startsWith('"')) { + keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); + } + + if(typeMatch) { + type = typeMatch[1]; + trimmedLine = trimmedLine.replace(typeMatch[0], ''); + } + + if(keyMatch) { + if(!object) object = {}; + + key = keyMatch[1]; + value = trimmedLine.replace(keyMatch[0], '').trim(); + } else if(trimmedLine.startsWith('-')) { + if(!object) object = []; + value = trimmedLine.slice(1).trim(); + } + + if(value) { + value = getValue(value, type); + } else { + value = getObject(lineGroup.nextGroup(), type); + } + + if(Array.isArray(object)) { + object.push(value); + } else { + object[key] = value; + } + } + + if(type) { + object = { + type: type, + data: object + }; + } + + return object; +} + +function getValue(value, type) { + value = JSON.parse(value); + if(type) { + value = { + type: type, + data: value + }; + } + + return value; +} + +function parse(str) { + let lines = str.replace(/\t/g, ' ').split('\n'); + let lineGenerator = new LineGenerator(lines); + + return getObject(lineGenerator); +} + +export {preStringify as stringifyYaml, parse as parseYaml}; \ No newline at end of file diff --git a/src/core/libs/png.js b/src/core/libs/png.js new file mode 100644 index 0000000..32cbf23 --- /dev/null +++ b/src/core/libs/png.js @@ -0,0 +1 @@ +var t={396:function(){!function(t){if(t.TextEncoder&&t.TextDecoder)return!1;function e(t="utf-8"){if("utf-8"!==t)throw new RangeError(`Failed to construct 'TextEncoder': The encoding label provided ('${t}') is invalid.`)}function i(t="utf-8",e={fatal:!1}){if("utf-8"!==t)throw new RangeError(`Failed to construct 'TextDecoder': The encoding label provided ('${t}') is invalid.`);if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},e={};function i(n){var r=e[n];if(void 0!==r)return r.exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,i),s.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};(()=>{i.d(n,{P:()=>Mi,m:()=>Fi}),i(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class r{constructor(t=8192,e={}){let i=!1;"number"==typeof t?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=i?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){const e=new Uint8Array(t);for(let i=0;ithis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function s(t){let e=t.length;for(;--e>=0;)t[e]=0}const a=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),o=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),h=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),l=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),d=new Array(576);s(d);const _=new Array(60);s(_);const f=new Array(512);s(f);const c=new Array(256);s(c);const u=new Array(29);s(u);const w=new Array(30);function p(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let g,b,m;function k(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}s(w);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},E=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{E(t,i[2*e],i[2*e+1])},x=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},U=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=x(n[e]++,e))}},z=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},N=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,s,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?A(t,r,e):(s=c[r],A(t,s+256+1,e),h=a[s],0!==h&&(r-=u[s],E(t,r,h)),n--,s=y(n),A(t,s,i),h=o[s],0!==h&&(n-=w[s],E(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)T(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],T(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,T(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,_,f,c,u,w=0;for(f=0;f<=15;f++)t.bl_count[f]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],f=i[2*i[2*d+1]+1]+1,f>h&&(f=h,w++),i[2*d+1]=f,d>n||(t.bl_count[f]++,c=0,d>=o&&(c=a[d-o]),u=i[2*d],t.opt_len+=u*(f+c),s&&(t.static_len+=u*(r[2*d+1]+c)));if(0!==w){do{for(f=h-1;0===t.bl_count[f];)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(f=h;0!==f;f--)for(d=t.bl_count[f];0!==d;)_=t.heap[--l],_>n||(i[2*_+1]!==f&&(t.opt_len+=(f-i[2*_+1])*i[2*_],i[2*_+1]=f),d--)}})(t,e),U(i,l,t.bl_count)},B=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{E(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var S={_tr_init:t=>{D||((()=>{let t,e,i,n,r;const s=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(w[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(B(t,t.dyn_ltree,t.l_desc.max_code),B(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*l[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?I(t,e,i,n):4===t.strategy||s===r?(E(t,2+(n?1:0),3),O(t,d,_)):(E(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(E(t,e-257,5),E(t,i-1,5),E(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{E(t,2,3),A(t,256,d),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},Z=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const F=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var M=(t,e,i,n)=>{const r=F,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},H={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:W,_tr_stored_block:K,_tr_flush_block:$,_tr_tally:Y,_tr_align:j}=S,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:X,Z_FULL_FLUSH:V,Z_FINISH:q,Z_BLOCK:J,Z_OK:Q,Z_STREAM_END:tt,Z_STREAM_ERROR:et,Z_DATA_ERROR:it,Z_BUF_ERROR:nt,Z_DEFAULT_COMPRESSION:rt,Z_FILTERED:st,Z_HUFFMAN_ONLY:at,Z_RLE:ot,Z_FIXED:ht,Z_DEFAULT_STRATEGY:lt,Z_UNKNOWN:dt,Z_DEFLATED:_t}=H,ft=258,ct=262,ut=103,wt=113,pt=666,gt=(t,e)=>(t.msg=P[e],e),bt=t=>(t<<1)-(t>4?9:0),mt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let kt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},vt=(t,e)=>{$(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,yt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},xt=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=Z(t.adler,e,r,i):2===t.state.wrap&&(t.adler=M(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Ut=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-ct?t.strstart-(t.w_size-ct):0,l=t.window,d=t.w_mask,_=t.prev,f=t.strstart+ft;let c=l[s+a-1],u=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===u&&l[i+a-1]===c&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;c=l[s+a-1],u=l[s+a]}}}while((e=_[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},zt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-ct)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=xt(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=kt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=kt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead{let i,n;for(;;){if(t.lookahead=3&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-ct&&(t.match_length=Ut(t,i)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=kt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2},Nt=(t,e)=>{let i,n,r;for(;;){if(t.lookahead=3&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(vt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=Y(t,0,t.window[t.strstart-1]),n&&vt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2};function Tt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Ot=[new Tt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(zt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,vt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-ct&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(vt(t,!1),t.strm.avail_out),1)})),new Tt(4,4,8,4,Rt),new Tt(4,5,16,8,Rt),new Tt(4,6,32,32,Rt),new Tt(4,4,16,16,Nt),new Tt(8,16,32,32,Nt),new Tt(8,16,128,128,Nt),new Tt(8,32,128,256,Nt),new Tt(32,128,258,1024,Nt),new Tt(32,258,258,4096,Nt)];function Lt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=_t,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),mt(this.dyn_ltree),mt(this.dyn_dtree),mt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),mt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),mt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Bt=t=>{if(!t||!t.state)return gt(t,et);t.total_in=t.total_out=0,t.data_type=dt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:wt,t.adler=2===e.wrap?0:1,e.last_flush=G,W(e),Q},Ct=t=>{const e=Bt(t);var i;return e===Q&&((i=t.state).window_size=2*i.w_size,mt(i.head),i.max_lazy_match=Ot[i.level].max_lazy,i.good_match=Ot[i.level].good_length,i.nice_match=Ot[i.level].nice_length,i.max_chain_length=Ot[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e},Dt=(t,e,i,n,r,s)=>{if(!t)return et;let a=1;if(e===rt&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==_t||n<8||n>15||e<0||e>9||s<0||s>ht)return gt(t,et);8===n&&(n=9);const o=new Lt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<t&&t.state?2!==t.state.wrap?et:(t.state.gzhead=e,Q):et,Zt=(t,e)=>{let i,n;if(!t||!t.state||e>J||e<0)return t?gt(t,et):et;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===pt&&e!==q)return gt(t,0===t.avail_out?nt:et);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=at||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=M(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=at||r.level<2?4:0),Et(r,3),r.status=wt);else{let e=_t+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=at||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=wt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=ut)}else r.status=ut;if(r.status===ut&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&yt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=wt)):r.status=wt),0!==r.pending){if(yt(t),0===t.avail_out)return r.last_flush=-1,Q}else if(0===t.avail_in&&bt(e)<=bt(s)&&e!==q)return gt(t,nt);if(r.status===pt&&0!==t.avail_in)return gt(t,nt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==pt){let i=r.strategy===at?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(zt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ot?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ft){if(zt(t),t.lookahead<=ft&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ft;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Ot[r.level].func(r,e);if(3!==i&&4!==i||(r.status=pt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),Q;if(2===i&&(e===X?j(r):e!==J&&(K(r,0,0,!1),e===V&&(mt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),yt(t),0===t.avail_out))return r.last_flush=-1,Q}return e!==q?Q:r.wrap<=0?tt:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),yt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?Q:tt)},Ft=t=>{if(!t||!t.state)return et;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==ut&&e!==wt&&e!==pt?gt(t,et):(t.state=null,e===wt?gt(t,it):Q)},Mt=(t,e)=>{let i=e.length;if(!t||!t.state)return et;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return et;if(1===r&&(t.adler=Z(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(mt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,zt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=kt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,zt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,Q};const Pt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Ht=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Pt(i,e)&&(t[e]=i[e])}}return t},Wt=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;$t[254]=$t[254]=1;var Yt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},jt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Kt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+$t[t[i]]>e?i:e},Xt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Vt=Object.prototype.toString,{Z_NO_FLUSH:qt,Z_SYNC_FLUSH:Jt,Z_FULL_FLUSH:Qt,Z_FINISH:te,Z_OK:ee,Z_STREAM_END:ie,Z_DEFAULT_COMPRESSION:ne,Z_DEFAULT_STRATEGY:re,Z_DEFLATED:se}=H;function ae(t){this.options=Ht({level:ne,method:se,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Xt,this.strm.avail_out=0;let i=It(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==ee)throw new Error(P[i]);if(e.header&&St(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Yt(e.dictionary):"[object ArrayBuffer]"===Vt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=Mt(this.strm,t),i!==ee)throw new Error(P[i]);this._dict_set=!0}}function oe(t,e){const i=new ae(e);if(i.push(t,!0),i.err)throw i.msg||P[i.err];return i.result}ae.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?te:qt,"string"==typeof t?i.input=Yt(t):"[object ArrayBuffer]"===Vt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Jt||s===Qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Zt(i,s),r===ie)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ft(this.strm),this.onEnd(r),this.ended=!0,r===ee;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ae.prototype.onData=function(t){this.chunks.push(t)},ae.prototype.onEnd=function(t){t===ee&&(this.result=Wt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var he={Deflate:ae,deflate:oe,deflateRaw:function(t,e){return(e=e||{}).raw=!0,oe(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,oe(t,e)},constants:H},le=function(t,e){let i,n,r,s,a,o,h,l,d,_,f,c,u,w,p,g,b,m,k,y,v,E,A,x;const U=t.state;i=t.next_in,A=t.input,n=i+(t.avail_in-5),r=t.next_out,x=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,_=U.window,f=U.hold,c=U.bits,u=U.lencode,w=U.distcode,p=(1<>>24,f>>>=m,c-=m,m=b>>>16&255,0===m)x[r++]=65535&b;else{if(!(16&m)){if(0==(64&m)){b=u[(65535&b)+(f&(1<>>=m,c-=m),c<15&&(f+=A[i++]<>>24,f>>>=m,c-=m,m=b>>>16&255,!(16&m)){if(0==(64&m)){b=w[(65535&b)+(f&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(f>>>=m,c-=m,m=r-s,y>m){if(m=y-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(v=0,E=_,0===d){if(v+=h-m,m2;)x[r++]=E[v++],x[r++]=E[v++],x[r++]=E[v++],k-=3;k&&(x[r++]=E[v++],k>1&&(x[r++]=E[v++]))}else{v=r-y;do{x[r++]=x[v++],x[r++]=x[v++],x[r++]=x[v++],k-=3}while(k>2);k&&(x[r++]=x[v++],k>1&&(x[r++]=x[v++]))}break}}break}}while(i>3,i-=k,c-=k<<3,f&=(1<{const h=o.bits;let l,d,_,f,c,u,w=0,p=0,g=0,b=0,m=0,k=0,y=0,v=0,E=0,A=0,x=null,U=0;const z=new Uint16Array(16),R=new Uint16Array(16);let N,T,O,L=null,B=0;for(w=0;w<=15;w++)z[w]=0;for(p=0;p=1&&0===z[b];b--);if(m>b&&(m=b),0===b)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(R[1]=0,w=1;w<15;w++)R[w+1]=R[w]+z[w];for(p=0;p852||2===t&&E>592)return 1;for(;;){N=w-y,a[p]u?(T=L[B+a[p]],O=x[U+a[p]]):(T=96,O=0),l=1<>y)+d]=N<<24|T<<16|O|0}while(0!==d);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--z[w]){if(w===b)break;w=e[i+a[p]]}if(w>m&&(A&f)!==_){for(0===y&&(y=m),c+=g,k=w-y,v=1<852||2===t&&E>592)return 1;_=A&f,r[_]=m<<24|k<<16|c-s|0}}return 0!==A&&(r[c+A]=w-y<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:we,Z_BLOCK:pe,Z_TREES:ge,Z_OK:be,Z_STREAM_END:me,Z_NEED_DICT:ke,Z_STREAM_ERROR:ye,Z_DATA_ERROR:ve,Z_MEM_ERROR:Ee,Z_BUF_ERROR:Ae,Z_DEFLATED:xe}=H,Ue=12,ze=30,Re=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ne(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Te=t=>{if(!t||!t.state)return ye;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,be},Oe=t=>{if(!t||!t.state)return ye;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,Te(t)},Le=(t,e)=>{let i;if(!t||!t.state)return ye;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ye:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Oe(t))},Be=(t,e)=>{if(!t)return ye;const i=new Ne;t.state=i,i.window=null;const n=Le(t,e);return n!==be&&(t.state=null),n};let Ce,De,Ie=!0;const Se=t=>{if(Ie){Ce=new Int32Array(512),De=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(ue(1,t.lens,0,288,Ce,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;ue(2,t.lens,0,32,De,0,t.work,{bits:5}),Ie=!1}t.lencode=Ce,t.lenbits=9,t.distcode=De,t.distbits=5},Ze=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{let i,n,r,s,a,o,h,l,d,_,f,c,u,w,p,g,b,m,k,y,v,E,A=0;const x=new Uint8Array(4);let U,z;const R=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ye;i=t.state,i.mode===Ue&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,_=o,f=h,E=be;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=M(i.check,x,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=ze;break}if((15&l)!==xe){t.msg="unknown compression method",i.mode=ze;break}if(l>>>=4,d-=4,v=8+(15&l),0===i.wbits)i.wbits=v;else if(v>i.wbits){t.msg="invalid window size",i.mode=ze;break}i.dmax=1<>8&1),512&i.flags&&(x[0]=255&l,x[1]=l>>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,x[2]=l>>>16&255,x[3]=l>>>24&255,i.check=M(i.check,x,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(x[0]=255&l,x[1]=l>>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(c=i.length,c>o&&(c=o),c&&(i.head&&(v=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+c),v)),512&i.flags&&(i.check=M(i.check,n,c,s)),o-=c,s+=c,i.length-=c),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;c=0;do{v=n[s+c++],i.head&&v&&i.length<65536&&(i.head.name+=String.fromCharCode(v))}while(v&&c>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=Ue;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Se(i),i.mode=20,e===ge){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=ze}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=ze;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===ge)break t;case 15:i.mode=16;case 16:if(c=i.length,c){if(c>o&&(c=o),c>h&&(c=h),0===c)break t;r.set(n.subarray(s,s+c),a),o-=c,s+=c,h-=c,a+=c,i.length-=c;break}i.mode=Ue;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=ze;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[R[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},E=ue(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,E){t.msg="invalid code lengths set",i.mode=ze;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=b;else{if(16===b){for(z=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=ze;break}v=i.lens[i.have-1],c=3+(3&l),l>>>=2,d-=2}else if(17===b){for(z=p+3;d>>=p,d-=p,v=0,c=3+(7&l),l>>>=3,d-=3}else{for(z=p+7;d>>=p,d-=p,v=0,c=11+(127&l),l>>>=7,d-=7}if(i.have+c>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=ze;break}for(;c--;)i.lens[i.have++]=v}}if(i.mode===ze)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=ze;break}if(i.lenbits=9,U={bits:i.lenbits},E=ue(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,E){t.msg="invalid literal/lengths set",i.mode=ze;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},E=ue(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,E){t.msg="invalid distances set",i.mode=ze;break}if(i.mode=20,e===ge)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,le(t,f),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===Ue&&(i.back=-1);break}for(i.back=0;A=i.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=b,0===g){i.mode=26;break}if(32&g){i.back=-1,i.mode=Ue;break}if(64&g){t.msg="invalid literal/length code",i.mode=ze;break}i.extra=15&g,i.mode=22;case 22:if(i.extra){for(z=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;A=i.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&g){t.msg="invalid distance code",i.mode=ze;break}i.offset=b,i.extra=15&g,i.mode=24;case 24:if(i.extra){for(z=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=ze;break}i.mode=25;case 25:if(0===h)break t;if(c=f-h,i.offset>c){if(c=i.offset-c,c>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=ze;break}c>i.wnext?(c-=i.wnext,u=i.wsize-c):u=i.wnext-c,c>i.length&&(c=i.length),w=i.window}else w=r,u=a-i.offset,c=i.length;c>h&&(c=h),h-=c,i.length-=c;do{r[a++]=w[u++]}while(--c);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ye;let e=t.state;return e.window&&(e.window=null),t.state=null,be},We=(t,e)=>{if(!t||!t.state)return ye;const i=t.state;return 0==(2&i.wrap)?ye:(i.head=e,e.done=!1,be)},Ke=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ye:11===n.mode&&(r=1,r=Z(r,e,i,0),r!==n.check)?ve:(s=Ze(t,e,i,i),s?(n.mode=31,Ee):(n.havedict=1,be))):ye},$e=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ye=Object.prototype.toString,{Z_NO_FLUSH:je,Z_FINISH:Ge,Z_OK:Xe,Z_STREAM_END:Ve,Z_NEED_DICT:qe,Z_STREAM_ERROR:Je,Z_DATA_ERROR:Qe,Z_MEM_ERROR:ti}=H;function ei(t){this.options=Ht({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Xt,this.strm.avail_out=0;let i=Me(this.strm,e.windowBits);if(i!==Xe)throw new Error(P[i]);if(this.header=new $e,We(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Yt(e.dictionary):"[object ArrayBuffer]"===Ye.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Ke(this.strm,e.dictionary),i!==Xe)))throw new Error(P[i])}function ii(t,e){const i=new ei(e);if(i.push(t),i.err)throw i.msg||P[i.err];return i.result}ei.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ge:je,"[object ArrayBuffer]"===Ye.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=Pe(i,a),s===qe&&r&&(s=Ke(i,r),s===Xe?s=Pe(i,a):s===Qe&&(s=qe));i.avail_in>0&&s===Ve&&i.state.wrap>0&&0!==t[i.next_in];)Fe(i),s=Pe(i,a);switch(s){case Je:case Qe:case qe:case ti:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===Ve))if("string"===this.options.to){let t=Gt(i.output,i.next_out),e=i.next_out-t,r=jt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Xe||0!==o){if(s===Ve)return s=He(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},ei.prototype.onData=function(t){this.chunks.push(t)},ei.prototype.onEnd=function(t){t===Xe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Wt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var ni={Inflate:ei,inflate:ii,inflateRaw:function(t,e){return(e=e||{}).raw=!0,ii(t,e)},ungzip:ii,constants:H};const{Deflate:ri,deflate:si,deflateRaw:ai,gzip:oi}=he,{Inflate:hi,inflate:li,inflateRaw:di,ungzip:_i}=ni;var fi=si,ci=hi,ui=li;const wi=[137,80,78,71,13,10,26,10],pi=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;pi[t]=e}const gi=4294967295;function bi(t,e){return(function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e)^gi)>>>0}var mi,ki,yi,vi;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(mi||(mi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ki||(ki={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(yi||(yi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(vi||(vi={}));const Ei=new Uint8Array(0),Ai=new Uint16Array([255]),xi=255===new Uint8Array(Ai.buffer)[0];class Ui extends r{constructor(t,e={}){super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ci,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ki.UNKNOWN,this._filterMethod=yi.UNKNOWN,this._interlaceMethod=vi.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${t} vs ${this._palette.length})`);let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function zi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function Oi(t,e,i,n,r){let s=0;if(0===i.length){for(;s0)return t;throw new TypeError(`${e} must be a positive integer`)}function Ii(t,e,i,n){for(let r=0;rnew Ci({width:t,height:e,data:i},undefined).encode(),Mi=t=>function(t,e){return new Ui(t,void 0).decode()}(t)})();var r=n.P,s=n.m;export{r as fromPNG,s as toPNG}; \ No newline at end of file diff --git a/src/core/package.json b/src/core/package.json new file mode 100644 index 0000000..0d074f8 --- /dev/null +++ b/src/core/package.json @@ -0,0 +1,24 @@ +{ + "name": "@xnb/core", + "version": "1.1.0", + "description": "The core of xnb.js.", + "main": "./dist/core.js", + "module": "./dist/core.module.js", + "export": { + ".": { + "import": "./dist/core.module.js", + "require": "./dist/core.cjs" + } + }, + "files": [ + "dist" + ], + "keywords": [ + "xnb", + "converter", + "javascript", + "stardew-valley" + ], + "author": "Lybell", + "license": "LGPL-3.0-or-later" +} diff --git a/src/es5.js b/src/es5.js index 08c2d94..4422a27 100644 --- a/src/es5.js +++ b/src/es5.js @@ -1,7 +1,6 @@ import "core-js/modules/es.promise.js"; import "regenerator-runtime/runtime.js"; -import "core-js/modules/es.object.get-own-property-descriptors.js"; -import "core-js/modules/es.function.name.js"; import "core-js/modules/es.typed-array.map.js"; +import "core-js/modules/es.function.name.js"; -export * from "./XnbUnpacker.js"; \ No newline at end of file +export * from "./xnb.js"; \ No newline at end of file diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js new file mode 100644 index 0000000..e69de29 diff --git a/src/readers/LICENSE b/src/readers/LICENSE new file mode 100644 index 0000000..153d416 --- /dev/null +++ b/src/readers/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/src/readers/LICENSE-GPL.md b/src/readers/LICENSE-GPL.md new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/src/readers/LICENSE-GPL.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/src/readers/dist/readers.cjs b/src/readers/dist/readers.cjs new file mode 100644 index 0000000..9cc6846 --- /dev/null +++ b/src/readers/dist/readers.cjs @@ -0,0 +1,2718 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +class BaseReader { + static isTypeOf(type) { + return false; + } + + static hasSubType() { + return false; + } + + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + +} + +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + +} + +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + +} + +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + +} + +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + +} + +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + +} + +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + +} + +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + +} + +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + +} + +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + +} + +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } + + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content !== null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + +} + +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + +} + +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + +} + +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + +} + +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} + +function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} + +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; +} + +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; +} + +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; +} + +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; +} + +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); +} + +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} + +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + +} + +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + +} + +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} + +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} + +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} + +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} + +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } +} + +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + +} + +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + +} + +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} + +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; +} + +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; +} + +function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; +} + +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; +} + +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; +} + +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } +} + +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } +} + +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } +} + +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } +} + +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} + +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} + +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} + +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; +} + +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} + +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} + +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} + +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); +} + +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} + +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } +} + +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; + +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; +} + +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; +} + +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + +} + +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + +} + +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + +} + +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + +} + +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + +} + +exports.ArrayReader = ArrayReader; +exports.BaseReader = BaseReader; +exports.BmFontReader = BmFontReader; +exports.BooleanReader = BooleanReader; +exports.CharReader = CharReader; +exports.DictionaryReader = DictionaryReader; +exports.DoubleReader = DoubleReader; +exports.EffectReader = EffectReader; +exports.Int32Reader = Int32Reader; +exports.LightweightTexture2DReader = LightweightTexture2DReader; +exports.ListReader = ListReader; +exports.NullableReader = NullableReader; +exports.RectangleReader = RectangleReader; +exports.ReflectiveReader = ReflectiveReader; +exports.SingleReader = SingleReader; +exports.SpriteFontReader = SpriteFontReader; +exports.StringReader = StringReader; +exports.TBinReader = TBinReader; +exports.Texture2DReader = Texture2DReader; +exports.UInt32Reader = UInt32Reader; +exports.Vector2Reader = Vector2Reader; +exports.Vector3Reader = Vector3Reader; +exports.Vector4Reader = Vector4Reader; diff --git a/src/readers/dist/readers.es5.js b/src/readers/dist/readers.es5.js new file mode 100644 index 0000000..67306d0 --- /dev/null +++ b/src/readers/dist/readers.es5.js @@ -0,0 +1,4734 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {})); +})(this, (function (exports) { 'use strict'; + + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + // eslint-disable-next-line es-x/no-typed-arrays -- safe + var arrayBufferNative = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined'; + + var fails$9 = function (exec) { + try { + return !!exec(); + } catch (error) { + return true; + } + }; + + var fails$8 = fails$9; + + // Detect IE8's incomplete defineProperty implementation + var descriptors = !fails$8(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7; + }); + + var check = function (it) { + return it && it.Math == Math && it; + }; + + // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 + var global$q = + // eslint-disable-next-line es-x/no-global-this -- safe + check(typeof globalThis == 'object' && globalThis) || + check(typeof window == 'object' && window) || + // eslint-disable-next-line no-restricted-globals -- safe + check(typeof self == 'object' && self) || + check(typeof commonjsGlobal == 'object' && commonjsGlobal) || + // eslint-disable-next-line no-new-func -- fallback + (function () { return this; })() || Function('return this')(); + + // `IsCallable` abstract operation + // https://tc39.es/ecma262/#sec-iscallable + var isCallable$e = function (argument) { + return typeof argument == 'function'; + }; + + var isCallable$d = isCallable$e; + + var isObject$7 = function (it) { + return typeof it == 'object' ? it !== null : isCallable$d(it); + }; + + var fails$7 = fails$9; + + var functionBindNative = !fails$7(function () { + // eslint-disable-next-line es-x/no-function-prototype-bind -- safe + var test = (function () { /* empty */ }).bind(); + // eslint-disable-next-line no-prototype-builtins -- safe + return typeof test != 'function' || test.hasOwnProperty('prototype'); + }); + + var NATIVE_BIND$2 = functionBindNative; + + var FunctionPrototype$2 = Function.prototype; + var bind$2 = FunctionPrototype$2.bind; + var call$3 = FunctionPrototype$2.call; + var uncurryThis$c = NATIVE_BIND$2 && bind$2.bind(call$3, call$3); + + var functionUncurryThis = NATIVE_BIND$2 ? function (fn) { + return fn && uncurryThis$c(fn); + } : function (fn) { + return fn && function () { + return call$3.apply(fn, arguments); + }; + }; + + var global$p = global$q; + + var TypeError$a = global$p.TypeError; + + // `RequireObjectCoercible` abstract operation + // https://tc39.es/ecma262/#sec-requireobjectcoercible + var requireObjectCoercible$1 = function (it) { + if (it == undefined) throw TypeError$a("Can't call method on " + it); + return it; + }; + + var global$o = global$q; + var requireObjectCoercible = requireObjectCoercible$1; + + var Object$5 = global$o.Object; + + // `ToObject` abstract operation + // https://tc39.es/ecma262/#sec-toobject + var toObject$3 = function (argument) { + return Object$5(requireObjectCoercible(argument)); + }; + + var uncurryThis$b = functionUncurryThis; + var toObject$2 = toObject$3; + + var hasOwnProperty = uncurryThis$b({}.hasOwnProperty); + + // `HasOwnProperty` abstract operation + // https://tc39.es/ecma262/#sec-hasownproperty + // eslint-disable-next-line es-x/no-object-hasown -- safe + var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) { + return hasOwnProperty(toObject$2(it), key); + }; + + var shared$3 = {exports: {}}; + + var global$n = global$q; + + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var defineProperty$3 = Object.defineProperty; + + var setGlobal$2 = function (key, value) { + try { + defineProperty$3(global$n, key, { value: value, configurable: true, writable: true }); + } catch (error) { + global$n[key] = value; + } return value; + }; + + var global$m = global$q; + var setGlobal$1 = setGlobal$2; + + var SHARED = '__core-js_shared__'; + var store$3 = global$m[SHARED] || setGlobal$1(SHARED, {}); + + var sharedStore = store$3; + + var store$2 = sharedStore; + + (shared$3.exports = function (key, value) { + return store$2[key] || (store$2[key] = value !== undefined ? value : {}); + })('versions', []).push({ + version: '3.22.4', + mode: 'global', + copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)', + license: 'https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE', + source: 'https://github.com/zloirock/core-js' + }); + + var uncurryThis$a = functionUncurryThis; + + var id = 0; + var postfix = Math.random(); + var toString$1 = uncurryThis$a(1.0.toString); + + var uid$3 = function (key) { + return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$1(++id + postfix, 36); + }; + + var global$l = global$q; + var isCallable$c = isCallable$e; + + var aFunction = function (argument) { + return isCallable$c(argument) ? argument : undefined; + }; + + var getBuiltIn$3 = function (namespace, method) { + return arguments.length < 2 ? aFunction(global$l[namespace]) : global$l[namespace] && global$l[namespace][method]; + }; + + var getBuiltIn$2 = getBuiltIn$3; + + var engineUserAgent = getBuiltIn$2('navigator', 'userAgent') || ''; + + var global$k = global$q; + var userAgent = engineUserAgent; + + var process = global$k.process; + var Deno = global$k.Deno; + var versions = process && process.versions || Deno && Deno.version; + var v8 = versions && versions.v8; + var match, version; + + if (v8) { + match = v8.split('.'); + // in old Chrome, versions of V8 isn't V8 = Chrome / 10 + // but their correct versions are not interesting for us + version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); + } + + // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` + // so check `userAgent` even if `.v8` exists, but 0 + if (!version && userAgent) { + match = userAgent.match(/Edge\/(\d+)/); + if (!match || match[1] >= 74) { + match = userAgent.match(/Chrome\/(\d+)/); + if (match) version = +match[1]; + } + } + + var engineV8Version = version; + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var V8_VERSION = engineV8Version; + var fails$6 = fails$9; + + // eslint-disable-next-line es-x/no-object-getownpropertysymbols -- required for testing + var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$6(function () { + var symbol = Symbol(); + // Chrome 38 Symbol has incorrect toString conversion + // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances + return !String(symbol) || !(Object(symbol) instanceof Symbol) || + // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances + !Symbol.sham && V8_VERSION && V8_VERSION < 41; + }); + + /* eslint-disable es-x/no-symbol -- required for testing */ + + var NATIVE_SYMBOL$1 = nativeSymbol; + + var useSymbolAsUid = NATIVE_SYMBOL$1 + && !Symbol.sham + && typeof Symbol.iterator == 'symbol'; + + var global$j = global$q; + var shared$2 = shared$3.exports; + var hasOwn$5 = hasOwnProperty_1; + var uid$2 = uid$3; + var NATIVE_SYMBOL = nativeSymbol; + var USE_SYMBOL_AS_UID$1 = useSymbolAsUid; + + var WellKnownSymbolsStore = shared$2('wks'); + var Symbol$1 = global$j.Symbol; + var symbolFor = Symbol$1 && Symbol$1['for']; + var createWellKnownSymbol = USE_SYMBOL_AS_UID$1 ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$2; + + var wellKnownSymbol$6 = function (name) { + if (!hasOwn$5(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) { + var description = 'Symbol.' + name; + if (NATIVE_SYMBOL && hasOwn$5(Symbol$1, name)) { + WellKnownSymbolsStore[name] = Symbol$1[name]; + } else if (USE_SYMBOL_AS_UID$1 && symbolFor) { + WellKnownSymbolsStore[name] = symbolFor(description); + } else { + WellKnownSymbolsStore[name] = createWellKnownSymbol(description); + } + } return WellKnownSymbolsStore[name]; + }; + + var wellKnownSymbol$5 = wellKnownSymbol$6; + + var TO_STRING_TAG$2 = wellKnownSymbol$5('toStringTag'); + var test = {}; + + test[TO_STRING_TAG$2] = 'z'; + + var toStringTagSupport = String(test) === '[object z]'; + + var uncurryThis$9 = functionUncurryThis; + + var toString = uncurryThis$9({}.toString); + var stringSlice = uncurryThis$9(''.slice); + + var classofRaw$1 = function (it) { + return stringSlice(toString(it), 8, -1); + }; + + var global$i = global$q; + var TO_STRING_TAG_SUPPORT = toStringTagSupport; + var isCallable$b = isCallable$e; + var classofRaw = classofRaw$1; + var wellKnownSymbol$4 = wellKnownSymbol$6; + + var TO_STRING_TAG$1 = wellKnownSymbol$4('toStringTag'); + var Object$4 = global$i.Object; + + // ES3 wrong here + var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments'; + + // fallback for IE11 Script Access Denied error + var tryGet = function (it, key) { + try { + return it[key]; + } catch (error) { /* empty */ } + }; + + // getting tag from ES6+ `Object.prototype.toString` + var classof$4 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (tag = tryGet(O = Object$4(it), TO_STRING_TAG$1)) == 'string' ? tag + // builtinTag case + : CORRECT_ARGUMENTS ? classofRaw(O) + // ES3 arguments fallback + : (result = classofRaw(O)) == 'Object' && isCallable$b(O.callee) ? 'Arguments' : result; + }; + + var global$h = global$q; + + var String$3 = global$h.String; + + var tryToString$3 = function (argument) { + try { + return String$3(argument); + } catch (error) { + return 'Object'; + } + }; + + var objectDefineProperty = {}; + + var global$g = global$q; + var isObject$6 = isObject$7; + + var document = global$g.document; + // typeof document.createElement is 'object' in old IE + var EXISTS$1 = isObject$6(document) && isObject$6(document.createElement); + + var documentCreateElement = function (it) { + return EXISTS$1 ? document.createElement(it) : {}; + }; + + var DESCRIPTORS$6 = descriptors; + var fails$5 = fails$9; + var createElement = documentCreateElement; + + // Thanks to IE8 for its funny defineProperty + var ie8DomDefine = !DESCRIPTORS$6 && !fails$5(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(createElement('div'), 'a', { + get: function () { return 7; } + }).a != 7; + }); + + var DESCRIPTORS$5 = descriptors; + var fails$4 = fails$9; + + // V8 ~ Chrome 36- + // https://bugs.chromium.org/p/v8/issues/detail?id=3334 + var v8PrototypeDefineBug = DESCRIPTORS$5 && fails$4(function () { + // eslint-disable-next-line es-x/no-object-defineproperty -- required for testing + return Object.defineProperty(function () { /* empty */ }, 'prototype', { + value: 42, + writable: false + }).prototype != 42; + }); + + var global$f = global$q; + var isObject$5 = isObject$7; + + var String$2 = global$f.String; + var TypeError$9 = global$f.TypeError; + + // `Assert: Type(argument) is Object` + var anObject$3 = function (argument) { + if (isObject$5(argument)) return argument; + throw TypeError$9(String$2(argument) + ' is not an object'); + }; + + var NATIVE_BIND$1 = functionBindNative; + + var call$2 = Function.prototype.call; + + var functionCall = NATIVE_BIND$1 ? call$2.bind(call$2) : function () { + return call$2.apply(call$2, arguments); + }; + + var uncurryThis$8 = functionUncurryThis; + + var objectIsPrototypeOf = uncurryThis$8({}.isPrototypeOf); + + var global$e = global$q; + var getBuiltIn$1 = getBuiltIn$3; + var isCallable$a = isCallable$e; + var isPrototypeOf$1 = objectIsPrototypeOf; + var USE_SYMBOL_AS_UID = useSymbolAsUid; + + var Object$3 = global$e.Object; + + var isSymbol$2 = USE_SYMBOL_AS_UID ? function (it) { + return typeof it == 'symbol'; + } : function (it) { + var $Symbol = getBuiltIn$1('Symbol'); + return isCallable$a($Symbol) && isPrototypeOf$1($Symbol.prototype, Object$3(it)); + }; + + var global$d = global$q; + var isCallable$9 = isCallable$e; + var tryToString$2 = tryToString$3; + + var TypeError$8 = global$d.TypeError; + + // `Assert: IsCallable(argument) is true` + var aCallable$2 = function (argument) { + if (isCallable$9(argument)) return argument; + throw TypeError$8(tryToString$2(argument) + ' is not a function'); + }; + + var aCallable$1 = aCallable$2; + + // `GetMethod` abstract operation + // https://tc39.es/ecma262/#sec-getmethod + var getMethod$1 = function (V, P) { + var func = V[P]; + return func == null ? undefined : aCallable$1(func); + }; + + var global$c = global$q; + var call$1 = functionCall; + var isCallable$8 = isCallable$e; + var isObject$4 = isObject$7; + + var TypeError$7 = global$c.TypeError; + + // `OrdinaryToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-ordinarytoprimitive + var ordinaryToPrimitive$1 = function (input, pref) { + var fn, val; + if (pref === 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = call$1(fn, input))) return val; + if (isCallable$8(fn = input.valueOf) && !isObject$4(val = call$1(fn, input))) return val; + if (pref !== 'string' && isCallable$8(fn = input.toString) && !isObject$4(val = call$1(fn, input))) return val; + throw TypeError$7("Can't convert object to primitive value"); + }; + + var global$b = global$q; + var call = functionCall; + var isObject$3 = isObject$7; + var isSymbol$1 = isSymbol$2; + var getMethod = getMethod$1; + var ordinaryToPrimitive = ordinaryToPrimitive$1; + var wellKnownSymbol$3 = wellKnownSymbol$6; + + var TypeError$6 = global$b.TypeError; + var TO_PRIMITIVE = wellKnownSymbol$3('toPrimitive'); + + // `ToPrimitive` abstract operation + // https://tc39.es/ecma262/#sec-toprimitive + var toPrimitive$1 = function (input, pref) { + if (!isObject$3(input) || isSymbol$1(input)) return input; + var exoticToPrim = getMethod(input, TO_PRIMITIVE); + var result; + if (exoticToPrim) { + if (pref === undefined) pref = 'default'; + result = call(exoticToPrim, input, pref); + if (!isObject$3(result) || isSymbol$1(result)) return result; + throw TypeError$6("Can't convert object to primitive value"); + } + if (pref === undefined) pref = 'number'; + return ordinaryToPrimitive(input, pref); + }; + + var toPrimitive = toPrimitive$1; + var isSymbol = isSymbol$2; + + // `ToPropertyKey` abstract operation + // https://tc39.es/ecma262/#sec-topropertykey + var toPropertyKey$1 = function (argument) { + var key = toPrimitive(argument, 'string'); + return isSymbol(key) ? key : key + ''; + }; + + var global$a = global$q; + var DESCRIPTORS$4 = descriptors; + var IE8_DOM_DEFINE = ie8DomDefine; + var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; + var anObject$2 = anObject$3; + var toPropertyKey = toPropertyKey$1; + + var TypeError$5 = global$a.TypeError; + // eslint-disable-next-line es-x/no-object-defineproperty -- safe + var $defineProperty = Object.defineProperty; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var ENUMERABLE = 'enumerable'; + var CONFIGURABLE$1 = 'configurable'; + var WRITABLE = 'writable'; + + // `Object.defineProperty` method + // https://tc39.es/ecma262/#sec-object.defineproperty + objectDefineProperty.f = DESCRIPTORS$4 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { + anObject$2(O); + P = toPropertyKey(P); + anObject$2(Attributes); + if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { + var current = $getOwnPropertyDescriptor(O, P); + if (current && current[WRITABLE]) { + O[P] = Attributes.value; + Attributes = { + configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1], + enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], + writable: false + }; + } + } return $defineProperty(O, P, Attributes); + } : $defineProperty : function defineProperty(O, P, Attributes) { + anObject$2(O); + P = toPropertyKey(P); + anObject$2(Attributes); + if (IE8_DOM_DEFINE) try { + return $defineProperty(O, P, Attributes); + } catch (error) { /* empty */ } + if ('get' in Attributes || 'set' in Attributes) throw TypeError$5('Accessors not supported'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; + }; + + var createPropertyDescriptor$1 = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; + }; + + var DESCRIPTORS$3 = descriptors; + var definePropertyModule = objectDefineProperty; + var createPropertyDescriptor = createPropertyDescriptor$1; + + var createNonEnumerableProperty$3 = DESCRIPTORS$3 ? function (object, key, value) { + return definePropertyModule.f(object, key, createPropertyDescriptor(1, value)); + } : function (object, key, value) { + object[key] = value; + return object; + }; + + var makeBuiltIn$2 = {exports: {}}; + + var DESCRIPTORS$2 = descriptors; + var hasOwn$4 = hasOwnProperty_1; + + var FunctionPrototype$1 = Function.prototype; + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + var getDescriptor = DESCRIPTORS$2 && Object.getOwnPropertyDescriptor; + + var EXISTS = hasOwn$4(FunctionPrototype$1, 'name'); + // additional protection from minified / mangled / dropped function names + var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; + var CONFIGURABLE = EXISTS && (!DESCRIPTORS$2 || (DESCRIPTORS$2 && getDescriptor(FunctionPrototype$1, 'name').configurable)); + + var functionName = { + EXISTS: EXISTS, + PROPER: PROPER, + CONFIGURABLE: CONFIGURABLE + }; + + var uncurryThis$7 = functionUncurryThis; + var isCallable$7 = isCallable$e; + var store$1 = sharedStore; + + var functionToString$1 = uncurryThis$7(Function.toString); + + // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper + if (!isCallable$7(store$1.inspectSource)) { + store$1.inspectSource = function (it) { + return functionToString$1(it); + }; + } + + var inspectSource$3 = store$1.inspectSource; + + var global$9 = global$q; + var isCallable$6 = isCallable$e; + var inspectSource$2 = inspectSource$3; + + var WeakMap$1 = global$9.WeakMap; + + var nativeWeakMap = isCallable$6(WeakMap$1) && /native code/.test(inspectSource$2(WeakMap$1)); + + var shared$1 = shared$3.exports; + var uid$1 = uid$3; + + var keys = shared$1('keys'); + + var sharedKey$2 = function (key) { + return keys[key] || (keys[key] = uid$1(key)); + }; + + var hiddenKeys$1 = {}; + + var NATIVE_WEAK_MAP = nativeWeakMap; + var global$8 = global$q; + var uncurryThis$6 = functionUncurryThis; + var isObject$2 = isObject$7; + var createNonEnumerableProperty$2 = createNonEnumerableProperty$3; + var hasOwn$3 = hasOwnProperty_1; + var shared = sharedStore; + var sharedKey$1 = sharedKey$2; + var hiddenKeys = hiddenKeys$1; + + var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; + var TypeError$4 = global$8.TypeError; + var WeakMap = global$8.WeakMap; + var set, get, has; + + var enforce = function (it) { + return has(it) ? get(it) : set(it, {}); + }; + + var getterFor = function (TYPE) { + return function (it) { + var state; + if (!isObject$2(it) || (state = get(it)).type !== TYPE) { + throw TypeError$4('Incompatible receiver, ' + TYPE + ' required'); + } return state; + }; + }; + + if (NATIVE_WEAK_MAP || shared.state) { + var store = shared.state || (shared.state = new WeakMap()); + var wmget = uncurryThis$6(store.get); + var wmhas = uncurryThis$6(store.has); + var wmset = uncurryThis$6(store.set); + set = function (it, metadata) { + if (wmhas(store, it)) throw new TypeError$4(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + wmset(store, it, metadata); + return metadata; + }; + get = function (it) { + return wmget(store, it) || {}; + }; + has = function (it) { + return wmhas(store, it); + }; + } else { + var STATE = sharedKey$1('state'); + hiddenKeys[STATE] = true; + set = function (it, metadata) { + if (hasOwn$3(it, STATE)) throw new TypeError$4(OBJECT_ALREADY_INITIALIZED); + metadata.facade = it; + createNonEnumerableProperty$2(it, STATE, metadata); + return metadata; + }; + get = function (it) { + return hasOwn$3(it, STATE) ? it[STATE] : {}; + }; + has = function (it) { + return hasOwn$3(it, STATE); + }; + } + + var internalState = { + set: set, + get: get, + has: has, + enforce: enforce, + getterFor: getterFor + }; + + var fails$3 = fails$9; + var isCallable$5 = isCallable$e; + var hasOwn$2 = hasOwnProperty_1; + var defineProperty$2 = objectDefineProperty.f; + var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE; + var inspectSource$1 = inspectSource$3; + var InternalStateModule = internalState; + + var enforceInternalState = InternalStateModule.enforce; + var getInternalState = InternalStateModule.get; + + var CONFIGURABLE_LENGTH = !fails$3(function () { + return defineProperty$2(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; + }); + + var TEMPLATE = String(String).split('String'); + + var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) { + if (String(name).slice(0, 7) === 'Symbol(') { + name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']'; + } + if (options && options.getter) name = 'get ' + name; + if (options && options.setter) name = 'set ' + name; + if (!hasOwn$2(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { + defineProperty$2(value, 'name', { value: name, configurable: true }); + } + if (CONFIGURABLE_LENGTH && options && hasOwn$2(options, 'arity') && value.length !== options.arity) { + defineProperty$2(value, 'length', { value: options.arity }); + } + var state = enforceInternalState(value); + if (!hasOwn$2(state, 'source')) { + state.source = TEMPLATE.join(typeof name == 'string' ? name : ''); + } return value; + }; + + // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative + // eslint-disable-next-line no-extend-native -- required + Function.prototype.toString = makeBuiltIn$1(function toString() { + return isCallable$5(this) && getInternalState(this).source || inspectSource$1(this); + }, 'toString'); + + var global$7 = global$q; + var isCallable$4 = isCallable$e; + var createNonEnumerableProperty$1 = createNonEnumerableProperty$3; + var makeBuiltIn = makeBuiltIn$2.exports; + var setGlobal = setGlobal$2; + + var defineBuiltIn$1 = function (O, key, value, options) { + var unsafe = options ? !!options.unsafe : false; + var simple = options ? !!options.enumerable : false; + var noTargetGet = options ? !!options.noTargetGet : false; + var name = options && options.name !== undefined ? options.name : key; + if (isCallable$4(value)) makeBuiltIn(value, name, options); + if (O === global$7) { + if (simple) O[key] = value; + else setGlobal(key, value); + return O; + } else if (!unsafe) { + delete O[key]; + } else if (!noTargetGet && O[key]) { + simple = true; + } + if (simple) O[key] = value; + else createNonEnumerableProperty$1(O, key, value); + return O; + }; + + var fails$2 = fails$9; + + var correctPrototypeGetter = !fails$2(function () { + function F() { /* empty */ } + F.prototype.constructor = null; + // eslint-disable-next-line es-x/no-object-getprototypeof -- required for testing + return Object.getPrototypeOf(new F()) !== F.prototype; + }); + + var global$6 = global$q; + var hasOwn$1 = hasOwnProperty_1; + var isCallable$3 = isCallable$e; + var toObject$1 = toObject$3; + var sharedKey = sharedKey$2; + var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter; + + var IE_PROTO = sharedKey('IE_PROTO'); + var Object$2 = global$6.Object; + var ObjectPrototype$1 = Object$2.prototype; + + // `Object.getPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.getprototypeof + var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? Object$2.getPrototypeOf : function (O) { + var object = toObject$1(O); + if (hasOwn$1(object, IE_PROTO)) return object[IE_PROTO]; + var constructor = object.constructor; + if (isCallable$3(constructor) && object instanceof constructor) { + return constructor.prototype; + } return object instanceof Object$2 ? ObjectPrototype$1 : null; + }; + + var global$5 = global$q; + var isCallable$2 = isCallable$e; + + var String$1 = global$5.String; + var TypeError$3 = global$5.TypeError; + + var aPossiblePrototype$1 = function (argument) { + if (typeof argument == 'object' || isCallable$2(argument)) return argument; + throw TypeError$3("Can't set " + String$1(argument) + ' as a prototype'); + }; + + /* eslint-disable no-proto -- safe */ + + var uncurryThis$5 = functionUncurryThis; + var anObject$1 = anObject$3; + var aPossiblePrototype = aPossiblePrototype$1; + + // `Object.setPrototypeOf` method + // https://tc39.es/ecma262/#sec-object.setprototypeof + // Works with __proto__ only. Old v8 can't work with null proto objects. + // eslint-disable-next-line es-x/no-object-setprototypeof -- safe + var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe + setter = uncurryThis$5(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); + setter(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { /* empty */ } + return function setPrototypeOf(O, proto) { + anObject$1(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) setter(O, proto); + else O.__proto__ = proto; + return O; + }; + }() : undefined); + + var NATIVE_ARRAY_BUFFER = arrayBufferNative; + var DESCRIPTORS$1 = descriptors; + var global$4 = global$q; + var isCallable$1 = isCallable$e; + var isObject$1 = isObject$7; + var hasOwn = hasOwnProperty_1; + var classof$3 = classof$4; + var tryToString$1 = tryToString$3; + var createNonEnumerableProperty = createNonEnumerableProperty$3; + var defineBuiltIn = defineBuiltIn$1; + var defineProperty$1 = objectDefineProperty.f; + var isPrototypeOf = objectIsPrototypeOf; + var getPrototypeOf = objectGetPrototypeOf; + var setPrototypeOf = objectSetPrototypeOf; + var wellKnownSymbol$2 = wellKnownSymbol$6; + var uid = uid$3; + + var Int8Array = global$4.Int8Array; + var Int8ArrayPrototype = Int8Array && Int8Array.prototype; + var Uint8ClampedArray = global$4.Uint8ClampedArray; + var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype; + var TypedArray = Int8Array && getPrototypeOf(Int8Array); + var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype); + var ObjectPrototype = Object.prototype; + var TypeError$2 = global$4.TypeError; + + var TO_STRING_TAG = wellKnownSymbol$2('toStringTag'); + var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG'); + var TYPED_ARRAY_CONSTRUCTOR$1 = uid('TYPED_ARRAY_CONSTRUCTOR'); + // Fixing native typed arrays in Opera Presto crashes the browser, see #595 + var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof$3(global$4.opera) !== 'Opera'; + var TYPED_ARRAY_TAG_REQUIRED = false; + var NAME$1, Constructor, Prototype; + + var TypedArrayConstructorsList = { + Int8Array: 1, + Uint8Array: 1, + Uint8ClampedArray: 1, + Int16Array: 2, + Uint16Array: 2, + Int32Array: 4, + Uint32Array: 4, + Float32Array: 4, + Float64Array: 8 + }; + + var BigIntArrayConstructorsList = { + BigInt64Array: 8, + BigUint64Array: 8 + }; + + var isView = function isView(it) { + if (!isObject$1(it)) return false; + var klass = classof$3(it); + return klass === 'DataView' + || hasOwn(TypedArrayConstructorsList, klass) + || hasOwn(BigIntArrayConstructorsList, klass); + }; + + var isTypedArray = function (it) { + if (!isObject$1(it)) return false; + var klass = classof$3(it); + return hasOwn(TypedArrayConstructorsList, klass) + || hasOwn(BigIntArrayConstructorsList, klass); + }; + + var aTypedArray$1 = function (it) { + if (isTypedArray(it)) return it; + throw TypeError$2('Target is not a typed array'); + }; + + var aTypedArrayConstructor$1 = function (C) { + if (isCallable$1(C) && (!setPrototypeOf || isPrototypeOf(TypedArray, C))) return C; + throw TypeError$2(tryToString$1(C) + ' is not a typed array constructor'); + }; + + var exportTypedArrayMethod$1 = function (KEY, property, forced, options) { + if (!DESCRIPTORS$1) return; + if (forced) for (var ARRAY in TypedArrayConstructorsList) { + var TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try { + delete TypedArrayConstructor.prototype[KEY]; + } catch (error) { + // old WebKit bug - some methods are non-configurable + try { + TypedArrayConstructor.prototype[KEY] = property; + } catch (error2) { /* empty */ } + } + } + if (!TypedArrayPrototype[KEY] || forced) { + defineBuiltIn(TypedArrayPrototype, KEY, forced ? property + : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property, options); + } + }; + + var exportTypedArrayStaticMethod = function (KEY, property, forced) { + var ARRAY, TypedArrayConstructor; + if (!DESCRIPTORS$1) return; + if (setPrototypeOf) { + if (forced) for (ARRAY in TypedArrayConstructorsList) { + TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && hasOwn(TypedArrayConstructor, KEY)) try { + delete TypedArrayConstructor[KEY]; + } catch (error) { /* empty */ } + } + if (!TypedArray[KEY] || forced) { + // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable + try { + return defineBuiltIn(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && TypedArray[KEY] || property); + } catch (error) { /* empty */ } + } else return; + } + for (ARRAY in TypedArrayConstructorsList) { + TypedArrayConstructor = global$4[ARRAY]; + if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) { + defineBuiltIn(TypedArrayConstructor, KEY, property); + } + } + }; + + for (NAME$1 in TypedArrayConstructorsList) { + Constructor = global$4[NAME$1]; + Prototype = Constructor && Constructor.prototype; + if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); + else NATIVE_ARRAY_BUFFER_VIEWS = false; + } + + for (NAME$1 in BigIntArrayConstructorsList) { + Constructor = global$4[NAME$1]; + Prototype = Constructor && Constructor.prototype; + if (Prototype) createNonEnumerableProperty(Prototype, TYPED_ARRAY_CONSTRUCTOR$1, Constructor); + } + + // WebKit bug - typed arrays constructors prototype is Object.prototype + if (!NATIVE_ARRAY_BUFFER_VIEWS || !isCallable$1(TypedArray) || TypedArray === Function.prototype) { + // eslint-disable-next-line no-shadow -- safe + TypedArray = function TypedArray() { + throw TypeError$2('Incorrect invocation'); + }; + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$4[NAME$1]) setPrototypeOf(global$4[NAME$1], TypedArray); + } + } + + if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) { + TypedArrayPrototype = TypedArray.prototype; + if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME$1 in TypedArrayConstructorsList) { + if (global$4[NAME$1]) setPrototypeOf(global$4[NAME$1].prototype, TypedArrayPrototype); + } + } + + // WebKit bug - one more object in Uint8ClampedArray prototype chain + if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) { + setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype); + } + + if (DESCRIPTORS$1 && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) { + TYPED_ARRAY_TAG_REQUIRED = true; + defineProperty$1(TypedArrayPrototype, TO_STRING_TAG, { get: function () { + return isObject$1(this) ? this[TYPED_ARRAY_TAG] : undefined; + } }); + for (NAME$1 in TypedArrayConstructorsList) if (global$4[NAME$1]) { + createNonEnumerableProperty(global$4[NAME$1], TYPED_ARRAY_TAG, NAME$1); + } + } + + var arrayBufferViewCore = { + NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS, + TYPED_ARRAY_CONSTRUCTOR: TYPED_ARRAY_CONSTRUCTOR$1, + TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQUIRED && TYPED_ARRAY_TAG, + aTypedArray: aTypedArray$1, + aTypedArrayConstructor: aTypedArrayConstructor$1, + exportTypedArrayMethod: exportTypedArrayMethod$1, + exportTypedArrayStaticMethod: exportTypedArrayStaticMethod, + isView: isView, + isTypedArray: isTypedArray, + TypedArray: TypedArray, + TypedArrayPrototype: TypedArrayPrototype + }; + + var uncurryThis$4 = functionUncurryThis; + var aCallable = aCallable$2; + var NATIVE_BIND = functionBindNative; + + var bind$1 = uncurryThis$4(uncurryThis$4.bind); + + // optional / simple context binding + var functionBindContext = function (fn, that) { + aCallable(fn); + return that === undefined ? fn : NATIVE_BIND ? bind$1(fn, that) : function (/* ...args */) { + return fn.apply(that, arguments); + }; + }; + + var global$3 = global$q; + var uncurryThis$3 = functionUncurryThis; + var fails$1 = fails$9; + var classof$2 = classofRaw$1; + + var Object$1 = global$3.Object; + var split = uncurryThis$3(''.split); + + // fallback for non-array-like ES3 and non-enumerable old V8 strings + var indexedObject = fails$1(function () { + // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 + // eslint-disable-next-line no-prototype-builtins -- safe + return !Object$1('z').propertyIsEnumerable(0); + }) ? function (it) { + return classof$2(it) == 'String' ? split(it, '') : Object$1(it); + } : Object$1; + + var ceil = Math.ceil; + var floor = Math.floor; + + // `ToIntegerOrInfinity` abstract operation + // https://tc39.es/ecma262/#sec-tointegerorinfinity + var toIntegerOrInfinity$1 = function (argument) { + var number = +argument; + // eslint-disable-next-line no-self-compare -- safe + return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil)(number); + }; + + var toIntegerOrInfinity = toIntegerOrInfinity$1; + + var min = Math.min; + + // `ToLength` abstract operation + // https://tc39.es/ecma262/#sec-tolength + var toLength$1 = function (argument) { + return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 + }; + + var toLength = toLength$1; + + // `LengthOfArrayLike` abstract operation + // https://tc39.es/ecma262/#sec-lengthofarraylike + var lengthOfArrayLike$1 = function (obj) { + return toLength(obj.length); + }; + + var classof$1 = classofRaw$1; + + // `IsArray` abstract operation + // https://tc39.es/ecma262/#sec-isarray + // eslint-disable-next-line es-x/no-array-isarray -- safe + var isArray$1 = Array.isArray || function isArray(argument) { + return classof$1(argument) == 'Array'; + }; + + var uncurryThis$2 = functionUncurryThis; + var fails = fails$9; + var isCallable = isCallable$e; + var classof = classof$4; + var getBuiltIn = getBuiltIn$3; + var inspectSource = inspectSource$3; + + var noop = function () { /* empty */ }; + var empty = []; + var construct = getBuiltIn('Reflect', 'construct'); + var constructorRegExp = /^\s*(?:class|function)\b/; + var exec = uncurryThis$2(constructorRegExp.exec); + var INCORRECT_TO_STRING = !constructorRegExp.exec(noop); + + var isConstructorModern = function isConstructor(argument) { + if (!isCallable(argument)) return false; + try { + construct(noop, empty, argument); + return true; + } catch (error) { + return false; + } + }; + + var isConstructorLegacy = function isConstructor(argument) { + if (!isCallable(argument)) return false; + switch (classof(argument)) { + case 'AsyncFunction': + case 'GeneratorFunction': + case 'AsyncGeneratorFunction': return false; + } + try { + // we can't check .prototype since constructors produced by .bind haven't it + // `Function#toString` throws on some built-it function in some legacy engines + // (for example, `DOMQuad` and similar in FF41-) + return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource(argument)); + } catch (error) { + return true; + } + }; + + isConstructorLegacy.sham = true; + + // `IsConstructor` abstract operation + // https://tc39.es/ecma262/#sec-isconstructor + var isConstructor$2 = !construct || fails(function () { + var called; + return isConstructorModern(isConstructorModern.call) + || !isConstructorModern(Object) + || !isConstructorModern(function () { called = true; }) + || called; + }) ? isConstructorLegacy : isConstructorModern; + + var global$2 = global$q; + var isArray = isArray$1; + var isConstructor$1 = isConstructor$2; + var isObject = isObject$7; + var wellKnownSymbol$1 = wellKnownSymbol$6; + + var SPECIES$1 = wellKnownSymbol$1('species'); + var Array$1 = global$2.Array; + + // a part of `ArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#sec-arrayspeciescreate + var arraySpeciesConstructor$1 = function (originalArray) { + var C; + if (isArray(originalArray)) { + C = originalArray.constructor; + // cross-realm fallback + if (isConstructor$1(C) && (C === Array$1 || isArray(C.prototype))) C = undefined; + else if (isObject(C)) { + C = C[SPECIES$1]; + if (C === null) C = undefined; + } + } return C === undefined ? Array$1 : C; + }; + + var arraySpeciesConstructor = arraySpeciesConstructor$1; + + // `ArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#sec-arrayspeciescreate + var arraySpeciesCreate$1 = function (originalArray, length) { + return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length); + }; + + var bind = functionBindContext; + var uncurryThis$1 = functionUncurryThis; + var IndexedObject = indexedObject; + var toObject = toObject$3; + var lengthOfArrayLike = lengthOfArrayLike$1; + var arraySpeciesCreate = arraySpeciesCreate$1; + + var push = uncurryThis$1([].push); + + // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation + var createMethod = function (TYPE) { + var IS_MAP = TYPE == 1; + var IS_FILTER = TYPE == 2; + var IS_SOME = TYPE == 3; + var IS_EVERY = TYPE == 4; + var IS_FIND_INDEX = TYPE == 6; + var IS_FILTER_REJECT = TYPE == 7; + var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; + return function ($this, callbackfn, that, specificCreate) { + var O = toObject($this); + var self = IndexedObject(O); + var boundFunction = bind(callbackfn, that); + var length = lengthOfArrayLike(self); + var index = 0; + var create = specificCreate || arraySpeciesCreate; + var target = IS_MAP ? create($this, length) : IS_FILTER || IS_FILTER_REJECT ? create($this, 0) : undefined; + var value, result; + for (;length > index; index++) if (NO_HOLES || index in self) { + value = self[index]; + result = boundFunction(value, index, O); + if (TYPE) { + if (IS_MAP) target[index] = result; // map + else if (result) switch (TYPE) { + case 3: return true; // some + case 5: return value; // find + case 6: return index; // findIndex + case 2: push(target, value); // filter + } else switch (TYPE) { + case 4: return false; // every + case 7: push(target, value); // filterReject + } + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target; + }; + }; + + var arrayIteration = { + // `Array.prototype.forEach` method + // https://tc39.es/ecma262/#sec-array.prototype.foreach + forEach: createMethod(0), + // `Array.prototype.map` method + // https://tc39.es/ecma262/#sec-array.prototype.map + map: createMethod(1), + // `Array.prototype.filter` method + // https://tc39.es/ecma262/#sec-array.prototype.filter + filter: createMethod(2), + // `Array.prototype.some` method + // https://tc39.es/ecma262/#sec-array.prototype.some + some: createMethod(3), + // `Array.prototype.every` method + // https://tc39.es/ecma262/#sec-array.prototype.every + every: createMethod(4), + // `Array.prototype.find` method + // https://tc39.es/ecma262/#sec-array.prototype.find + find: createMethod(5), + // `Array.prototype.findIndex` method + // https://tc39.es/ecma262/#sec-array.prototype.findIndex + findIndex: createMethod(6), + // `Array.prototype.filterReject` method + // https://github.com/tc39/proposal-array-filtering + filterReject: createMethod(7) + }; + + var global$1 = global$q; + var isConstructor = isConstructor$2; + var tryToString = tryToString$3; + + var TypeError$1 = global$1.TypeError; + + // `Assert: IsConstructor(argument) is true` + var aConstructor$1 = function (argument) { + if (isConstructor(argument)) return argument; + throw TypeError$1(tryToString(argument) + ' is not a constructor'); + }; + + var anObject = anObject$3; + var aConstructor = aConstructor$1; + var wellKnownSymbol = wellKnownSymbol$6; + + var SPECIES = wellKnownSymbol('species'); + + // `SpeciesConstructor` abstract operation + // https://tc39.es/ecma262/#sec-speciesconstructor + var speciesConstructor$1 = function (O, defaultConstructor) { + var C = anObject(O).constructor; + var S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? defaultConstructor : aConstructor(S); + }; + + var ArrayBufferViewCore$1 = arrayBufferViewCore; + var speciesConstructor = speciesConstructor$1; + + var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore$1.TYPED_ARRAY_CONSTRUCTOR; + var aTypedArrayConstructor = ArrayBufferViewCore$1.aTypedArrayConstructor; + + // a part of `TypedArraySpeciesCreate` abstract operation + // https://tc39.es/ecma262/#typedarray-species-create + var typedArraySpeciesConstructor$1 = function (originalArray) { + return aTypedArrayConstructor(speciesConstructor(originalArray, originalArray[TYPED_ARRAY_CONSTRUCTOR])); + }; + + var ArrayBufferViewCore = arrayBufferViewCore; + var $map = arrayIteration.map; + var typedArraySpeciesConstructor = typedArraySpeciesConstructor$1; + + var aTypedArray = ArrayBufferViewCore.aTypedArray; + var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; + + // `%TypedArray%.prototype.map` method + // https://tc39.es/ecma262/#sec-%typedarray%.prototype.map + exportTypedArrayMethod('map', function map(mapfn /* , thisArg */) { + return $map(aTypedArray(this), mapfn, arguments.length > 1 ? arguments[1] : undefined, function (O, length) { + return new (typedArraySpeciesConstructor(O))(length); + }); + }); + + var DESCRIPTORS = descriptors; + var FUNCTION_NAME_EXISTS = functionName.EXISTS; + var uncurryThis = functionUncurryThis; + var defineProperty = objectDefineProperty.f; + + var FunctionPrototype = Function.prototype; + var functionToString = uncurryThis(FunctionPrototype.toString); + var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/; + var regExpExec = uncurryThis(nameRE.exec); + var NAME = 'name'; + + // Function instances `.name` property + // https://tc39.es/ecma262/#sec-function-instances-name + if (DESCRIPTORS && !FUNCTION_NAME_EXISTS) { + defineProperty(FunctionPrototype, NAME, { + configurable: true, + get: function () { + try { + return regExpExec(nameRE, functionToString(this))[1]; + } catch (error) { + return ''; + } + } + }); + } + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } else if (call !== void 0) { + throw new TypeError("Derived constructors may only return object or undefined"); + } + + return _assertThisInitialized(self); + } + + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; + } + + var BaseReader = function () { + function BaseReader() { + _classCallCheck(this, BaseReader); + } + + _createClass(BaseReader, [{ + key: "isValueType", + value: function isValueType() { + return true; + } + }, { + key: "type", + get: function get() { + return this.constructor.type(); + } + }, { + key: "read", + value: function read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + }, { + key: "writeIndex", + value: function writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(parseInt(resolver.getIndex(this)) + 1); + } + }, { + key: "toString", + value: function toString() { + return this.type; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + return false; + } + }, { + key: "hasSubType", + value: function hasSubType() { + return false; + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type()].concat(subtype); + } + }, { + key: "type", + value: function type() { + return this.name.slice(0, -6); + } + }]); + + return BaseReader; + }(); + + var UInt32Reader = function (_BaseReader) { + _inherits(UInt32Reader, _BaseReader); + + var _super = _createSuper(UInt32Reader); + + function UInt32Reader() { + _classCallCheck(this, UInt32Reader); + + return _super.apply(this, arguments); + } + + _createClass(UInt32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readUInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + }]); + + return UInt32Reader; + }(BaseReader); + + var ArrayReader = function (_BaseReader) { + _inherits(ArrayReader, _BaseReader); + + var _super = _createSuper(ArrayReader); + + function ArrayReader(reader) { + var _this; + + _classCallCheck(this, ArrayReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ArrayReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var array = []; + + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (var i = 0; i < content.length; i++) { + this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Array<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ArrayReader; + }(BaseReader); + + function __arrayMaker(obj, func) { + if (!obj || _typeof(obj) !== "object") throw new Error("Invalid Data!"); + var result = []; + var length = obj.length; + + for (var i = 0; i < length; i++) { + result[i] = func(obj[i], i); + } + + return result; + } + + function __trunc(number) { + if (number < 0) return Math.ceil(number); + return Math.floor(number); + } + + Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { + var mappedPromises = promises.map(function (p) { + return p.then(function (value) { + return { + status: 'fulfilled', + value: value + }; + }).catch(function (reason) { + return { + status: 'rejected', + reason: reason + }; + }); + }); + return Promise.all(mappedPromises); + }; + + var UTF16_BITES = [0xD800, 0xDC00]; + var UTF16_MASK = 1023; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + var codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + var utf16Map = __arrayMaker({ + length: str.length + }, function (_, i) { + return str.charCodeAt(i); + }); + + var result = []; + var index = 0; + + while (index < str.length) { + var code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + var codes = stringToUnicode(str); + return codes.reduce(function (sum, unicode) { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + var StringReader = function (_BaseReader) { + _inherits(StringReader, _BaseReader); + + var _super = _createSuper(StringReader); + + function StringReader() { + _classCallCheck(this, StringReader); + + return _super.apply(this, arguments); + } + + _createClass(StringReader, [{ + key: "read", + value: function read(buffer) { + var length = buffer.read7BitNumber(); + return buffer.readString(length); + } + }, { + key: "write", + value: function write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + var size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + }]); + + return StringReader; + }(BaseReader); + + var BmFontReader = function (_BaseReader) { + _inherits(BmFontReader, _BaseReader); + + var _super = _createSuper(BmFontReader); + + function BmFontReader() { + _classCallCheck(this, BmFontReader); + + return _super.apply(this, arguments); + } + + _createClass(BmFontReader, [{ + key: "read", + value: function read(buffer) { + var stringReader = new StringReader(); + var xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + }]); + + return BmFontReader; + }(BaseReader); + + var BooleanReader = function (_BaseReader) { + _inherits(BooleanReader, _BaseReader); + + var _super = _createSuper(BooleanReader); + + function BooleanReader() { + _classCallCheck(this, BooleanReader); + + return _super.apply(this, arguments); + } + + _createClass(BooleanReader, [{ + key: "read", + value: function read(buffer) { + return Boolean(buffer.readInt()); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + }]); + + return BooleanReader; + }(BaseReader); + + var CharReader = function (_BaseReader) { + _inherits(CharReader, _BaseReader); + + var _super = _createSuper(CharReader); + + function CharReader() { + _classCallCheck(this, CharReader); + + return _super.apply(this, arguments); + } + + _createClass(CharReader, [{ + key: "read", + value: function read(buffer) { + var charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + }, { + key: "_getCharSize", + value: function _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + }]); + + return CharReader; + }(BaseReader); + + var DictionaryReader = function (_BaseReader) { + _inherits(DictionaryReader, _BaseReader); + + var _super = _createSuper(DictionaryReader); + + function DictionaryReader(key, value) { + var _this; + + _classCallCheck(this, DictionaryReader); + + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + _this = _super.call(this); + _this.key = key; + _this.value = value; + return _this; + } + + _createClass(DictionaryReader, [{ + key: "read", + value: function read(buffer, resolver) { + var dictionary = {}; + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + + for (var i = 0; i < size; i++) { + var key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + var value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (var _i2 = 0, _Object$keys2 = Object.keys(content); _i2 < _Object$keys2.length; _i2++) { + var key = _Object$keys2[_i2]; + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return DictionaryReader; + }(BaseReader); + + var DoubleReader = function (_BaseReader) { + _inherits(DoubleReader, _BaseReader); + + var _super = _createSuper(DoubleReader); + + function DoubleReader() { + _classCallCheck(this, DoubleReader); + + return _super.apply(this, arguments); + } + + _createClass(DoubleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readDouble(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + }]); + + return DoubleReader; + }(BaseReader); + + var EffectReader = function (_BaseReader) { + _inherits(EffectReader, _BaseReader); + + var _super = _createSuper(EffectReader); + + function EffectReader() { + _classCallCheck(this, EffectReader); + + return _super.apply(this, arguments); + } + + _createClass(EffectReader, [{ + key: "read", + value: function read(buffer) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + }]); + + return EffectReader; + }(BaseReader); + + var Int32Reader = function (_BaseReader) { + _inherits(Int32Reader, _BaseReader); + + var _super = _createSuper(Int32Reader); + + function Int32Reader() { + _classCallCheck(this, Int32Reader); + + return _super.apply(this, arguments); + } + + _createClass(Int32Reader, [{ + key: "read", + value: function read(buffer) { + return buffer.readInt32(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + }]); + + return Int32Reader; + }(BaseReader); + + var ListReader = function (_BaseReader) { + _inherits(ListReader, _BaseReader); + + var _super = _createSuper(ListReader); + + function ListReader(reader) { + var _this; + + _classCallCheck(this, ListReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ListReader, [{ + key: "read", + value: function read(buffer, resolver) { + var uint32Reader = new UInt32Reader(); + var size = uint32Reader.read(buffer); + var list = []; + + for (var i = 0; i < size; i++) { + var value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + var __keys = Object.keys(content); + + for (var __i = 0; __i < __keys.length; __i++) { + var __key = __keys[__i], + data = content[__key]; + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "List<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ListReader; + }(BaseReader); + + var NullableReader = function (_BaseReader) { + _inherits(NullableReader, _BaseReader); + + var _super = _createSuper(NullableReader); + + function NullableReader(reader) { + var _this; + + _classCallCheck(this, NullableReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(NullableReader, [{ + key: "read", + value: function read(buffer) { + var resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var booleanReader = new BooleanReader(); + var hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } + }, { + key: "write", + value: function write(buffer) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + new BooleanReader(); + + if (content !== null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Nullable<".concat(this.reader.type, ">"); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return NullableReader; + }(BaseReader); + + var ReflectiveReader = function (_BaseReader) { + _inherits(ReflectiveReader, _BaseReader); + + var _super = _createSuper(ReflectiveReader); + + function ReflectiveReader(reader) { + var _this; + + _classCallCheck(this, ReflectiveReader); + + _this = _super.call(this); + _this.reader = reader; + return _this; + } + + _createClass(ReflectiveReader, [{ + key: "read", + value: function read(buffer, resolver) { + var reflective = this.reader.read(buffer, resolver); + return reflective; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "".concat(this.reader.type); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + }, { + key: "hasSubType", + value: function hasSubType() { + return true; + } + }]); + + return ReflectiveReader; + }(BaseReader); + + var RectangleReader = function (_BaseReader) { + _inherits(RectangleReader, _BaseReader); + + var _super = _createSuper(RectangleReader); + + function RectangleReader() { + _classCallCheck(this, RectangleReader); + + return _super.apply(this, arguments); + } + + _createClass(RectangleReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var x = int32Reader.read(buffer); + var y = int32Reader.read(buffer); + var width = int32Reader.read(buffer); + var height = int32Reader.read(buffer); + return { + x: x, + y: y, + width: width, + height: height + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + }]); + + return RectangleReader; + }(BaseReader); + + var SingleReader = function (_BaseReader) { + _inherits(SingleReader, _BaseReader); + + var _super = _createSuper(SingleReader); + + function SingleReader() { + _classCallCheck(this, SingleReader); + + return _super.apply(this, arguments); + } + + _createClass(SingleReader, [{ + key: "read", + value: function read(buffer) { + return buffer.readSingle(); + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + }]); + + return SingleReader; + }(BaseReader); + + var kDxt1 = 1 << 0; + var kDxt3 = 1 << 1; + var kDxt5 = 1 << 2; + var kColourIterativeClusterFit = 1 << 8; + var kColourClusterFit = 1 << 3; + var kColourRangeFit = 1 << 4; + var kColourMetricPerceptual = 1 << 5; + var kColourMetricUniform = 1 << 6; + var kWeightColourByAlpha = 1 << 7; + + function Rot(theta) { + var Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } + + function Rij(k, l, theta, N) { + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i = 0; _i < N; _i++) { + for (var j = 0; j < N; j++) { + Mat[_i][j] = (_i === j) * 1.0; + } + } + + var Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } + + function getTheta(aii, ajj, aij) { + var th = 0.0; + var denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; + } + + function getAij(Mij) { + var N = Mij.length; + var maxMij = 0.0; + var maxIJ = [0, 1]; + + for (var i = 0; i < N; i++) { + for (var j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; + } + + function unitary(U, H) { + var N = U.length; + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i2 = 0; _i2 < N; _i2++) { + for (var j = 0; j < N; j++) { + Mat[_i2][j] = 0; + + for (var k = 0; k < N; k++) { + for (var l = 0; l < N; l++) { + Mat[_i2][j] = Mat[_i2][j] + U[k][_i2] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; + } + + function AxB(A, B) { + var N = A.length; + var Mat = Array(N); + + for (var i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (var _i3 = 0; _i3 < N; _i3++) { + for (var j = 0; j < N; j++) { + Mat[_i3][j] = 0; + + for (var k = 0; k < N; k++) { + Mat[_i3][j] = Mat[_i3][j] + A[_i3][k] * B[k][j]; + } + } + } + + return Mat; + } + + function eigens(Hij) { + var convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + var N = Hij.length; + var Ei = Array(N); + var e0 = Math.abs(convergence / N); + var Sij = Array(N); + + for (var i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (var _i4 = 0; _i4 < N; _i4++) { + for (var j = 0; j < N; j++) { + Sij[_i4][j] = (_i4 === j) * 1.0; + } + } + + var Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + var _i5 = Vab[0][0]; + var _j = Vab[0][1]; + var psi = getTheta(Hij[_i5][_i5], Hij[_j][_j], Hij[_i5][_j]); + var Gij = Rij(_i5, _j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (var _i6 = 0; _i6 < N; _i6++) { + Ei[_i6] = Hij[_i6][_i6]; + } + + return sorting(Ei, Sij); + } + + function sorting(values, vectors) { + var eigsCount = values.length; + vectors.length; + + var pairs = __arrayMaker({ + length: eigsCount + }, function (_, i) { + var vector = vectors.map(function (v) { + return v[i]; + }); + return { + value: values[i], + vec: vector + }; + }); + + pairs.sort(function (a, b) { + return b.value - a.value; + }); + var sortedValues = pairs.map(function (_ref) { + var value = _ref.value; + return value; + }); + var sortedVectors = pairs.map(function (_ref2) { + var vec = _ref2.vec; + return vec; + }); + return [sortedValues, sortedVectors]; + } + + function dominentPrincipalVector(matrix) { + var _eigens = eigens(matrix), + _eigens$ = _eigens[1], + dominentVector = _eigens$[0]; + + return dominentVector; + } + + var Vec3 = function () { + function Vec3() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + + _classCallCheck(this, Vec3); + + this._values = [x, y, z]; + } + + _createClass(Vec3, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + }, { + key: "colorInt", + get: function get() { + var floatToInt = function floatToInt(value) { + var result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + }, { + key: "clone", + value: function clone() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + }, { + key: "toVec4", + value: function toVec4() { + var w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; + + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + }, { + key: "toString", + value: function toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec3.multScalar(a, 1 - p); + var b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + }]); + + return Vec3; + }(); + + var Vec4 = function () { + function Vec4() { + var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + + _classCallCheck(this, Vec4); + + this._values = [x, y, z, w]; + } + + _createClass(Vec4, [{ + key: "x", + get: function get() { + return this._values[0]; + }, + set: function set(value) { + this._values[0] = value; + } + }, { + key: "y", + get: function get() { + return this._values[1]; + }, + set: function set(value) { + this._values[1] = value; + } + }, { + key: "z", + get: function get() { + return this._values[2]; + }, + set: function set(value) { + this._values[2] = value; + } + }, { + key: "w", + get: function get() { + return this._values[3]; + }, + set: function set(value) { + this._values[3] = value; + } + }, { + key: "length", + get: function get() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + }, { + key: "lengthSq", + get: function get() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + }, { + key: "normalized", + get: function get() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + }, { + key: "xyz", + get: function get() { + return new Vec3(this.x, this.y, this.z); + } + }, { + key: "splatX", + get: function get() { + return new Vec4(this.x); + } + }, { + key: "splatY", + get: function get() { + return new Vec4(this.y); + } + }, { + key: "splatZ", + get: function get() { + return new Vec4(this.z); + } + }, { + key: "splatW", + get: function get() { + return new Vec4(this.w); + } + }, { + key: "clone", + value: function clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + }, { + key: "set", + value: function set(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + var w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + }, { + key: "toVec3", + value: function toVec3() { + return this.xyz; + } + }, { + key: "addVector", + value: function addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + }, { + key: "addScaledVector", + value: function addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + }, { + key: "subVector", + value: function subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + }, { + key: "mult", + value: function mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + }, { + key: "multVector", + value: function multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + }, { + key: "reciprocal", + value: function reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + }, { + key: "clamp", + value: function clamp(min, max) { + var clamper = function clamper(v) { + return min > v ? min : max < v ? max : v; + }; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + }, { + key: "clampGrid", + value: function clampGrid() { + var clamper = function clamper(v) { + return 0 > v ? 0 : 1 < v ? 1 : v; + }; + + var gridClamper = function gridClamper(value, grid) { + return __trunc(clamper(value) * grid + 0.5) / grid; + }; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + }, { + key: "truncate", + value: function truncate() { + this._values[0] = __trunc(this._values[0]); + this._values[1] = __trunc(this._values[1]); + this._values[2] = __trunc(this._values[2]); + this._values[3] = __trunc(this._values[3]); + return this; + } + }, { + key: "normalize", + value: function normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + }, { + key: "toString", + value: function toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + }], [{ + key: "add", + value: function add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + }, { + key: "sub", + value: function sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + }, { + key: "dot", + value: function dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + }, { + key: "multScalar", + value: function multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + }, { + key: "multVector", + value: function multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + }, { + key: "interpolate", + value: function interpolate(a, b, p) { + var a_ = Vec4.multScalar(a, 1 - p); + var b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + }, { + key: "multiplyAdd", + value: function multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + }, { + key: "negativeMultiplySubtract", + value: function negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + }, { + key: "compareAnyLessThan", + value: function compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + }]); + + return Vec4; + }(); + + function computeWeightedCovariance(values, weights) { + var total = 0; + var mean = values.reduce(function (sum, value, i) { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + var covariance = values.reduce(function (sum, value, i) { + var weight = weights[i]; + var v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } + + function computePCA(values, weights) { + var covariance = computeWeightedCovariance(values, weights); + return _construct(Vec3, dominentPrincipalVector(covariance)); + } + + var lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + var lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + var lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + + function floatToInt(value, limit) { + var integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } + + function floatTo565(color) { + var r = floatToInt(31.0 * color.x, 31); + var g = floatToInt(63.0 * color.y, 63); + var b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } + + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (var y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } + } + + function writeColourBlock3(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + var _ref = [secondColor, firstColor]; + firstColor = _ref[0]; + secondColor = _ref[1]; + remapped = indices.map(function (index) { + return index === 0 ? 1 : index === 1 ? 0 : index; + }); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + function writeColourBlock4(start, end, indices, result, blockOffset) { + var firstColor = floatTo565(start); + var secondColor = floatTo565(end); + var remapped; + + if (firstColor < secondColor) { + var _ref2 = [secondColor, firstColor]; + firstColor = _ref2[0]; + secondColor = _ref2[1]; + remapped = indices.map(function (index) { + return (index ^ 0x1) & 0x3; + }); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + var ColorSet = function () { + function ColorSet(rgba, mask, flags) { + _classCallCheck(this, ColorSet); + + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + var isDxt1 = (this.flags & kDxt1) != 0; + var weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (var i = 0; i < 16; i++) { + var bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (var j = 0;; j++) { + if (j == i) { + var r = rgba[4 * i] / 255.0; + var g = rgba[4 * i + 1] / 255.0; + var b = rgba[4 * i + 2] / 255.0; + var a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + var oldbit = 1 << j; + var match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + var index = this._remap[j]; + var w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (var _i = 0; _i < this._count; ++_i) { + this._weights[_i] = Math.sqrt(this._weights[_i]); + } + } + + _createClass(ColorSet, [{ + key: "transparent", + get: function get() { + return this._transparent; + } + }, { + key: "count", + get: function get() { + return this._count; + } + }, { + key: "points", + get: function get() { + return Object.freeze(this._points.slice()); + } + }, { + key: "weights", + get: function get() { + return Object.freeze(this._weights.slice()); + } + }, { + key: "remapIndicesSingle", + value: function remapIndicesSingle(singleIndex, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : singleIndex; + }); + + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }, { + key: "remapIndices", + value: function remapIndices(indexMap, target) { + var result = this._remap.map(function (index) { + return index === -1 ? 3 : indexMap[index]; + }); + + target.forEach(function (_, i) { + return target[i] = result[i]; + }); + } + }]); + + return ColorSet; + }(); + + var ColorFit = function () { + function ColorFit(colorSet) { + _classCallCheck(this, ColorFit); + + this.colors = colorSet; + this.flags = colorSet.flags; + } + + _createClass(ColorFit, [{ + key: "compress", + value: function compress(result, offset) { + var isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + }, { + key: "compress3", + value: function compress3(result, offset) {} + }, { + key: "compress4", + value: function compress4(result, offset) {} + }]); + + return ColorFit; + }(); + + var SingleColourFit = function (_ColorFit) { + _inherits(SingleColourFit, _ColorFit); + + var _super = _createSuper(SingleColourFit); + + function SingleColourFit(colorSet) { + var _this; + + _classCallCheck(this, SingleColourFit); + + _this = _super.call(this, colorSet); + var singleColor = colorSet.points[0]; + _this.color = singleColor.colorInt; + _this.start = new Vec3(0); + _this.end = new Vec3(0); + _this.index = 0; + _this.error = Infinity; + _this.bestError = Infinity; + return _this; + } + + _createClass(SingleColourFit, [{ + key: "compressBase", + value: function compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(lookups, saveFunc); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(lookups, saveFunc); + } + }, { + key: "computeEndPoints", + value: function computeEndPoints(lookups) { + this.error = Infinity; + + for (var index = 0; index < 2; index++) { + var sources = []; + var error = 0; + + for (var channel = 0; channel < 3; channel++) { + var lookup = lookups[channel]; + var target = this.color[channel]; + sources[channel] = lookup[target][index]; + var diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + }]); + + return SingleColourFit; + }(ColorFit); + + var RangeFit = function (_ColorFit2) { + _inherits(RangeFit, _ColorFit2); + + var _super2 = _createSuper(RangeFit); + + function RangeFit(colorSet) { + var _this2; + + _classCallCheck(this, RangeFit); + + _this2 = _super2.call(this, colorSet); + _this2.metric = new Vec3(1); + + if ((_this2.flags & kColourMetricPerceptual) !== 0) { + _this2.metric.set(0.2126, 0.7152, 0.0722); + } + + _this2.start = new Vec3(0); + _this2.end = new Vec3(0); + _this2.bestError = Infinity; + + _this2.computePoints(); + + return _this2; + } + + _createClass(RangeFit, [{ + key: "compressBase", + value: function compressBase(codes, saveFunc) { + var _this3 = this; + + var values = this.colors.points; + var error = 0; + var closest = values.map(function (color) { + var minDist = Infinity; + var packedIndex = codes.reduce(function (idx, code, j) { + var dist = Vec3.sub(color, code).multVector(_this3.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + var indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(codes, saveFunc); + } + }, { + key: "computePoints", + value: function computePoints() { + var _this$colors = this.colors, + count = _this$colors.count, + values = _this$colors.points, + weights = _this$colors.weights; + if (count <= 0) return; + var principle = computePCA(values, weights); + var start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (var i = 1; i < count; i++) { + var value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + }]); + + return RangeFit; + }(ColorFit); + + var ClusterFit = function (_ColorFit3) { + _inherits(ClusterFit, _ColorFit3); + + var _super3 = _createSuper(ClusterFit); + + function ClusterFit(colorSet) { + var _this4; + + _classCallCheck(this, ClusterFit); + + _this4 = _super3.call(this, colorSet); + var kMaxIterations = 8; + _this4.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + _this4.bestError = Infinity; + _this4.metric = new Vec4(1); + + if ((_this4.flags & kColourMetricPerceptual) !== 0) { + _this4.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + var _this4$colors = _this4.colors, + values = _this4$colors.points, + weights = _this4$colors.weights; + _this4.principle = computePCA(values, weights); + _this4.order = new Uint8Array(16 * kMaxIterations); + _this4.pointsWeights = []; + _this4.xSum_wSum = new Vec4(0); + return _this4; + } + + _createClass(ClusterFit, [{ + key: "constructOrdering", + value: function constructOrdering(axis, iteration) { + var currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + var uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + }, { + key: "compress3", + value: function compress3(result, offset) { + var aabbx = function aabbx(_ref) { + var part0 = _ref[0], + part1 = _ref[2], + part2 = _ref[3]; + var const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + var alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock3(start, end, indices, result, offset); + }; + + this.compressBase(aabbx, saveFunc, 2); + } + }, { + key: "compress4", + value: function compress4(result, offset) { + var aabbx = function aabbx(_ref2) { + var part0 = _ref2[0], + part1 = _ref2[1], + part2 = _ref2[2], + part3 = _ref2[3]; + var const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + var const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + var const2_9 = new Vec4(2 / 9); + var alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + var alpha2_sum = alphax_sum.splatW; + var betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + var beta2_sum = betax_sum.splatW; + var alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + var saveFunc = function saveFunc(start, end, indices) { + return writeColourBlock4(start, end, indices, result, offset); + }; + + this.compressBase(aabbx, saveFunc, 3); + } + }, { + key: "compressBase", + value: function compressBase(aabbFunc, saveFunc) { + var _this5 = this; + + var repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + var best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + var leastSquares = function leastSquares(parts, internalIndices) { + var aabbx = aabbFunc(parts); + + var internalBest = _this5.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (var iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + var newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + }, { + key: "makeOrder", + value: function makeOrder(axis) { + var _this$colors2 = this.colors, + count = _this$colors2.count, + values = _this$colors2.points; + var dotProducts = values.map(function (color, i) { + return Vec3.dot(color, axis); + }); + return __arrayMaker({ + length: count + }, function (_, i) { + return i; + }).sort(function (a, b) { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + }, { + key: "copyOrderToThisOrder", + value: function copyOrderToThisOrder(order, iteration) { + var _this6 = this; + + var orderOffset = iteration * 16; + order.forEach(function (ord, i) { + _this6.order[orderOffset + i] = ord; + }); + } + }, { + key: "checkOrderUnique", + value: function checkOrderUnique(order, iteration) { + var count = this.colors.count; + + for (var it = 0; it < iteration; it++) { + var prevOffset = it * 16; + var same = true; + + for (var i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + }, { + key: "copyOrderWeight", + value: function copyOrderWeight(order) { + var _this$colors3 = this.colors, + count = _this$colors3.count, + unweighted = _this$colors3.points, + weights = _this$colors3.weights; + this.xSum_wSum.set(0); + + for (var i = 0; i < count; i++) { + var j = order[i]; + var p = unweighted[j].toVec4(1); + var w = new Vec4(weights[j]); + var x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + }, { + key: "computeOptimalPoints", + value: function computeOptimalPoints(vectorPoint) { + var ax = vectorPoint.ax, + bx = vectorPoint.bx, + aa = vectorPoint.aa, + bb = vectorPoint.bb, + ab = vectorPoint.ab; + var factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + var a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + var b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + var error = this.computeError(_objectSpread2({ + a: a, + b: b + }, vectorPoint)); + return { + start: a, + end: b, + error: error + }; + } + }, { + key: "computeError", + value: function computeError(_ref3) { + var a = _ref3.a, + b = _ref3.b, + ax = _ref3.ax, + bx = _ref3.bx, + aa = _ref3.aa, + bb = _ref3.bb, + ab = _ref3.ab; + var two = new Vec4(2); + var e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + var e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + var e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + var e4 = Vec4.multiplyAdd(two, e3, e1); + var e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + }, { + key: "saveBlock", + value: function saveBlock(best, writeFunc) { + var count = this.colors.count; + var start = best.start, + end = best.end, + iteration = best.iteration, + error = best.error, + bestI = best.bestI, + bestJ = best.bestJ, + _best$bestK = best.bestK, + bestK = _best$bestK === void 0 ? -1 : _best$bestK; + var orderOffset = iteration * 16; + var unordered = new Uint8Array(16); + + var mapper = function mapper(m) { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (var i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + var bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + }, { + key: "clusterIterate", + value: function clusterIterate(index, func) { + var iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + var count = this.colors.count; + + var indexMapper = function indexMapper(i, j, k) { + var mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + var part0 = new Vec4(0.0); + + for (var i = 0; i < count; i++) { + var part1 = new Vec4(0.0); + + for (var j = i;;) { + var preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + var kmin = j == 0 ? 1 : j; + + for (var k = kmin;;) { + var restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + }]); + + return ClusterFit; + }(ColorFit); + + function quantise(alpha) { + var GRID = 15; + var result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; + } + + function compressAlphaDxt3(rgba, mask, result, offset) { + for (var i = 0; i < 8; i++) { + var quant1 = quantise(rgba[8 * i + 3]); + var quant2 = quantise(rgba[8 * i + 7]); + var bit1 = 1 << 2 * i; + var bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } + } + + function compressAlphaDxt5(rgba, mask, result, offset) { + var step5 = interpolateAlpha(rgba, mask, 5); + var step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } + + function interpolateAlpha(rgba, mask, steps) { + var _setAlphaRange = setAlphaRange(rgba, mask, steps), + min = _setAlphaRange.min, + max = _setAlphaRange.max; + + var code = setAlphaCodeBook(min, max, steps); + var indices = new Uint8Array(16); + var error = fitCodes(rgba, mask, code, indices); + return { + min: min, + max: max, + indices: indices, + error: error + }; + } + + function setAlphaRange(rgba, mask, steps) { + var min = 255; + var max = 0; + + for (var i = 0; i < 16; i++) { + var bit = 1 << i; + if ((mask & bit) == 0) continue; + var value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min: min, + max: max + }; + } + + function setAlphaCodeBook(min, max, steps) { + var codes = [min, max].concat(__arrayMaker({ + length: steps - 1 + }, function (_, i) { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })); + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; + } + + function fitCodes(rgba, mask, codes, indices) { + var err = 0; + + for (var i = 0; i < 16; ++i) { + var bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + var value = rgba[4 * i + 3]; + var least = Infinity; + var index = 0; + + for (var j = 0; j < 8; ++j) { + var dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; + } + + function writeAlphaBlock5(_ref, result, offset) { + var alpha0 = _ref.min, + alpha1 = _ref.max, + indices = _ref.indices; + + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock7(_ref2, result, offset) { + var alpha0 = _ref2.min, + alpha1 = _ref2.max, + indices = _ref2.indices; + + if (alpha0 > alpha1) { + var swapped = indices.map(function (index) { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + var indicesPointer = 0; + var resultPointer = offset + 2; + + for (var i = 0; i < 2; i++) { + var value = 0; + + for (var j = 0; j < 8; ++j) { + var index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (var _j = 0; _j < 3; ++_j) { + var byte = value >> 8 * _j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } + } + + function unpack565(color16bit) { + var red = color16bit >> 11 & 0x1f; + var green = color16bit >> 5 & 0x3f; + var blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; + } + + function interpolateColorArray(a, b, amount) { + var result = a.map(function (aColor, i) { + return Math.floor(aColor * (1 - amount) + b[i] * amount); + }); + result[3] = 255; + return result; + } + + function unpackColorCodes(block, offset, isDxt1) { + var color1 = block[offset] | block[offset + 1] << 8; + var color2 = block[offset + 2] | block[offset + 3] << 8; + var unpackedColor1 = unpack565(color1); + var unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } + + function unpackIndices(block, blockOffset) { + var offset = blockOffset + 4; + var result = new Uint8Array(16); + + for (var i = 0; i < 4; i++) { + var packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; + } + + function decompressColor(rgba, block, offset, isDxt1) { + var colorCode = unpackColorCodes(block, offset, isDxt1); + var indices = unpackIndices(block, offset); + + for (var i = 0; i < 16; i++) { + for (var j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } + } + + function decompressAlphaDxt3(rgba, block, offset) { + for (var i = 0; i < 8; ++i) { + var quant = block[offset + i]; + var lo = quant & 0x0f; + var hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } + } + + function decompressAlphaDxt5(rgba, block, offset) { + var alpha0 = block[offset + 0]; + var alpha1 = block[offset + 1]; + var codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + var indices = new Uint8Array(16); + var indicePointer = 0; + var bytePointer = 2; + + for (var i = 0; i < 2; i++) { + var value = 0; + + for (var j = 0; j < 3; j++) { + var byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (var _j = 0; _j < 8; _j++) { + var index = value >> 3 * _j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (var _i = 0; _i < 16; ++_i) { + rgba[4 * _i + 3] = codes[indices[_i]]; + } + } + + var DXT1_COMPRESSED_BYTES = 8; + var DXT5_COMPRESSED_BYTES = 16; + var COLORS = 4; + var DECOMPRESSED_BLOCK_SIZE = 16; + + function blockRepeat(width, height, func) { + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + func(x, y); + } + } + } + + function rectRepeat(func) { + for (var y = 0; y < 4; y++) { + for (var x = 0; x < 4; x++) { + func(x, y); + } + } + } + + function FixFlags(flags) { + var method = flags & (kDxt1 | kDxt3 | kDxt5); + var fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + var metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + var extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; + } + + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + var blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + var blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } + + function extractColorBlock(img) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$x = _ref.x, + x = _ref$x === void 0 ? 0 : _ref$x, + _ref$y = _ref.y, + y = _ref$y === void 0 ? 0 : _ref$y, + _ref$width = _ref.width, + width = _ref$width === void 0 ? 0 : _ref$width, + _ref$height = _ref.height, + height = _ref$height === void 0 ? 0 : _ref$height; + + var block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + var mask = 0; + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; + + if (sx < width && sy < height) { + var sourceColorOffset = COLORS * (width * sy + sx); + + for (var i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block: block, + mask: mask + }; + } + + function copyBuffer(result, block) { + var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref2$x = _ref2.x, + x = _ref2$x === void 0 ? 0 : _ref2$x, + _ref2$y = _ref2.y, + y = _ref2$y === void 0 ? 0 : _ref2$y, + _ref2$width = _ref2.width, + width = _ref2$width === void 0 ? 0 : _ref2$width, + _ref2$height = _ref2.height, + height = _ref2$height === void 0 ? 0 : _ref2$height; + + var blockColorOffset = 0; + rectRepeat(function (px, py) { + var sx = x + px; + var sy = y + py; + + if (sx < width && sy < height) { + var resultColorOffset = COLORS * (width * sy + sx); + + for (var i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } + + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } + + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + var colors = new ColorSet(rgba, mask, flags); + var compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } + + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + var colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); + } + + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + var _extractColorBlock = extractColorBlock(source, { + x: x, + y: y, + width: width, + height: height + }), + sourceRGBA = _extractColorBlock.block, + mask = _extractColorBlock.mask; + + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } + + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + var bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + var sourceBlockPointer = 0; + + for (var y = 0; y < height; y += 4) { + for (var x = 0; x < width; x += 4) { + var targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x: x, + y: y, + width: width, + height: height + }); + sourceBlockPointer += bytesPerBlock; + } + } + } + + var flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; + + function compress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = GetStorageRequirements(width, height, flags); + var result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; + } + + function decompress(inputData, width, height, flags) { + var source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + var targetSize = width * height * 4; + var result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; + } + + var Texture2DReader = function (_BaseReader) { + _inherits(Texture2DReader, _BaseReader); + + var _super = _createSuper(Texture2DReader); + + function Texture2DReader() { + _classCallCheck(this, Texture2DReader); + + return _super.apply(this, arguments); + } + + _createClass(Texture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + var width = content.export.width; + var height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; + + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + }]); + + return Texture2DReader; + }(BaseReader); + + var Vector3Reader = function (_BaseReader) { + _inherits(Vector3Reader, _BaseReader); + + var _super = _createSuper(Vector3Reader); + + function Vector3Reader() { + _classCallCheck(this, Vector3Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector3Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + return { + x: x, + y: y, + z: z + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + }]); + + return Vector3Reader; + }(BaseReader); + + var SpriteFontReader = function (_BaseReader) { + _inherits(SpriteFontReader, _BaseReader); + + var _super = _createSuper(SpriteFontReader); + + function SpriteFontReader() { + _classCallCheck(this, SpriteFontReader); + + return _super.apply(this, arguments); + } + + _createClass(SpriteFontReader, [{ + key: "read", + value: function read(buffer, resolver) { + var int32Reader = new Int32Reader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(new CharReader()); + var texture = resolver.read(buffer); + var glyphs = resolver.read(buffer); + var cropping = resolver.read(buffer); + var characterMap = resolver.read(buffer); + var verticalLineSpacing = int32Reader.read(buffer); + var horizontalSpacing = singleReader.read(buffer); + var kerning = resolver.read(buffer); + var defaultCharacter = nullableCharReader.read(buffer); + return { + texture: texture, + glyphs: glyphs, + cropping: cropping, + characterMap: characterMap, + verticalLineSpacing: verticalLineSpacing, + horizontalSpacing: horizontalSpacing, + kerning: kerning, + defaultCharacter: defaultCharacter + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + var int32Reader = new Int32Reader(); + var charReader = new CharReader(); + var singleReader = new SingleReader(); + var nullableCharReader = new NullableReader(charReader); + var texture2DReader = new Texture2DReader(); + var rectangleListReader = new ListReader(new RectangleReader()); + var charListReader = new ListReader(charReader); + var vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + }]); + + return SpriteFontReader; + }(BaseReader); + + var TBinReader = function (_BaseReader) { + _inherits(TBinReader, _BaseReader); + + var _super = _createSuper(TBinReader); + + function TBinReader() { + _classCallCheck(this, TBinReader); + + return _super.apply(this, arguments); + } + + _createClass(TBinReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var size = int32Reader.read(buffer); + var data = buffer.read(size); + return { + export: { + type: this.type, + data: data + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + var data = content.export.data; + var int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + }]); + + return TBinReader; + }(BaseReader); + + var LightweightTexture2DReader = function (_BaseReader) { + _inherits(LightweightTexture2DReader, _BaseReader); + + var _super = _createSuper(LightweightTexture2DReader); + + function LightweightTexture2DReader() { + _classCallCheck(this, LightweightTexture2DReader); + + return _super.apply(this, arguments); + } + + _createClass(LightweightTexture2DReader, [{ + key: "read", + value: function read(buffer) { + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + var format = int32Reader.read(buffer); + var width = uint32Reader.read(buffer); + var height = uint32Reader.read(buffer); + var mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + var dataSize = uint32Reader.read(buffer); + var data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (var i = 0; i < data.length; i += 4) { + var inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format: format, + export: { + type: this.type, + data: data, + width: width, + height: height + } + }; + } + }, { + key: "write", + value: function write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + var int32Reader = new Int32Reader(); + var uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + var data = content.export.data; + + for (var i = 0; i < data.length; i += 4) { + var alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } + }, { + key: "type", + get: function get() { + return "Texture2D"; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + }, { + key: "type", + value: function type() { + return "Texture2D"; + } + }]); + + return LightweightTexture2DReader; + }(BaseReader); + + var Vector2Reader = function (_BaseReader) { + _inherits(Vector2Reader, _BaseReader); + + var _super = _createSuper(Vector2Reader); + + function Vector2Reader() { + _classCallCheck(this, Vector2Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector2Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + return { + x: x, + y: y + }; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + }]); + + return Vector2Reader; + }(BaseReader); + + var Vector4Reader = function (_BaseReader) { + _inherits(Vector4Reader, _BaseReader); + + var _super = _createSuper(Vector4Reader); + + function Vector4Reader() { + _classCallCheck(this, Vector4Reader); + + return _super.apply(this, arguments); + } + + _createClass(Vector4Reader, [{ + key: "read", + value: function read(buffer) { + var singleReader = new SingleReader(); + var x = singleReader.read(buffer); + var y = singleReader.read(buffer); + var z = singleReader.read(buffer); + var w = singleReader.read(buffer); + return { + x: x, + y: y, + z: z, + w: w + }; + } + }], [{ + key: "isTypeOf", + value: function isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + }]); + + return Vector4Reader; + }(BaseReader); + + exports.ArrayReader = ArrayReader; + exports.BaseReader = BaseReader; + exports.BmFontReader = BmFontReader; + exports.BooleanReader = BooleanReader; + exports.CharReader = CharReader; + exports.DictionaryReader = DictionaryReader; + exports.DoubleReader = DoubleReader; + exports.EffectReader = EffectReader; + exports.Int32Reader = Int32Reader; + exports.LightweightTexture2DReader = LightweightTexture2DReader; + exports.ListReader = ListReader; + exports.NullableReader = NullableReader; + exports.RectangleReader = RectangleReader; + exports.ReflectiveReader = ReflectiveReader; + exports.SingleReader = SingleReader; + exports.SpriteFontReader = SpriteFontReader; + exports.StringReader = StringReader; + exports.TBinReader = TBinReader; + exports.Texture2DReader = Texture2DReader; + exports.UInt32Reader = UInt32Reader; + exports.Vector2Reader = Vector2Reader; + exports.Vector3Reader = Vector3Reader; + exports.Vector4Reader = Vector4Reader; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/src/readers/dist/readers.es5.min.js b/src/readers/dist/readers.es5.min.js new file mode 100644 index 0000000..f5109c5 --- /dev/null +++ b/src/readers/dist/readers.es5.min.js @@ -0,0 +1,23 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,n=function(t){try{return!!t()}catch(t){return!0}},i=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=function(t){return t&&t.Math==Math&&t},o=u("object"==typeof globalThis&&globalThis)||u("object"==typeof window&&window)||u("object"==typeof self&&self)||u("object"==typeof e&&e)||function(){return this}()||Function("return this")(),a=function(t){return"function"==typeof t},s=a,c=function(t){return"object"==typeof t?null!==t:s(t)},l=!n((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),f=l,h=Function.prototype,v=h.bind,y=h.call,p=f&&v.bind(y,y),d=f?function(t){return t&&p(t)}:function(t){return t&&function(){return y.apply(t,arguments)}},w=o.TypeError,m=function(t){if(null==t)throw w("Can't call method on "+t);return t},g=o.Object,k=function(t){return g(m(t))},b=k,_=d({}.hasOwnProperty),x=Object.hasOwn||function(t,e){return _(b(t),e)},S={exports:{}},T=o,O=Object.defineProperty,A=function(t,e){try{O(T,t,{value:e,configurable:!0,writable:!0})}catch(r){T[t]=e}return e},M=A,R="__core-js_shared__",z=o[R]||M(R,{}),V=z;(S.exports=function(t,e){return V[t]||(V[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var j,I,E=d,C=0,P=Math.random(),F=E(1..toString),B=function(t){return"Symbol("+(void 0===t?"":t)+")_"+F(++C+P,36)},D=o,U=a,X=function(t){return U(t)?t:void 0},L=function(t,e){return arguments.length<2?X(D[t]):D[t]&&D[t][e]},W=o,N=L("navigator","userAgent")||"",G=W.process,Y=W.Deno,q=G&&G.versions||Y&&Y.version,K=q&&q.v8;K&&(I=(j=K.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=o,tt=S.exports,et=x,rt=B,nt=$,it=H,ut=tt("wks"),ot=Q.Symbol,at=ot&&ot.for,st=it?ot:ot&&ot.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(ot,t)?ut[t]=ot[t]:ut[t]=it&&at?at(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,vt=ht({}.toString),yt=ht("".slice),pt=function(t){return yt(vt(t),8,-1)},dt=o,wt=ft,mt=a,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},St=o.String,Tt=function(t){try{return St(t)}catch(t){return"Object"}},Ot={},At=c,Mt=o.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=o,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Bt=l,Dt=Function.prototype.call,Ut=Bt?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},Xt=d({}.isPrototypeOf),Lt=L,Wt=a,Nt=Xt,Gt=H,Yt=o.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Lt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=a,Jt=Tt,Zt=o.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=a,ee=c,re=o.TypeError,ne=Ut,ie=c,ue=qt,oe=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},ae=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=o.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=oe(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),ae(t,e)},he=qt,ve=i,ye=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=o.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ve?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ye)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Se=Ot,Te=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Se.f(t,e,Te(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=a,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,Be,De,Ue=Ce.inspectSource,Xe=a,Le=Ue,We=o.WeakMap,Ne=Xe(We)&&/native code/.test(Le(We)),Ge=S.exports,Ye=B,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=o,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,or=Ze.WeakMap;if(Je||er.state){var ar=er.state||(er.state=new or),sr=$e(ar.get),cr=$e(ar.has),lr=$e(ar.set);Fe=function(t,e){if(cr(ar,t))throw new ur(ir);return e.facade=t,lr(ar,t,e),e},Be=function(t){return sr(ar,t)||{}},De=function(t){return cr(ar,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},Be=function(t){return tr(t,fr)?t[fr]:{}},De=function(t){return tr(t,fr)}}var hr={set:Fe,get:Be,has:De,enforce:function(t){return De(t)?Be(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=Be(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},vr=n,yr=a,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!vr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return yr(this)&&kr(this).source||mr(this)}),"toString");var Sr,Tr,Or,Ar=o,Mr=a,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=o,Er=x,Cr=a,Pr=k,Fr=jr,Br=Ke("IE_PROTO"),Dr=Ir.Object,Ur=Dr.prototype,Xr=Fr?Dr.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Br))return e[Br];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Dr?Ur:null},Lr=o,Wr=a,Nr=Lr.String,Gr=Lr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=o,Qr=a,tn=c,en=x,rn=xt,nn=Tt,un=Oe,on=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,a=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,a,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!o&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},an=Ot.f,sn=Xt,cn=Xr,ln=Jr,fn=ct,hn=B,vn=Hr.Int8Array,yn=vn&&vn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=vn&&cn(vn),mn=yn&&cn(yn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Sn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Tn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Sr in On)(Or=(Tr=Hr[Sr])&&Tr.prototype)?un(Or,xn,Tr):Sn=!1;for(Sr in An)(Or=(Tr=Hr[Sr])&&Tr.prototype)&&un(Or,xn,Tr);if((!Sn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr],wn);if((!Sn||!mn||mn===gn)&&(mn=wn.prototype,Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr].prototype,mn);if(Sn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Sr in Tn=!0,an(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Sr]&&un(Hr[Sr],_n,Sr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Sn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Tn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||on(mn,t,r?e:Sn&&yn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return on(wn,t,r?e:Sn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||on(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=o.Object,Fn=In("".split),Bn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Dn=Math.ceil,Un=Math.floor,Xn=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Dn)(e)},Ln=Math.min,Wn=function(t){return t>0?Ln(Xn(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=a,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=L("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,oi=o,ai=Gn,si=ui,ci=c,li=ct("species"),fi=oi.Array,hi=function(t){var e;return ai(t)&&(e=t.constructor,(si(e)&&(e===fi||ai(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},vi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},yi=Bn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,o=7==t,a=5==t||u;return function(s,c,l,f){for(var h,v,y=pi(s),p=yi(y),d=vi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||o?g(s,0):void 0;w>m;m++)if((a||m in p)&&(v=d(h=p[m],m,y),t))if(e)k[m]=v;else if(v)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=Tt,xi=o.TypeError,Si=Ft,Ti=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Si(t).constructor;return void 0===n||null==(r=Si(n)[Oi])?e:Ti(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Bi=Ci(Fi.toString),Di=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Di.exec);function Xi(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Li(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),ru=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(eu),nu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new fu,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new fu,null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),o=0;o=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Su(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Tu(t)}for(var v=0;v0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,o=Bu(t),a=Bu(e);if(o<=a)u=r.slice();else{var s=[a,o];o=s[0],a=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Du(o,a,u,n,i)}function Xu(t,e,r,n,i){var u,o=Bu(t),a=Bu(e);if(o=128||!i)){var h=this._remap[a],v=(e[4*o+3]+1)/256;this._weights[h]+=u?v:1,this._remap[o]=h;break}}else this._remap[o]=-1}for(var y=0;y=n?t:(n=o,u)}),0);return i+=n,u}));if(ia&&(u=r[c],a=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,o=i.weights;return n.principle=ju(u,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),o=u.splatW,a=Vu.multiplyAdd(r,i,n);return{ax:u,aa:o,bx:a,bb:a.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),o=new Vu(2/3,2/3,2/3,4/9),a=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,o,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,o,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(a,Vu.add(r,n)).splatW}}),(function(r,n,i){return Xu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),o=r.computeOptimalPoints(u);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),o=0;o15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*l&255;n[o]=f,o++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function to(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),o=Hu(i);return[u,o,Qu(u,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,o,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),o=0;o<16;o++)for(var a=0;a<4;a++)t[4*o+a]=i[u[o]][a]}function eo(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ro(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function no(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,o=void 0===u?0:u,a=r.width,s=void 0===a?0:a,c=r.height,l=void 0===c?0:c,f=0;eo((function(r,n){var u=i+r,a=o+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),o=new Uint8Array(16),a=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var v=l>>3*h&7;o[a]=v,a++}}for(var y=0;y<16;++y)t[4*y+3]=u[o[y]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function oo(t,e,r,n,i){var u=0!=(1&(i=ro(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,o=e.width,a=void 0===o?0:o,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return eo((function(e,r){var i=n+e,o=u+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(4==n)s=fo(s,i,u,ao);else if(5==n)s=fo(s,i,u,so);else if(6==n)s=fo(s,i,u,co);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),po=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),wo=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),o=r.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + + } + + class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + + } + + class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + + } + + const UTF16_BITES = [0xD800, 0xDC00]; + const UTF16_MASK = 0b1111111111; + + function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + } + + function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; + } + + function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); + } + + class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + + } + + class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + + } + + class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + + } + + class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + + } + + class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + + } + + class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + + } + + class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + + } + + class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + + } + + class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } + + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content !== null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + + } + + class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + + } + + class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + + } + + class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + + } + + const kDxt1 = 1 << 0; + const kDxt3 = 1 << 1; + const kDxt5 = 1 << 2; + const kColourIterativeClusterFit = 1 << 8; + const kColourClusterFit = 1 << 3; + const kColourRangeFit = 1 << 4; + const kColourMetricPerceptual = 1 << 5; + const kColourMetricUniform = 1 << 6; + const kWeightColourByAlpha = 1 << 7; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; + } + + function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; + } + + function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; + } + + function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; + } + + function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; + } + + function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; + } + + function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); + } + + function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; + } + + function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; + } + + class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + + } + + class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + + } + + function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; + } + + function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); + } + + const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; + const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + + function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; + } + + function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; + } + + function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } + } + + function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); + } + + class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + + } + + class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + + } + + class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + + } + + class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + + } + + class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + + } + + function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; + } + + function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } + } + + function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); + } + + function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; + } + + function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; + } + + function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; + } + + function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; + } + + function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); + } + + function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } + } + + function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; + } + + function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; + } + + function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; + } + + function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; + } + + function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } + } + + function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } + } + + function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } + } + + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ + const DXT1_COMPRESSED_BYTES = 8; + const DXT5_COMPRESSED_BYTES = 16; + const COLORS = 4; + const DECOMPRESSED_BLOCK_SIZE = 16; + + function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } + } + + function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } + } + + function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; + } + + function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; + } + + function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; + } + + function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); + } + + function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); + } + + function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); + } + + function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); + } + + function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); + } + + function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } + } + + const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha + }; + + function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; + } + + function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; + } + + class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + + } + + class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + + } + + class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + } + + class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + + } + + class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + + } + + class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + + } + + exports.ArrayReader = ArrayReader; + exports.BaseReader = BaseReader; + exports.BmFontReader = BmFontReader; + exports.BooleanReader = BooleanReader; + exports.CharReader = CharReader; + exports.DictionaryReader = DictionaryReader; + exports.DoubleReader = DoubleReader; + exports.EffectReader = EffectReader; + exports.Int32Reader = Int32Reader; + exports.LightweightTexture2DReader = LightweightTexture2DReader; + exports.ListReader = ListReader; + exports.NullableReader = NullableReader; + exports.RectangleReader = RectangleReader; + exports.ReflectiveReader = ReflectiveReader; + exports.SingleReader = SingleReader; + exports.SpriteFontReader = SpriteFontReader; + exports.StringReader = StringReader; + exports.TBinReader = TBinReader; + exports.Texture2DReader = Texture2DReader; + exports.UInt32Reader = UInt32Reader; + exports.Vector2Reader = Vector2Reader; + exports.Vector3Reader = Vector3Reader; + exports.Vector4Reader = Vector4Reader; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/src/readers/dist/readers.min.js b/src/readers/dist/readers.min.js new file mode 100644 index 0000000..ce43f36 --- /dev/null +++ b/src/readers/dist/readers.min.js @@ -0,0 +1,24 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";class e{static isTypeOf(t){return!1}static hasSubType(){return!1}static parseTypeList(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new o;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class w extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const f=256;//! Use DXT1 compression. +//! Weight the colour by alpha during cluster fit (disabled by default). +function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function T(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...T(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function B(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class X{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class D{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class U extends D{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class P extends D{constructor(t){super(t);this.iterationCount=t.flags&f?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>B(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=f&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]} +/** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new w,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new w,a=new h(n),o=new ot,f=new c(new d),p=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),f.write(t,e.glyphs,r),f.write(t,e.cropping,r),p.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/readers/dist/readers.module.js b/src/readers/dist/readers.module.js new file mode 100644 index 0000000..e81fa92 --- /dev/null +++ b/src/readers/dist/readers.module.js @@ -0,0 +1,2692 @@ +class BaseReader { + static isTypeOf(type) { + return false; + } + + static hasSubType() { + return false; + } + + static parseTypeList() { + let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + return [this.type(), ...subtype]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + +} + +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + +} + +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + +} + +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + +} + +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + +} + +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + +} + +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + +} + +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + +} + +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + +} + +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + +} + +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + } + + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content !== null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + +} + +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + +} + +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + +} + +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + +} + +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} + +function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} + +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; +} + +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; +} + +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; +} + +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; +} + +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); +} + +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} + +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + +} + +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + +} + +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} + +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} + +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} + +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} + +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } +} + +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + +} + +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + +} + +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} + +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; +} + +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; +} + +function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; +} + +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; +} + +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; +} + +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } +} + +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } +} + +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } +} + +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } +} + +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} + +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} + +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} + +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; +} + +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} + +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} + +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} + +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); +} + +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} + +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } +} + +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; + +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; +} + +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; +} + +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + +} + +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } + +} + +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + +} + +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + +} + +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + +} + +export { ArrayReader, BaseReader, BmFontReader, BooleanReader, CharReader, DictionaryReader, DoubleReader, EffectReader, Int32Reader, LightweightTexture2DReader, ListReader, NullableReader, RectangleReader, ReflectiveReader, SingleReader, SpriteFontReader, StringReader, TBinReader, Texture2DReader, UInt32Reader, Vector2Reader, Vector3Reader, Vector4Reader }; diff --git a/src/readers/es5.js b/src/readers/es5.js new file mode 100644 index 0000000..977ab6b --- /dev/null +++ b/src/readers/es5.js @@ -0,0 +1,4 @@ +import "core-js/modules/es.typed-array.map.js"; +import "core-js/modules/es.function.name.js"; + +export * from "./readers.js"; \ No newline at end of file diff --git a/src/readers/libs/UTF8ToString.js b/src/readers/libs/UTF8ToString.js new file mode 100644 index 0000000..7ab013c --- /dev/null +++ b/src/readers/libs/UTF8ToString.js @@ -0,0 +1,183 @@ +const UTF8_FIRST_BITES=[0xC0, 0xE0, 0xF0]; +const UTF8_SECOND_BITES=0x80; +const UTF8_MASK=0b111111; + +const UTF16_BITES=[0xD800, 0xDC00]; +const UTF16_MASK=0b1111111111; + +function UTF8Encode(code) +{ + //0x0000 ~ 0x007F + if(code < 0x80) return [code]; + + //0x0080 ~ 0x07FF + if(code < 0x800) return [ + UTF8_FIRST_BITES[0] | (code >> 6), + UTF8_SECOND_BITES | (code & UTF8_MASK) + ]; + + //0x0800 ~ 0xFFFF + if(code < 0x10000) return [ + UTF8_FIRST_BITES[1] | (code >> 12), + UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), + UTF8_SECOND_BITES | (code & UTF8_MASK) + ]; + + //0x10000 ~ + return [ + UTF8_FIRST_BITES[2] | (code >> 18), + UTF8_SECOND_BITES | ( (code >> 12) & UTF8_MASK ), + UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), + UTF8_SECOND_BITES | ( code & UTF8_MASK ) + ]; +} + +function UTF16Encode(code) +{ + //0x0000 ~ 0xFFFF + if(code < 0xFFFF) return [code]; + + //0x10000 ~ + code -= 0x10000; + return [ + UTF16_BITES[0] | ( (code >> 10) & UTF16_MASK ), + UTF16_BITES[1] | ( code & UTF16_MASK ) + ]; +} + +function UTF8Decode(codeSet) +{ + if(typeof codeSet === "number") codeSet=[codeSet]; + if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); + + const codeSetRange = codeSet.length; + + //0x0000 ~ 0x007F + if(codeSetRange === 1) return codeSet[0]; + + //0x0080 ~ 0x07FF + if(codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); + + //0x0800 ~ 0xFFFF + if(codeSetRange === 3) { + return ( ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + + ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + + (codeSet[2] ^ UTF8_SECOND_BITES) ); + } + + //0x10000 ~ + return ( ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + + (codeSet[3] ^ UTF8_SECOND_BITES) ); +} + +function UTF16Decode(codeSet) +{ + if(typeof codeSet === "number") codeSet=[codeSet]; + if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); + + const codeSetRange = codeSet.length; + + //0x0000 ~ 0xFFFF + if(codeSetRange === 1) return codeSet[0]; + + //0x10000 ~ + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) +{ + const utf16Map = Array.from({length:str.length}, (_,i)=>str.charCodeAt(i)); + const result=[]; + let index=0; + while(index < str.length) { + let code = utf16Map[index]; + if( (UTF16_BITES[0] & code) !== UTF16_BITES[0] ) { + result.push( code ); + index++; + } + else { + result.push( UTF16Decode(utf16Map.slice(index, index+2)) ); + index+=2; + } + } + return result; +} + +function UTF8ToUnicode(codes) +{ + const dataArray = (codes instanceof ArrayBuffer) ? new Uint8Array(codes) : codes; + + const result=[]; + let index=0; + while(index < dataArray.length) { + let headerCode = dataArray[index]; + if((headerCode & 0x80) === 0) { + result.push(headerCode); + index++; + } + else if(headerCode < UTF8_FIRST_BITES[1]) { + result.push( UTF8Decode(dataArray.slice(index, index+2)) ); + index+=2; + } + else if(headerCode < UTF8_FIRST_BITES[2]) { + result.push( UTF8Decode(dataArray.slice(index, index+3)) ); + index+=3; + } + else{ + result.push( UTF8Decode(dataArray.slice(index, index+4)) ); + index+=4; + } + } + return result; +} + +function UnicodeToUTF8(unicodeArr) +{ + const result = []; + for(let code of unicodeArr) { + result.push(...UTF8Encode(code)); + } + return result; +} + +function UnicodeToString(unicodeArr) +{ + const result = []; + for(let code of unicodeArr) { + result.push(...UTF16Encode(code)); + } + + //for bigger strings + const blockSize = 32768; + let resultStr = ""; + for(let i=0; i{ + if(unicode < 0x80) return sum+1; + if(unicode < 0x800) return sum+2; + if(unicode < 0x10000) return sum+3; + return sum+4; + }, 0); +} + +export {stringToUTF8, UTF8ToString, UTF8Length}; \ No newline at end of file diff --git a/src/readers/libs/dxt.js b/src/readers/libs/dxt.js new file mode 100644 index 0000000..d804297 --- /dev/null +++ b/src/readers/libs/dxt.js @@ -0,0 +1,328 @@ +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ + +import {kDxt1, kDxt3, kDxt5, + kColourIterativeClusterFit, kColourClusterFit, kColourRangeFit, + kColourMetricPerceptual, kColourMetricUniform, kWeightColourByAlpha +} from "./dxt/constant.js"; +import {ColorSet, SingleColourFit, RangeFit, ClusterFit} from "./dxt/colorFits.js"; +import {compressAlphaDxt3, compressAlphaDxt5} from "./dxt/alphaCompressor.js"; +import {decompressColor, decompressAlphaDxt3, decompressAlphaDxt5} from "./dxt/decompressor.js"; + +//internal constant(deconstructing) +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + + +//---------------------------------------------------------------------------// + + +/** + * image-block repeat function + * @param {function(int, int)} callback function to perform per iteration + * @param {int} x-coord + * @param {int} y-coord + */ +function blockRepeat(width, height, func) +{ + for(let y=0;y GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) +{ + // quantise and pack the alpha values pairwise + // repeat by 1byte (= 4bit * 2) + + for( let i = 0; i < 8; i++ ) + { + // quantise down to 4 bits + let quant1 = quantise( rgba[8*i + 3] ); + let quant2 = quantise( rgba[8*i + 7] ); + + // set alpha to zero where masked + const bit1 = 1 << ( 2*i ); + const bit2 = 1 << ( 2*i + 1 ); + if( ( mask & bit1 ) == 0 ) quant1 = 0; + if( ( mask & bit2 ) == 0 ) quant2 = 0; + + // pack into the byte + result[offset + i] = quant1 | ( quant2 << 4 ); + } + +} + +function compressAlphaDxt5(rgba, mask, result, offset) +{ + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + + // save the block with least error + if( step5.error <= step7.error ) writeAlphaBlock5( step5, result, offset ); + else writeAlphaBlock7( step7, result, offset); +} + + +function interpolateAlpha(rgba, mask, steps) +{ + let {min, max} = setAlphaRange(rgba, mask, steps); + + let code = setAlphaCodeBook(min, max, steps); + + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + + return {min, max, indices, error}; +} + +function setAlphaRange(rgba, mask, steps) +{ + let min = 255; + let max = 0; + + for( let i = 0; i < 16; i++ ) + { + // check this pixel is valid + let bit = 1 << i; + if( ( mask & bit ) == 0 ) continue; + + // incorporate into the min/max + let value = rgba[4*i + 3]; + + if(steps === 5) + { + if(value !== 0 && value < min) min = value; + if(value !== 255 && value > max) max = value; + } + else + { + if(value < min) min = value; + if(value > max) max = value; + } + } + + // handle the case that no valid range was found + if(min > max) min = max; + + // fix range + if(max - min < steps) max = Math.min(min + steps, 255); + if(max - min < steps) min = Math.max(max - steps, 0); + + return {min, max}; +} + +function setAlphaCodeBook(min, max, steps) +{ + // set up the alpha code book + let codes = [min, max, ...Array.from({length:steps-1}, (_,i)=>{ + return Math.floor( ( (steps - (i+1) ) * min + (i+1) * max ) / steps ); + })]; + if(steps === 5) + { + codes[6] = 0; + codes[7] = 255; + } + return codes; +} + +function fitCodes(rgba, mask, codes, indices) +{ + // fit each alpha value to the codebook + let err = 0; + for( let i = 0; i < 16; ++i ) + { + // check this pixel is valid + let bit = 1 << i; + if( ( mask & bit ) == 0 ) + { + // use the first code + indices[i] = 0; + continue; + } + + // find the least error and corresponding index + let value = rgba[4*i + 3]; + let least = Infinity; + let index = 0; + for( let j = 0; j < 8; ++j ) + { + // get the squared error from this code + let dist = value - codes[j]; + dist *= dist; + + // compare with the best so far + if( dist < least ) + { + least = dist; + index = j; + } + } + + // save this index and accumulate the error + indices[i] = index; + err += least; + } + + // return the total error + return err; +} + +function writeAlphaBlock5({min:alpha0, max:alpha1, indices}, result, offset) +{ + // check the relative values of the endpoints + if( alpha0 > alpha1 ) + { + //swap the indices; + const swapped = indices.map((index)=>{ + if(index === 0) return 1; + if(index === 1) return 0; + if(index <= 5) return 7-index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } + else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7({min:alpha0, max:alpha1, indices}, result, offset) +{ + // check the relative values of the endpoints + if( alpha0 > alpha1 ) + { + //swap the indices; + const swapped = indices.map((index)=>{ + if(index === 0) return 1; + if(index === 1) return 0; + return 9-index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } + else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) +{ + // write the first two bytes + result[offset] = alpha0; + result[offset + 1] = alpha1; + + // pack the indices with 3 bits each + let indicesPointer = 0; + let resultPointer = offset + 2; + + for( let i = 0; i < 2; i++ ) + { + // pack 8 3-bit values + let value = 0; + for( let j = 0; j < 8; ++j ) + { + let index = indices[indicesPointer]; + value |= ( index << 3*j ); + indicesPointer++; + } + + // store in 3 bytes + for( let j = 0; j < 3; ++j ) + { + let byte = ( value >> 8*j ) & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + + +export {compressAlphaDxt3, compressAlphaDxt5, setAlphaCodeBook}; \ No newline at end of file diff --git a/src/readers/libs/dxt/colorBlock.js b/src/readers/libs/dxt/colorBlock.js new file mode 100644 index 0000000..33350b2 --- /dev/null +++ b/src/readers/libs/dxt/colorBlock.js @@ -0,0 +1,111 @@ +import {Vec3} from "./math.js"; + +function floatToInt(value, limit) +{ + // use ANSI round-to-zero behaviour to get round-to-nearest + const integer = parseInt( value + 0.5 ); + + // clamp to the limit + if(integer < 0) return 0; + if(integer > limit) return integer; + return integer; +} + +function floatTo565( color ) +{ + // get the components in the correct range + const r = floatToInt( 31.0*color.x, 31 ); + const g = floatToInt( 63.0*color.y, 63 ); + const b = floatToInt( 31.0*color.z, 31 ); + + // pack into a single value + return ( r << 11 ) | ( g << 5 ) | b; +} + +/** + * @param {int} packed 16bit first color + * @param {int} packed 16bit second color + * @param {Array(int)} each pixel block's index data + * @param {Uint8Array} the array to save result + * @param {int} the array's offset + */ +function writeColourBlock( firstColor, secondColor, indices, result, blockOffset ) +{ + // write the endpoints as little endian + result[blockOffset + 0] = firstColor & 0xff ; + result[blockOffset + 1] = firstColor >> 8 ; + result[blockOffset + 2] = secondColor & 0xff ; + result[blockOffset + 3] = secondColor >> 8 ; + + // write the indices as big endian like [33221100] + for( let y = 0; y < 4; y++ ) + { + result[blockOffset + 4 + y] = ( indices[4*y + 0] | + ( indices[4*y + 1] << 2 ) | + ( indices[4*y + 2] << 4 ) | + ( indices[4*y + 3] << 6 ) ); + } +} + + +/** + * @param {Vec3} first color + * @param {Vec3} second color + * @param {Array(int)} each pixel block's index data + * @param {Uint8Array} the array to save result + * @param {int} the array's offset + */ +function writeColourBlock3( start, end, indices, result, blockOffset ) +{ + // get the packed values + let firstColor = floatTo565( start ); + let secondColor = floatTo565( end ); + + // remap the indices + let remapped; + if( firstColor <= secondColor ) + { + // use the indices directly + remapped = indices.slice(); + } + else + { + // swap a and b + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map((index) => (index===0) ? 1 : ( (index===1) ? 0 : index) ); + } + + // write the block + writeColourBlock( firstColor, secondColor, remapped, result, blockOffset ); +} + +function writeColourBlock4( start, end, indices, result, blockOffset ) +{ + // get the packed values + let firstColor = floatTo565( start ); + let secondColor = floatTo565( end ); + + // remap the indices + let remapped; + if( firstColor < secondColor ) + { + // swap a and b + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map((index) => (index^0x1) & 0x3); + } + else if( firstColor == secondColor ) + { + // use index 0 + remapped = new Array(16).fill(0); + } + else + { + // use the indices directly + remapped = indices.slice(); + } + + // write the block + writeColourBlock( firstColor, secondColor, remapped, result, blockOffset ); +} + +export {writeColourBlock3, writeColourBlock4}; \ No newline at end of file diff --git a/src/readers/libs/dxt/colorFits.js b/src/readers/libs/dxt/colorFits.js new file mode 100644 index 0000000..1fa650e --- /dev/null +++ b/src/readers/libs/dxt/colorFits.js @@ -0,0 +1,744 @@ +/* ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Copyright (c) 2007 Ignacio Castano icastano@nvidia.com + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ + +import {kDxt1, kDxt3, kDxt5, + kColourIterativeClusterFit, kColourClusterFit, kColourRangeFit, + kColourMetricPerceptual, kColourMetricUniform, kWeightColourByAlpha +} from "./constant.js"; +import {Vec3, Vec4, computePCA} from "./math.js"; +import {lookup_5_3, lookup_6_3, lookup_5_4, lookup_6_4} from "./lookup.js"; +import {writeColourBlock3, writeColourBlock4} from "./colorBlock.js"; + +class ColorSet +{ + constructor(rgba, mask, flags) + { + /** + * this colorset's flags + * @public + * @type {Number} + */ + this.flags = flags; + /** + * the number of colors + * @private + * @type {Number} + */ + this._count = 0; + /** + * the number of colors + * @private + * @type {boolean} + */ + this._transparent = false; + + /** + * the indices of color + * @private + * @type {Array(Number)} + */ + this._remap = []; + /** + * Weighted by how many colors there are + * @private + * @type {Array(Number)} + */ + this._weights = []; + /** + * the color data + * @private + * @type {Array(Vec3)} + */ + this._points = []; + + const isDxt1 = ( (this.flags & kDxt1) != 0); + const weightByAlpha = ( (this.flags & kWeightColourByAlpha ) != 0); + + // create the minimal set + for( let i = 0; i < 16; i++ ) + { + // check this pixel is enabled + const bit = 1 << i; + if( ( mask & bit ) == 0 ) + { + this._remap[i] = -1; + continue; + } + + // check for transparent pixels when using dxt1 + if( isDxt1 && rgba[4*i + 3] < 128 ) + { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + // loop over previous points for a match + for( let j = 0;; j++ ) + { + // allocate a new point + if( j == i ) + { + // normalise coordinates to [0,1] + const r = rgba[4*i] / 255.0; + const g = rgba[4*i + 1] / 255.0; + const b = rgba[4*i + 2] / 255.0; + + // ensure there is always non-zero weight even for zero alpha + const a = ( rgba[4*i + 3] + 1 ) / 256.0; + + // add the point + this._points[this._count] = new Vec3( r, g, b ); + this._weights[this._count] = ( weightByAlpha ? a : 1.0 ); + this._remap[i] = this._count; + + // advance + this._count++; + break; + } + + // check for a match + const oldbit = 1 << j; + const match = ( ( mask & oldbit ) != 0 ) + && ( rgba[4*i] == rgba[4*j] ) + && ( rgba[4*i + 1] == rgba[4*j + 1] ) + && ( rgba[4*i + 2] == rgba[4*j + 2] ) + && ( rgba[4*j + 3] >= 128 || !isDxt1 ); + if( match ) + { + // get the index of the match + const index = this._remap[j]; + + // ensure there is always non-zero weight even for zero alpha + const w = ( rgba[4*i + 3] + 1 ) / 256.0; + + // map to this point and increase the weight + this._weights[index] += ( weightByAlpha ? w : 1.0 ); + this._remap[i] = index; + break; + } + } + } + + // square root the weights + for( let i = 0; i < this._count; ++i ) + this._weights[i] = Math.sqrt( this._weights[i] ); + } + + get transparent() + { + return this._transparent; + } + get count() + { + return this._count; + } + get points() + { + return Object.freeze(this._points.slice()); + } + get weights() + { + return Object.freeze(this._weights.slice()); + } + + /** + * @param {int} index no + * @param {Uint8Array} Colormap index to store the result + */ + remapIndicesSingle(singleIndex, target) + { + const result = this._remap.map((index)=>index===-1 ? 3 : singleIndex); + target.forEach((_,i)=>target[i]=result[i]); + } + /** + * @example + * this.remap=[0,1,2,3, 2,2,3,4, 3,4,6,6, 7,5,5,0] + * indexMap = [0,0,1,1,2,2,3,3] + * target(result) => [0,0,1,1, 1,1,1,2, 1,1,3,3, 3,2,2,0] + * @param {Uint8Array} map of index numbers to fill + * @param {Uint8Array} Colormap index to store the result + */ + remapIndices(indexMap, target) + { + const result = this._remap.map((index)=>index===-1 ? 3 : indexMap[index]); + target.forEach((_,i)=>target[i]=result[i]); + } +} + +class ColorFit +{ + constructor(colorSet) + { + this.colors = colorSet; + this.flags = colorSet.flags; + } + compress(result, offset) + { + const isDxt1 = ( (this.flags & kDxt1) != 0); + if(isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } + else this.compress4(result, offset); + } + compress3(result, offset){} + compress4(result, offset){} +} + +class SingleColourFit extends ColorFit +{ + constructor(colorSet) + { + super(colorSet); + + // grab the single colour + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + + // private property + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + + this.error = Infinity; + this.bestError = Infinity; + } + compressBase(lookups, saveFunc) + { + this.computeEndPoints(lookups); + + if(this.error < this.bestError) + { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + + this.bestError = this.error; + } + } + compress3(result, offset) + { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + compress4(result, offset) + { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + computeEndPoints(lookups) + { + // check each index combination (endpoint or intermediate) + this.error = Infinity; + for( let index = 0; index < 2; index++ ) + { + // check the error for this codebook index + const sources = []; //source : [channel][start/end/error] + let error = 0; + for( let channel = 0; channel < 3; channel++ ) + { + // grab the lookup table and index for this channel + const lookup = lookups[channel]; //lookup : [rgb-raw index][startpoint/midpoint] + const target = this.color[channel]; + + // store a pointer to the source for this channel + sources[channel] = lookup[target][index]; + + // accumulate the error + const diff = sources[channel][2]; + error += diff*diff; + } + + // keep it if the error is lower + if( error < this.error ) + { + this.start = new Vec3( + sources[0][0]/31.0, + sources[1][0]/63.0, + sources[2][0]/31.0 + ); + this.end = new Vec3( + sources[0][1]/31.0, + sources[1][1]/63.0, + sources[2][1]/31.0 + ); + this.index = 2*index ; // 0:startpoint, 2:midpoint + this.error = error; + } + } + } +} + +class RangeFit extends ColorFit +{ + constructor(colorSet) + { + super(colorSet); + + this.metric = new Vec3(1); + if( (this.flags & kColourMetricPerceptual) !== 0) + { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + // private property + this.start = new Vec3(0); + this.end = new Vec3(0); + + this.bestError = Infinity; + + //compute start&end points + this.computePoints(); + } + compressBase(codes, saveFunc) + { + const {points:values} = this.colors; + + let error = 0; + + // Map the closest code of each color + const closest = values.map((color)=>{ + let minDist = Infinity; + + // find the closest code + const packedIndex = codes.reduce((idx, code, j)=>{ + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + + if(dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + + // accumulate the error + error += minDist; + + // save the index + return packedIndex; + }); + + // save this scheme if it wins + if( error < this.bestError ) + { + // remap the indices + let indices = new Uint8Array(16); + this.colors.remapIndices( closest, indices ); + + // save the block + saveFunc( this.start, this.end, indices ); + + // save the error + this.bestError = error; + } + } + compress3(result, offset) + { + const codes=[ + this.start.clone(), + this.end.clone(), + Vec3.interpolate(this.start, this.end, 0.5) + ]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + compress4(result, offset) + { + const codes=[ + this.start.clone(), + this.end.clone(), + Vec3.interpolate(this.start, this.end, 1/3), + Vec3.interpolate(this.start, this.end, 2/3), + ]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + computePoints() + { + const {count, points:values, weights} = this.colors; + if(count <= 0) return; + + //dimension regression + const principle = computePCA(values, weights); + + let start, end, min, max; + + start=end=values[0]; + min=max=Vec3.dot(start, principle); + + //compute the range + for(let i=1; i max) + { + end = values[i]; + max = value; + } + } + + // clamp to the grid and save + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } +} + + +class ClusterFit extends ColorFit +{ + constructor(colorSet) + { + super(colorSet); + + // set the iteration count + const kMaxIterations = 8; + this.iterationCount = (colorSet.flags & kColourIterativeClusterFit) ? kMaxIterations : 1; + + // initialise the best error + this.bestError = Infinity; + + // initialise the metric + this.metric = new Vec4(1); + if( (this.flags & kColourMetricPerceptual) !== 0) + { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + // dimension regression + const {points:values, weights} = this.colors; + this.principle = computePCA(values, weights); + + // private property + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights=[]; //Array(Vec4)[16] + this.xSum_wSum = new Vec4(0); //Vec4 + } + + /* + * main Logics + */ + constructOrdering(axis, iteration) + { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration) + + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if(!uniqueOrder) return false; + + this.copyOrderWeight(currentOrder); + + return true; + } + compress3(result, offset) + { + const aabbx = ([part0, , part1, part2])=>{ + const const1_2 = new Vec4(1/2, 1/2, 1/2, 1/4); + + const alphax_sum = Vec4.multiplyAdd( part1, const1_2, part0 ); + const alpha2_sum = alphax_sum.splatW; + + const betax_sum = Vec4.multiplyAdd( part1, const1_2, part2 ); + const beta2_sum = betax_sum.splatW; + + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + + return { + ax:alphax_sum, + aa:alpha2_sum, + bx:betax_sum, + bb:beta2_sum, + ab:alphabeta_sum + } + }; + const saveFunc = (start, end, indices)=>writeColourBlock3(start, end, indices, result, offset); + this.compressBase(aabbx, saveFunc, 2); + } + compress4(result, offset) + { + const aabbx = ([part0, part1, part2, part3])=>{ + const const1_3 = new Vec4(1/3, 1/3, 1/3, 1/9); + const const2_3 = new Vec4(2/3, 2/3, 2/3, 4/9); + const const2_9 = new Vec4(2/9); + + const alphax_sum = Vec4.multiplyAdd( part2, const1_3, Vec4.multiplyAdd( part1, const2_3, part0 ) ); + const alpha2_sum = alphax_sum.splatW; + + const betax_sum = Vec4.multiplyAdd( part1, const1_3, Vec4.multiplyAdd( part2, const2_3, part3 ) ); + const beta2_sum = betax_sum.splatW; + + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + + return { + ax:alphax_sum, + aa:alpha2_sum, + bx:betax_sum, + bb:beta2_sum, + ab:alphabeta_sum + } + }; + const saveFunc = (start, end, indices)=>writeColourBlock4(start, end, indices, result, offset); + this.compressBase(aabbx, saveFunc, 3); + } + compressBase(aabbFunc, saveFunc, repeater=2) + { + // prepare an ordering using the principle axis + this.constructOrdering(this.principle, 0); + + // check all possible clusters and iterate on the total order + let best = { + start : new Vec4(0), + end : new Vec4(0), + error : this.bestError, + iteration : 0, + bestI : 0, + bestJ : 0, + }; + if(repeater === 3) best.bestK = 0; + + // inner least squares terms function + const leastSquares = (parts, internalIndices)=>{ + const aabbx = aabbFunc(parts); + + const internalBest = this.computeOptimalPoints(aabbx); + + if(internalBest.error < best.error) + { + // keep the solution if it wins + best = {...internalBest, ...internalIndices}; + return true; + } + return false; + }; + + // loop over iterations (we avoid the case that all points in first or last cluster) + for( let iterationIndex = 0;; ) + { + this.clusterIterate(iterationIndex, leastSquares, repeater); + + // stop if we didn't improve in this iteration + if( best.iteration != iterationIndex ) break; + + // advance if possible + iterationIndex++; + if( iterationIndex == this.iterationCount ) break; + + // stop if a new iteration is an ordering that has already been tried + const newAxis = Vec4.sub( best.end, best.start ).xyz; + if( !this.constructOrdering( newAxis, iterationIndex ) ) break; + } + + // save the block if win + if(best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + /* + * for constructOrdering function + */ + makeOrder(axis) + { + const {count, points:values} = this.colors; + + // map dot products and stable sort + // result : [1st index of color, 2nd index of color, ...] + const dotProducts=values.map((color, i)=>Vec3.dot(color, axis)); + return Array.from({length:count},(_,i)=>i) + .sort((a,b)=>{ + if(dotProducts[a]-dotProducts[b] != 0) return dotProducts[a]-dotProducts[b]; + return a-b; + }); + } + copyOrderToThisOrder(order, iteration) + { + //copy currentOrder array to this.order + const orderOffset = iteration * 16; + order.forEach((ord, i)=>{ + this.order[orderOffset + i] = ord; + }); + } + checkOrderUnique(order, iteration) + { + // check this ordering is unique + const {count} = this.colors; + + for(let it =0; it{ + if(m < bestI) return 0; + if(m < bestJ) return 2; + if(m < bestK) return 3; + return 1; + } + for(let i=0; i{ + const mapper = { + bestI:i, + bestJ:( iterCount === 2 ? k : j ), + iteration : index + }; + if(iterCount === 3) mapper.bestK = k; + return mapper; + }; + + // first cluster [0,i) is at the start + let part0 = new Vec4( 0.0 ); + for( let i = 0; i < count; i++ ) + { + // second cluster [i,j) is half along + let part1 = new Vec4( 0.0 ); + for( let j = i;; ) + { + // third cluster [j,k) is two thirds along + let preLastPart = ( j == 0 ) ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = ( j == 0 ) ? 1 : j; + for( let k = kmin;; ) + { + // last cluster [k,count) is at the end + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + + // advance + if( k == count ) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + // if iterCount === 2(=using Compress3), j iteration is not used + if(iterCount === 2) break; + + // advance + if(j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + // advance + part0.addVector(this.pointsWeights[i]); + } + } +} + + +export {ColorSet, SingleColourFit, RangeFit, ClusterFit}; \ No newline at end of file diff --git a/src/readers/libs/dxt/constant.js b/src/readers/libs/dxt/constant.js new file mode 100644 index 0000000..9a9ce93 --- /dev/null +++ b/src/readers/libs/dxt/constant.js @@ -0,0 +1,21 @@ +//constant values +const kDxt1 = ( 1 << 0 ); //! Use DXT1 compression. +const kDxt3 = ( 1 << 1 ); //! Use DXT3 compression. +const kDxt5 = ( 1 << 2 ); //! Use DXT5 compression. +const kColourIterativeClusterFit = ( 1 << 8 ); //! Use a very slow but very high quality colour compressor. +const kColourClusterFit = ( 1 << 3 ); //! Use a slow but high quality colour compressor (the default). +const kColourRangeFit = ( 1 << 4 ); //! Use a fast but low quality colour compressor. +const kColourMetricPerceptual = ( 1 << 5 ); //! Use a perceptual metric for colour error (the default). +const kColourMetricUniform = ( 1 << 6 ); //! Use a uniform metric for colour error. +const kWeightColourByAlpha = ( 1 << 7 ); //! Weight the colour by alpha during cluster fit (disabled by default). + +export {kDxt1, + kDxt3, + kDxt5, + kColourIterativeClusterFit, + kColourClusterFit, + kColourRangeFit, + kColourMetricPerceptual, + kColourMetricUniform, + kWeightColourByAlpha +}; \ No newline at end of file diff --git a/src/readers/libs/dxt/decompressor.js b/src/readers/libs/dxt/decompressor.js new file mode 100644 index 0000000..b4d9c4b --- /dev/null +++ b/src/readers/libs/dxt/decompressor.js @@ -0,0 +1,163 @@ +import {setAlphaCodeBook} from "./alphaCompressor.js"; + +function unpack565(color16bit) +{ + // get the components in the stored range + const red = (color16bit >> 11) & 0x1f; + const green = (color16bit >> 5) & 0x3f; + const blue = color16bit & 0x1f; + + // scale up to 8 bits + return [ + ( red << 3 ) | ( red >> 2 ), + ( green << 2 ) | ( green >> 4 ), + ( blue << 3 ) | ( blue >> 2 ), + 255 + ]; +} + +function interpolateColorArray(a, b, amount) +{ + const result = a.map((aColor, i)=>Math.floor( aColor * (1-amount) + b[i] * amount) ); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) +{ + const color1 = block[offset] | (block[offset+1] << 8); + const color2 = block[offset+2] | (block[offset+3] << 8); + + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + + return [ + unpackedColor1, + unpackedColor2, + ( isDxt1 && color1 <= color2 ) ? + interpolateColorArray(unpackedColor1, unpackedColor2, 1/2) : + interpolateColorArray(unpackedColor1, unpackedColor2, 1/3), + ( isDxt1 && color1 <= color2 ) ? [0, 0, 0, 0] : + interpolateColorArray(unpackedColor1, unpackedColor2, 2/3) + ]; +} + +function unpackIndices(block, blockOffset) +{ + // unpack the indices + let offset = blockOffset + 4; + let result = new Uint8Array(16); + for(let i=0;i < 4; i++) + { + let packedIndices = block[offset + i]; + result[i*4 + 0] = packedIndices & 0x3; + result[i*4 + 1] = (packedIndices>>2) & 0x3; + result[i*4 + 2] = (packedIndices>>4) & 0x3; + result[i*4 + 3] = (packedIndices>>6) & 0x3; + } + return result; +} + + +/** + * @param {Uint8Array} Buffer in which the decompressed result will be stored + * @param {Uint8Array} compressed data + * @param {int} compressed data's offset + * @param {boolean} is using DXT1 + */ + +function decompressColor(rgba, block, offset, isDxt1) +{ + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + // store out the colours + for( let i = 0; i < 16; i++ ) + { + for( let j = 0; j < 4; j++ ) { + rgba[4*i + j] = colorCode[ indices[i]][j]; + } + } +} +/* + compressed color bites are like this: + [color1(low)] + [color1(high)] + [color2(low)] + [color2(high)] + [id3|id2|id1|id0] + [id7|id6|id5|id4] + [id11|id10|id9|id8] + [id15|id14|id13|id12] +*/ + + +/** + * @param {Uint8Array} Buffer in which the decompressed result will be stored + * @param {Uint8Array} compressed data + * @param {int} compressed data's offset + */ +function decompressAlphaDxt3(rgba, block, offset) +{ + // unpack the alpha values pairwise + for( let i = 0; i < 8; ++i ) + { + // quantise down to 4 bits + let quant = block[offset + i]; + + // unpack the values + let lo = quant & 0x0f; + let hi = quant & 0xf0; + + // convert back up to bytes + rgba[8*i + 3] = lo | ( lo << 4 ); + rgba[8*i + 7] = hi | ( hi >> 4 ); + } +} + +/** + * @param {Uint8Array} Buffer in which the decompressed result will be stored + * @param {Uint8Array} compressed data + * @param {int} compressed data's offset + */ +function decompressAlphaDxt5(rgba, block, offset) +{ + // get the two alpha values + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + + // compare the values to build the codebook + let codes = setAlphaCodeBook(alpha0, alpha1, (alpha0 <= alpha1) ? 5 : 7); + + // decode the indices + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for( let i = 0; i < 2; i++ ) + { + // grab 3 bytes + let value = 0; + for( let j = 0; j < 3; j++ ) + { + let byte = block[offset + bytePointer]; + value |= ( byte << 8*j ); + bytePointer++; + } + + // unpack 8 3-bit values from it + for( let j = 0; j < 8; j++ ) + { + let index = ( value >> 3*j ) & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + // write out the indexed codebook values + for( let i = 0; i < 16; ++i ) { + rgba[4*i + 3] = codes[indices[i]]; + } +} + +export {decompressColor, decompressAlphaDxt3, decompressAlphaDxt5}; \ No newline at end of file diff --git a/src/readers/libs/dxt/eigs.js b/src/readers/libs/dxt/eigs.js new file mode 100644 index 0000000..67ef201 --- /dev/null +++ b/src/readers/libs/dxt/eigs.js @@ -0,0 +1,162 @@ +/* + * get Eigen-values and Eigen-vectors from symmetric matrix + * I can use it directly because covarience matrix is symmetric - Lybell + * from DiagonalizeJS : https://github.com/arkajitmandal/DiagonalizeJS + * made by Arkajit Mandal + */ + +// Rotation Matrix +function Rot(theta){ + let Mat = [[Math.cos(theta),Math.sin(theta)],[-Math.sin(theta),Math.cos(theta)]]; + return Mat +} +// Givens Matrix +function Rij(k,l,theta,N){ + let Mat = Array(N) + for (let i = 0; i= Math.abs(e0)){ + // block index to be rotated + let i = Vab[0][0]; + let j = Vab[0][1]; + // get theta + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + // Givens matrix + let Gij = Rij(i,j,psi,N); + // rotate Hamiltonian using Givens + Hij = unitary(Gij,Hij); + // Update vectors + Sij = AxB(Sij,Gij); + // update error + Vab = getAij(Hij); + } + for (let i = 0; i{ + let vector = vectors.map((v)=>v[i]); + return {value:values[i], vec:vector}; + }); + pairs.sort((a,b)=>b.value - a.value); + + let sortedValues = pairs.map(({value})=>value); + let sortedVectors = pairs.map(({vec})=>vec); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) +{ + let [,[dominentVector]] = eigens(matrix); + return dominentVector; +} + +export {eigens, dominentPrincipalVector}; \ No newline at end of file diff --git a/src/readers/libs/dxt/lookup.js b/src/readers/libs/dxt/lookup.js new file mode 100644 index 0000000..ad5d570 --- /dev/null +++ b/src/readers/libs/dxt/lookup.js @@ -0,0 +1,1041 @@ +const lookup_5_3 = +[ + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 1 ], [ 0, 0, 1 ] ], + [ [ 0, 0, 2 ], [ 0, 0, 2 ] ], + [ [ 0, 0, 3 ], [ 0, 1, 1 ] ], + [ [ 0, 0, 4 ], [ 0, 1, 0 ] ], + [ [ 1, 0, 3 ], [ 0, 1, 1 ] ], + [ [ 1, 0, 2 ], [ 0, 1, 2 ] ], + [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], + [ [ 1, 0, 0 ], [ 0, 2, 0 ] ], + [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], + [ [ 1, 0, 2 ], [ 0, 2, 2 ] ], + [ [ 1, 0, 3 ], [ 0, 3, 1 ] ], + [ [ 1, 0, 4 ], [ 0, 3, 0 ] ], + [ [ 2, 0, 3 ], [ 0, 3, 1 ] ], + [ [ 2, 0, 2 ], [ 0, 3, 2 ] ], + [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], + [ [ 2, 0, 0 ], [ 0, 4, 0 ] ], + [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], + [ [ 2, 0, 2 ], [ 0, 4, 2 ] ], + [ [ 2, 0, 3 ], [ 0, 5, 1 ] ], + [ [ 2, 0, 4 ], [ 0, 5, 0 ] ], + [ [ 3, 0, 3 ], [ 0, 5, 1 ] ], + [ [ 3, 0, 2 ], [ 0, 5, 2 ] ], + [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], + [ [ 3, 0, 0 ], [ 0, 6, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], + [ [ 3, 0, 2 ], [ 0, 6, 2 ] ], + [ [ 3, 0, 3 ], [ 0, 7, 1 ] ], + [ [ 3, 0, 4 ], [ 0, 7, 0 ] ], + [ [ 4, 0, 4 ], [ 0, 7, 1 ] ], + [ [ 4, 0, 3 ], [ 0, 7, 2 ] ], + [ [ 4, 0, 2 ], [ 1, 7, 1 ] ], + [ [ 4, 0, 1 ], [ 1, 7, 0 ] ], + [ [ 4, 0, 0 ], [ 0, 8, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 8, 1 ] ], + [ [ 4, 0, 2 ], [ 2, 7, 1 ] ], + [ [ 4, 0, 3 ], [ 2, 7, 0 ] ], + [ [ 4, 0, 4 ], [ 0, 9, 0 ] ], + [ [ 5, 0, 3 ], [ 0, 9, 1 ] ], + [ [ 5, 0, 2 ], [ 3, 7, 1 ] ], + [ [ 5, 0, 1 ], [ 3, 7, 0 ] ], + [ [ 5, 0, 0 ], [ 0, 10, 0 ] ], + [ [ 5, 0, 1 ], [ 0, 10, 1 ] ], + [ [ 5, 0, 2 ], [ 0, 10, 2 ] ], + [ [ 5, 0, 3 ], [ 0, 11, 1 ] ], + [ [ 5, 0, 4 ], [ 0, 11, 0 ] ], + [ [ 6, 0, 3 ], [ 0, 11, 1 ] ], + [ [ 6, 0, 2 ], [ 0, 11, 2 ] ], + [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], + [ [ 6, 0, 0 ], [ 0, 12, 0 ] ], + [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], + [ [ 6, 0, 2 ], [ 0, 12, 2 ] ], + [ [ 6, 0, 3 ], [ 0, 13, 1 ] ], + [ [ 6, 0, 4 ], [ 0, 13, 0 ] ], + [ [ 7, 0, 3 ], [ 0, 13, 1 ] ], + [ [ 7, 0, 2 ], [ 0, 13, 2 ] ], + [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], + [ [ 7, 0, 0 ], [ 0, 14, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], + [ [ 7, 0, 2 ], [ 0, 14, 2 ] ], + [ [ 7, 0, 3 ], [ 0, 15, 1 ] ], + [ [ 7, 0, 4 ], [ 0, 15, 0 ] ], + [ [ 8, 0, 4 ], [ 0, 15, 1 ] ], + [ [ 8, 0, 3 ], [ 0, 15, 2 ] ], + [ [ 8, 0, 2 ], [ 1, 15, 1 ] ], + [ [ 8, 0, 1 ], [ 1, 15, 0 ] ], + [ [ 8, 0, 0 ], [ 0, 16, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 16, 1 ] ], + [ [ 8, 0, 2 ], [ 2, 15, 1 ] ], + [ [ 8, 0, 3 ], [ 2, 15, 0 ] ], + [ [ 8, 0, 4 ], [ 0, 17, 0 ] ], + [ [ 9, 0, 3 ], [ 0, 17, 1 ] ], + [ [ 9, 0, 2 ], [ 3, 15, 1 ] ], + [ [ 9, 0, 1 ], [ 3, 15, 0 ] ], + [ [ 9, 0, 0 ], [ 0, 18, 0 ] ], + [ [ 9, 0, 1 ], [ 0, 18, 1 ] ], + [ [ 9, 0, 2 ], [ 0, 18, 2 ] ], + [ [ 9, 0, 3 ], [ 0, 19, 1 ] ], + [ [ 9, 0, 4 ], [ 0, 19, 0 ] ], + [ [ 10, 0, 3 ], [ 0, 19, 1 ] ], + [ [ 10, 0, 2 ], [ 0, 19, 2 ] ], + [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], + [ [ 10, 0, 0 ], [ 0, 20, 0 ] ], + [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], + [ [ 10, 0, 2 ], [ 0, 20, 2 ] ], + [ [ 10, 0, 3 ], [ 0, 21, 1 ] ], + [ [ 10, 0, 4 ], [ 0, 21, 0 ] ], + [ [ 11, 0, 3 ], [ 0, 21, 1 ] ], + [ [ 11, 0, 2 ], [ 0, 21, 2 ] ], + [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], + [ [ 11, 0, 0 ], [ 0, 22, 0 ] ], + [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], + [ [ 11, 0, 2 ], [ 0, 22, 2 ] ], + [ [ 11, 0, 3 ], [ 0, 23, 1 ] ], + [ [ 11, 0, 4 ], [ 0, 23, 0 ] ], + [ [ 12, 0, 4 ], [ 0, 23, 1 ] ], + [ [ 12, 0, 3 ], [ 0, 23, 2 ] ], + [ [ 12, 0, 2 ], [ 1, 23, 1 ] ], + [ [ 12, 0, 1 ], [ 1, 23, 0 ] ], + [ [ 12, 0, 0 ], [ 0, 24, 0 ] ], + [ [ 12, 0, 1 ], [ 0, 24, 1 ] ], + [ [ 12, 0, 2 ], [ 2, 23, 1 ] ], + [ [ 12, 0, 3 ], [ 2, 23, 0 ] ], + [ [ 12, 0, 4 ], [ 0, 25, 0 ] ], + [ [ 13, 0, 3 ], [ 0, 25, 1 ] ], + [ [ 13, 0, 2 ], [ 3, 23, 1 ] ], + [ [ 13, 0, 1 ], [ 3, 23, 0 ] ], + [ [ 13, 0, 0 ], [ 0, 26, 0 ] ], + [ [ 13, 0, 1 ], [ 0, 26, 1 ] ], + [ [ 13, 0, 2 ], [ 0, 26, 2 ] ], + [ [ 13, 0, 3 ], [ 0, 27, 1 ] ], + [ [ 13, 0, 4 ], [ 0, 27, 0 ] ], + [ [ 14, 0, 3 ], [ 0, 27, 1 ] ], + [ [ 14, 0, 2 ], [ 0, 27, 2 ] ], + [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], + [ [ 14, 0, 0 ], [ 0, 28, 0 ] ], + [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], + [ [ 14, 0, 2 ], [ 0, 28, 2 ] ], + [ [ 14, 0, 3 ], [ 0, 29, 1 ] ], + [ [ 14, 0, 4 ], [ 0, 29, 0 ] ], + [ [ 15, 0, 3 ], [ 0, 29, 1 ] ], + [ [ 15, 0, 2 ], [ 0, 29, 2 ] ], + [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], + [ [ 15, 0, 0 ], [ 0, 30, 0 ] ], + [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], + [ [ 15, 0, 2 ], [ 0, 30, 2 ] ], + [ [ 15, 0, 3 ], [ 0, 31, 1 ] ], + [ [ 15, 0, 4 ], [ 0, 31, 0 ] ], + [ [ 16, 0, 4 ], [ 0, 31, 1 ] ], + [ [ 16, 0, 3 ], [ 0, 31, 2 ] ], + [ [ 16, 0, 2 ], [ 1, 31, 1 ] ], + [ [ 16, 0, 1 ], [ 1, 31, 0 ] ], + [ [ 16, 0, 0 ], [ 4, 28, 0 ] ], + [ [ 16, 0, 1 ], [ 4, 28, 1 ] ], + [ [ 16, 0, 2 ], [ 2, 31, 1 ] ], + [ [ 16, 0, 3 ], [ 2, 31, 0 ] ], + [ [ 16, 0, 4 ], [ 4, 29, 0 ] ], + [ [ 17, 0, 3 ], [ 4, 29, 1 ] ], + [ [ 17, 0, 2 ], [ 3, 31, 1 ] ], + [ [ 17, 0, 1 ], [ 3, 31, 0 ] ], + [ [ 17, 0, 0 ], [ 4, 30, 0 ] ], + [ [ 17, 0, 1 ], [ 4, 30, 1 ] ], + [ [ 17, 0, 2 ], [ 4, 30, 2 ] ], + [ [ 17, 0, 3 ], [ 4, 31, 1 ] ], + [ [ 17, 0, 4 ], [ 4, 31, 0 ] ], + [ [ 18, 0, 3 ], [ 4, 31, 1 ] ], + [ [ 18, 0, 2 ], [ 4, 31, 2 ] ], + [ [ 18, 0, 1 ], [ 5, 31, 1 ] ], + [ [ 18, 0, 0 ], [ 5, 31, 0 ] ], + [ [ 18, 0, 1 ], [ 5, 31, 1 ] ], + [ [ 18, 0, 2 ], [ 5, 31, 2 ] ], + [ [ 18, 0, 3 ], [ 6, 31, 1 ] ], + [ [ 18, 0, 4 ], [ 6, 31, 0 ] ], + [ [ 19, 0, 3 ], [ 6, 31, 1 ] ], + [ [ 19, 0, 2 ], [ 6, 31, 2 ] ], + [ [ 19, 0, 1 ], [ 7, 31, 1 ] ], + [ [ 19, 0, 0 ], [ 7, 31, 0 ] ], + [ [ 19, 0, 1 ], [ 7, 31, 1 ] ], + [ [ 19, 0, 2 ], [ 7, 31, 2 ] ], + [ [ 19, 0, 3 ], [ 8, 31, 1 ] ], + [ [ 19, 0, 4 ], [ 8, 31, 0 ] ], + [ [ 20, 0, 4 ], [ 8, 31, 1 ] ], + [ [ 20, 0, 3 ], [ 8, 31, 2 ] ], + [ [ 20, 0, 2 ], [ 9, 31, 1 ] ], + [ [ 20, 0, 1 ], [ 9, 31, 0 ] ], + [ [ 20, 0, 0 ], [ 12, 28, 0 ] ], + [ [ 20, 0, 1 ], [ 12, 28, 1 ] ], + [ [ 20, 0, 2 ], [ 10, 31, 1 ] ], + [ [ 20, 0, 3 ], [ 10, 31, 0 ] ], + [ [ 20, 0, 4 ], [ 12, 29, 0 ] ], + [ [ 21, 0, 3 ], [ 12, 29, 1 ] ], + [ [ 21, 0, 2 ], [ 11, 31, 1 ] ], + [ [ 21, 0, 1 ], [ 11, 31, 0 ] ], + [ [ 21, 0, 0 ], [ 12, 30, 0 ] ], + [ [ 21, 0, 1 ], [ 12, 30, 1 ] ], + [ [ 21, 0, 2 ], [ 12, 30, 2 ] ], + [ [ 21, 0, 3 ], [ 12, 31, 1 ] ], + [ [ 21, 0, 4 ], [ 12, 31, 0 ] ], + [ [ 22, 0, 3 ], [ 12, 31, 1 ] ], + [ [ 22, 0, 2 ], [ 12, 31, 2 ] ], + [ [ 22, 0, 1 ], [ 13, 31, 1 ] ], + [ [ 22, 0, 0 ], [ 13, 31, 0 ] ], + [ [ 22, 0, 1 ], [ 13, 31, 1 ] ], + [ [ 22, 0, 2 ], [ 13, 31, 2 ] ], + [ [ 22, 0, 3 ], [ 14, 31, 1 ] ], + [ [ 22, 0, 4 ], [ 14, 31, 0 ] ], + [ [ 23, 0, 3 ], [ 14, 31, 1 ] ], + [ [ 23, 0, 2 ], [ 14, 31, 2 ] ], + [ [ 23, 0, 1 ], [ 15, 31, 1 ] ], + [ [ 23, 0, 0 ], [ 15, 31, 0 ] ], + [ [ 23, 0, 1 ], [ 15, 31, 1 ] ], + [ [ 23, 0, 2 ], [ 15, 31, 2 ] ], + [ [ 23, 0, 3 ], [ 16, 31, 1 ] ], + [ [ 23, 0, 4 ], [ 16, 31, 0 ] ], + [ [ 24, 0, 4 ], [ 16, 31, 1 ] ], + [ [ 24, 0, 3 ], [ 16, 31, 2 ] ], + [ [ 24, 0, 2 ], [ 17, 31, 1 ] ], + [ [ 24, 0, 1 ], [ 17, 31, 0 ] ], + [ [ 24, 0, 0 ], [ 20, 28, 0 ] ], + [ [ 24, 0, 1 ], [ 20, 28, 1 ] ], + [ [ 24, 0, 2 ], [ 18, 31, 1 ] ], + [ [ 24, 0, 3 ], [ 18, 31, 0 ] ], + [ [ 24, 0, 4 ], [ 20, 29, 0 ] ], + [ [ 25, 0, 3 ], [ 20, 29, 1 ] ], + [ [ 25, 0, 2 ], [ 19, 31, 1 ] ], + [ [ 25, 0, 1 ], [ 19, 31, 0 ] ], + [ [ 25, 0, 0 ], [ 20, 30, 0 ] ], + [ [ 25, 0, 1 ], [ 20, 30, 1 ] ], + [ [ 25, 0, 2 ], [ 20, 30, 2 ] ], + [ [ 25, 0, 3 ], [ 20, 31, 1 ] ], + [ [ 25, 0, 4 ], [ 20, 31, 0 ] ], + [ [ 26, 0, 3 ], [ 20, 31, 1 ] ], + [ [ 26, 0, 2 ], [ 20, 31, 2 ] ], + [ [ 26, 0, 1 ], [ 21, 31, 1 ] ], + [ [ 26, 0, 0 ], [ 21, 31, 0 ] ], + [ [ 26, 0, 1 ], [ 21, 31, 1 ] ], + [ [ 26, 0, 2 ], [ 21, 31, 2 ] ], + [ [ 26, 0, 3 ], [ 22, 31, 1 ] ], + [ [ 26, 0, 4 ], [ 22, 31, 0 ] ], + [ [ 27, 0, 3 ], [ 22, 31, 1 ] ], + [ [ 27, 0, 2 ], [ 22, 31, 2 ] ], + [ [ 27, 0, 1 ], [ 23, 31, 1 ] ], + [ [ 27, 0, 0 ], [ 23, 31, 0 ] ], + [ [ 27, 0, 1 ], [ 23, 31, 1 ] ], + [ [ 27, 0, 2 ], [ 23, 31, 2 ] ], + [ [ 27, 0, 3 ], [ 24, 31, 1 ] ], + [ [ 27, 0, 4 ], [ 24, 31, 0 ] ], + [ [ 28, 0, 4 ], [ 24, 31, 1 ] ], + [ [ 28, 0, 3 ], [ 24, 31, 2 ] ], + [ [ 28, 0, 2 ], [ 25, 31, 1 ] ], + [ [ 28, 0, 1 ], [ 25, 31, 0 ] ], + [ [ 28, 0, 0 ], [ 28, 28, 0 ] ], + [ [ 28, 0, 1 ], [ 28, 28, 1 ] ], + [ [ 28, 0, 2 ], [ 26, 31, 1 ] ], + [ [ 28, 0, 3 ], [ 26, 31, 0 ] ], + [ [ 28, 0, 4 ], [ 28, 29, 0 ] ], + [ [ 29, 0, 3 ], [ 28, 29, 1 ] ], + [ [ 29, 0, 2 ], [ 27, 31, 1 ] ], + [ [ 29, 0, 1 ], [ 27, 31, 0 ] ], + [ [ 29, 0, 0 ], [ 28, 30, 0 ] ], + [ [ 29, 0, 1 ], [ 28, 30, 1 ] ], + [ [ 29, 0, 2 ], [ 28, 30, 2 ] ], + [ [ 29, 0, 3 ], [ 28, 31, 1 ] ], + [ [ 29, 0, 4 ], [ 28, 31, 0 ] ], + [ [ 30, 0, 3 ], [ 28, 31, 1 ] ], + [ [ 30, 0, 2 ], [ 28, 31, 2 ] ], + [ [ 30, 0, 1 ], [ 29, 31, 1 ] ], + [ [ 30, 0, 0 ], [ 29, 31, 0 ] ], + [ [ 30, 0, 1 ], [ 29, 31, 1 ] ], + [ [ 30, 0, 2 ], [ 29, 31, 2 ] ], + [ [ 30, 0, 3 ], [ 30, 31, 1 ] ], + [ [ 30, 0, 4 ], [ 30, 31, 0 ] ], + [ [ 31, 0, 3 ], [ 30, 31, 1 ] ], + [ [ 31, 0, 2 ], [ 30, 31, 2 ] ], + [ [ 31, 0, 1 ], [ 31, 31, 1 ] ], + [ [ 31, 0, 0 ], [ 31, 31, 0 ] ] +]; + +const lookup_6_3 = +[ + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 1 ], [ 0, 1, 1 ] ], + [ [ 0, 0, 2 ], [ 0, 1, 0 ] ], + [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], + [ [ 1, 0, 0 ], [ 0, 2, 0 ] ], + [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], + [ [ 1, 0, 2 ], [ 0, 3, 0 ] ], + [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], + [ [ 2, 0, 0 ], [ 0, 4, 0 ] ], + [ [ 2, 0, 1 ], [ 0, 5, 1 ] ], + [ [ 2, 0, 2 ], [ 0, 5, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], + [ [ 3, 0, 0 ], [ 0, 6, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 7, 1 ] ], + [ [ 3, 0, 2 ], [ 0, 7, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 8, 1 ] ], + [ [ 4, 0, 0 ], [ 0, 8, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 9, 1 ] ], + [ [ 4, 0, 2 ], [ 0, 9, 0 ] ], + [ [ 5, 0, 1 ], [ 0, 10, 1 ] ], + [ [ 5, 0, 0 ], [ 0, 10, 0 ] ], + [ [ 5, 0, 1 ], [ 0, 11, 1 ] ], + [ [ 5, 0, 2 ], [ 0, 11, 0 ] ], + [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], + [ [ 6, 0, 0 ], [ 0, 12, 0 ] ], + [ [ 6, 0, 1 ], [ 0, 13, 1 ] ], + [ [ 6, 0, 2 ], [ 0, 13, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], + [ [ 7, 0, 0 ], [ 0, 14, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 15, 1 ] ], + [ [ 7, 0, 2 ], [ 0, 15, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 16, 1 ] ], + [ [ 8, 0, 0 ], [ 0, 16, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 17, 1 ] ], + [ [ 8, 0, 2 ], [ 0, 17, 0 ] ], + [ [ 9, 0, 1 ], [ 0, 18, 1 ] ], + [ [ 9, 0, 0 ], [ 0, 18, 0 ] ], + [ [ 9, 0, 1 ], [ 0, 19, 1 ] ], + [ [ 9, 0, 2 ], [ 0, 19, 0 ] ], + [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], + [ [ 10, 0, 0 ], [ 0, 20, 0 ] ], + [ [ 10, 0, 1 ], [ 0, 21, 1 ] ], + [ [ 10, 0, 2 ], [ 0, 21, 0 ] ], + [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], + [ [ 11, 0, 0 ], [ 0, 22, 0 ] ], + [ [ 11, 0, 1 ], [ 0, 23, 1 ] ], + [ [ 11, 0, 2 ], [ 0, 23, 0 ] ], + [ [ 12, 0, 1 ], [ 0, 24, 1 ] ], + [ [ 12, 0, 0 ], [ 0, 24, 0 ] ], + [ [ 12, 0, 1 ], [ 0, 25, 1 ] ], + [ [ 12, 0, 2 ], [ 0, 25, 0 ] ], + [ [ 13, 0, 1 ], [ 0, 26, 1 ] ], + [ [ 13, 0, 0 ], [ 0, 26, 0 ] ], + [ [ 13, 0, 1 ], [ 0, 27, 1 ] ], + [ [ 13, 0, 2 ], [ 0, 27, 0 ] ], + [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], + [ [ 14, 0, 0 ], [ 0, 28, 0 ] ], + [ [ 14, 0, 1 ], [ 0, 29, 1 ] ], + [ [ 14, 0, 2 ], [ 0, 29, 0 ] ], + [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], + [ [ 15, 0, 0 ], [ 0, 30, 0 ] ], + [ [ 15, 0, 1 ], [ 0, 31, 1 ] ], + [ [ 15, 0, 2 ], [ 0, 31, 0 ] ], + [ [ 16, 0, 2 ], [ 1, 31, 1 ] ], + [ [ 16, 0, 1 ], [ 1, 31, 0 ] ], + [ [ 16, 0, 0 ], [ 0, 32, 0 ] ], + [ [ 16, 0, 1 ], [ 2, 31, 0 ] ], + [ [ 16, 0, 2 ], [ 0, 33, 0 ] ], + [ [ 17, 0, 1 ], [ 3, 31, 0 ] ], + [ [ 17, 0, 0 ], [ 0, 34, 0 ] ], + [ [ 17, 0, 1 ], [ 4, 31, 0 ] ], + [ [ 17, 0, 2 ], [ 0, 35, 0 ] ], + [ [ 18, 0, 1 ], [ 5, 31, 0 ] ], + [ [ 18, 0, 0 ], [ 0, 36, 0 ] ], + [ [ 18, 0, 1 ], [ 6, 31, 0 ] ], + [ [ 18, 0, 2 ], [ 0, 37, 0 ] ], + [ [ 19, 0, 1 ], [ 7, 31, 0 ] ], + [ [ 19, 0, 0 ], [ 0, 38, 0 ] ], + [ [ 19, 0, 1 ], [ 8, 31, 0 ] ], + [ [ 19, 0, 2 ], [ 0, 39, 0 ] ], + [ [ 20, 0, 1 ], [ 9, 31, 0 ] ], + [ [ 20, 0, 0 ], [ 0, 40, 0 ] ], + [ [ 20, 0, 1 ], [ 10, 31, 0 ] ], + [ [ 20, 0, 2 ], [ 0, 41, 0 ] ], + [ [ 21, 0, 1 ], [ 11, 31, 0 ] ], + [ [ 21, 0, 0 ], [ 0, 42, 0 ] ], + [ [ 21, 0, 1 ], [ 12, 31, 0 ] ], + [ [ 21, 0, 2 ], [ 0, 43, 0 ] ], + [ [ 22, 0, 1 ], [ 13, 31, 0 ] ], + [ [ 22, 0, 0 ], [ 0, 44, 0 ] ], + [ [ 22, 0, 1 ], [ 14, 31, 0 ] ], + [ [ 22, 0, 2 ], [ 0, 45, 0 ] ], + [ [ 23, 0, 1 ], [ 15, 31, 0 ] ], + [ [ 23, 0, 0 ], [ 0, 46, 0 ] ], + [ [ 23, 0, 1 ], [ 0, 47, 1 ] ], + [ [ 23, 0, 2 ], [ 0, 47, 0 ] ], + [ [ 24, 0, 1 ], [ 0, 48, 1 ] ], + [ [ 24, 0, 0 ], [ 0, 48, 0 ] ], + [ [ 24, 0, 1 ], [ 0, 49, 1 ] ], + [ [ 24, 0, 2 ], [ 0, 49, 0 ] ], + [ [ 25, 0, 1 ], [ 0, 50, 1 ] ], + [ [ 25, 0, 0 ], [ 0, 50, 0 ] ], + [ [ 25, 0, 1 ], [ 0, 51, 1 ] ], + [ [ 25, 0, 2 ], [ 0, 51, 0 ] ], + [ [ 26, 0, 1 ], [ 0, 52, 1 ] ], + [ [ 26, 0, 0 ], [ 0, 52, 0 ] ], + [ [ 26, 0, 1 ], [ 0, 53, 1 ] ], + [ [ 26, 0, 2 ], [ 0, 53, 0 ] ], + [ [ 27, 0, 1 ], [ 0, 54, 1 ] ], + [ [ 27, 0, 0 ], [ 0, 54, 0 ] ], + [ [ 27, 0, 1 ], [ 0, 55, 1 ] ], + [ [ 27, 0, 2 ], [ 0, 55, 0 ] ], + [ [ 28, 0, 1 ], [ 0, 56, 1 ] ], + [ [ 28, 0, 0 ], [ 0, 56, 0 ] ], + [ [ 28, 0, 1 ], [ 0, 57, 1 ] ], + [ [ 28, 0, 2 ], [ 0, 57, 0 ] ], + [ [ 29, 0, 1 ], [ 0, 58, 1 ] ], + [ [ 29, 0, 0 ], [ 0, 58, 0 ] ], + [ [ 29, 0, 1 ], [ 0, 59, 1 ] ], + [ [ 29, 0, 2 ], [ 0, 59, 0 ] ], + [ [ 30, 0, 1 ], [ 0, 60, 1 ] ], + [ [ 30, 0, 0 ], [ 0, 60, 0 ] ], + [ [ 30, 0, 1 ], [ 0, 61, 1 ] ], + [ [ 30, 0, 2 ], [ 0, 61, 0 ] ], + [ [ 31, 0, 1 ], [ 0, 62, 1 ] ], + [ [ 31, 0, 0 ], [ 0, 62, 0 ] ], + [ [ 31, 0, 1 ], [ 0, 63, 1 ] ], + [ [ 31, 0, 2 ], [ 0, 63, 0 ] ], + [ [ 32, 0, 2 ], [ 1, 63, 1 ] ], + [ [ 32, 0, 1 ], [ 1, 63, 0 ] ], + [ [ 32, 0, 0 ], [ 16, 48, 0 ] ], + [ [ 32, 0, 1 ], [ 2, 63, 0 ] ], + [ [ 32, 0, 2 ], [ 16, 49, 0 ] ], + [ [ 33, 0, 1 ], [ 3, 63, 0 ] ], + [ [ 33, 0, 0 ], [ 16, 50, 0 ] ], + [ [ 33, 0, 1 ], [ 4, 63, 0 ] ], + [ [ 33, 0, 2 ], [ 16, 51, 0 ] ], + [ [ 34, 0, 1 ], [ 5, 63, 0 ] ], + [ [ 34, 0, 0 ], [ 16, 52, 0 ] ], + [ [ 34, 0, 1 ], [ 6, 63, 0 ] ], + [ [ 34, 0, 2 ], [ 16, 53, 0 ] ], + [ [ 35, 0, 1 ], [ 7, 63, 0 ] ], + [ [ 35, 0, 0 ], [ 16, 54, 0 ] ], + [ [ 35, 0, 1 ], [ 8, 63, 0 ] ], + [ [ 35, 0, 2 ], [ 16, 55, 0 ] ], + [ [ 36, 0, 1 ], [ 9, 63, 0 ] ], + [ [ 36, 0, 0 ], [ 16, 56, 0 ] ], + [ [ 36, 0, 1 ], [ 10, 63, 0 ] ], + [ [ 36, 0, 2 ], [ 16, 57, 0 ] ], + [ [ 37, 0, 1 ], [ 11, 63, 0 ] ], + [ [ 37, 0, 0 ], [ 16, 58, 0 ] ], + [ [ 37, 0, 1 ], [ 12, 63, 0 ] ], + [ [ 37, 0, 2 ], [ 16, 59, 0 ] ], + [ [ 38, 0, 1 ], [ 13, 63, 0 ] ], + [ [ 38, 0, 0 ], [ 16, 60, 0 ] ], + [ [ 38, 0, 1 ], [ 14, 63, 0 ] ], + [ [ 38, 0, 2 ], [ 16, 61, 0 ] ], + [ [ 39, 0, 1 ], [ 15, 63, 0 ] ], + [ [ 39, 0, 0 ], [ 16, 62, 0 ] ], + [ [ 39, 0, 1 ], [ 16, 63, 1 ] ], + [ [ 39, 0, 2 ], [ 16, 63, 0 ] ], + [ [ 40, 0, 1 ], [ 17, 63, 1 ] ], + [ [ 40, 0, 0 ], [ 17, 63, 0 ] ], + [ [ 40, 0, 1 ], [ 18, 63, 1 ] ], + [ [ 40, 0, 2 ], [ 18, 63, 0 ] ], + [ [ 41, 0, 1 ], [ 19, 63, 1 ] ], + [ [ 41, 0, 0 ], [ 19, 63, 0 ] ], + [ [ 41, 0, 1 ], [ 20, 63, 1 ] ], + [ [ 41, 0, 2 ], [ 20, 63, 0 ] ], + [ [ 42, 0, 1 ], [ 21, 63, 1 ] ], + [ [ 42, 0, 0 ], [ 21, 63, 0 ] ], + [ [ 42, 0, 1 ], [ 22, 63, 1 ] ], + [ [ 42, 0, 2 ], [ 22, 63, 0 ] ], + [ [ 43, 0, 1 ], [ 23, 63, 1 ] ], + [ [ 43, 0, 0 ], [ 23, 63, 0 ] ], + [ [ 43, 0, 1 ], [ 24, 63, 1 ] ], + [ [ 43, 0, 2 ], [ 24, 63, 0 ] ], + [ [ 44, 0, 1 ], [ 25, 63, 1 ] ], + [ [ 44, 0, 0 ], [ 25, 63, 0 ] ], + [ [ 44, 0, 1 ], [ 26, 63, 1 ] ], + [ [ 44, 0, 2 ], [ 26, 63, 0 ] ], + [ [ 45, 0, 1 ], [ 27, 63, 1 ] ], + [ [ 45, 0, 0 ], [ 27, 63, 0 ] ], + [ [ 45, 0, 1 ], [ 28, 63, 1 ] ], + [ [ 45, 0, 2 ], [ 28, 63, 0 ] ], + [ [ 46, 0, 1 ], [ 29, 63, 1 ] ], + [ [ 46, 0, 0 ], [ 29, 63, 0 ] ], + [ [ 46, 0, 1 ], [ 30, 63, 1 ] ], + [ [ 46, 0, 2 ], [ 30, 63, 0 ] ], + [ [ 47, 0, 1 ], [ 31, 63, 1 ] ], + [ [ 47, 0, 0 ], [ 31, 63, 0 ] ], + [ [ 47, 0, 1 ], [ 32, 63, 1 ] ], + [ [ 47, 0, 2 ], [ 32, 63, 0 ] ], + [ [ 48, 0, 2 ], [ 33, 63, 1 ] ], + [ [ 48, 0, 1 ], [ 33, 63, 0 ] ], + [ [ 48, 0, 0 ], [ 48, 48, 0 ] ], + [ [ 48, 0, 1 ], [ 34, 63, 0 ] ], + [ [ 48, 0, 2 ], [ 48, 49, 0 ] ], + [ [ 49, 0, 1 ], [ 35, 63, 0 ] ], + [ [ 49, 0, 0 ], [ 48, 50, 0 ] ], + [ [ 49, 0, 1 ], [ 36, 63, 0 ] ], + [ [ 49, 0, 2 ], [ 48, 51, 0 ] ], + [ [ 50, 0, 1 ], [ 37, 63, 0 ] ], + [ [ 50, 0, 0 ], [ 48, 52, 0 ] ], + [ [ 50, 0, 1 ], [ 38, 63, 0 ] ], + [ [ 50, 0, 2 ], [ 48, 53, 0 ] ], + [ [ 51, 0, 1 ], [ 39, 63, 0 ] ], + [ [ 51, 0, 0 ], [ 48, 54, 0 ] ], + [ [ 51, 0, 1 ], [ 40, 63, 0 ] ], + [ [ 51, 0, 2 ], [ 48, 55, 0 ] ], + [ [ 52, 0, 1 ], [ 41, 63, 0 ] ], + [ [ 52, 0, 0 ], [ 48, 56, 0 ] ], + [ [ 52, 0, 1 ], [ 42, 63, 0 ] ], + [ [ 52, 0, 2 ], [ 48, 57, 0 ] ], + [ [ 53, 0, 1 ], [ 43, 63, 0 ] ], + [ [ 53, 0, 0 ], [ 48, 58, 0 ] ], + [ [ 53, 0, 1 ], [ 44, 63, 0 ] ], + [ [ 53, 0, 2 ], [ 48, 59, 0 ] ], + [ [ 54, 0, 1 ], [ 45, 63, 0 ] ], + [ [ 54, 0, 0 ], [ 48, 60, 0 ] ], + [ [ 54, 0, 1 ], [ 46, 63, 0 ] ], + [ [ 54, 0, 2 ], [ 48, 61, 0 ] ], + [ [ 55, 0, 1 ], [ 47, 63, 0 ] ], + [ [ 55, 0, 0 ], [ 48, 62, 0 ] ], + [ [ 55, 0, 1 ], [ 48, 63, 1 ] ], + [ [ 55, 0, 2 ], [ 48, 63, 0 ] ], + [ [ 56, 0, 1 ], [ 49, 63, 1 ] ], + [ [ 56, 0, 0 ], [ 49, 63, 0 ] ], + [ [ 56, 0, 1 ], [ 50, 63, 1 ] ], + [ [ 56, 0, 2 ], [ 50, 63, 0 ] ], + [ [ 57, 0, 1 ], [ 51, 63, 1 ] ], + [ [ 57, 0, 0 ], [ 51, 63, 0 ] ], + [ [ 57, 0, 1 ], [ 52, 63, 1 ] ], + [ [ 57, 0, 2 ], [ 52, 63, 0 ] ], + [ [ 58, 0, 1 ], [ 53, 63, 1 ] ], + [ [ 58, 0, 0 ], [ 53, 63, 0 ] ], + [ [ 58, 0, 1 ], [ 54, 63, 1 ] ], + [ [ 58, 0, 2 ], [ 54, 63, 0 ] ], + [ [ 59, 0, 1 ], [ 55, 63, 1 ] ], + [ [ 59, 0, 0 ], [ 55, 63, 0 ] ], + [ [ 59, 0, 1 ], [ 56, 63, 1 ] ], + [ [ 59, 0, 2 ], [ 56, 63, 0 ] ], + [ [ 60, 0, 1 ], [ 57, 63, 1 ] ], + [ [ 60, 0, 0 ], [ 57, 63, 0 ] ], + [ [ 60, 0, 1 ], [ 58, 63, 1 ] ], + [ [ 60, 0, 2 ], [ 58, 63, 0 ] ], + [ [ 61, 0, 1 ], [ 59, 63, 1 ] ], + [ [ 61, 0, 0 ], [ 59, 63, 0 ] ], + [ [ 61, 0, 1 ], [ 60, 63, 1 ] ], + [ [ 61, 0, 2 ], [ 60, 63, 0 ] ], + [ [ 62, 0, 1 ], [ 61, 63, 1 ] ], + [ [ 62, 0, 0 ], [ 61, 63, 0 ] ], + [ [ 62, 0, 1 ], [ 62, 63, 1 ] ], + [ [ 62, 0, 2 ], [ 62, 63, 0 ] ], + [ [ 63, 0, 1 ], [ 63, 63, 1 ] ], + [ [ 63, 0, 0 ], [ 63, 63, 0 ] ] +]; + +const lookup_5_4 = +[ + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 1 ], [ 0, 1, 1 ] ], + [ [ 0, 0, 2 ], [ 0, 1, 0 ] ], + [ [ 0, 0, 3 ], [ 0, 1, 1 ] ], + [ [ 0, 0, 4 ], [ 0, 2, 1 ] ], + [ [ 1, 0, 3 ], [ 0, 2, 0 ] ], + [ [ 1, 0, 2 ], [ 0, 2, 1 ] ], + [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], + [ [ 1, 0, 0 ], [ 0, 3, 0 ] ], + [ [ 1, 0, 1 ], [ 1, 2, 1 ] ], + [ [ 1, 0, 2 ], [ 1, 2, 0 ] ], + [ [ 1, 0, 3 ], [ 0, 4, 0 ] ], + [ [ 1, 0, 4 ], [ 0, 5, 1 ] ], + [ [ 2, 0, 3 ], [ 0, 5, 0 ] ], + [ [ 2, 0, 2 ], [ 0, 5, 1 ] ], + [ [ 2, 0, 1 ], [ 0, 6, 1 ] ], + [ [ 2, 0, 0 ], [ 0, 6, 0 ] ], + [ [ 2, 0, 1 ], [ 2, 3, 1 ] ], + [ [ 2, 0, 2 ], [ 2, 3, 0 ] ], + [ [ 2, 0, 3 ], [ 0, 7, 0 ] ], + [ [ 2, 0, 4 ], [ 1, 6, 1 ] ], + [ [ 3, 0, 3 ], [ 1, 6, 0 ] ], + [ [ 3, 0, 2 ], [ 0, 8, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], + [ [ 3, 0, 0 ], [ 0, 9, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], + [ [ 3, 0, 2 ], [ 0, 10, 1 ] ], + [ [ 3, 0, 3 ], [ 0, 10, 0 ] ], + [ [ 3, 0, 4 ], [ 2, 7, 1 ] ], + [ [ 4, 0, 4 ], [ 2, 7, 0 ] ], + [ [ 4, 0, 3 ], [ 0, 11, 0 ] ], + [ [ 4, 0, 2 ], [ 1, 10, 1 ] ], + [ [ 4, 0, 1 ], [ 1, 10, 0 ] ], + [ [ 4, 0, 0 ], [ 0, 12, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 13, 1 ] ], + [ [ 4, 0, 2 ], [ 0, 13, 0 ] ], + [ [ 4, 0, 3 ], [ 0, 13, 1 ] ], + [ [ 4, 0, 4 ], [ 0, 14, 1 ] ], + [ [ 5, 0, 3 ], [ 0, 14, 0 ] ], + [ [ 5, 0, 2 ], [ 2, 11, 1 ] ], + [ [ 5, 0, 1 ], [ 2, 11, 0 ] ], + [ [ 5, 0, 0 ], [ 0, 15, 0 ] ], + [ [ 5, 0, 1 ], [ 1, 14, 1 ] ], + [ [ 5, 0, 2 ], [ 1, 14, 0 ] ], + [ [ 5, 0, 3 ], [ 0, 16, 0 ] ], + [ [ 5, 0, 4 ], [ 0, 17, 1 ] ], + [ [ 6, 0, 3 ], [ 0, 17, 0 ] ], + [ [ 6, 0, 2 ], [ 0, 17, 1 ] ], + [ [ 6, 0, 1 ], [ 0, 18, 1 ] ], + [ [ 6, 0, 0 ], [ 0, 18, 0 ] ], + [ [ 6, 0, 1 ], [ 2, 15, 1 ] ], + [ [ 6, 0, 2 ], [ 2, 15, 0 ] ], + [ [ 6, 0, 3 ], [ 0, 19, 0 ] ], + [ [ 6, 0, 4 ], [ 1, 18, 1 ] ], + [ [ 7, 0, 3 ], [ 1, 18, 0 ] ], + [ [ 7, 0, 2 ], [ 0, 20, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 21, 1 ] ], + [ [ 7, 0, 0 ], [ 0, 21, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 21, 1 ] ], + [ [ 7, 0, 2 ], [ 0, 22, 1 ] ], + [ [ 7, 0, 3 ], [ 0, 22, 0 ] ], + [ [ 7, 0, 4 ], [ 2, 19, 1 ] ], + [ [ 8, 0, 4 ], [ 2, 19, 0 ] ], + [ [ 8, 0, 3 ], [ 0, 23, 0 ] ], + [ [ 8, 0, 2 ], [ 1, 22, 1 ] ], + [ [ 8, 0, 1 ], [ 1, 22, 0 ] ], + [ [ 8, 0, 0 ], [ 0, 24, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 25, 1 ] ], + [ [ 8, 0, 2 ], [ 0, 25, 0 ] ], + [ [ 8, 0, 3 ], [ 0, 25, 1 ] ], + [ [ 8, 0, 4 ], [ 0, 26, 1 ] ], + [ [ 9, 0, 3 ], [ 0, 26, 0 ] ], + [ [ 9, 0, 2 ], [ 2, 23, 1 ] ], + [ [ 9, 0, 1 ], [ 2, 23, 0 ] ], + [ [ 9, 0, 0 ], [ 0, 27, 0 ] ], + [ [ 9, 0, 1 ], [ 1, 26, 1 ] ], + [ [ 9, 0, 2 ], [ 1, 26, 0 ] ], + [ [ 9, 0, 3 ], [ 0, 28, 0 ] ], + [ [ 9, 0, 4 ], [ 0, 29, 1 ] ], + [ [ 10, 0, 3 ], [ 0, 29, 0 ] ], + [ [ 10, 0, 2 ], [ 0, 29, 1 ] ], + [ [ 10, 0, 1 ], [ 0, 30, 1 ] ], + [ [ 10, 0, 0 ], [ 0, 30, 0 ] ], + [ [ 10, 0, 1 ], [ 2, 27, 1 ] ], + [ [ 10, 0, 2 ], [ 2, 27, 0 ] ], + [ [ 10, 0, 3 ], [ 0, 31, 0 ] ], + [ [ 10, 0, 4 ], [ 1, 30, 1 ] ], + [ [ 11, 0, 3 ], [ 1, 30, 0 ] ], + [ [ 11, 0, 2 ], [ 4, 24, 0 ] ], + [ [ 11, 0, 1 ], [ 1, 31, 1 ] ], + [ [ 11, 0, 0 ], [ 1, 31, 0 ] ], + [ [ 11, 0, 1 ], [ 1, 31, 1 ] ], + [ [ 11, 0, 2 ], [ 2, 30, 1 ] ], + [ [ 11, 0, 3 ], [ 2, 30, 0 ] ], + [ [ 11, 0, 4 ], [ 2, 31, 1 ] ], + [ [ 12, 0, 4 ], [ 2, 31, 0 ] ], + [ [ 12, 0, 3 ], [ 4, 27, 0 ] ], + [ [ 12, 0, 2 ], [ 3, 30, 1 ] ], + [ [ 12, 0, 1 ], [ 3, 30, 0 ] ], + [ [ 12, 0, 0 ], [ 4, 28, 0 ] ], + [ [ 12, 0, 1 ], [ 3, 31, 1 ] ], + [ [ 12, 0, 2 ], [ 3, 31, 0 ] ], + [ [ 12, 0, 3 ], [ 3, 31, 1 ] ], + [ [ 12, 0, 4 ], [ 4, 30, 1 ] ], + [ [ 13, 0, 3 ], [ 4, 30, 0 ] ], + [ [ 13, 0, 2 ], [ 6, 27, 1 ] ], + [ [ 13, 0, 1 ], [ 6, 27, 0 ] ], + [ [ 13, 0, 0 ], [ 4, 31, 0 ] ], + [ [ 13, 0, 1 ], [ 5, 30, 1 ] ], + [ [ 13, 0, 2 ], [ 5, 30, 0 ] ], + [ [ 13, 0, 3 ], [ 8, 24, 0 ] ], + [ [ 13, 0, 4 ], [ 5, 31, 1 ] ], + [ [ 14, 0, 3 ], [ 5, 31, 0 ] ], + [ [ 14, 0, 2 ], [ 5, 31, 1 ] ], + [ [ 14, 0, 1 ], [ 6, 30, 1 ] ], + [ [ 14, 0, 0 ], [ 6, 30, 0 ] ], + [ [ 14, 0, 1 ], [ 6, 31, 1 ] ], + [ [ 14, 0, 2 ], [ 6, 31, 0 ] ], + [ [ 14, 0, 3 ], [ 8, 27, 0 ] ], + [ [ 14, 0, 4 ], [ 7, 30, 1 ] ], + [ [ 15, 0, 3 ], [ 7, 30, 0 ] ], + [ [ 15, 0, 2 ], [ 8, 28, 0 ] ], + [ [ 15, 0, 1 ], [ 7, 31, 1 ] ], + [ [ 15, 0, 0 ], [ 7, 31, 0 ] ], + [ [ 15, 0, 1 ], [ 7, 31, 1 ] ], + [ [ 15, 0, 2 ], [ 8, 30, 1 ] ], + [ [ 15, 0, 3 ], [ 8, 30, 0 ] ], + [ [ 15, 0, 4 ], [ 10, 27, 1 ] ], + [ [ 16, 0, 4 ], [ 10, 27, 0 ] ], + [ [ 16, 0, 3 ], [ 8, 31, 0 ] ], + [ [ 16, 0, 2 ], [ 9, 30, 1 ] ], + [ [ 16, 0, 1 ], [ 9, 30, 0 ] ], + [ [ 16, 0, 0 ], [ 12, 24, 0 ] ], + [ [ 16, 0, 1 ], [ 9, 31, 1 ] ], + [ [ 16, 0, 2 ], [ 9, 31, 0 ] ], + [ [ 16, 0, 3 ], [ 9, 31, 1 ] ], + [ [ 16, 0, 4 ], [ 10, 30, 1 ] ], + [ [ 17, 0, 3 ], [ 10, 30, 0 ] ], + [ [ 17, 0, 2 ], [ 10, 31, 1 ] ], + [ [ 17, 0, 1 ], [ 10, 31, 0 ] ], + [ [ 17, 0, 0 ], [ 12, 27, 0 ] ], + [ [ 17, 0, 1 ], [ 11, 30, 1 ] ], + [ [ 17, 0, 2 ], [ 11, 30, 0 ] ], + [ [ 17, 0, 3 ], [ 12, 28, 0 ] ], + [ [ 17, 0, 4 ], [ 11, 31, 1 ] ], + [ [ 18, 0, 3 ], [ 11, 31, 0 ] ], + [ [ 18, 0, 2 ], [ 11, 31, 1 ] ], + [ [ 18, 0, 1 ], [ 12, 30, 1 ] ], + [ [ 18, 0, 0 ], [ 12, 30, 0 ] ], + [ [ 18, 0, 1 ], [ 14, 27, 1 ] ], + [ [ 18, 0, 2 ], [ 14, 27, 0 ] ], + [ [ 18, 0, 3 ], [ 12, 31, 0 ] ], + [ [ 18, 0, 4 ], [ 13, 30, 1 ] ], + [ [ 19, 0, 3 ], [ 13, 30, 0 ] ], + [ [ 19, 0, 2 ], [ 16, 24, 0 ] ], + [ [ 19, 0, 1 ], [ 13, 31, 1 ] ], + [ [ 19, 0, 0 ], [ 13, 31, 0 ] ], + [ [ 19, 0, 1 ], [ 13, 31, 1 ] ], + [ [ 19, 0, 2 ], [ 14, 30, 1 ] ], + [ [ 19, 0, 3 ], [ 14, 30, 0 ] ], + [ [ 19, 0, 4 ], [ 14, 31, 1 ] ], + [ [ 20, 0, 4 ], [ 14, 31, 0 ] ], + [ [ 20, 0, 3 ], [ 16, 27, 0 ] ], + [ [ 20, 0, 2 ], [ 15, 30, 1 ] ], + [ [ 20, 0, 1 ], [ 15, 30, 0 ] ], + [ [ 20, 0, 0 ], [ 16, 28, 0 ] ], + [ [ 20, 0, 1 ], [ 15, 31, 1 ] ], + [ [ 20, 0, 2 ], [ 15, 31, 0 ] ], + [ [ 20, 0, 3 ], [ 15, 31, 1 ] ], + [ [ 20, 0, 4 ], [ 16, 30, 1 ] ], + [ [ 21, 0, 3 ], [ 16, 30, 0 ] ], + [ [ 21, 0, 2 ], [ 18, 27, 1 ] ], + [ [ 21, 0, 1 ], [ 18, 27, 0 ] ], + [ [ 21, 0, 0 ], [ 16, 31, 0 ] ], + [ [ 21, 0, 1 ], [ 17, 30, 1 ] ], + [ [ 21, 0, 2 ], [ 17, 30, 0 ] ], + [ [ 21, 0, 3 ], [ 20, 24, 0 ] ], + [ [ 21, 0, 4 ], [ 17, 31, 1 ] ], + [ [ 22, 0, 3 ], [ 17, 31, 0 ] ], + [ [ 22, 0, 2 ], [ 17, 31, 1 ] ], + [ [ 22, 0, 1 ], [ 18, 30, 1 ] ], + [ [ 22, 0, 0 ], [ 18, 30, 0 ] ], + [ [ 22, 0, 1 ], [ 18, 31, 1 ] ], + [ [ 22, 0, 2 ], [ 18, 31, 0 ] ], + [ [ 22, 0, 3 ], [ 20, 27, 0 ] ], + [ [ 22, 0, 4 ], [ 19, 30, 1 ] ], + [ [ 23, 0, 3 ], [ 19, 30, 0 ] ], + [ [ 23, 0, 2 ], [ 20, 28, 0 ] ], + [ [ 23, 0, 1 ], [ 19, 31, 1 ] ], + [ [ 23, 0, 0 ], [ 19, 31, 0 ] ], + [ [ 23, 0, 1 ], [ 19, 31, 1 ] ], + [ [ 23, 0, 2 ], [ 20, 30, 1 ] ], + [ [ 23, 0, 3 ], [ 20, 30, 0 ] ], + [ [ 23, 0, 4 ], [ 22, 27, 1 ] ], + [ [ 24, 0, 4 ], [ 22, 27, 0 ] ], + [ [ 24, 0, 3 ], [ 20, 31, 0 ] ], + [ [ 24, 0, 2 ], [ 21, 30, 1 ] ], + [ [ 24, 0, 1 ], [ 21, 30, 0 ] ], + [ [ 24, 0, 0 ], [ 24, 24, 0 ] ], + [ [ 24, 0, 1 ], [ 21, 31, 1 ] ], + [ [ 24, 0, 2 ], [ 21, 31, 0 ] ], + [ [ 24, 0, 3 ], [ 21, 31, 1 ] ], + [ [ 24, 0, 4 ], [ 22, 30, 1 ] ], + [ [ 25, 0, 3 ], [ 22, 30, 0 ] ], + [ [ 25, 0, 2 ], [ 22, 31, 1 ] ], + [ [ 25, 0, 1 ], [ 22, 31, 0 ] ], + [ [ 25, 0, 0 ], [ 24, 27, 0 ] ], + [ [ 25, 0, 1 ], [ 23, 30, 1 ] ], + [ [ 25, 0, 2 ], [ 23, 30, 0 ] ], + [ [ 25, 0, 3 ], [ 24, 28, 0 ] ], + [ [ 25, 0, 4 ], [ 23, 31, 1 ] ], + [ [ 26, 0, 3 ], [ 23, 31, 0 ] ], + [ [ 26, 0, 2 ], [ 23, 31, 1 ] ], + [ [ 26, 0, 1 ], [ 24, 30, 1 ] ], + [ [ 26, 0, 0 ], [ 24, 30, 0 ] ], + [ [ 26, 0, 1 ], [ 26, 27, 1 ] ], + [ [ 26, 0, 2 ], [ 26, 27, 0 ] ], + [ [ 26, 0, 3 ], [ 24, 31, 0 ] ], + [ [ 26, 0, 4 ], [ 25, 30, 1 ] ], + [ [ 27, 0, 3 ], [ 25, 30, 0 ] ], + [ [ 27, 0, 2 ], [ 28, 24, 0 ] ], + [ [ 27, 0, 1 ], [ 25, 31, 1 ] ], + [ [ 27, 0, 0 ], [ 25, 31, 0 ] ], + [ [ 27, 0, 1 ], [ 25, 31, 1 ] ], + [ [ 27, 0, 2 ], [ 26, 30, 1 ] ], + [ [ 27, 0, 3 ], [ 26, 30, 0 ] ], + [ [ 27, 0, 4 ], [ 26, 31, 1 ] ], + [ [ 28, 0, 4 ], [ 26, 31, 0 ] ], + [ [ 28, 0, 3 ], [ 28, 27, 0 ] ], + [ [ 28, 0, 2 ], [ 27, 30, 1 ] ], + [ [ 28, 0, 1 ], [ 27, 30, 0 ] ], + [ [ 28, 0, 0 ], [ 28, 28, 0 ] ], + [ [ 28, 0, 1 ], [ 27, 31, 1 ] ], + [ [ 28, 0, 2 ], [ 27, 31, 0 ] ], + [ [ 28, 0, 3 ], [ 27, 31, 1 ] ], + [ [ 28, 0, 4 ], [ 28, 30, 1 ] ], + [ [ 29, 0, 3 ], [ 28, 30, 0 ] ], + [ [ 29, 0, 2 ], [ 30, 27, 1 ] ], + [ [ 29, 0, 1 ], [ 30, 27, 0 ] ], + [ [ 29, 0, 0 ], [ 28, 31, 0 ] ], + [ [ 29, 0, 1 ], [ 29, 30, 1 ] ], + [ [ 29, 0, 2 ], [ 29, 30, 0 ] ], + [ [ 29, 0, 3 ], [ 29, 30, 1 ] ], + [ [ 29, 0, 4 ], [ 29, 31, 1 ] ], + [ [ 30, 0, 3 ], [ 29, 31, 0 ] ], + [ [ 30, 0, 2 ], [ 29, 31, 1 ] ], + [ [ 30, 0, 1 ], [ 30, 30, 1 ] ], + [ [ 30, 0, 0 ], [ 30, 30, 0 ] ], + [ [ 30, 0, 1 ], [ 30, 31, 1 ] ], + [ [ 30, 0, 2 ], [ 30, 31, 0 ] ], + [ [ 30, 0, 3 ], [ 30, 31, 1 ] ], + [ [ 30, 0, 4 ], [ 31, 30, 1 ] ], + [ [ 31, 0, 3 ], [ 31, 30, 0 ] ], + [ [ 31, 0, 2 ], [ 31, 30, 1 ] ], + [ [ 31, 0, 1 ], [ 31, 31, 1 ] ], + [ [ 31, 0, 0 ], [ 31, 31, 0 ] ] +]; + +const lookup_6_4 = +[ + [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], + [ [ 0, 0, 1 ], [ 0, 1, 0 ] ], + [ [ 0, 0, 2 ], [ 0, 2, 0 ] ], + [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], + [ [ 1, 0, 0 ], [ 0, 3, 0 ] ], + [ [ 1, 0, 1 ], [ 0, 4, 0 ] ], + [ [ 1, 0, 2 ], [ 0, 5, 0 ] ], + [ [ 2, 0, 1 ], [ 0, 6, 1 ] ], + [ [ 2, 0, 0 ], [ 0, 6, 0 ] ], + [ [ 2, 0, 1 ], [ 0, 7, 0 ] ], + [ [ 2, 0, 2 ], [ 0, 8, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], + [ [ 3, 0, 0 ], [ 0, 9, 0 ] ], + [ [ 3, 0, 1 ], [ 0, 10, 0 ] ], + [ [ 3, 0, 2 ], [ 0, 11, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 12, 1 ] ], + [ [ 4, 0, 0 ], [ 0, 12, 0 ] ], + [ [ 4, 0, 1 ], [ 0, 13, 0 ] ], + [ [ 4, 0, 2 ], [ 0, 14, 0 ] ], + [ [ 5, 0, 1 ], [ 0, 15, 1 ] ], + [ [ 5, 0, 0 ], [ 0, 15, 0 ] ], + [ [ 5, 0, 1 ], [ 0, 16, 0 ] ], + [ [ 5, 0, 2 ], [ 1, 15, 0 ] ], + [ [ 6, 0, 1 ], [ 0, 17, 0 ] ], + [ [ 6, 0, 0 ], [ 0, 18, 0 ] ], + [ [ 6, 0, 1 ], [ 0, 19, 0 ] ], + [ [ 6, 0, 2 ], [ 3, 14, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 20, 0 ] ], + [ [ 7, 0, 0 ], [ 0, 21, 0 ] ], + [ [ 7, 0, 1 ], [ 0, 22, 0 ] ], + [ [ 7, 0, 2 ], [ 4, 15, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 23, 0 ] ], + [ [ 8, 0, 0 ], [ 0, 24, 0 ] ], + [ [ 8, 0, 1 ], [ 0, 25, 0 ] ], + [ [ 8, 0, 2 ], [ 6, 14, 0 ] ], + [ [ 9, 0, 1 ], [ 0, 26, 0 ] ], + [ [ 9, 0, 0 ], [ 0, 27, 0 ] ], + [ [ 9, 0, 1 ], [ 0, 28, 0 ] ], + [ [ 9, 0, 2 ], [ 7, 15, 0 ] ], + [ [ 10, 0, 1 ], [ 0, 29, 0 ] ], + [ [ 10, 0, 0 ], [ 0, 30, 0 ] ], + [ [ 10, 0, 1 ], [ 0, 31, 0 ] ], + [ [ 10, 0, 2 ], [ 9, 14, 0 ] ], + [ [ 11, 0, 1 ], [ 0, 32, 0 ] ], + [ [ 11, 0, 0 ], [ 0, 33, 0 ] ], + [ [ 11, 0, 1 ], [ 2, 30, 0 ] ], + [ [ 11, 0, 2 ], [ 0, 34, 0 ] ], + [ [ 12, 0, 1 ], [ 0, 35, 0 ] ], + [ [ 12, 0, 0 ], [ 0, 36, 0 ] ], + [ [ 12, 0, 1 ], [ 3, 31, 0 ] ], + [ [ 12, 0, 2 ], [ 0, 37, 0 ] ], + [ [ 13, 0, 1 ], [ 0, 38, 0 ] ], + [ [ 13, 0, 0 ], [ 0, 39, 0 ] ], + [ [ 13, 0, 1 ], [ 5, 30, 0 ] ], + [ [ 13, 0, 2 ], [ 0, 40, 0 ] ], + [ [ 14, 0, 1 ], [ 0, 41, 0 ] ], + [ [ 14, 0, 0 ], [ 0, 42, 0 ] ], + [ [ 14, 0, 1 ], [ 6, 31, 0 ] ], + [ [ 14, 0, 2 ], [ 0, 43, 0 ] ], + [ [ 15, 0, 1 ], [ 0, 44, 0 ] ], + [ [ 15, 0, 0 ], [ 0, 45, 0 ] ], + [ [ 15, 0, 1 ], [ 8, 30, 0 ] ], + [ [ 15, 0, 2 ], [ 0, 46, 0 ] ], + [ [ 16, 0, 2 ], [ 0, 47, 0 ] ], + [ [ 16, 0, 1 ], [ 1, 46, 0 ] ], + [ [ 16, 0, 0 ], [ 0, 48, 0 ] ], + [ [ 16, 0, 1 ], [ 0, 49, 0 ] ], + [ [ 16, 0, 2 ], [ 0, 50, 0 ] ], + [ [ 17, 0, 1 ], [ 2, 47, 0 ] ], + [ [ 17, 0, 0 ], [ 0, 51, 0 ] ], + [ [ 17, 0, 1 ], [ 0, 52, 0 ] ], + [ [ 17, 0, 2 ], [ 0, 53, 0 ] ], + [ [ 18, 0, 1 ], [ 4, 46, 0 ] ], + [ [ 18, 0, 0 ], [ 0, 54, 0 ] ], + [ [ 18, 0, 1 ], [ 0, 55, 0 ] ], + [ [ 18, 0, 2 ], [ 0, 56, 0 ] ], + [ [ 19, 0, 1 ], [ 5, 47, 0 ] ], + [ [ 19, 0, 0 ], [ 0, 57, 0 ] ], + [ [ 19, 0, 1 ], [ 0, 58, 0 ] ], + [ [ 19, 0, 2 ], [ 0, 59, 0 ] ], + [ [ 20, 0, 1 ], [ 7, 46, 0 ] ], + [ [ 20, 0, 0 ], [ 0, 60, 0 ] ], + [ [ 20, 0, 1 ], [ 0, 61, 0 ] ], + [ [ 20, 0, 2 ], [ 0, 62, 0 ] ], + [ [ 21, 0, 1 ], [ 8, 47, 0 ] ], + [ [ 21, 0, 0 ], [ 0, 63, 0 ] ], + [ [ 21, 0, 1 ], [ 1, 62, 0 ] ], + [ [ 21, 0, 2 ], [ 1, 63, 0 ] ], + [ [ 22, 0, 1 ], [ 10, 46, 0 ] ], + [ [ 22, 0, 0 ], [ 2, 62, 0 ] ], + [ [ 22, 0, 1 ], [ 2, 63, 0 ] ], + [ [ 22, 0, 2 ], [ 3, 62, 0 ] ], + [ [ 23, 0, 1 ], [ 11, 47, 0 ] ], + [ [ 23, 0, 0 ], [ 3, 63, 0 ] ], + [ [ 23, 0, 1 ], [ 4, 62, 0 ] ], + [ [ 23, 0, 2 ], [ 4, 63, 0 ] ], + [ [ 24, 0, 1 ], [ 13, 46, 0 ] ], + [ [ 24, 0, 0 ], [ 5, 62, 0 ] ], + [ [ 24, 0, 1 ], [ 5, 63, 0 ] ], + [ [ 24, 0, 2 ], [ 6, 62, 0 ] ], + [ [ 25, 0, 1 ], [ 14, 47, 0 ] ], + [ [ 25, 0, 0 ], [ 6, 63, 0 ] ], + [ [ 25, 0, 1 ], [ 7, 62, 0 ] ], + [ [ 25, 0, 2 ], [ 7, 63, 0 ] ], + [ [ 26, 0, 1 ], [ 16, 45, 0 ] ], + [ [ 26, 0, 0 ], [ 8, 62, 0 ] ], + [ [ 26, 0, 1 ], [ 8, 63, 0 ] ], + [ [ 26, 0, 2 ], [ 9, 62, 0 ] ], + [ [ 27, 0, 1 ], [ 16, 48, 0 ] ], + [ [ 27, 0, 0 ], [ 9, 63, 0 ] ], + [ [ 27, 0, 1 ], [ 10, 62, 0 ] ], + [ [ 27, 0, 2 ], [ 10, 63, 0 ] ], + [ [ 28, 0, 1 ], [ 16, 51, 0 ] ], + [ [ 28, 0, 0 ], [ 11, 62, 0 ] ], + [ [ 28, 0, 1 ], [ 11, 63, 0 ] ], + [ [ 28, 0, 2 ], [ 12, 62, 0 ] ], + [ [ 29, 0, 1 ], [ 16, 54, 0 ] ], + [ [ 29, 0, 0 ], [ 12, 63, 0 ] ], + [ [ 29, 0, 1 ], [ 13, 62, 0 ] ], + [ [ 29, 0, 2 ], [ 13, 63, 0 ] ], + [ [ 30, 0, 1 ], [ 16, 57, 0 ] ], + [ [ 30, 0, 0 ], [ 14, 62, 0 ] ], + [ [ 30, 0, 1 ], [ 14, 63, 0 ] ], + [ [ 30, 0, 2 ], [ 15, 62, 0 ] ], + [ [ 31, 0, 1 ], [ 16, 60, 0 ] ], + [ [ 31, 0, 0 ], [ 15, 63, 0 ] ], + [ [ 31, 0, 1 ], [ 24, 46, 0 ] ], + [ [ 31, 0, 2 ], [ 16, 62, 0 ] ], + [ [ 32, 0, 2 ], [ 16, 63, 0 ] ], + [ [ 32, 0, 1 ], [ 17, 62, 0 ] ], + [ [ 32, 0, 0 ], [ 25, 47, 0 ] ], + [ [ 32, 0, 1 ], [ 17, 63, 0 ] ], + [ [ 32, 0, 2 ], [ 18, 62, 0 ] ], + [ [ 33, 0, 1 ], [ 18, 63, 0 ] ], + [ [ 33, 0, 0 ], [ 27, 46, 0 ] ], + [ [ 33, 0, 1 ], [ 19, 62, 0 ] ], + [ [ 33, 0, 2 ], [ 19, 63, 0 ] ], + [ [ 34, 0, 1 ], [ 20, 62, 0 ] ], + [ [ 34, 0, 0 ], [ 28, 47, 0 ] ], + [ [ 34, 0, 1 ], [ 20, 63, 0 ] ], + [ [ 34, 0, 2 ], [ 21, 62, 0 ] ], + [ [ 35, 0, 1 ], [ 21, 63, 0 ] ], + [ [ 35, 0, 0 ], [ 30, 46, 0 ] ], + [ [ 35, 0, 1 ], [ 22, 62, 0 ] ], + [ [ 35, 0, 2 ], [ 22, 63, 0 ] ], + [ [ 36, 0, 1 ], [ 23, 62, 0 ] ], + [ [ 36, 0, 0 ], [ 31, 47, 0 ] ], + [ [ 36, 0, 1 ], [ 23, 63, 0 ] ], + [ [ 36, 0, 2 ], [ 24, 62, 0 ] ], + [ [ 37, 0, 1 ], [ 24, 63, 0 ] ], + [ [ 37, 0, 0 ], [ 32, 47, 0 ] ], + [ [ 37, 0, 1 ], [ 25, 62, 0 ] ], + [ [ 37, 0, 2 ], [ 25, 63, 0 ] ], + [ [ 38, 0, 1 ], [ 26, 62, 0 ] ], + [ [ 38, 0, 0 ], [ 32, 50, 0 ] ], + [ [ 38, 0, 1 ], [ 26, 63, 0 ] ], + [ [ 38, 0, 2 ], [ 27, 62, 0 ] ], + [ [ 39, 0, 1 ], [ 27, 63, 0 ] ], + [ [ 39, 0, 0 ], [ 32, 53, 0 ] ], + [ [ 39, 0, 1 ], [ 28, 62, 0 ] ], + [ [ 39, 0, 2 ], [ 28, 63, 0 ] ], + [ [ 40, 0, 1 ], [ 29, 62, 0 ] ], + [ [ 40, 0, 0 ], [ 32, 56, 0 ] ], + [ [ 40, 0, 1 ], [ 29, 63, 0 ] ], + [ [ 40, 0, 2 ], [ 30, 62, 0 ] ], + [ [ 41, 0, 1 ], [ 30, 63, 0 ] ], + [ [ 41, 0, 0 ], [ 32, 59, 0 ] ], + [ [ 41, 0, 1 ], [ 31, 62, 0 ] ], + [ [ 41, 0, 2 ], [ 31, 63, 0 ] ], + [ [ 42, 0, 1 ], [ 32, 61, 0 ] ], + [ [ 42, 0, 0 ], [ 32, 62, 0 ] ], + [ [ 42, 0, 1 ], [ 32, 63, 0 ] ], + [ [ 42, 0, 2 ], [ 41, 46, 0 ] ], + [ [ 43, 0, 1 ], [ 33, 62, 0 ] ], + [ [ 43, 0, 0 ], [ 33, 63, 0 ] ], + [ [ 43, 0, 1 ], [ 34, 62, 0 ] ], + [ [ 43, 0, 2 ], [ 42, 47, 0 ] ], + [ [ 44, 0, 1 ], [ 34, 63, 0 ] ], + [ [ 44, 0, 0 ], [ 35, 62, 0 ] ], + [ [ 44, 0, 1 ], [ 35, 63, 0 ] ], + [ [ 44, 0, 2 ], [ 44, 46, 0 ] ], + [ [ 45, 0, 1 ], [ 36, 62, 0 ] ], + [ [ 45, 0, 0 ], [ 36, 63, 0 ] ], + [ [ 45, 0, 1 ], [ 37, 62, 0 ] ], + [ [ 45, 0, 2 ], [ 45, 47, 0 ] ], + [ [ 46, 0, 1 ], [ 37, 63, 0 ] ], + [ [ 46, 0, 0 ], [ 38, 62, 0 ] ], + [ [ 46, 0, 1 ], [ 38, 63, 0 ] ], + [ [ 46, 0, 2 ], [ 47, 46, 0 ] ], + [ [ 47, 0, 1 ], [ 39, 62, 0 ] ], + [ [ 47, 0, 0 ], [ 39, 63, 0 ] ], + [ [ 47, 0, 1 ], [ 40, 62, 0 ] ], + [ [ 47, 0, 2 ], [ 48, 46, 0 ] ], + [ [ 48, 0, 2 ], [ 40, 63, 0 ] ], + [ [ 48, 0, 1 ], [ 41, 62, 0 ] ], + [ [ 48, 0, 0 ], [ 41, 63, 0 ] ], + [ [ 48, 0, 1 ], [ 48, 49, 0 ] ], + [ [ 48, 0, 2 ], [ 42, 62, 0 ] ], + [ [ 49, 0, 1 ], [ 42, 63, 0 ] ], + [ [ 49, 0, 0 ], [ 43, 62, 0 ] ], + [ [ 49, 0, 1 ], [ 48, 52, 0 ] ], + [ [ 49, 0, 2 ], [ 43, 63, 0 ] ], + [ [ 50, 0, 1 ], [ 44, 62, 0 ] ], + [ [ 50, 0, 0 ], [ 44, 63, 0 ] ], + [ [ 50, 0, 1 ], [ 48, 55, 0 ] ], + [ [ 50, 0, 2 ], [ 45, 62, 0 ] ], + [ [ 51, 0, 1 ], [ 45, 63, 0 ] ], + [ [ 51, 0, 0 ], [ 46, 62, 0 ] ], + [ [ 51, 0, 1 ], [ 48, 58, 0 ] ], + [ [ 51, 0, 2 ], [ 46, 63, 0 ] ], + [ [ 52, 0, 1 ], [ 47, 62, 0 ] ], + [ [ 52, 0, 0 ], [ 47, 63, 0 ] ], + [ [ 52, 0, 1 ], [ 48, 61, 0 ] ], + [ [ 52, 0, 2 ], [ 48, 62, 0 ] ], + [ [ 53, 0, 1 ], [ 56, 47, 0 ] ], + [ [ 53, 0, 0 ], [ 48, 63, 0 ] ], + [ [ 53, 0, 1 ], [ 49, 62, 0 ] ], + [ [ 53, 0, 2 ], [ 49, 63, 0 ] ], + [ [ 54, 0, 1 ], [ 58, 46, 0 ] ], + [ [ 54, 0, 0 ], [ 50, 62, 0 ] ], + [ [ 54, 0, 1 ], [ 50, 63, 0 ] ], + [ [ 54, 0, 2 ], [ 51, 62, 0 ] ], + [ [ 55, 0, 1 ], [ 59, 47, 0 ] ], + [ [ 55, 0, 0 ], [ 51, 63, 0 ] ], + [ [ 55, 0, 1 ], [ 52, 62, 0 ] ], + [ [ 55, 0, 2 ], [ 52, 63, 0 ] ], + [ [ 56, 0, 1 ], [ 61, 46, 0 ] ], + [ [ 56, 0, 0 ], [ 53, 62, 0 ] ], + [ [ 56, 0, 1 ], [ 53, 63, 0 ] ], + [ [ 56, 0, 2 ], [ 54, 62, 0 ] ], + [ [ 57, 0, 1 ], [ 62, 47, 0 ] ], + [ [ 57, 0, 0 ], [ 54, 63, 0 ] ], + [ [ 57, 0, 1 ], [ 55, 62, 0 ] ], + [ [ 57, 0, 2 ], [ 55, 63, 0 ] ], + [ [ 58, 0, 1 ], [ 56, 62, 1 ] ], + [ [ 58, 0, 0 ], [ 56, 62, 0 ] ], + [ [ 58, 0, 1 ], [ 56, 63, 0 ] ], + [ [ 58, 0, 2 ], [ 57, 62, 0 ] ], + [ [ 59, 0, 1 ], [ 57, 63, 1 ] ], + [ [ 59, 0, 0 ], [ 57, 63, 0 ] ], + [ [ 59, 0, 1 ], [ 58, 62, 0 ] ], + [ [ 59, 0, 2 ], [ 58, 63, 0 ] ], + [ [ 60, 0, 1 ], [ 59, 62, 1 ] ], + [ [ 60, 0, 0 ], [ 59, 62, 0 ] ], + [ [ 60, 0, 1 ], [ 59, 63, 0 ] ], + [ [ 60, 0, 2 ], [ 60, 62, 0 ] ], + [ [ 61, 0, 1 ], [ 60, 63, 1 ] ], + [ [ 61, 0, 0 ], [ 60, 63, 0 ] ], + [ [ 61, 0, 1 ], [ 61, 62, 0 ] ], + [ [ 61, 0, 2 ], [ 61, 63, 0 ] ], + [ [ 62, 0, 1 ], [ 62, 62, 1 ] ], + [ [ 62, 0, 0 ], [ 62, 62, 0 ] ], + [ [ 62, 0, 1 ], [ 62, 63, 0 ] ], + [ [ 62, 0, 2 ], [ 63, 62, 0 ] ], + [ [ 63, 0, 1 ], [ 63, 63, 1 ] ], + [ [ 63, 0, 0 ], [ 63, 63, 0 ] ] +]; + +export {lookup_5_3, lookup_6_3, lookup_5_4, lookup_6_4}; \ No newline at end of file diff --git a/src/readers/libs/dxt/math.js b/src/readers/libs/dxt/math.js new file mode 100644 index 0000000..d39ee6d --- /dev/null +++ b/src/readers/libs/dxt/math.js @@ -0,0 +1,448 @@ +import {dominentPrincipalVector} from "./eigs.js"; + +class Vec3 +{ + constructor(x=0, y=x, z=x) + { + this._values = [x, y, z]; + } + get x() + { + return this._values[0]; + } + get y() + { + return this._values[1]; + } + get z() + { + return this._values[2]; + } + set x(value) + { + this._values[0]=value; + } + set y(value) + { + this._values[1]=value; + } + set z(value) + { + this._values[2]=value; + } + get length() + { + return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); + } + get lengthSq() + { + return this.x*this.x + this.y*this.y + this.z*this.z; + } + get normalized() + { + if(this.length === 0) return null; + return Vec3.multScalar(this, 1/this.length); + } + get colorInt() + { + const floatToInt = (value)=>{ + const result = parseInt( (value * 255) + 0.5 ); + return Math.max(Math.min(result, 255), 0); + } + return this._values.map(floatToInt); + } + clone() + { + return new Vec3(this.x, this.y, this.z); + } + set(x, y=x, z=x) + { + this._values[0]=x; + this._values[1]=y; + this._values[2]=z; + + return this; + } + toVec4(w=1) + { + return new Vec4(this.x, this.y, this.z, w); + } + addVector(v) + { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + + return this; + } + addScaledVector(v, scalar) + { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + + return this; + } + mult(scalar) + { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + + return this; + } + multVector(vec) + { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + + return this; + } + clamp(min, max) + { + const clamper = (v)=>(min > v) ? min : ( (max < v) ? max : v ); + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + + return this; + } + clampGrid() + { + const clamper = (v)=>(0 > v) ? 0 : ( (1 < v) ? 1 : v ); + const gridClamper = (value, grid)=>Math.trunc(clamper(value) * grid + 0.5) / grid; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + + return this; + } + normalize() + { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + + return this; + } + toString() + { + return `Vec3( ${this._values.join(", ")} )`; + } + static add(a, b) + { + return new Vec3(a.x+b.x, a.y+b.y, a.z+b.z); + } + static sub(a, b) + { + return new Vec3(a.x-b.x, a.y-b.y, a.z-b.z); + } + static dot(a, b) + { + return (a.x*b.x)+(a.y*b.y)+(a.z*b.z); + } + static multScalar(a, scalar) + { + return new Vec3(a.x*scalar, a.y*scalar, a.z*scalar); + } + static multVector(a, b) + { + return new Vec3(a.x*b.x, a.y*b.y, a.z*b.z); + } + static interpolate(a, b, p) + { + let a_=Vec3.multScalar(a, 1-p); + let b_=Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } +} + + +class Vec4 +{ + constructor(x=0, y=x, z=x, w=x) + { + this._values = [x, y, z, w]; + } + get x() + { + return this._values[0]; + } + get y() + { + return this._values[1]; + } + get z() + { + return this._values[2]; + } + get w() + { + return this._values[3]; + } + set x(value) + { + this._values[0]=value; + } + set y(value) + { + this._values[1]=value; + } + set z(value) + { + this._values[2]=value; + } + set w(value) + { + this._values[3]=value; + } + get length() + { + return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z + this.w*this.w); + } + get lengthSq() + { + return this.x*this.x + this.y*this.y + this.z*this.z + this.w*this.w; + } + get normalized() + { + if(this.length === 0) return null; + return Vec4.multScalar(this, 1/this.length); + } + get xyz() + { + return new Vec3(this.x, this.y, this.z); + } + // idk what is "splat", but these functions returns new Vec4 filled with (x,x,x,x). + get splatX() + { + return new Vec4(this.x); + } + get splatY() + { + return new Vec4(this.y); + } + get splatZ() + { + return new Vec4(this.z); + } + get splatW() + { + return new Vec4(this.w); + } + clone() + { + return new Vec4(this.x, this.y, this.z, this.w); + } + set(x, y=x, z=x, w=x) + { + this._values[0]=x; + this._values[1]=y; + this._values[2]=z; + this._values[3]=w; + + return this; + } + toVec3() + { + return this.xyz; + } + addVector(v) + { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + + return this; + } + addScaledVector(v, scalar) + { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + + return this; + } + subVector(v) + { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + + return this; + } + mult(scalar) + { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + + return this; + } + multVector(vec) + { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + + return this; + } + reciprocal() + { + this._values[0] = 1/this._values[0]; + this._values[1] = 1/this._values[1]; + this._values[2] = 1/this._values[2]; + this._values[3] = 1/this._values[3]; + + return this; + } + clamp(min, max) + { + const clamper = (v)=>(min > v) ? min : ( (max < v) ? max : v ); + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + + return this; + } + clampGrid() + { + const clamper = (v)=>(0 > v) ? 0 : ( (1 < v) ? 1 : v ); + const gridClamper = (value, grid)=>Math.trunc(clamper(value) * grid + 0.5) / grid; + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + + return this; + } + truncate() + { + this._values[0]= Math.trunc(this._values[0]); + this._values[1]= Math.trunc(this._values[1]); + this._values[2]= Math.trunc(this._values[2]); + this._values[3]= Math.trunc(this._values[3]); + + return this; + } + normalize() + { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + + return this; + } + toString() + { + return `Vec4( ${this._values.join(", ")} )`; + } + static add(a, b) + { + return new Vec4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); + } + static sub(a, b) + { + return new Vec4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); + } + static dot(a, b) + { + return (a.x*b.x)+(a.y*b.y)+(a.z*b.z)+(a.w*b.w); + } + static multScalar(a, scalar) + { + return new Vec4(a.x*scalar, a.y*scalar, a.z*scalar, a.w*scalar); + } + static multVector(a, b) + { + return new Vec4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); + } + static interpolate(a, b, p) + { + let a_=Vec4.multScalar(a, 1-p); + let b_=Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + // returns a*b + c + static multiplyAdd(a, b, c) + { + return new Vec4( + a.x*b.x+c.x, + a.y*b.y+c.y, + a.z*b.z+c.z, + a.w*b.w+c.w); + } + // returns c - a*b + static negativeMultiplySubtract(a, b, c) + { + return new Vec4( + c.x-a.x*b.x, + c.y-a.y*b.y, + c.z-a.z*b.z, + c.w-a.w*b.w); + } + static compareAnyLessThan(left, right) + { + return (left.x < right.x + || left.y < right.y + || left.z < right.z + || left.w < right.w); + } +} + + + + +function computeWeightedCovariance(values, weights) +{ + //compute the mean vector + let total = 0; + let mean = values.reduce((sum, value, i)=>{ + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1/total); + + //compute the covariance matrix + //sigma( (x-m)*(x-m)^T ) + + // [0(xx) 1(xy) 2(xz)] + // [1(xy) 3(yy) 4(yz)] + // [2(xz) 4(yz) 5(zz)] + let covariance = values.reduce((sum, value, i)=>{ + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; sum[0][1] += v.x * v.y * weight; sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; sum[1][2] += v.y * v.z * weight; sum[2][2] += v.z * v.z * weight; + + return sum; + }, [[0,0,0], + [0,0,0], + [0,0,0]]); + + //post-processing + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + // there is no need to divide by total since the eigenvector of the scalar multiplied matrix + // is the same as the eigenvector of the original matrix. + + return covariance; +} + +function computePCA(values, weights) +{ + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance) ); +} + +export {Vec3, Vec4, computePCA}; \ No newline at end of file diff --git a/src/readers/package.json b/src/readers/package.json new file mode 100644 index 0000000..1f8aad0 --- /dev/null +++ b/src/readers/package.json @@ -0,0 +1,24 @@ +{ + "name": "@xnb/readers", + "version": "1.1.0", + "description": "The basic readers of xnb.js.", + "main": "./dist/readers.js", + "module": "./dist/readers.module.js", + "export": { + ".": { + "import": "./dist/readers.module.js", + "require": "./dist/readers.cjs" + } + }, + "files": [ + "dist" + ], + "keywords": [ + "xnb", + "converter", + "javascript", + "stardew-valley" + ], + "author": "Lybell", + "license": "LGPL-3.0-or-later" +} diff --git a/src/readers/readers.js b/src/readers/readers.js new file mode 100644 index 0000000..1a823f9 --- /dev/null +++ b/src/readers/readers.js @@ -0,0 +1,49 @@ +import ArrayReader from "./readers/ArrayReader.js"; +import BaseReader from "./readers/BaseReader.js"; +import BmFontReader from "./readers/BmFontReader.js"; +import BooleanReader from "./readers/BooleanReader.js"; +import CharReader from "./readers/CharReader.js"; +import DictionaryReader from "./readers/DictionaryReader.js"; +import DoubleReader from "./readers/DoubleReader.js"; +import EffectReader from "./readers/EffectReader.js"; +import Int32Reader from "./readers/Int32Reader.js"; +import ListReader from "./readers/ListReader.js"; +import NullableReader from "./readers/NullableReader.js"; +import ReflectiveReader from "./readers/ReflectiveReader.js"; +import RectangleReader from "./readers/RectangleReader.js"; +import SingleReader from "./readers/SingleReader.js"; +import SpriteFontReader from "./readers/SpriteFontReader.js"; +import StringReader from "./readers/StringReader.js"; +import TBinReader from "./readers/TBinReader.js"; +import LightweightTexture2DReader from "./readers/LightweightTexture2DReader.js"; +import Texture2DReader from "./readers/Texture2DReader.js"; +import UInt32Reader from "./readers/UInt32Reader.js"; +import Vector2Reader from "./readers/Vector2Reader.js"; +import Vector3Reader from "./readers/Vector3Reader.js"; +import Vector4Reader from "./readers/Vector4Reader.js"; + +export { + ArrayReader, + BaseReader, + BmFontReader, + BooleanReader, + CharReader, + DictionaryReader, + DoubleReader, + EffectReader, + Int32Reader, + ListReader, + NullableReader, + RectangleReader, + ReflectiveReader, + SingleReader, + SpriteFontReader, + StringReader, + TBinReader, + LightweightTexture2DReader, + Texture2DReader, + UInt32Reader, + Vector2Reader, + Vector3Reader, + Vector4Reader +} \ No newline at end of file diff --git a/src/App/Readers/ArrayReader.js b/src/readers/readers/ArrayReader.js similarity index 90% rename from src/App/Readers/ArrayReader.js rename to src/readers/readers/ArrayReader.js index 9c7e29e..664dc28 100644 --- a/src/App/Readers/ArrayReader.js +++ b/src/readers/readers/ArrayReader.js @@ -1,5 +1,4 @@ import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; import UInt32Reader from "./UInt32Reader.js"; /** @@ -8,6 +7,16 @@ import UInt32Reader from "./UInt32Reader.js"; * @extends BaseReader */ export default class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + default: return false; + } + } + static hasSubType() { + return true; + } /** * Constructor for the ArrayReader diff --git a/src/readers/readers/BaseReader.js b/src/readers/readers/BaseReader.js new file mode 100644 index 0000000..b9f3012 --- /dev/null +++ b/src/readers/readers/BaseReader.js @@ -0,0 +1,79 @@ +/** + * Base class for all readers. + * @abstract + * @class + */ +export default class BaseReader { + static isTypeOf(type) { + return false; + } + static hasSubType() { + return false; + } + static parseTypeList(subtype=[]) { + return [this.type(), ...subtype]; + } + static type() + { + return this.name.slice(0, -6); + } + + /** + * Returns if type normally requires a special reader. + * @public + * @method + * @returns {Boolean} Returns true if type is primitive. + */ + isValueType() { + return true; + } + + /** + * Returns string type of reader + * @public + * @property + * @returns {string} + */ + get type() { + return this.constructor.type(); + } + + /** + * Reads the buffer by the specification of the type reader. + * @public + * @param {BufferReader} buffer The buffer to read from. + * @param {ReaderResolver} resolver The content reader to resolve readers from. + * @returns {mixed} Returns the type as specified by the type reader. + */ + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + /** + * Writes into the buffer + * @param {BufferWriter} buffer The buffer to write to + * @param {Mixed} data The data to parse to write to the buffer + * @param {ReaderResolver} resolver ReaderResolver to write non-primitive types + */ + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + /** + * Writes the index of this reader to the buffer + * @param {BufferWriter} buffer + * @param {ReaderResolver} resolver + */ + writeIndex(buffer, resolver) { + if (resolver != null) + buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + /** + * When printing out in a string. + * @returns {String} + */ + toString() { + return this.type; + } +} \ No newline at end of file diff --git a/src/readers/readers/BmFontReader.js b/src/readers/readers/BmFontReader.js new file mode 100644 index 0000000..db6d3aa --- /dev/null +++ b/src/readers/readers/BmFontReader.js @@ -0,0 +1,45 @@ +import BaseReader from "./BaseReader.js"; +import StringReader from "./StringReader.js"; + +/** + * BmFont Reader + * @class + * @extends BaseReader + */ +export default class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + default: return false; + } + } + + /** + * Reads BmFont from buffer. + * @param {BufferReader} buffer + * @returns {Object} + */ + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { export: { type: this.type, data: xml } }; + } + + /** + * Writes BmFont into buffer + * @param {BufferWriter} buffer + * @param {Mixed} data + * @param {ReaderResolver} + */ + write(buffer, content, resolver) { + // write index of reader + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/readers/readers/BooleanReader.js b/src/readers/readers/BooleanReader.js new file mode 100644 index 0000000..d3e1a12 --- /dev/null +++ b/src/readers/readers/BooleanReader.js @@ -0,0 +1,37 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Boolean Reader + * @class + * @extends BaseReader + */ +export default class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + default: return false; + } + } + + /** + * Reads Boolean from buffer. + * @param {BufferReader} buffer + * @returns {Boolean} + */ + read(buffer) { + return Boolean(buffer.readInt()); + } + + /** + * Writes Boolean into buffer + * @param {BufferWriter} buffer + * @param {Mixed} data + * @param {ReaderResolver} + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } +} diff --git a/src/readers/readers/CharReader.js b/src/readers/readers/CharReader.js new file mode 100644 index 0000000..0bce936 --- /dev/null +++ b/src/readers/readers/CharReader.js @@ -0,0 +1,47 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Char Reader + * @class + * @extends BaseReader + */ +export default class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + default: return false; + } + } + + /** + * Reads Char from the buffer. + * @param {BufferReader} buffer + * @returns {String} + */ + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + return buffer.readString(charSize); + } + + /** + * Writes Char into buffer + * @param {BufferWriter} buffer + * @param {Mixed} data + * @param {ReaderResolver} + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + /** + * Gets size of char for some special characters that are more than one byte. + * @param {Number} byte + * @returns {Number} + */ + _getCharSize(byte) { + return (( 0xE5000000 >> (( byte >> 3 ) & 0x1e )) & 3 ) + 1; + } +} \ No newline at end of file diff --git a/src/readers/readers/DictionaryReader.js b/src/readers/readers/DictionaryReader.js new file mode 100644 index 0000000..59008e5 --- /dev/null +++ b/src/readers/readers/DictionaryReader.js @@ -0,0 +1,100 @@ +import BaseReader from "./BaseReader.js"; +import UInt32Reader from "./UInt32Reader.js"; + +/** + * Dictionary Reader + * @class + * @extends BaseReader + */ +export default class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + default: return false; + } + } + static hasSubType() { + return true; + } + + /** + * Constructor for DictionaryReader. + * @constructor + * @param {BaseReader} key The BaseReader for the dictionary key. + * @param {BaseReader} value The BaseReader for the dictionary value. + */ + constructor(key, value) { + // verify key and value are specified + if (key == undefined || value == undefined) + throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + + // call base constructor + super(); + + /** @type {BaseReader} */ + this.key = key; + /** @type {BaseReader} */ + this.value = value; + } + + /** + * Reads Dictionary from buffer. + * @param {BufferReader} buffer Buffer to read from. + * @param {ReaderResolver} resolver ReaderResolver to read non-primitive types. + * @returns {object} + */ + read(buffer, resolver) { + // the dictionary to return + let dictionary = {}; + + // read in the size of the dictionary + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + // loop over the size of the dictionary and read in the data + for (let i = 0; i < size; i++) { + // get the key + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + // get the value + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + + // assign KV pair to the dictionary + dictionary[key] = value; + } + + // return the dictionary object + return dictionary; + } + + /** + * Writes Dictionary into buffer + * @param {BufferWriter} buffer + * @param {Object} data The data to parse for the + * @param {ReaderResolver} resolver ReaderResolver to write non-primitive types + * @returns {Buffer} buffer instance with the data in it + */ + write(buffer, content, resolver) { + // write the index + this.writeIndex(buffer, resolver); + + // write the amount of entries in the Dictionary + buffer.writeUInt32(Object.keys(content).length); + + // loop over the entries + for (let key of Object.keys(content)) { + // write the key + this.key.write(buffer, key, (this.key.isValueType() ? null : resolver)); + // write the value + this.value.write(buffer, content[key], (this.value.isValueType() ? null : resolver)); + } + } + + isValueType() { + return false; + } + + get type() { + return `Dictionary<${this.key.type},${this.value.type}>`; + } +} diff --git a/src/readers/readers/DoubleReader.js b/src/readers/readers/DoubleReader.js new file mode 100644 index 0000000..46daf14 --- /dev/null +++ b/src/readers/readers/DoubleReader.js @@ -0,0 +1,37 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Double Reader + * @class + * @extends BaseReader + */ +export default class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + default: return false; + } + } + + /** + * Reads Double from buffer. + * @param {BufferReader} buffer + * @returns {Number} + */ + read(buffer) { + return buffer.readDouble(); + } + + /** + * Writes Double into buffer + * @param {BufferWriter} buffer + * @param {Mixed} data + * @param {ReaderResolver} + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } +} diff --git a/src/readers/readers/EffectReader.js b/src/readers/readers/EffectReader.js new file mode 100644 index 0000000..8ab62f8 --- /dev/null +++ b/src/readers/readers/EffectReader.js @@ -0,0 +1,47 @@ +import BaseReader from "./BaseReader.js"; +import UInt32Reader from "./UInt32Reader.js"; + +/** + * Effect Reader + * @class + * @extends BaseReader + */ +export default class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + default: return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + + return { export: { type: this.type, data: bytecode } }; + } + + /** + * Writes Effects into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/readers/readers/Int32Reader.js b/src/readers/readers/Int32Reader.js new file mode 100644 index 0000000..1461b93 --- /dev/null +++ b/src/readers/readers/Int32Reader.js @@ -0,0 +1,37 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Int32 Reader + * @class + * @extends BaseReader + */ +export default class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + default: return false; + } + } + + /** + * Reads Int32 from buffer. + * @param {BufferReader} buffer + * @returns {Number} + */ + read(buffer) { + return buffer.readInt32(); + } + + /** + * Writes Int32 and returns buffer + * @param {BufferWriter} buffer + * @param {Number} content + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } +} \ No newline at end of file diff --git a/src/readers/readers/LightweightTexture2DReader.js b/src/readers/readers/LightweightTexture2DReader.js new file mode 100644 index 0000000..1f87996 --- /dev/null +++ b/src/readers/readers/LightweightTexture2DReader.js @@ -0,0 +1,108 @@ +import BaseReader from "./BaseReader.js"; +import Int32Reader from "./Int32Reader.js"; +import UInt32Reader from "./UInt32Reader.js"; + +/** + * Lightweight Texture2D Reader. Exclude DXT compressors. + * @class + * @extends BaseReader + */ +export default class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + default: return false; + } + } + static type() + { + return "Texture2D"; + } + + /** + * Reads Texture2D from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + + if (mipCount > 1) + console.warn(`Found mipcount of ${mipCount}, only the first will be used.`); + + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + + if (format != 0) + throw new Error("Compressed texture format is not supported!"); + + // add the alpha channel into the image + for(let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i ] = Math.min(Math.ceil(data[i ] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + /** + * Writes Texture2D into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + + this.writeIndex(buffer, resolver); + + const width = content.export.width; + const height = content.export.height; + + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i ] = Math.floor(data[i ] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() + { + return "Texture2D"; + } +} diff --git a/src/readers/readers/ListReader.js b/src/readers/readers/ListReader.js new file mode 100644 index 0000000..ef355d6 --- /dev/null +++ b/src/readers/readers/ListReader.js @@ -0,0 +1,70 @@ +import BaseReader from "./BaseReader.js"; +import UInt32Reader from "./UInt32Reader.js"; + +/** + * List Reader + * @class + * @extends BaseReader + */ +export default class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + default: return false; + } + } + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + /** @type {BaseReader} */ + this.reader = reader; + } + + /** + * Reads List from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {Array} + */ + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + const list = []; + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + return list; + } + + /** + * Writes List into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + for (let data of Object.values(content) ) + { + this.reader.write(buffer, data, (this.reader.isValueType() ? null : resolver)); + } + } + + isValueType() + { + return false; + } + + get type() { + return `List<${this.reader.type}>`; + } +} diff --git a/src/readers/readers/NullableReader.js b/src/readers/readers/NullableReader.js new file mode 100644 index 0000000..4e2488c --- /dev/null +++ b/src/readers/readers/NullableReader.js @@ -0,0 +1,85 @@ +import BaseReader from "./BaseReader.js"; +import BooleanReader from "./BooleanReader.js"; + +/** + * Nullable Reader + * @class + * @extends BaseReader + */ +export default class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + default: return false; + } + } + static hasSubType() { + return true; + } + + /** + * @constructor + * @param {BaseReader} reader + */ + constructor(reader) { + super(); + /** + * Nullable type + * @type {BaseReader} + */ + this.reader = reader; + } + + /** + * Reads Nullable type from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {mixed|null} + */ + read(buffer, resolver=null) { + // get an instance of boolean reader + const booleanReader = new BooleanReader(); + // read in if the nullable has a value or not + const hasValue = buffer.peekByte(1); + + if(!hasValue) + { + booleanReader.read(buffer); + return null; + } + if(resolver === null) + { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + return (this.reader.isValueType()) ? resolver.read(buffer) : this.reader.read(buffer); + } + + /** + * Writes Nullable into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content=null, resolver=null) { + //this.writeIndex(buffer, resolver); + const booleanReader = new BooleanReader(); + + if(content !== null) + { + buffer.writeByte(0); + return; + } + if(resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, (this.reader.isValueType() ? null : resolver)); + } + + isValueType() { + return false; + } + + get type() { + return `Nullable<${this.reader.type}>`; + } +} diff --git a/src/readers/readers/RectangleReader.js b/src/readers/readers/RectangleReader.js new file mode 100644 index 0000000..164b683 --- /dev/null +++ b/src/readers/readers/RectangleReader.js @@ -0,0 +1,49 @@ +import BaseReader from "./BaseReader.js"; +import Int32Reader from "./Int32Reader.js"; + +/** + * Rectangle Reader + * @class + * @extends BaseReader + */ +export default class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + default: return false; + } + } + + /** + * Reads Rectangle from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const int32Reader = new Int32Reader(); + + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + + return { x, y, width, height }; + } + + /** + * Writes Effects into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } +} diff --git a/src/readers/readers/ReflectiveReader.js b/src/readers/readers/ReflectiveReader.js new file mode 100644 index 0000000..9278168 --- /dev/null +++ b/src/readers/readers/ReflectiveReader.js @@ -0,0 +1,61 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Reflective Reader + * @class + * @extends BaseReader + */ +export default class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + default: return false; + } + } + static hasSubType() { + return true; + } + + /** + * @constructor + * @param {BaseReader} reader + */ + constructor(reader) { + super(); + /** + * Reflective type + * @type {BaseReader} + */ + this.reader = reader; + } + + /** + * Reads Reflection data from buffer. + * @param {BufferReader} buffer + * @returns {Mixed} + */ + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } + + /** + * Writes Reflection data and returns buffer + * @param {BufferWriter} buffer + * @param {Number} content + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + this.reader.write(buffer, content, (this.reader.isValueType() ? null : resolver)); + } + + isValueType() { + return false; + } + + get type() { + return `${this.reader.type}`; + } +} diff --git a/src/readers/readers/SingleReader.js b/src/readers/readers/SingleReader.js new file mode 100644 index 0000000..7cec400 --- /dev/null +++ b/src/readers/readers/SingleReader.js @@ -0,0 +1,31 @@ +import BaseReader from "./BaseReader.js"; + +/** + * Single Reader + * @class + * @extends BaseReader + */ +export default class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + default: return false; + } + } + + /** + * Reads Single from the buffer. + * @param {BufferReader} buffer + * @returns {Number} + */ + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } +} diff --git a/src/readers/readers/SpriteFontReader.js b/src/readers/readers/SpriteFontReader.js new file mode 100644 index 0000000..9fa6748 --- /dev/null +++ b/src/readers/readers/SpriteFontReader.js @@ -0,0 +1,99 @@ +import BaseReader from "./BaseReader.js"; +import Int32Reader from "./Int32Reader.js"; +import SingleReader from "./SingleReader.js"; +import NullableReader from "./NullableReader.js"; +import CharReader from "./CharReader.js"; +import Texture2DReader from "./Texture2DReader.js"; +import ListReader from "./ListReader.js"; +import RectangleReader from "./RectangleReader.js"; +import Vector3Reader from "./Vector3Reader.js"; + +/** + * SpriteFont Reader + * @class + * @extends BaseReader + */ +export default class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + default: return false; + } + } + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', + 'List', 'Rectangle', + 'List', 'Char', + null, null, + 'List', 'Vector3', + 'Nullable', 'Char']; + } + + /** + * Reads SpriteFont from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + // Allocate space in the buffer in advance to minimize reallocation to improve performance. + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } + catch (ex) { + throw ex; + } + + console.log("writing complitd!"); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/readers/readers/StringReader.js b/src/readers/readers/StringReader.js new file mode 100644 index 0000000..b5fca45 --- /dev/null +++ b/src/readers/readers/StringReader.js @@ -0,0 +1,51 @@ +import BaseReader from "./BaseReader.js"; +import {UTF8Length} from "../libs/UTF8ToString.js"; + +/** + * String Reader + * @class + * @extends BaseReader + */ +export default class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + default: return false; + } + } + + /** + * Reads String from buffer. + * @param {BufferReader} buffer + * @returns {String} + */ + read(buffer) { + // read in the length of the string + let length = buffer.read7BitNumber(); + // read in the UTF-8 encoded string + return buffer.readString(length); + } + + /** + * Writes the string to the buffer. + * @param {BufferWriter} buffer + * @param {String} string + * @param {ReaderResolver} resolver + */ + write(buffer, string, resolver) { + // write the index + this.writeIndex(buffer, resolver); + // get the size of UTF-8 encoded string + const size = UTF8Length(string); + // write the length of the string + buffer.write7BitNumber(size); + // write the string + buffer.writeString(string); + } + + isValueType() { + return false; + } +} diff --git a/src/readers/readers/TBinReader.js b/src/readers/readers/TBinReader.js new file mode 100644 index 0000000..698fd6b --- /dev/null +++ b/src/readers/readers/TBinReader.js @@ -0,0 +1,41 @@ +import BaseReader from "./BaseReader.js"; +import Int32Reader from "./Int32Reader.js"; + +/** + * TBin Reader + * @class + * @extends BaseReader + */ +export default class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + default: return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + + // read in the size of the data block + let size = int32Reader.read(buffer); + // read in the data block + let data = buffer.read(size); + + // return the data + return { export: { type: this.type, data } }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } +} diff --git a/src/readers/readers/Texture2DReader.js b/src/readers/readers/Texture2DReader.js new file mode 100644 index 0000000..1fcb91b --- /dev/null +++ b/src/readers/readers/Texture2DReader.js @@ -0,0 +1,115 @@ +import BaseReader from "./BaseReader.js"; +import Int32Reader from "./Int32Reader.js"; +import UInt32Reader from "./UInt32Reader.js"; +import * as dxt from "../libs/dxt.js"; + +/** + * Texture2D Reader + * @class + * @extends BaseReader + */ +export default class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + default: return false; + } + } + + /** + * Reads Texture2D from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + + if (mipCount > 1) + console.warn(`Found mipcount of ${mipCount}, only the first will be used.`); + + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + + if (format == 4) + data = dxt.decompress(data, width, height, dxt.flags.DXT1); + else if (format == 5) + data = dxt.decompress(data, width, height, dxt.flags.DXT3); + else if (format == 6) + data = dxt.decompress(data, width, height, dxt.flags.DXT5); + else if (format == 2) { + // require('fs').writeFileSync('texture.bin', data); + throw new Error('Texture2D format type ECT1 not implemented!'); + } + else if (format != 0) + throw new Error(`Non-implemented Texture2D format type (${format}) found.`); + + // add the alpha channel into the image + for(let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i ] = Math.min(Math.ceil(data[i ] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + /** + * Writes Texture2D into the buffer + * @param {BufferWriter} buffer + * @param {Mixed} data The data + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + + this.writeIndex(buffer, resolver); + + const width = content.export.width; + const height = content.export.height; + + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i ] = Math.floor(data[i ] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) + data = dxt.compress(data, width, height, dxt.flags.DXT1); + else if (content.format == 5) + data = dxt.compress(data, width, height, dxt.flags.DXT3); + else if (content.format == 6) + data = dxt.compress(data, width, height, dxt.flags.DXT5); + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } +} diff --git a/src/readers/readers/UInt32Reader.js b/src/readers/readers/UInt32Reader.js new file mode 100644 index 0000000..b0040d7 --- /dev/null +++ b/src/readers/readers/UInt32Reader.js @@ -0,0 +1,37 @@ +import BaseReader from "./BaseReader.js"; + +/** + * UInt32 Reader + * @class + * @extends BaseReader + */ +export default class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + default: return false; + } + } + + /** + * Reads UInt32 from buffer. + * @param {BufferReader} buffer + * @returns {Number} + */ + read(buffer) { + return buffer.readUInt32(); + } + + /** + * + * @param {BufferWriter} buffer + * @param {Number} content + * @param {ReaderResolver} resolver + */ + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } +} \ No newline at end of file diff --git a/src/readers/readers/Vector2Reader.js b/src/readers/readers/Vector2Reader.js new file mode 100644 index 0000000..3c4ef6b --- /dev/null +++ b/src/readers/readers/Vector2Reader.js @@ -0,0 +1,32 @@ +import BaseReader from "./BaseReader.js"; +import SingleReader from "./SingleReader.js"; + +/** + * Vector2 Reader + * @class + * @extends BaseReader + */ +export default class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + default: return false; + } + } + + /** + * Reads Vector2 from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const singleReader = new SingleReader(); + + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + + return { x, y }; + } +} diff --git a/src/readers/readers/Vector3Reader.js b/src/readers/readers/Vector3Reader.js new file mode 100644 index 0000000..1d93c7f --- /dev/null +++ b/src/readers/readers/Vector3Reader.js @@ -0,0 +1,41 @@ +import BaseReader from "./BaseReader.js"; +import SingleReader from "./SingleReader.js"; + +/** + * Vector3 Reader + * @class + * @extends BaseReader + */ +export default class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + default: return false; + } + } + + /** + * Reads Vector3 from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const singleReader = new SingleReader(); + + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + + return { x, y, z }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } +} diff --git a/src/readers/readers/Vector4Reader.js b/src/readers/readers/Vector4Reader.js new file mode 100644 index 0000000..5a19681 --- /dev/null +++ b/src/readers/readers/Vector4Reader.js @@ -0,0 +1,33 @@ +import BaseReader from "./BaseReader.js"; +import SingleReader from "./SingleReader.js"; +/** + * Vector4 Reader + * @class + * @extends BaseReader + */ +export default class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + default: return false; + } + } + + /** + * Reads Vector4 from buffer. + * @param {BufferReader} buffer + * @returns {object} + */ + read(buffer) { + const singleReader = new SingleReader(); + + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + + return { x, y, z, w }; + } +} \ No newline at end of file diff --git a/src/xnb.js b/src/xnb.js new file mode 100644 index 0000000..ae23dbf --- /dev/null +++ b/src/xnb.js @@ -0,0 +1,63 @@ +import { + setReaders, + addReaders, + + unpackToXnbData, + unpackToContent, + unpackToFiles, + + bufferToXnb, + bufferToContents, + + xnbDataToContent, + xnbDataToFiles, + pack, + XnbData, + XnbContent +} from "./core/Xnb.js"; // @xnb/core +import * as Reader from "./readers/readers.js"; // @xnb/readers + +const Readers = { + ArrayReader:Reader.ArrayReader, + BaseReader:Reader.BaseReader, + BmFontReader:Reader.BmFontReader, + BooleanReader:Reader.BooleanReader, + CharReader:Reader.CharReader, + DictionaryReader:Reader.DictionaryReader, + DoubleReader:Reader.DoubleReader, + EffectReader:Reader.EffectReader, + Int32Reader:Reader.Int32Reader, + ListReader:Reader.ListReader, + NullableReader:Reader.NullableReader, + RectangleReader:Reader.RectangleReader, + ReflectiveReader:Reader.ReflectiveReader, + SingleReader:Reader.SingleReader, + SpriteFontReader:Reader.SpriteFontReader, + StringReader:Reader.StringReader, + TBinReader:Reader.TBinReader, + Texture2DReader:Reader.Texture2DReader, + UInt32Reader:Reader.UInt32Reader, + Vector2Reader:Reader.Vector2Reader, + Vector3Reader:Reader.Vector3Reader, + Vector4Reader:Reader.Vector4Reader +}; + +setReaders(Readers); + +export { + Readers, + addReaders, + + unpackToXnbData, + unpackToContent, + unpackToFiles, + + bufferToXnb, + bufferToContents, + + xnbDataToContent, + xnbDataToFiles, + pack, + XnbData, + XnbContent +}; \ No newline at end of file From 9b7748ed586902da8ce73f1847ae6ec527c008f7 Mon Sep 17 00:00:00 2001 From: lybell Date: Mon, 23 May 2022 01:10:30 +0900 Subject: [PATCH 02/11] Add some stardew readers --- src/core/App/ReaderResolver.js | 4 + src/core/App/Readers/TypeReader.js | 13 +-- src/core/App/XnbConverter.js | 5 +- src/core/Utils/xnbNodeConverter.js | 29 +++++- .../Readers/BundleDataReader.js | 85 ++++++++++++++++ .../Readers/BundleSetDataReader.js | 52 ++++++++++ .../Readers/ConcessionItemDataReader.js | 81 ++++++++++++++++ .../Readers/HomeRenovationReader.js | 93 ++++++++++++++++++ .../Readers/MovieDataReader.js | 83 ++++++++++++++++ .../Readers/MovieSceneReader.js | 96 +++++++++++++++++++ .../Readers/RandomBundleDataReader.js | 74 ++++++++++++++ .../Readers/RectGroupReader.js | 52 ++++++++++ .../Readers/RectReader.js | 28 ++++++ .../Readers/RenovationValueReader.js | 55 +++++++++++ .../Readers/SpecialOrderDataReader.js | 59 ++++++++++++ src/plugins-stardewvalley/readers.js | 27 ++++++ src/readers/readers/ArrayReader.js | 4 + src/readers/readers/BaseReader.js | 8 +- src/readers/readers/DictionaryReader.js | 8 +- src/readers/readers/ListReader.js | 4 + src/readers/readers/NullableReader.js | 9 +- src/readers/readers/ReflectiveReader.js | 6 +- src/readers/readers/SpriteFontReader.js | 2 - 23 files changed, 851 insertions(+), 26 deletions(-) create mode 100644 src/plugins-stardewvalley/Readers/BundleDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/BundleSetDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/HomeRenovationReader.js create mode 100644 src/plugins-stardewvalley/Readers/MovieDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/MovieSceneReader.js create mode 100644 src/plugins-stardewvalley/Readers/RandomBundleDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/RectGroupReader.js create mode 100644 src/plugins-stardewvalley/Readers/RectReader.js create mode 100644 src/plugins-stardewvalley/Readers/RenovationValueReader.js create mode 100644 src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js diff --git a/src/core/App/ReaderResolver.js b/src/core/App/ReaderResolver.js index ebccefc..844e059 100644 --- a/src/core/App/ReaderResolver.js +++ b/src/core/App/ReaderResolver.js @@ -1,5 +1,6 @@ import BufferReader from "./BufferReader.js"; import XnbError from "../Utils/XnbError.js"; +import Debug from "../Utils/Debug.js"; /** * Class used to read the XNB types using the readers @@ -26,8 +27,11 @@ class ReaderResolver { * @param {BufferReader} buffer The buffer to read from. */ read(buffer) { + Debug(`Buffer Position : 0x${buffer.bytePosition.toString(16)}`); // read the index of which reader to use let index = buffer.read7BitNumber() - 1; + Debug(`Reader Index : ${index+1}`); + if (this.readers[index] == null) throw new XnbError(`Invalid reader index ${index}`); // read the buffer using the selected reader diff --git a/src/core/App/Readers/TypeReader.js b/src/core/App/Readers/TypeReader.js index 7b09dab..dd0b4bb 100644 --- a/src/core/App/Readers/TypeReader.js +++ b/src/core/App/Readers/TypeReader.js @@ -123,17 +123,8 @@ class TypeReader * @returns {Array} returns an type structure array for yaml convertion. */ static getReaderTypeList(typeString){ - // get type info for complex types - let {type, subtypes} = TypeReader.getTypeInfo(typeString); -// // loop over subtypes and resolve readers for them -// subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); - - // if we have a reader then use one - if (TypeReader.readers.hasOwnProperty(`${type}Reader`)) - return TypeReader.readers[`${type}Reader`].parseTypeList(subtypes); - - // throw an error as type is not supported - throw new XnbError(`Invalid reader type "${typeString}" passed, unable to resolve!`); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } diff --git a/src/core/App/XnbConverter.js b/src/core/App/XnbConverter.js index de03a7d..21a7580 100644 --- a/src/core/App/XnbConverter.js +++ b/src/core/App/XnbConverter.js @@ -87,8 +87,6 @@ class XnbConverter { // print out the file size Debug(`File size: ${this.fileSize} bytes.`); - - // if the file is compressed then we need to decompress it if (this.compressed) { @@ -158,6 +156,9 @@ class XnbConverter { readers.push({ type, version }); } + Debug( readers.map( ({type})=>TypeReader.simplifyType(type) ) ); + Debug( this.buffer.buffer ); + // get the 7-bit value for shared resources const shared = this.buffer.read7BitNumber(); diff --git a/src/core/Utils/xnbNodeConverter.js b/src/core/Utils/xnbNodeConverter.js index c749ef2..7b53c0d 100644 --- a/src/core/Utils/xnbNodeConverter.js +++ b/src/core/Utils/xnbNodeConverter.js @@ -43,6 +43,7 @@ function isPrimitiveReaderType(reader) case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: return false; } @@ -89,14 +90,30 @@ function convertJsonContentsToXnbNode(raw, readers) } //nullable + //Nullable format is Nullable:(traversed block size) if(reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed=1] = reader.split(":"); + blockTraversed = +blockTraversed; + if(obj === null) + { + nullableData = null; + trav = index + blockTraversed; + } + else + { + let {converted, traversed} = recursiveConvert( obj, [...path], index+1 ); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, - data: {data:{ type:readers[index+1], data:obj } } + type: readerType, + data: {data:nullableData} }, - traversed: index + 1 + traversed: trav }; } @@ -178,6 +195,12 @@ function convertJsonContentsFromXnbNode(obj) return data; } + if(type.startsWith("Nullable")) + { + if(data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/src/plugins-stardewvalley/Readers/BundleDataReader.js b/src/plugins-stardewvalley/Readers/BundleDataReader.js new file mode 100644 index 0000000..ae5fa1f --- /dev/null +++ b/src/plugins-stardewvalley/Readers/BundleDataReader.js @@ -0,0 +1,85 @@ +import {BaseReader, + Int32Reader, + StringReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * BundleData Reader + * @class + * @extends BaseReader + */ +export default class BundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["BundleData", + "String", // name + null, // index + "String", // sprite + "String", // color + "String", // items + null, // pick + null, // requireItems + "String", // reward + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads BundleData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/BundleSetDataReader.js b/src/plugins-stardewvalley/Readers/BundleSetDataReader.js new file mode 100644 index 0000000..9321014 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/BundleSetDataReader.js @@ -0,0 +1,52 @@ +import {BaseReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import BundleDataReader from "./BundleDataReader.js"; + +/** + * BundleSetData Reader + * @class + * @extends BaseReader + */ +export default class BundleSetDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["BundleSetData", + "List", ...BundleDataReader.parseTypeList() //Bundles + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads BundleSetData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + + return {Bundles}; + } + + write(buffer, content, resolver) { + const bundleListReader = new ListReader( new BundleDataReader() ); + + this.writeIndex(buffer, resolver); + + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js b/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js new file mode 100644 index 0000000..f5782be --- /dev/null +++ b/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js @@ -0,0 +1,81 @@ +import {BaseReader, + ListReader, + Int32Reader, + StringReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * ConcessionItemData Reader + * @class + * @extends BaseReader + */ +export default class ConcessionItemDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["ConcessionItemData", + null, //ID + 'String', //name + 'String', //displayName + 'String', //description + null, //price + 'Nullable>', "List", 'String' //itemTag + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads ConcessionItemData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + + this.writeIndex(buffer, resolver); + + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/HomeRenovationReader.js b/src/plugins-stardewvalley/Readers/HomeRenovationReader.js new file mode 100644 index 0000000..eb0e415 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/HomeRenovationReader.js @@ -0,0 +1,93 @@ +import {BaseReader, + BooleanReader, + StringReader, + ListReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers +import RenovationValueReader from "./RenovationValueReader.js"; +import RectGroupReader from "./RectGroupReader.js"; + +/** + * HomeRenovation Reader + * @class + * @extends BaseReader + */ +export default class HomeRenovationReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + default: return false; + } + } + static parseTypeList() { + return ["HomeRenovation", + "String", //textStrings + "String", //animationType + null, // checkForObstructions + "List", ...RenovationValueReader.parseTypeList(), //requirements + "List", ...RenovationValueReader.parseTypeList(), //renovateActions + "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), //rectGroups + "Nullable", "String" //specialRect + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads HomeRenovation from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + + + const TextStrings = resolver.read(buffer); //string + const AnimationType = resolver.read(buffer); //string + + const CheckForObstructions = booleanReader.read(buffer); //boolean + + const Requirements = resolver.read(buffer); //List + const RenovateActions = resolver.read(buffer); //List + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); //List + const SpecialRect = nullableStringReader.read(buffer, resolver); //string + + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + const renovationValueListReader = new ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/MovieDataReader.js b/src/plugins-stardewvalley/Readers/MovieDataReader.js new file mode 100644 index 0000000..a5a448c --- /dev/null +++ b/src/plugins-stardewvalley/Readers/MovieDataReader.js @@ -0,0 +1,83 @@ +import {BaseReader, + ListReader, + Int32Reader, + StringReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers +import MovieSceneReader from "./MovieSceneReader.js"; + +/** + * MovieData Reader + * @class + * @extends BaseReader + */ +export default class MovieDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["MovieData", + "Nullable", 'String', + null, + 'String', + 'String', + "Nullable>", 'List', 'String', + "List", ...MovieSceneReader.parseTypeList()]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads MovieData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const movieSceneListReader = new ListReader(new MovieSceneReader()); + + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/MovieSceneReader.js b/src/plugins-stardewvalley/Readers/MovieSceneReader.js new file mode 100644 index 0000000..cb618ea --- /dev/null +++ b/src/plugins-stardewvalley/Readers/MovieSceneReader.js @@ -0,0 +1,96 @@ +import {BaseReader, + ListReader, + BooleanReader, + Int32Reader, + StringReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * MovieScene Reader + * @class + * @extends BaseReader + */ +export default class MovieSceneReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + default: return false; + } + } + static parseTypeList() { + return ["MovieScene", + null, // image + "Nullable", 'String', // music + "Nullable", 'String', // sound + null, // messageDelay + "Nullable", 'String', // script + "Nullable", 'String', // text + null, // shake + "Nullable", 'String', // responsePoint + 'String' // ID + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads MovieScene from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const stringReader = new StringReader(); + + this.writeIndex(buffer, resolver); + + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js b/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js new file mode 100644 index 0000000..1521615 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js @@ -0,0 +1,74 @@ +import {BaseReader, + StringReader, + NullableReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import BundleSetDataReader from "./BundleSetDataReader.js"; +import BundleDataReader from "./BundleDataReader.js"; + +/** + * RandomBundleData Reader + * @class + * @extends BaseReader + */ +export default class RandomBundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["RandomBundleData", + "String", // AreaName + "String", // Keys + "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(),// BundleSets + "Nullable>:10", "List", ...BundleDataReader.parseTypeList()//Bundles + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads RandomBundleData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableBundleSetListReader = new NullableReader( new ListReader( new BundleSetDataReader() ) ); + const nullableBundleListReader = new NullableReader( new ListReader( new BundleDataReader() ) ); + + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableBundleSetListReader = new NullableReader( new ListReader( new BundleSetDataReader() ) ); + const nullableBundleListReader = new NullableReader( new ListReader( new BundleDataReader() ) ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RectGroupReader.js b/src/plugins-stardewvalley/Readers/RectGroupReader.js new file mode 100644 index 0000000..098c50c --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RectGroupReader.js @@ -0,0 +1,52 @@ +import {BaseReader, + ListReader, +} from "../../readers/src/readers.js"; //@xnb/readers +import RectReader from "./RectReader.js" + +/** + * RectGroup Reader + * @class + * @extends BaseReader + */ +export default class RectGroupReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + default: return false; + } + } + static parseTypeList() { + return ["RectGroup", + "List", "Rect" + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads RectGroup from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const Rects = resolver.read(buffer); //List + + return {Rects}; + } + + write(buffer, content, resolver) { + const rectListReader = new ListReader(new RectReader()); + + this.writeIndex(buffer, resolver); + + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RectReader.js b/src/plugins-stardewvalley/Readers/RectReader.js new file mode 100644 index 0000000..1321ca6 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RectReader.js @@ -0,0 +1,28 @@ +import {RectangleReader} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * Stardew Valley Rect Reader + * @class + * @extends BaseReader + */ +export default class RectReader extends RectangleReader { + static isTypeOf(type) { + if( super.isTypeOf(type) ) return true; + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + default: return false; + } + } + static parseTypeList() { + return ["Rect"]; + } + static type() + { + return "Reflective"; + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RenovationValueReader.js b/src/plugins-stardewvalley/Readers/RenovationValueReader.js new file mode 100644 index 0000000..3520e59 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RenovationValueReader.js @@ -0,0 +1,55 @@ +import {BaseReader, + StringReader, +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * RenovationValue Reader + * @class + * @extends BaseReader + */ +export default class RenovationValueReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + default: return false; + } + } + static parseTypeList() { + return ["RenovationValue", + "String", "String", "String" + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads RenovationValue from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const Type = resolver.read(buffer); //string + const Key = resolver.read(buffer); //string + const Value = resolver.read(buffer); //string + + return {Type,Key,Value}; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js new file mode 100644 index 0000000..69ee3e6 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js @@ -0,0 +1,59 @@ +import {BaseReader, + StringReader, + NullableReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import RandomizedElementReader from "./RandomizedElementReader.js"; +import SpecialOrderObjectiveDataReader from "./SpecialOrderObjectiveDataReader.js"; +import SpecialOrderRewardDataReader from "./SpecialOrderRewardData.js"; + +/** + * SpecialOrderData Reader + * @class + * @extends BaseReader + */ +export default class SpecialOrderDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["SpecialOrderData", + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads SpecialOrderData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + + let AreaName = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + + return { + AreaName, + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.AreaName, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js index e69de29..e7a7d47 100644 --- a/src/plugins-stardewvalley/readers.js +++ b/src/plugins-stardewvalley/readers.js @@ -0,0 +1,27 @@ +// movie scene data:1.4 +import MovieSceneReader from "./Readers/MovieSceneReader.js"; +import MovieDataReader from "./Readers/MovieDataReader.js"; +// concession item data:1.4 +import ConcessionItemDataReader from "./Readers/ConcessionItemDataReader.js"; +// home renovation data:1.5 +import HomeRenovationReader from "./Readers/HomeRenovationReader.js"; +import RenovationValueReader from "./Readers/RenovationValueReader.js"; +import RectGroupReader from "./Readers/RectGroupReader.js"; +import RectReader from "./Readers/RectReader.js"; +// random bundle data:1.5 +import RandomBundleDataReader from "./Readers/RandomBundleDataReader.js"; +import BundleSetDataReader from "./Readers/BundleSetDataReader.js"; +import BundleDataReader from "./Readers/BundleDataReader.js"; + +export { + MovieSceneReader, + MovieDataReader, + ConcessionItemDataReader, + HomeRenovationReader, + RenovationValueReader, + RectGroupReader, + RectReader, + RandomBundleDataReader, + BundleSetDataReader, + BundleDataReader +}; \ No newline at end of file diff --git a/src/readers/readers/ArrayReader.js b/src/readers/readers/ArrayReader.js index 664dc28..5751959 100644 --- a/src/readers/readers/ArrayReader.js +++ b/src/readers/readers/ArrayReader.js @@ -80,4 +80,8 @@ export default class ArrayReader extends BaseReader { get type() { return `Array<${this.reader.type}>`; } + + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } } diff --git a/src/readers/readers/BaseReader.js b/src/readers/readers/BaseReader.js index b9f3012..aa817f8 100644 --- a/src/readers/readers/BaseReader.js +++ b/src/readers/readers/BaseReader.js @@ -10,8 +10,8 @@ export default class BaseReader { static hasSubType() { return false; } - static parseTypeList(subtype=[]) { - return [this.type(), ...subtype]; + static parseTypeList() { + return [this.type()]; } static type() { @@ -76,4 +76,8 @@ export default class BaseReader { toString() { return this.type; } + + parseTypeList() { + return this.constructor.parseTypeList(); + } } \ No newline at end of file diff --git a/src/readers/readers/DictionaryReader.js b/src/readers/readers/DictionaryReader.js index 59008e5..67097b4 100644 --- a/src/readers/readers/DictionaryReader.js +++ b/src/readers/readers/DictionaryReader.js @@ -80,7 +80,7 @@ export default class DictionaryReader extends BaseReader { // write the amount of entries in the Dictionary buffer.writeUInt32(Object.keys(content).length); - + // loop over the entries for (let key of Object.keys(content)) { // write the key @@ -97,4 +97,8 @@ export default class DictionaryReader extends BaseReader { get type() { return `Dictionary<${this.key.type},${this.value.type}>`; } -} + + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } +} \ No newline at end of file diff --git a/src/readers/readers/ListReader.js b/src/readers/readers/ListReader.js index ef355d6..745d82b 100644 --- a/src/readers/readers/ListReader.js +++ b/src/readers/readers/ListReader.js @@ -67,4 +67,8 @@ export default class ListReader extends BaseReader { get type() { return `List<${this.reader.type}>`; } + + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } } diff --git a/src/readers/readers/NullableReader.js b/src/readers/readers/NullableReader.js index 4e2488c..8d4dcec 100644 --- a/src/readers/readers/NullableReader.js +++ b/src/readers/readers/NullableReader.js @@ -53,7 +53,7 @@ export default class NullableReader extends BaseReader { booleanReader.read(buffer); return this.reader.read(buffer); } - return (this.reader.isValueType()) ? resolver.read(buffer) : this.reader.read(buffer); + return (this.reader.isValueType()) ? this.reader.read(buffer) : resolver.read(buffer); } /** @@ -66,7 +66,7 @@ export default class NullableReader extends BaseReader { //this.writeIndex(buffer, resolver); const booleanReader = new BooleanReader(); - if(content !== null) + if(content === null) { buffer.writeByte(0); return; @@ -82,4 +82,9 @@ export default class NullableReader extends BaseReader { get type() { return `Nullable<${this.reader.type}>`; } + + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return [`${this.type}:${inBlock.length}`, ...inBlock]; + } } diff --git a/src/readers/readers/ReflectiveReader.js b/src/readers/readers/ReflectiveReader.js index 9278168..dddd77b 100644 --- a/src/readers/readers/ReflectiveReader.js +++ b/src/readers/readers/ReflectiveReader.js @@ -16,7 +16,6 @@ export default class ReflectiveReader extends BaseReader { static hasSubType() { return true; } - /** * @constructor * @param {BaseReader} reader @@ -47,7 +46,6 @@ export default class ReflectiveReader extends BaseReader { * @param {ReaderResolver} resolver */ write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, (this.reader.isValueType() ? null : resolver)); } @@ -58,4 +56,8 @@ export default class ReflectiveReader extends BaseReader { get type() { return `${this.reader.type}`; } + + parseTypeList() { + return [...this.reader.parseTypeList()]; + } } diff --git a/src/readers/readers/SpriteFontReader.js b/src/readers/readers/SpriteFontReader.js index 9fa6748..97f8774 100644 --- a/src/readers/readers/SpriteFontReader.js +++ b/src/readers/readers/SpriteFontReader.js @@ -89,8 +89,6 @@ export default class SpriteFontReader extends BaseReader { catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { From ce2eef73653e5055d0af840f62596a9fd7496308 Mon Sep 17 00:00:00 2001 From: lybell Date: Mon, 23 May 2022 22:02:07 +0900 Subject: [PATCH 03/11] add some readers(~1.5 all datatype) MovieCharacterReactionReader, ConcessionTasteReader, FishPondDataReader, TailorItemRecipeReader, SpecialOrderDataReader --- .../Readers/CharacterResponseReader.js | 64 ++++++++++++++ .../Readers/ConcessionItemDataReader.js | 2 +- .../Readers/ConcessionTasteReader.js | 70 +++++++++++++++ .../Readers/FishPondDataReader.js | 83 ++++++++++++++++++ .../Readers/FishPondRewardReader.js | 70 +++++++++++++++ .../Readers/MovieCharacterReactionReader.js | 67 +++++++++++++++ .../Readers/MovieReactionReader.js | 78 +++++++++++++++++ .../Readers/RandomBundleDataReader.js | 2 +- .../Readers/RandomizedElementItemReader.js | 58 +++++++++++++ .../Readers/RandomizedElementReader.js | 59 +++++++++++++ .../Readers/SpecialOrderDataReader.js | 76 ++++++++++++++++- .../SpecialOrderObjectiveDataReader.js | 67 +++++++++++++++ .../Readers/SpecialOrderRewardDataReader.js | 61 +++++++++++++ .../Readers/SpecialResponsesReader.js | 64 ++++++++++++++ .../Readers/TailorItemRecipeReader.js | 85 +++++++++++++++++++ src/plugins-stardewvalley/readers.js | 47 +++++++++- 16 files changed, 946 insertions(+), 7 deletions(-) create mode 100644 src/plugins-stardewvalley/Readers/CharacterResponseReader.js create mode 100644 src/plugins-stardewvalley/Readers/ConcessionTasteReader.js create mode 100644 src/plugins-stardewvalley/Readers/FishPondDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/FishPondRewardReader.js create mode 100644 src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js create mode 100644 src/plugins-stardewvalley/Readers/MovieReactionReader.js create mode 100644 src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js create mode 100644 src/plugins-stardewvalley/Readers/RandomizedElementReader.js create mode 100644 src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js create mode 100644 src/plugins-stardewvalley/Readers/SpecialResponsesReader.js create mode 100644 src/plugins-stardewvalley/Readers/TailorItemRecipeReader.js diff --git a/src/plugins-stardewvalley/Readers/CharacterResponseReader.js b/src/plugins-stardewvalley/Readers/CharacterResponseReader.js new file mode 100644 index 0000000..e2fb7b0 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/CharacterResponseReader.js @@ -0,0 +1,64 @@ +import {BaseReader, + NullableReader, + StringReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * CharacterResponse Reader + * @class + * @extends BaseReader + */ +export default class CharacterResponseReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + default: return false; + } + } + static parseTypeList() { + return ["CharacterResponse", + "Nullable:1", "String", // responsePoint + "Nullable:1", "String", // script + "Nullable:1", "String" // text + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads CharacterResponse from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + + this.writeIndex(buffer, resolver); + + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js b/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js index f5782be..ad935c5 100644 --- a/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js +++ b/src/plugins-stardewvalley/Readers/ConcessionItemDataReader.js @@ -25,7 +25,7 @@ export default class ConcessionItemDataReader extends BaseReader { 'String', //displayName 'String', //description null, //price - 'Nullable>', "List", 'String' //itemTag + 'Nullable>:2', "List", 'String' //itemTag ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/ConcessionTasteReader.js b/src/plugins-stardewvalley/Readers/ConcessionTasteReader.js new file mode 100644 index 0000000..6ed19a9 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/ConcessionTasteReader.js @@ -0,0 +1,70 @@ +import {BaseReader, + ListReader, + StringReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * ConcessionTaste Reader + * @class + * @extends BaseReader + */ +export default class ConcessionTasteReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + default: return false; + } + } + static parseTypeList() { + return ["ConcessionTaste", + 'String', //name + 'Nullable>:2', "List", 'String', //lovedTags + 'Nullable>:2', "List", 'String', //likedTags + 'Nullable>:2', "List", 'String', //dislikedTags + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads ConcessionTaste from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/FishPondDataReader.js b/src/plugins-stardewvalley/Readers/FishPondDataReader.js new file mode 100644 index 0000000..8cd5b22 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/FishPondDataReader.js @@ -0,0 +1,83 @@ +import {BaseReader, + ListReader, + Int32Reader, + StringReader, + DictionaryReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers +import FishPondRewardReader from "./FishPondRewardReader.js"; + +/** + * FishPondData Reader + * @class + * @extends BaseReader + */ +export default class FishPondDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.FishPondData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["FishPondData", + "List", "String", // requiredTags + null, // spawnTime + "List", FishPondRewardReader.parseTypeList(), //producedItems + "Nullable>>:4", + "Dictionary>", "Int32", "List", "String" //populationGates + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads FishPondData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const stringListDictReader = new NullableReader( new DictionaryReader( + new Int32Reader(), + new ListReader( new StringReader() ) + ) ); + + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, ) + + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new ListReader( new StringReader() ); + const int32Reader = new Int32Reader(); + const fishPondRewardListReader = new ListReader( new FishPondRewardReader() ); + const stringListDictReader = new NullableReader( new DictionaryReader( + new Int32Reader(), + new ListReader( new StringReader() ) + ) ); + + this.writeIndex(buffer, resolver); + + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, resolver); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/FishPondRewardReader.js b/src/plugins-stardewvalley/Readers/FishPondRewardReader.js new file mode 100644 index 0000000..95d92d8 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/FishPondRewardReader.js @@ -0,0 +1,70 @@ +import {BaseReader, + SingleReader, + Int32Reader, +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * FishPondReward Reader + * @class + * @extends BaseReader + */ +export default class FishPondRewardReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.FishPondReward': + return true; + default: return false; + } + } + static parseTypeList() { + return ["FishPondReward", + null,null,null,null,null + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads FishPondReward from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + + const RequiredPopulation = int32Reader.read(buffer); + const Chance = floatReader.read(buffer); + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + + this.writeIndex(buffer, resolver); + + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js b/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js new file mode 100644 index 0000000..9bd2179 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js @@ -0,0 +1,67 @@ +import {BaseReader, + StringReader, + NullableReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import MovieReactionReader from "./MovieReactionReader.js"; + +/** + * MovieCharacterReaction Reader + * @class + * @extends BaseReader + */ +export default class MovieCharacterReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + default: return false; + } + } + static parseTypeList() { + return ["MovieCharacterReaction", + "String", // NPCName + "Nullable>:34", "List", MovieReactionReader.parseTypeList() //reactions + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads MovieCharacterReaction from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableReactionListReader = new NullableReader( + new ListReader( new MovieReactionReader() ) + ); + + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableReactionListReader = new NullableReader( + new ListReader( new MovieReactionReader() ) + ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/MovieReactionReader.js b/src/plugins-stardewvalley/Readers/MovieReactionReader.js new file mode 100644 index 0000000..175f1c7 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/MovieReactionReader.js @@ -0,0 +1,78 @@ +import {BaseReader, + StringReader, + NullableReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import SpecialResponsesReader from "./SpecialResponseReader.js"; + +/** + * MovieCharacterReaction Reader + * @class + * @extends BaseReader + */ +export default class MovieReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + default: return false; + } + } + static parseTypeList() { + return ["MovieReaction", + "String", // tag + "Nullable:1", "String", // response + "Nullable>:2", "List", "String", // whitelist + "Nullable:25", SpecialResponsesReader.parseTypeList(), // specialResponses + "String" // ID + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads MovieCharacterReaction from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableStringListReader = new NullableReader( new ListReader( new StringReader() ) ); + const nullableSpecialResponsesReader = new NullableReader( new SpecialResponsesReader() ); + + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const WhiteList = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableStringListReader = new NullableReader( new ListReader( new StringReader() ) ); + const nullableSpecialResponsesReader = new NullableReader( new SpecialResponsesReader() ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.WhiteList, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js b/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js index 1521615..47b645d 100644 --- a/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js +++ b/src/plugins-stardewvalley/Readers/RandomBundleDataReader.js @@ -24,7 +24,7 @@ export default class RandomBundleDataReader extends BaseReader { "String", // AreaName "String", // Keys "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(),// BundleSets - "Nullable>:10", "List", ...BundleDataReader.parseTypeList()//Bundles + "Nullable>:11", "List", ...BundleDataReader.parseTypeList()//Bundles ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js b/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js new file mode 100644 index 0000000..72836e0 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js @@ -0,0 +1,58 @@ +import {BaseReader, + StringReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * RandomizedElementItem Reader + * @class + * @extends BaseReader + */ +export default class RandomizedElementItemReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + default: return false; + } + } + static parseTypeList() { + return ["RandomizedElementItem", + "Nullable", "String", // name + "String" // value + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads RandomizedElementItem from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + + return {RequiredTags, Value}; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader( new StringReader() ); + + this.writeIndex(buffer, resolver); + + nullableStringReader.write(buffer, content, resolver); + stringReader.write(buffer, content, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/RandomizedElementReader.js b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js new file mode 100644 index 0000000..7677ec9 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js @@ -0,0 +1,59 @@ +import {BaseReader, + StringReader, + ListReader +} from "../../readers/src/readers.js"; //@xnb/readers +import RandomizedElementItemReader from "./RandomizedElementItemReader.js"; + +/** + * RandomizedElement Reader + * @class + * @extends BaseReader + */ +export default class RandomizedElementReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + default: return false; + } + } + static parseTypeList() { + return ["RandomizedElement", + "String", // name + "List", RandomizedElementItemReader.parseTypeList() // values + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads RandomizedElement from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const itemListReader = new ListReader( new RandomizedElementItemReader() ); + + const Name = resolver.read(buffer); + const Values = itemListReader.read(buffer, resolver); + + return {Name, Values}; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const itemListReader = new ListReader( new RandomizedElementItemReader() ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content, resolver); + itemListReader.write(buffer, content, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js index 69ee3e6..28789e1 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js @@ -22,6 +22,19 @@ export default class SpecialOrderDataReader extends BaseReader { } static parseTypeList() { return ["SpecialOrderData", + "String", // name + "String", // requester + "String", // duration + "Nullable", "String", // repeatable + "Nullable", "String", // requiredTags + "Nullable", "String", // orderType + "Nullable", "String", // specialRule + "String", // text + "Nullable", "String", // orderType + "Nullable", "String", // specialRule + "Nullable>:8", "List", RandomizedElementReader.parseTypeList(), // randomizedElement + "List", SpecialOrderObjectiveDataReader.parseTypeList(), // objectives + "List", SpecialOrderRewardDataReader.parseTypeList() // rewards ]; } static type() @@ -36,21 +49,76 @@ export default class SpecialOrderDataReader extends BaseReader { * @returns {object} */ read(buffer, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableRandomizedElemListReader = new NullableReader( + new ListReader( new RandomizedElementReader() ) + ); + const objectiveListReader = new ListReader( + new SpecialOrderObjectiveDataReader() + ); + const rewardListReader = new ListReader( + new SpecialOrderRewardDataReader() + ); - let AreaName = resolver.read(buffer); - let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = objectiveListReader.read(buffer, resolver); + const Rewards = rewardListReader.read(buffer, resolver); return { - AreaName, + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards }; } write(buffer, content, resolver) { const stringReader = new StringReader(); + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableRandomizedElemListReader = new NullableReader( + new ListReader( new RandomizedElementReader() ) + ); + const objectiveListReader = new ListReader( + new SpecialOrderObjectiveDataReader() + ); + const rewardListReader = new ListReader( + new SpecialOrderRewardDataReader() + ); this.writeIndex(buffer, resolver); - stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver) } isValueType() { diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js new file mode 100644 index 0000000..67d098c --- /dev/null +++ b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js @@ -0,0 +1,67 @@ +import {BaseReader, + StringReader, + DictionaryReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * SpecialOrderObjectiveData Reader + * @class + * @extends BaseReader + */ +export default class SpecialOrderObjectiveDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["SpecialOrderObjectiveData", + "String", // type + "String", // text + "String", // requiredCount + "Dictionary", "String", "String" // data + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads SpecialOrderObjectiveData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js new file mode 100644 index 0000000..679658c --- /dev/null +++ b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js @@ -0,0 +1,61 @@ +import {BaseReader, + StringReader, + DictionaryReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * SpecialOrderRewardData Reader + * @class + * @extends BaseReader + */ +export default class SpecialOrderRewardDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + default: return false; + } + } + static parseTypeList() { + return ["SpecialOrderRewardData", + "String", // type + "Dictionary", "String", "String" // data + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads SpecialOrderRewardData from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js b/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js new file mode 100644 index 0000000..dd24ec3 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js @@ -0,0 +1,64 @@ +import {BaseReader, + NullableReader +} from "../../readers/src/readers.js"; //@xnb/readers +import CharacterResponseReader from "./CharacterResponseReader.js"; + +/** + * SpecialResponses Reader + * @class + * @extends BaseReader + */ +export default class SpecialResponsesReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + default: return false; + } + } + static parseTypeList() { + return ["SpecialResponses", + "Nullable:7", CharacterResponseReader.parseTypeList(), // beforeMovie + "Nullable:7", CharacterResponseReader.parseTypeList(), // duringMovie + "Nullable:7", CharacterResponseReader.parseTypeList() // afterMovie + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads SpecialResponses from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableCharacterResponseReader = new NullableReader( new CharacterResponseReader() ); + + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new NullableReader( new CharacterResponseReader() ); + + this.writeIndex(buffer, resolver); + + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/TailorItemRecipeReader.js b/src/plugins-stardewvalley/Readers/TailorItemRecipeReader.js new file mode 100644 index 0000000..94b1f37 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/TailorItemRecipeReader.js @@ -0,0 +1,85 @@ +import {BaseReader, + NullableReader, + ListReader, + StringReader, + BooleanReader, + Int32Reader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * TailorItemRecipe Reader + * @class + * @extends BaseReader + */ +export default class TailorItemRecipeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + default: return false; + } + } + static parseTypeList() { + return ["TailorItemRecipe", + "Nullable>:2", "List", "String", // firstItemTags + "Nullable>:2", "List", "String", // secondItemTags + null, //spendingRightItem + null, //craftedItemID + "Nullable>:2", "List", "String", // craftedItemIDs + "Nullable", "String" // craftedItemColor + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads TailorItemRecipe from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringListReader = new NullableReader( new ListReader( new StringReader() ) ); + const nullableStringReader = new NullableReader( new StringReader() ); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new NullableReader( new ListReader( new StringReader() ) ); + const nullableStringReader = new NullableReader( new StringReader() ); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + + this.writeIndex(buffer, resolver); + + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js index e7a7d47..61b1224 100644 --- a/src/plugins-stardewvalley/readers.js +++ b/src/plugins-stardewvalley/readers.js @@ -1,27 +1,72 @@ // movie scene data:1.4 import MovieSceneReader from "./Readers/MovieSceneReader.js"; import MovieDataReader from "./Readers/MovieDataReader.js"; + +// movie character reaction data:1.4 +import MovieCharacterReactionReader from "./MovieCharacterReactionReader.js"; +import MovieReactionReader from "./MovieReactionReader.js"; +import SpecialResponsesReader from "./SpecialResponseReader.js"; +import CharacterResponseReader from "./CharacterResponseReader.js"; + // concession item data:1.4 import ConcessionItemDataReader from "./Readers/ConcessionItemDataReader.js"; +// concession taste data:1.4 +import ConcessionTasteReader from "./Readers/ConcessionTasteReader.js"; + +// fish pond data:1.4 +import FishPondDataReader from "./FishPondDataReader.js"; +import FishPondRewardReader from "./FishPondRewardReader.js"; + +// tailor item recipe data:1.4 +import TailorItemRecipeReader from "./Readers/TailorItemRecipeReader.js"; + // home renovation data:1.5 import HomeRenovationReader from "./Readers/HomeRenovationReader.js"; import RenovationValueReader from "./Readers/RenovationValueReader.js"; import RectGroupReader from "./Readers/RectGroupReader.js"; import RectReader from "./Readers/RectReader.js"; + // random bundle data:1.5 import RandomBundleDataReader from "./Readers/RandomBundleDataReader.js"; import BundleSetDataReader from "./Readers/BundleSetDataReader.js"; import BundleDataReader from "./Readers/BundleDataReader.js"; +// special order data:1.5 +import SpecialOrderDataReader from "./SpecialOrderDataReader.js"; +import RandomizedElementReader from "./RandomizedElementReader.js"; +import RandomizedElementItemReader from "./RandomizedElementItemReader.js"; +import SpecialOrderObjectiveDataReader from "./SpecialOrderObjectiveDataReader.js"; +import SpecialOrderRewardDataReader from "./SpecialOrderRewardData.js" + export { MovieSceneReader, MovieDataReader, + + MovieCharacterReactionReader, + MovieReactionReader, + SpecialResponsesReader, + CharacterResponseReader, + ConcessionItemDataReader, + ConcessionTasteReader, + + FishPondDataReader, + FishPondRewardReader, + + TailorItemRecipeReader, + HomeRenovationReader, RenovationValueReader, RectGroupReader, RectReader, + RandomBundleDataReader, BundleSetDataReader, - BundleDataReader + BundleDataReader, + + SpecialOrderDataReader, + RandomizedElementReader, + RandomizedElementItemReader, + SpecialOrderObjectiveDataReader, + SpecialOrderRewardDataReader }; \ No newline at end of file From c584a8f0915f042e6010f9da0fdde285880d401c Mon Sep 17 00:00:00 2001 From: lybell Date: Mon, 23 May 2022 23:33:03 +0900 Subject: [PATCH 04/11] Update readers.js --- src/plugins-stardewvalley/readers.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js index 61b1224..0982137 100644 --- a/src/plugins-stardewvalley/readers.js +++ b/src/plugins-stardewvalley/readers.js @@ -3,10 +3,10 @@ import MovieSceneReader from "./Readers/MovieSceneReader.js"; import MovieDataReader from "./Readers/MovieDataReader.js"; // movie character reaction data:1.4 -import MovieCharacterReactionReader from "./MovieCharacterReactionReader.js"; -import MovieReactionReader from "./MovieReactionReader.js"; -import SpecialResponsesReader from "./SpecialResponseReader.js"; -import CharacterResponseReader from "./CharacterResponseReader.js"; +import MovieCharacterReactionReader from "./Readers/MovieCharacterReactionReader.js"; +import MovieReactionReader from "./Readers/MovieReactionReader.js"; +import SpecialResponsesReader from "./Readers/SpecialResponseReader.js"; +import CharacterResponseReader from "./Readers/CharacterResponseReader.js"; // concession item data:1.4 import ConcessionItemDataReader from "./Readers/ConcessionItemDataReader.js"; @@ -14,8 +14,8 @@ import ConcessionItemDataReader from "./Readers/ConcessionItemDataReader.js"; import ConcessionTasteReader from "./Readers/ConcessionTasteReader.js"; // fish pond data:1.4 -import FishPondDataReader from "./FishPondDataReader.js"; -import FishPondRewardReader from "./FishPondRewardReader.js"; +import FishPondDataReader from "./Readers/FishPondDataReader.js"; +import FishPondRewardReader from "./Readers/FishPondRewardReader.js"; // tailor item recipe data:1.4 import TailorItemRecipeReader from "./Readers/TailorItemRecipeReader.js"; @@ -32,11 +32,11 @@ import BundleSetDataReader from "./Readers/BundleSetDataReader.js"; import BundleDataReader from "./Readers/BundleDataReader.js"; // special order data:1.5 -import SpecialOrderDataReader from "./SpecialOrderDataReader.js"; -import RandomizedElementReader from "./RandomizedElementReader.js"; -import RandomizedElementItemReader from "./RandomizedElementItemReader.js"; -import SpecialOrderObjectiveDataReader from "./SpecialOrderObjectiveDataReader.js"; -import SpecialOrderRewardDataReader from "./SpecialOrderRewardData.js" +import SpecialOrderDataReader from "./Readers/SpecialOrderDataReader.js"; +import RandomizedElementReader from "./Readers/RandomizedElementReader.js"; +import RandomizedElementItemReader from "./Readers/RandomizedElementItemReader.js"; +import SpecialOrderObjectiveDataReader from "./Readers/SpecialOrderObjectiveDataReader.js"; +import SpecialOrderRewardDataReader from "./Readers/SpecialOrderRewardData.js" export { MovieSceneReader, From 41f4885e5f637e0e118fffa1a900fa396f44dd14 Mon Sep 17 00:00:00 2001 From: lybell Date: Tue, 24 May 2022 01:06:54 +0900 Subject: [PATCH 05/11] TypeReader nested exception bugfix --- src/core/App/ReaderResolver.js | 96 ++++++++++--------- src/core/App/Readers/TypeReader.js | 37 ++++--- src/core/Utils/Debug.js | 2 +- src/core/Utils/xnbNodeConverter.js | 8 ++ .../Readers/FishPondDataReader.js | 12 +-- .../Readers/FishPondRewardReader.js | 4 +- .../Readers/MovieCharacterReactionReader.js | 2 +- .../Readers/MovieReactionReader.js | 14 +-- .../Readers/RandomizedElementReader.js | 2 +- .../Readers/SpecialOrderDataReader.js | 8 +- .../SpecialOrderObjectiveDataReader.js | 2 +- .../Readers/SpecialOrderRewardDataReader.js | 2 +- .../Readers/SpecialResponsesReader.js | 6 +- src/plugins-stardewvalley/readers.js | 4 +- 14 files changed, 112 insertions(+), 87 deletions(-) diff --git a/src/core/App/ReaderResolver.js b/src/core/App/ReaderResolver.js index 844e059..e62e21f 100644 --- a/src/core/App/ReaderResolver.js +++ b/src/core/App/ReaderResolver.js @@ -7,56 +7,58 @@ import Debug from "../Utils/Debug.js"; * @class */ class ReaderResolver { - /** - * Creating a new instance of ReaderResolver - * @constructor - * @param {BaseReader[]} readers Array of BaseReaders - */ - constructor(readers) { - /** - * Array of base readers - * @type {BaseReader[]} - */ - this.readers = readers; - } + /** + * Creating a new instance of ReaderResolver + * @constructor + * @param {BaseReader[]} readers Array of BaseReaders + */ + constructor(readers) { + /** + * Array of base readers + * @type {BaseReader[]} + */ + this.readers = readers; + } - /** - * Read the XNB file contents - * @method read - * @public - * @param {BufferReader} buffer The buffer to read from. - */ - read(buffer) { - Debug(`Buffer Position : 0x${buffer.bytePosition.toString(16)}`); - // read the index of which reader to use - let index = buffer.read7BitNumber() - 1; - Debug(`Reader Index : ${index+1}`); - - if (this.readers[index] == null) - throw new XnbError(`Invalid reader index ${index}`); - // read the buffer using the selected reader - return this.readers[index].read(buffer, this); - } + /** + * Read the XNB file contents + * @method read + * @public + * @param {BufferReader} buffer The buffer to read from. + */ + read(buffer) { + Debug(`Buffer Position : 0x${buffer.bytePosition.toString(16)}`); + // read the index of which reader to use + let index = buffer.read7BitNumber() - 1; + Debug(`Reader Index : ${index+1}`); + + if (this.readers[index] == null) + throw new XnbError(`Invalid reader index ${index}`); + // read the buffer using the selected reader + return this.readers[index].read(buffer, this); + } - /** - * Writes the XNB file contents - * @param {BufferWriter} buffer - * @param {Object} content - */ - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } + /** + * Writes the XNB file contents + * @param {BufferWriter} buffer + * @param {Object} content + */ + write(buffer, content) { + this.readers[0].write(buffer, content, this); + } - /** - * Returns the index of the reader - * @param {BaseReader} reader - * @param {Number} - */ - getIndex(reader) { - for (let i in this.readers) - if (reader.toString() == this.readers[i].toString()) - return i; - } + /** + * Returns the index of the reader + * @param {BaseReader} reader + * @param {Number} + */ + getIndex(reader) { + for (let i=0, len=this.readers.length; i { - return e.slice(1, -1); - }); + subtype = removeExternBracket(subtype)[0]; + + let matches = removeExternBracket(subtype); // return the matches return matches; diff --git a/src/core/Utils/Debug.js b/src/core/Utils/Debug.js index 4093f29..9f211df 100644 --- a/src/core/Utils/Debug.js +++ b/src/core/Utils/Debug.js @@ -3,7 +3,7 @@ function Debug(str, ...args) if(Debug.__isVisible) console.log(str, ...args); } -Debug.__isVisible=false; +Debug.__isVisible=true; Debug.setVisible=function(state) { Debug.__isVisible=state; diff --git a/src/core/Utils/xnbNodeConverter.js b/src/core/Utils/xnbNodeConverter.js index 7b53c0d..6451a72 100644 --- a/src/core/Utils/xnbNodeConverter.js +++ b/src/core/Utils/xnbNodeConverter.js @@ -70,6 +70,7 @@ function convertJsonContentsToXnbNode(raw, readers) const {converted} = (function recursiveConvert(obj, path, index=0) { const reader = readers[index]; + console.log(`index : ${index}, reader: ${reader}, obj: ${JSON.stringify(obj)}`); //primitive if(isPrimitiveReaderType(reader)) @@ -101,6 +102,11 @@ function convertJsonContentsToXnbNode(raw, readers) nullableData = null; trav = index + blockTraversed; } + else if(typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) + { + nullableData = {type:readers[index+1], data:deepCopy(obj)}; + trav = index + blockTraversed; + } else { let {converted, traversed} = recursiveConvert( obj, [...path], index+1 ); @@ -265,6 +271,8 @@ function toXnbNodeData(json) delete rawContent.verticalLineSpacing; } + console.log(readersTypeList); + const { converted, extractedImages, extractedMaps } = convertJsonContentsToXnbNode(rawContent, readersTypeList); toYamlJson.content = converted; diff --git a/src/plugins-stardewvalley/Readers/FishPondDataReader.js b/src/plugins-stardewvalley/Readers/FishPondDataReader.js index 8cd5b22..bf4123e 100644 --- a/src/plugins-stardewvalley/Readers/FishPondDataReader.js +++ b/src/plugins-stardewvalley/Readers/FishPondDataReader.js @@ -15,7 +15,7 @@ import FishPondRewardReader from "./FishPondRewardReader.js"; export default class FishPondDataReader extends BaseReader { static isTypeOf(type) { switch (type) { - case 'StardewValley.GameData.Movies.FishPondData': + case 'StardewValley.GameData.FishPond.FishPondData': return true; default: return false; } @@ -24,9 +24,9 @@ export default class FishPondDataReader extends BaseReader { return ["FishPondData", "List", "String", // requiredTags null, // spawnTime - "List", FishPondRewardReader.parseTypeList(), //producedItems - "Nullable>>:4", - "Dictionary>", "Int32", "List", "String" //populationGates + "List", ...FishPondRewardReader.parseTypeList(), //producedItems + "Nullable>>:4", + "Dictionary>", "Int32", "List", "String" //populationGates ]; } static type() @@ -50,7 +50,7 @@ export default class FishPondDataReader extends BaseReader { const RequiredTags = resolver.read(buffer); const SpawnTime = int32Reader.read(buffer); const ProducedItems = resolver.read(buffer); - const PopulationGates = stringListDictReader.read(buffer, ) + const PopulationGates = stringListDictReader.read(buffer, resolver); return { RequiredTags, @@ -72,7 +72,7 @@ export default class FishPondDataReader extends BaseReader { this.writeIndex(buffer, resolver); stringListReader.write(buffer, content.RequiredTags, resolver); - int32Reader.write(buffer, content.SpawnTime, resolver); + int32Reader.write(buffer, content.SpawnTime, null); fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); stringListDictReader.write(buffer, content.PopulationGates, resolver); } diff --git a/src/plugins-stardewvalley/Readers/FishPondRewardReader.js b/src/plugins-stardewvalley/Readers/FishPondRewardReader.js index 95d92d8..c82ea56 100644 --- a/src/plugins-stardewvalley/Readers/FishPondRewardReader.js +++ b/src/plugins-stardewvalley/Readers/FishPondRewardReader.js @@ -11,7 +11,7 @@ import {BaseReader, export default class FishPondRewardReader extends BaseReader { static isTypeOf(type) { switch (type) { - case 'StardewValley.GameData.Movies.FishPondReward': + case 'StardewValley.GameData.FishPond.FishPondReward': return true; default: return false; } @@ -37,7 +37,7 @@ export default class FishPondRewardReader extends BaseReader { const floatReader = new SingleReader(); const RequiredPopulation = int32Reader.read(buffer); - const Chance = floatReader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; const ItemId = int32Reader.read(buffer); const MinQuantity = int32Reader.read(buffer); const MaxQuantity = int32Reader.read(buffer); diff --git a/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js b/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js index 9bd2179..765ab25 100644 --- a/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js +++ b/src/plugins-stardewvalley/Readers/MovieCharacterReactionReader.js @@ -21,7 +21,7 @@ export default class MovieCharacterReactionReader extends BaseReader { static parseTypeList() { return ["MovieCharacterReaction", "String", // NPCName - "Nullable>:34", "List", MovieReactionReader.parseTypeList() //reactions + "Nullable>:34", "List", ...MovieReactionReader.parseTypeList() //reactions ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/MovieReactionReader.js b/src/plugins-stardewvalley/Readers/MovieReactionReader.js index 175f1c7..d701419 100644 --- a/src/plugins-stardewvalley/Readers/MovieReactionReader.js +++ b/src/plugins-stardewvalley/Readers/MovieReactionReader.js @@ -3,10 +3,10 @@ import {BaseReader, NullableReader, ListReader } from "../../readers/src/readers.js"; //@xnb/readers -import SpecialResponsesReader from "./SpecialResponseReader.js"; +import SpecialResponsesReader from "./SpecialResponsesReader.js"; /** - * MovieCharacterReaction Reader + * MovieReaction Reader * @class * @extends BaseReader */ @@ -23,17 +23,17 @@ export default class MovieReactionReader extends BaseReader { "String", // tag "Nullable:1", "String", // response "Nullable>:2", "List", "String", // whitelist - "Nullable:25", SpecialResponsesReader.parseTypeList(), // specialResponses + "Nullable:25", ...SpecialResponsesReader.parseTypeList(), // specialResponses "String" // ID ]; } static type() { - return "Reflective"; + return "Reflective"; } /** - * Reads MovieCharacterReaction from buffer. + * Reads MovieReaction from buffer. * @param {BufferReader} buffer * @param {ReaderResolver} resolver * @returns {object} @@ -45,7 +45,7 @@ export default class MovieReactionReader extends BaseReader { const Tag = resolver.read(buffer); const Response = nullableStringReader.read(buffer, resolver) || "like"; - const WhiteList = nullableStringListReader.read(buffer, resolver) || []; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); const ID = resolver.read(buffer); @@ -67,7 +67,7 @@ export default class MovieReactionReader extends BaseReader { stringReader.write(buffer, content.Tag, resolver); nullableStringReader.write(buffer, content.Response, resolver); - nullableStringListReader.write(buffer, content.WhiteList, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); stringReader.write(buffer, content.ID, resolver); } diff --git a/src/plugins-stardewvalley/Readers/RandomizedElementReader.js b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js index 7677ec9..ed65620 100644 --- a/src/plugins-stardewvalley/Readers/RandomizedElementReader.js +++ b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js @@ -20,7 +20,7 @@ export default class RandomizedElementReader extends BaseReader { static parseTypeList() { return ["RandomizedElement", "String", // name - "List", RandomizedElementItemReader.parseTypeList() // values + "List", ...RandomizedElementItemReader.parseTypeList() // values ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js index 28789e1..ca524c1 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js @@ -5,7 +5,7 @@ import {BaseReader, } from "../../readers/src/readers.js"; //@xnb/readers import RandomizedElementReader from "./RandomizedElementReader.js"; import SpecialOrderObjectiveDataReader from "./SpecialOrderObjectiveDataReader.js"; -import SpecialOrderRewardDataReader from "./SpecialOrderRewardData.js"; +import SpecialOrderRewardDataReader from "./SpecialOrderRewardDataReader.js"; /** * SpecialOrderData Reader @@ -32,9 +32,9 @@ export default class SpecialOrderDataReader extends BaseReader { "String", // text "Nullable", "String", // orderType "Nullable", "String", // specialRule - "Nullable>:8", "List", RandomizedElementReader.parseTypeList(), // randomizedElement - "List", SpecialOrderObjectiveDataReader.parseTypeList(), // objectives - "List", SpecialOrderRewardDataReader.parseTypeList() // rewards + "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), // randomizedElement + "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), // objectives + "List", ...SpecialOrderRewardDataReader.parseTypeList() // rewards ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js index 67d098c..eb3bc32 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js @@ -21,7 +21,7 @@ export default class SpecialOrderObjectiveDataReader extends BaseReader { "String", // type "String", // text "String", // requiredCount - "Dictionary", "String", "String" // data + "Dictionary", "String", "String" // data ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js index 679658c..68c4de5 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js @@ -19,7 +19,7 @@ export default class SpecialOrderRewardDataReader extends BaseReader { static parseTypeList() { return ["SpecialOrderRewardData", "String", // type - "Dictionary", "String", "String" // data + "Dictionary", "String", "String" // data ]; } static type() diff --git a/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js b/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js index dd24ec3..7f205ec 100644 --- a/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialResponsesReader.js @@ -18,9 +18,9 @@ export default class SpecialResponsesReader extends BaseReader { } static parseTypeList() { return ["SpecialResponses", - "Nullable:7", CharacterResponseReader.parseTypeList(), // beforeMovie - "Nullable:7", CharacterResponseReader.parseTypeList(), // duringMovie - "Nullable:7", CharacterResponseReader.parseTypeList() // afterMovie + "Nullable:7", ...CharacterResponseReader.parseTypeList(), // beforeMovie + "Nullable:7", ...CharacterResponseReader.parseTypeList(), // duringMovie + "Nullable:7", ...CharacterResponseReader.parseTypeList() // afterMovie ]; } static type() diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js index 0982137..5e0d0bc 100644 --- a/src/plugins-stardewvalley/readers.js +++ b/src/plugins-stardewvalley/readers.js @@ -5,7 +5,7 @@ import MovieDataReader from "./Readers/MovieDataReader.js"; // movie character reaction data:1.4 import MovieCharacterReactionReader from "./Readers/MovieCharacterReactionReader.js"; import MovieReactionReader from "./Readers/MovieReactionReader.js"; -import SpecialResponsesReader from "./Readers/SpecialResponseReader.js"; +import SpecialResponsesReader from "./Readers/SpecialResponsesReader.js"; import CharacterResponseReader from "./Readers/CharacterResponseReader.js"; // concession item data:1.4 @@ -36,7 +36,7 @@ import SpecialOrderDataReader from "./Readers/SpecialOrderDataReader.js"; import RandomizedElementReader from "./Readers/RandomizedElementReader.js"; import RandomizedElementItemReader from "./Readers/RandomizedElementItemReader.js"; import SpecialOrderObjectiveDataReader from "./Readers/SpecialOrderObjectiveDataReader.js"; -import SpecialOrderRewardDataReader from "./Readers/SpecialOrderRewardData.js" +import SpecialOrderRewardDataReader from "./Readers/SpecialOrderRewardDataReader.js" export { MovieSceneReader, From 5cceb0a57a6ec2efaebcb70260e9ae7ed6395c8c Mon Sep 17 00:00:00 2001 From: lybell Date: Tue, 24 May 2022 15:35:21 +0900 Subject: [PATCH 06/11] movie reaction, special order reader bugfix --- .../Readers/MovieReactionReader.js | 1 + .../Readers/RandomizedElementItemReader.js | 4 ++-- .../Readers/RandomizedElementReader.js | 8 +++----- .../Readers/SpecialOrderDataReader.js | 10 ++-------- .../Readers/SpecialOrderObjectiveDataReader.js | 4 +++- .../Readers/SpecialOrderRewardDataReader.js | 4 +--- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/plugins-stardewvalley/Readers/MovieReactionReader.js b/src/plugins-stardewvalley/Readers/MovieReactionReader.js index d701419..fce863a 100644 --- a/src/plugins-stardewvalley/Readers/MovieReactionReader.js +++ b/src/plugins-stardewvalley/Readers/MovieReactionReader.js @@ -59,6 +59,7 @@ export default class MovieReactionReader extends BaseReader { } write(buffer, content, resolver) { + const stringReader = new StringReader(); const nullableStringReader = new NullableReader( new StringReader() ); const nullableStringListReader = new NullableReader( new ListReader( new StringReader() ) ); const nullableSpecialResponsesReader = new NullableReader( new SpecialResponsesReader() ); diff --git a/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js b/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js index 72836e0..830bf13 100644 --- a/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js +++ b/src/plugins-stardewvalley/Readers/RandomizedElementItemReader.js @@ -48,8 +48,8 @@ export default class RandomizedElementItemReader extends BaseReader { this.writeIndex(buffer, resolver); - nullableStringReader.write(buffer, content, resolver); - stringReader.write(buffer, content, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); } isValueType() { diff --git a/src/plugins-stardewvalley/Readers/RandomizedElementReader.js b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js index ed65620..21dfe56 100644 --- a/src/plugins-stardewvalley/Readers/RandomizedElementReader.js +++ b/src/plugins-stardewvalley/Readers/RandomizedElementReader.js @@ -35,10 +35,8 @@ export default class RandomizedElementReader extends BaseReader { * @returns {object} */ read(buffer, resolver) { - const itemListReader = new ListReader( new RandomizedElementItemReader() ); - const Name = resolver.read(buffer); - const Values = itemListReader.read(buffer, resolver); + const Values = resolver.read(buffer); return {Name, Values}; } @@ -49,8 +47,8 @@ export default class RandomizedElementReader extends BaseReader { this.writeIndex(buffer, resolver); - stringReader.write(buffer, content, resolver); - itemListReader.write(buffer, content, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); } isValueType() { diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js index ca524c1..1aa6739 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderDataReader.js @@ -53,12 +53,6 @@ export default class SpecialOrderDataReader extends BaseReader { const nullableRandomizedElemListReader = new NullableReader( new ListReader( new RandomizedElementReader() ) ); - const objectiveListReader = new ListReader( - new SpecialOrderObjectiveDataReader() - ); - const rewardListReader = new ListReader( - new SpecialOrderRewardDataReader() - ); const Name = resolver.read(buffer); const Requester = resolver.read(buffer); @@ -71,8 +65,8 @@ export default class SpecialOrderDataReader extends BaseReader { const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); - const Objectives = objectiveListReader.read(buffer, resolver); - const Rewards = rewardListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); return { Name, diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js index eb3bc32..2546997 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js @@ -50,6 +50,8 @@ export default class SpecialOrderObjectiveDataReader extends BaseReader { } write(buffer, content, resolver) { + console.log(content); + const stringReader = new StringReader(); const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); @@ -58,7 +60,7 @@ export default class SpecialOrderObjectiveDataReader extends BaseReader { stringReader.write(buffer, content.Type, resolver); stringReader.write(buffer, content.Text, resolver); stringReader.write(buffer, content.RequiredCount, resolver); - stringReader.write(buffer, content.Data, resolver); + stringDictReader.write(buffer, content.Data, resolver); } isValueType() { diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js index 68c4de5..f492c9b 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderRewardDataReader.js @@ -39,8 +39,6 @@ export default class SpecialOrderRewardDataReader extends BaseReader { return { Type, - Text, - RequiredCount, Data }; } @@ -52,7 +50,7 @@ export default class SpecialOrderRewardDataReader extends BaseReader { this.writeIndex(buffer, resolver); stringReader.write(buffer, content.Type, resolver); - stringReader.write(buffer, content.Data, resolver); + stringDictReader.write(buffer, content.Data, resolver); } isValueType() { From 5048931788329dcc90d546e71a497496dfc8c73f Mon Sep 17 00:00:00 2001 From: lybell Date: Tue, 24 May 2022 23:29:12 +0900 Subject: [PATCH 07/11] build --- builder/builder-plugins.js | 156 ++ builder/plugins-rollup.config.js | 165 ++ builder/rollup.config.js | 109 +- dist/core/core.es5.min.js | 1 - dist/core/core.min.js | 41 - dist/core/{core.cjs => xnb-core.cjs} | 87 +- dist/core/{core.es5.js => xnb-core.es5.js} | 106 +- dist/core/xnb-core.es5.min.js | 48 + dist/core/{core.js => xnb-core.js} | 87 +- dist/core/xnb-core.min.js | 48 + .../{core.module.js => xnb-core.module.js} | 87 +- dist/plugins/stardewvalley/index.es5.min.js | 9 + dist/plugins/stardewvalley/index.min.js | 9 + dist/plugins/stardewvalley/index.module.js | 1366 ++++++++++++++++ dist/readers/readers.es5.min.js | 23 - dist/readers/readers.min.js | 24 - dist/readers/{readers.cjs => xnb-readers.cjs} | 78 +- .../{readers.es5.js => xnb-readers.es5.js} | 106 +- dist/readers/xnb-readers.es5.min.js | 31 + dist/readers/{readers.js => xnb-readers.js} | 78 +- dist/readers/xnb-readers.min.js | 31 + ...eaders.module.js => xnb-readers.module.js} | 78 +- dist/xnb.cjs | 120 +- dist/xnb.es5.js | 166 +- dist/xnb.es5.min.js | 93 +- dist/xnb.js | 120 +- dist/xnb.min.js | 134 +- dist/xnb.module.js | 120 +- package.json | 10 +- src/core/App/ReaderResolver.js | 3 - src/core/Utils/Debug.js | 2 +- src/core/Utils/xnbNodeConverter.js | 3 - src/core/dist/core.cjs | 85 +- src/core/dist/core.es5.js | 104 +- src/core/dist/core.es5.min.js | 49 +- src/core/dist/core.js | 85 +- src/core/dist/core.min.js | 89 +- src/core/dist/core.module.js | 85 +- src/core/libs/jsonToYaml.js | 1 + .../Readers/ModFarmTypeReader.js | 84 + .../Readers/ModLanguageReader.js | 115 ++ .../Readers/ModWallpaperOrFlooringReader.js | 72 + .../SpecialOrderObjectiveDataReader.js | 2 - src/plugins-stardewvalley/dist/index.cjs | 1395 ++++++++++++++++ src/plugins-stardewvalley/dist/index.js | 1399 +++++++++++++++++ src/plugins-stardewvalley/dist/index.min.js | 9 + .../dist/index.module.js | 1366 ++++++++++++++++ src/plugins-stardewvalley/readers.js | 13 +- src/readers/dist/readers.cjs | 44 +- src/readers/dist/readers.es5.js | 71 +- src/readers/dist/readers.es5.min.js | 54 +- src/readers/dist/readers.js | 44 +- src/readers/dist/readers.min.js | 55 +- src/readers/dist/readers.module.js | 44 +- 54 files changed, 8065 insertions(+), 739 deletions(-) create mode 100644 builder/builder-plugins.js create mode 100644 builder/plugins-rollup.config.js delete mode 100644 dist/core/core.es5.min.js delete mode 100644 dist/core/core.min.js rename dist/core/{core.cjs => xnb-core.cjs} (98%) rename dist/core/{core.es5.js => xnb-core.es5.js} (99%) create mode 100644 dist/core/xnb-core.es5.min.js rename dist/core/{core.js => xnb-core.js} (98%) create mode 100644 dist/core/xnb-core.min.js rename dist/core/{core.module.js => xnb-core.module.js} (98%) create mode 100644 dist/plugins/stardewvalley/index.es5.min.js create mode 100644 dist/plugins/stardewvalley/index.min.js create mode 100644 dist/plugins/stardewvalley/index.module.js delete mode 100644 dist/readers/readers.es5.min.js delete mode 100644 dist/readers/readers.min.js rename dist/readers/{readers.cjs => xnb-readers.cjs} (98%) rename dist/readers/{readers.es5.js => xnb-readers.es5.js} (97%) create mode 100644 dist/readers/xnb-readers.es5.min.js rename dist/readers/{readers.js => xnb-readers.js} (98%) create mode 100644 dist/readers/xnb-readers.min.js rename dist/readers/{readers.module.js => xnb-readers.module.js} (98%) create mode 100644 src/plugins-stardewvalley/Readers/ModFarmTypeReader.js create mode 100644 src/plugins-stardewvalley/Readers/ModLanguageReader.js create mode 100644 src/plugins-stardewvalley/Readers/ModWallpaperOrFlooringReader.js create mode 100644 src/plugins-stardewvalley/dist/index.cjs create mode 100644 src/plugins-stardewvalley/dist/index.js create mode 100644 src/plugins-stardewvalley/dist/index.min.js create mode 100644 src/plugins-stardewvalley/dist/index.module.js diff --git a/builder/builder-plugins.js b/builder/builder-plugins.js new file mode 100644 index 0000000..6c14048 --- /dev/null +++ b/builder/builder-plugins.js @@ -0,0 +1,156 @@ +import babel from '@rollup/plugin-babel'; +import polyfill from './polyfills/makePolyfill.js'; +import babelrc from './.babelrc.json'; +import es5babelrc from './.babelrc.es5.json'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import {terser} from "rollup-plugin-terser"; + +function removeDebug() { + return { + resolveId(importee) { + return importee.includes("Debug.js") ? "__empty__" : null; + }, + load(id) { + return (id === "__empty__") ? "export default {};" : null; + }, + transform(code, filename) { + code = code.replace(/\/\/ read the target platform\s+switch[\s\S]+found\.`\);\s+break;\s+}/mg, ""); + code = code.replace(/\/\/ read the XNB format version\s+switch[\s\S]+unknown\.`\);\s+break;\s+}/mg, ""); + code = code.replace(/Debug\(.+[\)];\n{0,1}/g, ""); + code = code.replace("import Debug from .*\n$", ""); + return { + code: code, + map: null + }; + } + } +} + +function babelCleanup() { + const doubleSpaces = / {2}/g; + return { + transform( code ) { + code = code.replace( doubleSpaces, '\t' ); + return { + code: code, + map: null + }; + } + }; +} + +function makePlugins(production=false, es5=false) +{ + const shouldPrintComment = (val)=>{ + const regexp = new RegExp(`^\\* @(api|license)(?!\\S)`); + return production ? false : regexp.test(val); + } + + const commonPlugins = [ + removeDebug(), + polyfill( { version: (es5 ? "es5" : "es2017") } ), + babel({ + babelHelpers:'bundled', + babelrc: false, + exclude:'node_modules/**', + ...(es5 ? es5babelrc : babelrc), + shouldPrintComment + }), + babelCleanup() + ]; + + const es5Plugins = [ + nodeResolve(), + commonjs() + ]; + const prodPlugins = [ + terser() + ]; + + return [ + ...(es5 ? es5Plugins : []), + ...commonPlugins, + ...(production ? prodPlugins : []) + ] +} + +function makeBanners(production=false, includes={}) +{ +const licensesDict={ +LZ4: ` * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/`, +LZX: ` * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * -----------------------------------------------------------------------------`, +DXT: ` * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * --------------------------------------------------------------------------` +} +let licensesComments = []; +for(let key of Object.keys(licensesDict)) +{ + if(includes[key] === true) licensesComments.push(licensesDict[key]); +} +return `/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * ${production ? "\n"+licensesComments.join("\n *\n") : ""} +*/ +`; +} + +export { makePlugins, makeBanners }; \ No newline at end of file diff --git a/builder/plugins-rollup.config.js b/builder/plugins-rollup.config.js new file mode 100644 index 0000000..0f54884 --- /dev/null +++ b/builder/plugins-rollup.config.js @@ -0,0 +1,165 @@ +import {makePlugins, makeBanners} from "./builder-plugins.js"; + +function header() +{ + return { + renderChunk(code){ + return `/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +${code}`; + } + }; +} + +function replaceDependency() +{ + return { + transform(code) { + code = code.replace('from "../../readers/src/readers.js"; //@xnb/readers', 'from "@xnb/readers";'); + return { + code: code, + map: null + }; + } + } +} + +function rejoinDependency() +{ + return { + renderChunk(code) { + code = code.replace('@xnb/readers', '../../readers/xnb-readers.module.js'); + return code; + } + } +} + + +function buildMaker(srcBase, srcName, distNode, distWeb) +{ + return [ + // for es2017+ module + { + input: `${srcBase}/${srcName}.js`, + output: [{ + file: `${distNode}.module.js`, + format: 'esm' + }, + { + file: `${distNode}.cjs`, + name: "XNB", + format: 'cjs' + }, + { + file: `${distNode}.js`, + name: "XNB", + format: 'umd', + globals: { + "@xnb/readers": 'XNB' + } + }], + external: ['@xnb/readers'], + plugins: [ + replaceDependency(), + ...makePlugins(false, false), + header() + ], + treeshake: false + }, + { + input: `${srcBase}/${srcName}.js`, + output: { + file: `${distNode}.min.js`, + name: "XNB", + format: 'umd', + globals: { + "@xnb/readers": 'XNB' + } + }, + external: ['@xnb/readers'], + plugins: [ + replaceDependency(), + ...makePlugins(true, false), + header() + ], + treeshake: false + }, + + // dist web + { + input: `${srcBase}/${srcName}.js`, + output: [{ + file: `${distWeb}.module.js`, + format: 'esm' + }], + external: ['@xnb/readers'], + plugins: [ + replaceDependency(), + ...makePlugins(false, false), + rejoinDependency(), + header() + ], + treeshake: false + }, + { + input: `${srcBase}/${srcName}.js`, + output: { + file: `${distWeb}.min.js`, + name: "XNB", + format: 'umd', + globals: { + "@xnb/readers": 'XNB' + } + }, + external: ['@xnb/readers'], + plugins: [ + replaceDependency(), + ...makePlugins(true, false), + header() + ], + treeshake: false + }, + { + input: `${srcBase}/${srcName}.js`, + output: { + file: `${distWeb}.es5.min.js`, + name: "XNB", + format: 'umd', + globals: { + "@xnb/readers": 'XNB' + } + }, + external: ['@xnb/readers'], + plugins: [ + replaceDependency(), + ...makePlugins(true, true), + header() + ], + treeshake: false + }, + + ]; +} + +function buildTargetMaker(target=-1) +{ + const targetArray = [ + ["src/plugins-stardewvalley", + "readers", + "src/plugins-stardewvalley/dist/index", + "dist/plugins/stardewvalley/index"] + ] + + if(target >= 0 ) return buildMaker(...targetArray[target]); + return targetArray.map((paths)=>buildMaker(...paths)).flat(); +} + +const builds = buildTargetMaker(process.env.BUILD_MODULE); + +export default builds; \ No newline at end of file diff --git a/builder/rollup.config.js b/builder/rollup.config.js index 1cf73ff..020a80e 100644 --- a/builder/rollup.config.js +++ b/builder/rollup.config.js @@ -1,76 +1,39 @@ -import babel from '@rollup/plugin-babel'; -import polyfill from './polyfills/makePolyfill.js'; -import babelrc from './.babelrc.json'; -import es5babelrc from './.babelrc.es5.json'; -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import commonjs from '@rollup/plugin-commonjs'; -import {terser} from "rollup-plugin-terser"; +import {makePlugins, makeBanners} from "./builder-plugins.js"; -function removeDebug() { - return { - resolveId(importee) { - return importee.includes("Debug.js") ? "__empty__" : null; - }, - load(id) { - return (id === "__empty__") ? "export default {};" : null; - }, - transform(code, filename) { - code = code.replace(/\/\/ read the target platform\s+switch[\s\S]+found\.`\);\s+break;\s+}/mg, ""); - code = code.replace(/\/\/ read the XNB format version\s+switch[\s\S]+unknown\.`\);\s+break;\s+}/mg, ""); - code = code.replace(/Debug\(.+[\)];\n{0,1}/g, ""); - code = code.replace("import Debug from .*\n$", ""); - return { - code: code, - map: null - }; - } - } -} - -function babelCleanup() { - const doubleSpaces = / {2}/g; +function header(licenseMap) +{ return { - transform( code ) { - code = code.replace( doubleSpaces, '\t' ); - return { - code: code, - map: null - }; + renderChunk(code){ + return `${makeBanners(true, licenseMap)} +${code}`; } }; } -function buildMaker(srcBase, srcName, dist) +function buildMaker(srcBase, srcName, dist, licenseMap) { return [ // for es2017+ module { input: `${srcBase}/${srcName}.js`, output: [{ + banner: makeBanners(false), file: `${dist}.module.js`, format: 'esm' }, { + banner: makeBanners(false), file: `${dist}.cjs`, name: "XNB", format: 'cjs' }, { + banner: makeBanners(false), file: `${dist}.js`, name: "XNB", format: 'umd' }], - plugins: [ - removeDebug(), - polyfill({version:"es2017"}), - babel({ - babelHelpers:'bundled', - babelrc: false, - ...babelrc, - shouldPrintComment:(val)=>/^\* @(api|license)(?!\S)/.test(val) - }), - babelCleanup() - ] + plugins: makePlugins(false, false) }, { input: `${srcBase}/${srcName}.js`, @@ -79,42 +42,20 @@ function buildMaker(srcBase, srcName, dist) name: "XNB", format: 'umd' }, - plugins: [ - removeDebug(), - polyfill({version:"es2017"}), - babel({ - babelHelpers:'bundled', - babelrc: false, - ...babelrc - }), - babelCleanup(), - terser() - ] + plugins: [...makePlugins(true, false), header(licenseMap)] }, // for es5(legacy) { input: `${srcBase}/es5.js`, output: { + banner: makeBanners(false), file: `${dist}.es5.js`, name: "XNB", format: 'umd', indent: '\t' }, - plugins: [ - nodeResolve(), - commonjs(), - removeDebug(), - polyfill(), - babel({ - babelHelpers:'bundled', - babelrc: false, - exclude:'node_modules/**', - ...es5babelrc, - shouldPrintComment:(val)=>val.startsWith("* @api") - }), - babelCleanup() - ] + plugins: makePlugins(false, true) }, { input: `${srcBase}/es5.js`, @@ -124,30 +65,16 @@ function buildMaker(srcBase, srcName, dist) format: 'umd', indent: '\t' }, - plugins: [ - nodeResolve(), - commonjs(), - removeDebug(), - polyfill(), - babel({ - babelHelpers:'bundled', - babelrc: false, - exclude:'node_modules/**', - ...es5babelrc - }), - babelCleanup(), - terser() - ] + plugins: [...makePlugins(true, true), header(licenseMap)] } ]; } function buildTargetMaker(target=-1) { const targetArray = [ - ["src", "xnb", "dist/xnb"], - ["src/core", "Xnb", "src/core/dist/core"], - ["src/readers", "readers", "src/readers/dist/readers"], -// ["src/plugins-stardewvalley/", "readers", "src/plugins-stardewvalley/dist"] + ["src", "xnb", "dist/xnb", {LZ4:true, LZX:true, DXT:true}], + ["src/core", "Xnb", "src/core/dist/core", {LZ4:true, LZX:true}], + ["src/readers", "readers", "src/readers/dist/readers", {DXT:true}] ] if(target >= 0 ) return buildMaker(...targetArray[target]); diff --git a/dist/core/core.es5.min.js b/dist/core/core.es5.min.js deleted file mode 100644 index 3fe78b2..0000000 --- a/dist/core/core.es5.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},z=I,j=P,D=function(t){return z(j(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},zt=x,jt=0,Dt=Math.random(),Ct=zt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++jt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,ze=r.TypeError,je=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return je(t,e,n)}:je:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return je(t,e,n)}catch(t){}if("get"in n||"set"in n)throw ze("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,zn=$e.CONFIGURABLE,jn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||zn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||jn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==zr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",zr=Br.POLYFILL="P",jr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,zo=C,jo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=za.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!jo(t)||!zo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!zo(t)||t,r.fail=zo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},zo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,zs=Te,js=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;zs(t);try{if(!(r=js(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return zs(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error)),eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"setReaders",value:function(e){t.readers=Qs({},e)}},{key:"addReaders",value:function(e){t.readers=Qs(Qs({},t.readers),e)}},{key:"makeSimplied",value:function(e,n){var r=e.split(/`|,/)[0];if(n.isTypeOf(r)){if(n.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n.type(),"<").concat(i.join(","),">")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(simplifyType);return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(t.readers.hasOwnProperty("".concat(r,"Reader")))return t.readers["".concat(r,"Reader")].parseTypeList(i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(eh,"readers",{});var nh=[192,224,240],rh=128,ih=63,ah=[55296,56320],oh=1023;function sh(t){return t<128?[t]:t<2048?[nh[0]|t>>6,rh|t&ih]:t<65536?[nh[1]|t>>12,rh|t>>6&ih,rh|t&ih]:[nh[2]|t>>18,rh|t>>12&ih,rh|t>>6&ih,rh|t&ih]}function uh(t){return t<65535?[t]:[ah[0]|(t-=65536)>>10&oh,ah[1]|t&oh]}function hh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^nh[0])<<6)+(t[1]^rh):3===n?((t[0]^nh[1])<<12)+((t[1]^rh)<<6)+(t[2]^rh):((t[0]^nh[2])<<18)+((t[1]^rh)<<12)+((t[2]^rh)<<6)+(t[3]^rh)}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&oh)<<10)+(t[1]&oh)+65536}function ch(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),ph=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),vh=256,_h=0,yh=1,wh=2,gh=3,bh=656,mh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case wh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case yh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(bh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case gh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case wh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(h>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case yh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(_>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case gh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();mh.position_base=[],mh.extra_bits=[];var kh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new mh(16),s=new ph(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Eh=65536,Oh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||xh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Oh){for(e[f++]=240+_,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Oh){for(e[f++]=240,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Fh={};function Zh(t){var e=Fh[t];if(void 0!==e)return e.exports;var n=Fh[t]={exports:{}};return Ch[t].call(n.exports,n,n.exports,Zh),n.exports}Zh.d=function(t,e){for(var n in e)Zh.o(e,n)&&!Zh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Zh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Mh={};!function(){Zh.d(Mh,{P:function(){return Un},m:function(){return An}}),Zh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=z,G=j,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},jt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=zt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=jt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},ze=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=ze(a,r))===He&&s&&((n=De(a,s))===Ve?n=ze(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=ze(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=je(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Hh(t,n,-1)}var Gh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Yh(s,u):Kh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Yh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Jh(t){var e=t.replace(/\t/g,"\t").split("\n");return Kh(new Gh(e))}function $h(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Qh(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,f=!0,c=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function nf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=$h(i),e.content=tf(t.content),"SpriteFont"===eh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function rf(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=rf(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Xh(r.width,r.height,new Uint8Array(a))),uf(a,i)}if(e){var o=JSON.stringify(t,null,4);return uf(o,"JSON")}return null}function ff(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=hf(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(of(e.type)):"".concat(e.type,".").concat(of(e.type)):e}),4),l=c;return r&&(l=Wh(ef(t))),u.unshift(uf(l,r?"yaml":"JSON")),u}function cf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function lf(t){return df.apply(this,arguments)}function df(){return(df=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pf(t){return vf.apply(this,arguments)}function vf(){return(vf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _f(t,e){return yf.apply(this,arguments)}function yf(){return yf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,pf(n.png);case 3:return r=t.sent,i=Vh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,pf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,pf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,lf(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),yf.apply(this,arguments)}function wf(t){return gf.apply(this,arguments)}function gf(){return gf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,lf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):nf(Jh(o)),null!==(u=cf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=rf(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=af(c),d=l[1],t.next=20,_f(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),gf.apply(this,arguments)}function bf(t){return mf.apply(this,arguments)}function mf(){return(mf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=af(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",kf(r));case 8:return t.abrupt("return",kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kf(t){return(new Dh).load(t)}function xf(t){var e=hf(t.content,!0),n=e.data,r=e.extension;return new Nh(n,r)}function Ef(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Ef(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=af(s),h=u[0],f=function(t){return ff(t,{yaml:r,contentOnly:a,fileName:h})};return bf(t).then(f)},t.unpackToXnbData=bf,t.xnbDataToContent=xf,t.xnbDataToFiles=ff,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.min.js b/dist/core/core.min.js deleted file mode 100644 index 48dc783..0000000 --- a/dist/core/core.min.js +++ /dev/null @@ -1,41 +0,0 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=n({},t)}static addReaders(t){a.readers=n(n({},a.readers),t)}static makeSimplied(t,e){let i=t.split(/`|,/)[0];if(e.isTypeOf(i)){if(e.hasSubType()){let i=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(i.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(simplifyType);return"".concat(e)}for(let e of Object.values(a.readers)){let i=a.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let i=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return i}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(i=i.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}r(a,"readers",{});const o=[192,224,240],h=128,l=63,d=[55296,56320],f=1023;function c(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function u(t){return t<65535?[t]:[d[0]|(t-=65536)>>10&f,d[1]|t&f]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^o[0])<<6)+(t[1]^h):3===i?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&f)<<10)+(t[1]&f)+65536}function p(t){return function(t){const e=[];for(let i of t)e.push(...c(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class m{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} -/** @license - * - * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons - * which is derived from libmspack by Stuart Cole. - * - * (C) 2003-2004 Stuart Caie. - * (C) 2011 Ali Scissons. - * (C) 2017 James Stine. - * - * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. - * - * - * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - * LzxDecoder is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * MICROSOFT PUBLIC LICENSE - * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). - * - * Redistribution and use in source and binary forms, with or without modification, - * is permitted provided that redistributions of the source code retain the above - * copyright notices and this file header. - * - * Additional copyright notices should be appended to the list above. - * - * For details, see . - * - * - * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been - * acknowleded properly as it should have been back in 2017. - * - * Resources: - * - * cabextract/libmspack - http://http://www.cabextract.org.uk/ - * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs - * - */const y=256,v=0,k=1,x=2,E=3,A=656;class U{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!U.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)U.extra_bits[t]=U.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!U.position_base.length)for(let t=0,e=0;t<=50;t++)U.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(A,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case E:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){let e=U.extra_bits[s];if(s=U.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){if(3!=s){let e=U.extra_bits[s],i=t.readLZXBits(e);s=U.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case E:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}U.position_base=[],U.extra_bits=[];class R{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}} -/** @license - * Original Code by: https://github.com/Benzinga/lz4js/ - */const B=65536,O=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||R.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=O){for(e[d++]=240+p,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=O){for(e[d++]=240,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class z{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=S(e);t.write7BitNumber(i),t.writeString(e)}}class D{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class P{constructor(t,e,i){let{target:n,formatVersion:r,hidef:s,compressed:a}=t;this.header={target:n,formatVersion:r,hidef:s,compressed:a},this.readers=e,this.content=i}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class C{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const Z=64,F=128,V=14;class M{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new g(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==F){const e=this.fileSize-V,i=class{static decompress(t,e,i){let n,r,a=0;const o=new U(16);let h=new m(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,V,0,t),this.buffer.bytePosition=V}else if(this.compressionType==Z){const e=this.buffer.buffer.slice(V),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function X(t){var e=W[t];if(void 0!==e)return e.exports;var i=W[t]={exports:{}};return j[t].call(i.exports,i,i.exports,X),i.exports}X.d=(t,e)=>{for(var i in e)X.o(e,i)&&!X.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},X.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{X.d(H,{P:()=>Ti,m:()=>Li}),X(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),I(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:K,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},It=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=K(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new Lt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Ot),new Lt(4,5,16,8,Ot),new Lt(4,6,32,32,Ot),new Lt(4,4,16,16,It),new Lt(8,16,32,32,It),new Lt(8,16,128,128,It),new Lt(8,32,128,256,It),new Lt(32,128,258,1024,It),new Lt(32,258,258,4096,It)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,I,L,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(I=0,L=a[p]):a[p]>_?(I=T[N+a[p]],L=A[U+a[p]]):(I=96,L=0),l=1<>v)+d]=O<<24|I<<16|L|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Ie=!0;const Le=t=>{if(Ie){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Ie=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Le(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var K=H.P,Y=H.m;function G(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=G(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+G(t[s],e,i+1):s.includes(": ")?(r+=G(s,e,i+1),r+=": "+G(t[s],e,i+1)):r+=s+": "+G(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),G(t,i,-1)}class ${constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new $(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?Q(n,r):q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return q(new $(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(et(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=et(n);return e}return t}function it(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function nt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function rt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(it(e))return et(i);if(nt(e))return i=et(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;t=et(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(rt(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=rt(n);return e}return null}function st(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let d=a.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(it(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:r}}},traversed:a+1};if(nt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function at(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=et(n),e.content=rt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ot(i,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function dt(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ft(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:dt(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ct(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ot(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=Y(t.width,t.height,new Uint8Array(n))),ft(n,e)}if(e){return ft(JSON.stringify(t,null,4),"JSON")}return null}function ut(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ct(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),r.unshift(ft(l,e?"yaml":"JSON")),r}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function bt(t,e){if("png"===t){const t=await pt(e.png),i=K(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function gt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await wt(n);let a=null;a=t.json?JSON.parse(r):at(tt(r));let o=_t(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=ht(i);e.export=await bt(n,t)}return a}async function mt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return yt(await t.arrayBuffer())}return yt(t.buffer)}function yt(t){return(new M).load(t)}function vt(t){const{content:e}=t,{data:i,extension:n}=ct(e,!0);return new C(i,n)}function kt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=kt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(gt(e,i).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return a.setReaders(t)},t.unpackToContent=function(t){return mt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=ht(r);const a=t=>ut(t,{yaml:i,contentOnly:n,fileName:s});return mt(t).then(a)},t.unpackToXnbData=mt,t.xnbDataToContent=vt,t.xnbDataToFiles=ut,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.cjs b/dist/core/xnb-core.cjs similarity index 98% rename from dist/core/core.cjs rename to dist/core/xnb-core.cjs index 395110f..84a46e8 100644 --- a/dist/core/core.cjs +++ b/dist/core/xnb-core.cjs @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -71,6 +80,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -99,7 +124,7 @@ class TypeReader { if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { - let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); return "".concat(reflectiveType); } @@ -112,13 +137,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -133,12 +155,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1537,7 +1555,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4684,6 +4704,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4732,17 +4753,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4829,6 +4869,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/dist/core/core.es5.js b/dist/core/xnb-core.es5.js similarity index 99% rename from dist/core/core.es5.js rename to dist/core/xnb-core.es5.js index 0cfa925..67be59a 100644 --- a/dist/core/core.es5.js +++ b/dist/core/xnb-core.es5.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -3254,6 +3263,22 @@ return _createClass(XnbError); }(_wrapNativeSuper(Error)); + function removeExternBracket(str) { + var bracketStack = []; + var result = []; + + for (var i = 0; i < str.length; i++) { + var c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + var startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + var TypeReader = function () { function TypeReader() { _classCallCheck(this, TypeReader); @@ -3303,7 +3328,7 @@ if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { - var reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + var reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); return "".concat(reflectiveType); } @@ -3318,13 +3343,10 @@ }, { key: "parseSubtypes", value: function parseSubtypes(type) { - var subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - var matches = subtype.match(pattern).map(function (e) { - return e.slice(1, -1); - }); + var subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + var matches = removeExternBracket(subtype); return matches; } }, { @@ -3343,19 +3365,15 @@ }, { key: "getReaderTypeList", value: function getReaderTypeList(typeString) { - var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn.type, - subtypes = _TypeReader$getTypeIn.subtypes; - - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + var reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } }, { key: "getReader", value: function getReader(typeString) { - var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn2.type, - subtypes = _TypeReader$getTypeIn2.subtypes; + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); @@ -4865,8 +4883,8 @@ }, { key: "getIndex", value: function getIndex(reader) { - for (var i in this.readers) { - if (reader.toString() == this.readers[i].toString()) return i; + for (var i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; } } }]); @@ -8362,6 +8380,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -8408,17 +8427,41 @@ } if (__startsWithString(reader, 'Nullable')) { + var nullableData, trav; + + var _reader$split = reader.split(":"), + readerType = _reader$split[0], + _reader$split$ = _reader$split[1], + blockTraversed = _reader$split$ === void 0 ? 1 : _reader$split$; + + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (_typeof(obj) === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + var _recursiveConvert2 = recursiveConvert(obj, [].concat(path), index + 1), + _converted = _recursiveConvert2.converted, + _traversed = _recursiveConvert2.traversed; + + nullableData = _converted; + trav = _traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -8467,11 +8510,11 @@ var newIndex = void 0; if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; - var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), - _converted = _recursiveConvert2.converted, - nexter = _recursiveConvert2.traversed; + var _recursiveConvert3 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted2 = _recursiveConvert3.converted, + nexter = _recursiveConvert3.traversed; - data[key] = _converted; + data[key] = _converted2; if (isComplex) traversed = nexter;else if (first) { traversed = nexter; first = false; @@ -8510,6 +8553,11 @@ return data; } + if (__startsWithString(type, "Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/dist/core/xnb-core.es5.min.js b/dist/core/xnb-core.es5.min.js new file mode 100644 index 0000000..3dd11ae --- /dev/null +++ b/dist/core/xnb-core.es5.min.js @@ -0,0 +1,48 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},j=I,z=P,D=function(t){return j(z(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},jt=x,zt=0,Dt=Math.random(),Ct=jt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++zt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,je=r.TypeError,ze=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return ze(t,e,n)}:ze:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return ze(t,e,n)}catch(t){}if("get"in n||"set"in n)throw je("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,jn=$e.CONFIGURABLE,zn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||jn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||zn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==jr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",jr=Br.POLYFILL="P",zr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,jo=C,zo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=ja.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!zo(t)||!jo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!jo(t)||t,r.fail=jo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},jo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,js=Te,zs=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;js(t);try{if(!(r=zs(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return js(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error));function eh(t){for(var e=[],n=[],r=0;r")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){return t.getReader(e).parseTypeList()}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(nh,"readers",{});var rh=[192,224,240],ih=128,ah=63,oh=[55296,56320],sh=1023;function uh(t){return t<128?[t]:t<2048?[rh[0]|t>>6,ih|t&ah]:t<65536?[rh[1]|t>>12,ih|t>>6&ah,ih|t&ah]:[rh[2]|t>>18,ih|t>>12&ah,ih|t>>6&ah,ih|t&ah]}function hh(t){return t<65535?[t]:[oh[0]|(t-=65536)>>10&sh,oh[1]|t&sh]}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^rh[0])<<6)+(t[1]^ih):3===n?((t[0]^rh[1])<<12)+((t[1]^ih)<<6)+(t[2]^ih):((t[0]^rh[2])<<18)+((t[1]^ih)<<12)+((t[2]^ih)<<6)+(t[3]^ih)}function ch(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&sh)<<10)+(t[1]&sh)+65536}function lh(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),vh=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),_h=256,yh=0,wh=1,gh=2,bh=3,mh=656,kh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case gh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case wh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(mh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case bh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case gh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,mh,12);if(h<_h)this.win[this.window_posn++]=h,u--;else{var f=7&(h-=_h);7==f&&(f+=this.readHuffSymbol(e,this.length_table,this.length_len,250,12)),f+=2;var c=h>>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case wh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,mh,12);if(_<_h)this.win[this.window_posn++]=_,u--;else{var y=7&(_-=_h);7==y&&(y+=this.readHuffSymbol(e,this.length_table,this.length_len,250,12)),y+=2;var w=_>>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case bh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();kh.position_base=[],kh.extra_bits=[];var xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new kh(16),s=new vh(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),Eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Oh=65536,Rh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||Eh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Rh){for(e[f++]=240+_,l=h-Rh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Rh){for(e[f++]=240,l=h-Rh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Zh={};function Mh(t){var e=Zh[t];if(void 0!==e)return e.exports;var n=Zh[t]={exports:{}};return Fh[t].call(n.exports,n,n.exports,Mh),n.exports}Mh.d=function(t,e){for(var n in e)Mh.o(e,n)&&!Mh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Mh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Vh={};!function(){Mh.d(Vh,{P:function(){return Un},m:function(){return An}}),Mh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=j,G=z,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},zt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=jt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=zt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},je=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=je(a,r))===He&&s&&((n=De(a,s))===Ve?n=je(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=je(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=ze(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Wh(t,n,-1)}var Kh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Jh(s,u):Yh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Jh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function $h(t){var e=t.replace(/\t/g,"\t").split("\n");return Yh(new Kh(e))}function qh(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(Qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable")){var h,f,c=u.split(":"),l=c[0],d=c[1],p=void 0===d?1:d;if(p=+p,null===i)h=null,f=s+p;else if("object"!==tu(i)||i&&0!==Object.keys(i).length){var v=t(i,[].concat(a),s+1);h=v.converted,f=v.traversed}else h={type:e[s+1],data:qh(i)},f=s+p;return{converted:{type:l,data:{data:h}},traversed:f}}if(tf(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var _=s,y=!0,w=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),g=Object.keys(i),b=0;b0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function rf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=qh(i),e.content=ef(t.content),"SpriteFont"===nh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function af(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=af(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Hh(r.width,r.height,new Uint8Array(a))),hf(a,i)}if(e){var o=JSON.stringify(t,null,4);return hf(o,"JSON")}return null}function cf(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=ff(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(sf(e.type)):"".concat(e.type,".").concat(sf(e.type)):e}),4),l=c;return r&&(l=Gh(nf(t))),u.unshift(hf(l,r?"yaml":"JSON")),u}function lf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function df(t){return pf.apply(this,arguments)}function pf(){return(pf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function vf(t){return _f.apply(this,arguments)}function _f(){return(_f=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function yf(t,e){return wf.apply(this,arguments)}function wf(){return wf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,vf(n.png);case 3:return r=t.sent,i=Xh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,vf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,vf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,df(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),wf.apply(this,arguments)}function gf(t){return bf.apply(this,arguments)}function bf(){return bf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,df(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):rf($h(o)),null!==(u=lf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=af(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=of(c),d=l[1],t.next=20,yf(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),bf.apply(this,arguments)}function mf(t){return kf.apply(this,arguments)}function kf(){return(kf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=of(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",xf(r));case 8:return t.abrupt("return",xf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function xf(t){return(new Ch).load(t)}function Ef(t){var e=ff(t.content,!0),n=e.data,r=e.extension;return new Ph(n,r)}function Of(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Of(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=of(s),h=u[0],f=function(t){return cf(t,{yaml:r,contentOnly:a,fileName:h})};return mf(t).then(f)},t.unpackToXnbData=mf,t.xnbDataToContent=Ef,t.xnbDataToFiles=cf,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.js b/dist/core/xnb-core.js similarity index 98% rename from dist/core/core.js rename to dist/core/xnb-core.js index 7f5a5b2..0c87258 100644 --- a/dist/core/core.js +++ b/dist/core/xnb-core.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -73,6 +82,22 @@ } + function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -101,7 +126,7 @@ if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { - let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); return "".concat(reflectiveType); } @@ -114,13 +139,10 @@ } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -135,12 +157,8 @@ } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1539,7 +1557,9 @@ } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4686,6 +4706,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4734,17 +4755,36 @@ } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4831,6 +4871,11 @@ return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/dist/core/xnb-core.min.js b/dist/core/xnb-core.min.js new file mode 100644 index 0000000..f6d9bca --- /dev/null +++ b/dist/core/xnb-core.min.js @@ -0,0 +1,48 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}function a(t){let e=[],i=[];for(let n=0;n")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=o.parseSubtypes(t).map(o.simplifyType.bind(o));return"".concat(e)}for(let e of Object.values(o.readers)){let i=o.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.slice(t.search("`")+1);return e[0],e=a(e)[0],a(e)}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){return o.getReader(t).parseTypeList()}static getReader(t){let{type:e,subtypes:i}=o.getTypeInfo(t);if(i=i.map(o.getReader.bind(o)),o.readers.hasOwnProperty("".concat(e,"Reader")))return new(o.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=o.simplifyType(t);return o.getReader(e)}}r(o,"readers",{});const h=[192,224,240],l=128,d=63,f=[55296,56320],c=1023;function u(t){return t<128?[t]:t<2048?[h[0]|t>>6,l|t&d]:t<65536?[h[1]|t>>12,l|t>>6&d,l|t&d]:[h[2]|t>>18,l|t>>12&d,l|t>>6&d,l|t&d]}function _(t){return t<65535?[t]:[f[0]|(t-=65536)>>10&c,f[1]|t&c]}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^h[0])<<6)+(t[1]^l):3===i?((t[0]^h[1])<<12)+((t[1]^l)<<6)+(t[2]^l):((t[0]^h[2])<<18)+((t[1]^l)<<12)+((t[2]^l)<<6)+(t[3]^l)}function p(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&c)<<10)+(t[1]&c)+65536}function b(t){return function(t){const e=[];for(let i of t)e.push(...u(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}const v=256,k=0,x=1,E=2,A=3,U=656;class R{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!R.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)R.extra_bits[t]=R.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!R.position_base.length)for(let t=0,e=0;t<=50;t++)R.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case E:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case x:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(U,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case A:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case E:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,U,12);if(n>3;if(s>2){let e=R.extra_bits[s];if(s=R.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,U,12);if(n>3;if(s>2){if(3!=s){let e=R.extra_bits[s],i=t.readLZXBits(e);s=R.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case A:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}R.position_base=[],R.extra_bits=[];class B{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}}const O=65536,L=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||B.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=L){for(e[d++]=240+p,c=l-L;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=L){for(e[d++]=240,c=l-L;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class D{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=z(e);t.write7BitNumber(i),t.writeString(e)}}class P{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e=0,i=this.readers.length;e"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class Z{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const F=64,V=128,M=14;class j{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new m(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==V){const e=this.fileSize-M,i=class{static decompress(t,e,i){let n,r,a=0;const o=new R(16);let h=new y(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,M,0,t),this.buffer.bytePosition=M}else if(this.compressionType==F){const e=this.buffer.buffer.slice(M),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},X={};function H(t){var e=X[t];if(void 0!==e)return e.exports;var i=X[t]={exports:{}};return W[t].call(i.exports,i,i.exports,H),i.exports}H.d=(t,e)=>{for(var i in e)H.o(e,i)&&!H.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},H.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var K={};(()=>{H.d(K,{P:()=>Ti,m:()=>Ii}),H(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),I(t,t.l_desc),I(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),I(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),L(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:X,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=X(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Lt=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=X(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=X(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=X(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new It(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,Ot),new It(4,5,16,8,Ot),new It(4,6,32,32,Ot),new It(4,4,16,16,Lt),new It(8,16,32,32,Lt),new It(8,16,128,128,Lt),new It(8,32,128,256,Lt),new It(32,128,258,1024,Lt),new It(32,258,258,4096,Lt)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=X(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,L,I,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(L=0,I=a[p]):a[p]>_?(L=T[N+a[p]],I=A[U+a[p]]):(L=96,I=0),l=1<>v)+d]=O<<24|L<<16|I|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Le=!0;const Ie=t=>{if(Le){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Le=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Ie(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var Y=K.P,G=K.m;function J(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=J(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+J(t[s],e,i+1):s.includes(": ")?(r+=J(s,e,i+1),r+=": "+J(t[s],e,i+1)):r+=s+": "+J(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function $(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),J(t,i,-1)}class q{constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new q(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function Q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?tt(n,r):Q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function tt(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function et(t){let e=t.replace(/\t/g,"\t").split("\n");return Q(new q(e))}function it(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(it(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=it(n);return e}return t}function nt(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":case"Rect":return!0;default:return!1}}function rt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function st(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(nt(e))return it(i);if(rt(e))return i=it(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;if(e.startsWith("Nullable"))return null===i||null===i.data?null:st(i.data);t=it(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(st(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=st(n);return e}return null}function at(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let a=it(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:a,numSharedResources:0};const h=it(t.content),l=o.simplifyType(a[0].type);let d=o.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(nt(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable")){let i,n,[h,l=1]=o.split(":");if(l=+l,null===r)i=null,n=a+l;else if("object"!=typeof r||r&&0!==Object.keys(r).length){let{converted:e,traversed:o}=t(r,[...s],a+1);i=e,n=o}else i={type:e[a+1],data:it(r)},n=a+l;return{converted:{type:h,data:{data:i}},traversed:n}}if(rt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function ot(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=it(n),e.content=st(t.content),"SpriteFont"===o.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ht(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ht(i,e);if(t)return t}return null}}function lt(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function dt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function ft(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ct(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:ft(e)}),extension:dt(e)}:{data:t,extension:dt(e)}}function ut(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ht(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=G(t.width,t.height,new Uint8Array(n))),ct(n,e)}if(e){return ct(JSON.stringify(t,null,4),"JSON")}return null}function _t(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ut(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(dt(e.type)):"".concat(e.type,".").concat(dt(e.type)):e),4);let l=h;return e&&(l=$(at(t))),r.unshift(ct(l,e?"yaml":"JSON")),r}function wt(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function bt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function gt(t,e){if("png"===t){const t=await bt(e.png),i=Y(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await bt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await bt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await pt(e.xml)}}}async function mt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await pt(n);let a=null;a=t.json?JSON.parse(r):ot(et(r));let o=wt(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ht(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=lt(i);e.export=await gt(n,t)}return a}async function yt(t){if("undefined"!=typeof window){const[,e]=lt(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return vt(await t.arrayBuffer())}return vt(t.buffer)}function vt(t){return(new j).load(t)}function kt(t){const{content:e}=t,{data:i,extension:n}=ut(e,!0);return new Z(i,n)}function xt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=xt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(mt(e,i).then(Et).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return o.setReaders(t)},t.unpackToContent=function(t){return yt(t).then(kt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=lt(r);const a=t=>_t(t,{yaml:i,contentOnly:n,fileName:s});return yt(t).then(a)},t.unpackToXnbData=yt,t.xnbDataToContent=kt,t.xnbDataToFiles=_t,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/core/core.module.js b/dist/core/xnb-core.module.js similarity index 98% rename from dist/core/core.module.js rename to dist/core/xnb-core.module.js index c0bd5a0..1b4d0ba 100644 --- a/dist/core/core.module.js +++ b/dist/core/xnb-core.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { let mappedPromises = promises.map(p => { return p.then(value => { @@ -67,6 +76,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -95,7 +120,7 @@ class TypeReader { if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { - let reflectiveType = TypeReader.parseSubtypes(type).map(simplifyType); + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); return "".concat(reflectiveType); } @@ -108,13 +133,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -129,12 +151,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1533,7 +1551,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4680,6 +4700,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4728,17 +4749,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4825,6 +4865,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/dist/plugins/stardewvalley/index.es5.min.js b/dist/plugins/stardewvalley/index.es5.min.js new file mode 100644 index 0000000..047d348 --- /dev/null +++ b/dist/plugins/stardewvalley/index.es5.min.js @@ -0,0 +1,9 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,r){"use strict";function t(e){this.wrapped=e}function n(e){var r,n;function a(r,n){try{var u=e[r](n),l=u.value,o=l instanceof t;Promise.resolve(o?l.wrapped:l).then((function(e){o?a("return"===r?"return":"next",e):i(u.done?"return":"normal",e)}),(function(e){a("throw",e)}))}catch(e){i("throw",e)}}function i(e,t){switch(e){case"return":r.resolve({value:t,done:!0});break;case"throw":r.reject(t);break;default:r.resolve({value:t,done:!1})}(r=r.next)?a(r.key,r.arg):n=null}this._invoke=function(e,t){return new Promise((function(i,u){var l={key:e,arg:t,resolve:i,reject:u,next:null};n?n=n.next=l:(r=n=l,a(e,t))}))},"function"!=typeof e.return&&(this.return=void 0)}function a(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function i(e,r){for(var t=0;t","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),f=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.StringReader),i=new r.NullableReader(new r.ListReader(new r.StringReader));return{ID:a.read(e,t),SheetIndex:n.read(e),Title:t.read(e),Description:t.read(e),Tags:i.read(e,t),Scenes:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader,u=new r.NullableReader(new r.StringReader),l=new r.NullableReader(new r.ListReader(new r.StringReader)),o=new r.ListReader(new R);this.writeIndex(e,n),u.write(e,t.ID,n),a.write(e,t.SheetIndex,null),i.write(e,t.Title,n),i.write(e,t.Description,n),l.write(e,t.Tags,n),o.write(e,t.Scenes,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieData"===e}},{key:"parseTypeList",value:function(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List"].concat(R.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),v=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader);return{ResponsePoint:n.read(e,t),Script:n.read(e,t)||"",Text:n.read(e,t)||""}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),a.write(e,t.ResponsePoint,n),a.write(e,t.Script,n),a.write(e,t.Text,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}},{key:"parseTypeList",value:function(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),S=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new v);return{BeforeMovie:n.read(e,t),DuringMovie:n.read(e,t),AfterMovie:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new v);this.writeIndex(e,n),a.write(e,t.BeforeMovie,n),a.write(e,t.DuringMovie,n),a.write(e,t.AfterMovie,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}},{key:"parseTypeList",value:function(){return["SpecialResponses","Nullable:7"].concat(v.parseTypeList(),["Nullable:7"],v.parseTypeList(),["Nullable:7"],v.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),g=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.ListReader(new r.StringReader)),i=new r.NullableReader(new S);return{Tag:t.read(e),Response:n.read(e,t)||"like",Whitelist:a.read(e,t)||[],SpecialResponses:i.read(e,t),ID:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.ListReader(new r.StringReader)),l=new r.NullableReader(new S);this.writeIndex(e,n),a.write(e,t.Tag,n),i.write(e,t.Response,n),u.write(e,t.Whitelist,n),l.write(e,t.SpecialResponses,n),a.write(e,t.ID,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieReaction"===e}},{key:"parseTypeList",value:function(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25"].concat(S.parseTypeList(),["String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),T=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new g));return{NPCName:t.read(e),Reactions:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new g));this.writeIndex(e,n),a.write(e,t.NPCName,n),i.write(e,t.Reactions,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}},{key:"parseTypeList",value:function(){return["MovieCharacterReaction","String","Nullable>:34","List"].concat(g.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),k=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.ListReader(new r.StringReader));return{ID:n.read(e),Name:t.read(e),DisplayName:t.read(e),Description:t.read(e),Price:n.read(e),ItemTags:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader,u=new r.NullableReader(new r.ListReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.ID,null),i.write(e,t.Name,n),i.write(e,t.DisplayName,n),i.write(e,t.Description,n),a.write(e,t.Price,null),u.write(e,t.ItemTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}},{key:"parseTypeList",value:function(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),m=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new r.StringReader));return{Name:t.read(e),LovedTags:n.read(e,t),LikedTags:n.read(e,t),DislikedTags:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.Name,n),i.write(e,t.LovedTags,n),i.write(e,t.LikedTags,n),i.write(e,t.DislikedTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}},{key:"parseTypeList",value:function(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),h=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.SingleReader;return{RequiredPopulation:n.read(e),Chance:Math.round(1e5*a.read(e))/1e5,ItemId:n.read(e),MinQuantity:n.read(e),MaxQuantity:n.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.SingleReader;this.writeIndex(e,n),a.write(e,t.RequiredPopulation,null),i.write(e,t.Chance,null),a.write(e,t.ItemId,null),a.write(e,t.MinQuantity,null),a.write(e,t.MaxQuantity,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}},{key:"parseTypeList",value:function(){return["FishPondReward",null,null,null,null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),b=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.DictionaryReader(new r.Int32Reader,new r.ListReader(new r.StringReader)));return{RequiredTags:t.read(e),SpawnTime:n.read(e),ProducedItems:t.read(e),PopulationGates:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new r.StringReader),i=new r.Int32Reader,u=new r.ListReader(new h),l=new r.NullableReader(new r.DictionaryReader(new r.Int32Reader,new r.ListReader(new r.StringReader)));this.writeIndex(e,n),a.write(e,t.RequiredTags,n),i.write(e,t.SpawnTime,null),u.write(e,t.ProducedItems,n),l.write(e,t.PopulationGates,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondData"===e}},{key:"parseTypeList",value:function(){return["FishPondData","List","String",null,"List"].concat(h.parseTypeList(),["Nullable>>:4","Dictionary>","Int32","List","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),L=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new r.StringReader)),a=new r.NullableReader(new r.StringReader),i=new r.BooleanReader,u=new r.Int32Reader;return{FirstItemTags:n.read(e,t),SecondItemTags:n.read(e,t),SpendingRightItem:i.read(e),CraftedItemID:u.read(e),CraftedItemIDs:n.read(e,t),CraftedItemColor:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new r.ListReader(new r.StringReader)),i=new r.NullableReader(new r.StringReader),u=new r.BooleanReader,l=new r.Int32Reader;this.writeIndex(e,n),a.write(e,t.FirstItemTags,n),a.write(e,t.SecondItemTags,n),u.write(e,t.SpendingRightItem,null),l.write(e,t.CraftedItemID,null),a.write(e,t.CraftedItemIDs,n),i.write(e,t.CraftedItemColor,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}},{key:"parseTypeList",value:function(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),D=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Key:r.read(e),Value:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader;this.writeIndex(e,n),a.write(e,t.Type,n),a.write(e,t.Key,n),a.write(e,t.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}},{key:"parseTypeList",value:function(){return["RenovationValue","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),I=function(e){l(t,e);var r=w(t);function t(){return a(this,t),r.apply(this,arguments)}return u(t,[{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return!!p(o(t),"isTypeOf",this).call(this,e)||"StardewValley.GameData.HomeRenovations.Rect"===e}},{key:"parseTypeList",value:function(){return["Rect"]}},{key:"type",value:function(){return"Reflective"}}]),t}(r.RectangleReader),N=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Rects:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new I);this.writeIndex(e,n),a.write(e,t.Rects,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}},{key:"parseTypeList",value:function(){return["RectGroup","List","Rect"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),O=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.BooleanReader,a=new r.NullableReader(new r.ListReader(new N)),i=new r.NullableReader(new r.StringReader);return{TextStrings:t.read(e),AnimationType:t.read(e),CheckForObstructions:n.read(e),Requirements:t.read(e),RenovateActions:t.read(e),RectGroups:a.read(e,t),SpecialRect:i.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.BooleanReader,i=new r.StringReader,u=new r.ListReader(new D),l=new r.NullableReader(new r.ListReader(new N)),o=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),i.write(e,t.TextStrings,n),i.write(e,t.AnimationType,n),a.write(e,t.CheckForObstructions,null),u.write(e,t.Requirements,n),u.write(e,t.RenovateActions,n),l.write(e,t.RectGroups,n),o.write(e,t.SpecialRect,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}},{key:"parseTypeList",value:function(){return["HomeRenovation","String","String",null,"List"].concat(D.parseTypeList(),["List"],D.parseTypeList(),["Nullable>:4","List"],N.parseTypeList(),["Nullable","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),B=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader;return{Name:t.read(e),Index:n.read(e),Sprite:t.read(e),Color:t.read(e),Items:t.read(e),Pick:n.read(e),RequiredItems:n.read(e),Reward:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader;this.writeIndex(e,n),i.write(e,t.Name,n),a.write(e,t.Index,null),i.write(e,t.Sprite,n),i.write(e,t.Color,n),i.write(e,t.Items,n),a.write(e,t.Pick,null),a.write(e,t.RequiredItems,null),i.write(e,t.Reward,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleData"===e}},{key:"parseTypeList",value:function(){return["BundleData","String",null,"String","String","String",null,null,"String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),x=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Bundles:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new B);this.writeIndex(e,n),a.write(e,t.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleSetData"===e}},{key:"parseTypeList",value:function(){return["BundleSetData","List"].concat(B.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),V=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new x)),a=new r.NullableReader(new r.ListReader(new B));return{AreaName:t.read(e),Keys:t.read(e),BundleSets:n.read(e,t),Bundles:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new x)),u=new r.NullableReader(new r.ListReader(new B));this.writeIndex(e,n),a.write(e,t.AreaName,n),a.write(e,t.Keys,n),i.write(e,t.BundleSets,n),u.write(e,t.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomBundleData"===e}},{key:"parseTypeList",value:function(){return["RandomBundleData","String","String","Nullable>:13","List"].concat(x.parseTypeList(),["Nullable>:11","List"],B.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),M=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{RequiredTags:new r.NullableReader(new r.StringReader).read(e,t)||"",Value:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),i.write(e,t.RequiredTags,n),a.write(e,t.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElementItem"===e}},{key:"parseTypeList",value:function(){return["RandomizedElementItem","Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),C=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Name:r.read(e),Values:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.ListReader(new M);this.writeIndex(e,n),a.write(e,t.Name,n),i.write(e,t.Values,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElement"===e}},{key:"parseTypeList",value:function(){return["RandomizedElement","String","List"].concat(M.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),F=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Text:r.read(e),RequiredCount:r.read(e),Data:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.DictionaryReader(new r.StringReader,new r.StringReader);this.writeIndex(e,n),a.write(e,t.Type,n),a.write(e,t.Text,n),a.write(e,t.RequiredCount,n),i.write(e,t.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),P=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Data:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.DictionaryReader(new r.StringReader,new r.StringReader);this.writeIndex(e,n),a.write(e,t.Type,n),i.write(e,t.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),G=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.ListReader(new C));return{Name:t.read(e),Requester:t.read(e),Duration:t.read(e),Repeatable:n.read(e,t)||"False",RequiredTags:n.read(e,t)||"",OrderType:n.read(e,t)||"",SpecialRule:n.read(e,t)||"",Text:t.read(e),ItemToRemoveOnEnd:n.read(e,t),MailToRemoveOnEnd:n.read(e,t),RandomizedElements:a.read(e,t),Objectives:t.read(e),Rewards:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.ListReader(new C)),l=new r.ListReader(new F),o=new r.ListReader(new P);this.writeIndex(e,n),a.write(e,t.Name,n),a.write(e,t.Requester,n),a.write(e,t.Duration,n),i.write(e,t.Repeatable,n),i.write(e,t.RequiredTags,n),i.write(e,t.OrderType,n),i.write(e,t.SpecialRule,n),a.write(e,t.Text,n),i.write(e,t.ItemToRemoveOnEnd,n),i.write(e,t.MailToRemoveOnEnd,n),u.write(e,t.RandomizedElements,n),l.write(e,t.Objectives,n),o.write(e,t.Rewards,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List"].concat(C.parseTypeList(),["List"],F.parseTypeList(),["List"],P.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),j=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.DictionaryReader(new r.StringReader));return{ID:t.read(e),TooltipStringPath:t.read(e),MapName:t.read(e),IconTexture:n.read(e,t),WorldMapTexture:n.read(e,t),ModData:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.DictionaryReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.ID,n),a.write(e,t.TooltipStringPath,n),a.write(e,t.MapName,n),i.write(e,t.IconTexture,n),i.write(e,t.WorldMapTexture,n),u.write(e,t.ModData,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModFarmType"===e}},{key:"parseTypeList",value:function(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),E=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.SingleReader,i=new r.BooleanReader,u=new r.NullableReader(new r.StringReader);return{ID:t.read(e),LanguageCode:t.read(e),ButtonTexture:t.read(e),UseLatinFont:i.read(e),FontFile:u.read(e,t),FontPixelZoom:a.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:n.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:u.read(e,t),TimeFormat:t.read(e),ClockTimeFormat:t.read(e),ClockDateFormat:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.Int32Reader,u=new r.SingleReader,l=new r.BooleanReader,o=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),a.write(e,t.ID,n),a.write(e,t.LanguageCode,n),a.write(e,t.ButtonTexture,n),l.write(e,t.UseLatinFont,null),o.write(e,t.FontFile,n),u.write(e,t.FontPixelZoom,null),l.write(e,t.FontApplyYOffset,null),i.write(e,t.SmallFontLineSpacing,null),l.write(e,t.UseGenderedCharacterTranslations,null),o.write(e,t.NumberComma,n),a.write(e,t.TimeFormat,n),a.write(e,t.ClockTimeFormat,n),a.write(e,t.ClockDateFormat,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModLanguage"===e}},{key:"parseTypeList",value:function(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),q=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.BooleanReader;return{ID:t.read(e),Texture:t.read(e),IsFlooring:a.read(e),Count:n.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.BooleanReader,u=new r.StringReader;this.writeIndex(e,n),u.write(e,t.ID,n),u.write(e,t.Texture,n),i.write(e,t.IsFlooring,null),a.write(e,t.Count,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}},{key:"parseTypeList",value:function(){return["ModWallpaperOrFlooring","String","String",null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader);e.BundleDataReader=B,e.BundleSetDataReader=x,e.CharacterResponseReader=v,e.ConcessionItemDataReader=k,e.ConcessionTasteReader=m,e.FishPondDataReader=b,e.FishPondRewardReader=h,e.HomeRenovationReader=O,e.ModFarmTypeReader=j,e.ModLanguageReader=E,e.ModWallpaperOrFlooringReader=q,e.MovieCharacterReactionReader=T,e.MovieDataReader=f,e.MovieReactionReader=g,e.MovieSceneReader=R,e.RandomBundleDataReader=V,e.RandomizedElementItemReader=M,e.RandomizedElementReader=C,e.RectGroupReader=N,e.RectReader=I,e.RenovationValueReader=D,e.SpecialOrderDataReader=G,e.SpecialOrderObjectiveDataReader=F,e.SpecialOrderRewardDataReader=P,e.SpecialResponsesReader=S,e.TailorItemRecipeReader=L,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/dist/plugins/stardewvalley/index.min.js b/dist/plugins/stardewvalley/index.min.js new file mode 100644 index 0000000..d1a388c --- /dev/null +++ b/dist/plugins/stardewvalley/index.min.js @@ -0,0 +1,9 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),u=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),u.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...w.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new w),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=u,e.FishPondDataReader=R,e.FishPondRewardReader=w,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=f,e.ModWallpaperOrFlooringReader=x,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/dist/plugins/stardewvalley/index.module.js b/dist/plugins/stardewvalley/index.module.js new file mode 100644 index 0000000..68f9d01 --- /dev/null +++ b/dist/plugins/stardewvalley/index.module.js @@ -0,0 +1,1366 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +import { BaseReader, BooleanReader, Int32Reader, NullableReader, StringReader, ListReader, SingleReader, DictionaryReader, RectangleReader } from '../../readers/xnb-readers.module.js'; + +class MovieSceneReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieScene", null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieData", "Nullable", 'String', null, 'String', 'String', "Nullable>", 'List', 'String', "List", ...MovieSceneReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const movieSceneListReader = new ListReader(new MovieSceneReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } + +} + +class CharacterResponseReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["CharacterResponse", "Nullable:1", "String", "Nullable:1", "String", "Nullable:1", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialResponsesReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialResponses", "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + this.writeIndex(buffer, resolver); + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieReaction", "String", "Nullable:1", "String", "Nullable>:2", "List", "String", "Nullable:25", ...SpecialResponsesReader.parseTypeList(), "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieCharacterReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieCharacterReaction", "String", "Nullable>:34", "List", ...MovieReactionReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionItemDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionItemData", null, 'String', 'String', 'String', null, 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionTasteReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionTaste", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } + +} + +class FishPondRewardReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondReward': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondReward", null, null, null, null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const RequiredPopulation = int32Reader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } + +} + +class FishPondDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondData", "List", "String", null, "List", ...FishPondRewardReader.parseTypeList(), "Nullable>>:4", "Dictionary>", "Int32", "List", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, resolver); + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new ListReader(new StringReader()); + const int32Reader = new Int32Reader(); + const fishPondRewardListReader = new ListReader(new FishPondRewardReader()); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + this.writeIndex(buffer, resolver); + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, null); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } + +} + +class TailorItemRecipeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["TailorItemRecipe", "Nullable>:2", "List", "String", "Nullable>:2", "List", "String", null, null, "Nullable>:2", "List", "String", "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + this.writeIndex(buffer, resolver); + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } + +} + +class RenovationValueReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RenovationValue", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Key = resolver.read(buffer); + const Value = resolver.read(buffer); + return { + Type, + Key, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RectReader extends RectangleReader { + static isTypeOf(type) { + if (super.isTypeOf(type)) return true; + + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["Rect"]; + } + + static type() { + return "Reflective"; + } + + isValueType() { + return false; + } + +} + +class RectGroupReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RectGroup", "List", "Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Rects = resolver.read(buffer); + return { + Rects + }; + } + + write(buffer, content, resolver) { + const rectListReader = new ListReader(new RectReader()); + this.writeIndex(buffer, resolver); + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } + +} + +class HomeRenovationReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["HomeRenovation", "String", "String", null, "List", ...RenovationValueReader.parseTypeList(), "List", ...RenovationValueReader.parseTypeList(), "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const TextStrings = resolver.read(buffer); + const AnimationType = resolver.read(buffer); + const CheckForObstructions = booleanReader.read(buffer); + const Requirements = resolver.read(buffer); + const RenovateActions = resolver.read(buffer); + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); + const SpecialRect = nullableStringReader.read(buffer, resolver); + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + const renovationValueListReader = new ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleData", "String", null, "String", "String", "String", null, null, "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleSetDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleSetData", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + return { + Bundles + }; + } + + write(buffer, content, resolver) { + const bundleListReader = new ListReader(new BundleDataReader()); + this.writeIndex(buffer, resolver); + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomBundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomBundleData", "String", "String", "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(), "Nullable>:11", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementItemReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElementItem", "Nullable", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + return { + RequiredTags, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElement", "String", "List", ...RandomizedElementItemReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Name = resolver.read(buffer); + const Values = resolver.read(buffer); + return { + Name, + Values + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const itemListReader = new ListReader(new RandomizedElementItemReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderObjectiveDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderObjectiveData", "String", "String", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderRewardDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderRewardData", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderData", "String", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), "List", ...SpecialOrderRewardDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); + return { + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const objectiveListReader = new ListReader(new SpecialOrderObjectiveDataReader()); + const rewardListReader = new ListReader(new SpecialOrderRewardDataReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver); + } + + isValueType() { + return false; + } + +} + +class ModFarmTypeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModFarmType", "String", "String", "String", "Nullable:1", "String", "Nullable:1", "String", "Nullable>:4", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } + +} + +class ModLanguageReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModLanguage", "String", "String", "String", null, "Nullable:1", "String", null, null, null, null, "Nullable:1", "String", "String", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } + +} + +class ModWallpaperOrFlooringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModWallpaperOrFlooring", "String", "String", null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } + +} + +export { BundleDataReader, BundleSetDataReader, CharacterResponseReader, ConcessionItemDataReader, ConcessionTasteReader, FishPondDataReader, FishPondRewardReader, HomeRenovationReader, ModFarmTypeReader, ModLanguageReader, ModWallpaperOrFlooringReader, MovieCharacterReactionReader, MovieDataReader, MovieReactionReader, MovieSceneReader, RandomBundleDataReader, RandomizedElementItemReader, RandomizedElementReader, RectGroupReader, RectReader, RenovationValueReader, SpecialOrderDataReader, SpecialOrderObjectiveDataReader, SpecialOrderRewardDataReader, SpecialResponsesReader, TailorItemRecipeReader }; diff --git a/dist/readers/readers.es5.min.js b/dist/readers/readers.es5.min.js deleted file mode 100644 index 57e0287..0000000 --- a/dist/readers/readers.es5.min.js +++ /dev/null @@ -1,23 +0,0 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,n=function(t){try{return!!t()}catch(t){return!0}},i=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=function(t){return t&&t.Math==Math&&t},o=u("object"==typeof globalThis&&globalThis)||u("object"==typeof window&&window)||u("object"==typeof self&&self)||u("object"==typeof e&&e)||function(){return this}()||Function("return this")(),a=function(t){return"function"==typeof t},s=a,c=function(t){return"object"==typeof t?null!==t:s(t)},l=!n((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),f=l,h=Function.prototype,v=h.bind,y=h.call,p=f&&v.bind(y,y),d=f?function(t){return t&&p(t)}:function(t){return t&&function(){return y.apply(t,arguments)}},w=o.TypeError,m=function(t){if(null==t)throw w("Can't call method on "+t);return t},g=o.Object,k=function(t){return g(m(t))},b=k,_=d({}.hasOwnProperty),x=Object.hasOwn||function(t,e){return _(b(t),e)},S={exports:{}},T=o,O=Object.defineProperty,A=function(t,e){try{O(T,t,{value:e,configurable:!0,writable:!0})}catch(r){T[t]=e}return e},M=A,R="__core-js_shared__",z=o[R]||M(R,{}),V=z;(S.exports=function(t,e){return V[t]||(V[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var j,I,E=d,C=0,P=Math.random(),F=E(1..toString),D=function(t){return"Symbol("+(void 0===t?"":t)+")_"+F(++C+P,36)},B=o,U=a,X=function(t){return U(t)?t:void 0},L=function(t,e){return arguments.length<2?X(B[t]):B[t]&&B[t][e]},W=o,N=L("navigator","userAgent")||"",G=W.process,Y=W.Deno,q=G&&G.versions||Y&&Y.version,K=q&&q.v8;K&&(I=(j=K.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=o,tt=S.exports,et=x,rt=D,nt=$,it=H,ut=tt("wks"),ot=Q.Symbol,at=ot&&ot.for,st=it?ot:ot&&ot.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(ot,t)?ut[t]=ot[t]:ut[t]=it&&at?at(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,vt=ht({}.toString),yt=ht("".slice),pt=function(t){return yt(vt(t),8,-1)},dt=o,wt=ft,mt=a,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},St=o.String,Tt=function(t){try{return St(t)}catch(t){return"Object"}},Ot={},At=c,Mt=o.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=o,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Dt=l,Bt=Function.prototype.call,Ut=Dt?Bt.bind(Bt):function(){return Bt.apply(Bt,arguments)},Xt=d({}.isPrototypeOf),Lt=L,Wt=a,Nt=Xt,Gt=H,Yt=o.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Lt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=a,Jt=Tt,Zt=o.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=a,ee=c,re=o.TypeError,ne=Ut,ie=c,ue=qt,oe=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},ae=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=o.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=oe(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),ae(t,e)},he=qt,ve=i,ye=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=o.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ve?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ye)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Se=Ot,Te=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Se.f(t,e,Te(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=a,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,De,Be,Ue=Ce.inspectSource,Xe=a,Le=Ue,We=o.WeakMap,Ne=Xe(We)&&/native code/.test(Le(We)),Ge=S.exports,Ye=D,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=o,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,or=Ze.WeakMap;if(Je||er.state){var ar=er.state||(er.state=new or),sr=$e(ar.get),cr=$e(ar.has),lr=$e(ar.set);Fe=function(t,e){if(cr(ar,t))throw new ur(ir);return e.facade=t,lr(ar,t,e),e},De=function(t){return sr(ar,t)||{}},Be=function(t){return cr(ar,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},De=function(t){return tr(t,fr)?t[fr]:{}},Be=function(t){return tr(t,fr)}}var hr={set:Fe,get:De,has:Be,enforce:function(t){return Be(t)?De(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=De(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},vr=n,yr=a,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!vr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return yr(this)&&kr(this).source||mr(this)}),"toString");var Sr,Tr,Or,Ar=o,Mr=a,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=o,Er=x,Cr=a,Pr=k,Fr=jr,Dr=Ke("IE_PROTO"),Br=Ir.Object,Ur=Br.prototype,Xr=Fr?Br.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Dr))return e[Dr];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Br?Ur:null},Lr=o,Wr=a,Nr=Lr.String,Gr=Lr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=o,Qr=a,tn=c,en=x,rn=xt,nn=Tt,un=Oe,on=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,a=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,a,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!o&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},an=Ot.f,sn=Xt,cn=Xr,ln=Jr,fn=ct,hn=D,vn=Hr.Int8Array,yn=vn&&vn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=vn&&cn(vn),mn=yn&&cn(yn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Sn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Tn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Sr in On)(Or=(Tr=Hr[Sr])&&Tr.prototype)?un(Or,xn,Tr):Sn=!1;for(Sr in An)(Or=(Tr=Hr[Sr])&&Tr.prototype)&&un(Or,xn,Tr);if((!Sn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr],wn);if((!Sn||!mn||mn===gn)&&(mn=wn.prototype,Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr].prototype,mn);if(Sn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Sr in Tn=!0,an(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Sr]&&un(Hr[Sr],_n,Sr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Sn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Tn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||on(mn,t,r?e:Sn&&yn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return on(wn,t,r?e:Sn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||on(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=o.Object,Fn=In("".split),Dn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Bn=Math.ceil,Un=Math.floor,Xn=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Bn)(e)},Ln=Math.min,Wn=function(t){return t>0?Ln(Xn(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=a,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=L("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,oi=o,ai=Gn,si=ui,ci=c,li=ct("species"),fi=oi.Array,hi=function(t){var e;return ai(t)&&(e=t.constructor,(si(e)&&(e===fi||ai(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},vi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},yi=Dn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,o=7==t,a=5==t||u;return function(s,c,l,f){for(var h,v,y=pi(s),p=yi(y),d=vi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||o?g(s,0):void 0;w>m;m++)if((a||m in p)&&(v=d(h=p[m],m,y),t))if(e)k[m]=v;else if(v)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=Tt,xi=o.TypeError,Si=Ft,Ti=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Si(t).constructor;return void 0===n||null==(r=Si(n)[Oi])?e:Ti(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Di=Ci(Fi.toString),Bi=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Bi.exec);function Xi(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Li(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),ru=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(eu),nu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return(new fu).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}},{key:"write",value:function(t,e,r){new fu,t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.isValueType()?this.reader.read(t):e.read(t)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),o=0;o=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Su(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Tu(t)}for(var v=0;v0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,o=Du(t),a=Du(e);if(o<=a)u=r.slice();else{var s=[a,o];o=s[0],a=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Bu(o,a,u,n,i)}function Xu(t,e,r,n,i){var u,o=Du(t),a=Du(e);if(o=128||!i)){var h=this._remap[a],v=(e[4*o+3]+1)/256;this._weights[h]+=u?v:1,this._remap[o]=h;break}}else this._remap[o]=-1}for(var y=0;y=n?t:(n=o,u)}),0);return i+=n,u}));if(ia&&(u=r[c],a=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,o=i.weights;return n.principle=ju(u,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),o=u.splatW,a=Vu.multiplyAdd(r,i,n);return{ax:u,aa:o,bx:a,bb:a.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),o=new Vu(2/3,2/3,2/3,4/9),a=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,o,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,o,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(a,Vu.add(r,n)).splatW}}),(function(r,n,i){return Xu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),o=r.computeOptimalPoints(u);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),o=0;o15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*l&255;n[o]=f,o++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function to(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),o=Hu(i);return[u,o,Qu(u,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,o,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),o=0;o<16;o++)for(var a=0;a<4;a++)t[4*o+a]=i[u[o]][a]}function eo(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ro(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function no(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,o=void 0===u?0:u,a=r.width,s=void 0===a?0:a,c=r.height,l=void 0===c?0:c,f=0;eo((function(r,n){var u=i+r,a=o+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),o=new Uint8Array(16),a=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var v=l>>3*h&7;o[a]=v,a++}}for(var y=0;y<16;++y)t[4*y+3]=u[o[y]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function oo(t,e,r,n,i){var u=0!=(1&(i=ro(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,o=e.width,a=void 0===o?0:o,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return eo((function(e,r){var i=n+e,o=u+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(4==n)s=fo(s,i,u,ao);else if(5==n)s=fo(s,i,u,so);else if(6==n)s=fo(s,i,u,co);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),po=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),wo=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),o=r.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){return(new o).read(t)?this.reader.isValueType()?this.reader.read(t):e.read(t):null}write(t,e,r){t.writeByte(null!=e),null!=e&&this.reader.write(t,e,this.reader.isValueType()?null:r)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class w extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const f=256;//! Use DXT1 compression. -//! Weight the colour by alpha during cluster fit (disabled by default). -function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function T(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...T(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function X(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class B{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class D{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class U extends D{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>X(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>X(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class P extends D{constructor(t){super(t);this.iterationCount=t.flags&f?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>X(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=f&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new w,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new w,a=new h(n),o=new ot,f=new c(new d),p=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),f.write(t,e.glyphs,r),f.write(t,e.cropping,r),p.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/readers/readers.cjs b/dist/readers/xnb-readers.cjs similarity index 98% rename from dist/readers/readers.cjs rename to dist/readers/xnb-readers.cjs index 3b2428a..ab6d541 100644 --- a/dist/readers/readers.cjs +++ b/dist/readers/xnb-readers.cjs @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -12,8 +21,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -44,6 +52,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -118,6 +130,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -335,6 +351,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -465,10 +485,18 @@ class ListReader extends BaseReader { } } + isValueType() { + return false; + } + get type() { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -491,15 +519,35 @@ class NullableReader extends BaseReader { this.reader = reader; } - read(buffer, resolver) { + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content === null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } isValueType() { @@ -510,6 +558,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -533,12 +586,11 @@ class ReflectiveReader extends BaseReader { } read(buffer, resolver) { - const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + const reflective = this.reader.read(buffer, resolver); return reflective; } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -550,6 +602,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2491,8 +2547,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/dist/readers/readers.es5.js b/dist/readers/xnb-readers.es5.js similarity index 97% rename from dist/readers/readers.es5.js rename to dist/readers/xnb-readers.es5.js index a6cf2e6..31ff9ad 100644 --- a/dist/readers/readers.es5.js +++ b/dist/readers/xnb-readers.es5.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -1485,6 +1494,11 @@ value: function toString() { return this.type; } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return this.constructor.parseTypeList(); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -1498,8 +1512,7 @@ }, { key: "parseTypeList", value: function parseTypeList() { - var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type()].concat(subtype); + return [this.type()]; } }, { key: "type", @@ -1600,6 +1613,11 @@ get: function get() { return "Array<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -1940,6 +1958,11 @@ get: function get() { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.key.parseTypeList(), this.value.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2138,11 +2161,21 @@ this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); } } + }, { + key: "isValueType", + value: function isValueType() { + return false; + } }, { key: "type", get: function get() { return "List<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2182,17 +2215,37 @@ _createClass(NullableReader, [{ key: "read", - value: function read(buffer, resolver) { + value: function read(buffer) { + var resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var booleanReader = new BooleanReader(); - var hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + var hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } }, { key: "write", - value: function write(buffer, content, resolver) { + value: function write(buffer) { + var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; new BooleanReader(); - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + + if (content === null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } }, { key: "isValueType", @@ -2204,6 +2257,12 @@ get: function get() { return "Nullable<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length)].concat(inBlock); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2243,13 +2302,12 @@ _createClass(ReflectiveReader, [{ key: "read", value: function read(buffer, resolver) { - var reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + var reflective = this.reader.read(buffer, resolver); return reflective; } }, { key: "write", value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } }, { @@ -2262,6 +2320,11 @@ get: function get() { return "".concat(this.reader.type); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -4027,6 +4090,27 @@ } } + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ var DXT1_COMPRESSED_BYTES = 8; var DXT5_COMPRESSED_BYTES = 16; var COLORS = 4; @@ -4417,8 +4501,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } }, { key: "isValueType", diff --git a/dist/readers/xnb-readers.es5.min.js b/dist/readers/xnb-readers.es5.min.js new file mode 100644 index 0000000..2e7c348 --- /dev/null +++ b/dist/readers/xnb-readers.es5.min.js @@ -0,0 +1,31 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * -------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,n=function(t){try{return!!t()}catch(t){return!0}},i=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=function(t){return t&&t.Math==Math&&t},a=u("object"==typeof globalThis&&globalThis)||u("object"==typeof window&&window)||u("object"==typeof self&&self)||u("object"==typeof e&&e)||function(){return this}()||Function("return this")(),o=function(t){return"function"==typeof t},s=o,c=function(t){return"object"==typeof t?null!==t:s(t)},l=!n((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),f=l,h=Function.prototype,y=h.bind,v=h.call,p=f&&y.bind(v,v),d=f?function(t){return t&&p(t)}:function(t){return t&&function(){return v.apply(t,arguments)}},w=a.TypeError,m=function(t){if(null==t)throw w("Can't call method on "+t);return t},g=a.Object,k=function(t){return g(m(t))},b=k,_=d({}.hasOwnProperty),x=Object.hasOwn||function(t,e){return _(b(t),e)},T={exports:{}},S=a,O=Object.defineProperty,A=function(t,e){try{O(S,t,{value:e,configurable:!0,writable:!0})}catch(r){S[t]=e}return e},M=A,R="__core-js_shared__",z=a[R]||M(R,{}),V=z;(T.exports=function(t,e){return V[t]||(V[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var j,I,E=d,C=0,P=Math.random(),F=E(1..toString),B=function(t){return"Symbol("+(void 0===t?"":t)+")_"+F(++C+P,36)},D=a,U=o,L=function(t){return U(t)?t:void 0},X=function(t,e){return arguments.length<2?L(D[t]):D[t]&&D[t][e]},W=a,N=X("navigator","userAgent")||"",G=W.process,Y=W.Deno,q=G&&G.versions||Y&&Y.version,K=q&&q.v8;K&&(I=(j=K.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=a,tt=T.exports,et=x,rt=B,nt=$,it=H,ut=tt("wks"),at=Q.Symbol,ot=at&&at.for,st=it?at:at&&at.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(at,t)?ut[t]=at[t]:ut[t]=it&&ot?ot(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,yt=ht({}.toString),vt=ht("".slice),pt=function(t){return vt(yt(t),8,-1)},dt=a,wt=ft,mt=o,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},Tt=a.String,St=function(t){try{return Tt(t)}catch(t){return"Object"}},Ot={},At=c,Mt=a.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=a,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Bt=l,Dt=Function.prototype.call,Ut=Bt?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},Lt=d({}.isPrototypeOf),Xt=X,Wt=o,Nt=Lt,Gt=H,Yt=a.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Xt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=o,Jt=St,Zt=a.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=o,ee=c,re=a.TypeError,ne=Ut,ie=c,ue=qt,ae=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},oe=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=a.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=ae(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),oe(t,e)},he=qt,ye=i,ve=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=a.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ye?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ve)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Te=Ot,Se=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Te.f(t,e,Se(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=o,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,Be,De,Ue=Ce.inspectSource,Le=o,Xe=Ue,We=a.WeakMap,Ne=Le(We)&&/native code/.test(Xe(We)),Ge=T.exports,Ye=B,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=a,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,ar=Ze.WeakMap;if(Je||er.state){var or=er.state||(er.state=new ar),sr=$e(or.get),cr=$e(or.has),lr=$e(or.set);Fe=function(t,e){if(cr(or,t))throw new ur(ir);return e.facade=t,lr(or,t,e),e},Be=function(t){return sr(or,t)||{}},De=function(t){return cr(or,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},Be=function(t){return tr(t,fr)?t[fr]:{}},De=function(t){return tr(t,fr)}}var hr={set:Fe,get:Be,has:De,enforce:function(t){return De(t)?Be(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=Be(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},yr=n,vr=o,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!yr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return vr(this)&&kr(this).source||mr(this)}),"toString");var Tr,Sr,Or,Ar=a,Mr=o,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=a,Er=x,Cr=o,Pr=k,Fr=jr,Br=Ke("IE_PROTO"),Dr=Ir.Object,Ur=Dr.prototype,Lr=Fr?Dr.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Br))return e[Br];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Dr?Ur:null},Xr=a,Wr=o,Nr=Xr.String,Gr=Xr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=a,Qr=o,tn=c,en=x,rn=xt,nn=St,un=Oe,an=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,a=!!n&&!!n.noTargetGet,o=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,o,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!a&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},on=Ot.f,sn=Lt,cn=Lr,ln=Jr,fn=ct,hn=B,yn=Hr.Int8Array,vn=yn&&yn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=yn&&cn(yn),mn=vn&&cn(vn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Tn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Sn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Tr in On)(Or=(Sr=Hr[Tr])&&Sr.prototype)?un(Or,xn,Sr):Tn=!1;for(Tr in An)(Or=(Sr=Hr[Tr])&&Sr.prototype)&&un(Or,xn,Sr);if((!Tn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Tn))for(Tr in On)Hr[Tr]&&ln(Hr[Tr],wn);if((!Tn||!mn||mn===gn)&&(mn=wn.prototype,Tn))for(Tr in On)Hr[Tr]&&ln(Hr[Tr].prototype,mn);if(Tn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Tr in Sn=!0,on(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Tr]&&un(Hr[Tr],_n,Tr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Tn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Sn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||an(mn,t,r?e:Tn&&vn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return an(wn,t,r?e:Tn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||an(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=a.Object,Fn=In("".split),Bn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Dn=Math.ceil,Un=Math.floor,Ln=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Dn)(e)},Xn=Math.min,Wn=function(t){return t>0?Xn(Ln(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=o,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=X("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,ai=a,oi=Gn,si=ui,ci=c,li=ct("species"),fi=ai.Array,hi=function(t){var e;return oi(t)&&(e=t.constructor,(si(e)&&(e===fi||oi(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},yi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},vi=Bn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,a=7==t,o=5==t||u;return function(s,c,l,f){for(var h,y,v=pi(s),p=vi(v),d=yi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||a?g(s,0):void 0;w>m;m++)if((o||m in p)&&(y=d(h=p[m],m,v),t))if(e)k[m]=y;else if(y)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=St,xi=a.TypeError,Ti=Ft,Si=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Ti(t).constructor;return void 0===n||null==(r=Ti(n)[Oi])?e:Si(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Bi=Ci(Fi.toString),Di=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Di.exec);function Li(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Xi(t){for(var e=1;e")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.key.parseTypeList(),this.value.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new fu,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new fu,null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}},{key:"parseTypeList",value:function(){var t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length)].concat(t)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}},{key:"parseTypeList",value:function(){return[].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),a=0;a=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Tu(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Su(t)}for(var y=0;y0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,a=Bu(t),o=Bu(e);if(a<=o)u=r.slice();else{var s=[o,a];a=s[0],o=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Du(a,o,u,n,i)}function Lu(t,e,r,n,i){var u,a=Bu(t),o=Bu(e);if(a=128||!i)){var h=this._remap[o],y=(e[4*a+3]+1)/256;this._weights[h]+=u?y:1,this._remap[a]=h;break}}else this._remap[a]=-1}for(var v=0;v=n?t:(n=a,u)}),0);return i+=n,u}));if(io&&(u=r[c],o=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,a=i.weights;return n.principle=ju(u,a),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),a=u.splatW,o=Vu.multiplyAdd(r,i,n);return{ax:u,aa:a,bx:o,bb:o.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),a=new Vu(2/3,2/3,2/3,4/9),o=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,a,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,a,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(o,Vu.add(r,n)).splatW}}),(function(r,n,i){return Lu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),a=r.computeOptimalPoints(u);return a.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),a=0;a15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=a)):(ai&&(i=a))}}n>i&&(n=i);i-n>8*l&255;n[a]=f,a++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function ta(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),a=Hu(i);return[u,a,Qu(u,a,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,a,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),a=0;a<16;a++)for(var o=0;o<4;o++)t[4*a+o]=i[u[a]][o]}function ea(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ra(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function na(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,a=void 0===u?0:u,o=r.width,s=void 0===o?0:o,c=r.height,l=void 0===c?0:c,f=0;ea((function(r,n){var u=i+r,o=a+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),a=new Uint8Array(16),o=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var y=l>>3*h&7;a[o]=y,o++}}for(var v=0;v<16;++v)t[4*v+3]=u[a[v]]}(t,e,r)}function aa(t,e,r,n,i){var u=0!=(1&(i=ra(i)))?8:16,a=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,a=e.width,o=void 0===a?0:a,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return ea((function(e,r){var i=n+e,a=u+r;if(i1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));var o=r.read(t),s=t.read(o);if(4==n)s=fa(s,i,u,oa);else if(5==n)s=fa(s,i,u,sa);else if(6==n)s=fa(s,i,u,ca);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),pa=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),da=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),a=r.read(t);a>1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));var o=r.read(t),s=t.read(o);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -46,6 +54,10 @@ return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -120,6 +132,10 @@ return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -337,6 +353,10 @@ return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -467,10 +487,18 @@ } } + isValueType() { + return false; + } + get type() { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -493,15 +521,35 @@ this.reader = reader; } - read(buffer, resolver) { + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content === null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } isValueType() { @@ -512,6 +560,11 @@ return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -535,12 +588,11 @@ } read(buffer, resolver) { - const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + const reflective = this.reader.read(buffer, resolver); return reflective; } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -552,6 +604,10 @@ return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2493,8 +2549,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/dist/readers/xnb-readers.min.js b/dist/readers/xnb-readers.min.js new file mode 100644 index 0000000..04f1807 --- /dev/null +++ b/dist/readers/xnb-readers.min.js @@ -0,0 +1,31 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * -------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";class e{static isTypeOf(t){return!1}static hasSubType(){return!1}static parseTypeList(){return[this.type()]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}parseTypeList(){return this.constructor.parseTypeList()}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new o;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}parseTypeList(){const t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length),...t]}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class p extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const w=256;function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function M(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...M(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function B(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class L{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class X{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class D extends X{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class j extends X{constructor(t){super(t);this.iterationCount=t.flags&w?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>B(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=w&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]}(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}parseTypeList(){return[this.type,...this.key.parseTypeList(),...this.value.parseTypeList()]}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new p,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new p,a=new h(n),o=new ot,w=new c(new d),f=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),w.write(t,e.glyphs,r),w.write(t,e.cropping,r),f.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new p;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new p;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/readers/readers.module.js b/dist/readers/xnb-readers.module.js similarity index 98% rename from dist/readers/readers.module.js rename to dist/readers/xnb-readers.module.js index 9f3e7b1..070d6bd 100644 --- a/dist/readers/readers.module.js +++ b/dist/readers/xnb-readers.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + class BaseReader { static isTypeOf(type) { return false; @@ -8,8 +17,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -40,6 +48,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -114,6 +126,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -331,6 +347,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -461,10 +481,18 @@ class ListReader extends BaseReader { } } + isValueType() { + return false; + } + get type() { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -487,15 +515,35 @@ class NullableReader extends BaseReader { this.reader = reader; } - read(buffer, resolver) { + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content === null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } isValueType() { @@ -506,6 +554,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -529,12 +582,11 @@ class ReflectiveReader extends BaseReader { } read(buffer, resolver) { - const reflective = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + const reflective = this.reader.read(buffer, resolver); return reflective; } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -546,6 +598,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2487,8 +2543,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/dist/xnb.cjs b/dist/xnb.cjs index beadf3f..4cde76b 100644 --- a/dist/xnb.cjs +++ b/dist/xnb.cjs @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -71,6 +80,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -112,13 +137,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -133,12 +155,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1537,7 +1555,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4684,6 +4704,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4732,17 +4753,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4829,6 +4869,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } @@ -5352,8 +5397,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -5384,6 +5428,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -5458,6 +5506,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -5675,6 +5727,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -5813,6 +5869,10 @@ class ListReader extends BaseReader { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -5850,14 +5910,14 @@ class NullableReader extends BaseReader { return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -5874,6 +5934,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -5902,7 +5967,6 @@ class ReflectiveReader extends BaseReader { } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -5914,6 +5978,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -7814,8 +7882,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/dist/xnb.es5.js b/dist/xnb.es5.js index f279887..52846a0 100644 --- a/dist/xnb.es5.js +++ b/dist/xnb.es5.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -3641,6 +3650,22 @@ return _createClass(XnbError); }(_wrapNativeSuper(Error)); + function removeExternBracket(str) { + var bracketStack = []; + var result = []; + + for (var i = 0; i < str.length; i++) { + var c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + var startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + var TypeReader = function () { function TypeReader() { _classCallCheck(this, TypeReader); @@ -3705,13 +3730,10 @@ }, { key: "parseSubtypes", value: function parseSubtypes(type) { - var subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - var matches = subtype.match(pattern).map(function (e) { - return e.slice(1, -1); - }); + var subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + var matches = removeExternBracket(subtype); return matches; } }, { @@ -3730,19 +3752,15 @@ }, { key: "getReaderTypeList", value: function getReaderTypeList(typeString) { - var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn.type, - subtypes = _TypeReader$getTypeIn.subtypes; - - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + var reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } }, { key: "getReader", value: function getReader(typeString) { - var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn2.type, - subtypes = _TypeReader$getTypeIn2.subtypes; + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); @@ -5252,8 +5270,8 @@ }, { key: "getIndex", value: function getIndex(reader) { - for (var i in this.readers) { - if (reader.toString() == this.readers[i].toString()) return i; + for (var i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; } } }]); @@ -8749,6 +8767,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -8795,17 +8814,41 @@ } if (__startsWithString(reader, 'Nullable')) { + var nullableData, trav; + + var _reader$split = reader.split(":"), + readerType = _reader$split[0], + _reader$split$ = _reader$split[1], + blockTraversed = _reader$split$ === void 0 ? 1 : _reader$split$; + + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (_typeof(obj) === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + var _recursiveConvert2 = recursiveConvert(obj, [].concat(path), index + 1), + _converted = _recursiveConvert2.converted, + _traversed = _recursiveConvert2.traversed; + + nullableData = _converted; + trav = _traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -8854,11 +8897,11 @@ var newIndex = void 0; if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; - var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), - _converted = _recursiveConvert2.converted, - nexter = _recursiveConvert2.traversed; + var _recursiveConvert3 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted2 = _recursiveConvert3.converted, + nexter = _recursiveConvert3.traversed; - data[key] = _converted; + data[key] = _converted2; if (isComplex) traversed = nexter;else if (first) { traversed = nexter; first = false; @@ -8897,6 +8940,11 @@ return data; } + if (__startsWithString(type, "Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } @@ -9654,6 +9702,11 @@ value: function toString() { return this.type; } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return this.constructor.parseTypeList(); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -9667,8 +9720,7 @@ }, { key: "parseTypeList", value: function parseTypeList() { - var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type()].concat(subtype); + return [this.type()]; } }, { key: "type", @@ -9769,6 +9821,11 @@ get: function get() { return "Array<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -10075,6 +10132,11 @@ get: function get() { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.key.parseTypeList(), this.value.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -10283,6 +10345,11 @@ get: function get() { return "List<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -10337,7 +10404,7 @@ return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } }, { key: "write", @@ -10346,7 +10413,7 @@ var resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; new BooleanReader(); - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -10364,6 +10431,12 @@ get: function get() { return "Nullable<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length)].concat(inBlock); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -10409,7 +10482,6 @@ }, { key: "write", value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } }, { @@ -10422,6 +10494,11 @@ get: function get() { return "".concat(this.reader.type); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -12187,6 +12264,27 @@ } } + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ var DXT1_COMPRESSED_BYTES = 8; var DXT5_COMPRESSED_BYTES = 16; var COLORS = 4; @@ -12577,8 +12675,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } }, { key: "isValueType", diff --git a/dist/xnb.es5.min.js b/dist/xnb.es5.min.js index 4afba2f..b91c407 100644 --- a/dist/xnb.es5.min.js +++ b/dist/xnb.es5.min.js @@ -1,23 +1,70 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=function(t){return t&&t.Math==Math&&t},n=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,c=u?h.bind(h):function(){return h.apply(h,arguments)},f={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,v=d&&!l.call({1:2},1);f.f=v?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var p,y,w=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},_=s,g=Function.prototype,b=g.bind,m=g.call,k=_&&b.bind(m,m),x=_?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,R=E({}.toString),A=E("".slice),O=function(t){return A(R(t),8,-1)},T=x,S=a,U=O,I=n.Object,B=T("".split),z=S((function(){return!I("z").propertyIsEnumerable(0)}))?function(t){return"String"==U(t)?B(t,""):I(t)}:I,L=n.TypeError,P=function(t){if(null==t)throw L("Can't call method on "+t);return t},N=z,C=P,D=function(t){return N(C(t))},j=function(t){return"function"==typeof t},M=j,F=function(t){return"object"==typeof t?null!==t:M(t)},V=n,Z=j,X=function(t){return Z(t)?t:void 0},W=function(t,e){return arguments.length<2?X(V[t]):V[t]&&V[t][e]},H=x({}.isPrototypeOf),G=W("navigator","userAgent")||"",Y=n,K=G,J=Y.process,q=Y.Deno,$=J&&J.versions||q&&q.version,Q=$&&$.v8;Q&&(y=(p=Q.split("."))[0]>0&&p[0]<4?1:+(p[0]+p[1])),!y&&K&&(!(p=K.match(/Edge\/(\d+)/))||p[1]>=74)&&(p=K.match(/Chrome\/(\d+)/))&&(y=+p[1]);var tt=y,et=tt,rt=a,nt=!!Object.getOwnPropertySymbols&&!rt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=nt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=W,ot=j,st=H,ut=it,ht=n.Object,ct=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ft=n.String,lt=function(t){try{return ft(t)}catch(t){return"Object"}},dt=j,vt=lt,pt=n.TypeError,yt=function(t){if(dt(t))return t;throw pt(vt(t)+" is not a function")},wt=yt,_t=function(t,e){var r=t[e];return null==r?void 0:wt(r)},gt=c,bt=j,mt=F,kt=n.TypeError,xt={exports:{}},Et=n,Rt=Object.defineProperty,At=function(t,e){try{Rt(Et,t,{value:e,configurable:!0,writable:!0})}catch(r){Et[t]=e}return e},Ot=At,Tt="__core-js_shared__",St=n[Tt]||Ot(Tt,{}),Ut=St;(xt.exports=function(t,e){return Ut[t]||(Ut[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var It=P,Bt=n.Object,zt=function(t){return Bt(It(t))},Lt=zt,Pt=x({}.hasOwnProperty),Nt=Object.hasOwn||function(t,e){return Pt(Lt(t),e)},Ct=x,Dt=0,jt=Math.random(),Mt=Ct(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Mt(++Dt+jt,36)},Vt=n,Zt=xt.exports,Xt=Nt,Wt=Ft,Ht=nt,Gt=it,Yt=Zt("wks"),Kt=Vt.Symbol,Jt=Kt&&Kt.for,qt=Gt?Kt:Kt&&Kt.withoutSetter||Wt,$t=function(t){if(!Xt(Yt,t)||!Ht&&"string"!=typeof Yt[t]){var e="Symbol."+t;Ht&&Xt(Kt,t)?Yt[t]=Kt[t]:Yt[t]=Gt&&Jt?Jt(e):qt(e)}return Yt[t]},Qt=c,te=F,ee=ct,re=_t,ne=function(t,e){var r,n;if("string"===e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;if(bt(r=t.valueOf)&&!mt(n=gt(r,t)))return n;if("string"!==e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;throw kt("Can't convert object to primitive value")},ie=$t,ae=n.TypeError,oe=ie("toPrimitive"),se=function(t,e){if(!te(t)||ee(t))return t;var r,n=re(t,oe);if(n){if(void 0===e&&(e="default"),r=Qt(n,t,e),!te(r)||ee(r))return r;throw ae("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},ue=ct,he=function(t){var e=se(t,"string");return ue(e)?e:e+""},ce=F,fe=n.document,le=ce(fe)&&ce(fe.createElement),de=function(t){return le?fe.createElement(t):{}},ve=de,pe=!o&&!a((function(){return 7!=Object.defineProperty(ve("div"),"a",{get:function(){return 7}}).a})),ye=o,we=c,_e=f,ge=w,be=D,me=he,ke=Nt,xe=pe,Ee=Object.getOwnPropertyDescriptor;i.f=ye?Ee:function(t,e){if(t=be(t),e=me(e),xe)try{return Ee(t,e)}catch(t){}if(ke(t,e))return ge(!we(_e.f,t,e),t[e])};var Re={},Ae=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Oe=n,Te=F,Se=Oe.String,Ue=Oe.TypeError,Ie=function(t){if(Te(t))return t;throw Ue(Se(t)+" is not an object")},Be=o,ze=pe,Le=Ae,Pe=Ie,Ne=he,Ce=n.TypeError,De=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Me="enumerable",Fe="configurable",Ve="writable";Re.f=Be?Le?function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),"function"==typeof t&&"prototype"===e&&"value"in r&&Ve in r&&!r.writable){var n=je(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:Fe in r?r.configurable:n.configurable,enumerable:Me in r?r.enumerable:n.enumerable,writable:!1})}return De(t,e,r)}:De:function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),ze)try{return De(t,e,r)}catch(t){}if("get"in r||"set"in r)throw Ce("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Ze=Re,Xe=w,We=o?function(t,e,r){return Ze.f(t,e,Xe(1,r))}:function(t,e,r){return t[e]=r,t},He={exports:{}},Ge=o,Ye=Nt,Ke=Function.prototype,Je=Ge&&Object.getOwnPropertyDescriptor,qe=Ye(Ke,"name"),$e={EXISTS:qe,PROPER:qe&&"something"===function(){}.name,CONFIGURABLE:qe&&(!Ge||Ge&&Je(Ke,"name").configurable)},Qe=j,tr=St,er=x(Function.toString);Qe(tr.inspectSource)||(tr.inspectSource=function(t){return er(t)});var rr,nr,ir,ar=tr.inspectSource,or=j,sr=ar,ur=n.WeakMap,hr=or(ur)&&/native code/.test(sr(ur)),cr=xt.exports,fr=Ft,lr=cr("keys"),dr=function(t){return lr[t]||(lr[t]=fr(t))},vr={},pr=hr,yr=n,wr=x,_r=F,gr=We,br=Nt,mr=St,kr=dr,xr=vr,Er="Object already initialized",Rr=yr.TypeError,Ar=yr.WeakMap;if(pr||mr.state){var Or=mr.state||(mr.state=new Ar),Tr=wr(Or.get),Sr=wr(Or.has),Ur=wr(Or.set);rr=function(t,e){if(Sr(Or,t))throw new Rr(Er);return e.facade=t,Ur(Or,t,e),e},nr=function(t){return Tr(Or,t)||{}},ir=function(t){return Sr(Or,t)}}else{var Ir=kr("state");xr[Ir]=!0,rr=function(t,e){if(br(t,Ir))throw new Rr(Er);return e.facade=t,gr(t,Ir,e),e},nr=function(t){return br(t,Ir)?t[Ir]:{}},ir=function(t){return br(t,Ir)}}var Br={set:rr,get:nr,has:ir,enforce:function(t){return ir(t)?nr(t):rr(t,{})},getterFor:function(t){return function(e){var r;if(!_r(e)||(r=nr(e)).type!==t)throw Rr("Incompatible receiver, "+t+" required");return r}}},zr=a,Lr=j,Pr=Nt,Nr=Re.f,Cr=$e.CONFIGURABLE,Dr=ar,jr=Br.enforce,Mr=Br.get,Fr=!zr((function(){return 8!==Nr((function(){}),"length",{value:8}).length})),Vr=String(String).split("String"),Zr=He.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!Pr(t,"name")||Cr&&t.name!==e)&&Nr(t,"name",{value:e,configurable:!0}),Fr&&r&&Pr(r,"arity")&&t.length!==r.arity&&Nr(t,"length",{value:r.arity});var n=jr(t);return Pr(n,"source")||(n.source=Vr.join("string"==typeof e?e:"")),t};Function.prototype.toString=Zr((function(){return Lr(this)&&Mr(this).source||Dr(this)}),"toString");var Xr=n,Wr=j,Hr=We,Gr=He.exports,Yr=At,Kr=function(t,e,r,n){var i=!!n&&!!n.unsafe,a=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,s=n&&void 0!==n.name?n.name:e;return Wr(r)&&Gr(r,s,n),t===Xr?(a?t[e]=r:Yr(e,r),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=r:Hr(t,e,r),t)},Jr={},qr=Math.ceil,$r=Math.floor,Qr=function(t){var e=+t;return e!=e||0===e?0:(e>0?$r:qr)(e)},tn=Qr,en=Math.max,rn=Math.min,nn=Qr,an=Math.min,on=function(t){return t>0?an(nn(t),9007199254740991):0},sn=function(t){return on(t.length)},un=D,hn=function(t,e){var r=tn(t);return r<0?en(r+e,0):rn(r,e)},cn=sn,fn=function(t){return function(e,r,n){var i,a=un(e),o=cn(a),s=hn(n,o);if(t&&r!=r){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===r)return t||s||0;return!t&&-1}},ln={includes:fn(!0),indexOf:fn(!1)},dn=Nt,vn=D,pn=ln.indexOf,yn=vr,wn=x([].push),_n=function(t,e){var r,n=vn(t),i=0,a=[];for(r in n)!dn(yn,r)&&dn(n,r)&&wn(a,r);for(;e.length>i;)dn(n,r=e[i++])&&(~pn(a,r)||wn(a,r));return a},gn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Jr.f=Object.getOwnPropertyNames||function(t){return _n(t,gn)};var bn={};bn.f=Object.getOwnPropertySymbols;var mn=W,kn=Jr,xn=bn,En=Ie,Rn=x([].concat),An=mn("Reflect","ownKeys")||function(t){var e=kn.f(En(t)),r=xn.f;return r?Rn(e,r(t)):e},On=Nt,Tn=An,Sn=i,Un=Re,In=a,Bn=j,zn=/#|\.prototype\./,Ln=function(t,e){var r=Nn[Pn(t)];return r==Dn||r!=Cn&&(Bn(e)?In(e):!!e)},Pn=Ln.normalize=function(t){return String(t).replace(zn,".").toLowerCase()},Nn=Ln.data={},Cn=Ln.NATIVE="N",Dn=Ln.POLYFILL="P",jn=Ln,Mn=n,Fn=i.f,Vn=We,Zn=Kr,Xn=At,Wn=function(t,e,r){for(var n=Tn(e),i=Un.f,a=Sn.f,o=0;o=51&&/native code/.test(t))return!1;var r=new fo((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};return(r.constructor={})[go]=n,!(bo=r.then((function(){}))instanceof n)||!e&&wo&&!mo})),xo={CONSTRUCTOR:ko,REJECTION_EVENT:mo,SUBCLASSING:bo},Eo={},Ro=yt,Ao=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError("Bad Promise constructor");e=t,r=n})),this.resolve=Ro(e),this.reject=Ro(r)};Eo.f=function(t){return new Ao(t)};var Oo,To,So,Uo=Gn,Io=Yn,Bo=n,zo=c,Lo=Kr,Po=ri,No=function(t,e,r){t&&!r&&(t=t.prototype),t&&!ii(t,ai)&&ni(t,ai,{configurable:!0,value:e})},Co=function(t){var e=oi(t),r=si.f;ui&&e&&!e[hi]&&r(e,hi,{configurable:!0,get:function(){return this}})},Do=yt,jo=j,Mo=F,Fo=function(t,e){if(ci(e,t))return t;throw fi("Incorrect invocation")},Vo=Wi,Zo=ja.set,Xo=no,Wo=function(t,e){var r=io.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ho=ao,Go=so,Yo=Br,Ko=uo,Jo=Eo,qo="Promise",$o=xo.CONSTRUCTOR,Qo=xo.REJECTION_EVENT,ts=xo.SUBCLASSING,es=Yo.getterFor(qo),rs=Yo.set,ns=Ko&&Ko.prototype,is=Ko,as=ns,os=Bo.TypeError,ss=Bo.document,us=Bo.process,hs=Jo.f,cs=hs,fs=!!(ss&&ss.createEvent&&Bo.dispatchEvent),ls="unhandledrejection",ds=function(t){var e;return!(!Mo(t)||!jo(e=t.then))&&e},vs=function(t,e){var r,n,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,c=t.domain;try{s?(o||(2===e.rejection&&gs(e),e.rejection=1),!0===s?r=a:(c&&c.enter(),r=s(a),c&&(c.exit(),i=!0)),r===t.promise?h(os("Promise-chain cycle")):(n=ds(r))?zo(n,r,u,h):u(r)):h(a)}catch(t){c&&!i&&c.exit(),h(t)}},ps=function(t,e){t.notified||(t.notified=!0,Xo((function(){for(var r,n=t.reactions;r=n.get();)vs(r,t);t.notified=!1,e&&!t.rejection&&ws(t)})))},ys=function(t,e,r){var n,i;fs?((n=ss.createEvent("Event")).promise=e,n.reason=r,n.initEvent(t,!1,!0),Bo.dispatchEvent(n)):n={promise:e,reason:r},!Qo&&(i=Bo["on"+t])?i(n):t===ls&&Wo("Unhandled promise rejection",r)},ws=function(t){zo(Zo,Bo,(function(){var e,r=t.facade,n=t.value;if(_s(t)&&(e=Ho((function(){Io?us.emit("unhandledRejection",n,r):ys(ls,r,n)})),t.rejection=Io||_s(t)?2:1,e.error))throw e.value}))},_s=function(t){return 1!==t.rejection&&!t.parent},gs=function(t){zo(Zo,Bo,(function(){var e=t.facade;Io?us.emit("rejectionHandled",e):ys("rejectionhandled",e,t.value)}))},bs=function(t,e,r){return function(n){t(e,n,r)}},ms=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,ps(t,!0))},ks=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw os("Promise can't be resolved itself");var n=ds(e);n?Xo((function(){var r={done:!1};try{zo(n,e,bs(ks,r,t),bs(ms,r,t))}catch(e){ms(r,e,t)}})):(t.value=e,t.state=1,ps(t,!1))}catch(e){ms({done:!1},e,t)}}};if($o&&(as=(is=function(t){Fo(this,as),Do(t),zo(Oo,this);var e=es(this);try{t(bs(ks,e),bs(ms,e))}catch(t){ms(e,t)}}).prototype,(Oo=function(t){rs(this,{type:qo,done:!1,notified:!1,parent:!1,reactions:new Go,rejection:!1,state:0,value:void 0})}).prototype=Lo(as,"then",(function(t,e){var r=es(this),n=hs(Vo(this,is));return r.parent=!0,n.ok=!jo(t)||t,n.fail=jo(e)&&e,n.domain=Io?us.domain:void 0,0==r.state?r.reactions.add(n):Xo((function(){vs(n,r)})),n.promise})),To=function(){var t=new Oo,e=es(t);this.promise=t,this.resolve=bs(ks,e),this.reject=bs(ms,e)},Jo.f=hs=function(t){return t===is||undefined===t?new To(t):cs(t)},jo(Ko)&&ns!==Object.prototype)){So=ns.then,ts||Lo(ns,"then",(function(t,e){var r=this;return new is((function(t,e){zo(So,r,t,e)})).then(t,e)}),{unsafe:!0});try{delete ns.constructor}catch(t){}Po&&Po(ns,as)}Uo({global:!0,wrap:!0,forced:$o},{Promise:is}),No(is,qo,!1),Co(qo);var xs={},Es=xs,Rs=$t("iterator"),As=Array.prototype,Os=bi,Ts=_t,Ss=xs,Us=$t("iterator"),Is=function(t){if(null!=t)return Ts(t,Us)||Ts(t,"@@iterator")||Ss[Os(t)]},Bs=c,zs=yt,Ls=Ie,Ps=lt,Ns=Is,Cs=n.TypeError,Ds=c,js=Ie,Ms=_t,Fs=ta,Vs=c,Zs=Ie,Xs=lt,Ws=function(t){return void 0!==t&&(Es.Array===t||As[Rs]===t)},Hs=sn,Gs=H,Ys=function(t,e){var r=arguments.length<2?Ns(t):e;if(zs(r))return Ls(Bs(r,t));throw Cs(Ps(t)+" is not iterable")},Ks=Is,Js=function(t,e,r){var n,i;js(t);try{if(!(n=Ms(t,"return"))){if("throw"===e)throw r;return r}n=Ds(n,t)}catch(t){i=!0,n=t}if("throw"===e)throw r;if(i)throw n;return js(n),r},qs=n.TypeError,$s=function(t,e){this.stopped=t,this.result=e},Qs=$s.prototype,tu=function(t,e,r){var n,i,a,o,s,u,h,c=r&&r.that,f=!(!r||!r.AS_ENTRIES),l=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=Fs(e,c),p=function(t){return n&&Js(n,"normal",t),new $s(!0,t)},y=function(t){return f?(Zs(t),d?v(t[0],t[1],p):v(t[0],t[1])):d?v(t,p):v(t)};if(l)n=t;else{if(!(i=Ks(t)))throw qs(Xs(t)+" is not iterable");if(Ws(i)){for(a=0,o=Hs(t);o>a;a++)if((s=y(t[a]))&&Gs(Qs,s))return s;return new $s(!1)}n=Ys(t,i)}for(u=n.next;!(h=Vs(u,n)).done;){try{s=y(h.value)}catch(t){Js(n,"throw",t)}if("object"==typeof s&&s&&Gs(Qs,s))return s}return new $s(!1)};function eu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function ru(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),h=n.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var ih,ah,oh,sh="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,uh=!a((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),hh=n,ch=Nt,fh=j,lh=zt,dh=uh,vh=dr("IE_PROTO"),ph=hh.Object,yh=ph.prototype,wh=dh?ph.getPrototypeOf:function(t){var e=lh(t);if(ch(e,vh))return e[vh];var r=e.constructor;return fh(r)&&e instanceof r?r.prototype:e instanceof ph?yh:null},_h=sh,gh=o,bh=n,mh=j,kh=F,xh=Nt,Eh=bi,Rh=lt,Ah=We,Oh=Kr,Th=Re.f,Sh=H,Uh=wh,Ih=ri,Bh=$t,zh=Ft,Lh=bh.Int8Array,Ph=Lh&&Lh.prototype,Nh=bh.Uint8ClampedArray,Ch=Nh&&Nh.prototype,Dh=Lh&&Uh(Lh),jh=Ph&&Uh(Ph),Mh=Object.prototype,Fh=bh.TypeError,Vh=Bh("toStringTag"),Zh=zh("TYPED_ARRAY_TAG"),Xh=zh("TYPED_ARRAY_CONSTRUCTOR"),Wh=_h&&!!Ih&&"Opera"!==Eh(bh.opera),Hh=!1,Gh={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Yh={BigInt64Array:8,BigUint64Array:8},Kh=function(t){if(!kh(t))return!1;var e=Eh(t);return xh(Gh,e)||xh(Yh,e)};for(ih in Gh)(oh=(ah=bh[ih])&&ah.prototype)?Ah(oh,Xh,ah):Wh=!1;for(ih in Yh)(oh=(ah=bh[ih])&&ah.prototype)&&Ah(oh,Xh,ah);if((!Wh||!mh(Dh)||Dh===Function.prototype)&&(Dh=function(){throw Fh("Incorrect invocation")},Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih],Dh);if((!Wh||!jh||jh===Mh)&&(jh=Dh.prototype,Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih].prototype,jh);if(Wh&&Uh(Ch)!==jh&&Ih(Ch,jh),gh&&!xh(jh,Vh))for(ih in Hh=!0,Th(jh,Vh,{get:function(){return kh(this)?this[Zh]:void 0}}),Gh)bh[ih]&&Ah(bh[ih],Zh,ih);var Jh={NATIVE_ARRAY_BUFFER_VIEWS:Wh,TYPED_ARRAY_CONSTRUCTOR:Xh,TYPED_ARRAY_TAG:Hh&&Zh,aTypedArray:function(t){if(Kh(t))return t;throw Fh("Target is not a typed array")},aTypedArrayConstructor:function(t){if(mh(t)&&(!Ih||Sh(Dh,t)))return t;throw Fh(Rh(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if(gh){if(r)for(var i in Gh){var a=bh[i];if(a&&xh(a.prototype,t))try{delete a.prototype[t]}catch(r){try{a.prototype[t]=e}catch(t){}}}jh[t]&&!r||Oh(jh,t,r?e:Wh&&Ph[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if(gh){if(Ih){if(r)for(n in Gh)if((i=bh[n])&&xh(i,t))try{delete i[t]}catch(t){}if(Dh[t]&&!r)return;try{return Oh(Dh,t,r?e:Wh&&Dh[t]||e)}catch(t){}}for(n in Gh)!(i=bh[n])||i[t]&&!r||Oh(i,t,e)}},isView:function(t){if(!kh(t))return!1;var e=Eh(t);return"DataView"===e||xh(Gh,e)||xh(Yh,e)},isTypedArray:Kh,TypedArray:Dh,TypedArrayPrototype:jh},qh=O,$h=n,Qh=Array.isArray||function(t){return"Array"==qh(t)},tc=Di,ec=F,rc=$t("species"),nc=$h.Array,ic=function(t){var e;return Qh(t)&&(e=t.constructor,(tc(e)&&(e===nc||Qh(e.prototype))||ec(e)&&null===(e=e[rc]))&&(e=void 0)),void 0===e?nc:e},ac=ta,oc=z,sc=zt,uc=sn,hc=function(t,e){return new(ic(t))(0===e?0:e)},cc=x([].push),fc=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,a=6==t,o=7==t,s=5==t||a;return function(u,h,c,f){for(var l,d,v=sc(u),p=oc(v),y=ac(h,c),w=uc(p),_=0,g=f||hc,b=e?g(u,w):r||o?g(u,0):void 0;w>_;_++)if((s||_ in p)&&(d=y(l=p[_],_,v),t))if(e)b[_]=d;else if(d)switch(t){case 3:return!0;case 5:return l;case 6:return _;case 2:cc(b,l)}else switch(t){case 4:return!1;case 7:cc(b,l)}return a?-1:n||i?i:b}},lc={forEach:fc(0),map:fc(1),filter:fc(2),some:fc(3),every:fc(4),find:fc(5),findIndex:fc(6),filterReject:fc(7)},dc=Wi,vc=Jh.TYPED_ARRAY_CONSTRUCTOR,pc=Jh.aTypedArrayConstructor,yc=lc.map,wc=function(t){return pc(dc(t,t[vc]))},_c=Jh.aTypedArray;(0,Jh.exportTypedArrayMethod)("map",(function(t){return yc(_c(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(wc(t))(e)}))}));var gc=o,bc=$e.EXISTS,mc=x,kc=Re.f,xc=Function.prototype,Ec=mc(xc.toString),Rc=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ac=mc(Rc.exec);gc&&!bc&&kc(xc,"name",{configurable:!0,get:function(){try{return Ac(Rc,Ec(this))[1]}catch(t){return""}}});var Oc=function(t){cu(r,t);var e=_u(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ou(this,r),(t=e.call(this,n)).name="XnbError",t.message=n,Error.captureStackTrace(yu(t),r),t}return uu(r)}(pu(Error)),Tc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"setReaders",value:function(e){t.readers=ru({},e)}},{key:"addReaders",value:function(e){t.readers=ru(ru({},t.readers),e)}},{key:"makeSimplied",value:function(e,r){var n=e.split(/`|,/)[0];if(r.isTypeOf(n)){if(r.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r.type(),"<").concat(i.join(","),">")}return r.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var r=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(r,"[]"))return"Array<".concat(simplifyType(r.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===r){var n=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n)}for(var i=0,a=Object.values(t.readers);i/);return r=r?r[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:r}}},{key:"getReaderTypeList",value:function(e){var r=t.getTypeInfo(e),n=r.type,i=r.subtypes;if(t.readers.hasOwnProperty("".concat(n,"Reader")))return t.readers["".concat(n,"Reader")].parseTypeList(i);throw new Oc('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var r=t.getTypeInfo(e),n=r.type,i=r.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(n,"Reader")))return vu(t.readers["".concat(n,"Reader")],i);throw new Oc('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var r=t.simplifyType(e);return t.getReader(r)}}]),t}();hu(Tc,"readers",{});var Sc=[192,224,240],Uc=128,Ic=63,Bc=[55296,56320],zc=1023;function Lc(t){return t<128?[t]:t<2048?[Sc[0]|t>>6,Uc|t&Ic]:t<65536?[Sc[1]|t>>12,Uc|t>>6&Ic,Uc|t&Ic]:[Sc[2]|t>>18,Uc|t>>12&Ic,Uc|t>>6&Ic,Uc|t&Ic]}function Pc(t){return t<65535?[t]:[Bc[0]|(t-=65536)>>10&zc,Bc[1]|t&zc]}function Nc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var r=t.length;return 1===r?t[0]:2===r?((t[0]^Sc[0])<<6)+(t[1]^Uc):3===r?((t[0]^Sc[1])<<12)+((t[1]^Uc)<<6)+(t[2]^Uc):((t[0]^Sc[2])<<18)+((t[1]^Uc)<<12)+((t[2]^Uc)<<6)+(t[3]^Uc)}function Cc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&zc)<<10)+(t[1]&zc)+65536}function Dc(t){return function(t){for(var e=[],r=0;r1&&void 0!==arguments[1])||arguments[1];ou(this,t),this._endianus=r,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return uu(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,r=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:0,e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0;){var n=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(n&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,r|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),Fc=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ou(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return uu(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e),n=0;n>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),Vc=256,Zc=0,Xc=1,Wc=2,Hc=3,Gc=656,Yc=function(){function t(e){if(ou(this,t),this.window_size=1<21)throw new Oc("Window size out of range!");if(!t.extra_bits.length)for(var r=0,n=0;r<=50;r+=2)t.extra_bits[r]=t.extra_bits[r+1]=n,0!=r&&n<17&&n++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case Wc:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case Xc:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(Gc,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case Hc:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new Oc("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new Oc("Cannot run outside of window frame.");switch(this.block_type){case Wc:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Gc,12);if(h>3;if(f>2){var l=t.extra_bits[f];if(f=t.position_base[f]-2,l>3)l-=3,f+=e.readLZXBits(l)<<3,f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?f+=e.readLZXBits(l):f=1;this.R2=this.R1,this.R1=this.R0,this.R0=f}else 0===f?f=this.R0:1==f?(f=this.R1,this.R1=this.R0,this.R0=f):(f=this.R2,this.R2=this.R0,this.R0=f);var d=this.window_posn,v=void 0;if(u-=c,this.window_posn>=f)v=d-f;else{v=d+(this.window_size-f);var p=f-this.window_posn;if(p0;)this.win[d++]=this.win[v++];v=0}}for(this.window_posn+=c;c-- >0;)this.win[d++]=this.win[v++]}}break;case Xc:for(;u>0;){var y=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Gc,12);if(y>3;if(_>2){if(3!=_){var g=t.extra_bits[_],b=e.readLZXBits(g);_=t.position_base[_]-2+b}else _=1;this.R2=this.R1,this.R1=this.R0,this.R0=_}else 0===_?_=this.R0:1==_?(_=this.R1,this.R1=this.R0,this.R0=_):(_=this.R2,this.R2=this.R0,this.R0=_);var m=this.window_posn,k=void 0;if(u-=w,this.window_posn>=_)k=m-_;else{k=m+(this.window_size-_);var x=_-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=w;w-- >0;)this.win[m++]=this.win[k++]}}break;case Hc:if(e.bytePosition+u>n)throw new Oc("Overrun!"+n+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new Oc("Overrun table!");for(var c=o;c-- >0;)n[h++]=u}o>>=1}if(i==a)return n;for(var f=i;f>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var v=0;v>16,y=0;y>15-y&1&&p++;if(n[p]=v,(i+=o)>a)throw new Oc("Overrun table during decoding.")}o>>=1}if(i==a)return n;throw new Oc("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,r,n,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=n){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=n)}return t.bitPosition+=r[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var r=this.R2;this.R2=this.R0,this.R0=r}}}]),t}();Yc.position_base=[],Yc.extra_bits=[];var Kc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"decompress",value:function(t,e,r){for(var n,i,a=0,o=new Yc(16),s=new Fc(r);a65536||i>65536)throw new Oc("Invalid size read in compression content.");s.write(o.decompress(t,i,n)),a+=n}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),Jc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}},{key:"readU32",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}},{key:"writeU32",value:function(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}},{key:"imul",value:function(t,e){var r=65535&t,n=65535&e;return r*n+((t>>>16)*n+r*(e>>>16)<<16)|0}}]),t}(),qc=65536,$c=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),r=0;r=13)for(var d=67;r+4>>0;if(a=i[p=(p>>16^p)>>>0&65535]-1,i[p]=r+1,a<0||r-a>>>16>0||Jc.readU32(t,a)!==v)r+=d++>>6;else{for(d=67,h=r-o,u=r-a,a+=4,s=r+=4;r=$c){for(e[c++]=240+y,l=h-$c;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=(h<<4)+y;for(var w=0;w>8,s>=15){for(l=s-15;l>=255;l-=255)e[c++]=255;e[c++]=l}o=r}}if(0===o)return 0;if((h=f-o)>=$c){for(e[c++]=240,l=h-$c;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=h<<4;for(r=o;r2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,c=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(r=15&f,n=t[s++]|t[s++]<<8,15===r)for(;r+=t[s],255===t[s++];);if(r+=4,c&&1===n)e.fill(0|e[h-1],h,h+r),h+=r;else if(c&&n>r&&r>31)e.copyWithin(h,h-n,h-n+r),h+=r;else for(a=(o=h-n)+r;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var r=0,n=t.length,i=0,a=Math.max(32,n+(n>>1)+7),o=new Uint8Array(a>>3<<3);r=55296&&s<=56319){if(r=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+r/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var r=new Uint8Array(t),n=0,i=r.length,a=[];n65535&&(c-=65536,a.push(c>>>10&1023|55296),c=56320|1023&c),a.push(c)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},vf={};function pf(t){var e=vf[t];if(void 0!==e)return e.exports;var r=vf[t]={exports:{}};return df[t].call(r.exports,r,r.exports,pf),r.exports}pf.d=function(t,e){for(var r in e)pf.o(e,r)&&!pf.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},pf.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var yf={};!function(){pf.d(yf,{P:function(){return Or},m:function(){return Ar}}),pf(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,r=function(){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r);var n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=n?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return uu(r,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="",r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(r),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),r}();function n(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);n(u);var h=new Array(60);n(h);var c=new Array(512);n(c);var f=new Array(256);n(f);var l=new Array(29);n(l);var d,v,p,y=new Array(30);function w(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}function _(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(y);var g=function(t){return t<256?c[t]:c[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,r){t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<>>=1,r<<=1}while(--e>0);return r>>>1},E=function(t,e,r){var n,i,a=new Array(16),o=0;for(n=1;n<=15;n++)a[n]=o=o+r[n-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},R=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},A=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},O=function(t,e,r,n){var i=2*e,a=2*r;return t[i]>1;r>=1;r--)T(t,a,r);i=u;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],T(t,a,1),n=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=n,a[2*i]=a[2*r]+a[2*n],t.depth[i]=(t.depth[r]>=t.depth[n]?t.depth[r]:t.depth[n])+1,a[2*r+1]=a[2*n+1]=i,t.heap[1]=i++,T(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var r,n,i,a,o,s,u=e.dyn_tree,h=e.max_code,c=e.stat_desc.static_tree,f=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,v=e.stat_desc.max_length,p=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,r=t.heap_max+1;r<573;r++)(a=u[2*u[2*(n=t.heap[r])+1]+1]+1)>v&&(a=v,p++),u[2*n+1]=a,n>h||(t.bl_count[a]++,o=0,n>=d&&(o=l[n-d]),s=u[2*n],t.opt_len+=s*(a+o),f&&(t.static_len+=s*(c[2*n+1]+o)));if(0!==p){do{for(a=v-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[v]--,p-=2}while(p>0);for(a=v;0!==a;a--)for(n=t.bl_count[a];0!==n;)(i=t.heap[--r])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),n--)}}(t,e),E(a,h,t.bl_count)},I=function(t,e,r){var n,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(r+1)+1]=65535,n=0;n<=r;n++)i=o,o=e[2*(n+1)+1],++s>=7;n<30;n++)for(y[n]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),U(t,t.l_desc),U(t,t.d_desc),o=function(t){var e;for(I(t,t.dyn_ltree,t.l_desc.max_code),I(t,t.dyn_dtree,t.d_desc.max_code),U(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==e?L(t,e,r,n):4===t.strategy||a===i?(m(t,2+(n?1:0),3),S(t,u,h)):(m(t,4+(n?1:0),3),function(t,e,r,n){var i;for(m(t,e-257,5),m(t,r-1,5),m(t,n-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(f[r]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},j=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},M=function(t,e,r,n){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+e[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},F=new Uint32Array(function(){for(var t,e=[],r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e}()),V=function(t,e,r,n){var i=F,a=n+r;t^=-1;for(var o=n;o>>8^i[255&(t^e[o])];return-1^t},Z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},W=P,H=N,G=C,Y=D,K=j,J=X.Z_NO_FLUSH,q=X.Z_PARTIAL_FLUSH,$=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,rt=X.Z_STREAM_END,nt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ct=X.Z_FIXED,ft=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,vt=262,pt=103,yt=113,wt=666,_t=function(t,e){return t.msg=Z[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,r){return(e<t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Rt=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},At=function(t,e,r,n){var i=t.avail_in;return i>n&&(i=n),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),1===t.state.wrap?t.adler=M(t.adler,e,i,r):2===t.state.wrap&&(t.adler=V(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},Ot=function(t,e){var r,n,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-vt?t.strstart-(t.w_size-vt):0,h=t.window,c=t.w_mask,f=t.prev,l=t.strstart+dt,d=h[a+o-1],v=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(r=e)+o]===v&&h[r+o-1]===d&&h[r]===h[a]&&h[++r]===h[a+1]){a+=2,r++;do{}while(h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&ao){if(t.match_start=e,o=n,n>=s)break;d=h[a+o-1],v=h[a+o]}}}while((e=f[e&c])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Tt=function(t){var e,r,n,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-vt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=r=t.hash_size;do{n=t.head[--e],t.head[e]=n>=o?n-o:0}while(--r);e=r=o;do{n=t.prev[--e],t.prev[e]=n>=o?n-o:0}while(--r);i+=o}if(0===t.strm.avail_in)break;if(r=At(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=r,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-vt&&(t.match_length=Ot(t,r)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Ut=function(t,e){for(var r,n,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((n=Y(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Bt=[new It(0,0,0,0,(function(t,e){var r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+r;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-vt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,St),new It(4,5,16,8,St),new It(4,6,32,32,St),new It(4,4,16,16,Ut),new It(8,16,32,32,Ut),new It(8,16,128,128,Ut),new It(8,32,128,256,Ut),new It(32,128,258,1024,Ut),new It(32,258,258,4096,Ut)];function zt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Lt=function(t){var e,r=function(t){if(!t||!t.state)return _t(t,nt);t.total_in=t.total_out=0,t.data_type=ft;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:yt,t.adler=2===e.wrap?0:1,e.last_flush=J,W(e),et}(t);return r===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),r},Pt=function(t,e,r,n,i,a){if(!t)return nt;var o=1;if(e===ot&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>9||r!==lt||n<8||n>15||e<0||e>9||a<0||a>ct)return _t(t,nt);8===n&&(n=9);var s=new zt;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<tt||e<0)return t?_t(t,nt):nt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===wt&&e!==Q)return _t(t,0===t.avail_out?at:nt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=V(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=yt);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=yt,Rt(i,o),0!==i.strstart&&(Rt(i,t.adler>>>16),Rt(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=pt)}else i.status=pt;if(i.status===pt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=yt)):i.status=yt),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return _t(t,at);if(i.status===wt&&0!==t.avail_in)return _t(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==wt){var s=i.strategy===ut?function(t,e){for(var r;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var r,n,i,a,o=t.window;;){if(t.lookahead<=dt){if(Tt(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((n=o[i=t.strstart-1])===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+dt;do{}while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=wt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===q?K(i):e!==tt&&(H(i,0,0,!1),e===$&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?rt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Rt(i,t.adler>>>16),Rt(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:rt)},Ct=function(t){if(!t||!t.state)return nt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==pt&&e!==yt&&e!==wt?_t(t,nt):(t.state=null,e===yt?_t(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},jt=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var r=e.shift();if(r){if("object"!=nu(r))throw new TypeError(r+"must be non-object");for(var n in r)Dt(r,n)&&(t[n]=r[n])}}return t},Mt=function(t){for(var e=0,r=0,n=t.length;r=252?6:Zt>=248?5:Zt>=240?4:Zt>=224?3:Zt>=192?2:1;Vt[254]=Vt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,r,n,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&r):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|63&r):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|63&r);return e},Wt=function(t,e){var r,n,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var r="",n=0;nt.length&&(e=t.length);for(var r=e-1;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Vt[t[r]]>e?r:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Yt=Object.prototype.toString,Kt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,qt=X.Z_FULL_FLUSH,$t=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,re=X.Z_DEFAULT_STRATEGY,ne=X.Z_DEFLATED;function ie(t){this.options=jt({level:ee,method:ne,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Qt)throw new Error(Z[r]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Yt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=function(t,e){var r=e.length;if(!t||!t.state)return nt;var n=t.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return nt;if(1===i&&(t.adler=M(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){0===i&&(bt(n.head),n.strstart=0,n.block_start=0,n.insert=0);var a=new Uint8Array(n.w_size);a.set(e.subarray(r-n.w_size,r),0),e=a,r=n.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Tt(n);n.lookahead>=3;){var h=n.strstart,c=n.lookahead-2;do{n.ins_h=mt(n,n.ins_h,n.window[h+3-1]),n.prev[h&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=h,h++}while(--c);n.strstart=h,n.lookahead=2,Tt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,n.wrap=i,et}(this.strm,n),r!==Qt)throw new Error(Z[r]);this._dict_set=!0}}function ae(t,e){var r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||Z[r.err];return r.result}ie.prototype.push=function(t,e){var r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=e===~~e?e:!0===e?$t:Kt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Yt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===Jt||n===qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((r=Nt(i,n))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ct(this.strm),this.onEnd(r),this.ended=!0,r===Qt;if(0!==i.avail_out){if(n>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Mt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,R,A=t.state;r=t.next_in,E=t.input,n=r+(t.avail_in-5),i=t.next_out,R=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=A.dmax,u=A.wsize,h=A.whave,c=A.wnext,f=A.window,l=A.hold,d=A.bits,v=A.lencode,p=A.distcode,y=(1<>>=g=_>>>24,d-=g,0===(g=_>>>16&255))R[i++]=65535&_;else{if(!(16&g)){if(0==(64&g)){_=v[(65535&_)+(l&(1<>>=g,d-=g),d<15&&(l+=E[r++]<>>=g=_>>>24,d-=g,!(16&(g=_>>>16&255))){if(0==(64&g)){_=p[(65535&_)+(l&(1<s){t.msg="invalid distance too far back",A.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&A.sane){t.msg="invalid distance too far back",A.mode=30;break t}if(k=0,x=f,0===c){if(k+=u-g,g2;)R[i++]=x[k++],R[i++]=x[k++],R[i++]=x[k++],b-=3;b&&(R[i++]=x[k++],b>1&&(R[i++]=x[k++]))}else{k=i-m;do{R[i++]=R[k++],R[i++]=R[k++],R[i++]=R[k++],b-=3}while(b>2);b&&(R[i++]=R[k++],b>1&&(R[i++]=R[k++]))}break}}break}}while(r>3,l&=(1<<(d-=b<<3))-1,t.next_in=r,t.next_out=i,t.avail_in=r=1&&0===U[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(I[1]=0,_=1;_<15;_++)I[_+1]=I[_]+U[_];for(g=0;g852||2===t&&A>592)return 1;for(;;){v=_-E,o[g]d?(p=B[z+o[g]],y=T[S+o[g]]):(p=96,y=0),u=1<<_-E,b=h=1<>E)+(h-=u)]=v<<24|p<<16|y|0}while(0!==h);for(u=1<<_-1;O&u;)u>>=1;if(0!==u?(O&=u-1,O+=u):O=0,g++,0==--U[_]){if(_===m)break;_=e[r+o[g]]}if(_>k&&(O&f)!==c){for(0===E&&(E=k),l+=b,R=1<<(x=_-E);x+E852||2===t&&A>592)return 1;i[c=O&f]=k<<24|x<<16|l-a|0}}return 0!==O&&(i[l+O]=_-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,ve=X.Z_BLOCK,pe=X.Z_TREES,ye=X.Z_OK,we=X.Z_STREAM_END,_e=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Re=30,Ae=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Oe(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Te,Se,Ue=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ye}(t)},Ie=!0,Be=function(t){if(Ie){Te=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Te,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Ie=!1}t.lencode=Te,t.lenbits=9,t.distcode=Se,t.distbits=5},ze=function(t,e,r,n){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,Ue(t))}(t,e);return n!==ye&&(t.state=null),n},Ne=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,R,A=0,O=new Uint8Array(4),T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(r=t.state).mode===Ee&&(r.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,f=s,l=u,x=ye;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,O,2,0),h=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",r.mode=Re;break}if((15&h)!==xe){t.msg="unknown compression method",r.mode=Re;break}if(c-=4,k=8+(15&(h>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Re;break}r.dmax=1<>8&1),512&r.flags&&(O[0]=255&h,O[1]=h>>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>8&255,O[2]=h>>>16&255,O[3]=h>>>24&255,r.check=V(r.check,O,4,0)),h=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>8),512&r.flags&&(O[0]=255&h,O[1]=h>>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,O,2,0)),h=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),k)),512&r.flags&&(r.check=V(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break t;d=0;do{k=n[a+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&d>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ee;break;case 10:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===s)break t;s--,h+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Be(r),r.mode=20,e===pe){h>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Re}h>>>=2,c-=2;break;case 14:for(h>>>=7&c,c-=7&c;c<32;){if(0===s)break t;s--,h+=n[a++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Re;break}if(r.length=65535&h,h=0,c=0,r.mode=15,e===pe)break t;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(n.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,r.length-=d;break}r.mode=Ee;break;case 17:for(;c<14;){if(0===s)break t;s--,h+=n[a++]<>>=5,c-=5,r.ndist=1+(31&h),h>>>=5,c-=5,r.ncode=4+(15&h),h>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Re;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,E={bits:r.lenbits},x=le(0,r.lens,0,19,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid code lengths set",r.mode=Re;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=y,c-=y,r.lens[r.have++]=_;else{if(16===_){for(R=y+2;c>>=y,c-=y,0===r.have){t.msg="invalid bit length repeat",r.mode=Re;break}k=r.lens[r.have-1],d=3+(3&h),h>>>=2,c-=2}else if(17===_){for(R=y+3;c>>=y)),h>>>=3,c-=3}else{for(R=y+7;c>>=y)),h>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Re;break}for(;d--;)r.lens[r.have++]=k}}if(r.mode===Re)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Re;break}if(r.lenbits=9,E={bits:r.lenbits},x=le(1,r.lens,0,r.nlen,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid literal/lengths set",r.mode=Re;break}if(r.distbits=6,r.distcode=r.distdyn,E={bits:r.distbits},x=le(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,E),r.distbits=E.bits,x){t.msg="invalid distances set",r.mode=Re;break}if(r.mode=20,e===pe)break t;case 20:r.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,r.hold=h,r.bits=c,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,r.mode===Ee&&(r.back=-1);break}for(r.back=0;w=(A=r.lencode[h&(1<>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&A,!(g+(y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,r.length=_,0===w){r.mode=26;break}if(32&w){r.back=-1,r.mode=Ee;break}if(64&w){t.msg="invalid literal/length code",r.mode=Re;break}r.extra=15&w,r.mode=22;case 22:if(r.extra){for(R=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;w=(A=r.distcode[h&(1<>>16&255,_=65535&A,!((y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&A,!(g+(y=A>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,64&w){t.msg="invalid distance code",r.mode=Re;break}r.offset=_,r.extra=15&w,r.mode=24;case 24:if(r.extra){for(R=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Re;break}r.mode=25;case 25:if(0===u)break t;if(d=l-u,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Re;break}d>r.wnext?(d-=r.wnext,v=r.wsize-d):v=r.wnext-d,d>r.length&&(d=r.length),p=r.window}else p=i,v=o-r.offset,d=r.length;d>u&&(d=u),u-=d,r.length-=d;do{i[o++]=p[v++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===u)break t;i[o++]=r.length,u--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===s)break t;s--,h|=n[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pe(this.strm,e.windowBits);if(r!==Ze)throw new Error(Z[r]);if(this.header=new je,function(t,e){if(!t||!t.state)return ge;var r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Me.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary))!==Ze))throw new Error(Z[r])}function Je(t,e){var r=new Ke(e);if(r.push(t),r.err)throw r.msg||Z[r.err];return r.result}Ke.prototype.push=function(t,e){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Me.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ne(a,n))===We&&s&&((r=De(a,s))===Ze?r=Ne(a,n):r===Ge&&(r=We));a.avail_in>0&&r===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Le(a),r=Ne(a,n);switch(r){case He:case Ge:case We:case Ye:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Xe))if("string"===this.options.to){var u=Ht(a.output,a.next_out),h=a.next_out-u,c=Wt(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(c)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Ze||0!==i){if(r===Xe)return r=Ce(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ke.prototype.onData=function(t){this.chunks.push(t)},Ke.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Mt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var qe=oe,$e=Ke,Qe=Je,tr=[137,80,78,71,13,10,26,10],er=[],rr=0;rr<256;rr++){for(var nr=rr,ir=0;ir<8;ir++)1&nr?nr=3988292384^nr>>>1:nr>>>=1;er[rr]=nr}var ar,or,sr,ur;function hr(t,e){return(4294967295^function(t,e,r){for(var n=4294967295,i=0;i>>8;return n}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(ar||(ar={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(or||(or={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(sr||(sr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(ur||(ur={}));var cr=new Uint8Array(0),fr=new Uint16Array([255]),lr=255===new Uint8Array(fr.buffer)[0],dr=function(t){cu(r,t);var e=_u(r);function r(t){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r),n=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return n._checkCrc=o,n._inflator=new $e,n._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},n._end=!1,n._hasPalette=!1,n._palette=[],n._compressionMethod=or.UNKNOWN,n._filterMethod=sr.UNKNOWN,n._interlaceMethod=ur.UNKNOWN,n._colorType=-1,n.setBigEndian(),n}return uu(r,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=f}else this._png.data=s}}]),r}(r);function vr(t,e,r){for(var n=0;n>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function _r(t,e,r,n,i){var a=0;if(0===r.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ou(this,n),(r=e.call(this))._colorType=ar.UNKNOWN,r._zlibOptions=ru(ru({},mr),i.zlib),r._png=r._checkData(t),r.setBigEndian(),r}return uu(n,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tr)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(or.DEFLATE),this.writeByte(sr.ADAPTIVE),this.writeByte(ur.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,n=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new r).setBigEndian(),h=0,c=0;c0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Er(t,e,r,n){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,r="";return"number"==typeof e?r=gu(" ",Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),gf(t,r,-1)}var mf=function(){function t(e,r,n){ou(this,t),this.startingLine=n||0,this.lineIndex=-1;for(var i=[],a=0;a=r;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;mu(n,'"')&&(i=n.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],n=n.replace(a[0],"")),i?(r||(r={}),o=i[1],s=n.replace(i[0],"").trim()):mu(n,"-")&&(r||(r=[]),s=n.slice(1).trim()),s=s?xf(s,u):kf(t.nextGroup(),u),Array.isArray(r)?r.push(s):r[o]=s}return e&&(r={type:e,data:r}),r}function xf(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Ef(t){var e=t.replace(/\t/g,"\t").split("\n");return kf(new mf(e))}function Rf(t){var e;if(Array.isArray(t)){e=[];for(var r=0;r","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var c=function(t,e){var r=[],n=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(Af(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(mu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Of(u))return"Texture2D"===u?(r.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&n.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,c=!0,f=!mu(u,"Dictionary")&&!mu(u,"Array")&&!mu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function Uf(t){var e={},r=t.xnbData,n=r.compressed,i=r.readerData,a=r.hiDef,o=r.target;return e.header={target:o,formatVersion:5,compressed:n?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=Rf(i),e.content=Tf(t.content),"SpriteFont"===Tc.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function If(t,e){if(t&&"object"==nu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var r=Object.keys(t),n=0;n1&&void 0!==arguments[1]&&arguments[1],r=If(t,"export");if(r){var n=r.value,i=n.type,a=n.data;return"Texture2D"===i&&(a=_f(n.width,n.height,new Uint8Array(a))),Pf(a,i)}if(e){var o=JSON.stringify(t,null,4);return Pf(o,"JSON")}return null}function Cf(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(n&&a&&(n=!1),!t.hasOwnProperty("content"))throw new Oc("Invalid object!");var u=[],h=t.content,c=Nf(h,a);if(null!==c&&u.push(c),a)return u;var f=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(zf(e.type)):"".concat(e.type,".").concat(zf(e.type)):e}),4),l=f;return n&&(l=bf(Sf(t))),u.unshift(Pf(l,n?"yaml":"JSON")),u}function Df(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function jf(t){return Mf.apply(this,arguments)}function Mf(){return(Mf=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ff(t){return Vf.apply(this,arguments)}function Vf(){return(Vf=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Zf(t,e){return Xf.apply(this,arguments)}function Xf(){return Xf=au(regeneratorRuntime.mark((function t(e,r){var n,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,Ff(r.png);case 3:return n=t.sent,i=wf(new Uint8Array(n)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,Ff(r.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,Ff(r.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,jf(r.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),Xf.apply(this,arguments)}function Wf(t){return Hf.apply(this,arguments)}function Hf(){return Hf=au(regeneratorRuntime.mark((function t(e){var r,n,i,a,o,s,u,h,c,f,l,d,v=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=v.length>1&&void 0!==v[1]?v[1]:{},n=r.compression,i=void 0===n?"default":n,a=e.json||e.yaml){t.next=5;break}throw new Oc("There is no JSON or YAML file to pack!");case 5:return t.next=7,jf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):Uf(Ef(o)),null!==(u=Df(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new Oc("".concat(a.name,' does not have "content".'));case 14:if(!(h=If(s.content,"export"))){t.next=21;break}return c=h.parent,f=h.value,l=Bf(f),d=l[1],t.next=20,Zf(d,e);case 20:c.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),Hf.apply(this,arguments)}function Gf(t){return Yf.apply(this,arguments)}function Yf(){return(Yf=au(regeneratorRuntime.mark((function t(e){var r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(r=Bf(e.name),"xnb"===r[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return n=t.sent,t.abrupt("return",Kf(n));case 8:return t.abrupt("return",Kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Kf(t){return(new lf).load(t)}function Jf(t){var e=Nf(t.content,!0),r=e.data,n=e.extension;return new uf(r,n)}function qf(t){for(var e={},r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),tl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(Qf),el=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){for(var r=(new tl).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),rl=[55296,56320];function nl(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function il(t){var e=function(t){for(var e=ku({length:t.length},(function(e,r){return t.charCodeAt(r)})),r=[],n=0;n>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(Qf),hl=function(t){cu(r,t);var e=_u(r);function r(t,n){var i;if(ou(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return uu(r,[{key:"read",value:function(t,e){for(var r={},n=(new tl).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),cl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(Qf),fl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new tl).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new tl).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(Qf),ll=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(Qf),dl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){for(var r=(new tl).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),vl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new sl,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new sl,null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),pl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(Qf),yl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new ll;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new ll;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(Qf),wl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(Qf),_l=256;function gl(t,e,r,n){for(var i=Array(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),a=Array(r),o=0;o=Math.abs(i);){var c=h[0][0],f=h[0][1],l=gl(c,f,bl(t[c][c],t[f][f],t[c][f]),r);t=kl(l,t),a=xl(a,l),h=ml(t)}for(var d=0;d0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;ou(this,t),this._values=[e,r,n]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Ol(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;ou(this,t),this._values=[e,r,n,i]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new Al(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var a=0;a<4;a++)n[i+4+a]=r[4*a+0]|r[4*a+1]<<2|r[4*a+2]<<4|r[4*a+3]<<6}function Nl(t,e,r,n,i){var a,o=Ll(t),s=Ll(e);if(o<=s)a=r.slice();else{var u=[s,o];o=u[0],s=u[1],a=r.map((function(t){return 0===t?1:1===t?0:t}))}Pl(o,s,a,n,i)}function Cl(t,e,r,n,i){var a,o=Ll(t),s=Ll(e);if(o=128||!i)){var l=this._remap[s],d=(e[4*o+3]+1)/256;this._weights[l]+=a?d:1,this._remap[o]=l;break}}else this._remap[o]=-1}for(var v=0;v=n?t:(n=o,a)}),0);return i+=n,a}));if(is&&(a=r[h],s=c)}this.start=i.clampGrid().clone(),this.end=a.clampGrid().clone()}}}]),r}(jl),Vl=function(t){cu(r,t);var e=_u(r);function r(t){var n;ou(this,r);(n=e.call(this,t)).iterationCount=t.flags&_l?8:1,n.bestError=1/0,n.metric=new Ol(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,a=i.points,o=i.weights;return n.principle=Tl(a,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Ol(0),n}return uu(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Ol(.5,.5,.5,1/4),a=Ol.multiplyAdd(r,i,e),o=a.splatW,s=Ol.multiplyAdd(r,i,n);return{ax:a,aa:o,bx:s,bb:s.splatW,ab:Ol.multVector(r,i).splatW}}),(function(r,n,i){return Nl(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=new Ol(1/3,1/3,1/3,1/9),o=new Ol(2/3,2/3,2/3,4/9),s=new Ol(2/9),u=Ol.multiplyAdd(n,a,Ol.multiplyAdd(r,o,e)),h=u.splatW,c=Ol.multiplyAdd(r,a,Ol.multiplyAdd(n,o,i));return{ax:u,aa:h,bx:c,bb:c.splatW,ab:Ol.multVector(s,Ol.add(r,n)).splatW}}),(function(r,n,i){return Cl(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Ol(0),end:new Ol(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var a=function(e,n){var a=t(e),o=r.computeOptimalPoints(a);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var a={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(a.bestK=i),a},a=new Ol(0),o=0;o15?15:e}function Xl(t,e,r,n){var i=Wl(t,e,5),a=Wl(t,e,7);i.error<=a.error?function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Gl(i,n,a.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else Gl(n,i,a,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Gl(i,n,a.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else Gl(n,i,a,e,r)}(a,r,n)}function Wl(t,e,r){var n=function(t,e,r){for(var n=255,i=0,a=0;a<16;a++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*c&255;n[o]=f,o++}}}function Yl(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Kl(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function Jl(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,a=Yl(n),o=Yl(i);return[a,o,Kl(a,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Kl(a,o,2/3)]}(e,r,n),a=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var a=t[r+i];n[4*i+0]=3&a,n[4*i+1]=a>>2&3,n[4*i+2]=a>>4&3,n[4*i+3]=a>>6&3}return n}(e,r),o=0;o<16;o++)for(var s=0;s<4;s++)t[4*o+s]=i[a[o]][s]}function ql(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function $l(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_l&&(r=8),64!=n&&(n=32),e|r|n|128&t}function Ql(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,a=r.y,o=void 0===a?0:a,s=r.width,u=void 0===s?0:s,h=r.height,c=void 0===h?0:h,f=0;ql((function(r,n){var a=i+r,s=o+n;if(a>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],a=Hl(n,i,n<=i?5:7),o=new Uint8Array(16),s=0,u=2,h=0;h<2;h++){for(var c=0,f=0;f<3;f++)c|=e[r+u]<<8*f,u++;for(var l=0;l<8;l++){var d=c>>3*l&7;o[s]=d,s++}}for(var v=0;v<16;++v)t[4*v+3]=a[o[v]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function rd(t,e,r,n,i){var a=0!=(1&(i=$l(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,a=void 0===i?0:i,o=e.width,s=void 0===o?0:o,u=e.height,h=void 0===u?0:u,c=new Uint8Array(64),f=0,l=0;return ql((function(e,r){var i=n+e,o=a+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var s=r.read(t),u=t.read(s);if(4==n)u=sd(u,i,a,nd);else if(5==n)u=sd(u,i,a,id);else if(6==n)u=sd(u,i,a,ad);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var h=0;h","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(Qf),ld=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new ll).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ll).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(Qf),dd=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new wl;return{x:e.read(t),y:e.read(t)}}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}}]),r}(Qf),vd=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new wl;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}}]),r}(Qf),pd={ArrayReader:el,BaseReader:Qf,BmFontReader:ol,BooleanReader:sl,CharReader:ul,DictionaryReader:hl,DoubleReader:cl,EffectReader:fl,Int32Reader:ll,ListReader:dl,NullableReader:vl,RectangleReader:yl,ReflectiveReader:pl,SingleReader:wl,SpriteFontReader:fd,StringReader:al,TBinReader:ld,Texture2DReader:hd,UInt32Reader:tl,Vector2Reader:dd,Vector3Reader:cd,Vector4Reader:vd};ud=pd,Tc.setReaders(ud),t.Readers=pd,t.XnbContent=uf,t.XnbData=sf,t.addReaders=function(t){return Tc.addReaders(t)},t.bufferToContents=function(t){return Jf((new lf).load(t))},t.bufferToXnb=Kf,t.pack=function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=qf(t),n=[],i=Object.keys(r),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=Bf(s),h=u[0],c=function(t){return Cf(t,{yaml:n,contentOnly:a,fileName:h})};return Gf(t).then(c)},t.unpackToXnbData=Gf,t.xnbDataToContent=Jf,t.xnbDataToFiles=Cf,Object.defineProperty(t,"__esModule",{value:!0})})); +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- + * + * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * -------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=function(t){return t&&t.Math==Math&&t},n=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,c=u?h.bind(h):function(){return h.apply(h,arguments)},f={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,v=d&&!l.call({1:2},1);f.f=v?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var p,y,w=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},_=s,g=Function.prototype,b=g.bind,m=g.call,k=_&&b.bind(m,m),x=_?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,T=E({}.toString),R=E("".slice),A=function(t){return R(T(t),8,-1)},O=x,S=a,U=A,I=n.Object,L=O("".split),B=S((function(){return!I("z").propertyIsEnumerable(0)}))?function(t){return"String"==U(t)?L(t,""):I(t)}:I,z=n.TypeError,P=function(t){if(null==t)throw z("Can't call method on "+t);return t},N=B,C=P,D=function(t){return N(C(t))},M=function(t){return"function"==typeof t},j=M,F=function(t){return"object"==typeof t?null!==t:j(t)},V=n,Z=M,X=function(t){return Z(t)?t:void 0},W=function(t,e){return arguments.length<2?X(V[t]):V[t]&&V[t][e]},H=x({}.isPrototypeOf),G=W("navigator","userAgent")||"",Y=n,K=G,J=Y.process,q=Y.Deno,$=J&&J.versions||q&&q.version,Q=$&&$.v8;Q&&(y=(p=Q.split("."))[0]>0&&p[0]<4?1:+(p[0]+p[1])),!y&&K&&(!(p=K.match(/Edge\/(\d+)/))||p[1]>=74)&&(p=K.match(/Chrome\/(\d+)/))&&(y=+p[1]);var tt=y,et=tt,rt=a,nt=!!Object.getOwnPropertySymbols&&!rt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=nt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=W,ot=M,st=H,ut=it,ht=n.Object,ct=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ft=n.String,lt=function(t){try{return ft(t)}catch(t){return"Object"}},dt=M,vt=lt,pt=n.TypeError,yt=function(t){if(dt(t))return t;throw pt(vt(t)+" is not a function")},wt=yt,_t=function(t,e){var r=t[e];return null==r?void 0:wt(r)},gt=c,bt=M,mt=F,kt=n.TypeError,xt={exports:{}},Et=n,Tt=Object.defineProperty,Rt=function(t,e){try{Tt(Et,t,{value:e,configurable:!0,writable:!0})}catch(r){Et[t]=e}return e},At=Rt,Ot="__core-js_shared__",St=n[Ot]||At(Ot,{}),Ut=St;(xt.exports=function(t,e){return Ut[t]||(Ut[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var It=P,Lt=n.Object,Bt=function(t){return Lt(It(t))},zt=Bt,Pt=x({}.hasOwnProperty),Nt=Object.hasOwn||function(t,e){return Pt(zt(t),e)},Ct=x,Dt=0,Mt=Math.random(),jt=Ct(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+jt(++Dt+Mt,36)},Vt=n,Zt=xt.exports,Xt=Nt,Wt=Ft,Ht=nt,Gt=it,Yt=Zt("wks"),Kt=Vt.Symbol,Jt=Kt&&Kt.for,qt=Gt?Kt:Kt&&Kt.withoutSetter||Wt,$t=function(t){if(!Xt(Yt,t)||!Ht&&"string"!=typeof Yt[t]){var e="Symbol."+t;Ht&&Xt(Kt,t)?Yt[t]=Kt[t]:Yt[t]=Gt&&Jt?Jt(e):qt(e)}return Yt[t]},Qt=c,te=F,ee=ct,re=_t,ne=function(t,e){var r,n;if("string"===e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;if(bt(r=t.valueOf)&&!mt(n=gt(r,t)))return n;if("string"!==e&&bt(r=t.toString)&&!mt(n=gt(r,t)))return n;throw kt("Can't convert object to primitive value")},ie=$t,ae=n.TypeError,oe=ie("toPrimitive"),se=function(t,e){if(!te(t)||ee(t))return t;var r,n=re(t,oe);if(n){if(void 0===e&&(e="default"),r=Qt(n,t,e),!te(r)||ee(r))return r;throw ae("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},ue=ct,he=function(t){var e=se(t,"string");return ue(e)?e:e+""},ce=F,fe=n.document,le=ce(fe)&&ce(fe.createElement),de=function(t){return le?fe.createElement(t):{}},ve=de,pe=!o&&!a((function(){return 7!=Object.defineProperty(ve("div"),"a",{get:function(){return 7}}).a})),ye=o,we=c,_e=f,ge=w,be=D,me=he,ke=Nt,xe=pe,Ee=Object.getOwnPropertyDescriptor;i.f=ye?Ee:function(t,e){if(t=be(t),e=me(e),xe)try{return Ee(t,e)}catch(t){}if(ke(t,e))return ge(!we(_e.f,t,e),t[e])};var Te={},Re=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Ae=n,Oe=F,Se=Ae.String,Ue=Ae.TypeError,Ie=function(t){if(Oe(t))return t;throw Ue(Se(t)+" is not an object")},Le=o,Be=pe,ze=Re,Pe=Ie,Ne=he,Ce=n.TypeError,De=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,je="enumerable",Fe="configurable",Ve="writable";Te.f=Le?ze?function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),"function"==typeof t&&"prototype"===e&&"value"in r&&Ve in r&&!r.writable){var n=Me(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:Fe in r?r.configurable:n.configurable,enumerable:je in r?r.enumerable:n.enumerable,writable:!1})}return De(t,e,r)}:De:function(t,e,r){if(Pe(t),e=Ne(e),Pe(r),Be)try{return De(t,e,r)}catch(t){}if("get"in r||"set"in r)throw Ce("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Ze=Te,Xe=w,We=o?function(t,e,r){return Ze.f(t,e,Xe(1,r))}:function(t,e,r){return t[e]=r,t},He={exports:{}},Ge=o,Ye=Nt,Ke=Function.prototype,Je=Ge&&Object.getOwnPropertyDescriptor,qe=Ye(Ke,"name"),$e={EXISTS:qe,PROPER:qe&&"something"===function(){}.name,CONFIGURABLE:qe&&(!Ge||Ge&&Je(Ke,"name").configurable)},Qe=M,tr=St,er=x(Function.toString);Qe(tr.inspectSource)||(tr.inspectSource=function(t){return er(t)});var rr,nr,ir,ar=tr.inspectSource,or=M,sr=ar,ur=n.WeakMap,hr=or(ur)&&/native code/.test(sr(ur)),cr=xt.exports,fr=Ft,lr=cr("keys"),dr=function(t){return lr[t]||(lr[t]=fr(t))},vr={},pr=hr,yr=n,wr=x,_r=F,gr=We,br=Nt,mr=St,kr=dr,xr=vr,Er="Object already initialized",Tr=yr.TypeError,Rr=yr.WeakMap;if(pr||mr.state){var Ar=mr.state||(mr.state=new Rr),Or=wr(Ar.get),Sr=wr(Ar.has),Ur=wr(Ar.set);rr=function(t,e){if(Sr(Ar,t))throw new Tr(Er);return e.facade=t,Ur(Ar,t,e),e},nr=function(t){return Or(Ar,t)||{}},ir=function(t){return Sr(Ar,t)}}else{var Ir=kr("state");xr[Ir]=!0,rr=function(t,e){if(br(t,Ir))throw new Tr(Er);return e.facade=t,gr(t,Ir,e),e},nr=function(t){return br(t,Ir)?t[Ir]:{}},ir=function(t){return br(t,Ir)}}var Lr={set:rr,get:nr,has:ir,enforce:function(t){return ir(t)?nr(t):rr(t,{})},getterFor:function(t){return function(e){var r;if(!_r(e)||(r=nr(e)).type!==t)throw Tr("Incompatible receiver, "+t+" required");return r}}},Br=a,zr=M,Pr=Nt,Nr=Te.f,Cr=$e.CONFIGURABLE,Dr=ar,Mr=Lr.enforce,jr=Lr.get,Fr=!Br((function(){return 8!==Nr((function(){}),"length",{value:8}).length})),Vr=String(String).split("String"),Zr=He.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!Pr(t,"name")||Cr&&t.name!==e)&&Nr(t,"name",{value:e,configurable:!0}),Fr&&r&&Pr(r,"arity")&&t.length!==r.arity&&Nr(t,"length",{value:r.arity});var n=Mr(t);return Pr(n,"source")||(n.source=Vr.join("string"==typeof e?e:"")),t};Function.prototype.toString=Zr((function(){return zr(this)&&jr(this).source||Dr(this)}),"toString");var Xr=n,Wr=M,Hr=We,Gr=He.exports,Yr=Rt,Kr=function(t,e,r,n){var i=!!n&&!!n.unsafe,a=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,s=n&&void 0!==n.name?n.name:e;return Wr(r)&&Gr(r,s,n),t===Xr?(a?t[e]=r:Yr(e,r),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=r:Hr(t,e,r),t)},Jr={},qr=Math.ceil,$r=Math.floor,Qr=function(t){var e=+t;return e!=e||0===e?0:(e>0?$r:qr)(e)},tn=Qr,en=Math.max,rn=Math.min,nn=Qr,an=Math.min,on=function(t){return t>0?an(nn(t),9007199254740991):0},sn=function(t){return on(t.length)},un=D,hn=function(t,e){var r=tn(t);return r<0?en(r+e,0):rn(r,e)},cn=sn,fn=function(t){return function(e,r,n){var i,a=un(e),o=cn(a),s=hn(n,o);if(t&&r!=r){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===r)return t||s||0;return!t&&-1}},ln={includes:fn(!0),indexOf:fn(!1)},dn=Nt,vn=D,pn=ln.indexOf,yn=vr,wn=x([].push),_n=function(t,e){var r,n=vn(t),i=0,a=[];for(r in n)!dn(yn,r)&&dn(n,r)&&wn(a,r);for(;e.length>i;)dn(n,r=e[i++])&&(~pn(a,r)||wn(a,r));return a},gn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Jr.f=Object.getOwnPropertyNames||function(t){return _n(t,gn)};var bn={};bn.f=Object.getOwnPropertySymbols;var mn=W,kn=Jr,xn=bn,En=Ie,Tn=x([].concat),Rn=mn("Reflect","ownKeys")||function(t){var e=kn.f(En(t)),r=xn.f;return r?Tn(e,r(t)):e},An=Nt,On=Rn,Sn=i,Un=Te,In=a,Ln=M,Bn=/#|\.prototype\./,zn=function(t,e){var r=Nn[Pn(t)];return r==Dn||r!=Cn&&(Ln(e)?In(e):!!e)},Pn=zn.normalize=function(t){return String(t).replace(Bn,".").toLowerCase()},Nn=zn.data={},Cn=zn.NATIVE="N",Dn=zn.POLYFILL="P",Mn=zn,jn=n,Fn=i.f,Vn=We,Zn=Kr,Xn=Rt,Wn=function(t,e,r){for(var n=On(e),i=Un.f,a=Sn.f,o=0;o=51&&/native code/.test(t))return!1;var r=new fo((function(t){t(1)})),n=function(t){t((function(){}),(function(){}))};return(r.constructor={})[go]=n,!(bo=r.then((function(){}))instanceof n)||!e&&wo&&!mo})),xo={CONSTRUCTOR:ko,REJECTION_EVENT:mo,SUBCLASSING:bo},Eo={},To=yt,Ro=function(t){var e,r;this.promise=new t((function(t,n){if(void 0!==e||void 0!==r)throw TypeError("Bad Promise constructor");e=t,r=n})),this.resolve=To(e),this.reject=To(r)};Eo.f=function(t){return new Ro(t)};var Ao,Oo,So,Uo=Gn,Io=Yn,Lo=n,Bo=c,zo=Kr,Po=ri,No=function(t,e,r){t&&!r&&(t=t.prototype),t&&!ii(t,ai)&&ni(t,ai,{configurable:!0,value:e})},Co=function(t){var e=oi(t),r=si.f;ui&&e&&!e[hi]&&r(e,hi,{configurable:!0,get:function(){return this}})},Do=yt,Mo=M,jo=F,Fo=function(t,e){if(ci(e,t))return t;throw fi("Incorrect invocation")},Vo=Wi,Zo=Ma.set,Xo=no,Wo=function(t,e){var r=io.console;r&&r.error&&(1==arguments.length?r.error(t):r.error(t,e))},Ho=ao,Go=so,Yo=Lr,Ko=uo,Jo=Eo,qo="Promise",$o=xo.CONSTRUCTOR,Qo=xo.REJECTION_EVENT,ts=xo.SUBCLASSING,es=Yo.getterFor(qo),rs=Yo.set,ns=Ko&&Ko.prototype,is=Ko,as=ns,os=Lo.TypeError,ss=Lo.document,us=Lo.process,hs=Jo.f,cs=hs,fs=!!(ss&&ss.createEvent&&Lo.dispatchEvent),ls="unhandledrejection",ds=function(t){var e;return!(!jo(t)||!Mo(e=t.then))&&e},vs=function(t,e){var r,n,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,c=t.domain;try{s?(o||(2===e.rejection&&gs(e),e.rejection=1),!0===s?r=a:(c&&c.enter(),r=s(a),c&&(c.exit(),i=!0)),r===t.promise?h(os("Promise-chain cycle")):(n=ds(r))?Bo(n,r,u,h):u(r)):h(a)}catch(t){c&&!i&&c.exit(),h(t)}},ps=function(t,e){t.notified||(t.notified=!0,Xo((function(){for(var r,n=t.reactions;r=n.get();)vs(r,t);t.notified=!1,e&&!t.rejection&&ws(t)})))},ys=function(t,e,r){var n,i;fs?((n=ss.createEvent("Event")).promise=e,n.reason=r,n.initEvent(t,!1,!0),Lo.dispatchEvent(n)):n={promise:e,reason:r},!Qo&&(i=Lo["on"+t])?i(n):t===ls&&Wo("Unhandled promise rejection",r)},ws=function(t){Bo(Zo,Lo,(function(){var e,r=t.facade,n=t.value;if(_s(t)&&(e=Ho((function(){Io?us.emit("unhandledRejection",n,r):ys(ls,r,n)})),t.rejection=Io||_s(t)?2:1,e.error))throw e.value}))},_s=function(t){return 1!==t.rejection&&!t.parent},gs=function(t){Bo(Zo,Lo,(function(){var e=t.facade;Io?us.emit("rejectionHandled",e):ys("rejectionhandled",e,t.value)}))},bs=function(t,e,r){return function(n){t(e,n,r)}},ms=function(t,e,r){t.done||(t.done=!0,r&&(t=r),t.value=e,t.state=2,ps(t,!0))},ks=function(t,e,r){if(!t.done){t.done=!0,r&&(t=r);try{if(t.facade===e)throw os("Promise can't be resolved itself");var n=ds(e);n?Xo((function(){var r={done:!1};try{Bo(n,e,bs(ks,r,t),bs(ms,r,t))}catch(e){ms(r,e,t)}})):(t.value=e,t.state=1,ps(t,!1))}catch(e){ms({done:!1},e,t)}}};if($o&&(as=(is=function(t){Fo(this,as),Do(t),Bo(Ao,this);var e=es(this);try{t(bs(ks,e),bs(ms,e))}catch(t){ms(e,t)}}).prototype,(Ao=function(t){rs(this,{type:qo,done:!1,notified:!1,parent:!1,reactions:new Go,rejection:!1,state:0,value:void 0})}).prototype=zo(as,"then",(function(t,e){var r=es(this),n=hs(Vo(this,is));return r.parent=!0,n.ok=!Mo(t)||t,n.fail=Mo(e)&&e,n.domain=Io?us.domain:void 0,0==r.state?r.reactions.add(n):Xo((function(){vs(n,r)})),n.promise})),Oo=function(){var t=new Ao,e=es(t);this.promise=t,this.resolve=bs(ks,e),this.reject=bs(ms,e)},Jo.f=hs=function(t){return t===is||undefined===t?new Oo(t):cs(t)},Mo(Ko)&&ns!==Object.prototype)){So=ns.then,ts||zo(ns,"then",(function(t,e){var r=this;return new is((function(t,e){Bo(So,r,t,e)})).then(t,e)}),{unsafe:!0});try{delete ns.constructor}catch(t){}Po&&Po(ns,as)}Uo({global:!0,wrap:!0,forced:$o},{Promise:is}),No(is,qo,!1),Co(qo);var xs={},Es=xs,Ts=$t("iterator"),Rs=Array.prototype,As=bi,Os=_t,Ss=xs,Us=$t("iterator"),Is=function(t){if(null!=t)return Os(t,Us)||Os(t,"@@iterator")||Ss[As(t)]},Ls=c,Bs=yt,zs=Ie,Ps=lt,Ns=Is,Cs=n.TypeError,Ds=c,Ms=Ie,js=_t,Fs=ta,Vs=c,Zs=Ie,Xs=lt,Ws=function(t){return void 0!==t&&(Es.Array===t||Rs[Ts]===t)},Hs=sn,Gs=H,Ys=function(t,e){var r=arguments.length<2?Ns(t):e;if(Bs(r))return zs(Ls(r,t));throw Cs(Ps(t)+" is not iterable")},Ks=Is,Js=function(t,e,r){var n,i;Ms(t);try{if(!(n=js(t,"return"))){if("throw"===e)throw r;return r}n=Ds(n,t)}catch(t){i=!0,n=t}if("throw"===e)throw r;if(i)throw n;return Ms(n),r},qs=n.TypeError,$s=function(t,e){this.stopped=t,this.result=e},Qs=$s.prototype,tu=function(t,e,r){var n,i,a,o,s,u,h,c=r&&r.that,f=!(!r||!r.AS_ENTRIES),l=!(!r||!r.IS_ITERATOR),d=!(!r||!r.INTERRUPTED),v=Fs(e,c),p=function(t){return n&&Js(n,"normal",t),new $s(!0,t)},y=function(t){return f?(Zs(t),d?v(t[0],t[1],p):v(t[0],t[1])):d?v(t,p):v(t)};if(l)n=t;else{if(!(i=Ks(t)))throw qs(Xs(t)+" is not iterable");if(Ws(i)){for(a=0,o=Hs(t);o>a;a++)if((s=y(t[a]))&&Gs(Qs,s))return s;return new $s(!1)}n=Ys(t,i)}for(u=n.next;!(h=Vs(u,n)).done;){try{s=y(h.value)}catch(t){Js(n,"throw",t)}if("object"==typeof s&&s&&Gs(Qs,s))return s}return new $s(!1)};function eu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function ru(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),h=n.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),A(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;A(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var ih,ah,oh,sh="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,uh=!a((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),hh=n,ch=Nt,fh=M,lh=Bt,dh=uh,vh=dr("IE_PROTO"),ph=hh.Object,yh=ph.prototype,wh=dh?ph.getPrototypeOf:function(t){var e=lh(t);if(ch(e,vh))return e[vh];var r=e.constructor;return fh(r)&&e instanceof r?r.prototype:e instanceof ph?yh:null},_h=sh,gh=o,bh=n,mh=M,kh=F,xh=Nt,Eh=bi,Th=lt,Rh=We,Ah=Kr,Oh=Te.f,Sh=H,Uh=wh,Ih=ri,Lh=$t,Bh=Ft,zh=bh.Int8Array,Ph=zh&&zh.prototype,Nh=bh.Uint8ClampedArray,Ch=Nh&&Nh.prototype,Dh=zh&&Uh(zh),Mh=Ph&&Uh(Ph),jh=Object.prototype,Fh=bh.TypeError,Vh=Lh("toStringTag"),Zh=Bh("TYPED_ARRAY_TAG"),Xh=Bh("TYPED_ARRAY_CONSTRUCTOR"),Wh=_h&&!!Ih&&"Opera"!==Eh(bh.opera),Hh=!1,Gh={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Yh={BigInt64Array:8,BigUint64Array:8},Kh=function(t){if(!kh(t))return!1;var e=Eh(t);return xh(Gh,e)||xh(Yh,e)};for(ih in Gh)(oh=(ah=bh[ih])&&ah.prototype)?Rh(oh,Xh,ah):Wh=!1;for(ih in Yh)(oh=(ah=bh[ih])&&ah.prototype)&&Rh(oh,Xh,ah);if((!Wh||!mh(Dh)||Dh===Function.prototype)&&(Dh=function(){throw Fh("Incorrect invocation")},Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih],Dh);if((!Wh||!Mh||Mh===jh)&&(Mh=Dh.prototype,Wh))for(ih in Gh)bh[ih]&&Ih(bh[ih].prototype,Mh);if(Wh&&Uh(Ch)!==Mh&&Ih(Ch,Mh),gh&&!xh(Mh,Vh))for(ih in Hh=!0,Oh(Mh,Vh,{get:function(){return kh(this)?this[Zh]:void 0}}),Gh)bh[ih]&&Rh(bh[ih],Zh,ih);var Jh={NATIVE_ARRAY_BUFFER_VIEWS:Wh,TYPED_ARRAY_CONSTRUCTOR:Xh,TYPED_ARRAY_TAG:Hh&&Zh,aTypedArray:function(t){if(Kh(t))return t;throw Fh("Target is not a typed array")},aTypedArrayConstructor:function(t){if(mh(t)&&(!Ih||Sh(Dh,t)))return t;throw Fh(Th(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if(gh){if(r)for(var i in Gh){var a=bh[i];if(a&&xh(a.prototype,t))try{delete a.prototype[t]}catch(r){try{a.prototype[t]=e}catch(t){}}}Mh[t]&&!r||Ah(Mh,t,r?e:Wh&&Ph[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if(gh){if(Ih){if(r)for(n in Gh)if((i=bh[n])&&xh(i,t))try{delete i[t]}catch(t){}if(Dh[t]&&!r)return;try{return Ah(Dh,t,r?e:Wh&&Dh[t]||e)}catch(t){}}for(n in Gh)!(i=bh[n])||i[t]&&!r||Ah(i,t,e)}},isView:function(t){if(!kh(t))return!1;var e=Eh(t);return"DataView"===e||xh(Gh,e)||xh(Yh,e)},isTypedArray:Kh,TypedArray:Dh,TypedArrayPrototype:Mh},qh=A,$h=n,Qh=Array.isArray||function(t){return"Array"==qh(t)},tc=Di,ec=F,rc=$t("species"),nc=$h.Array,ic=function(t){var e;return Qh(t)&&(e=t.constructor,(tc(e)&&(e===nc||Qh(e.prototype))||ec(e)&&null===(e=e[rc]))&&(e=void 0)),void 0===e?nc:e},ac=ta,oc=B,sc=Bt,uc=sn,hc=function(t,e){return new(ic(t))(0===e?0:e)},cc=x([].push),fc=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,a=6==t,o=7==t,s=5==t||a;return function(u,h,c,f){for(var l,d,v=sc(u),p=oc(v),y=ac(h,c),w=uc(p),_=0,g=f||hc,b=e?g(u,w):r||o?g(u,0):void 0;w>_;_++)if((s||_ in p)&&(d=y(l=p[_],_,v),t))if(e)b[_]=d;else if(d)switch(t){case 3:return!0;case 5:return l;case 6:return _;case 2:cc(b,l)}else switch(t){case 4:return!1;case 7:cc(b,l)}return a?-1:n||i?i:b}},lc={forEach:fc(0),map:fc(1),filter:fc(2),some:fc(3),every:fc(4),find:fc(5),findIndex:fc(6),filterReject:fc(7)},dc=Wi,vc=Jh.TYPED_ARRAY_CONSTRUCTOR,pc=Jh.aTypedArrayConstructor,yc=lc.map,wc=function(t){return pc(dc(t,t[vc]))},_c=Jh.aTypedArray;(0,Jh.exportTypedArrayMethod)("map",(function(t){return yc(_c(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(wc(t))(e)}))}));var gc=o,bc=$e.EXISTS,mc=x,kc=Te.f,xc=Function.prototype,Ec=mc(xc.toString),Tc=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Rc=mc(Tc.exec);gc&&!bc&&kc(xc,"name",{configurable:!0,get:function(){try{return Rc(Tc,Ec(this))[1]}catch(t){return""}}});var Ac=function(t){cu(r,t);var e=_u(r);function r(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ou(this,r),(t=e.call(this,n)).name="XnbError",t.message=n,Error.captureStackTrace(yu(t),r),t}return uu(r)}(pu(Error));function Oc(t){for(var e=[],r=[],n=0;n")}return r.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var r=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(r,"[]"))return"Array<".concat(simplifyType(r.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===r){var n=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n)}for(var i=0,a=Object.values(t.readers);i/);return r=r?r[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:r}}},{key:"getReaderTypeList",value:function(e){return t.getReader(e).parseTypeList()}},{key:"getReader",value:function(e){var r=t.getTypeInfo(e),n=r.type,i=r.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(n,"Reader")))return vu(t.readers["".concat(n,"Reader")],i);throw new Ac('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var r=t.simplifyType(e);return t.getReader(r)}}]),t}();hu(Sc,"readers",{});var Uc=[192,224,240],Ic=128,Lc=63,Bc=[55296,56320],zc=1023;function Pc(t){return t<128?[t]:t<2048?[Uc[0]|t>>6,Ic|t&Lc]:t<65536?[Uc[1]|t>>12,Ic|t>>6&Lc,Ic|t&Lc]:[Uc[2]|t>>18,Ic|t>>12&Lc,Ic|t>>6&Lc,Ic|t&Lc]}function Nc(t){return t<65535?[t]:[Bc[0]|(t-=65536)>>10&zc,Bc[1]|t&zc]}function Cc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var r=t.length;return 1===r?t[0]:2===r?((t[0]^Uc[0])<<6)+(t[1]^Ic):3===r?((t[0]^Uc[1])<<12)+((t[1]^Ic)<<6)+(t[2]^Ic):((t[0]^Uc[2])<<18)+((t[1]^Ic)<<12)+((t[2]^Ic)<<6)+(t[3]^Ic)}function Dc(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&zc)<<10)+(t[1]&zc)+65536}function Mc(t){return function(t){for(var e=[],r=0;r1&&void 0!==arguments[1])||arguments[1];ou(this,t),this._endianus=r,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return uu(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,r=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:0,e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0;){var n=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(n&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,r|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),Vc=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ou(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return uu(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e),n=0;n>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),Zc=256,Xc=0,Wc=1,Hc=2,Gc=3,Yc=656,Kc=function(){function t(e){if(ou(this,t),this.window_size=1<21)throw new Ac("Window size out of range!");if(!t.extra_bits.length)for(var r=0,n=0;r<=50;r+=2)t.extra_bits[r]=t.extra_bits[r+1]=n,0!=r&&n<17&&n++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case Hc:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case Wc:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(Yc,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case Gc:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new Ac("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new Ac("Cannot run outside of window frame.");switch(this.block_type){case Hc:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Yc,12);if(h>3;if(f>2){var l=t.extra_bits[f];if(f=t.position_base[f]-2,l>3)l-=3,f+=e.readLZXBits(l)<<3,f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?f+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?f+=e.readLZXBits(l):f=1;this.R2=this.R1,this.R1=this.R0,this.R0=f}else 0===f?f=this.R0:1==f?(f=this.R1,this.R1=this.R0,this.R0=f):(f=this.R2,this.R2=this.R0,this.R0=f);var d=this.window_posn,v=void 0;if(u-=c,this.window_posn>=f)v=d-f;else{v=d+(this.window_size-f);var p=f-this.window_posn;if(p0;)this.win[d++]=this.win[v++];v=0}}for(this.window_posn+=c;c-- >0;)this.win[d++]=this.win[v++]}}break;case Wc:for(;u>0;){var y=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,Yc,12);if(y>3;if(_>2){if(3!=_){var g=t.extra_bits[_],b=e.readLZXBits(g);_=t.position_base[_]-2+b}else _=1;this.R2=this.R1,this.R1=this.R0,this.R0=_}else 0===_?_=this.R0:1==_?(_=this.R1,this.R1=this.R0,this.R0=_):(_=this.R2,this.R2=this.R0,this.R0=_);var m=this.window_posn,k=void 0;if(u-=w,this.window_posn>=_)k=m-_;else{k=m+(this.window_size-_);var x=_-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=w;w-- >0;)this.win[m++]=this.win[k++]}}break;case Gc:if(e.bytePosition+u>n)throw new Ac("Overrun!"+n+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new Ac("Overrun table!");for(var c=o;c-- >0;)n[h++]=u}o>>=1}if(i==a)return n;for(var f=i;f>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var v=0;v>16,y=0;y>15-y&1&&p++;if(n[p]=v,(i+=o)>a)throw new Ac("Overrun table during decoding.")}o>>=1}if(i==a)return n;throw new Ac("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,r,n,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=n){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=n)}return t.bitPosition+=r[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var r=this.R2;this.R2=this.R0,this.R0=r}}}]),t}();Kc.position_base=[],Kc.extra_bits=[];var Jc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"decompress",value:function(t,e,r){for(var n,i,a=0,o=new Kc(16),s=new Vc(r);a65536||i>65536)throw new Ac("Invalid size read in compression content.");s.write(o.decompress(t,i,n)),a+=n}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),qc=function(){function t(){ou(this,t)}return uu(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}},{key:"readU32",value:function(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}},{key:"writeU32",value:function(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}},{key:"imul",value:function(t,e){var r=65535&t,n=65535&e;return r*n+((t>>>16)*n+r*(e>>>16)<<16)|0}}]),t}(),$c=65536,Qc=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),r=0;r=13)for(var d=67;r+4>>0;if(a=i[p=(p>>16^p)>>>0&65535]-1,i[p]=r+1,a<0||r-a>>>16>0||qc.readU32(t,a)!==v)r+=d++>>6;else{for(d=67,h=r-o,u=r-a,a+=4,s=r+=4;r=Qc){for(e[c++]=240+y,l=h-Qc;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=(h<<4)+y;for(var w=0;w>8,s>=15){for(l=s-15;l>=255;l-=255)e[c++]=255;e[c++]=l}o=r}}if(0===o)return 0;if((h=f-o)>=Qc){for(e[c++]=240,l=h-Qc;l>=255;l-=255)e[c++]=255;e[c++]=l}else e[c++]=h<<4;for(r=o;r2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,c=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(r=15&f,n=t[s++]|t[s++]<<8,15===r)for(;r+=t[s],255===t[s++];);if(r+=4,c&&1===n)e.fill(0|e[h-1],h,h+r),h+=r;else if(c&&n>r&&r>31)e.copyWithin(h,h-n,h-n+r),h+=r;else for(a=(o=h-n)+r;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var r=0,n=t.length,i=0,a=Math.max(32,n+(n>>1)+7),o=new Uint8Array(a>>3<<3);r=55296&&s<=56319){if(r=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+r/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var r=new Uint8Array(t),n=0,i=r.length,a=[];n65535&&(c-=65536,a.push(c>>>10&1023|55296),c=56320|1023&c),a.push(c)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},pf={};function yf(t){var e=pf[t];if(void 0!==e)return e.exports;var r=pf[t]={exports:{}};return vf[t].call(r.exports,r,r.exports,yf),r.exports}yf.d=function(t,e){for(var r in e)yf.o(e,r)&&!yf.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},yf.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var wf={};!function(){yf.d(wf,{P:function(){return Ar},m:function(){return Rr}}),yf(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,r=function(){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r);var n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=n?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return uu(r,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="",r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(r),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),r}();function n(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);n(u);var h=new Array(60);n(h);var c=new Array(512);n(c);var f=new Array(256);n(f);var l=new Array(29);n(l);var d,v,p,y=new Array(30);function w(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}function _(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(y);var g=function(t){return t<256?c[t]:c[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,r){t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<>>=1,r<<=1}while(--e>0);return r>>>1},E=function(t,e,r){var n,i,a=new Array(16),o=0;for(n=1;n<=15;n++)a[n]=o=o+r[n-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},T=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,r,n){var i=2*e,a=2*r;return t[i]>1;r>=1;r--)O(t,a,r);i=u;do{r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,a,1),n=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=n,a[2*i]=a[2*r]+a[2*n],t.depth[i]=(t.depth[r]>=t.depth[n]?t.depth[r]:t.depth[n])+1,a[2*r+1]=a[2*n+1]=i,t.heap[1]=i++,O(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var r,n,i,a,o,s,u=e.dyn_tree,h=e.max_code,c=e.stat_desc.static_tree,f=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,v=e.stat_desc.max_length,p=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,r=t.heap_max+1;r<573;r++)(a=u[2*u[2*(n=t.heap[r])+1]+1]+1)>v&&(a=v,p++),u[2*n+1]=a,n>h||(t.bl_count[a]++,o=0,n>=d&&(o=l[n-d]),s=u[2*n],t.opt_len+=s*(a+o),f&&(t.static_len+=s*(c[2*n+1]+o)));if(0!==p){do{for(a=v-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[v]--,p-=2}while(p>0);for(a=v;0!==a;a--)for(n=t.bl_count[a];0!==n;)(i=t.heap[--r])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),n--)}}(t,e),E(a,h,t.bl_count)},I=function(t,e,r){var n,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(r+1)+1]=65535,n=0;n<=r;n++)i=o,o=e[2*(n+1)+1],++s>=7;n<30;n++)for(y[n]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),U(t,t.l_desc),U(t,t.d_desc),o=function(t){var e;for(I(t,t.dyn_ltree,t.l_desc.max_code),I(t,t.dyn_dtree,t.d_desc.max_code),U(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=r+5,r+4<=i&&-1!==e?z(t,e,r,n):4===t.strategy||a===i?(m(t,2+(n?1:0),3),S(t,u,h)):(m(t,4+(n?1:0),3),function(t,e,r,n){var i;for(m(t,e-257,5),m(t,r-1,5),m(t,n-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(f[r]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},M=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},j=function(t,e,r,n){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+e[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},F=new Uint32Array(function(){for(var t,e=[],r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e}()),V=function(t,e,r,n){var i=F,a=n+r;t^=-1;for(var o=n;o>>8^i[255&(t^e[o])];return-1^t},Z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},W=P,H=N,G=C,Y=D,K=M,J=X.Z_NO_FLUSH,q=X.Z_PARTIAL_FLUSH,$=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,rt=X.Z_STREAM_END,nt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ct=X.Z_FIXED,ft=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,vt=262,pt=103,yt=113,wt=666,_t=function(t,e){return t.msg=Z[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,r){return(e<t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Tt=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,r,n){var i=t.avail_in;return i>n&&(i=n),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),1===t.state.wrap?t.adler=j(t.adler,e,i,r):2===t.state.wrap&&(t.adler=V(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var r,n,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-vt?t.strstart-(t.w_size-vt):0,h=t.window,c=t.w_mask,f=t.prev,l=t.strstart+dt,d=h[a+o-1],v=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(r=e)+o]===v&&h[r+o-1]===d&&h[r]===h[a]&&h[++r]===h[a+1]){a+=2,r++;do{}while(h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&h[++a]===h[++r]&&ao){if(t.match_start=e,o=n,n>=s)break;d=h[a+o-1],v=h[a+o]}}}while((e=f[e&c])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ot=function(t){var e,r,n,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-vt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=r=t.hash_size;do{n=t.head[--e],t.head[e]=n>=o?n-o:0}while(--r);e=r=o;do{n=t.prev[--e],t.prev[e]=n>=o?n-o:0}while(--r);i+=o}if(0===t.strm.avail_in)break;if(r=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=r,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-vt&&(t.match_length=At(t,r)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Ut=function(t,e){for(var r,n,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((n=Y(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Lt=[new It(0,0,0,0,(function(t,e){var r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ot(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+r;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-vt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,St),new It(4,5,16,8,St),new It(4,6,32,32,St),new It(4,4,16,16,Ut),new It(8,16,32,32,Ut),new It(8,16,128,128,Ut),new It(8,32,128,256,Ut),new It(32,128,258,1024,Ut),new It(32,258,258,4096,Ut)];function Bt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var zt=function(t){var e,r=function(t){if(!t||!t.state)return _t(t,nt);t.total_in=t.total_out=0,t.data_type=ft;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:yt,t.adler=2===e.wrap?0:1,e.last_flush=J,W(e),et}(t);return r===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Lt[e.level].max_lazy,e.good_match=Lt[e.level].good_length,e.nice_match=Lt[e.level].nice_length,e.max_chain_length=Lt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),r},Pt=function(t,e,r,n,i,a){if(!t)return nt;var o=1;if(e===ot&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>9||r!==lt||n<8||n>15||e<0||e>9||a<0||a>ct)return _t(t,nt);8===n&&(n=9);var s=new Bt;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<tt||e<0)return t?_t(t,nt):nt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===wt&&e!==Q)return _t(t,0===t.avail_out?at:nt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=V(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=yt);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=yt,Tt(i,o),0!==i.strstart&&(Tt(i,t.adler>>>16),Tt(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(r=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){r=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>r&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),kt(t),r=i.pending,i.pending===i.pending_buf_size)){n=1;break}n=i.gzindexr&&(t.adler=V(t.adler,i.pending_buf,i.pending-r,r)),0===n&&(i.status=pt)}else i.status=pt;if(i.status===pt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=yt)):i.status=yt),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return _t(t,at);if(i.status===wt&&0!==t.avail_in)return _t(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==wt){var s=i.strategy===ut?function(t,e){for(var r;;){if(0===t.lookahead&&(Ot(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var r,n,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ot(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((n=o[i=t.strstart-1])===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+dt;do{}while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Lt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=wt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===q?K(i):e!==tt&&(H(i,0,0,!1),e===$&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?rt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Tt(i,t.adler>>>16),Tt(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:rt)},Ct=function(t){if(!t||!t.state)return nt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==pt&&e!==yt&&e!==wt?_t(t,nt):(t.state=null,e===yt?_t(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Mt=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var r=e.shift();if(r){if("object"!=nu(r))throw new TypeError(r+"must be non-object");for(var n in r)Dt(r,n)&&(t[n]=r[n])}}return t},jt=function(t){for(var e=0,r=0,n=t.length;r=252?6:Zt>=248?5:Zt>=240?4:Zt>=224?3:Zt>=192?2:1;Vt[254]=Vt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,r,n,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&r):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|63&r):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|63&r);return e},Wt=function(t,e){var r,n,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(n=0,r=0;r4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var r="",n=0;nt.length&&(e=t.length);for(var r=e-1;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Vt[t[r]]>e?r:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Yt=Object.prototype.toString,Kt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,qt=X.Z_FULL_FLUSH,$t=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,re=X.Z_DEFAULT_STRATEGY,ne=X.Z_DEFLATED;function ie(t){this.options=Mt({level:ee,method:ne,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Qt)throw new Error(Z[r]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Yt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=function(t,e){var r=e.length;if(!t||!t.state)return nt;var n=t.state,i=n.wrap;if(2===i||1===i&&42!==n.status||n.lookahead)return nt;if(1===i&&(t.adler=j(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){0===i&&(bt(n.head),n.strstart=0,n.block_start=0,n.insert=0);var a=new Uint8Array(n.w_size);a.set(e.subarray(r-n.w_size,r),0),e=a,r=n.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Ot(n);n.lookahead>=3;){var h=n.strstart,c=n.lookahead-2;do{n.ins_h=mt(n,n.ins_h,n.window[h+3-1]),n.prev[h&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=h,h++}while(--c);n.strstart=h,n.lookahead=2,Ot(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,n.wrap=i,et}(this.strm,n),r!==Qt)throw new Error(Z[r]);this._dict_set=!0}}function ae(t,e){var r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||Z[r.err];return r.result}ie.prototype.push=function(t,e){var r,n,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(n=e===~~e?e:!0===e?$t:Kt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Yt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(n===Jt||n===qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((r=Nt(i,n))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ct(this.strm),this.onEnd(r),this.ended=!0,r===Qt;if(0!==i.avail_out){if(n>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=jt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,T,R=t.state;r=t.next_in,E=t.input,n=r+(t.avail_in-5),i=t.next_out,T=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,c=R.wnext,f=R.window,l=R.hold,d=R.bits,v=R.lencode,p=R.distcode,y=(1<>>=g=_>>>24,d-=g,0===(g=_>>>16&255))T[i++]=65535&_;else{if(!(16&g)){if(0==(64&g)){_=v[(65535&_)+(l&(1<>>=g,d-=g),d<15&&(l+=E[r++]<>>=g=_>>>24,d-=g,!(16&(g=_>>>16&255))){if(0==(64&g)){_=p[(65535&_)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=f,0===c){if(k+=u-g,g2;)T[i++]=x[k++],T[i++]=x[k++],T[i++]=x[k++],b-=3;b&&(T[i++]=x[k++],b>1&&(T[i++]=x[k++]))}else{k=i-m;do{T[i++]=T[k++],T[i++]=T[k++],T[i++]=T[k++],b-=3}while(b>2);b&&(T[i++]=T[k++],b>1&&(T[i++]=T[k++]))}break}}break}}while(r>3,l&=(1<<(d-=b<<3))-1,t.next_in=r,t.next_out=i,t.avail_in=r=1&&0===U[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(I[1]=0,_=1;_<15;_++)I[_+1]=I[_]+U[_];for(g=0;g852||2===t&&R>592)return 1;for(;;){v=_-E,o[g]d?(p=L[B+o[g]],y=O[S+o[g]]):(p=96,y=0),u=1<<_-E,b=h=1<>E)+(h-=u)]=v<<24|p<<16|y|0}while(0!==h);for(u=1<<_-1;A&u;)u>>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--U[_]){if(_===m)break;_=e[r+o[g]]}if(_>k&&(A&f)!==c){for(0===E&&(E=k),l+=b,T=1<<(x=_-E);x+E852||2===t&&R>592)return 1;i[c=A&f]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=_-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,ve=X.Z_BLOCK,pe=X.Z_TREES,ye=X.Z_OK,we=X.Z_STREAM_END,_e=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Te=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Oe,Se,Ue=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ye}(t)},Ie=!0,Le=function(t){if(Ie){Oe=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Oe,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Ie=!1}t.lencode=Oe,t.lenbits=9,t.distcode=Se,t.distbits=5},Be=function(t,e,r,n){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,Ue(t))}(t,e);return n!==ye&&(t.state=null),n},Ne=function(t,e){var r,n,i,a,o,s,u,h,c,f,l,d,v,p,y,w,_,g,b,m,k,x,E,T,R=0,A=new Uint8Array(4),O=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(r=t.state).mode===Ee&&(r.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,f=s,l=u,x=ye;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,A,2,0),h=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",r.mode=Te;break}if((15&h)!==xe){t.msg="unknown compression method",r.mode=Te;break}if(c-=4,k=8+(15&(h>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Te;break}r.dmax=1<>8&1),512&r.flags&&(A[0]=255&h,A[1]=h>>>8&255,r.check=V(r.check,A,2,0)),h=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,r.check=V(r.check,A,4,0)),h=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>8),512&r.flags&&(A[0]=255&h,A[1]=h>>>8&255,r.check=V(r.check,A,2,0)),h=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===s)break t;s--,h+=n[a++]<>>8&255,r.check=V(r.check,A,2,0)),h=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),k)),512&r.flags&&(r.check=V(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break t;d=0;do{k=n[a+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&d>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ee;break;case 10:for(;c<32;){if(0===s)break t;s--,h+=n[a++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===s)break t;s--,h+=n[a++]<>>=1)){case 0:r.mode=14;break;case 1:if(Le(r),r.mode=20,e===pe){h>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Te}h>>>=2,c-=2;break;case 14:for(h>>>=7&c,c-=7&c;c<32;){if(0===s)break t;s--,h+=n[a++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Te;break}if(r.length=65535&h,h=0,c=0,r.mode=15,e===pe)break t;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(n.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,r.length-=d;break}r.mode=Ee;break;case 17:for(;c<14;){if(0===s)break t;s--,h+=n[a++]<>>=5,c-=5,r.ndist=1+(31&h),h>>>=5,c-=5,r.ncode=4+(15&h),h>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Te;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[O[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,E={bits:r.lenbits},x=le(0,r.lens,0,19,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid code lengths set",r.mode=Te;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,_=65535&R,!((y=R>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=y,c-=y,r.lens[r.have++]=_;else{if(16===_){for(T=y+2;c>>=y,c-=y,0===r.have){t.msg="invalid bit length repeat",r.mode=Te;break}k=r.lens[r.have-1],d=3+(3&h),h>>>=2,c-=2}else if(17===_){for(T=y+3;c>>=y)),h>>>=3,c-=3}else{for(T=y+7;c>>=y)),h>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Te;break}for(;d--;)r.lens[r.have++]=k}}if(r.mode===Te)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Te;break}if(r.lenbits=9,E={bits:r.lenbits},x=le(1,r.lens,0,r.nlen,r.lencode,0,r.work,E),r.lenbits=E.bits,x){t.msg="invalid literal/lengths set",r.mode=Te;break}if(r.distbits=6,r.distcode=r.distdyn,E={bits:r.distbits},x=le(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,E),r.distbits=E.bits,x){t.msg="invalid distances set",r.mode=Te;break}if(r.mode=20,e===pe)break t;case 20:r.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,r.hold=h,r.bits=c,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,h=r.hold,c=r.bits,r.mode===Ee&&(r.back=-1);break}for(r.back=0;w=(R=r.lencode[h&(1<>>16&255,_=65535&R,!((y=R>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&R,!(g+(y=R>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,r.length=_,0===w){r.mode=26;break}if(32&w){r.back=-1,r.mode=Ee;break}if(64&w){t.msg="invalid literal/length code",r.mode=Te;break}r.extra=15&w,r.mode=22;case 22:if(r.extra){for(T=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;w=(R=r.distcode[h&(1<>>16&255,_=65535&R,!((y=R>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>g)])>>>16&255,_=65535&R,!(g+(y=R>>>24)<=c);){if(0===s)break t;s--,h+=n[a++]<>>=g,c-=g,r.back+=g}if(h>>>=y,c-=y,r.back+=y,64&w){t.msg="invalid distance code",r.mode=Te;break}r.offset=_,r.extra=15&w,r.mode=24;case 24:if(r.extra){for(T=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Te;break}r.mode=25;case 25:if(0===u)break t;if(d=l-u,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Te;break}d>r.wnext?(d-=r.wnext,v=r.wsize-d):v=r.wnext-d,d>r.length&&(d=r.length),p=r.window}else p=i,v=o-r.offset,d=r.length;d>u&&(d=u),u-=d,r.length-=d;do{i[o++]=p[v++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===u)break t;i[o++]=r.length,u--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===s)break t;s--,h|=n[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var r=Pe(this.strm,e.windowBits);if(r!==Ze)throw new Error(Z[r]);if(this.header=new Me,function(t,e){if(!t||!t.state)return ge;var r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===je.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary))!==Ze))throw new Error(Z[r])}function Je(t,e){var r=new Ke(e);if(r.push(t),r.err)throw r.msg||Z[r.err];return r.result}Ke.prototype.push=function(t,e){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===je.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ne(a,n))===We&&s&&((r=De(a,s))===Ze?r=Ne(a,n):r===Ge&&(r=We));a.avail_in>0&&r===Xe&&a.state.wrap>0&&0!==t[a.next_in];)ze(a),r=Ne(a,n);switch(r){case He:case Ge:case We:case Ye:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Xe))if("string"===this.options.to){var u=Ht(a.output,a.next_out),h=a.next_out-u,c=Wt(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(c)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Ze||0!==i){if(r===Xe)return r=Ce(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ke.prototype.onData=function(t){this.chunks.push(t)},Ke.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=jt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var qe=oe,$e=Ke,Qe=Je,tr=[137,80,78,71,13,10,26,10],er=[],rr=0;rr<256;rr++){for(var nr=rr,ir=0;ir<8;ir++)1&nr?nr=3988292384^nr>>>1:nr>>>=1;er[rr]=nr}var ar,or,sr,ur;function hr(t,e){return(4294967295^function(t,e,r){for(var n=4294967295,i=0;i>>8;return n}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(ar||(ar={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(or||(or={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(sr||(sr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(ur||(ur={}));var cr=new Uint8Array(0),fr=new Uint16Array([255]),lr=255===new Uint8Array(fr.buffer)[0],dr=function(t){cu(r,t);var e=_u(r);function r(t){var n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ou(this,r),n=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return n._checkCrc=o,n._inflator=new $e,n._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},n._end=!1,n._hasPalette=!1,n._palette=[],n._compressionMethod=or.UNKNOWN,n._filterMethod=sr.UNKNOWN,n._interlaceMethod=ur.UNKNOWN,n._colorType=-1,n.setBigEndian(),n}return uu(r,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=f}else this._png.data=s}}]),r}(r);function vr(t,e,r){for(var n=0;n>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function _r(t,e,r,n,i){var a=0;if(0===r.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ou(this,n),(r=e.call(this))._colorType=ar.UNKNOWN,r._zlibOptions=ru(ru({},mr),i.zlib),r._png=r._checkData(t),r.setBigEndian(),r}return uu(n,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tr)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(or.DEFLATE),this.writeByte(sr.ADAPTIVE),this.writeByte(ur.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,n=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new r).setBigEndian(),h=0,c=0;c0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Er(t,e,r,n){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,r="";return"number"==typeof e?r=gu(" ",Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),bf(t,r,-1)}var kf=function(){function t(e,r,n){ou(this,t),this.startingLine=n||0,this.lineIndex=-1;for(var i=[],a=0;a=r;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;mu(n,'"')&&(i=n.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],n=n.replace(a[0],"")),i?(r||(r={}),o=i[1],s=n.replace(i[0],"").trim()):mu(n,"-")&&(r||(r=[]),s=n.slice(1).trim()),s=s?Ef(s,u):xf(t.nextGroup(),u),Array.isArray(r)?r.push(s):r[o]=s}return e&&(r={type:e,data:r}),r}function Ef(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Tf(t){var e=t.replace(/\t/g,"\t").split("\n");return xf(new kf(e))}function Rf(t){var e;if(Array.isArray(t)){e=[];for(var r=0;r","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var c=function(t,e){var r=[],n=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(Af(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(mu(u,"Nullable")){var h,c,f=u.split(":"),l=f[0],d=f[1],v=void 0===d?1:d;if(v=+v,null===i)h=null,c=s+v;else if("object"!==nu(i)||i&&0!==Object.keys(i).length){var p=t(i,[].concat(a),s+1);h=p.converted,c=p.traversed}else h={type:e[s+1],data:Rf(i)},c=s+v;return{converted:{type:l,data:{data:h}},traversed:c}}if(Of(u))return"Texture2D"===u?(r.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&n.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var y=s,w=!0,_=!mu(u,"Dictionary")&&!mu(u,"Array")&&!mu(u,"List"),g=Object.keys(i),b=0;b0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function If(t){var e={},r=t.xnbData,n=r.compressed,i=r.readerData,a=r.hiDef,o=r.target;return e.header={target:o,formatVersion:5,compressed:n?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=Rf(i),e.content=Sf(t.content),"SpriteFont"===Sc.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function Lf(t,e){if(t&&"object"==nu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var r=Object.keys(t),n=0;n1&&void 0!==arguments[1]&&arguments[1],r=Lf(t,"export");if(r){var n=r.value,i=n.type,a=n.data;return"Texture2D"===i&&(a=gf(n.width,n.height,new Uint8Array(a))),Nf(a,i)}if(e){var o=JSON.stringify(t,null,4);return Nf(o,"JSON")}return null}function Df(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(n&&a&&(n=!1),!t.hasOwnProperty("content"))throw new Ac("Invalid object!");var u=[],h=t.content,c=Cf(h,a);if(null!==c&&u.push(c),a)return u;var f=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(zf(e.type)):"".concat(e.type,".").concat(zf(e.type)):e}),4),l=f;return n&&(l=mf(Uf(t))),u.unshift(Nf(l,n?"yaml":"JSON")),u}function Mf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function jf(t){return Ff.apply(this,arguments)}function Ff(){return(Ff=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Vf(t){return Zf.apply(this,arguments)}function Zf(){return(Zf=au(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xf(t,e){return Wf.apply(this,arguments)}function Wf(){return Wf=au(regeneratorRuntime.mark((function t(e,r){var n,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,Vf(r.png);case 3:return n=t.sent,i=_f(new Uint8Array(n)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,Vf(r.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,Vf(r.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,jf(r.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),Wf.apply(this,arguments)}function Hf(t){return Gf.apply(this,arguments)}function Gf(){return Gf=au(regeneratorRuntime.mark((function t(e){var r,n,i,a,o,s,u,h,c,f,l,d,v=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=v.length>1&&void 0!==v[1]?v[1]:{},n=r.compression,i=void 0===n?"default":n,a=e.json||e.yaml){t.next=5;break}throw new Ac("There is no JSON or YAML file to pack!");case 5:return t.next=7,jf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):If(Tf(o)),null!==(u=Mf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new Ac("".concat(a.name,' does not have "content".'));case 14:if(!(h=Lf(s.content,"export"))){t.next=21;break}return c=h.parent,f=h.value,l=Bf(f),d=l[1],t.next=20,Xf(d,e);case 20:c.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),Gf.apply(this,arguments)}function Yf(t){return Kf.apply(this,arguments)}function Kf(){return(Kf=au(regeneratorRuntime.mark((function t(e){var r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(r=Bf(e.name),"xnb"===r[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return n=t.sent,t.abrupt("return",Jf(n));case 8:return t.abrupt("return",Jf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Jf(t){return(new df).load(t)}function qf(t){var e=Cf(t.content,!0),r=e.data,n=e.extension;return new hf(r,n)}function $f(t){for(var e={},r=0;r")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(tl),nl=[55296,56320];function il(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function al(t){var e=function(t){for(var e=ku({length:t.length},(function(e,r){return t.charCodeAt(r)})),r=[],n=0;n>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(tl),cl=function(t){cu(r,t);var e=_u(r);function r(t,n){var i;if(ou(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return uu(r,[{key:"read",value:function(t,e){for(var r={},n=(new el).read(t),i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.key.parseTypeList(),this.value.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(tl),fl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(tl),ll=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new el).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new el).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(tl),dl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(tl),vl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){for(var r=(new el).read(t),n=[],i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(tl),pl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new ul,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new ul,null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}},{key:"parseTypeList",value:function(){var t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length)].concat(t)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(tl),yl=function(t){cu(r,t);var e=_u(r);function r(t){var n;return ou(this,r),(n=e.call(this)).reader=t,n}return uu(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}},{key:"parseTypeList",value:function(){return[].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(tl),wl=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=new dl;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new dl;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(tl),_l=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(tl),gl=256;function bl(t,e,r,n){for(var i=Array(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),a=Array(r),o=0;o=Math.abs(i);){var c=h[0][0],f=h[0][1],l=bl(c,f,ml(t[c][c],t[f][f],t[c][f]),r);t=xl(l,t),a=El(a,l),h=kl(t)}for(var d=0;d0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;ou(this,t),this._values=[e,r,n]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Ol(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;ou(this,t),this._values=[e,r,n,i]}return uu(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new Al(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var a=0;a<4;a++)n[i+4+a]=r[4*a+0]|r[4*a+1]<<2|r[4*a+2]<<4|r[4*a+3]<<6}function Cl(t,e,r,n,i){var a,o=Pl(t),s=Pl(e);if(o<=s)a=r.slice();else{var u=[s,o];o=u[0],s=u[1],a=r.map((function(t){return 0===t?1:1===t?0:t}))}Nl(o,s,a,n,i)}function Dl(t,e,r,n,i){var a,o=Pl(t),s=Pl(e);if(o=128||!i)){var l=this._remap[s],d=(e[4*o+3]+1)/256;this._weights[l]+=a?d:1,this._remap[o]=l;break}}else this._remap[o]=-1}for(var v=0;v=n?t:(n=o,a)}),0);return i+=n,a}));if(is&&(a=r[h],s=c)}this.start=i.clampGrid().clone(),this.end=a.clampGrid().clone()}}}]),r}(jl),Zl=function(t){cu(r,t);var e=_u(r);function r(t){var n;ou(this,r);(n=e.call(this,t)).iterationCount=t.flags&gl?8:1,n.bestError=1/0,n.metric=new Ol(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,a=i.points,o=i.weights;return n.principle=Sl(a,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Ol(0),n}return uu(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Ol(.5,.5,.5,1/4),a=Ol.multiplyAdd(r,i,e),o=a.splatW,s=Ol.multiplyAdd(r,i,n);return{ax:a,aa:o,bx:s,bb:s.splatW,ab:Ol.multVector(r,i).splatW}}),(function(r,n,i){return Cl(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=new Ol(1/3,1/3,1/3,1/9),o=new Ol(2/3,2/3,2/3,4/9),s=new Ol(2/9),u=Ol.multiplyAdd(n,a,Ol.multiplyAdd(r,o,e)),h=u.splatW,c=Ol.multiplyAdd(r,a,Ol.multiplyAdd(n,o,i));return{ax:u,aa:h,bx:c,bb:c.splatW,ab:Ol.multVector(s,Ol.add(r,n)).splatW}}),(function(r,n,i){return Dl(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Ol(0),end:new Ol(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var a=function(e,n){var a=t(e),o=r.computeOptimalPoints(a);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var a={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(a.bestK=i),a},a=new Ol(0),o=0;o15?15:e}function Wl(t,e,r,n){var i=Hl(t,e,5),a=Hl(t,e,7);i.error<=a.error?function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Yl(i,n,a.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else Yl(n,i,a,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,a=t.indices;if(n>i){Yl(i,n,a.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else Yl(n,i,a,e,r)}(a,r,n)}function Hl(t,e,r){var n=function(t,e,r){for(var n=255,i=0,a=0;a<16;a++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*c&255;n[o]=f,o++}}}function Kl(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Jl(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function ql(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,a=Kl(n),o=Kl(i);return[a,o,Jl(a,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Jl(a,o,2/3)]}(e,r,n),a=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var a=t[r+i];n[4*i+0]=3&a,n[4*i+1]=a>>2&3,n[4*i+2]=a>>4&3,n[4*i+3]=a>>6&3}return n}(e,r),o=0;o<16;o++)for(var s=0;s<4;s++)t[4*o+s]=i[a[o]][s]}function $l(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function Ql(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=gl&&(r=8),64!=n&&(n=32),e|r|n|128&t}function td(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,a=r.y,o=void 0===a?0:a,s=r.width,u=void 0===s?0:s,h=r.height,c=void 0===h?0:h,f=0;$l((function(r,n){var a=i+r,s=o+n;if(a>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],a=Gl(n,i,n<=i?5:7),o=new Uint8Array(16),s=0,u=2,h=0;h<2;h++){for(var c=0,f=0;f<3;f++)c|=e[r+u]<<8*f,u++;for(var l=0;l<8;l++){var d=c>>3*l&7;o[s]=d,s++}}for(var v=0;v<16;++v)t[4*v+3]=a[o[v]]}(t,e,r)}function nd(t,e,r,n,i){var a=0!=(1&(i=Ql(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,a=void 0===i?0:i,o=e.width,s=void 0===o?0:o,u=e.height,h=void 0===u?0:u,c=new Uint8Array(64),f=0,l=0;return $l((function(e,r){var i=n+e,o=a+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var s=r.read(t),u=t.read(s);if(4==n)u=ud(u,i,a,id);else if(5==n)u=ud(u,i,a,ad);else if(6==n)u=ud(u,i,a,od);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var h=0;h","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(tl),ld=function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}return uu(r,[{key:"read",value:function(t){var e=(new dl).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new dl).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(tl);!function(t){cu(r,t);var e=_u(r);function r(){return ou(this,r),e.apply(this,arguments)}uu(r,[{key:"read",value:function(t){var e=new dl,r=new el,n=e.read(t),i=r.read(t),a=r.read(t),o=r.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var s=r.read(t),u=t.read(s);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var h=0;h1&&void 0!==arguments[1]?arguments[1]:{},r=$f(t),n=[],i=Object.keys(r),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.yaml,n=void 0!==r&&r,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=Bf(s),h=u[0],c=function(t){return Df(t,{yaml:n,contentOnly:a,fileName:h})};return Yf(t).then(c)},t.unpackToXnbData=Yf,t.xnbDataToContent=qf,t.xnbDataToFiles=Df,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/xnb.js b/dist/xnb.js index 551691e..0fc9d31 100644 --- a/dist/xnb.js +++ b/dist/xnb.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -73,6 +82,22 @@ } + function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -114,13 +139,10 @@ } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -135,12 +157,8 @@ } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1539,7 +1557,9 @@ } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4686,6 +4706,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4734,17 +4755,36 @@ } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4831,6 +4871,11 @@ return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } @@ -5354,8 +5399,7 @@ } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -5386,6 +5430,10 @@ return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -5460,6 +5508,10 @@ return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -5677,6 +5729,10 @@ return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -5815,6 +5871,10 @@ return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -5852,14 +5912,14 @@ return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -5876,6 +5936,11 @@ return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -5904,7 +5969,6 @@ } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -5916,6 +5980,10 @@ return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -7816,8 +7884,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/dist/xnb.min.js b/dist/xnb.min.js index b56b4ac..e39c8a5 100644 --- a/dist/xnb.min.js +++ b/dist/xnb.min.js @@ -1,64 +1,70 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function i(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=i({},t)}static addReaders(t){a.readers=i(i({},a.readers),t)}static makeSimplied(t,e){let r=t.split(/`|,/)[0];if(e.isTypeOf(r)){if(e.hasSubType()){let r=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(r.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e)}for(let e of Object.values(a.readers)){let r=a.makeSimplied(t,e);if(null!==r)return r}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let r=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return r}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],r=t.match(/<(.+)>/);return r=r?r[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:r}}static getReaderTypeList(t){let{type:e,subtypes:r}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(r);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:r}=a.getTypeInfo(t);if(r=r.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...r);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}n(a,"readers",{});const o=[192,224,240],h=128,l=63,c=[55296,56320],d=1023;function u(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function f(t){return t<65535?[t]:[c[0]|(t-=65536)>>10&d,c[1]|t&d]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const r=t.length;return 1===r?t[0]:2===r?((t[0]^o[0])<<6)+(t[1]^h):3===r?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&d)<<10)+(t[1]&d)+65536}function p(t){return function(t){const e=[];for(let r of t)e.push(...u(r));return e}(function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;i1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const r=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const n=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:0;const e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0;){const t=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),n=16-this.bitPosition-i,s=(t&2**i-1<>n;e-=i,this.bitPosition+=i,r|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} -/** @license - * - * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons - * which is derived from libmspack by Stuart Cole. - * - * (C) 2003-2004 Stuart Caie. - * (C) 2011 Ali Scissons. - * (C) 2017 James Stine. - * - * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. - * - * - * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - * LzxDecoder is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * MICROSOFT PUBLIC LICENSE - * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). - * - * Redistribution and use in source and binary forms, with or without modification, - * is permitted provided that redistributions of the source code retain the above - * copyright notices and this file header. - * - * Additional copyright notices should be appended to the list above. - * - * For details, see . - * - * - * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been - * acknowleded properly as it should have been back in 2017. - * - * Resources: - * - * cabextract/libmspack - http://http://www.cabextract.org.uk/ - * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs - * - */const m=256,v=0,k=1,x=2,A=3,E=656;class R{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!R.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)R.extra_bits[t]=R.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!R.position_base.length)for(let t=0,e=0;t<=50;t++)R.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),r=t.readLZXBits(8);switch(this.block_remaining=e<<8|r,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(E,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case A:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&i>0;){if(e>i&&(e=i),i-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,E,12);if(i>3;if(s>2){let e=R.extra_bits[s];if(s=R.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,E,12);if(i>3;if(s>2){if(3!=s){let e=R.extra_bits[s],r=t.readLZXBits(e);s=R.position_base[s]-2+r}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case A:if(t.bytePosition+e>r)throw new s("Overrun!"+r+" "+t.bytePosition+" "+e);for(let r=0;r>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let r=o;for(;r-- >0;)i[t++]=e}o>>=1}if(n==a)return i;for(let t=n;t>1>1;n<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let c=0;c>16;for(let r=0;r>15-r&1&&t++;if(i[t]=c,(n+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(n==a)return i;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,r,i,n){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(n)];if(a>=i){let t=1<<32-n;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=i)}return t.bitPosition+=r[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}R.position_base=[],R.extra_bits=[];class U{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}static readU32(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}static writeU32(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}static imul(t,e){var r=65535&t,i=65535&e;return r*i+((t>>>16)*i+r*(e>>>16)<<16)|0}} -/** @license - * Original Code by: https://github.com/Benzinga/lz4js/ - */const T=65536,S=15;!function(t){try{new Uint8Array(t)}catch(i){for(var e=new Array(t),r=0;r=13)for(var f=67;r+4>>0;if(s=n[w=(w>>16^w)>>>0&65535]-1,n[w]=r+1,s<0||r-s>>>16>0||U.readU32(t,s)!==_)r+=f++>>6;else{for(f=67,l=r-a,h=r-s,s+=4,o=r+=4;r=S){for(e[c++]=240+p,u=l-S;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=(l<<4)+p;for(var g=0;g>8,o>=15){for(u=o-15;u>=255;u-=255)e[c++]=255;e[c++]=u}a=r}}if(0===a)return 0;if((l=d-a)>=S){for(e[c++]=240,u=l-S;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=l<<4;for(r=a;rt.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class N{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const r=L(e);t.write7BitNumber(r),t.writeString(e)}}class C{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class D{constructor(t,e,r){let{target:i,formatVersion:n,hidef:s,compressed:a}=t;this.header={target:i,formatVersion:n,hidef:s,compressed:a},this.readers=e,this.content=r}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class V{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const M=64,P=128,F=14;class Z{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new b(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==P){const e=this.fileSize-F,r=class{static decompress(t,e,r){let i,n,a=0;const o=new R(16);let h=new y(r);for(;a65536||n>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,n,i)),a+=i}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(r,F,0,t),this.buffer.bytePosition=F}else if(this.compressionType==M){const e=this.buffer.buffer.slice(F),r=new Uint8Array(e),i=new Uint8Array(t);!function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*r,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,c=void 0!==e.copyWithin&&void 0!==e.fill;for(o=r+i;r>4;if(u>0){if(15===u)for(;u+=t[r],255===t[r++];);for(h=r+u;r=o)break;if(s=15&d,a=t[r++]|t[r++]<<8,15===s)for(;s+=t[r],255===t[r++];);if(s+=4,c&&1===a)e.fill(0|e[n-1],n,n+s),n+=s;else if(c&&a>s&&s>31)e.copyWithin(n,n-a,n-a+s),n+=s;else for(h=(l=n-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let r=0;const i=t.length;let n=0,s=Math.max(32,i+(i>>1)+7),a=new Uint8Array(s>>3<<3);for(;r=55296&&e<=56319){if(r=55296&&e<=56319)continue}if(n+4>a.length){s+=8,s*=1+r/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[n++]=e>>6&31|192;else if(0==(4294901760&e))a[n++]=e>>12&15|224,a[n++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[n++]=e>>18&7|240,a[n++]=e>>12&63|128,a[n++]=e>>6&63|128}a[n++]=63&e|128}else a[n++]=e}return a.slice(0,n)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const r=new Uint8Array(t);let i=0;const n=r.length,s=[];for(;i65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function j(t){var e=W[t];if(void 0!==e)return e.exports;var r=W[t]={exports:{}};return X[t].call(r.exports,r,r.exports,j),r.exports}j.d=(t,e)=>{for(var r in e)j.o(e,r)&&!j.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},j.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{j.d(H,{P:()=>Br,m:()=>Ir}),j(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class r{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=!1;"number"==typeof t?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=i?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return r=this.readBytes(e),t.decode(r);var r}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function n(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);n(l);const c=new Array(60);n(c);const d=new Array(512);n(d);const u=new Array(256);n(u);const f=new Array(29);n(f);const _=new Array(30);function w(t,e,r,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let p,g,b;function y(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(_);const m=t=>t<256?d[t]:d[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,r)=>{t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<{k(t,r[2*e],r[2*e+1])},A=(t,e)=>{let r=0;do{r|=1&t,t>>>=1,r<<=1}while(--e>0);return r>>>1},E=(t,e,r)=>{const i=new Array(16);let n,s,a=0;for(n=1;n<=15;n++)i[n]=a=a+r[n-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=A(i[e]++,e))}},R=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},U=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},T=(t,e,r,i)=>{const n=2*e,s=2*r;return t[n]{const i=t.heap[r];let n=r<<1;for(;n<=t.heap_len&&(n{let i,n,o,h,l=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],n=t.pending_buf[t.l_buf+l],l++,0===i?x(t,n,e):(o=u[n],x(t,o+256+1,e),h=s[o],0!==h&&(n-=f[o],k(t,n,h)),i--,o=m(i),x(t,o,r),h=a[o],0!==h&&(i-=_[o],k(t,i,h)))}while(l{const r=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)S(t,r,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],S(t,r,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,r[2*h]=r[2*a]+r[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,r[2*a+1]=r[2*o+1]=h,t.heap[1]=h++,S(t,r,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const r=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,d,u,f,_,w=0;for(u=0;u<=15;u++)t.bl_count[u]=0;for(r[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],u=r[2*r[2*c+1]+1]+1,u>h&&(u=h,w++),r[2*c+1]=u,c>i||(t.bl_count[u]++,f=0,c>=o&&(f=a[c-o]),_=r[2*c],t.opt_len+=_*(u+f),s&&(t.static_len+=_*(n[2*c+1]+f)));if(0!==w){do{for(u=h-1;0===t.bl_count[u];)u--;t.bl_count[u]--,t.bl_count[u+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(u=h;0!==u;u--)for(c=t.bl_count[u];0!==c;)d=t.heap[--l],d>i||(r[2*d+1]!==u&&(t.opt_len+=(u-r[2*d+1])*r[2*d],r[2*d+1]=u),c--)}})(t,e),E(r,l,t.bl_count)},B=(t,e,r)=>{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(r+1)+1]=65535,i=0;i<=r;i++)n=a,a=e[2*(i+1)+1],++o{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),i=0;i<=r;i++)if(n=a,a=e[2*(i+1)+1],!(++o{k(t,0+(i?1:0),3),((t,e,r,i)=>{U(t),v(t,r),v(t,~r),t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r})(t,e,r)};var C={_tr_init:t=>{L||((()=>{let t,e,r,i,n;const h=new Array(16);for(r=0,i=0;i<28;i++)for(f[i]=r,t=0;t<1<>=7;i<30;i++)for(_[i]=n<<7,t=0;t<1<{let n,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),I(t,t.l_desc),I(t,t.d_desc),a=(t=>{let e;for(B(t,t.dyn_ltree,t.l_desc.max_code),B(t,t.dyn_dtree,t.d_desc.max_code),I(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=n&&(n=s)):n=s=r+5,r+4<=n&&-1!==e?N(t,e,r,i):4===t.strategy||s===n?(k(t,2+(i?1:0),3),z(t,l,c)):(k(t,4+(i?1:0),3),((t,e,r,i)=>{let n;for(k(t,e-257,5),k(t,r-1,5),k(t,i-4,4),n=0;n(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(u[r]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},D=(t,e,r,i)=>{let n=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==r;){a=r>2e3?2e3:r,r-=a;do{n=n+e[i++]|0,s=s+n|0}while(--a);n%=65521,s%=65521}return n|s<<16|0};const V=new Uint32Array((()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e})());var M=(t,e,r,i)=>{const n=V,s=i+r;t^=-1;for(let r=i;r>>8^n[255&(t^e[r])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},F={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Z,_tr_stored_block:X,_tr_flush_block:W,_tr_tally:K,_tr_align:G}=C,{Z_NO_FLUSH:Y,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:q,Z_FINISH:$,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:rt,Z_DATA_ERROR:it,Z_BUF_ERROR:nt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:ct,Z_UNKNOWN:dt,Z_DEFLATED:ut}=F,ft=258,_t=262,wt=103,pt=113,gt=666,bt=(t,e)=>(t.msg=P[e],e),yt=t=>(t<<1)-(t>4?9:0),mt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,r)=>(e<{const e=t.state;let r=e.pending;r>t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},At=(t,e)=>{t.pending_buf[t.pending++]=e},Et=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=(t,e,r,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),r),1===t.state.wrap?t.adler=D(t.adler,e,n,r):2===t.state.wrap&&(t.adler=M(t.adler,e,n,r)),t.next_in+=n,t.total_in+=n,n)},Ut=(t,e)=>{let r,i,n=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,c=t.w_mask,d=t.prev,u=t.strstart+ft;let f=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(r=e,l[r+a]===_&&l[r+a-1]===f&&l[r]===l[s]&&l[++r]===l[s+1]){s+=2,r++;do{}while(l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&sa){if(t.match_start=e,a=i,i>=o)break;f=l[s+a-1],_=l[s+a]}}}while((e=d[e&c])>h&&0!=--n);return a<=t.lookahead?a:t.lookahead},Tt=t=>{const e=t.w_size;let r,i,n,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,r=i;do{n=t.head[--r],t.head[r]=n>=e?n-e:0}while(--i);i=e,r=i;do{n=t.prev[--r],t.prev[r]=n>=e?n-e:0}while(--i);s+=e}if(0===t.strm.avail_in)break;if(i=Rt(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=i,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},St=(t,e)=>{let r,i;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-_t&&(t.match_length=Ut(t,r)),t.match_length>=3)if(i=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},zt=(t,e)=>{let r,i,n;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,i=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=K(t,0,t.window[t.strstart-1]),i&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,r,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=i,this.func=n}const Bt=[new It(0,0,0,0,((t,e)=>{let r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===Y)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+r;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,St),new It(4,5,16,8,St),new It(4,6,32,32,St),new It(4,4,16,16,zt),new It(8,16,32,32,zt),new It(8,16,128,128,zt),new It(8,32,128,256,zt),new It(32,128,258,1024,zt),new It(32,258,258,4096,zt)];function Ot(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ut,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),mt(this.dyn_ltree),mt(this.dyn_dtree),mt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),mt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),mt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Lt=t=>{const e=(t=>{if(!t||!t.state)return bt(t,rt);t.total_in=t.total_out=0,t.data_type=dt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=Y,Z(e),tt})(t);var r;return e===tt&&((r=t.state).window_size=2*r.w_size,mt(r.head),r.max_lazy_match=Bt[r.level].max_lazy,r.good_match=Bt[r.level].good_length,r.nice_match=Bt[r.level].nice_length,r.max_chain_length=Bt[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),e};var Nt=(t,e,r,i,n,s)=>{if(!t)return rt;let a=1;if(e===st&&(e=6),i<0?(a=0,i=-i):i>15&&(a=2,i-=16),n<1||n>9||r!==ut||i<8||i>15||e<0||e>9||s<0||s>lt)return bt(t,rt);8===i&&(i=9);const o=new Ot;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=i,o.w_size=1<{let r,i;if(!t||!t.state||e>Q||e<0)return t?bt(t,rt):rt;const n=t.state;if(!t.output||!t.input&&0!==t.avail_in||n.status===gt&&e!==$)return bt(t,0===t.avail_out?nt:rt);n.strm=t;const s=n.last_flush;if(n.last_flush=e,42===n.status)if(2===n.wrap)t.adler=0,At(n,31),At(n,139),At(n,8),n.gzhead?(At(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),At(n,255&n.gzhead.time),At(n,n.gzhead.time>>8&255),At(n,n.gzhead.time>>16&255),At(n,n.gzhead.time>>24&255),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(At(n,255&n.gzhead.extra.length),At(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=M(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(At(n,0),At(n,0),At(n,0),At(n,0),At(n,0),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,3),n.status=pt);else{let e=ut+(n.w_bits-8<<4)<<8,r=-1;r=n.strategy>=ot||n.level<2?0:n.level<6?1:6===n.level?2:3,e|=r<<6,0!==n.strstart&&(e|=32),e+=31-e%31,n.status=pt,Et(n,e),0!==n.strstart&&(Et(n,t.adler>>>16),Et(n,65535&t.adler)),t.adler=1}if(69===n.status)if(n.gzhead.extra){for(r=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending!==n.pending_buf_size));)At(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.status=wt)}else n.status=wt;if(n.status===wt&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&kt(t),n.pending+2<=n.pending_buf_size&&(At(n,255&t.adler),At(n,t.adler>>8&255),t.adler=0,n.status=pt)):n.status=pt),0!==n.pending){if(kt(t),0===t.avail_out)return n.last_flush=-1,tt}else if(0===t.avail_in&&yt(e)<=yt(s)&&e!==$)return bt(t,nt);if(n.status===gt&&0!==t.avail_in)return bt(t,nt);if(0!==t.avail_in||0!==n.lookahead||e!==Y&&n.status!==gt){let r=n.strategy===ot?((t,e)=>{let r;for(;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===Y)return 1;break}if(t.match_length=0,r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):n.strategy===ht?((t,e)=>{let r,i,n,s;const a=t.window;for(;;){if(t.lookahead<=ft){if(Tt(t),t.lookahead<=ft&&e===Y)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,i=a[n],i===a[++n]&&i===a[++n]&&i===a[++n])){s=t.strstart+ft;do{}while(i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):Bt[n.level].func(n,e);if(3!==r&&4!==r||(n.status=gt),1===r||3===r)return 0===t.avail_out&&(n.last_flush=-1),tt;if(2===r&&(e===J?G(n):e!==Q&&(X(n,0,0,!1),e===q&&(mt(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),kt(t),0===t.avail_out))return n.last_flush=-1,tt}return e!==$?tt:n.wrap<=0?et:(2===n.wrap?(At(n,255&t.adler),At(n,t.adler>>8&255),At(n,t.adler>>16&255),At(n,t.adler>>24&255),At(n,255&t.total_in),At(n,t.total_in>>8&255),At(n,t.total_in>>16&255),At(n,t.total_in>>24&255)):(Et(n,t.adler>>>16),Et(n,65535&t.adler)),kt(t),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?tt:et)},Dt=t=>{if(!t||!t.state)return rt;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==gt?bt(t,rt):(t.state=null,e===pt?bt(t,it):tt)};const Vt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Mt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const r=e.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const e in r)Vt(r,e)&&(t[e]=r[e])}}return t},Pt=t=>{let e=0;for(let r=0,i=t.length;r=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Zt[254]=Zt[254]=1;var Xt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,r,i,n,s,a=t.length,o=0;for(n=0;n>>6,e[s++]=128|63&r):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|63&r):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|63&r);return e},Wt=(t,e)=>{const r=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,n;const s=new Array(2*r);for(n=0,i=0;i4)s[n++]=65533,i+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&i1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let i=0;i{(e=e||t.length)>t.length&&(e=t.length);let r=e-1;for(;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Zt[t[r]]>e?r:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Gt,Z_SYNC_FLUSH:Yt,Z_FULL_FLUSH:Jt,Z_FINISH:qt,Z_OK:$t,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:re}=F;function ie(t){this.options=Mt({level:te,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Nt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==$t)throw new Error(P[r]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=((t,e)=>{let r=e.length;if(!t||!t.state)return rt;const i=t.state,n=i.wrap;if(2===n||1===n&&42!==i.status||i.lookahead)return rt;if(1===n&&(t.adler=D(t.adler,e,r,0)),i.wrap=0,r>=i.w_size){0===n&&(mt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(r-i.w_size,r),0),e=t,r=i.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Tt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=vt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Tt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,i.wrap=n,tt})(this.strm,t),r!==$t)throw new Error(P[r]);this._dict_set=!0}}function ne(t,e){const r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||P[r.err];return r.result}ie.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?qt:Gt,"string"==typeof t?r.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),(s===Yt||s===Jt)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(n=Ct(r,s),n===Qt)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),n=Dt(this.strm),this.onEnd(n),this.ended=!0,n===$t;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===$t&&(this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ie,deflate:ne,deflateRaw:function(t,e){return(e=e||{}).raw=!0,ne(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,ne(t,e)},constants:F},ae=function(t,e){let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A,E;const R=t.state;r=t.next_in,A=t.input,i=r+(t.avail_in-5),n=t.next_out,E=t.output,s=n-(e-t.avail_out),a=n+(t.avail_out-257),o=R.dmax,h=R.wsize,l=R.whave,c=R.wnext,d=R.window,u=R.hold,f=R.bits,_=R.lencode,w=R.distcode,p=(1<>>24,u>>>=y,f-=y,y=b>>>16&255,0===y)E[n++]=65535&b;else{if(!(16&y)){if(0==(64&y)){b=_[(65535&b)+(u&(1<>>=y,f-=y),f<15&&(u+=A[r++]<>>24,u>>>=y,f-=y,y=b>>>16&255,!(16&y)){if(0==(64&y)){b=w[(65535&b)+(u&(1<o){t.msg="invalid distance too far back",R.mode=30;break t}if(u>>>=y,f-=y,y=n-s,v>y){if(y=v-y,y>l&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=d,0===c){if(k+=h-y,y2;)E[n++]=x[k++],E[n++]=x[k++],E[n++]=x[k++],m-=3;m&&(E[n++]=x[k++],m>1&&(E[n++]=x[k++]))}else{k=n-v;do{E[n++]=E[k++],E[n++]=E[k++],E[n++]=E[k++],m-=3}while(m>2);m&&(E[n++]=E[k++],m>1&&(E[n++]=E[k++]))}break}}break}}while(r>3,r-=m,f-=m<<3,u&=(1<{const h=o.bits;let l,c,d,u,f,_,w=0,p=0,g=0,b=0,y=0,m=0,v=0,k=0,x=0,A=0,E=null,R=0;const U=new Uint16Array(16),T=new Uint16Array(16);let S,z,I,B=null,O=0;for(w=0;w<=15;w++)U[w]=0;for(p=0;p=1&&0===U[b];b--);if(y>b&&(y=b),0===b)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(T[1]=0,w=1;w<15;w++)T[w+1]=T[w]+U[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){S=w-v,a[p]<_?(z=0,I=a[p]):a[p]>_?(z=B[O+a[p]],I=E[R+a[p]]):(z=96,I=0),l=1<>v)+c]=S<<24|z<<16|I|0}while(0!==c);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--U[w]){if(w===b)break;w=e[r+a[p]]}if(w>y&&(A&u)!==d){for(0===v&&(v=y),f+=g,m=w-v,k=1<852||2===t&&x>592)return 1;d=A&u,n[d]=y<<24|m<<16|f-s|0}}return 0!==A&&(n[f+A]=w-v<<24|64<<16|0),o.bits=y,0};const{Z_FINISH:ue,Z_BLOCK:fe,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:ge,Z_STREAM_ERROR:be,Z_DATA_ERROR:ye,Z_MEM_ERROR:me,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=F,xe=12,Ae=30,Ee=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Re(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Ue=t=>{if(!t||!t.state)return be;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return be;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Te,Se,ze=!0;const Ie=t=>{if(ze){Te=new Int32Array(512),Se=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(de(1,t.lens,0,288,Te,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;de(2,t.lens,0,32,Se,0,t.work,{bits:5}),ze=!1}t.lencode=Te,t.lenbits=9,t.distcode=Se,t.distbits=5},Be=(t,e,r,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(r-i,r-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(r-i,r),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return be;const r=new Re;t.state=r,r.window=null;const i=((t,e)=>{let r;if(!t||!t.state)return be;const i=t.state;return e<0?(r=0,e=-e):(r=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?be:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=r,i.wbits=e,Ue(t))})(t,e);return i!==we&&(t.state=null),i},Ne=(t,e)=>{let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A=0;const E=new Uint8Array(4);let R,U;const T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return be;r=t.state,r.mode===xe&&(r.mode=13),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,d=o,u=h,x=we;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0),l=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=Ae;break}if((15&l)!==ke){t.msg="unknown compression method",r.mode=Ae;break}if(l>>>=4,c-=4,k=8+(15&l),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Ae;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>8&255,E[2]=l>>>16&255,E[3]=l>>>24&255,r.check=M(r.check,E,4,0)),l=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>8),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(f=r.length,f>o&&(f=o),f&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(i.subarray(s,s+f),k)),512&r.flags&&(r.check=M(r.check,i,f,s)),o-=f,s+=f,r.length-=f),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break t;f=0;do{k=i[s+f++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&f>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=xe;break;case 10:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===o)break t;o--,l+=i[s++]<>>=1,c-=1,3&l){case 0:r.mode=14;break;case 1:if(Ie(r),r.mode=20,e===_e){l>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Ae}l>>>=2,c-=2;break;case 14:for(l>>>=7&c,c-=7&c;c<32;){if(0===o)break t;o--,l+=i[s++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Ae;break}if(r.length=65535&l,l=0,c=0,r.mode=15,e===_e)break t;case 15:r.mode=16;case 16:if(f=r.length,f){if(f>o&&(f=o),f>h&&(f=h),0===f)break t;n.set(i.subarray(s,s+f),a),o-=f,s+=f,h-=f,a+=f,r.length-=f;break}r.mode=xe;break;case 17:for(;c<14;){if(0===o)break t;o--,l+=i[s++]<>>=5,c-=5,r.ndist=1+(31&l),l>>>=5,c-=5,r.ncode=4+(15&l),l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Ae;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,R={bits:r.lenbits},x=de(0,r.lens,0,19,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid code lengths set",r.mode=Ae;break}r.have=0,r.mode=19;case 19:for(;r.have>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=p,c-=p,r.lens[r.have++]=b;else{if(16===b){for(U=p+2;c>>=p,c-=p,0===r.have){t.msg="invalid bit length repeat",r.mode=Ae;break}k=r.lens[r.have-1],f=3+(3&l),l>>>=2,c-=2}else if(17===b){for(U=p+3;c>>=p,c-=p,k=0,f=3+(7&l),l>>>=3,c-=3}else{for(U=p+7;c>>=p,c-=p,k=0,f=11+(127&l),l>>>=7,c-=7}if(r.have+f>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Ae;break}for(;f--;)r.lens[r.have++]=k}}if(r.mode===Ae)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Ae;break}if(r.lenbits=9,R={bits:r.lenbits},x=de(1,r.lens,0,r.nlen,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid literal/lengths set",r.mode=Ae;break}if(r.distbits=6,r.distcode=r.distdyn,R={bits:r.distbits},x=de(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,R),r.distbits=R.bits,x){t.msg="invalid distances set",r.mode=Ae;break}if(r.mode=20,e===_e)break t;case 20:r.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,ae(t,u),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,r.mode===xe&&(r.back=-1);break}for(r.back=0;A=r.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=xe;break}if(64&g){t.msg="invalid literal/length code",r.mode=Ae;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;A=r.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,64&g){t.msg="invalid distance code",r.mode=Ae;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Ae;break}r.mode=25;case 25:if(0===h)break t;if(f=u-h,r.offset>f){if(f=r.offset-f,f>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Ae;break}f>r.wnext?(f-=r.wnext,_=r.wsize-f):_=r.wnext-f,f>r.length&&(f=r.length),w=r.window}else w=n,_=a-r.offset,f=r.length;f>h&&(f=h),h-=f,r.length-=f;do{n[a++]=w[_++]}while(--f);0===r.length&&(r.mode=21);break;case 26:if(0===h)break t;n[a++]=r.length,h--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===o)break t;o--,l|=i[s++]<{if(!t||!t.state)return be;let e=t.state;return e.window&&(e.window=null),t.state=null,we},De=(t,e)=>{const r=e.length;let i,n,s;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?be:11===i.mode&&(n=1,n=D(n,e,r,0),n!==i.check)?ye:(s=Be(t,e,r,r),s?(i.mode=31,me):(i.havedict=1,we))):be},Ve=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Me=Object.prototype.toString,{Z_NO_FLUSH:Pe,Z_FINISH:Fe,Z_OK:Ze,Z_STREAM_END:Xe,Z_NEED_DICT:We,Z_STREAM_ERROR:je,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=F;function Ge(t){this.options=Mt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Le(this.strm,e.windowBits);if(r!==Ze)throw new Error(P[r]);if(this.header=new Ve,((t,e)=>{if(!t||!t.state)return be;const r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Me.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary),r!==Ze)))throw new Error(P[r])}function Ye(t,e){const r=new Ge(e);if(r.push(t),r.err)throw r.msg||P[r.err];return r.result}Ge.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Fe:Pe,"[object ArrayBuffer]"===Me.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),s=Ne(r,a),s===We&&n&&(s=De(r,n),s===Ze?s=Ne(r,a):s===He&&(s=We));r.avail_in>0&&s===Xe&&r.state.wrap>0&&0!==t[r.next_in];)Oe(r),s=Ne(r,a);switch(s){case je:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=r.avail_out,r.next_out&&(0===r.avail_out||s===Xe))if("string"===this.options.to){let t=jt(r.output,r.next_out),e=r.next_out-t,n=Wt(r.output,t);r.next_out=e,r.avail_out=i-e,e&&r.output.set(r.output.subarray(t,t+e),0),this.onData(n)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(s!==Ze||0!==o){if(s===Xe)return s=Ce(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Ge.prototype.onData=function(t){this.chunks.push(t)},Ge.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ge,inflate:Ye,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ye(t,e)},ungzip:Ye,constants:F};const{Deflate:qe,deflate:$e,deflateRaw:Qe,gzip:tr}=se,{Inflate:er,inflate:rr,inflateRaw:ir,ungzip:nr}=Je;var sr=$e,ar=er,or=rr;const hr=[137,80,78,71,13,10,26,10],lr=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;lr[t]=e}function cr(t,e){return(4294967295^function(t,e,r){let i=4294967295;for(let t=0;t>>8;return i}(0,t,e))>>>0}var dr,ur,fr,_r;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(dr||(dr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ur||(ur={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(fr||(fr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_r||(_r={}));const wr=new Uint8Array(0),pr=new Uint16Array([255]),gr=255===new Uint8Array(pr.buffer)[0];class br extends r{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:r=!1}=e;this._checkCrc=r,this._inflator=new ar,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ur.UNKNOWN,this._filterMethod=fr.UNKNOWN,this._interlaceMethod=_r.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=n;var l}}function yr(t,e,r){for(let i=0;i>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xr(t,e,r,i,n){let s=0;if(0===r.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=dr.UNKNOWN,this._zlibOptions=i(i({},Er),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hr)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ur.DEFLATE),this.writeByte(fr.ADAPTIVE),this.writeByte(_r.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:i,depth:n,data:s}=this._png,a=i*t,o=(new r).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Tr(t,e,r,i){for(let n=0;nnew Rr({width:t,height:e,data:r},void 0).encode(),Br=t=>function(t,e){return new br(t,void 0).decode()}(t)})();var K=H.P,G=H.m;function Y(t,e,r){if((i=t)&&i.hasOwnProperty("type")&&i.hasOwnProperty("data")){let i=Y(t.data,e,r);return i.includes("\n")?" #!"+t.type+i:i+" #!"+t.type}if(t&&"object"==typeof t){let i=Array.isArray(t);if(0==Object.keys(t).length)return i?"[]":"{}";let n="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(n+=e.repeat(r+1),i?n+="- "+Y(t[s],e,r+1):s.includes(": ")?(n+=Y(s,e,r+1),n+=": "+Y(t[s],e,r+1)):n+=s+": "+Y(t[s],e,r+1),n+="\n");return n}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var i}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var r="";return"number"==typeof e?r=" ".repeat(Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),Y(t,r,-1)}class q{constructor(t,e,r){this.startingLine=r||0,this.lineIndex=-1;let i=[];for(let e=0;e=e;)t.push(this.next());return new q(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,r=this.getLine(t);for(;r.startsWith(this.indentString);)r=r.slice(this.indentString.length),e++;return e}}function $(t,e){let r;for(t.indentLevel();!t.finished();){let e,i,n,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(n=o[1],s=s.replace(o[0],"")),a?(r||(r={}),e=a[1],i=s.replace(a[0],"").trim()):s.startsWith("-")&&(r||(r=[]),i=s.slice(1).trim()),i=i?Q(i,n):$(t.nextGroup(),n),Array.isArray(r)?r.push(i):r[e]=i}return e&&(r={type:e,data:r}),r}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return $(new q(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(et(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=et(i);return e}return t}function rt(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function it(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function nt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:r}=t;if(rt(e))return et(r);if(it(e))return r=et(r),"Texture2D"===e?r.export="Texture2D.png":"Effect"===e?r.export="Effect.cso":"TBin"===e?r.export="TBin.tbin":"BmFont"===e&&(r.export="BmFont.xml"),r;t=et(r)}let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(nt(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=nt(i);return e}return null}function st(t){const e={},{compressed:r,formatVersion:i,hidef:n,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!r,hiDef:n,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let c=a.getReaderTypeList(l);"SpriteFont"===c[0]&&(c=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:d,extractedImages:u,extractedMaps:f}=function(t,e){let r=[],i=[];const{converted:n}=function t(n,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(rt(o))return{converted:{type:o,data:n},traversed:a};if(null===o)return{converted:n,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:n}}},traversed:a+1};if(it(o))return"Texture2D"===o?(r.push({path:s.join(".")}),{converted:{type:o,data:{format:n.format}},traversed:a}):("TBin"===o&&i.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(n)?[]:{};let l=a,c=!0,d=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,r]of Object.entries(n)){let r;r=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:i,traversed:u}=t(n[e],[...s,e],r);h[e]=i,d?l=u:c&&(l=u,c=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:n,extractedImages:r,extractedMaps:i}}(h,c);return e.content=d,u.length>0&&(e.extractedImages=u),f.length>0&&(e.extractedMaps=f),e}function at(t){const e={},{compressed:r,readerData:i,hiDef:n,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:r?"a"===s||"i"===s?64:128:0,hidef:n},e.readers=et(i),e.content=nt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let r of Object.values(t))if(r||"object"==typeof r){let t=ot(r,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function ct(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function dt(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:ct(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ut(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=ot(t,"export");if(r){const{value:t}=r;let{type:e,data:i}=t;return"Texture2D"===e&&(i=G(t.width,t.height,new Uint8Array(i))),dt(i,e)}if(e){return dt(JSON.stringify(t,null,4),"JSON")}return null}function ft(t){let{yaml:e=!1,contentOnly:r=!1,fileName:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&r&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const n=[],{content:a}=t,o=ut(a,r);if(null!==o&&n.push(o),r)return n;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof i&&""!==i?"".concat(i,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),n.unshift(dt(l,e?"yaml":"JSON")),n}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function gt(t,e){if("png"===t){const t=await pt(e.png),r=K(new Uint8Array(t));return{type:"Texture2D",data:r.data,width:r.width,height:r.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function bt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:r="default"}=e,i=t.json||t.yaml;if(!i)throw new s("There is no JSON or YAML file to pack!");const n=await wt(i);let a=null;a=t.json?JSON.parse(n):at(tt(n));let o=_t(r);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(i.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:r}=h,[,i]=ht(r);e.export=await gt(i,t)}return a}async function yt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return mt(await t.arrayBuffer())}return mt(t.buffer)}function mt(t){return(new Z).load(t)}function vt(t){const{content:e}=t,{data:r,extension:i}=ut(e,!0);return new V(r,i)}function kt(t){let e={};for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class Et extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const Rt=[55296,56320];function Ut(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function Tt(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class St extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const i=Tt(e);t.write7BitNumber(i),t.writeString(e)}isValueType(){return!1}}class zt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class It extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class Bt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class Ot extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const r=(new Et).read(t),i=[];for(let n=0;n")}}class Lt extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new zt;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class Nt extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new Bt;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const i=new Bt;i.write(t,e.x,null),i.write(t,e.y,null),i.write(t,e.width,null),i.write(t,e.height,null)}}class Ct extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const Dt=256;//! Use DXT1 compression. -function Vt(t,e,r,i){let n=Array(i);for(let t=0;t{let n=e.map((t=>t[i]));return{value:t[i],vec:n}}));return i.sort(((t,e)=>e.value-t.value)),[i.map((t=>{let{value:e}=t;return e})),i.map((t=>{let{vec:e}=t;return e}))]}function Wt(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,i=Array(r),n=Math.abs(e/r),s=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],i=a[0][1],n=Vt(e,i,Mt(t[e][e],t[i][i],t[e][i]),r);t=Ft(n,t),s=Zt(s,n),a=Pt(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:jt.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new jt(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Ht(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,i]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:Ht.multScalar(this,1/this.length)}get xyz(){return new jt(this.x,this.y,this.z)}get splatX(){return new Ht(this.x)}get splatY(){return new Ht(this.y)}get splatZ(){return new Ht(this.z)}get splatW(){return new Ht(this.w)}clone(){return new Ht(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=i,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new Ht(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new Ht(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new Ht(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new Ht(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let i=Ht.multScalar(t,1-r),n=Ht.multScalar(e,r);return Ht.add(i,n)}static multiplyAdd(t,e,r){return new Ht(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new Ht(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(i,e[n]),t)),new jt(0));i.mult(1/r);let n=t.reduce(((t,r,n)=>{let s=e[n],a=jt.sub(r,i);return t[0][0]+=a.x*a.x*s,t[0][1]+=a.x*a.y*s,t[0][2]+=a.x*a.z*s,t[1][1]+=a.y*a.y*s,t[1][2]+=a.y*a.z*s,t[2][2]+=a.z*a.z*s,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new jt(...Wt(r))}const Gt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],Yt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],Jt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],qt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function $t(t,e){const r=parseInt(t+.5);return r<0?0:r}function Qt(t){return $t(31*t.x)<<11|$t(63*t.y)<<5|$t(31*t.z)}function te(t,e,r,i,n){i[n+0]=255&t,i[n+1]=t>>8,i[n+2]=255&e,i[n+3]=e>>8;for(let t=0;t<4;t++)i[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function ee(t,e,r,i,n){let s,a=Qt(t),o=Qt(e);a<=o?s=r.slice():([a,o]=[o,a],s=r.map((t=>0===t?1:1===t?0:t))),te(a,o,s,i,n)}function re(t,e,r,i,n){let s,a=Qt(t),o=Qt(e);a3&(1^t)))):s=a==o?new Array(16).fill(0):r.slice(),te(a,o,s,i,n)}class ie{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const i=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!i)){const e=this._remap[s],i=(t[4*r+3]+1)/256;this._weights[e]+=n?i:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,i)=>e[i]=r[i]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,i)=>e[i]=r[i]))}}class ne{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class se extends ne{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new jt(0),this.end=new jt(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.erroree(r,i,n,t,e)))}compress4(t,e){const r=[Jt,qt,Jt];this.compressBase(r,((r,i,n)=>re(r,i,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let i=0;for(let n=0;n<3;n++){const s=t[n],a=this.color[n];r[n]=s[a][e];const o=r[n][2];i+=o*o}i{let r=1/0;const n=t.reduce(((t,i,n)=>{const s=jt.sub(e,i).multVector(this.metric).lengthSq;return s>=r?t:(r=s,n)}),0);return i+=r,n}));if(iee(r,i,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),jt.interpolate(this.start,this.end,1/3),jt.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,i,n)=>re(r,i,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const i=Kt(e,r);let n,s,a,o;n=s=e[0],a=o=jt.dot(n,i);for(let r=1;ro&&(s=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=s.clampGrid().clone()}}class oe extends ne{constructor(t){super(t);this.iterationCount=t.flags&Dt?8:1,this.bestError=1/0,this.metric=new Ht(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=Kt(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new Ht(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,i]=t;const n=new Ht(.5,.5,.5,1/4),s=Ht.multiplyAdd(r,n,e),a=s.splatW,o=Ht.multiplyAdd(r,n,i);return{ax:s,aa:a,bx:o,bb:o.splatW,ab:Ht.multVector(r,n).splatW}}),((r,i,n)=>ee(r,i,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,i,n]=t;const s=new Ht(1/3,1/3,1/3,1/9),a=new Ht(2/3,2/3,2/3,4/9),o=new Ht(2/9),h=Ht.multiplyAdd(i,s,Ht.multiplyAdd(r,a,e)),l=h.splatW,c=Ht.multiplyAdd(r,s,Ht.multiplyAdd(i,a,n));return{ax:h,aa:l,bx:c,bb:c.splatW,ab:Ht.multVector(o,Ht.add(r,i)).splatW}}),((r,i,n)=>re(r,i,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let n={start:new Ht(0),end:new Ht(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(n.bestK=0);const s=(e,r)=>{const s=t(e),a=this.computeOptimalPoints(s);return a.errorjt.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>i[t]-i[e]!=0?i[t]-i[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let i=0;i2&&void 0!==arguments[2]?arguments[2]:2;const{count:i}=this.colors,n=(e,i,n)=>{const s={bestI:e,bestJ:2===r?n:i,iteration:t};return 3===r&&(s.bestK=n),s};let s=new Ht(0);for(let t=0;t15?15:e}function le(t,e,r,i){let n=ce(t,e,5),s=ce(t,e,7);n.error<=s.error?function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){ue(n,i,s.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else ue(i,n,s,e,r)}(n,r,i):function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){ue(n,i,s.map((t=>0===t?1:1===t?0:9-t)),e,r)}else ue(i,n,s,e,r)}(s,r,i)}function ce(t,e,r){let{min:i,max:n}=function(t,e,r){let i=255,n=0;for(let s=0;s<16;s++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}i>n&&(i=n);n-iMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(i[6]=0,i[7]=255),i}function ue(t,e,r,i,n){i[n]=t,i[n+1]=e;let s=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[s]<<3*e,s++}for(let e=0;e<3;++e){let r=t>>8*e&255;i[a]=r,a++}}}function fe(t){const e=t>>11&31,r=t>>5&63,i=31&t;return[e<<3|e>>2,r<<2|r>>4,i<<3|i>>2,255]}function _e(t,e,r){const i=t.map(((t,i)=>Math.floor(t*(1-r)+e[i]*r)));return i[3]=255,i}function we(t,e,r,i){const n=function(t,e,r){const i=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,s=fe(i),a=fe(n);return[s,a,_e(s,a,r&&i<=n?.5:1/3),r&&i<=n?[0,0,0,0]:_e(s,a,2/3)]}(e,r,i),s=function(t,e){let r=e+4,i=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];i[4*e+0]=3&n,i[4*e+1]=n>>2&3,i[4*e+2]=n>>4&3,i[4*e+3]=n>>6&3}return i}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[s[e]][r]}function pe(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function ge(t){let e=7&t,r=280&t,i=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=Dt&&(r=8),64!=i&&(i=32),e|r|i|128&t}function be(t,e){let{x:r=0,y:i=0,width:n=0,height:s=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;pe((function(o,h){let l=r+o,c=i+h;if(l>4}}(t,e,r):0!=(4&i)&&function(t,e,r){let i=e[r+0],n=e[r+1],s=de(i,n,i<=n?5:7),a=new Uint8Array(16),o=0,h=2;for(let t=0;t<2;t++){let t=0;for(let i=0;i<3;i++)t|=e[r+h]<<8*i,h++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=s[a[e]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function ve(t,e,r,i,n){const s=0!=(1&(n=ge(n)))?8:16;let a=0;!function(t,e,r){for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const s=new Uint8Array(64);let a=0,o=0;return pe((function(h,l){let c=e+h,d=r+l;if(c1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));let o=r.read(t),h=t.read(o);if(4==i)h=Re(h,n,s,ke);else if(5==i)h=Re(h,n,s,xe);else if(6==i)h=Re(h,n,s,Ae);else{if(2==i)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=i)throw new Error("Non-implemented Texture2D format type (".concat(i,") found."))}for(let t=0;t")}},BaseReader:At,BmFontReader:class extends At{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new St).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new St).write(t,e.export.data,null)}isValueType(){return!1}},BooleanReader:zt,CharReader:It,DictionaryReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let r={};const i=(new Et).read(t);for(let n=0;n")}},DoubleReader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},EffectReader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new Et).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Et).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Int32Reader:Bt,ListReader:Ot,NullableReader:Lt,RectangleReader:Nt,ReflectiveReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){return this.reader.read(t,e)}write(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}isValueType(){return!1}get type(){return"".concat(this.reader.type)}},SingleReader:Ct,SpriteFontReader:class extends At{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.SpriteFontReader"===t}static parseTypeList(){return["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new Bt,i=new Ct,n=new Lt(new It);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:i.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const i=new Bt,n=new It,s=new Ct,a=new Lt(n),o=new Ue,h=new Ot(new Nt),l=new Ot(n),c=new Ot(new Te);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),h.write(t,e.glyphs,r),h.write(t,e.cropping,r),l.write(t,e.characterMap,r),i.write(t,e.verticalLineSpacing,null),s.write(t,e.horizontalSpacing,null),c.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},StringReader:St,TBinReader:class extends At{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new Bt).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Bt).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Texture2DReader:Ue,UInt32Reader:Et,Vector2Reader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new Ct;return{x:e.read(t),y:e.read(t)}}},Vector3Reader:Te,Vector4Reader:class extends At{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new Ct;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}};var ze;ze=Se,a.setReaders(ze),t.Readers=Se,t.XnbContent=V,t.XnbData=D,t.addReaders=function(t){return a.addReaders(t)},t.bufferToContents=function(t){return vt((new Z).load(t))},t.bufferToXnb=mt,t.pack=function(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=kt(t);let n=[];for(let[t,e]of Object.entries(i))n.push(bt(e,r).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(n).then((t=>!0===r.debug?t:t.filter((t=>{let{status:e,value:r}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.unpackToContent=function(t){return yt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:r=!1,contentOnly:i=!1,fileName:n=null}=e;"undefined"!=typeof window&&null===n&&(n=t.name);let[s]=ht(n);const a=t=>ft(t,{yaml:r,contentOnly:i,fileName:s});return yt(t).then(a)},t.unpackToXnbData=yt,t.xnbDataToContent=vt,t.xnbDataToFiles=ft,Object.defineProperty(t,"__esModule",{value:!0})})); +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- + * + * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * -------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function i(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}function a(t){let e=[],r=[];for(let i=0;i")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=o.parseSubtypes(t).map(o.simplifyType.bind(o));return"".concat(e)}for(let e of Object.values(o.readers)){let r=o.makeSimplied(t,e);if(null!==r)return r}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.slice(t.search("`")+1);return e[0],e=a(e)[0],a(e)}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],r=t.match(/<(.+)>/);return r=r?r[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:r}}static getReaderTypeList(t){return o.getReader(t).parseTypeList()}static getReader(t){let{type:e,subtypes:r}=o.getTypeInfo(t);if(r=r.map(o.getReader.bind(o)),o.readers.hasOwnProperty("".concat(e,"Reader")))return new(o.readers["".concat(e,"Reader")])(...r);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=o.simplifyType(t);return o.getReader(e)}}n(o,"readers",{});const h=[192,224,240],l=128,c=63,d=[55296,56320],u=1023;function f(t){return t<128?[t]:t<2048?[h[0]|t>>6,l|t&c]:t<65536?[h[1]|t>>12,l|t>>6&c,l|t&c]:[h[2]|t>>18,l|t>>12&c,l|t>>6&c,l|t&c]}function _(t){return t<65535?[t]:[d[0]|(t-=65536)>>10&u,d[1]|t&u]}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const r=t.length;return 1===r?t[0]:2===r?((t[0]^h[0])<<6)+(t[1]^l):3===r?((t[0]^h[1])<<12)+((t[1]^l)<<6)+(t[2]^l):((t[0]^h[2])<<18)+((t[1]^l)<<12)+((t[2]^l)<<6)+(t[3]^l)}function p(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&u)<<10)+(t[1]&u)+65536}function g(t){return function(t){const e=[];for(let r of t)e.push(...f(r));return e}(function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;i1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const r=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-r}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const n=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:0;const e=[],r=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let r=0;r0;){const t=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),n=16-this.bitPosition-i,s=(t&2**i-1<>n;e-=i,this.bitPosition+=i,r|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),r=this.readByte();return t||this.seek(-2),e<<8|r}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class m{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),r=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}const v=256,k=0,x=1,A=2,E=3,R=656;class U{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!U.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)U.extra_bits[t]=U.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!U.position_base.length)for(let t=0,e=0;t<=50;t++)U.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),r=t.readLZXBits(8);switch(this.block_remaining=e<<8|r,this.block_type){case A:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case x:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(R,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case E:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&i>0;){if(e>i&&(e=i),i-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case A:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,R,12);if(i>3;if(s>2){let e=U.extra_bits[s];if(s=U.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case x:for(;e>0;){let r,i=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,R,12);if(i>3;if(s>2){if(3!=s){let e=U.extra_bits[s],r=t.readLZXBits(e);s=U.position_base[s]-2+r}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=n,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=n;n-- >0;)this.win[o++]=this.win[a++]}break;case E:if(t.bytePosition+e>r)throw new s("Overrun!"+r+" "+t.bytePosition+" "+e);for(let r=0;r>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let r=o;for(;r-- >0;)i[t++]=e}o>>=1}if(n==a)return i;for(let t=n;t>1>1;n<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let c=0;c>16;for(let r=0;r>15-r&1&&t++;if(i[t]=c,(n+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(n==a)return i;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,r,i,n){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(n)];if(a>=i){let t=1<<32-n;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=i)}return t.bitPosition+=r[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}U.position_base=[],U.extra_bits=[];class T{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24,r|=t[e++]<<32,r|=t[e++]<<40,r|=t[e++]<<48,r|=t[e++]<<56}static readU32(t,e){var r=0;return r|=t[e++]<<0,r|=t[e++]<<8,r|=t[e++]<<16,r|=t[e++]<<24}static writeU32(t,e,r){t[e++]=r>>0&255,t[e++]=r>>8&255,t[e++]=r>>16&255,t[e++]=r>>24&255}static imul(t,e){var r=65535&t,i=65535&e;return r*i+((t>>>16)*i+r*(e>>>16)<<16)|0}}const S=65536,z=15;!function(t){try{new Uint8Array(t)}catch(i){for(var e=new Array(t),r=0;r=13)for(var f=67;r+4>>0;if(s=n[w=(w>>16^w)>>>0&65535]-1,n[w]=r+1,s<0||r-s>>>16>0||T.readU32(t,s)!==_)r+=f++>>6;else{for(f=67,l=r-a,h=r-s,s+=4,o=r+=4;r=z){for(e[c++]=240+p,u=l-z;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=(l<<4)+p;for(var g=0;g>8,o>=15){for(u=o-15;u>=255;u-=255)e[c++]=255;e[c++]=u}a=r}}if(0===a)return 0;if((l=d-a)>=z){for(e[c++]=240,u=l-z;u>=255;u-=255)e[c++]=255;e[c++]=u}else e[c++]=l<<4;for(r=a;rt.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class C{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const r=N(e);t.write7BitNumber(r),t.writeString(e)}}class D{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e=0,r=this.readers.length;e"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class M{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const P=64,F=128,Z=14;class X{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new y(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==F){const e=this.fileSize-Z,r=class{static decompress(t,e,r){let i,n,a=0;const o=new U(16);let h=new m(r);for(;a65536||n>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,n,i)),a+=i}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(r,Z,0,t),this.buffer.bytePosition=Z}else if(this.compressionType==P){const e=this.buffer.buffer.slice(Z),r=new Uint8Array(e),i=new Uint8Array(t);!function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*r,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,c=void 0!==e.copyWithin&&void 0!==e.fill;for(o=r+i;r>4;if(u>0){if(15===u)for(;u+=t[r],255===t[r++];);for(h=r+u;r=o)break;if(s=15&d,a=t[r++]|t[r++]<<8,15===s)for(;s+=t[r],255===t[r++];);if(s+=4,c&&1===a)e.fill(0|e[n-1],n,n+s),n+=s;else if(c&&a>s&&s>31)e.copyWithin(n,n-a,n-a+s),n+=s;else for(h=(l=n-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function r(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let r=0;const i=t.length;let n=0,s=Math.max(32,i+(i>>1)+7),a=new Uint8Array(s>>3<<3);for(;r=55296&&e<=56319){if(r=55296&&e<=56319)continue}if(n+4>a.length){s+=8,s*=1+r/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[n++]=e>>6&31|192;else if(0==(4294901760&e))a[n++]=e>>12&15|224,a[n++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[n++]=e>>18&7|240,a[n++]=e>>12&63|128,a[n++]=e>>6&63|128}a[n++]=63&e|128}else a[n++]=e}return a.slice(0,n)},Object.defineProperty(r.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(r.prototype,"fatal",{value:!1}),Object.defineProperty(r.prototype,"ignoreBOM",{value:!1}),r.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const r=new Uint8Array(t);let i=0;const n=r.length,s=[];for(;i65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=r}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},j={};function H(t){var e=j[t];if(void 0!==e)return e.exports;var r=j[t]={exports:{}};return W[t].call(r.exports,r,r.exports,H),r.exports}H.d=(t,e)=>{for(var r in e)H.o(e,r)&&!H.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},H.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var K={};(()=>{H.d(K,{P:()=>Ir,m:()=>Br}),H(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class r{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=!1;"number"==typeof t?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=i?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let r=0;r0&&void 0!==arguments[0]?arguments[0]:1;return r=this.readBytes(e),t.decode(r);var r}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function n(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);n(l);const c=new Array(60);n(c);const d=new Array(512);n(d);const u=new Array(256);n(u);const f=new Array(29);n(f);const _=new Array(30);function w(t,e,r,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let p,g,b;function y(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(_);const m=t=>t<256?d[t]:d[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,r)=>{t.bi_valid>16-r?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=r-16):(t.bi_buf|=e<{k(t,r[2*e],r[2*e+1])},A=(t,e)=>{let r=0;do{r|=1&t,t>>>=1,r<<=1}while(--e>0);return r>>>1},E=(t,e,r)=>{const i=new Array(16);let n,s,a=0;for(n=1;n<=15;n++)i[n]=a=a+r[n-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=A(i[e]++,e))}},R=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},U=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},T=(t,e,r,i)=>{const n=2*e,s=2*r;return t[n]{const i=t.heap[r];let n=r<<1;for(;n<=t.heap_len&&(n{let i,n,o,h,l=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],n=t.pending_buf[t.l_buf+l],l++,0===i?x(t,n,e):(o=u[n],x(t,o+256+1,e),h=s[o],0!==h&&(n-=f[o],k(t,n,h)),i--,o=m(i),x(t,o,r),h=a[o],0!==h&&(i-=_[o],k(t,i,h)))}while(l{const r=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)S(t,r,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],S(t,r,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,r[2*h]=r[2*a]+r[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,r[2*a+1]=r[2*o+1]=h,t.heap[1]=h++,S(t,r,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const r=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,d,u,f,_,w=0;for(u=0;u<=15;u++)t.bl_count[u]=0;for(r[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],u=r[2*r[2*c+1]+1]+1,u>h&&(u=h,w++),r[2*c+1]=u,c>i||(t.bl_count[u]++,f=0,c>=o&&(f=a[c-o]),_=r[2*c],t.opt_len+=_*(u+f),s&&(t.static_len+=_*(n[2*c+1]+f)));if(0!==w){do{for(u=h-1;0===t.bl_count[u];)u--;t.bl_count[u]--,t.bl_count[u+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(u=h;0!==u;u--)for(c=t.bl_count[u];0!==c;)d=t.heap[--l],d>i||(r[2*d+1]!==u&&(t.opt_len+=(u-r[2*d+1])*r[2*d],r[2*d+1]=u),c--)}})(t,e),E(r,l,t.bl_count)},I=(t,e,r)=>{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(r+1)+1]=65535,i=0;i<=r;i++)n=a,a=e[2*(i+1)+1],++o{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),i=0;i<=r;i++)if(n=a,a=e[2*(i+1)+1],!(++o{k(t,0+(i?1:0),3),((t,e,r,i)=>{U(t),v(t,r),v(t,~r),t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r})(t,e,r)};var C={_tr_init:t=>{L||((()=>{let t,e,r,i,n;const h=new Array(16);for(r=0,i=0;i<28;i++)for(f[i]=r,t=0;t<1<>=7;i<30;i++)for(_[i]=n<<7,t=0;t<1<{let n,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),B(t,t.l_desc),B(t,t.d_desc),a=(t=>{let e;for(I(t,t.dyn_ltree,t.l_desc.max_code),I(t,t.dyn_dtree,t.d_desc.max_code),B(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=n&&(n=s)):n=s=r+5,r+4<=n&&-1!==e?N(t,e,r,i):4===t.strategy||s===n?(k(t,2+(i?1:0),3),z(t,l,c)):(k(t,4+(i?1:0),3),((t,e,r,i)=>{let n;for(k(t,e-257,5),k(t,r-1,5),k(t,i-4,4),n=0;n(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(u[r]+256+1)]++,t.dyn_dtree[2*m(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},D=(t,e,r,i)=>{let n=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==r;){a=r>2e3?2e3:r,r-=a;do{n=n+e[i++]|0,s=s+n|0}while(--a);n%=65521,s%=65521}return n|s<<16|0};const V=new Uint32Array((()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e})());var M=(t,e,r,i)=>{const n=V,s=i+r;t^=-1;for(let r=i;r>>8^n[255&(t^e[r])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},F={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Z,_tr_stored_block:X,_tr_flush_block:W,_tr_tally:j,_tr_align:G}=C,{Z_NO_FLUSH:Y,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:q,Z_FINISH:$,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:rt,Z_DATA_ERROR:it,Z_BUF_ERROR:nt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:ct,Z_UNKNOWN:dt,Z_DEFLATED:ut}=F,ft=258,_t=262,wt=103,pt=113,gt=666,bt=(t,e)=>(t.msg=P[e],e),yt=t=>(t<<1)-(t>4?9:0),mt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,r)=>(e<{const e=t.state;let r=e.pending;r>t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},At=(t,e)=>{t.pending_buf[t.pending++]=e},Et=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=(t,e,r,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),r),1===t.state.wrap?t.adler=D(t.adler,e,n,r):2===t.state.wrap&&(t.adler=M(t.adler,e,n,r)),t.next_in+=n,t.total_in+=n,n)},Ut=(t,e)=>{let r,i,n=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,c=t.w_mask,d=t.prev,u=t.strstart+ft;let f=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(r=e,l[r+a]===_&&l[r+a-1]===f&&l[r]===l[s]&&l[++r]===l[s+1]){s+=2,r++;do{}while(l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&sa){if(t.match_start=e,a=i,i>=o)break;f=l[s+a-1],_=l[s+a]}}}while((e=d[e&c])>h&&0!=--n);return a<=t.lookahead?a:t.lookahead},Tt=t=>{const e=t.w_size;let r,i,n,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,r=i;do{n=t.head[--r],t.head[r]=n>=e?n-e:0}while(--i);i=e,r=i;do{n=t.prev[--r],t.prev[r]=n>=e?n-e:0}while(--i);s+=e}if(0===t.strm.avail_in)break;if(i=Rt(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=i,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},St=(t,e)=>{let r,i;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-_t&&(t.match_length=Ut(t,r)),t.match_length>=3)if(i=j(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else i=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},zt=(t,e)=>{let r,i,n;for(;;){if(t.lookahead<_t){if(Tt(t),t.lookahead<_t&&e===Y)return 1;if(0===t.lookahead)break}if(r=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==r&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-3,i=j(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=j(t,0,t.window[t.strstart-1]),i&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=j(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Bt(t,e,r,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=i,this.func=n}const It=[new Bt(0,0,0,0,((t,e)=>{let r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===Y)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+r;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Bt(4,4,8,4,St),new Bt(4,5,16,8,St),new Bt(4,6,32,32,St),new Bt(4,4,16,16,zt),new Bt(8,16,32,32,zt),new Bt(8,16,128,128,zt),new Bt(8,32,128,256,zt),new Bt(32,128,258,1024,zt),new Bt(32,258,258,4096,zt)];function Ot(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ut,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),mt(this.dyn_ltree),mt(this.dyn_dtree),mt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),mt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),mt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Lt=t=>{const e=(t=>{if(!t||!t.state)return bt(t,rt);t.total_in=t.total_out=0,t.data_type=dt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=Y,Z(e),tt})(t);var r;return e===tt&&((r=t.state).window_size=2*r.w_size,mt(r.head),r.max_lazy_match=It[r.level].max_lazy,r.good_match=It[r.level].good_length,r.nice_match=It[r.level].nice_length,r.max_chain_length=It[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),e};var Nt=(t,e,r,i,n,s)=>{if(!t)return rt;let a=1;if(e===st&&(e=6),i<0?(a=0,i=-i):i>15&&(a=2,i-=16),n<1||n>9||r!==ut||i<8||i>15||e<0||e>9||s<0||s>lt)return bt(t,rt);8===i&&(i=9);const o=new Ot;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=i,o.w_size=1<{let r,i;if(!t||!t.state||e>Q||e<0)return t?bt(t,rt):rt;const n=t.state;if(!t.output||!t.input&&0!==t.avail_in||n.status===gt&&e!==$)return bt(t,0===t.avail_out?nt:rt);n.strm=t;const s=n.last_flush;if(n.last_flush=e,42===n.status)if(2===n.wrap)t.adler=0,At(n,31),At(n,139),At(n,8),n.gzhead?(At(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),At(n,255&n.gzhead.time),At(n,n.gzhead.time>>8&255),At(n,n.gzhead.time>>16&255),At(n,n.gzhead.time>>24&255),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(At(n,255&n.gzhead.extra.length),At(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=M(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(At(n,0),At(n,0),At(n,0),At(n,0),At(n,0),At(n,9===n.level?2:n.strategy>=ot||n.level<2?4:0),At(n,3),n.status=pt);else{let e=ut+(n.w_bits-8<<4)<<8,r=-1;r=n.strategy>=ot||n.level<2?0:n.level<6?1:6===n.level?2:3,e|=r<<6,0!==n.strstart&&(e|=32),e+=31-e%31,n.status=pt,Et(n,e),0!==n.strstart&&(Et(n,t.adler>>>16),Et(n,65535&t.adler)),t.adler=1}if(69===n.status)if(n.gzhead.extra){for(r=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending!==n.pending_buf_size));)At(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),kt(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindexr&&(t.adler=M(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.status=wt)}else n.status=wt;if(n.status===wt&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&kt(t),n.pending+2<=n.pending_buf_size&&(At(n,255&t.adler),At(n,t.adler>>8&255),t.adler=0,n.status=pt)):n.status=pt),0!==n.pending){if(kt(t),0===t.avail_out)return n.last_flush=-1,tt}else if(0===t.avail_in&&yt(e)<=yt(s)&&e!==$)return bt(t,nt);if(n.status===gt&&0!==t.avail_in)return bt(t,nt);if(0!==t.avail_in||0!==n.lookahead||e!==Y&&n.status!==gt){let r=n.strategy===ot?((t,e)=>{let r;for(;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===Y)return 1;break}if(t.match_length=0,r=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):n.strategy===ht?((t,e)=>{let r,i,n,s;const a=t.window;for(;;){if(t.lookahead<=ft){if(Tt(t),t.lookahead<=ft&&e===Y)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(n=t.strstart-1,i=a[n],i===a[++n]&&i===a[++n]&&i===a[++n])){s=t.strstart+ft;do{}while(i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(r=j(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=j(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===$?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(n,e):It[n.level].func(n,e);if(3!==r&&4!==r||(n.status=gt),1===r||3===r)return 0===t.avail_out&&(n.last_flush=-1),tt;if(2===r&&(e===J?G(n):e!==Q&&(X(n,0,0,!1),e===q&&(mt(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),kt(t),0===t.avail_out))return n.last_flush=-1,tt}return e!==$?tt:n.wrap<=0?et:(2===n.wrap?(At(n,255&t.adler),At(n,t.adler>>8&255),At(n,t.adler>>16&255),At(n,t.adler>>24&255),At(n,255&t.total_in),At(n,t.total_in>>8&255),At(n,t.total_in>>16&255),At(n,t.total_in>>24&255)):(Et(n,t.adler>>>16),Et(n,65535&t.adler)),kt(t),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?tt:et)},Dt=t=>{if(!t||!t.state)return rt;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==gt?bt(t,rt):(t.state=null,e===pt?bt(t,it):tt)};const Vt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Mt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const r=e.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const e in r)Vt(r,e)&&(t[e]=r[e])}}return t},Pt=t=>{let e=0;for(let r=0,i=t.length;r=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Zt[254]=Zt[254]=1;var Xt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,r,i,n,s,a=t.length,o=0;for(n=0;n>>6,e[s++]=128|63&r):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|63&r):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|63&r);return e},Wt=(t,e)=>{const r=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,n;const s=new Array(2*r);for(n=0,i=0;i4)s[n++]=65533,i+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&i1?s[n++]=65533:e<65536?s[n++]=e:(e-=65536,s[n++]=55296|e>>10&1023,s[n++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Ft)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let i=0;i{(e=e||t.length)>t.length&&(e=t.length);let r=e-1;for(;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+Zt[t[r]]>e?r:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Gt,Z_SYNC_FLUSH:Yt,Z_FULL_FLUSH:Jt,Z_FINISH:qt,Z_OK:$t,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:re}=F;function ie(t){this.options=Mt({level:te,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Nt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==$t)throw new Error(P[r]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=((t,e)=>{let r=e.length;if(!t||!t.state)return rt;const i=t.state,n=i.wrap;if(2===n||1===n&&42!==i.status||i.lookahead)return rt;if(1===n&&(t.adler=D(t.adler,e,r,0)),i.wrap=0,r>=i.w_size){0===n&&(mt(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(r-i.w_size,r),0),e=t,r=i.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Tt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=vt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Tt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,i.wrap=n,tt})(this.strm,t),r!==$t)throw new Error(P[r]);this._dict_set=!0}}function ne(t,e){const r=new ie(e);if(r.push(t,!0),r.err)throw r.msg||P[r.err];return r.result}ie.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?qt:Gt,"string"==typeof t?r.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),(s===Yt||s===Jt)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(n=Ct(r,s),n===Qt)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),n=Dt(this.strm),this.onEnd(n),this.ended=!0,n===$t;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===$t&&(this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ie,deflate:ne,deflateRaw:function(t,e){return(e=e||{}).raw=!0,ne(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,ne(t,e)},constants:F},ae=function(t,e){let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A,E;const R=t.state;r=t.next_in,A=t.input,i=r+(t.avail_in-5),n=t.next_out,E=t.output,s=n-(e-t.avail_out),a=n+(t.avail_out-257),o=R.dmax,h=R.wsize,l=R.whave,c=R.wnext,d=R.window,u=R.hold,f=R.bits,_=R.lencode,w=R.distcode,p=(1<>>24,u>>>=y,f-=y,y=b>>>16&255,0===y)E[n++]=65535&b;else{if(!(16&y)){if(0==(64&y)){b=_[(65535&b)+(u&(1<>>=y,f-=y),f<15&&(u+=A[r++]<>>24,u>>>=y,f-=y,y=b>>>16&255,!(16&y)){if(0==(64&y)){b=w[(65535&b)+(u&(1<o){t.msg="invalid distance too far back",R.mode=30;break t}if(u>>>=y,f-=y,y=n-s,v>y){if(y=v-y,y>l&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=d,0===c){if(k+=h-y,y2;)E[n++]=x[k++],E[n++]=x[k++],E[n++]=x[k++],m-=3;m&&(E[n++]=x[k++],m>1&&(E[n++]=x[k++]))}else{k=n-v;do{E[n++]=E[k++],E[n++]=E[k++],E[n++]=E[k++],m-=3}while(m>2);m&&(E[n++]=E[k++],m>1&&(E[n++]=E[k++]))}break}}break}}while(r>3,r-=m,f-=m<<3,u&=(1<{const h=o.bits;let l,c,d,u,f,_,w=0,p=0,g=0,b=0,y=0,m=0,v=0,k=0,x=0,A=0,E=null,R=0;const U=new Uint16Array(16),T=new Uint16Array(16);let S,z,B,I=null,O=0;for(w=0;w<=15;w++)U[w]=0;for(p=0;p=1&&0===U[b];b--);if(y>b&&(y=b),0===b)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(T[1]=0,w=1;w<15;w++)T[w+1]=T[w]+U[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){S=w-v,a[p]<_?(z=0,B=a[p]):a[p]>_?(z=I[O+a[p]],B=E[R+a[p]]):(z=96,B=0),l=1<>v)+c]=S<<24|z<<16|B|0}while(0!==c);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--U[w]){if(w===b)break;w=e[r+a[p]]}if(w>y&&(A&u)!==d){for(0===v&&(v=y),f+=g,m=w-v,k=1<852||2===t&&x>592)return 1;d=A&u,n[d]=y<<24|m<<16|f-s|0}}return 0!==A&&(n[f+A]=w-v<<24|64<<16|0),o.bits=y,0};const{Z_FINISH:ue,Z_BLOCK:fe,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:ge,Z_STREAM_ERROR:be,Z_DATA_ERROR:ye,Z_MEM_ERROR:me,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=F,xe=12,Ae=30,Ee=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Re(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Ue=t=>{if(!t||!t.state)return be;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return be;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Te,Se,ze=!0;const Be=t=>{if(ze){Te=new Int32Array(512),Se=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(de(1,t.lens,0,288,Te,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;de(2,t.lens,0,32,Se,0,t.work,{bits:5}),ze=!1}t.lencode=Te,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=(t,e,r,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(r-i,r-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(r-i,r),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return be;const r=new Re;t.state=r,r.window=null;const i=((t,e)=>{let r;if(!t||!t.state)return be;const i=t.state;return e<0?(r=0,e=-e):(r=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?be:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=r,i.wbits=e,Ue(t))})(t,e);return i!==we&&(t.state=null),i},Ne=(t,e)=>{let r,i,n,s,a,o,h,l,c,d,u,f,_,w,p,g,b,y,m,v,k,x,A=0;const E=new Uint8Array(4);let R,U;const T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return be;r=t.state,r.mode===xe&&(r.mode=13),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,d=o,u=h,x=we;t:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0),l=0,c=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=Ae;break}if((15&l)!==ke){t.msg="unknown compression method",r.mode=Ae;break}if(l>>>=4,c-=4,k=8+(15&l),0===r.wbits)r.wbits=k;else if(k>r.wbits){t.msg="invalid window size",r.mode=Ae;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=3;case 3:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>8&255,E[2]=l>>>16&255,E[3]=l>>>24&255,r.check=M(r.check,E,4,0)),l=0,c=0,r.mode=4;case 4:for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>8),512&r.flags&&(E[0]=255&l,E[1]=l>>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0,r.mode=5;case 5:if(1024&r.flags){for(;c<16;){if(0===o)break t;o--,l+=i[s++]<>>8&255,r.check=M(r.check,E,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(f=r.length,f>o&&(f=o),f&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(i.subarray(s,s+f),k)),512&r.flags&&(r.check=M(r.check,i,f,s)),o-=f,s+=f,r.length-=f),r.length))break t;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break t;f=0;do{k=i[s+f++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&f>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=xe;break;case 10:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<>>=7&c,c-=7&c,r.mode=27;break}for(;c<3;){if(0===o)break t;o--,l+=i[s++]<>>=1,c-=1,3&l){case 0:r.mode=14;break;case 1:if(Be(r),r.mode=20,e===_e){l>>>=2,c-=2;break t}break;case 2:r.mode=17;break;case 3:t.msg="invalid block type",r.mode=Ae}l>>>=2,c-=2;break;case 14:for(l>>>=7&c,c-=7&c;c<32;){if(0===o)break t;o--,l+=i[s++]<>>16^65535)){t.msg="invalid stored block lengths",r.mode=Ae;break}if(r.length=65535&l,l=0,c=0,r.mode=15,e===_e)break t;case 15:r.mode=16;case 16:if(f=r.length,f){if(f>o&&(f=o),f>h&&(f=h),0===f)break t;n.set(i.subarray(s,s+f),a),o-=f,s+=f,h-=f,a+=f,r.length-=f;break}r.mode=xe;break;case 17:for(;c<14;){if(0===o)break t;o--,l+=i[s++]<>>=5,c-=5,r.ndist=1+(31&l),l>>>=5,c-=5,r.ncode=4+(15&l),l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Ae;break}r.have=0,r.mode=18;case 18:for(;r.have>>=3,c-=3}for(;r.have<19;)r.lens[T[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,R={bits:r.lenbits},x=de(0,r.lens,0,19,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid code lengths set",r.mode=Ae;break}r.have=0,r.mode=19;case 19:for(;r.have>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=p,c-=p,r.lens[r.have++]=b;else{if(16===b){for(U=p+2;c>>=p,c-=p,0===r.have){t.msg="invalid bit length repeat",r.mode=Ae;break}k=r.lens[r.have-1],f=3+(3&l),l>>>=2,c-=2}else if(17===b){for(U=p+3;c>>=p,c-=p,k=0,f=3+(7&l),l>>>=3,c-=3}else{for(U=p+7;c>>=p,c-=p,k=0,f=11+(127&l),l>>>=7,c-=7}if(r.have+f>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Ae;break}for(;f--;)r.lens[r.have++]=k}}if(r.mode===Ae)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=Ae;break}if(r.lenbits=9,R={bits:r.lenbits},x=de(1,r.lens,0,r.nlen,r.lencode,0,r.work,R),r.lenbits=R.bits,x){t.msg="invalid literal/lengths set",r.mode=Ae;break}if(r.distbits=6,r.distcode=r.distdyn,R={bits:r.distbits},x=de(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,R),r.distbits=R.bits,x){t.msg="invalid distances set",r.mode=Ae;break}if(r.mode=20,e===_e)break t;case 20:r.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,ae(t,u),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,r.mode===xe&&(r.back=-1);break}for(r.back=0;A=r.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=xe;break}if(64&g){t.msg="invalid literal/length code",r.mode=Ae;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;A=r.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<>y)],p=A>>>24,g=A>>>16&255,b=65535&A,!(y+p<=c);){if(0===o)break t;o--,l+=i[s++]<>>=y,c-=y,r.back+=y}if(l>>>=p,c-=p,r.back+=p,64&g){t.msg="invalid distance code",r.mode=Ae;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(U=r.extra;c>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Ae;break}r.mode=25;case 25:if(0===h)break t;if(f=u-h,r.offset>f){if(f=r.offset-f,f>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Ae;break}f>r.wnext?(f-=r.wnext,_=r.wsize-f):_=r.wnext-f,f>r.length&&(f=r.length),w=r.window}else w=n,_=a-r.offset,f=r.length;f>h&&(f=h),h-=f,r.length-=f;do{n[a++]=w[_++]}while(--f);0===r.length&&(r.mode=21);break;case 26:if(0===h)break t;n[a++]=r.length,h--,r.mode=21;break;case 27:if(r.wrap){for(;c<32;){if(0===o)break t;o--,l|=i[s++]<{if(!t||!t.state)return be;let e=t.state;return e.window&&(e.window=null),t.state=null,we},De=(t,e)=>{const r=e.length;let i,n,s;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?be:11===i.mode&&(n=1,n=D(n,e,r,0),n!==i.check)?ye:(s=Ie(t,e,r,r),s?(i.mode=31,me):(i.havedict=1,we))):be},Ve=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Me=Object.prototype.toString,{Z_NO_FLUSH:Pe,Z_FINISH:Fe,Z_OK:Ze,Z_STREAM_END:Xe,Z_NEED_DICT:We,Z_STREAM_ERROR:je,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=F;function Ge(t){this.options=Mt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let r=Le(this.strm,e.windowBits);if(r!==Ze)throw new Error(P[r]);if(this.header=new Ve,((t,e)=>{if(!t||!t.state)return be;const r=t.state;0==(2&r.wrap)||(r.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Me.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=De(this.strm,e.dictionary),r!==Ze)))throw new Error(P[r])}function Ye(t,e){const r=new Ge(e);if(r.push(t),r.err)throw r.msg||P[r.err];return r.result}Ge.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Fe:Pe,"[object ArrayBuffer]"===Me.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),s=Ne(r,a),s===We&&n&&(s=De(r,n),s===Ze?s=Ne(r,a):s===He&&(s=We));r.avail_in>0&&s===Xe&&r.state.wrap>0&&0!==t[r.next_in];)Oe(r),s=Ne(r,a);switch(s){case je:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=r.avail_out,r.next_out&&(0===r.avail_out||s===Xe))if("string"===this.options.to){let t=jt(r.output,r.next_out),e=r.next_out-t,n=Wt(r.output,t);r.next_out=e,r.avail_out=i-e,e&&r.output.set(r.output.subarray(t,t+e),0),this.onData(n)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(s!==Ze||0!==o){if(s===Xe)return s=Ce(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Ge.prototype.onData=function(t){this.chunks.push(t)},Ge.prototype.onEnd=function(t){t===Ze&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Pt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ge,inflate:Ye,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ye(t,e)},ungzip:Ye,constants:F};const{Deflate:qe,deflate:$e,deflateRaw:Qe,gzip:tr}=se,{Inflate:er,inflate:rr,inflateRaw:ir,ungzip:nr}=Je;var sr=$e,ar=er,or=rr;const hr=[137,80,78,71,13,10,26,10],lr=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;lr[t]=e}function cr(t,e){return(4294967295^function(t,e,r){let i=4294967295;for(let t=0;t>>8;return i}(0,t,e))>>>0}var dr,ur,fr,_r;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(dr||(dr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ur||(ur={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(fr||(fr={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_r||(_r={}));const wr=new Uint8Array(0),pr=new Uint16Array([255]),gr=255===new Uint8Array(pr.buffer)[0];class br extends r{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:r=!1}=e;this._checkCrc=r,this._inflator=new ar,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ur.UNKNOWN,this._filterMethod=fr.UNKNOWN,this._interlaceMethod=_r.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=n;var l}}function yr(t,e,r){for(let i=0;i>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xr(t,e,r,i,n){let s=0;if(0===r.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=dr.UNKNOWN,this._zlibOptions=i(i({},Er),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hr)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ur.DEFLATE),this.writeByte(fr.ADAPTIVE),this.writeByte(_r.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:i,depth:n,data:s}=this._png,a=i*t,o=(new r).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Tr(t,e,r,i){for(let n=0;nnew Rr({width:t,height:e,data:r},void 0).encode(),Ir=t=>function(t,e){return new br(t,void 0).decode()}(t)})();var G=K.P,Y=K.m;function J(t,e,r){if((i=t)&&i.hasOwnProperty("type")&&i.hasOwnProperty("data")){let i=J(t.data,e,r);return i.includes("\n")?" #!"+t.type+i:i+" #!"+t.type}if(t&&"object"==typeof t){let i=Array.isArray(t);if(0==Object.keys(t).length)return i?"[]":"{}";let n="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(n+=e.repeat(r+1),i?n+="- "+J(t[s],e,r+1):s.includes(": ")?(n+=J(s,e,r+1),n+=": "+J(t[s],e,r+1)):n+=s+": "+J(t[s],e,r+1),n+="\n");return n}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var i}function q(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var r="";return"number"==typeof e?r=" ".repeat(Math.min(10,e)):"string"==typeof e&&(r=e.slice(0,10)),J(t,r,-1)}class ${constructor(t,e,r){this.startingLine=r||0,this.lineIndex=-1;let i=[];for(let e=0;e=e;)t.push(this.next());return new $(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,r=this.getLine(t);for(;r.startsWith(this.indentString);)r=r.slice(this.indentString.length),e++;return e}}function Q(t,e){let r;for(t.indentLevel();!t.finished();){let e,i,n,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(n=o[1],s=s.replace(o[0],"")),a?(r||(r={}),e=a[1],i=s.replace(a[0],"").trim()):s.startsWith("-")&&(r||(r=[]),i=s.slice(1).trim()),i=i?tt(i,n):Q(t.nextGroup(),n),Array.isArray(r)?r.push(i):r[e]=i}return e&&(r={type:e,data:r}),r}function tt(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function et(t){let e=t.replace(/\t/g,"\t").split("\n");return Q(new $(e))}function rt(t){let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(rt(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=rt(i);return e}return t}function it(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":case"Rect":return!0;default:return!1}}function nt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function st(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:r}=t;if(it(e))return rt(r);if(nt(e))return r=rt(r),"Texture2D"===e?r.export="Texture2D.png":"Effect"===e?r.export="Effect.cso":"TBin"===e?r.export="TBin.tbin":"BmFont"===e&&(r.export="BmFont.xml"),r;if(e.startsWith("Nullable"))return null===r||null===r.data?null:st(r.data);t=rt(r)}let e;if(Array.isArray(t)){e=[];for(let r of t)e.push(st(r));return e}if(t&&"object"==typeof t){e={};for(let[r,i]of Object.entries(t))e[r]=st(i);return e}return null}function at(t){const e={},{compressed:r,formatVersion:i,hidef:n,target:s}=t.header;let a=rt(t.readers);e.xnbData={target:s,compressed:!!r,hiDef:n,readerData:a,numSharedResources:0};const h=rt(t.content),l=o.simplifyType(a[0].type);let c=o.getReaderTypeList(l);"SpriteFont"===c[0]&&(c=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:d,extractedImages:u,extractedMaps:f}=function(t,e){let r=[],i=[];const{converted:n}=function t(n,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(it(o))return{converted:{type:o,data:n},traversed:a};if(null===o)return{converted:n,traversed:a};if(o.startsWith("Nullable")){let r,i,[h,l=1]=o.split(":");if(l=+l,null===n)r=null,i=a+l;else if("object"!=typeof n||n&&0!==Object.keys(n).length){let{converted:e,traversed:o}=t(n,[...s],a+1);r=e,i=o}else r={type:e[a+1],data:rt(n)},i=a+l;return{converted:{type:h,data:{data:r}},traversed:i}}if(nt(o))return"Texture2D"===o?(r.push({path:s.join(".")}),{converted:{type:o,data:{format:n.format}},traversed:a}):("TBin"===o&&i.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(n)?[]:{};let l=a,c=!0,d=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,r]of Object.entries(n)){let r;r=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:i,traversed:u}=t(n[e],[...s,e],r);h[e]=i,d?l=u:c&&(l=u,c=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:n,extractedImages:r,extractedMaps:i}}(h,c);return e.content=d,u.length>0&&(e.extractedImages=u),f.length>0&&(e.extractedMaps=f),e}function ot(t){const e={},{compressed:r,readerData:i,hiDef:n,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:r?"a"===s||"i"===s?64:128:0,hidef:n},e.readers=rt(i),e.content=st(t.content),"SpriteFont"===o.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ht(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let r of Object.values(t))if(r||"object"==typeof r){let t=ht(r,e);if(t)return t}return null}}function lt(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function ct(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function dt(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ut(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:dt(e)}),extension:ct(e)}:{data:t,extension:ct(e)}}function ft(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=ht(t,"export");if(r){const{value:t}=r;let{type:e,data:i}=t;return"Texture2D"===e&&(i=Y(t.width,t.height,new Uint8Array(i))),ut(i,e)}if(e){return ut(JSON.stringify(t,null,4),"JSON")}return null}function _t(t){let{yaml:e=!1,contentOnly:r=!1,fileName:i=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&r&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const n=[],{content:a}=t,o=ft(a,r);if(null!==o&&n.push(o),r)return n;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof i&&""!==i?"".concat(i,".").concat(ct(e.type)):"".concat(e.type,".").concat(ct(e.type)):e),4);let l=h;return e&&(l=q(at(t))),n.unshift(ut(l,e?"yaml":"JSON")),n}function wt(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function gt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function bt(t,e){if("png"===t){const t=await gt(e.png),r=G(new Uint8Array(t));return{type:"Texture2D",data:r.data,width:r.width,height:r.height}}if("cso"===t){return{type:"Effect",data:await gt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await gt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await pt(e.xml)}}}async function yt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:r="default"}=e,i=t.json||t.yaml;if(!i)throw new s("There is no JSON or YAML file to pack!");const n=await pt(i);let a=null;a=t.json?JSON.parse(n):ot(et(n));let o=wt(r);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(i.name,' does not have "content".'));const h=ht(a.content,"export");if(h){const{parent:e,value:r}=h,[,i]=lt(r);e.export=await bt(i,t)}return a}async function mt(t){if("undefined"!=typeof window){const[,e]=lt(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return vt(await t.arrayBuffer())}return vt(t.buffer)}function vt(t){return(new X).load(t)}function kt(t){const{content:e}=t,{data:r,extension:i}=ft(e,!0);return new M(r,i)}function xt(t){let e={};for(let r=0;rt.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class zt extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const i=St(e);t.write7BitNumber(i),t.writeString(e)}isValueType(){return!1}}class Bt extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class It extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class Ot extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class Lt extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const r=(new Rt).read(t),i=[];for(let n=0;n")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}}class Nt extends Et{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new Bt;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}parseTypeList(){const t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length),...t]}}class Ct extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new Ot;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const i=new Ot;i.write(t,e.x,null),i.write(t,e.y,null),i.write(t,e.width,null),i.write(t,e.height,null)}}class Dt extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const Vt=256;function Mt(t,e,r,i){let n=Array(i);for(let t=0;t{let n=e.map((t=>t[i]));return{value:t[i],vec:n}}));return i.sort(((t,e)=>e.value-t.value)),[i.map((t=>{let{value:e}=t;return e})),i.map((t=>{let{vec:e}=t;return e}))]}function jt(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,i=Array(r),n=Math.abs(e/r),s=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],i=a[0][1],n=Mt(e,i,Pt(t[e][e],t[i][i],t[e][i]),r);t=Zt(n,t),s=Xt(s,n),a=Ft(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:Ht.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new Ht(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Kt(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,i]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:Kt.multScalar(this,1/this.length)}get xyz(){return new Ht(this.x,this.y,this.z)}get splatX(){return new Kt(this.x)}get splatY(){return new Kt(this.y)}get splatZ(){return new Kt(this.z)}get splatW(){return new Kt(this.w)}clone(){return new Kt(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=i,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new Kt(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new Kt(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new Kt(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new Kt(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let i=Kt.multScalar(t,1-r),n=Kt.multScalar(e,r);return Kt.add(i,n)}static multiplyAdd(t,e,r){return new Kt(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new Kt(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(i,e[n]),t)),new Ht(0));i.mult(1/r);let n=t.reduce(((t,r,n)=>{let s=e[n],a=Ht.sub(r,i);return t[0][0]+=a.x*a.x*s,t[0][1]+=a.x*a.y*s,t[0][2]+=a.x*a.z*s,t[1][1]+=a.y*a.y*s,t[1][2]+=a.y*a.z*s,t[2][2]+=a.z*a.z*s,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new Ht(...jt(r))}const Yt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],Jt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],qt=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],$t=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function Qt(t,e){const r=parseInt(t+.5);return r<0?0:r}function te(t){return Qt(31*t.x)<<11|Qt(63*t.y)<<5|Qt(31*t.z)}function ee(t,e,r,i,n){i[n+0]=255&t,i[n+1]=t>>8,i[n+2]=255&e,i[n+3]=e>>8;for(let t=0;t<4;t++)i[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function re(t,e,r,i,n){let s,a=te(t),o=te(e);a<=o?s=r.slice():([a,o]=[o,a],s=r.map((t=>0===t?1:1===t?0:t))),ee(a,o,s,i,n)}function ie(t,e,r,i,n){let s,a=te(t),o=te(e);a3&(1^t)))):s=a==o?new Array(16).fill(0):r.slice(),ee(a,o,s,i,n)}class ne{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const i=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!i)){const e=this._remap[s],i=(t[4*r+3]+1)/256;this._weights[e]+=n?i:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,i)=>e[i]=r[i]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,i)=>e[i]=r[i]))}}class se{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class ae extends se{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new Ht(0),this.end=new Ht(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorre(r,i,n,t,e)))}compress4(t,e){const r=[qt,$t,qt];this.compressBase(r,((r,i,n)=>ie(r,i,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let i=0;for(let n=0;n<3;n++){const s=t[n],a=this.color[n];r[n]=s[a][e];const o=r[n][2];i+=o*o}i{let r=1/0;const n=t.reduce(((t,i,n)=>{const s=Ht.sub(e,i).multVector(this.metric).lengthSq;return s>=r?t:(r=s,n)}),0);return i+=r,n}));if(ire(r,i,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),Ht.interpolate(this.start,this.end,1/3),Ht.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,i,n)=>ie(r,i,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const i=Gt(e,r);let n,s,a,o;n=s=e[0],a=o=Ht.dot(n,i);for(let r=1;ro&&(s=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=s.clampGrid().clone()}}class he extends se{constructor(t){super(t);this.iterationCount=t.flags&Vt?8:1,this.bestError=1/0,this.metric=new Kt(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=Gt(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new Kt(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,i]=t;const n=new Kt(.5,.5,.5,1/4),s=Kt.multiplyAdd(r,n,e),a=s.splatW,o=Kt.multiplyAdd(r,n,i);return{ax:s,aa:a,bx:o,bb:o.splatW,ab:Kt.multVector(r,n).splatW}}),((r,i,n)=>re(r,i,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,i,n]=t;const s=new Kt(1/3,1/3,1/3,1/9),a=new Kt(2/3,2/3,2/3,4/9),o=new Kt(2/9),h=Kt.multiplyAdd(i,s,Kt.multiplyAdd(r,a,e)),l=h.splatW,c=Kt.multiplyAdd(r,s,Kt.multiplyAdd(i,a,n));return{ax:h,aa:l,bx:c,bb:c.splatW,ab:Kt.multVector(o,Kt.add(r,i)).splatW}}),((r,i,n)=>ie(r,i,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let n={start:new Kt(0),end:new Kt(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(n.bestK=0);const s=(e,r)=>{const s=t(e),a=this.computeOptimalPoints(s);return a.errorHt.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>i[t]-i[e]!=0?i[t]-i[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let i=0;i2&&void 0!==arguments[2]?arguments[2]:2;const{count:i}=this.colors,n=(e,i,n)=>{const s={bestI:e,bestJ:2===r?n:i,iteration:t};return 3===r&&(s.bestK=n),s};let s=new Kt(0);for(let t=0;t15?15:e}function ce(t,e,r,i){let n=de(t,e,5),s=de(t,e,7);n.error<=s.error?function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){fe(n,i,s.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else fe(i,n,s,e,r)}(n,r,i):function(t,e,r){let{min:i,max:n,indices:s}=t;if(i>n){fe(n,i,s.map((t=>0===t?1:1===t?0:9-t)),e,r)}else fe(i,n,s,e,r)}(s,r,i)}function de(t,e,r){let{min:i,max:n}=function(t,e,r){let i=255,n=0;for(let s=0;s<16;s++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}i>n&&(i=n);n-iMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(i[6]=0,i[7]=255),i}function fe(t,e,r,i,n){i[n]=t,i[n+1]=e;let s=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[s]<<3*e,s++}for(let e=0;e<3;++e){let r=t>>8*e&255;i[a]=r,a++}}}function _e(t){const e=t>>11&31,r=t>>5&63,i=31&t;return[e<<3|e>>2,r<<2|r>>4,i<<3|i>>2,255]}function we(t,e,r){const i=t.map(((t,i)=>Math.floor(t*(1-r)+e[i]*r)));return i[3]=255,i}function pe(t,e,r,i){const n=function(t,e,r){const i=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,s=_e(i),a=_e(n);return[s,a,we(s,a,r&&i<=n?.5:1/3),r&&i<=n?[0,0,0,0]:we(s,a,2/3)]}(e,r,i),s=function(t,e){let r=e+4,i=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];i[4*e+0]=3&n,i[4*e+1]=n>>2&3,i[4*e+2]=n>>4&3,i[4*e+3]=n>>6&3}return i}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[s[e]][r]}function ge(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function be(t){let e=7&t,r=280&t,i=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=Vt&&(r=8),64!=i&&(i=32),e|r|i|128&t}function ye(t,e){let{x:r=0,y:i=0,width:n=0,height:s=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;ge((function(o,h){let l=r+o,c=i+h;if(l>4}}(t,e,r):0!=(4&i)&&function(t,e,r){let i=e[r+0],n=e[r+1],s=ue(i,n,i<=n?5:7),a=new Uint8Array(16),o=0,h=2;for(let t=0;t<2;t++){let t=0;for(let i=0;i<3;i++)t|=e[r+h]<<8*i,h++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=s[a[e]]}(t,e,r)}function ke(t,e,r,i,n){const s=0!=(1&(n=be(n)))?8:16;let a=0;!function(t,e,r){for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const s=new Uint8Array(64);let a=0,o=0;return ge((function(h,l){let c=e+h,d=r+l;if(c1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));let o=r.read(t),h=t.read(o);if(4==i)h=Ue(h,n,s,xe);else if(5==i)h=Ue(h,n,s,Ae);else if(6==i)h=Ue(h,n,s,Ee);else{if(2==i)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=i)throw new Error("Non-implemented Texture2D format type (".concat(i,") found."))}for(let t=0;t")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}},BaseReader:Et,BmFontReader:class extends Et{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new zt).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new zt).write(t,e.export.data,null)}isValueType(){return!1}},BooleanReader:Bt,CharReader:It,DictionaryReader:class extends Et{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let r={};const i=(new Rt).read(t);for(let n=0;n")}parseTypeList(){return[this.type,...this.key.parseTypeList(),...this.value.parseTypeList()]}},DoubleReader:class extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},EffectReader:class extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new Rt).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Rt).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Int32Reader:Ot,ListReader:Lt,NullableReader:Nt,RectangleReader:Ct,ReflectiveReader:class extends Et{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){return this.reader.read(t,e)}write(t,e,r){this.reader.write(t,e,this.reader.isValueType()?null:r)}isValueType(){return!1}get type(){return"".concat(this.reader.type)}parseTypeList(){return[...this.reader.parseTypeList()]}},SingleReader:Dt,SpriteFontReader:class extends Et{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.SpriteFontReader"===t}static parseTypeList(){return["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new Ot,i=new Dt,n=new Nt(new It);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:i.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const i=new Ot,n=new It,s=new Dt,a=new Nt(n),o=new Te,h=new Lt(new Ct),l=new Lt(n),c=new Lt(new Se);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),h.write(t,e.glyphs,r),h.write(t,e.cropping,r),l.write(t,e.characterMap,r),i.write(t,e.verticalLineSpacing,null),s.write(t,e.horizontalSpacing,null),c.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}}isValueType(){return!1}},StringReader:zt,TBinReader:class extends Et{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new Ot).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const i=e.export.data;(new Ot).write(t,i.byteLength,null),t.concat(i)}isValueType(){return!1}},Texture2DReader:Te,UInt32Reader:Rt,Vector2Reader:class extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new Dt;return{x:e.read(t),y:e.read(t)}}},Vector3Reader:Se,Vector4Reader:class extends Et{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new Dt;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}}};var Be;Be=ze,o.setReaders(Be),t.Readers=ze,t.XnbContent=M,t.XnbData=V,t.addReaders=function(t){return o.addReaders(t)},t.bufferToContents=function(t){return kt((new X).load(t))},t.bufferToXnb=vt,t.pack=function(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=xt(t);let n=[];for(let[t,e]of Object.entries(i))n.push(yt(e,r).then(At).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(n).then((t=>!0===r.debug?t:t.filter((t=>{let{status:e,value:r}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.unpackToContent=function(t){return mt(t).then(kt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:r=!1,contentOnly:i=!1,fileName:n=null}=e;"undefined"!=typeof window&&null===n&&(n=t.name);let[s]=lt(n);const a=t=>_t(t,{yaml:r,contentOnly:i,fileName:s});return mt(t).then(a)},t.unpackToXnbData=mt,t.xnbDataToContent=kt,t.xnbDataToFiles=_t,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/xnb.module.js b/dist/xnb.module.js index e062c28..3571be4 100644 --- a/dist/xnb.module.js +++ b/dist/xnb.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { let mappedPromises = promises.map(p => { return p.then(value => { @@ -67,6 +76,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -108,13 +133,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -129,12 +151,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1533,7 +1551,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4680,6 +4700,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4728,17 +4749,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4825,6 +4865,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } @@ -5348,8 +5393,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -5380,6 +5424,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -5454,6 +5502,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -5671,6 +5723,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -5809,6 +5865,10 @@ class ListReader extends BaseReader { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -5846,14 +5906,14 @@ class NullableReader extends BaseReader { return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -5870,6 +5930,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -5898,7 +5963,6 @@ class ReflectiveReader extends BaseReader { } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -5910,6 +5974,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -7810,8 +7878,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/package.json b/package.json index 8d8b946..18dc419 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,14 @@ ".": { "import": "./dist/xnb.module.js", "require": "./dist/xnb.cjs" + }, + "./core": { + "import": "./dist/core/xnb-core.module.js", + "require": "./dist/core/xnb-core.cjs" + }, + "./readers": { + "import": "./dist/readers/xnb-readers.module.js", + "require": "./dist/readers/xnb-readers.cjs" } }, "files": [ @@ -18,7 +26,7 @@ "build": "rollup -c builder/rollup.config.js", "build-core": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:1", "build-readers": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:2", - "build-stardew": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:3" + "build-stardew": "rollup -c builder/plugins-rollup.config.js --environment BUILD_MODULE:0" }, "keywords": [ "xnb", diff --git a/src/core/App/ReaderResolver.js b/src/core/App/ReaderResolver.js index e62e21f..91cefbd 100644 --- a/src/core/App/ReaderResolver.js +++ b/src/core/App/ReaderResolver.js @@ -1,6 +1,5 @@ import BufferReader from "./BufferReader.js"; import XnbError from "../Utils/XnbError.js"; -import Debug from "../Utils/Debug.js"; /** * Class used to read the XNB types using the readers @@ -27,10 +26,8 @@ class ReaderResolver { * @param {BufferReader} buffer The buffer to read from. */ read(buffer) { - Debug(`Buffer Position : 0x${buffer.bytePosition.toString(16)}`); // read the index of which reader to use let index = buffer.read7BitNumber() - 1; - Debug(`Reader Index : ${index+1}`); if (this.readers[index] == null) throw new XnbError(`Invalid reader index ${index}`); diff --git a/src/core/Utils/Debug.js b/src/core/Utils/Debug.js index 9f211df..4093f29 100644 --- a/src/core/Utils/Debug.js +++ b/src/core/Utils/Debug.js @@ -3,7 +3,7 @@ function Debug(str, ...args) if(Debug.__isVisible) console.log(str, ...args); } -Debug.__isVisible=true; +Debug.__isVisible=false; Debug.setVisible=function(state) { Debug.__isVisible=state; diff --git a/src/core/Utils/xnbNodeConverter.js b/src/core/Utils/xnbNodeConverter.js index 6451a72..5abc6cb 100644 --- a/src/core/Utils/xnbNodeConverter.js +++ b/src/core/Utils/xnbNodeConverter.js @@ -70,7 +70,6 @@ function convertJsonContentsToXnbNode(raw, readers) const {converted} = (function recursiveConvert(obj, path, index=0) { const reader = readers[index]; - console.log(`index : ${index}, reader: ${reader}, obj: ${JSON.stringify(obj)}`); //primitive if(isPrimitiveReaderType(reader)) @@ -271,8 +270,6 @@ function toXnbNodeData(json) delete rawContent.verticalLineSpacing; } - console.log(readersTypeList); - const { converted, extractedImages, extractedMaps } = convertJsonContentsToXnbNode(rawContent, readersTypeList); toYamlJson.content = converted; diff --git a/src/core/dist/core.cjs b/src/core/dist/core.cjs index 24ea9cb..84a46e8 100644 --- a/src/core/dist/core.cjs +++ b/src/core/dist/core.cjs @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -71,6 +80,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -112,13 +137,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -133,12 +155,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1537,7 +1555,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4684,6 +4704,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4732,17 +4753,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4829,6 +4869,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/src/core/dist/core.es5.js b/src/core/dist/core.es5.js index d35782b..67be59a 100644 --- a/src/core/dist/core.es5.js +++ b/src/core/dist/core.es5.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -3254,6 +3263,22 @@ return _createClass(XnbError); }(_wrapNativeSuper(Error)); + function removeExternBracket(str) { + var bracketStack = []; + var result = []; + + for (var i = 0; i < str.length; i++) { + var c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + var startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + var TypeReader = function () { function TypeReader() { _classCallCheck(this, TypeReader); @@ -3318,13 +3343,10 @@ }, { key: "parseSubtypes", value: function parseSubtypes(type) { - var subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - var pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - var matches = subtype.match(pattern).map(function (e) { - return e.slice(1, -1); - }); + var subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + var matches = removeExternBracket(subtype); return matches; } }, { @@ -3343,19 +3365,15 @@ }, { key: "getReaderTypeList", value: function getReaderTypeList(typeString) { - var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn.type, - subtypes = _TypeReader$getTypeIn.subtypes; - - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + var reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } }, { key: "getReader", value: function getReader(typeString) { - var _TypeReader$getTypeIn2 = TypeReader.getTypeInfo(typeString), - type = _TypeReader$getTypeIn2.type, - subtypes = _TypeReader$getTypeIn2.subtypes; + var _TypeReader$getTypeIn = TypeReader.getTypeInfo(typeString), + type = _TypeReader$getTypeIn.type, + subtypes = _TypeReader$getTypeIn.subtypes; subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return _construct(TypeReader.readers["".concat(type, "Reader")], subtypes); @@ -4865,8 +4883,8 @@ }, { key: "getIndex", value: function getIndex(reader) { - for (var i in this.readers) { - if (reader.toString() == this.readers[i].toString()) return i; + for (var i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; } } }]); @@ -8362,6 +8380,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -8408,17 +8427,41 @@ } if (__startsWithString(reader, 'Nullable')) { + var nullableData, trav; + + var _reader$split = reader.split(":"), + readerType = _reader$split[0], + _reader$split$ = _reader$split[1], + blockTraversed = _reader$split$ === void 0 ? 1 : _reader$split$; + + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (_typeof(obj) === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + var _recursiveConvert2 = recursiveConvert(obj, [].concat(path), index + 1), + _converted = _recursiveConvert2.converted, + _traversed = _recursiveConvert2.traversed; + + nullableData = _converted; + trav = _traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -8467,11 +8510,11 @@ var newIndex = void 0; if (__startsWithString(reader, "Dictionary")) newIndex = index + 2;else if (__startsWithString(reader, "Array") || __startsWithString(reader, "List")) newIndex = index + 1;else newIndex = traversed + 1; - var _recursiveConvert2 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), - _converted = _recursiveConvert2.converted, - nexter = _recursiveConvert2.traversed; + var _recursiveConvert3 = recursiveConvert(obj[key], [].concat(path, [key]), newIndex), + _converted2 = _recursiveConvert3.converted, + nexter = _recursiveConvert3.traversed; - data[key] = _converted; + data[key] = _converted2; if (isComplex) traversed = nexter;else if (first) { traversed = nexter; first = false; @@ -8510,6 +8553,11 @@ return data; } + if (__startsWithString(type, "Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/src/core/dist/core.es5.min.js b/src/core/dist/core.es5.min.js index 12be656..3dd11ae 100644 --- a/src/core/dist/core.es5.min.js +++ b/src/core/dist/core.es5.min.js @@ -1 +1,48 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},z=I,j=P,D=function(t){return z(j(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},zt=x,jt=0,Dt=Math.random(),Ct=zt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++jt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,ze=r.TypeError,je=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return je(t,e,n)}:je:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return je(t,e,n)}catch(t){}if("get"in n||"set"in n)throw ze("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,zn=$e.CONFIGURABLE,jn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||zn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||jn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==zr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",zr=Br.POLYFILL="P",jr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,zo=C,jo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=za.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!jo(t)||!zo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!zo(t)||t,r.fail=zo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},zo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,zs=Te,js=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;zs(t);try{if(!(r=js(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return zs(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error)),eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"setReaders",value:function(e){t.readers=Qs({},e)}},{key:"addReaders",value:function(e){t.readers=Qs(Qs({},t.readers),e)}},{key:"makeSimplied",value:function(e,n){var r=e.split(/`|,/)[0];if(n.isTypeOf(r)){if(n.hasSubType()){var i=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(n.type(),"<").concat(i.join(","),">")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(t.readers.hasOwnProperty("".concat(r,"Reader")))return t.readers["".concat(r,"Reader")].parseTypeList(i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(eh,"readers",{});var nh=[192,224,240],rh=128,ih=63,ah=[55296,56320],oh=1023;function sh(t){return t<128?[t]:t<2048?[nh[0]|t>>6,rh|t&ih]:t<65536?[nh[1]|t>>12,rh|t>>6&ih,rh|t&ih]:[nh[2]|t>>18,rh|t>>12&ih,rh|t>>6&ih,rh|t&ih]}function uh(t){return t<65535?[t]:[ah[0]|(t-=65536)>>10&oh,ah[1]|t&oh]}function hh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^nh[0])<<6)+(t[1]^rh):3===n?((t[0]^nh[1])<<12)+((t[1]^rh)<<6)+(t[2]^rh):((t[0]^nh[2])<<18)+((t[1]^rh)<<12)+((t[2]^rh)<<6)+(t[3]^rh)}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&oh)<<10)+(t[1]&oh)+65536}function ch(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),ph=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),vh=256,_h=0,yh=1,wh=2,gh=3,bh=656,mh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case wh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case yh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(bh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case gh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case wh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(h>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case yh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,bh,12);if(_>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case gh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();mh.position_base=[],mh.extra_bits=[];var kh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new mh(16),s=new ph(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Eh=65536,Oh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||xh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Oh){for(e[f++]=240+_,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Oh){for(e[f++]=240,l=h-Oh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Fh={};function Zh(t){var e=Fh[t];if(void 0!==e)return e.exports;var n=Fh[t]={exports:{}};return Ch[t].call(n.exports,n,n.exports,Zh),n.exports}Zh.d=function(t,e){for(var n in e)Zh.o(e,n)&&!Zh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Zh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Mh={};!function(){Zh.d(Mh,{P:function(){return Un},m:function(){return An}}),Zh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=z,G=j,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},jt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=zt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=jt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},ze=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=ze(a,r))===He&&s&&((n=De(a,s))===Ve?n=ze(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=ze(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=je(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Hh(t,n,-1)}var Gh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Yh(s,u):Kh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Yh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function Jh(t){var e=t.replace(/\t/g,"\t").split("\n");return Kh(new Gh(e))}function $h(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable"))return{converted:{type:u,data:{data:{type:e[s+1],data:i}}},traversed:s+1};if(Qh(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var h=s,f=!0,c=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),l=Object.keys(i),d=0;d0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function nf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=$h(i),e.content=tf(t.content),"SpriteFont"===eh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function rf(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=rf(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Xh(r.width,r.height,new Uint8Array(a))),uf(a,i)}if(e){var o=JSON.stringify(t,null,4);return uf(o,"JSON")}return null}function ff(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=hf(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(of(e.type)):"".concat(e.type,".").concat(of(e.type)):e}),4),l=c;return r&&(l=Wh(ef(t))),u.unshift(uf(l,r?"yaml":"JSON")),u}function cf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function lf(t){return df.apply(this,arguments)}function df(){return(df=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pf(t){return vf.apply(this,arguments)}function vf(){return(vf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _f(t,e){return yf.apply(this,arguments)}function yf(){return yf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,pf(n.png);case 3:return r=t.sent,i=Vh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,pf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,pf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,lf(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),yf.apply(this,arguments)}function wf(t){return gf.apply(this,arguments)}function gf(){return gf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,lf(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):nf(Jh(o)),null!==(u=cf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=rf(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=af(c),d=l[1],t.next=20,_f(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),gf.apply(this,arguments)}function bf(t){return mf.apply(this,arguments)}function mf(){return(mf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=af(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",kf(r));case 8:return t.abrupt("return",kf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kf(t){return(new Dh).load(t)}function xf(t){var e=hf(t.content,!0),n=e.data,r=e.extension;return new Nh(n,r)}function Ef(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Ef(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=af(s),h=u[0],f=function(t){return ff(t,{yaml:r,contentOnly:a,fileName:h})};return bf(t).then(f)},t.unpackToXnbData=bf,t.xnbDataToContent=xf,t.xnbDataToFiles=ff,Object.defineProperty(t,"__esModule",{value:!0})})); +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){return t&&t.Math==Math&&t},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||function(){return this}()||Function("return this")(),i={},a=function(t){try{return!!t()}catch(t){return!0}},o=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s=!a((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),u=s,h=Function.prototype.call,f=u?h.bind(h):function(){return h.apply(h,arguments)},c={},l={}.propertyIsEnumerable,d=Object.getOwnPropertyDescriptor,p=d&&!l.call({1:2},1);c.f=p?function(t){var e=d(this,t);return!!e&&e.enumerable}:l;var v,_,y=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},w=s,g=Function.prototype,b=g.bind,m=g.call,k=w&&b.bind(m,m),x=w?function(t){return t&&k(t)}:function(t){return t&&function(){return m.apply(t,arguments)}},E=x,O=E({}.toString),R=E("".slice),A=function(t){return R(O(t),8,-1)},U=x,S=a,T=A,L=r.Object,B=U("".split),I=S((function(){return!L("z").propertyIsEnumerable(0)}))?function(t){return"String"==T(t)?B(t,""):L(t)}:L,N=r.TypeError,P=function(t){if(null==t)throw N("Can't call method on "+t);return t},j=I,z=P,D=function(t){return j(z(t))},C=function(t){return"function"==typeof t},F=C,Z=function(t){return"object"==typeof t?null!==t:F(t)},M=r,V=C,X=function(t){return V(t)?t:void 0},H=function(t,e){return arguments.length<2?X(M[t]):M[t]&&M[t][e]},W=x({}.isPrototypeOf),G=H("navigator","userAgent")||"",K=r,Y=G,J=K.process,$=K.Deno,q=J&&J.versions||$&&$.version,Q=q&&q.v8;Q&&(_=(v=Q.split("."))[0]>0&&v[0]<4?1:+(v[0]+v[1])),!_&&Y&&(!(v=Y.match(/Edge\/(\d+)/))||v[1]>=74)&&(v=Y.match(/Chrome\/(\d+)/))&&(_=+v[1]);var tt=_,et=tt,nt=a,rt=!!Object.getOwnPropertySymbols&&!nt((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&et&&et<41})),it=rt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,at=H,ot=C,st=W,ut=it,ht=r.Object,ft=ut?function(t){return"symbol"==typeof t}:function(t){var e=at("Symbol");return ot(e)&&st(e.prototype,ht(t))},ct=r.String,lt=function(t){try{return ct(t)}catch(t){return"Object"}},dt=C,pt=lt,vt=r.TypeError,_t=function(t){if(dt(t))return t;throw vt(pt(t)+" is not a function")},yt=_t,wt=function(t,e){var n=t[e];return null==n?void 0:yt(n)},gt=f,bt=C,mt=Z,kt=r.TypeError,xt={exports:{}},Et=r,Ot=Object.defineProperty,Rt=function(t,e){try{Ot(Et,t,{value:e,configurable:!0,writable:!0})}catch(n){Et[t]=e}return e},At=Rt,Ut="__core-js_shared__",St=r[Ut]||At(Ut,{}),Tt=St;(xt.exports=function(t,e){return Tt[t]||(Tt[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var Lt=P,Bt=r.Object,It=function(t){return Bt(Lt(t))},Nt=x({}.hasOwnProperty),Pt=Object.hasOwn||function(t,e){return Nt(It(t),e)},jt=x,zt=0,Dt=Math.random(),Ct=jt(1..toString),Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Ct(++zt+Dt,36)},Zt=r,Mt=xt.exports,Vt=Pt,Xt=Ft,Ht=rt,Wt=it,Gt=Mt("wks"),Kt=Zt.Symbol,Yt=Kt&&Kt.for,Jt=Wt?Kt:Kt&&Kt.withoutSetter||Xt,$t=function(t){if(!Vt(Gt,t)||!Ht&&"string"!=typeof Gt[t]){var e="Symbol."+t;Ht&&Vt(Kt,t)?Gt[t]=Kt[t]:Gt[t]=Wt&&Yt?Yt(e):Jt(e)}return Gt[t]},qt=f,Qt=Z,te=ft,ee=wt,ne=function(t,e){var n,r;if("string"===e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;if(bt(n=t.valueOf)&&!mt(r=gt(n,t)))return r;if("string"!==e&&bt(n=t.toString)&&!mt(r=gt(n,t)))return r;throw kt("Can't convert object to primitive value")},re=$t,ie=r.TypeError,ae=re("toPrimitive"),oe=function(t,e){if(!Qt(t)||te(t))return t;var n,r=ee(t,ae);if(r){if(void 0===e&&(e="default"),n=qt(r,t,e),!Qt(n)||te(n))return n;throw ie("Can't convert object to primitive value")}return void 0===e&&(e="number"),ne(t,e)},se=ft,ue=function(t){var e=oe(t,"string");return se(e)?e:e+""},he=Z,fe=r.document,ce=he(fe)&&he(fe.createElement),le=function(t){return ce?fe.createElement(t):{}},de=le,pe=!o&&!a((function(){return 7!=Object.defineProperty(de("div"),"a",{get:function(){return 7}}).a})),ve=o,_e=f,ye=c,we=y,ge=D,be=ue,me=Pt,ke=pe,xe=Object.getOwnPropertyDescriptor;i.f=ve?xe:function(t,e){if(t=ge(t),e=be(e),ke)try{return xe(t,e)}catch(t){}if(me(t,e))return we(!_e(ye.f,t,e),t[e])};var Ee={},Oe=o&&a((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Re=r,Ae=Z,Ue=Re.String,Se=Re.TypeError,Te=function(t){if(Ae(t))return t;throw Se(Ue(t)+" is not an object")},Le=o,Be=pe,Ie=Oe,Ne=Te,Pe=ue,je=r.TypeError,ze=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ce="enumerable",Fe="configurable",Ze="writable";Ee.f=Le?Ie?function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),"function"==typeof t&&"prototype"===e&&"value"in n&&Ze in n&&!n.writable){var r=De(t,e);r&&r.writable&&(t[e]=n.value,n={configurable:Fe in n?n.configurable:r.configurable,enumerable:Ce in n?n.enumerable:r.enumerable,writable:!1})}return ze(t,e,n)}:ze:function(t,e,n){if(Ne(t),e=Pe(e),Ne(n),Be)try{return ze(t,e,n)}catch(t){}if("get"in n||"set"in n)throw je("Accessors not supported");return"value"in n&&(t[e]=n.value),t};var Me=Ee,Ve=y,Xe=o?function(t,e,n){return Me.f(t,e,Ve(1,n))}:function(t,e,n){return t[e]=n,t},He={exports:{}},We=o,Ge=Pt,Ke=Function.prototype,Ye=We&&Object.getOwnPropertyDescriptor,Je=Ge(Ke,"name"),$e={EXISTS:Je,PROPER:Je&&"something"===function(){}.name,CONFIGURABLE:Je&&(!We||We&&Ye(Ke,"name").configurable)},qe=C,Qe=St,tn=x(Function.toString);qe(Qe.inspectSource)||(Qe.inspectSource=function(t){return tn(t)});var en,nn,rn,an=Qe.inspectSource,on=C,sn=an,un=r.WeakMap,hn=on(un)&&/native code/.test(sn(un)),fn=xt.exports,cn=Ft,ln=fn("keys"),dn={},pn=hn,vn=r,_n=x,yn=Z,wn=Xe,gn=Pt,bn=St,mn=function(t){return ln[t]||(ln[t]=cn(t))},kn=dn,xn="Object already initialized",En=vn.TypeError,On=vn.WeakMap;if(pn||bn.state){var Rn=bn.state||(bn.state=new On),An=_n(Rn.get),Un=_n(Rn.has),Sn=_n(Rn.set);en=function(t,e){if(Un(Rn,t))throw new En(xn);return e.facade=t,Sn(Rn,t,e),e},nn=function(t){return An(Rn,t)||{}},rn=function(t){return Un(Rn,t)}}else{var Tn=mn("state");kn[Tn]=!0,en=function(t,e){if(gn(t,Tn))throw new En(xn);return e.facade=t,wn(t,Tn,e),e},nn=function(t){return gn(t,Tn)?t[Tn]:{}},rn=function(t){return gn(t,Tn)}}var Ln={set:en,get:nn,has:rn,enforce:function(t){return rn(t)?nn(t):en(t,{})},getterFor:function(t){return function(e){var n;if(!yn(e)||(n=nn(e)).type!==t)throw En("Incompatible receiver, "+t+" required");return n}}},Bn=a,In=C,Nn=Pt,Pn=Ee.f,jn=$e.CONFIGURABLE,zn=an,Dn=Ln.enforce,Cn=Ln.get,Fn=!Bn((function(){return 8!==Pn((function(){}),"length",{value:8}).length})),Zn=String(String).split("String"),Mn=He.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Nn(t,"name")||jn&&t.name!==e)&&Pn(t,"name",{value:e,configurable:!0}),Fn&&n&&Nn(n,"arity")&&t.length!==n.arity&&Pn(t,"length",{value:n.arity});var r=Dn(t);return Nn(r,"source")||(r.source=Zn.join("string"==typeof e?e:"")),t};Function.prototype.toString=Mn((function(){return In(this)&&Cn(this).source||zn(this)}),"toString");var Vn=r,Xn=C,Hn=Xe,Wn=He.exports,Gn=Rt,Kn=function(t,e,n,r){var i=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet,s=r&&void 0!==r.name?r.name:e;return Xn(n)&&Wn(n,s,r),t===Vn?(a?t[e]=n:Gn(e,n),t):(i?!o&&t[e]&&(a=!0):delete t[e],a?t[e]=n:Hn(t,e,n),t)},Yn={},Jn=Math.ceil,$n=Math.floor,qn=function(t){var e=+t;return e!=e||0===e?0:(e>0?$n:Jn)(e)},Qn=qn,tr=Math.max,er=Math.min,nr=qn,rr=Math.min,ir=function(t){return t>0?rr(nr(t),9007199254740991):0},ar=function(t){return ir(t.length)},or=D,sr=function(t,e){var n=Qn(t);return n<0?tr(n+e,0):er(n,e)},ur=ar,hr=function(t){return function(e,n,r){var i,a=or(e),o=ur(a),s=sr(r,o);if(t&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((t||s in a)&&a[s]===n)return t||s||0;return!t&&-1}},fr={includes:hr(!0),indexOf:hr(!1)},cr=Pt,lr=D,dr=fr.indexOf,pr=dn,vr=x([].push),_r=function(t,e){var n,r=lr(t),i=0,a=[];for(n in r)!cr(pr,n)&&cr(r,n)&&vr(a,n);for(;e.length>i;)cr(r,n=e[i++])&&(~dr(a,n)||vr(a,n));return a},yr=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype");Yn.f=Object.getOwnPropertyNames||function(t){return _r(t,yr)};var wr={};wr.f=Object.getOwnPropertySymbols;var gr=H,br=Yn,mr=wr,kr=Te,xr=x([].concat),Er=gr("Reflect","ownKeys")||function(t){var e=br.f(kr(t)),n=mr.f;return n?xr(e,n(t)):e},Or=Pt,Rr=Er,Ar=i,Ur=Ee,Sr=a,Tr=C,Lr=/#|\.prototype\./,Br=function(t,e){var n=Nr[Ir(t)];return n==jr||n!=Pr&&(Tr(e)?Sr(e):!!e)},Ir=Br.normalize=function(t){return String(t).replace(Lr,".").toLowerCase()},Nr=Br.data={},Pr=Br.NATIVE="N",jr=Br.POLYFILL="P",zr=Br,Dr=r,Cr=i.f,Fr=Xe,Zr=Kn,Mr=Rt,Vr=function(t,e,n){for(var r=Rr(e),i=Ur.f,a=Ar.f,o=0;o=51&&/native code/.test(t))return!1;var n=new uo((function(t){t(1)})),r=function(t){t((function(){}),(function(){}))};return(n.constructor={})[_o]=r,!(yo=n.then((function(){}))instanceof r)||!e&&po&&!wo})),bo={CONSTRUCTOR:go,REJECTION_EVENT:wo,SUBCLASSING:yo},mo={},ko=_t,xo=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=ko(e),this.reject=ko(n)};mo.f=function(t){return new xo(t)};var Eo,Oo,Ro,Ao=Hr,Uo=Wr,So=r,To=f,Lo=Kn,Bo=ti,Io=function(t,e,n){t&&!n&&(t=t.prototype),t&&!ni(t,ri)&&ei(t,ri,{configurable:!0,value:e})},No=function(t){var e=ii(t),n=ai.f;oi&&e&&!e[si]&&n(e,si,{configurable:!0,get:function(){return this}})},Po=_t,jo=C,zo=Z,Do=function(t,e){if(ui(e,t))return t;throw hi("Incorrect invocation")},Co=function(t,e){var n,r=Fi(t).constructor;return void 0===r||null==(n=Fi(r)[Mi])?e:Zi(n)},Fo=ja.set,Zo=to,Mo=function(t,e){var n=eo.console;n&&n.error&&(1==arguments.length?n.error(t):n.error(t,e))},Vo=no,Xo=io,Ho=Ln,Wo=ao,Go=mo,Ko="Promise",Yo=bo.CONSTRUCTOR,Jo=bo.REJECTION_EVENT,$o=bo.SUBCLASSING,qo=Ho.getterFor(Ko),Qo=Ho.set,ts=Wo&&Wo.prototype,es=Wo,ns=ts,rs=So.TypeError,is=So.document,as=So.process,os=Go.f,ss=os,us=!!(is&&is.createEvent&&So.dispatchEvent),hs="unhandledrejection",fs=function(t){var e;return!(!zo(t)||!jo(e=t.then))&&e},cs=function(t,e){var n,r,i,a=e.value,o=1==e.state,s=o?t.ok:t.fail,u=t.resolve,h=t.reject,f=t.domain;try{s?(o||(2===e.rejection&&_s(e),e.rejection=1),!0===s?n=a:(f&&f.enter(),n=s(a),f&&(f.exit(),i=!0)),n===t.promise?h(rs("Promise-chain cycle")):(r=fs(n))?To(r,n,u,h):u(n)):h(a)}catch(t){f&&!i&&f.exit(),h(t)}},ls=function(t,e){t.notified||(t.notified=!0,Zo((function(){for(var n,r=t.reactions;n=r.get();)cs(n,t);t.notified=!1,e&&!t.rejection&&ps(t)})))},ds=function(t,e,n){var r,i;us?((r=is.createEvent("Event")).promise=e,r.reason=n,r.initEvent(t,!1,!0),So.dispatchEvent(r)):r={promise:e,reason:n},!Jo&&(i=So["on"+t])?i(r):t===hs&&Mo("Unhandled promise rejection",n)},ps=function(t){To(Fo,So,(function(){var e,n=t.facade,r=t.value;if(vs(t)&&(e=Vo((function(){Uo?as.emit("unhandledRejection",r,n):ds(hs,n,r)})),t.rejection=Uo||vs(t)?2:1,e.error))throw e.value}))},vs=function(t){return 1!==t.rejection&&!t.parent},_s=function(t){To(Fo,So,(function(){var e=t.facade;Uo?as.emit("rejectionHandled",e):ds("rejectionhandled",e,t.value)}))},ys=function(t,e,n){return function(r){t(e,r,n)}},ws=function(t,e,n){t.done||(t.done=!0,n&&(t=n),t.value=e,t.state=2,ls(t,!0))},gs=function(t,e,n){if(!t.done){t.done=!0,n&&(t=n);try{if(t.facade===e)throw rs("Promise can't be resolved itself");var r=fs(e);r?Zo((function(){var n={done:!1};try{To(r,e,ys(gs,n,t),ys(ws,n,t))}catch(e){ws(n,e,t)}})):(t.value=e,t.state=1,ls(t,!1))}catch(e){ws({done:!1},e,t)}}};if(Yo&&(ns=(es=function(t){Do(this,ns),Po(t),To(Eo,this);var e=qo(this);try{t(ys(gs,e),ys(ws,e))}catch(t){ws(e,t)}}).prototype,(Eo=function(t){Qo(this,{type:Ko,done:!1,notified:!1,parent:!1,reactions:new Xo,rejection:!1,state:0,value:void 0})}).prototype=Lo(ns,"then",(function(t,e){var n=qo(this),r=os(Co(this,es));return n.parent=!0,r.ok=!jo(t)||t,r.fail=jo(e)&&e,r.domain=Uo?as.domain:void 0,0==n.state?n.reactions.add(r):Zo((function(){cs(r,n)})),r.promise})),Oo=function(){var t=new Eo,e=qo(t);this.promise=t,this.resolve=ys(gs,e),this.reject=ys(ws,e)},Go.f=os=function(t){return t===es||undefined===t?new Oo(t):ss(t)},jo(Wo)&&ts!==Object.prototype)){Ro=ts.then,$o||Lo(ts,"then",(function(t,e){var n=this;return new es((function(t,e){To(Ro,n,t,e)})).then(t,e)}),{unsafe:!0});try{delete ts.constructor}catch(t){}Bo&&Bo(ts,ns)}Ao({global:!0,wrap:!0,forced:Yo},{Promise:es}),Io(es,Ko,!1),No(Ko);var bs={},ms=bs,ks=$t("iterator"),xs=Array.prototype,Es=wi,Os=wt,Rs=bs,As=$t("iterator"),Us=function(t){if(null!=t)return Os(t,As)||Os(t,"@@iterator")||Rs[Es(t)]},Ss=f,Ts=_t,Ls=Te,Bs=lt,Is=Us,Ns=r.TypeError,Ps=f,js=Te,zs=wt,Ds=$i,Cs=f,Fs=Te,Zs=lt,Ms=function(t){return void 0!==t&&(ms.Array===t||xs[ks]===t)},Vs=ar,Xs=W,Hs=function(t,e){var n=arguments.length<2?Is(t):e;if(Ts(n))return Ls(Ss(n,t));throw Ns(Bs(t)+" is not iterable")},Ws=Us,Gs=function(t,e,n){var r,i;js(t);try{if(!(r=zs(t,"return"))){if("throw"===e)throw n;return n}r=Ps(r,t)}catch(t){i=!0,r=t}if("throw"===e)throw n;if(i)throw r;return js(r),n},Ks=r.TypeError,Ys=function(t,e){this.stopped=t,this.result=e},Js=Ys.prototype,$s=function(t,e,n){var r,i,a,o,s,u,h,f=n&&n.that,c=!(!n||!n.AS_ENTRIES),l=!(!n||!n.IS_ITERATOR),d=!(!n||!n.INTERRUPTED),p=Ds(e,f),v=function(t){return r&&Gs(r,"normal",t),new Ys(!0,t)},_=function(t){return c?(Fs(t),d?p(t[0],t[1],v):p(t[0],t[1])):d?p(t,v):p(t)};if(l)r=t;else{if(!(i=Ws(t)))throw Ks(Zs(t)+" is not iterable");if(Ms(i)){for(a=0,o=Vs(t);o>a;a++)if((s=_(t[a]))&&Xs(Js,s))return s;return new Ys(!1)}r=Hs(t,i)}for(u=r.next;!(h=Cs(u,r)).done;){try{s=_(h.value)}catch(t){Gs(r,"throw",t)}if("object"==typeof s&&s&&Xs(Js,s))return s}return new Ys(!1)};function qs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Qs(t){for(var e=1;e=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),h=r.call(o,"finallyLoc");if(u&&h){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}({exports:{}});var th=function(t){su(n,t);var e=vu(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return ru(this,n),(t=e.call(this,r)).name="XnbError",t.message=r,Error.captureStackTrace(du(t),n),t}return au(n)}(lu(Error));function eh(t){for(var e=[],n=[],r=0;r")}return n.type()}return null}},{key:"simplifyType",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(e){var n=e.split(/`|,/)[0];if(function(t,e){if("function"==typeof t.endsWith)return t.endsWith(e);if("string"!=typeof t||"string"!=typeof e)throw new Error("Invalid Data!");return new RegExp(e+"$").test(t)}(n,"[]"))return"Array<".concat(simplifyType(n.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===n){var r=t.parseSubtypes(e).map(t.simplifyType.bind(t));return"".concat(r)}for(var i=0,a=Object.values(t.readers);i/);return n=n?n[1].split(",").map((function(t){return t.trim()})):[],{type:e,subtypes:n}}},{key:"getReaderTypeList",value:function(e){return t.getReader(e).parseTypeList()}},{key:"getReader",value:function(e){var n=t.getTypeInfo(e),r=n.type,i=n.subtypes;if(i=i.map(t.getReader.bind(t)),t.readers.hasOwnProperty("".concat(r,"Reader")))return cu(t.readers["".concat(r,"Reader")],i);throw new th('Invalid reader type "'.concat(e,'" passed, unable to resolve!'))}},{key:"getReaderFromRaw",value:function(e){var n=t.simplifyType(e);return t.getReader(n)}}]),t}();ou(nh,"readers",{});var rh=[192,224,240],ih=128,ah=63,oh=[55296,56320],sh=1023;function uh(t){return t<128?[t]:t<2048?[rh[0]|t>>6,ih|t&ah]:t<65536?[rh[1]|t>>12,ih|t>>6&ah,ih|t&ah]:[rh[2]|t>>18,ih|t>>12&ah,ih|t>>6&ah,ih|t&ah]}function hh(t){return t<65535?[t]:[oh[0]|(t-=65536)>>10&sh,oh[1]|t&sh]}function fh(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");var n=t.length;return 1===n?t[0]:2===n?((t[0]^rh[0])<<6)+(t[1]^ih):3===n?((t[0]^rh[1])<<12)+((t[1]^ih)<<6)+(t[2]^ih):((t[0]^rh[2])<<18)+((t[1]^ih)<<12)+((t[2]^ih)<<6)+(t[3]^ih)}function ch(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&sh)<<10)+(t[1]&sh)+65536}function lh(t){return function(t){for(var e=[],n=0;n1&&void 0!==arguments[1])||arguments[1];ru(this,t),this._endianus=n,this._buffer=e.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}return au(t,[{key:"seek",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset,n=this._offset;if(this._offset=Math.max(e+parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-n}},{key:"bytePosition",get:function(){return parseInt(this._offset)},set:function(t){this._offset=t}},{key:"bitPosition",get:function(){return parseInt(this._bitOffset)},set:function(t){t<0&&(t=16-t),this._bitOffset=t%16;var e=(t-Math.abs(t)%16)/16*2;this.seek(e)}},{key:"size",get:function(){return this.buffer.byteLength}},{key:"buffer",get:function(){return this._buffer}},{key:"copyFrom",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength,i=new Uint8Array(t),a=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1,e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:0,e=[],n=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(var r=0;r0;){var r=this._dataView.getUint16(this._offset,!0),i=Math.min(Math.max(e,0),16-this.bitPosition),a=16-this.bitPosition-i,o=(r&Math.pow(2,i)-1<>a;e-=i,this.bitPosition+=i,n|=o<0&&void 0!==arguments[0])||arguments[0],e=this.readByte(),n=this.readByte();return t||this.seek(-2),e<<8|n}},{key:"align",value:function(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}]),t}(),vh=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;ru(this,t),this._buffer=new ArrayBuffer(e),this._dataView=new DataView(this._buffer),this.bytePosition=0}return au(t,[{key:"buffer",get:function(){return this._buffer}},{key:"reconnectDataView",value:function(){this._dataView=new DataView(this._buffer)}},{key:"trim",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}},{key:"alloc",value:function(t){if(this._buffer.byteLength<=this.bytePosition+t){for(var e=new ArrayBuffer(this._buffer.byteLength+t),n=new DataView(e),r=0;r>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}]),t}(),_h=256,yh=0,wh=1,gh=2,bh=3,mh=656,kh=function(){function t(e){if(ru(this,t),this.window_size=1<21)throw new th("Window size out of range!");if(!t.extra_bits.length)for(var n=0,r=0;n<=50;n+=2)t.extra_bits[n]=t.extra_bits[n+1]=r,0!=n&&r<17&&r++;if(!t.position_base.length)for(var i=0,a=0;i<=50;i++)t.position_base[i]=a,a+=1<0;){if(0==this.block_remaining){this.block_type=e.readLZXBits(3);var a=e.readLZXBits(16),o=e.readLZXBits(8);switch(this.block_remaining=a<<8|o,this.block_type){case gh:for(var s=0;s<8;s++)this.aligned_len[s]=e.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case wh:this.readLengths(e,this.maintree_len,0,256),this.readLengths(e,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(mh,12,this.maintree_len),this.readLengths(e,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case bh:e.align(),this.R0=e.readInt32(),this.R1=e.readInt32(),this.R2=e.readInt32();break;default:throw new th("Invalid Blocktype Found: ".concat(this.block_type))}}for(var u=this.block_remaining;(u=this.block_remaining)>0&&i>0;){if(u>i&&(u=i),i-=u,this.block_remaining-=u,this.window_posn&=this.window_size-1,this.window_posn+u>this.window_size)throw new th("Cannot run outside of window frame.");switch(this.block_type){case gh:for(;u>0;){var h=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,mh,12);if(h<_h)this.win[this.window_posn++]=h,u--;else{var f=7&(h-=_h);7==f&&(f+=this.readHuffSymbol(e,this.length_table,this.length_len,250,12)),f+=2;var c=h>>3;if(c>2){var l=t.extra_bits[c];if(c=t.position_base[c]-2,l>3)l-=3,c+=e.readLZXBits(l)<<3,c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7);else 3==l?c+=this.readHuffSymbol(e,this.aligned_table,this.aligned_len,8,7):l>0?c+=e.readLZXBits(l):c=1;this.R2=this.R1,this.R1=this.R0,this.R0=c}else 0===c?c=this.R0:1==c?(c=this.R1,this.R1=this.R0,this.R0=c):(c=this.R2,this.R2=this.R0,this.R0=c);var d=this.window_posn,p=void 0;if(u-=f,this.window_posn>=c)p=d-c;else{p=d+(this.window_size-c);var v=c-this.window_posn;if(v0;)this.win[d++]=this.win[p++];p=0}}for(this.window_posn+=f;f-- >0;)this.win[d++]=this.win[p++]}}break;case wh:for(;u>0;){var _=this.readHuffSymbol(e,this.maintree_table,this.maintree_len,mh,12);if(_<_h)this.win[this.window_posn++]=_,u--;else{var y=7&(_-=_h);7==y&&(y+=this.readHuffSymbol(e,this.length_table,this.length_len,250,12)),y+=2;var w=_>>3;if(w>2){if(3!=w){var g=t.extra_bits[w],b=e.readLZXBits(g);w=t.position_base[w]-2+b}else w=1;this.R2=this.R1,this.R1=this.R0,this.R0=w}else 0===w?w=this.R0:1==w?(w=this.R1,this.R1=this.R0,this.R0=w):(w=this.R2,this.R2=this.R0,this.R0=w);var m=this.window_posn,k=void 0;if(u-=y,this.window_posn>=w)k=m-w;else{k=m+(this.window_size-w);var x=w-this.window_posn;if(x0;)this.win[m++]=this.win[k++];k=0}}for(this.window_posn+=y;y-- >0;)this.win[m++]=this.win[k++]}}break;case bh:if(e.bytePosition+u>r)throw new th("Overrun!"+r+" "+e.bytePosition+" "+u);for(var E=0;E>1,s=1;s<=e;s++){for(var u=0;ua)throw new th("Overrun table!");for(var f=o;f-- >0;)r[h++]=u}o>>=1}if(i==a)return r;for(var c=i;c>1>1;i<<=16,a<<=16,o=32768;for(var d=e+1;d<=16;d++){for(var p=0;p>16,_=0;_>15-_&1&&v++;if(r[v]=p,(i+=o)>a)throw new th("Overrun table during decoding.")}o>>=1}if(i==a)return r;throw new th("Decode table did not reach table mask.")}},{key:"readHuffSymbol",value:function(t,e,n,r,i){var a=t.peekLZXBits(32)>>>0,o=e[t.peekLZXBits(i)];if(o>=r){var s=1<<32-i;do{if(o<<=1,o|=0!=(a&(s>>=1))?1:0,0==s)return 0}while((o=e[o])>=r)}return t.bitPosition+=n[o],o}},{key:"RRR",set:function(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){var e=this.R1;this.R1=this.R0,this.R0=e}else if(this.R2==t){var n=this.R2;this.R2=this.R0,this.R0=n}}}]),t}();kh.position_base=[],kh.extra_bits=[];var xh=function(){function t(){ru(this,t)}return au(t,null,[{key:"decompress",value:function(t,e,n){for(var r,i,a=0,o=new kh(16),s=new vh(n);a65536||i>65536)throw new th("Invalid size read in compression content.");s.write(o.decompress(t,i,r)),a+=r}return console.log("File has been successfully decompressed!"),s.trim(),s.buffer}}]),t}(),Eh=function(){function t(){ru(this,t)}return au(t,null,[{key:"hashU32",value:function(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}},{key:"readU64",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24,n|=t[e++]<<32,n|=t[e++]<<40,n|=t[e++]<<48,n|=t[e++]<<56}},{key:"readU32",value:function(t,e){var n=0;return n|=t[e++]<<0,n|=t[e++]<<8,n|=t[e++]<<16,n|=t[e++]<<24}},{key:"writeU32",value:function(t,e,n){t[e++]=n>>0&255,t[e++]=n>>8&255,t[e++]=n>>16&255,t[e++]=n>>24&255}},{key:"imul",value:function(t,e){var n=65535&t,r=65535&e;return n*r+((t>>>16)*r+n*(e>>>16)<<16)|0}}]),t}(),Oh=65536,Rh=15;!function(t){try{new Uint8Array(t)}catch(r){for(var e=new Array(t),n=0;n=13)for(var d=67;n+4>>0;if(a=i[v=(v>>16^v)>>>0&65535]-1,i[v]=n+1,a<0||n-a>>>16>0||Eh.readU32(t,a)!==p)n+=d++>>6;else{for(d=67,h=n-o,u=n-a,a+=4,s=n+=4;n=Rh){for(e[f++]=240+_,l=h-Rh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=(h<<4)+_;for(var y=0;y>8,s>=15){for(l=s-15;l>=255;l-=255)e[f++]=255;e[f++]=l}o=n}}if(0===o)return 0;if((h=c-o)>=Rh){for(e[f++]=240,l=h-Rh;l>=255;l-=255)e[f++]=255;e[f++]=l}else e[f++]=h<<4;for(n=o;n2&&void 0!==arguments[2]?arguments[2]:0,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*s,h=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,f=void 0!==e.copyWithin&&void 0!==e.fill;for(i=s+u;s>4;if(l>0){if(15===l)for(;l+=t[s],255===t[s++];);for(a=s+l;s=i)break;if(n=15&c,r=t[s++]|t[s++]<<8,15===n)for(;n+=t[s],255===t[s++];);if(n+=4,f&&1===r)e.fill(0|e[h-1],h,h+n),h+=n;else if(f&&r>n&&n>31)e.copyWithin(h,h-r,h-r+n),h+=n;else for(a=(o=h-r)+n;o0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");for(var n=0,r=t.length,i=0,a=Math.max(32,r+(r>>1)+7),o=new Uint8Array(a>>3<<3);n=55296&&s<=56319){if(n=55296&&s<=56319)continue}if(i+4>o.length){a+=8,a=(a*=1+n/t.length*2)>>3<<3;var h=new Uint8Array(a);h.set(o),o=h}if(0!=(4294967168&s)){if(0==(4294965248&s))o[i++]=s>>6&31|192;else if(0==(4294901760&s))o[i++]=s>>12&15|224,o[i++]=s>>6&63|128;else{if(0!=(4292870144&s))continue;o[i++]=s>>18&7|240,o[i++]=s>>12&63|128,o[i++]=s>>6&63|128}o[i++]=63&s|128}else o[i++]=s}return o.slice(0,i)},Object.defineProperty(n.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(n.prototype,"fatal",{value:!1}),Object.defineProperty(n.prototype,"ignoreBOM",{value:!1}),n.prototype.decode=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");for(var n=new Uint8Array(t),r=0,i=n.length,a=[];r65535&&(f-=65536,a.push(f>>>10&1023|55296),f=56320|1023&f),a.push(f)}}return String.fromCharCode.apply(null,a)},t.TextEncoder=e,t.TextDecoder=n}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},Zh={};function Mh(t){var e=Zh[t];if(void 0!==e)return e.exports;var n=Zh[t]={exports:{}};return Fh[t].call(n.exports,n,n.exports,Mh),n.exports}Mh.d=function(t,e){for(var n in e)Mh.o(e,n)&&!Mh.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},Mh.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var Vh={};!function(){Mh.d(Vh,{P:function(){return Un},m:function(){return An}}),Mh(396);var t=new TextDecoder("utf-8"),e=new TextEncoder,n=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n);var r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);var i=e.offset?e.offset>>>0:0,a=t.byteLength-i,o=i;(ArrayBuffer.isView(t)||t instanceof n)&&(t.byteLength!==t.buffer.byteLength&&(o=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?a:0,this.buffer=t,this.length=a,this.byteLength=a,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,a),this._mark=0,this._marks=[]}return au(n,[{key:"available",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}},{key:"isLittleEndian",value:function(){return this.littleEndian}},{key:"setLittleEndian",value:function(){return this.littleEndian=!0,this}},{key:"isBigEndian",value:function(){return!this.littleEndian}},{key:"setBigEndian",value:function(){return this.littleEndian=!1,this}},{key:"skip",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}},{key:"seek",value:function(t){return this.offset=t,this}},{key:"mark",value:function(){return this._mark=this.offset,this}},{key:"reset",value:function(){return this.offset=this._mark,this}},{key:"pushMark",value:function(){return this._marks.push(this.offset),this}},{key:"popMark",value:function(){var t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}},{key:"rewind",value:function(){return this.offset=0,this}},{key:"ensureAvailable",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){var e=2*(this.offset+t),n=new Uint8Array(e);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}},{key:"readBoolean",value:function(){return 0!==this.readUint8()}},{key:"readInt8",value:function(){return this._data.getInt8(this.offset++)}},{key:"readUint8",value:function(){return this._data.getUint8(this.offset++)}},{key:"readByte",value:function(){return this.readUint8()}},{key:"readBytes",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=new Uint8Array(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:1,e="",n=0;n0&&void 0!==arguments[0]?arguments[0]:1;return e=this.readBytes(n),t.decode(e)}},{key:"writeBoolean",value:function(t){return this.writeUint8(t?255:0),this}},{key:"writeInt8",value:function(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeUint8",value:function(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}},{key:"writeByte",value:function(t){return this.writeUint8(t)}},{key:"writeBytes",value:function(t){this.ensureAvailable(t.length);for(var e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}]),n}();function r(t){for(var e=t.length;--e>=0;)t[e]=0}var i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),s=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),u=new Array(576);r(u);var h=new Array(60);r(h);var f=new Array(512);r(f);var c=new Array(256);r(c);var l=new Array(29);r(l);var d,p,v,_=new Array(30);function y(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length}function w(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);var g=function(t){return t<256?f[t]:f[256+(t>>>7)]},b=function(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},m=function(t,e,n){t.bi_valid>16-n?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=n-16):(t.bi_buf|=e<>>=1,n<<=1}while(--e>0);return n>>>1},E=function(t,e,n){var r,i,a=new Array(16),o=0;for(r=1;r<=15;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=e;i++){var s=t[2*i+1];0!==s&&(t[2*i]=x(a[s]++,s))}},O=function(t){var e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=function(t){t.bi_valid>8?b(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},A=function(t,e,n,r){var i=2*e,a=2*n;return t[i]>1;n>=1;n--)U(t,a,n);i=u;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],U(t,a,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,a[2*i]=a[2*n]+a[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,a[2*n+1]=a[2*r+1]=i,t.heap[1]=i++,U(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],function(t,e){var n,r,i,a,o,s,u=e.dyn_tree,h=e.max_code,f=e.stat_desc.static_tree,c=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,d=e.stat_desc.extra_base,p=e.stat_desc.max_length,v=0;for(a=0;a<=15;a++)t.bl_count[a]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;n<573;n++)(a=u[2*u[2*(r=t.heap[n])+1]+1]+1)>p&&(a=p,v++),u[2*r+1]=a,r>h||(t.bl_count[a]++,o=0,r>=d&&(o=l[r-d]),s=u[2*r],t.opt_len+=s*(a+o),c&&(t.static_len+=s*(f[2*r+1]+o)));if(0!==v){do{for(a=p-1;0===t.bl_count[a];)a--;t.bl_count[a]--,t.bl_count[a+1]+=2,t.bl_count[p]--,v-=2}while(v>0);for(a=p;0!==a;a--)for(r=t.bl_count[a];0!==r;)(i=t.heap[--n])>h||(u[2*i+1]!==a&&(t.opt_len+=(a-u[2*i+1])*u[2*i],u[2*i+1]=a),r--)}}(t,e),E(a,h,t.bl_count)},L=function(t,e,n){var r,i,a=-1,o=e[1],s=0,u=7,h=4;for(0===o&&(u=138,h=3),e[2*(n+1)+1]=65535,r=0;r<=n;r++)i=o,o=e[2*(r+1)+1],++s>=7;r<30;r++)for(_[r]=s<<7,t=0;t<1<0?(2===t.strm.data_type&&(t.strm.data_type=function(t){var e,n=4093624447;for(e=0;e<=31;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0}(t)),T(t,t.l_desc),T(t,t.d_desc),o=function(t){var e;for(L(t,t.dyn_ltree,t.l_desc.max_code),L(t,t.dyn_dtree,t.d_desc.max_code),T(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*s[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}(t),i=t.opt_len+3+7>>>3,(a=t.static_len+3+7>>>3)<=i&&(i=a)):i=a=n+5,n+4<=i&&-1!==e?N(t,e,n,r):4===t.strategy||a===i?(m(t,2+(r?1:0),3),S(t,u,h)):(m(t,4+(r?1:0),3),function(t,e,n,r){var i;for(m(t,e-257,5),m(t,n-1,5),m(t,r-4,4),i=0;i>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(c[n]+256+1)]++,t.dyn_dtree[2*g(e)]++),t.last_lit===t.lit_bufsize-1},C=function(t){m(t,2,3),k(t,256,u),function(t){16===t.bi_valid?(b(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}(t)},F=function(t,e,n,r){for(var i=65535&t|0,a=t>>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(i=i+e[r++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},Z=new Uint32Array(function(){for(var t,e=[],n=0;n<256;n++){t=n;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}()),M=function(t,e,n,r){var i=Z,a=r+n;t^=-1;for(var o=r;o>>8^i[255&(t^e[o])];return-1^t},V={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},X={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},H=P,W=j,G=z,K=D,Y=C,J=X.Z_NO_FLUSH,$=X.Z_PARTIAL_FLUSH,q=X.Z_FULL_FLUSH,Q=X.Z_FINISH,tt=X.Z_BLOCK,et=X.Z_OK,nt=X.Z_STREAM_END,rt=X.Z_STREAM_ERROR,it=X.Z_DATA_ERROR,at=X.Z_BUF_ERROR,ot=X.Z_DEFAULT_COMPRESSION,st=X.Z_FILTERED,ut=X.Z_HUFFMAN_ONLY,ht=X.Z_RLE,ft=X.Z_FIXED,ct=X.Z_UNKNOWN,lt=X.Z_DEFLATED,dt=258,pt=262,vt=103,_t=113,yt=666,wt=function(t,e){return t.msg=V[e],e},gt=function(t){return(t<<1)-(t>4?9:0)},bt=function(t){for(var e=t.length;--e>=0;)t[e]=0},mt=function(t,e,n){return(e<t.avail_out&&(n=t.avail_out),0!==n&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+n),t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))},xt=function(t,e){G(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=function(t,e){t.pending_buf[t.pending++]=e},Ot=function(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Rt=function(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),n),1===t.state.wrap?t.adler=F(t.adler,e,i,n):2===t.state.wrap&&(t.adler=M(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)},At=function(t,e){var n,r,i=t.max_chain_length,a=t.strstart,o=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-pt?t.strstart-(t.w_size-pt):0,h=t.window,f=t.w_mask,c=t.prev,l=t.strstart+dt,d=h[a+o-1],p=h[a+o];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do{if(h[(n=e)+o]===p&&h[n+o-1]===d&&h[n]===h[a]&&h[++n]===h[a+1]){a+=2,n++;do{}while(h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&h[++a]===h[++n]&&ao){if(t.match_start=e,o=r,r>=s)break;d=h[a+o-1],p=h[a+o]}}}while((e=c[e&f])>u&&0!=--i);return o<=t.lookahead?o:t.lookahead},Ut=function(t){var e,n,r,i,a,o=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=o+(o-pt)){t.window.set(t.window.subarray(o,o+o),0),t.match_start-=o,t.strstart-=o,t.block_start-=o,e=n=t.hash_size;do{r=t.head[--e],t.head[e]=r>=o?r-o:0}while(--n);e=n=o;do{r=t.prev[--e],t.prev[e]=r>=o?r-o:0}while(--n);i+=o}if(0===t.strm.avail_in)break;if(n=Rt(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=mt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=mt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==n&&t.strstart-n<=t.w_size-pt&&(t.match_length=At(t,n)),t.match_length>=3)if(r=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=mt(t,t.ins_h,t.window[t.strstart+1]);else r=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Tt=function(t,e){for(var n,r,i;;){if(t.lookahead=3&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==n&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-3,r=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=i&&(t.ins_h=mt(t,t.ins_h,t.window[t.strstart+3-1]),n=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,r&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if((r=K(t,0,t.window[t.strstart-1]))&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(r=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i}var Bt=[new Lt(0,0,0,0,(function(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ut(t),0===t.lookahead&&e===J)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-pt&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,St),new Lt(4,5,16,8,St),new Lt(4,6,32,32,St),new Lt(4,4,16,16,Tt),new Lt(8,16,32,32,Tt),new Lt(8,16,128,128,Tt),new Lt(8,32,128,256,Tt),new Lt(32,128,258,1024,Tt),new Lt(32,258,258,4096,Tt)];function It(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=lt,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),bt(this.dyn_ltree),bt(this.dyn_dtree),bt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),bt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Nt=function(t){var e,n=function(t){if(!t||!t.state)return wt(t,rt);t.total_in=t.total_out=0,t.data_type=ct;var e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:_t,t.adler=2===e.wrap?0:1,e.last_flush=J,H(e),et}(t);return n===et&&((e=t.state).window_size=2*e.w_size,bt(e.head),e.max_lazy_match=Bt[e.level].max_lazy,e.good_match=Bt[e.level].good_length,e.nice_match=Bt[e.level].nice_length,e.max_chain_length=Bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0),n},Pt=function(t,e,n,r,i,a){if(!t)return rt;var o=1;if(e===ot&&(e=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>9||n!==lt||r<8||r>15||e<0||e>9||a<0||a>ft)return wt(t,rt);8===r&&(r=9);var s=new It;return t.state=s,s.strm=t,s.wrap=o,s.gzhead=null,s.w_bits=r,s.w_size=1<tt||e<0)return t?wt(t,rt):rt;var i=t.state;if(!t.output||!t.input&&0!==t.avail_in||i.status===yt&&e!==Q)return wt(t,0===t.avail_out?at:rt);i.strm=t;var a=i.last_flush;if(i.last_flush=e,42===i.status)if(2===i.wrap)t.adler=0,Et(i,31),Et(i,139),Et(i,8),i.gzhead?(Et(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Et(i,255&i.gzhead.time),Et(i,i.gzhead.time>>8&255),Et(i,i.gzhead.time>>16&255),Et(i,i.gzhead.time>>24&255),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Et(i,255&i.gzhead.extra.length),Et(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=M(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,0),Et(i,9===i.level?2:i.strategy>=ut||i.level<2?4:0),Et(i,3),i.status=_t);else{var o=lt+(i.w_bits-8<<4)<<8;o|=(i.strategy>=ut||i.level<2?0:i.level<6?1:6===i.level?2:3)<<6,0!==i.strstart&&(o|=32),o+=31-o%31,i.status=_t,Ot(i,o),0!==i.strstart&&(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),t.adler=1}if(69===i.status)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending!==i.pending_buf_size));)Et(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(73===i.status)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.gzindex=0,i.status=91)}else i.status=91;if(91===i.status)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),kt(t),n=i.pending,i.pending===i.pending_buf_size)){r=1;break}r=i.gzindexn&&(t.adler=M(t.adler,i.pending_buf,i.pending-n,n)),0===r&&(i.status=vt)}else i.status=vt;if(i.status===vt&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&kt(t),i.pending+2<=i.pending_buf_size&&(Et(i,255&t.adler),Et(i,t.adler>>8&255),t.adler=0,i.status=_t)):i.status=_t),0!==i.pending){if(kt(t),0===t.avail_out)return i.last_flush=-1,et}else if(0===t.avail_in&>(e)<=gt(a)&&e!==Q)return wt(t,at);if(i.status===yt&&0!==t.avail_in)return wt(t,at);if(0!==t.avail_in||0!==i.lookahead||e!==J&&i.status!==yt){var s=i.strategy===ut?function(t,e){for(var n;;){if(0===t.lookahead&&(Ut(t),0===t.lookahead)){if(e===J)return 1;break}if(t.match_length=0,n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):i.strategy===ht?function(t,e){for(var n,r,i,a,o=t.window;;){if(t.lookahead<=dt){if(Ut(t),t.lookahead<=dt&&e===J)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&((r=o[i=t.strstart-1])===o[++i]&&r===o[++i]&&r===o[++i])){a=t.strstart+dt;do{}while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&it.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(n=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===Q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2}(i,e):Bt[i.level].func(i,e);if(3!==s&&4!==s||(i.status=yt),1===s||3===s)return 0===t.avail_out&&(i.last_flush=-1),et;if(2===s&&(e===$?Y(i):e!==tt&&(W(i,0,0,!1),e===q&&(bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),kt(t),0===t.avail_out))return i.last_flush=-1,et}return e!==Q?et:i.wrap<=0?nt:(2===i.wrap?(Et(i,255&t.adler),Et(i,t.adler>>8&255),Et(i,t.adler>>16&255),Et(i,t.adler>>24&255),Et(i,255&t.total_in),Et(i,t.total_in>>8&255),Et(i,t.total_in>>16&255),Et(i,t.total_in>>24&255)):(Ot(i,t.adler>>>16),Ot(i,65535&t.adler)),kt(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?et:nt)},zt=function(t){if(!t||!t.state)return rt;var e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==vt&&e!==_t&&e!==yt?wt(t,rt):(t.state=null,e===_t?wt(t,it):et)},Dt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},Ct=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=tu(n))throw new TypeError(n+"must be non-object");for(var r in n)Dt(n,r)&&(t[r]=n[r])}}return t},Ft=function(t){for(var e=0,n=0,r=t.length;n=252?6:Vt>=248?5:Vt>=240?4:Vt>=224?3:Vt>=192?2:1;Mt[254]=Mt[254]=1;var Xt=function(t){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);var e,n,r,i,a,o=t.length,s=0;for(i=0;i>>6,e[a++]=128|63&n):n<65536?(e[a++]=224|n>>>12,e[a++]=128|n>>>6&63,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|n>>>12&63,e[a++]=128|n>>>6&63,e[a++]=128|63&n);return e},Ht=function(t,e){var n,r,i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));var a=new Array(2*i);for(r=0,n=0;n4)a[r++]=65533,n+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&n1?a[r++]=65533:o<65536?a[r++]=o:(o-=65536,a[r++]=55296|o>>10&1023,a[r++]=56320|1023&o)}}}return function(t,e){if(e<65534&&t.subarray&&Zt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));for(var n="",r=0;rt.length&&(e=t.length);for(var n=e-1;n>=0&&128==(192&t[n]);)n--;return n<0||0===n?e:n+Mt[t[n]]>e?n:e},Gt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},Kt=Object.prototype.toString,Yt=X.Z_NO_FLUSH,Jt=X.Z_SYNC_FLUSH,$t=X.Z_FULL_FLUSH,qt=X.Z_FINISH,Qt=X.Z_OK,te=X.Z_STREAM_END,ee=X.Z_DEFAULT_COMPRESSION,ne=X.Z_DEFAULT_STRATEGY,re=X.Z_DEFLATED;function ie(t){this.options=Ct({level:ee,method:re,chunkSize:16384,windowBits:15,memLevel:8,strategy:ne},t||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==Qt)throw new Error(V[n]);if(e.header&&function(t,e){t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))}(this.strm,e.header),e.dictionary){var r;if(r="string"==typeof e.dictionary?Xt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,n=function(t,e){var n=e.length;if(!t||!t.state)return rt;var r=t.state,i=r.wrap;if(2===i||1===i&&42!==r.status||r.lookahead)return rt;if(1===i&&(t.adler=F(t.adler,e,n,0)),r.wrap=0,n>=r.w_size){0===i&&(bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);var a=new Uint8Array(r.w_size);a.set(e.subarray(n-r.w_size,n),0),e=a,n=r.w_size}var o=t.avail_in,s=t.next_in,u=t.input;for(t.avail_in=n,t.next_in=0,t.input=e,Ut(r);r.lookahead>=3;){var h=r.strstart,f=r.lookahead-2;do{r.ins_h=mt(r,r.ins_h,r.window[h+3-1]),r.prev[h&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=h,h++}while(--f);r.strstart=h,r.lookahead=2,Ut(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=s,t.input=u,t.avail_in=o,r.wrap=i,et}(this.strm,r),n!==Qt)throw new Error(V[n]);this._dict_set=!0}}function ae(t,e){var n=new ie(e);if(n.push(t,!0),n.err)throw n.msg||V[n.err];return n.result}ie.prototype.push=function(t,e){var n,r,i=this.strm,a=this.options.chunkSize;if(this.ended)return!1;for(r=e===~~e?e:!0===e?qt:Yt,"string"==typeof t?i.input=Xt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(a),i.next_out=0,i.avail_out=a),(r===Jt||r===$t)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if((n=jt(i,r))===te)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),n=zt(this.strm),this.onEnd(n),this.ended=!0,n===Qt;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ie.prototype.onData=function(t){this.chunks.push(t)},ie.prototype.onEnd=function(t){t===Qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var oe=ae,se=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=t.state;n=t.next_in,E=t.input,r=n+(t.avail_in-5),i=t.next_out,O=t.output,a=i-(e-t.avail_out),o=i+(t.avail_out-257),s=R.dmax,u=R.wsize,h=R.whave,f=R.wnext,c=R.window,l=R.hold,d=R.bits,p=R.lencode,v=R.distcode,_=(1<>>=g=w>>>24,d-=g,0===(g=w>>>16&255))O[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(l&(1<>>=g,d-=g),d<15&&(l+=E[n++]<>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=v[(65535&w)+(l&(1<s){t.msg="invalid distance too far back",R.mode=30;break t}if(l>>>=g,d-=g,m>(g=i-a)){if((g=m-g)>h&&R.sane){t.msg="invalid distance too far back",R.mode=30;break t}if(k=0,x=c,0===f){if(k+=u-g,g2;)O[i++]=x[k++],O[i++]=x[k++],O[i++]=x[k++],b-=3;b&&(O[i++]=x[k++],b>1&&(O[i++]=x[k++]))}else{k=i-m;do{O[i++]=O[k++],O[i++]=O[k++],O[i++]=O[k++],b-=3}while(b>2);b&&(O[i++]=O[k++],b>1&&(O[i++]=O[k++]))}break}}break}}while(n>3,l&=(1<<(d-=b<<3))-1,t.next_in=n,t.next_out=i,t.avail_in=n=1&&0===T[m];m--);if(k>m&&(k=m),0===m)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b0&&(0===t||1!==m))return-1;for(L[1]=0,w=1;w<15;w++)L[w+1]=L[w]+T[w];for(g=0;g852||2===t&&R>592)return 1;for(;;){p=w-E,o[g]d?(v=B[I+o[g]],_=U[S+o[g]]):(v=96,_=0),u=1<>E)+(h-=u)]=p<<24|v<<16|_|0}while(0!==h);for(u=1<>=1;if(0!==u?(A&=u-1,A+=u):A=0,g++,0==--T[w]){if(w===m)break;w=e[n+o[g]]}if(w>k&&(A&c)!==f){for(0===E&&(E=k),l+=b,O=1<<(x=w-E);x+E852||2===t&&R>592)return 1;i[f=A&c]=k<<24|x<<16|l-a|0}}return 0!==A&&(i[l+A]=w-E<<24|64<<16|0),s.bits=k,0},de=X.Z_FINISH,pe=X.Z_BLOCK,ve=X.Z_TREES,_e=X.Z_OK,ye=X.Z_STREAM_END,we=X.Z_NEED_DICT,ge=X.Z_STREAM_ERROR,be=X.Z_DATA_ERROR,me=X.Z_MEM_ERROR,ke=X.Z_BUF_ERROR,xe=X.Z_DEFLATED,Ee=12,Oe=30,Re=function(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)};function Ae(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var Ue,Se,Te=function(t){if(!t||!t.state)return ge;var e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,function(t){if(!t||!t.state)return ge;var e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,_e}(t)},Le=!0,Be=function(t){if(Le){Ue=new Int32Array(512),Se=new Int32Array(32);for(var e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(le(1,t.lens,0,288,Ue,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;le(2,t.lens,0,32,Se,0,t.work,{bits:5}),Le=!1}t.lencode=Ue,t.lenbits=9,t.distcode=Se,t.distbits=5},Ie=function(t,e,n,r){var i,a=t.state;return null===a.window&&(a.wsize=1<=a.wsize?(a.window.set(e.subarray(n-a.wsize,n),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>r&&(i=r),a.window.set(e.subarray(n-r,n-r+i),a.wnext),(r-=i)?(a.window.set(e.subarray(n-r,n),0),a.wnext=r,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,Te(t))}(t,e);return r!==_e&&(t.state=null),r},je=function(t,e){var n,r,i,a,o,s,u,h,f,c,l,d,p,v,_,y,w,g,b,m,k,x,E,O,R=0,A=new Uint8Array(4),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;(n=t.state).mode===Ee&&(n.mode=13),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,c=s,l=u,x=_e;t:for(;;)switch(n.mode){case 1:if(0===n.wrap){n.mode=13;break}for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0),h=0,f=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",n.mode=Oe;break}if((15&h)!==xe){t.msg="unknown compression method",n.mode=Oe;break}if(f-=4,k=8+(15&(h>>>=4)),0===n.wbits)n.wbits=k;else if(k>n.wbits){t.msg="invalid window size",n.mode=Oe;break}n.dmax=1<>8&1),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=3;case 3:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>8&255,A[2]=h>>>16&255,A[3]=h>>>24&255,n.check=M(n.check,A,4,0)),h=0,f=0,n.mode=4;case 4:for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>8),512&n.flags&&(A[0]=255&h,A[1]=h>>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0,n.mode=5;case 5:if(1024&n.flags){for(;f<16;){if(0===s)break t;s--,h+=r[a++]<>>8&255,n.check=M(n.check,A,2,0)),h=0,f=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((d=n.length)>s&&(d=s),d&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(a,a+d),k)),512&n.flags&&(n.check=M(n.check,r,d,a)),s-=d,a+=d,n.length-=d),n.length))break t;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===s)break t;d=0;do{k=r[a+d++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&d>9&1,n.head.done=!0),t.adler=n.check=0,n.mode=Ee;break;case 10:for(;f<32;){if(0===s)break t;s--,h+=r[a++]<>>=7&f,f-=7&f,n.mode=27;break}for(;f<3;){if(0===s)break t;s--,h+=r[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(Be(n),n.mode=20,e===ve){h>>>=2,f-=2;break t}break;case 2:n.mode=17;break;case 3:t.msg="invalid block type",n.mode=Oe}h>>>=2,f-=2;break;case 14:for(h>>>=7&f,f-=7&f;f<32;){if(0===s)break t;s--,h+=r[a++]<>>16^65535)){t.msg="invalid stored block lengths",n.mode=Oe;break}if(n.length=65535&h,h=0,f=0,n.mode=15,e===ve)break t;case 15:n.mode=16;case 16:if(d=n.length){if(d>s&&(d=s),d>u&&(d=u),0===d)break t;i.set(r.subarray(a,a+d),o),s-=d,a+=d,u-=d,o+=d,n.length-=d;break}n.mode=Ee;break;case 17:for(;f<14;){if(0===s)break t;s--,h+=r[a++]<>>=5,f-=5,n.ndist=1+(31&h),h>>>=5,f-=5,n.ncode=4+(15&h),h>>>=4,f-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=Oe;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,f-=3}for(;n.have<19;)n.lens[U[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=le(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid code lengths set",n.mode=Oe;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=_,f-=_,n.lens[n.have++]=w;else{if(16===w){for(O=_+2;f>>=_,f-=_,0===n.have){t.msg="invalid bit length repeat",n.mode=Oe;break}k=n.lens[n.have-1],d=3+(3&h),h>>>=2,f-=2}else if(17===w){for(O=_+3;f>>=_)),h>>>=3,f-=3}else{for(O=_+7;f>>=_)),h>>>=7,f-=7}if(n.have+d>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=Oe;break}for(;d--;)n.lens[n.have++]=k}}if(n.mode===Oe)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=Oe;break}if(n.lenbits=9,E={bits:n.lenbits},x=le(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){t.msg="invalid literal/lengths set",n.mode=Oe;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=le(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){t.msg="invalid distances set",n.mode=Oe;break}if(n.mode=20,e===ve)break t;case 20:n.mode=21;case 21:if(s>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=a,t.avail_in=s,n.hold=h,n.bits=f,se(t,l),o=t.next_out,i=t.output,u=t.avail_out,a=t.next_in,r=t.input,s=t.avail_in,h=n.hold,f=n.bits,n.mode===Ee&&(n.back=-1);break}for(n.back=0;y=(R=n.lencode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,n.length=w,0===y){n.mode=26;break}if(32&y){n.back=-1,n.mode=Ee;break}if(64&y){t.msg="invalid literal/length code",n.mode=Oe;break}n.extra=15&y,n.mode=22;case 22:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;y=(R=n.distcode[h&(1<>>16&255,w=65535&R,!((_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>g)])>>>16&255,w=65535&R,!(g+(_=R>>>24)<=f);){if(0===s)break t;s--,h+=r[a++]<>>=g,f-=g,n.back+=g}if(h>>>=_,f-=_,n.back+=_,64&y){t.msg="invalid distance code",n.mode=Oe;break}n.offset=w,n.extra=15&y,n.mode=24;case 24:if(n.extra){for(O=n.extra;f>>=n.extra,f-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=Oe;break}n.mode=25;case 25:if(0===u)break t;if(d=l-u,n.offset>d){if((d=n.offset-d)>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=Oe;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),v=n.window}else v=i,p=o-n.offset,d=n.length;d>u&&(d=u),u-=d,n.length-=d;do{i[o++]=v[p++]}while(--d);0===n.length&&(n.mode=21);break;case 26:if(0===u)break t;i[o++]=n.length,u--,n.mode=21;break;case 27:if(n.wrap){for(;f<32;){if(0===s)break t;s--,h|=r[a++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Gt,this.strm.avail_out=0;var n=Pe(this.strm,e.windowBits);if(n!==Ve)throw new Error(V[n]);if(this.header=new Ce,function(t,e){if(!t||!t.state)return ge;var n=t.state;0==(2&n.wrap)||(n.head=e,e.done=!1)}(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Xt(e.dictionary):"[object ArrayBuffer]"===Fe.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(n=De(this.strm,e.dictionary))!==Ve))throw new Error(V[n])}function Je(t,e){var n=new Ye(e);if(n.push(t),n.err)throw n.msg||V[n.err];return n.result}Ye.prototype.push=function(t,e){var n,r,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(r=e===~~e?e:!0===e?Me:Ze,"[object ArrayBuffer]"===Fe.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(n=je(a,r))===He&&s&&((n=De(a,s))===Ve?n=je(a,r):n===Ge&&(n=He));a.avail_in>0&&n===Xe&&a.state.wrap>0&&0!==t[a.next_in];)Ne(a),n=je(a,r);switch(n){case We:case Ge:case He:case Ke:return this.onEnd(n),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||n===Xe))if("string"===this.options.to){var u=Wt(a.output,a.next_out),h=a.next_out-u,f=Ht(a.output,u);a.next_out=h,a.avail_out=o-h,h&&a.output.set(a.output.subarray(u,u+h),0),this.onData(f)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(n!==Ve||0!==i){if(n===Xe)return n=ze(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Ve&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};for(var $e=oe,qe=Ye,Qe=Je,tn=[137,80,78,71,13,10,26,10],en=[],nn=0;nn<256;nn++){for(var rn=nn,an=0;an<8;an++)1&rn?rn=3988292384^rn>>>1:rn>>>=1;en[nn]=rn}var on,sn,un,hn;function fn(t,e){return(4294967295^function(t,e,n){for(var r=4294967295,i=0;i>>8;return r}(0,t,e))>>>0}!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(on||(on={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(sn||(sn={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(un||(un={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(hn||(hn={}));var cn=new Uint8Array(0),ln=new Uint16Array([255]),dn=255===new Uint8Array(ln.buffer)[0],pn=function(t){su(n,t);var e=vu(n);function n(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ru(this,n),r=e.call(this,t);var a=i.checkCrc,o=void 0!==a&&a;return r._checkCrc=o,r._inflator=new qe,r._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},r._end=!1,r._hasPalette=!1,r._palette=[],r._compressionMethod=sn.UNKNOWN,r._filterMethod=un.UNKNOWN,r._interlaceMethod=hn.UNKNOWN,r._colorType=-1,r.setBigEndian(),r}return au(n,[{key:"decode",value:function(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}},{key:"decodeSignature",value:function(){for(var t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));for(var e=0;e>8&255;this._png.data=c}else this._png.data=s}}]),n}(n);function vn(t,e,n){for(var r=0;r>1)&255}else{for(;a>1)&255;for(;a>1)&255}}function gn(t,e,n,r,i){var a=0;if(0===n.length){for(;a1&&void 0!==arguments[1]?arguments[1]:{};return ru(this,r),(n=e.call(this))._colorType=on.UNKNOWN,n._zlibOptions=Qs(Qs({},kn),i.zlib),n._png=n._checkData(t),n.setBigEndian(),n}return au(r,[{key:"encode",value:function(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}},{key:"encodeSignature",value:function(){this.writeBytes(tn)}},{key:"encodeIHDR",value:function(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(sn.DEFLATE),this.writeByte(un.ADAPTIVE),this.writeByte(hn.NO_INTERLACE),this.writeCrc(17)}},{key:"encodeIEND",value:function(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}},{key:"encodeIDAT",value:function(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}},{key:"encodeData",value:function(){for(var t=this._png,e=t.width,r=t.height,i=t.channels,a=t.depth,o=t.data,s=i*e,u=(new n).setBigEndian(),h=0,f=0;f0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function On(t,e,n,r){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:4,n="";return"number"==typeof e?n=_u(" ",Math.min(10,e)):"string"==typeof e&&(n=e.slice(0,10)),Wh(t,n,-1)}var Kh=function(){function t(e,n,r){ru(this,t),this.startingLine=r||0,this.lineIndex=-1;for(var i=[],a=0;a=n;)e.push(this.next());return new t(e,this.indentString,this.getLineNumber()-e.length)}},{key:"next",value:function(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}},{key:"peek",value:function(){return this.getLine(this.lineIndex+1)}},{key:"finished",value:function(){return this.lineIndex==this.lines.length-1}},{key:"getLine",value:function(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}},{key:"findIndentString",value:function(){for(var t=0,e=this.lines;t]+)/),o=void 0,s=void 0,u=void 0;wu(r,'"')&&(i=r.match(/^"(.*?)":(?: |$)/)),a&&(u=a[1],r=r.replace(a[0],"")),i?(n||(n={}),o=i[1],s=r.replace(i[0],"").trim()):wu(r,"-")&&(n||(n=[]),s=r.slice(1).trim()),s=s?Jh(s,u):Yh(t.nextGroup(),u),Array.isArray(n)?n.push(s):n[o]=s}return e&&(n={type:e,data:n}),n}function Jh(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function $h(t){var e=t.replace(/\t/g,"\t").split("\n");return Yh(new Kh(e))}function qh(t){var e;if(Array.isArray(t)){e=[];for(var n=0;n","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],s.verticalSpacing=s.verticalLineSpacing,delete s.verticalLineSpacing);var f=function(t,e){var n=[],r=[],i=function t(i,a){var o,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,u=e[s];if(Qh(u))return{converted:{type:u,data:i},traversed:s};if(null===u)return{converted:i,traversed:s};if(wu(u,"Nullable")){var h,f,c=u.split(":"),l=c[0],d=c[1],p=void 0===d?1:d;if(p=+p,null===i)h=null,f=s+p;else if("object"!==tu(i)||i&&0!==Object.keys(i).length){var v=t(i,[].concat(a),s+1);h=v.converted,f=v.traversed}else h={type:e[s+1],data:qh(i)},f=s+p;return{converted:{type:l,data:{data:h}},traversed:f}}if(tf(u))return"Texture2D"===u?(n.push({path:a.join(".")}),{converted:{type:u,data:{format:i.format}},traversed:s}):("TBin"===u&&r.push({path:a.join(".")}),{converted:{type:u,data:{}},traversed:s});o=Array.isArray(i)?[]:{};for(var _=s,y=!0,w=!wu(u,"Dictionary")&&!wu(u,"Array")&&!wu(u,"List"),g=Object.keys(i),b=0;b0&&(e.extractedImages=l),d.length>0&&(e.extractedMaps=d),e}function rf(t){var e={},n=t.xnbData,r=n.compressed,i=n.readerData,a=n.hiDef,o=n.target;return e.header={target:o,formatVersion:5,compressed:r?"a"===o||"i"===o?64:128:0,hidef:a},e.readers=qh(i),e.content=ef(t.content),"SpriteFont"===nh.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function af(t,e){if(t&&"object"==tu(t)){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]&&arguments[1],n=af(t,"export");if(n){var r=n.value,i=r.type,a=r.data;return"Texture2D"===i&&(a=Hh(r.width,r.height,new Uint8Array(a))),hf(a,i)}if(e){var o=JSON.stringify(t,null,4);return hf(o,"JSON")}return null}function cf(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;if(r&&a&&(r=!1),!t.hasOwnProperty("content"))throw new th("Invalid object!");var u=[],h=t.content,f=ff(h,a);if(null!==f&&u.push(f),a)return u;var c=JSON.stringify(t,(function(t,e){return"export"===t?"string"==typeof s&&""!==s?"".concat(s,".").concat(sf(e.type)):"".concat(e.type,".").concat(sf(e.type)):e}),4),l=c;return r&&(l=Gh(nf(t))),u.unshift(hf(l,r?"yaml":"JSON")),u}function lf(t){var e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}function df(t){return pf.apply(this,arguments)}function pf(){return(pf=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.text());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.toString());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function vf(t){return _f.apply(this,arguments)}function _f(){return(_f=nu(regeneratorRuntime.mark((function t(e){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!("function"==typeof Blob&&e instanceof Blob)){t.next=4;break}return t.abrupt("return",e.arrayBuffer());case 4:if(!("function"==typeof Buffer&&e instanceof Buffer)){t.next=6;break}return t.abrupt("return",e.buffer);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function yf(t,e){return wf.apply(this,arguments)}function wf(){return wf=nu(regeneratorRuntime.mark((function t(e,n){var r,i,a,o,s;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("png"!==e){t.next=6;break}return t.next=3,vf(n.png);case 3:return r=t.sent,i=Xh(new Uint8Array(r)),t.abrupt("return",{type:"Texture2D",data:i.data,width:i.width,height:i.height});case 6:if("cso"!==e){t.next=11;break}return t.next=9,vf(n.cso);case 9:return a=t.sent,t.abrupt("return",{type:"Effect",data:a});case 11:if("tbin"!==e){t.next=16;break}return t.next=14,vf(n.tbin);case 14:return o=t.sent,t.abrupt("return",{type:"TBin",data:o});case 16:if("xml"!==e){t.next=21;break}return t.next=19,df(n.xml);case 19:return s=t.sent,t.abrupt("return",{type:"BmFont",data:s});case 21:case"end":return t.stop()}}),t)}))),wf.apply(this,arguments)}function gf(t){return bf.apply(this,arguments)}function bf(){return bf=nu(regeneratorRuntime.mark((function t(e){var n,r,i,a,o,s,u,h,f,c,l,d,p=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:{},r=n.compression,i=void 0===r?"default":r,a=e.json||e.yaml){t.next=5;break}throw new th("There is no JSON or YAML file to pack!");case 5:return t.next=7,df(a);case 7:if(o=t.sent,s=null,s=e.json?JSON.parse(o):rf($h(o)),null!==(u=lf(i))&&(s.header.compressed=u),s.hasOwnProperty("content")){t.next=14;break}throw new th("".concat(a.name,' does not have "content".'));case 14:if(!(h=af(s.content,"export"))){t.next=21;break}return f=h.parent,c=h.value,l=of(c),d=l[1],t.next=20,yf(d,e);case 20:f.export=t.sent;case 21:return t.abrupt("return",s);case 22:case"end":return t.stop()}}),t)}))),bf.apply(this,arguments)}function mf(t){return kf.apply(this,arguments)}function kf(){return(kf=nu(regeneratorRuntime.mark((function t(e){var n,r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("undefined"==typeof window){t.next=8;break}if(n=of(e.name),"xnb"===n[1]){t.next=4;break}return t.abrupt("return",new Error("Invalid XNB File!"));case 4:return t.next=6,e.arrayBuffer();case 6:return r=t.sent,t.abrupt("return",xf(r));case 8:return t.abrupt("return",xf(e.buffer));case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function xf(t){return(new Ch).load(t)}function Ef(t){var e=ff(t.content,!0),n=e.data,r=e.extension;return new Ph(n,r)}function Of(t){for(var e={},n=0;n1&&void 0!==arguments[1]?arguments[1]:{},n=Of(t),r=[],i=Object.keys(n),a=0;a1&&void 0!==arguments[1]?arguments[1]:{},n=e.yaml,r=void 0!==n&&n,i=e.contentOnly,a=void 0!==i&&i,o=e.fileName,s=void 0===o?null:o;"undefined"!=typeof window&&null===s&&(s=t.name);var u=of(s),h=u[0],f=function(t){return cf(t,{yaml:r,contentOnly:a,fileName:h})};return mf(t).then(f)},t.unpackToXnbData=mf,t.xnbDataToContent=Ef,t.xnbDataToFiles=cf,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/core/dist/core.js b/src/core/dist/core.js index 4c94e26..0c87258 100644 --- a/src/core/dist/core.js +++ b/src/core/dist/core.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -73,6 +82,22 @@ } + function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; + } + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -114,13 +139,10 @@ } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -135,12 +157,8 @@ } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1539,7 +1557,9 @@ } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4686,6 +4706,7 @@ case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4734,17 +4755,36 @@ } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4831,6 +4871,11 @@ return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/src/core/dist/core.min.js b/src/core/dist/core.min.js index 9cc559a..f6d9bca 100644 --- a/src/core/dist/core.min.js +++ b/src/core/dist/core.min.js @@ -1,41 +1,48 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}class a{static setReaders(t){a.readers=n({},t)}static addReaders(t){a.readers=n(n({},a.readers),t)}static makeSimplied(t,e){let i=t.split(/`|,/)[0];if(e.isTypeOf(i)){if(e.hasSubType()){let i=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e.type(),"<").concat(i.join(","),">")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=a.parseSubtypes(t).map(a.simplifyType.bind(a));return"".concat(e)}for(let e of Object.values(a.readers)){let i=a.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.split("`")[1];e.slice(0,1),e=e.slice(2,-1);let i=e.match(/\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g).map((t=>t.slice(1,-1)));return i}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(a.readers.hasOwnProperty("".concat(e,"Reader")))return a.readers["".concat(e,"Reader")].parseTypeList(i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReader(t){let{type:e,subtypes:i}=a.getTypeInfo(t);if(i=i.map(a.getReader.bind(a)),a.readers.hasOwnProperty("".concat(e,"Reader")))return new(a.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=a.simplifyType(t);return a.getReader(e)}}r(a,"readers",{});const o=[192,224,240],h=128,l=63,d=[55296,56320],f=1023;function c(t){return t<128?[t]:t<2048?[o[0]|t>>6,h|t&l]:t<65536?[o[1]|t>>12,h|t>>6&l,h|t&l]:[o[2]|t>>18,h|t>>12&l,h|t>>6&l,h|t&l]}function u(t){return t<65535?[t]:[d[0]|(t-=65536)>>10&f,d[1]|t&f]}function _(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^o[0])<<6)+(t[1]^h):3===i?((t[0]^o[1])<<12)+((t[1]^h)<<6)+(t[2]^h):((t[0]^o[2])<<18)+((t[1]^h)<<12)+((t[2]^h)<<6)+(t[3]^h)}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&f)<<10)+(t[1]&f)+65536}function p(t){return function(t){const e=[];for(let i of t)e.push(...c(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class m{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}} -/** @license - * - * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons - * which is derived from libmspack by Stuart Cole. - * - * (C) 2003-2004 Stuart Caie. - * (C) 2011 Ali Scissons. - * (C) 2017 James Stine. - * - * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. - * - * - * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - * LzxDecoder is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * MICROSOFT PUBLIC LICENSE - * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). - * - * Redistribution and use in source and binary forms, with or without modification, - * is permitted provided that redistributions of the source code retain the above - * copyright notices and this file header. - * - * Additional copyright notices should be appended to the list above. - * - * For details, see . - * - * - * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been - * acknowleded properly as it should have been back in 2017. - * - * Resources: - * - * cabextract/libmspack - http://http://www.cabextract.org.uk/ - * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs - * - */const y=256,v=0,k=1,x=2,E=3,A=656;class U{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!U.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)U.extra_bits[t]=U.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!U.position_base.length)for(let t=0,e=0;t<=50;t++)U.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case x:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case k:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(A,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case E:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){let e=U.extra_bits[s];if(s=U.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case k:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,A,12);if(n>3;if(s>2){if(3!=s){let e=U.extra_bits[s],i=t.readLZXBits(e);s=U.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case E:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}U.position_base=[],U.extra_bits=[];class R{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}} -/** @license - * Original Code by: https://github.com/Benzinga/lz4js/ - */const B=65536,O=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||R.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=O){for(e[d++]=240+p,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=O){for(e[d++]=240,c=l-O;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class z{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=S(e);t.write7BitNumber(i),t.writeString(e)}}class D{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e in this.readers)if(t.toString()==this.readers[e].toString())return e}}class P{constructor(t,e,i){let{target:n,formatVersion:r,hidef:s,compressed:a}=t;this.header={target:n,formatVersion:r,hidef:s,compressed:a},this.readers=e,this.content=i}get target(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.target){case"w":return"Microsoft Windows";case"m":return"Windows Phone 7";case"x":return"Xbox 360";case"a":return"Android";case"i":return"iOS";default:return"Unknown"}}get formatVersion(){var t;switch(null===(t=this.header)||void 0===t?void 0:t.formatVersion){case 3:return"XNA Game Studio 3.0";case 4:return"XNA Game Studio 3.1";case 5:return"XNA Game Studio 4.0";default:return"Unknown"}}get hidef(){var t;return!(null===(t=this.header)||void 0===t||!t.hidef)}get compressed(){var t;return!(null===(t=this.header)||void 0===t||!t.compressed)}get contentType(){let{export:t}=this.content;return void 0!==t?t.type:"JSON"}get rawContent(){let{export:t}=this.content;return void 0!==t?t.data:JSON.stringify(this.content,((t,e)=>"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class C{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const Z=64,F=128,V=14;class M{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new g(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==F){const e=this.fileSize-V,i=class{static decompress(t,e,i){let n,r,a=0;const o=new U(16);let h=new m(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,V,0,t),this.buffer.bytePosition=V}else if(this.compressionType==Z){const e=this.buffer.buffer.slice(V),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},W={};function X(t){var e=W[t];if(void 0!==e)return e.exports;var i=W[t]={exports:{}};return j[t].call(i.exports,i,i.exports,X),i.exports}X.d=(t,e)=>{for(var i in e)X.o(e,i)&&!X.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},X.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var H={};(()=>{X.d(H,{P:()=>Ti,m:()=>Li}),X(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),I(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:K,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=K(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},It=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=K(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=K(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=K(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new Lt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Ot),new Lt(4,5,16,8,Ot),new Lt(4,6,32,32,Ot),new Lt(4,4,16,16,It),new Lt(8,16,32,32,It),new Lt(8,16,128,128,It),new Lt(8,32,128,256,It),new Lt(32,128,258,1024,It),new Lt(32,258,258,4096,It)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=K(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=K(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,I,L,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(I=0,L=a[p]):a[p]>_?(I=T[N+a[p]],L=A[U+a[p]]):(I=96,L=0),l=1<>v)+d]=O<<24|I<<16|L|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Ie=!0;const Le=t=>{if(Ie){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Ie=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Le(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var K=H.P,Y=H.m;function G(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=G(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+G(t[s],e,i+1):s.includes(": ")?(r+=G(s,e,i+1),r+=": "+G(t[s],e,i+1)):r+=s+": "+G(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function J(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),G(t,i,-1)}class ${constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new $(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?Q(n,r):q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function Q(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function tt(t){let e=t.replace(/\t/g,"\t").split("\n");return q(new $(e))}function et(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(et(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=et(n);return e}return t}function it(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":return!0;default:return!1}}function nt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function rt(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(it(e))return et(i);if(nt(e))return i=et(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;t=et(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(rt(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=rt(n);return e}return null}function st(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let o=et(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:o,numSharedResources:0};const h=et(t.content),l=a.simplifyType(o[0].type);let d=a.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(it(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable"))return{converted:{type:o,data:{data:{type:e[a+1],data:r}}},traversed:a+1};if(nt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function at(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=et(n),e.content=rt(t.content),"SpriteFont"===a.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ot(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ot(i,e);if(t)return t}return null}}function ht(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function lt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function dt(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ft(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:dt(e)}),extension:lt(e)}:{data:t,extension:lt(e)}}function ct(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ot(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=Y(t.width,t.height,new Uint8Array(n))),ft(n,e)}if(e){return ft(JSON.stringify(t,null,4),"JSON")}return null}function ut(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ct(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(lt(e.type)):"".concat(e.type,".").concat(lt(e.type)):e),4);let l=h;return e&&(l=J(st(t))),r.unshift(ft(l,e?"yaml":"JSON")),r}function _t(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function wt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function bt(t,e){if("png"===t){const t=await pt(e.png),i=K(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await pt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await pt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await wt(e.xml)}}}async function gt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await wt(n);let a=null;a=t.json?JSON.parse(r):at(tt(r));let o=_t(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ot(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=ht(i);e.export=await bt(n,t)}return a}async function mt(t){if("undefined"!=typeof window){const[,e]=ht(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return yt(await t.arrayBuffer())}return yt(t.buffer)}function yt(t){return(new M).load(t)}function vt(t){const{content:e}=t,{data:i,extension:n}=ct(e,!0);return new C(i,n)}function kt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=kt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(gt(e,i).then(xt).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return a.setReaders(t)},t.unpackToContent=function(t){return mt(t).then(vt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=ht(r);const a=t=>ut(t,{yaml:i,contentOnly:n,fileName:s});return mt(t).then(a)},t.unpackToXnbData=mt,t.xnbDataToContent=vt,t.xnbDataToFiles=ut,Object.defineProperty(t,"__esModule",{value:!0})})); +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * LZ4 decoder license : ICS + * Original code : https://github.com/Benzinga/lz4js/ + * + * LZX decoder license : LGPL 2.1 + * ----------------------------------------------------------------------------- + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * ----------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";const e=void 0!==Promise.allSettled?Promise.allSettled.bind(Promise):function(t){let e=t.map((t=>t.then((t=>({status:"fulfilled",value:t}))).catch((t=>({status:"rejected",reason:t})))));return Promise.all(e)};function i(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function n(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"";super(t),this.name="XnbError",this.message=t,Error.captureStackTrace(this,s)}}function a(t){let e=[],i=[];for(let n=0;n")}return e.type()}return null}static simplifyType(t){let e=t.split(/`|,/)[0];if(e.endsWith("[]"))return"Array<".concat(simplifyType(e.slice(0,-2)),">");if("Microsoft.Xna.Framework.Content.ReflectiveReader"===e){let e=o.parseSubtypes(t).map(o.simplifyType.bind(o));return"".concat(e)}for(let e of Object.values(o.readers)){let i=o.makeSimplied(t,e);if(null!==i)return i}throw new s('Non-implemented type found, cannot resolve type "'.concat(e,'", "').concat(t,'".'))}static parseSubtypes(t){let e=t.slice(t.search("`")+1);return e[0],e=a(e)[0],a(e)}static getTypeInfo(t){let e=t.match(/[^<]+/)[0],i=t.match(/<(.+)>/);return i=i?i[1].split(",").map((t=>t.trim())):[],{type:e,subtypes:i}}static getReaderTypeList(t){return o.getReader(t).parseTypeList()}static getReader(t){let{type:e,subtypes:i}=o.getTypeInfo(t);if(i=i.map(o.getReader.bind(o)),o.readers.hasOwnProperty("".concat(e,"Reader")))return new(o.readers["".concat(e,"Reader")])(...i);throw new s('Invalid reader type "'.concat(t,'" passed, unable to resolve!'))}static getReaderFromRaw(t){const e=o.simplifyType(t);return o.getReader(e)}}r(o,"readers",{});const h=[192,224,240],l=128,d=63,f=[55296,56320],c=1023;function u(t){return t<128?[t]:t<2048?[h[0]|t>>6,l|t&d]:t<65536?[h[1]|t>>12,l|t>>6&d,l|t&d]:[h[2]|t>>18,l|t>>12&d,l|t>>6&d,l|t&d]}function _(t){return t<65535?[t]:[f[0]|(t-=65536)>>10&c,f[1]|t&c]}function w(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");const i=t.length;return 1===i?t[0]:2===i?((t[0]^h[0])<<6)+(t[1]^l):3===i?((t[0]^h[1])<<12)+((t[1]^l)<<6)+(t[2]^l):((t[0]^h[2])<<18)+((t[1]^l)<<12)+((t[2]^l)<<6)+(t[3]^l)}function p(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((t[0]&c)<<10)+(t[1]&c)+65536}function b(t){return function(t){const e=[];for(let i of t)e.push(...u(i));return e}(function(t){const e=Array.from({length:t.length},((e,i)=>t.charCodeAt(i))),i=[];let n=0;for(;n1&&void 0!==arguments[1])||arguments[1];this._endianus=e,this._buffer=t.slice(),this._dataView=new DataView(this._buffer),this._offset=0,this._bitOffset=0}seek(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this._offset;const i=this._offset;if(this._offset=Math.max(e+Number.parseInt(t),0),this._offset<0||this._offset>this.buffer.length)throw new RangeError("Buffer seek out of bounds! ".concat(this._offset," ").concat(this.buffer.length));return this._offset-i}get bytePosition(){return Number.parseInt(this._offset)}set bytePosition(t){this._offset=t}get bitPosition(){return Number.parseInt(this._bitOffset)}set bitPosition(t){t<0&&(t=16-t),this._bitOffset=t%16;const e=(t-Math.abs(t)%16)/16*2;this.seek(e)}get size(){return this.buffer.byteLength}get buffer(){return this._buffer}copyFrom(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.byteLength;const r=new Uint8Array(t),s=this.buffer.byteLength0&&void 0!==arguments[0]?arguments[0]:-1;const e=[];if(this._offset,-1===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:0;const e=[],i=this._offset;if(0===t)for(;0!=this.peekByte(1);)e.push(this.readByte());else for(let i=0;i0;){const t=this._dataView.getUint16(this._offset,!0),n=Math.min(Math.max(e,0),16-this.bitPosition),r=16-this.bitPosition-n,s=(t&2**n-1<>r;e-=n,this.bitPosition+=n,i|=s<0&&void 0!==arguments[0])||arguments[0];const e=this.readByte(),i=this.readByte();return t||this.seek(-2),e<<8|i}align(){this.bitPosition>0&&(this.bitPosition+=16-this.bitPosition)}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2048;this._buffer=new ArrayBuffer(t),this._dataView=new DataView(this._buffer),this.bytePosition=0}get buffer(){return this._buffer}reconnectDataView(){this._dataView=new DataView(this._buffer)}trim(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._buffer=this.buffer.slice(0,this.bytePosition),t||this.reconnectDataView()}alloc(t){if(this._buffer.byteLength<=this.bytePosition+t){const e=new ArrayBuffer(this._buffer.byteLength+t),i=new DataView(e);for(let t=0;t>=7)&&(e|=128),this._dataView.setUint8(this.bytePosition,e),this.bytePosition++}while(t)}}const v=256,k=0,x=1,E=2,A=3,U=656;class R{constructor(t){if(this.window_size=1<21)throw new s("Window size out of range!");if(!R.extra_bits.length)for(let t=0,e=0;t<=50;t+=2)R.extra_bits[t]=R.extra_bits[t+1]=e,0!=t&&e<17&&e++;if(!R.position_base.length)for(let t=0,e=0;t<=50;t++)R.position_base[t]=e,e+=1<0;){if(0==this.block_remaining){this.block_type=t.readLZXBits(3);const e=t.readLZXBits(16),i=t.readLZXBits(8);switch(this.block_remaining=e<<8|i,this.block_type){case E:for(let e=0;e<8;e++)this.aligned_len[e]=t.readLZXBits(3);this.aligned_table=this.decodeTable(8,7,this.aligned_len);case x:this.readLengths(t,this.maintree_len,0,256),this.readLengths(t,this.maintree_len,256,this.main_elements),this.maintree_table=this.decodeTable(U,12,this.maintree_len),this.readLengths(t,this.length_len,0,249),this.length_table=this.decodeTable(250,12,this.length_len);break;case A:t.align(),this.R0=t.readInt32(),this.R1=t.readInt32(),this.R2=t.readInt32();break;default:throw new s("Invalid Blocktype Found: ".concat(this.block_type))}}let e=this.block_remaining;for(;(e=this.block_remaining)>0&&n>0;){if(e>n&&(e=n),n-=e,this.block_remaining-=e,this.window_posn&=this.window_size-1,this.window_posn+e>this.window_size)throw new s("Cannot run outside of window frame.");switch(this.block_type){case E:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,U,12);if(n>3;if(s>2){let e=R.extra_bits[s];if(s=R.position_base[s]-2,e>3){e-=3,s+=t.readLZXBits(e)<<3,s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7)}else 3==e?s+=this.readHuffSymbol(t,this.aligned_table,this.aligned_len,8,7):e>0?s+=t.readLZXBits(e):s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case x:for(;e>0;){let i,n=this.readHuffSymbol(t,this.maintree_table,this.maintree_len,U,12);if(n>3;if(s>2){if(3!=s){let e=R.extra_bits[s],i=t.readLZXBits(e);s=R.position_base[s]-2+i}else s=1;this.R2=this.R1,this.R1=this.R0,this.R0=s}else 0===s?s=this.R0:1==s?(s=this.R1,this.R1=this.R0,this.R0=s):(s=this.R2,this.R2=this.R0,this.R0=s);let a,o=this.window_posn;if(e-=r,this.window_posn>=s)a=o-s;else{a=o+(this.window_size-s);let t=s-this.window_posn;if(t0;)this.win[o++]=this.win[a++];a=0}}for(this.window_posn+=r;r-- >0;)this.win[o++]=this.win[a++]}break;case A:if(t.bytePosition+e>i)throw new s("Overrun!"+i+" "+t.bytePosition+" "+e);for(let i=0;i>1;for(let h=1;h<=e;h++){for(let e=0;ea)throw new s("Overrun table!");let i=o;for(;i-- >0;)n[t++]=e}o>>=1}if(r==a)return n;for(let t=r;t>1>1;r<<=16,a<<=16,o=32768;for(let l=e+1;l<=16;l++){for(let d=0;d>16;for(let i=0;i>15-i&1&&t++;if(n[t]=d,(r+=o)>a)throw new s("Overrun table during decoding.")}o>>=1}if(r==a)return n;throw new s("Decode table did not reach table mask.")}readHuffSymbol(t,e,i,n,r){let s=t.peekLZXBits(32)>>>0,a=e[t.peekLZXBits(r)];if(a>=n){let t=1<<32-r;do{if(t>>=1,a<<=1,a|=0!=(s&t)?1:0,0==t)return 0}while((a=e[a])>=n)}return t.bitPosition+=i[a],a}set RRR(t){if(this.R0!=t&&this.R1!=t&&this.R2!=t)this.R2=this.R1,this.R1=this.R0,this.R0=t;else if(this.R1==t){let t=this.R1;this.R1=this.R0,this.R0=t}else if(this.R2==t){let t=this.R2;this.R2=this.R0,this.R0=t}}}R.position_base=[],R.extra_bits=[];class B{static hashU32(t){return-1252372727^(t=(t=(t=(t=-949894596^(t=(t|=0)+2127912214+(t<<12)|0)^t>>>19)+374761393+(t<<5)|0)+-744332180^t<<9)+-42973499+(t<<3)|0)^t>>>16|0}static readU64(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24,i|=t[e++]<<32,i|=t[e++]<<40,i|=t[e++]<<48,i|=t[e++]<<56}static readU32(t,e){var i=0;return i|=t[e++]<<0,i|=t[e++]<<8,i|=t[e++]<<16,i|=t[e++]<<24}static writeU32(t,e,i){t[e++]=i>>0&255,t[e++]=i>>8&255,t[e++]=i>>16&255,t[e++]=i>>24&255}static imul(t,e){var i=65535&t,n=65535&e;return i*n+((t>>>16)*n+i*(e>>>16)<<16)|0}}const O=65536,L=15;!function(t){try{new Uint8Array(t)}catch(n){for(var e=new Array(t),i=0;i=13)for(var u=67;i+4>>0;if(s=r[w=(w>>16^w)>>>0&65535]-1,r[w]=i+1,s<0||i-s>>>16>0||B.readU32(t,s)!==_)i+=u++>>6;else{for(u=67,l=i-a,h=i-s,s+=4,o=i+=4;i=L){for(e[d++]=240+p,c=l-L;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=(l<<4)+p;for(var b=0;b>8,o>=15){for(c=o-15;c>=255;c-=255)e[d++]=255;e[d++]=c}a=i}}if(0===a)return 0;if((l=f-a)>=L){for(e[d++]=240,c=l-L;c>=255;c-=255)e[d++]=255;e[d++]=c}else e[d++]=l<<4;for(i=a;it.charCodeAt(i))),i=[];let n=0;for(;ne<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class D{read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e){const i=z(e);t.write7BitNumber(i),t.writeString(e)}}class P{constructor(t){this.readers=t}read(t){let e=t.read7BitNumber()-1;if(null==this.readers[e])throw new s("Invalid reader index ".concat(e));return this.readers[e].read(t,this)}write(t,e){this.readers[0].write(t,e,this)}getIndex(t){for(let e=0,i=this.readers.length;e"export"===t?e.type:e),4)}stringify(){return JSON.stringify({header:this.header,readers:this.readers,content:this.content},null,4)}toString(){return this.stringify()}}class Z{constructor(t,e){this.type=function(t){switch(t){case"json":return"JSON";case"yaml":return"yaml";case"png":return"Texture2D";case"cso":return"Effect";case"tbin":return"TBin";case"xml":return"BmFont"}return"Others"}(e),this.content=t}}const F=64,V=128,M=14;class j{constructor(){this.target="",this.formatVersion=0,this.hidef=!1,this.compressed=!1,this.compressionType=0,this.buffer=null,this.fileSize=0,this.readers=[],this.sharedResources=[]}load(t){if(this.buffer=new m(t),this._validateHeader(),console.info("XNB file validated successfully!"),this.fileSize=this.buffer.readUInt32(),this.buffer.size!=this.fileSize)throw new s("XNB file has been truncated!");if(this.compressed){const t=this.buffer.readUInt32();if(this.compressionType==V){const e=this.fileSize-M,i=class{static decompress(t,e,i){let n,r,a=0;const o=new R(16);let h=new y(i);for(;a65536||r>65536)throw new s("Invalid size read in compression content.");h.write(o.decompress(t,r,n)),a+=n}return console.log("File has been successfully decompressed!"),h.trim(),h.buffer}}.decompress(this.buffer,e,t);this.buffer.copyFrom(i,M,0,t),this.buffer.bytePosition=M}else if(this.compressionType==F){const e=this.buffer.buffer.slice(M),i=new Uint8Array(e),n=new Uint8Array(t);!function(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.length-2*i,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;var s,a,o,h,l,d=void 0!==e.copyWithin&&void 0!==e.fill;for(o=i+n;i>4;if(c>0){if(15===c)for(;c+=t[i],255===t[i++];);for(h=i+c;i=o)break;if(s=15&f,a=t[i++]|t[i++]<<8,15===s)for(;s+=t[i],255===t[i++];);if(s+=4,d&&1===a)e.fill(0|e[r-1],r,r+s),r+=s;else if(d&&a>s&&s>31)e.copyWithin(r,r-a,r-a+s),r+=s;else for(h=(l=r-a)+s;l0&&void 0!==arguments[0]?arguments[0]:"utf-8";if("utf-8"!==t)throw new RangeError("Failed to construct 'TextEncoder': The encoding label provided ('".concat(t,"') is invalid."))}function i(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf-8",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{fatal:!1};if("utf-8"!==t)throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('".concat(t,"') is invalid."));if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stream:!1};if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},X={};function H(t){var e=X[t];if(void 0!==e)return e.exports;var i=X[t]={exports:{}};return W[t].call(i.exports,i,i.exports,H),i.exports}H.d=(t,e)=>{for(var i in e)H.o(e,i)&&!H.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},H.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var K={};(()=>{H.d(K,{P:()=>Ti,m:()=>Ii}),H(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8192,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;"number"==typeof t?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);const r=e.offset?e.offset>>>0:0,s=t.byteLength-r;let a=r;(ArrayBuffer.isView(t)||t instanceof i)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+r),t=t.buffer),this.lastWrittenByte=n?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;const e=new Uint8Array(t);for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1,e="";for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:1;return i=this.readBytes(e),t.decode(i);var i}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;ethis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function r(t){let e=t.length;for(;--e>=0;)t[e]=0}const s=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),a=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=new Array(576);r(l);const d=new Array(60);r(d);const f=new Array(512);r(f);const c=new Array(256);r(c);const u=new Array(29);r(u);const _=new Array(30);function w(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let p,b,g;function m(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}r(_);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},k=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{k(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},A=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=E(n[e]++,e))}},U=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},B=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,o,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?x(t,r,e):(o=c[r],x(t,o+256+1,e),h=s[o],0!==h&&(r-=u[o],k(t,r,h)),n--,o=y(n),x(t,o,i),h=a[o],0!==h&&(n-=_[o],k(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)O(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],O(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,O(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,f,c,u,_,w=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],c=i[2*i[2*d+1]+1]+1,c>h&&(c=h,w++),i[2*d+1]=c,d>n||(t.bl_count[c]++,u=0,d>=o&&(u=a[d-o]),_=i[2*d],t.opt_len+=_*(c+u),s&&(t.static_len+=_*(r[2*d+1]+u)));if(0!==w){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(c=h;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--l],f>n||(i[2*f+1]!==c&&(t.opt_len+=(c-i[2*f+1])*i[2*f],i[2*f+1]=c),d--)}})(t,e),A(i,l,t.bl_count)},T=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{k(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var D={_tr_init:t=>{S||((()=>{let t,e,i,n,r;const h=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(_[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),I(t,t.l_desc),I(t,t.d_desc),a=(t=>{let e;for(T(t,t.dyn_ltree,t.l_desc.max_code),T(t,t.dyn_dtree,t.d_desc.max_code),I(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*h[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?z(t,e,i,n):4===t.strategy||s===r?(k(t,2+(n?1:0),3),L(t,l,d)):(k(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(k(t,e-257,5),k(t,i-1,5),k(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{k(t,2,3),x(t,256,l),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},P=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const C=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var Z=(t,e,i,n)=>{const r=C,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},F={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},V={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:M,_tr_stored_block:j,_tr_flush_block:W,_tr_tally:X,_tr_align:Y}=D,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:J,Z_FULL_FLUSH:$,Z_FINISH:q,Z_BLOCK:Q,Z_OK:tt,Z_STREAM_END:et,Z_STREAM_ERROR:it,Z_DATA_ERROR:nt,Z_BUF_ERROR:rt,Z_DEFAULT_COMPRESSION:st,Z_FILTERED:at,Z_HUFFMAN_ONLY:ot,Z_RLE:ht,Z_FIXED:lt,Z_DEFAULT_STRATEGY:dt,Z_UNKNOWN:ft,Z_DEFLATED:ct}=V,ut=258,_t=262,wt=103,pt=113,bt=666,gt=(t,e)=>(t.msg=F[e],e),mt=t=>(t<<1)-(t>4?9:0),yt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let vt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},xt=(t,e)=>{W(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,kt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Ut=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=P(t.adler,e,r,i):2===t.state.wrap&&(t.adler=Z(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Rt=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-_t?t.strstart-(t.w_size-_t):0,l=t.window,d=t.w_mask,f=t.prev,c=t.strstart+ut;let u=l[s+a-1],_=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===_&&l[i+a-1]===u&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;u=l[s+a-1],_=l[s+a]}}}while((e=f[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},Bt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-_t)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=Ut(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=vt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=vt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<_t&&0!==t.strm.avail_in)},Ot=(t,e)=>{let i,n;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-_t&&(t.match_length=Rt(t,i)),t.match_length>=3)if(n=X(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=vt(t,t.ins_h,t.window[t.strstart+1]);else n=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2},Lt=(t,e)=>{let i,n,r;for(;;){if(t.lookahead<_t){if(Bt(t),t.lookahead<_t&&e===G)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=X(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=vt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(xt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=X(t,0,t.window[t.strstart-1]),n&&xt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=X(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2};function It(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Tt=[new It(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Bt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,xt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-_t&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(xt(t,!1),t.strm.avail_out),1)})),new It(4,4,8,4,Ot),new It(4,5,16,8,Ot),new It(4,6,32,32,Ot),new It(4,4,16,16,Lt),new It(8,16,32,32,Lt),new It(8,16,128,128,Lt),new It(8,32,128,256,Lt),new It(32,128,258,1024,Lt),new It(32,258,258,4096,Lt)];function Nt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ct,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),yt(this.dyn_ltree),yt(this.dyn_dtree),yt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),yt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),yt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const St=t=>{const e=(t=>{if(!t||!t.state)return gt(t,it);t.total_in=t.total_out=0,t.data_type=ft;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:pt,t.adler=2===e.wrap?0:1,e.last_flush=G,M(e),tt})(t);var i;return e===tt&&((i=t.state).window_size=2*i.w_size,yt(i.head),i.max_lazy_match=Tt[i.level].max_lazy,i.good_match=Tt[i.level].good_length,i.nice_match=Tt[i.level].nice_length,i.max_chain_length=Tt[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e};var zt=(t,e,i,n,r,s)=>{if(!t)return it;let a=1;if(e===st&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==ct||n<8||n>15||e<0||e>9||s<0||s>lt)return gt(t,it);8===n&&(n=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<{let i,n;if(!t||!t.state||e>Q||e<0)return t?gt(t,it):it;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===bt&&e!==q)return gt(t,0===t.avail_out?rt:it);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Z(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=ot||r.level<2?4:0),Et(r,3),r.status=pt);else{let e=ct+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=ot||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=pt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),kt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=Z(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=wt)}else r.status=wt;if(r.status===wt&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&kt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=pt)):r.status=pt),0!==r.pending){if(kt(t),0===t.avail_out)return r.last_flush=-1,tt}else if(0===t.avail_in&&mt(e)<=mt(s)&&e!==q)return gt(t,rt);if(r.status===bt&&0!==t.avail_in)return gt(t,rt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==bt){let i=r.strategy===ot?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Bt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ht?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ut){if(Bt(t),t.lookahead<=ut&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ut;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=X(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=X(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(xt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(xt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(xt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Tt[r.level].func(r,e);if(3!==i&&4!==i||(r.status=bt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),tt;if(2===i&&(e===J?Y(r):e!==Q&&(j(r,0,0,!1),e===$&&(yt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),kt(t),0===t.avail_out))return r.last_flush=-1,tt}return e!==q?tt:r.wrap<=0?et:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),kt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?tt:et)},Pt=t=>{if(!t||!t.state)return it;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==wt&&e!==pt&&e!==bt?gt(t,it):(t.state=null,e===pt?gt(t,nt):tt)};const Ct=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Zt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Ct(i,e)&&(t[e]=i[e])}}return t},Ft=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Mt[254]=Mt[254]=1;var jt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},Wt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Vt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Mt[t[i]]>e?i:e},Ht=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Kt=Object.prototype.toString,{Z_NO_FLUSH:Yt,Z_SYNC_FLUSH:Gt,Z_FULL_FLUSH:Jt,Z_FINISH:$t,Z_OK:qt,Z_STREAM_END:Qt,Z_DEFAULT_COMPRESSION:te,Z_DEFAULT_STRATEGY:ee,Z_DEFLATED:ie}=V;function ne(t){this.options=Zt({level:te,method:ie,chunkSize:16384,windowBits:15,memLevel:8,strategy:ee},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=zt(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==qt)throw new Error(F[i]);if(e.header&&((t,e)=>{t&&t.state&&(2!==t.state.wrap||(t.state.gzhead=e))})(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?jt(e.dictionary):"[object ArrayBuffer]"===Kt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=((t,e)=>{let i=e.length;if(!t||!t.state)return it;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return it;if(1===r&&(t.adler=P(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(yt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Bt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=vt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,Bt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,tt})(this.strm,t),i!==qt)throw new Error(F[i]);this._dict_set=!0}}function re(t,e){const i=new ne(e);if(i.push(t,!0),i.err)throw i.msg||F[i.err];return i.result}ne.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?$t:Yt,"string"==typeof t?i.input=jt(t):"[object ArrayBuffer]"===Kt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Gt||s===Jt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Dt(i,s),r===Qt)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Pt(this.strm),this.onEnd(r),this.ended=!0,r===qt;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ne.prototype.onData=function(t){this.chunks.push(t)},ne.prototype.onEnd=function(t){t===qt&&(this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var se={Deflate:ne,deflate:re,deflateRaw:function(t,e){return(e=e||{}).raw=!0,re(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,re(t,e)},constants:V},ae=function(t,e){let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E,A;const U=t.state;i=t.next_in,E=t.input,n=i+(t.avail_in-5),r=t.next_out,A=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,f=U.window,c=U.hold,u=U.bits,_=U.lencode,w=U.distcode,p=(1<>>24,c>>>=m,u-=m,m=g>>>16&255,0===m)A[r++]=65535&g;else{if(!(16&m)){if(0==(64&m)){g=_[(65535&g)+(c&(1<>>=m,u-=m),u<15&&(c+=E[i++]<>>24,c>>>=m,u-=m,m=g>>>16&255,!(16&m)){if(0==(64&m)){g=w[(65535&g)+(c&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=m,u-=m,m=r-s,v>m){if(m=v-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(k=0,x=f,0===d){if(k+=h-m,m2;)A[r++]=x[k++],A[r++]=x[k++],A[r++]=x[k++],y-=3;y&&(A[r++]=x[k++],y>1&&(A[r++]=x[k++]))}else{k=r-v;do{A[r++]=A[k++],A[r++]=A[k++],A[r++]=A[k++],y-=3}while(y>2);y&&(A[r++]=A[k++],y>1&&(A[r++]=A[k++]))}break}}break}}while(i>3,i-=y,u-=y<<3,c&=(1<{const h=o.bits;let l,d,f,c,u,_,w=0,p=0,b=0,g=0,m=0,y=0,v=0,k=0,x=0,E=0,A=null,U=0;const R=new Uint16Array(16),B=new Uint16Array(16);let O,L,I,T=null,N=0;for(w=0;w<=15;w++)R[w]=0;for(p=0;p=1&&0===R[g];g--);if(m>g&&(m=g),0===g)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(0===t||1!==g))return-1;for(B[1]=0,w=1;w<15;w++)B[w+1]=B[w]+R[w];for(p=0;p852||2===t&&x>592)return 1;for(;;){O=w-v,a[p]<_?(L=0,I=a[p]):a[p]>_?(L=T[N+a[p]],I=A[U+a[p]]):(L=96,I=0),l=1<>v)+d]=O<<24|L<<16|I|0}while(0!==d);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--R[w]){if(w===g)break;w=e[i+a[p]]}if(w>m&&(E&c)!==f){for(0===v&&(v=m),u+=b,y=w-v,k=1<852||2===t&&x>592)return 1;f=E&c,r[f]=m<<24|y<<16|u-s|0}}return 0!==E&&(r[u+E]=w-v<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:ce,Z_BLOCK:ue,Z_TREES:_e,Z_OK:we,Z_STREAM_END:pe,Z_NEED_DICT:be,Z_STREAM_ERROR:ge,Z_DATA_ERROR:me,Z_MEM_ERROR:ye,Z_BUF_ERROR:ve,Z_DEFLATED:ke}=V,xe=12,Ee=30,Ae=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ue(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Re=t=>{if(!t||!t.state)return ge;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,(t=>{if(!t||!t.state)return ge;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,we})(t)};let Be,Oe,Le=!0;const Ie=t=>{if(Le){Be=new Int32Array(512),Oe=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(fe(1,t.lens,0,288,Be,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;fe(2,t.lens,0,32,Oe,0,t.work,{bits:5}),Le=!1}t.lencode=Be,t.lenbits=9,t.distcode=Oe,t.distbits=5},Te=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{if(!t)return ge;const i=new Ue;t.state=i,i.window=null;const n=((t,e)=>{let i;if(!t||!t.state)return ge;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ge:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Re(t))})(t,e);return n!==we&&(t.state=null),n},ze=(t,e)=>{let i,n,r,s,a,o,h,l,d,f,c,u,_,w,p,b,g,m,y,v,k,x,E=0;const A=new Uint8Array(4);let U,R;const B=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ge;i=t.state,i.mode===xe&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,f=o,c=h,x=we;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=Ee;break}if((15&l)!==ke){t.msg="unknown compression method",i.mode=Ee;break}if(l>>>=4,d-=4,k=8+(15&l),0===i.wbits)i.wbits=k;else if(k>i.wbits){t.msg="invalid window size",i.mode=Ee;break}i.dmax=1<>8&1),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,i.check=Z(i.check,A,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(A[0]=255&l,A[1]=l>>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=Z(i.check,A,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(u=i.length,u>o&&(u=o),u&&(i.head&&(k=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+u),k)),512&i.flags&&(i.check=Z(i.check,n,u,s)),o-=u,s+=u,i.length-=u),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;u=0;do{k=n[s+u++],i.head&&k&&i.length<65536&&(i.head.name+=String.fromCharCode(k))}while(k&&u>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=xe;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Ie(i),i.mode=20,e===_e){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=Ee}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=Ee;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===_e)break t;case 15:i.mode=16;case 16:if(u=i.length,u){if(u>o&&(u=o),u>h&&(u=h),0===u)break t;r.set(n.subarray(s,s+u),a),o-=u,s+=u,h-=u,a+=u,i.length-=u;break}i.mode=xe;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=Ee;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[B[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},x=fe(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid code lengths set",i.mode=Ee;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=g;else{if(16===g){for(R=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=Ee;break}k=i.lens[i.have-1],u=3+(3&l),l>>>=2,d-=2}else if(17===g){for(R=p+3;d>>=p,d-=p,k=0,u=3+(7&l),l>>>=3,d-=3}else{for(R=p+7;d>>=p,d-=p,k=0,u=11+(127&l),l>>>=7,d-=7}if(i.have+u>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=Ee;break}for(;u--;)i.lens[i.have++]=k}}if(i.mode===Ee)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=Ee;break}if(i.lenbits=9,U={bits:i.lenbits},x=fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,x){t.msg="invalid literal/lengths set",i.mode=Ee;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},x=fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,x){t.msg="invalid distances set",i.mode=Ee;break}if(i.mode=20,e===_e)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,ae(t,c),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===xe&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=g,0===b){i.mode=26;break}if(32&b){i.back=-1,i.mode=xe;break}if(64&b){t.msg="invalid literal/length code",i.mode=Ee;break}i.extra=15&b,i.mode=22;case 22:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,g=65535&E,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=E>>>24,b=E>>>16&255,g=65535&E,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&b){t.msg="invalid distance code",i.mode=Ee;break}i.offset=g,i.extra=15&b,i.mode=24;case 24:if(i.extra){for(R=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=Ee;break}i.mode=25;case 25:if(0===h)break t;if(u=c-h,i.offset>u){if(u=i.offset-u,u>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=Ee;break}u>i.wnext?(u-=i.wnext,_=i.wsize-u):_=i.wnext-u,u>i.length&&(u=i.length),w=i.window}else w=r,_=a-i.offset,u=i.length;u>h&&(u=h),h-=u,i.length-=u;do{r[a++]=w[_++]}while(--u);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ge;let e=t.state;return e.window&&(e.window=null),t.state=null,we},Pe=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ge:11===n.mode&&(r=1,r=P(r,e,i,0),r!==n.check)?me:(s=Te(t,e,i,i),s?(n.mode=31,ye):(n.havedict=1,we))):ge},Ce=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ze=Object.prototype.toString,{Z_NO_FLUSH:Fe,Z_FINISH:Ve,Z_OK:Me,Z_STREAM_END:je,Z_NEED_DICT:We,Z_STREAM_ERROR:Xe,Z_DATA_ERROR:He,Z_MEM_ERROR:Ke}=V;function Ye(t){this.options=Zt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Ht,this.strm.avail_out=0;let i=Se(this.strm,e.windowBits);if(i!==Me)throw new Error(F[i]);if(this.header=new Ce,((t,e)=>{if(!t||!t.state)return ge;const i=t.state;0==(2&i.wrap)||(i.head=e,e.done=!1)})(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=jt(e.dictionary):"[object ArrayBuffer]"===Ze.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Pe(this.strm,e.dictionary),i!==Me)))throw new Error(F[i])}function Ge(t,e){const i=new Ye(e);if(i.push(t),i.err)throw i.msg||F[i.err];return i.result}Ye.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ve:Fe,"[object ArrayBuffer]"===Ze.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=ze(i,a),s===We&&r&&(s=Pe(i,r),s===Me?s=ze(i,a):s===He&&(s=We));i.avail_in>0&&s===je&&i.state.wrap>0&&0!==t[i.next_in];)Ne(i),s=ze(i,a);switch(s){case Xe:case He:case We:case Ke:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===je))if("string"===this.options.to){let t=Xt(i.output,i.next_out),e=i.next_out-t,r=Wt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Me||0!==o){if(s===je)return s=De(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Ye.prototype.onData=function(t){this.chunks.push(t)},Ye.prototype.onEnd=function(t){t===Me&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Ft(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Je={Inflate:Ye,inflate:Ge,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Ge(t,e)},ungzip:Ge,constants:V};const{Deflate:$e,deflate:qe,deflateRaw:Qe,gzip:ti}=se,{Inflate:ei,inflate:ii,inflateRaw:ni,ungzip:ri}=Je;var si=qe,ai=ei,oi=ii;const hi=[137,80,78,71,13,10,26,10],li=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;li[t]=e}function di(t,e){return(4294967295^function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e))>>>0}var fi,ci,ui,_i;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(fi||(fi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ci||(ci={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(ui||(ui={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(_i||(_i={}));const wi=new Uint8Array(0),pi=new Uint16Array([255]),bi=255===new Uint8Array(pi.buffer)[0];class gi extends i{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ai,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ci.UNKNOWN,this._filterMethod=ui.UNKNOWN,this._interlaceMethod=_i.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error("tRNS chunk contains more alpha values than there are palette colors (".concat(t," vs ").concat(this._palette.length,")"));let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function mi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function xi(t,e,i,n,r){let s=0;if(0===i.length){for(;s1&&void 0!==arguments[1]?arguments[1]:{};super(),this._colorType=fi.UNKNOWN,this._zlibOptions=n(n({},Ai),e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(hi)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(ci.DEFLATE),this.writeByte(ui.ADAPTIVE),this.writeByte(_i.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:n,depth:r,data:s}=this._png,a=n*t,o=(new i).setBigEndian();let h=0;for(let t=0;t0)return t;throw new TypeError("".concat(e," must be a positive integer"))}function Bi(t,e,i,n){for(let r=0;rnew Ui({width:t,height:e,data:i},void 0).encode(),Ti=t=>function(t,e){return new gi(t,void 0).decode()}(t)})();var Y=K.P,G=K.m;function J(t,e,i){if((n=t)&&n.hasOwnProperty("type")&&n.hasOwnProperty("data")){let n=J(t.data,e,i);return n.includes("\n")?" #!"+t.type+n:n+" #!"+t.type}if(t&&"object"==typeof t){let n=Array.isArray(t);if(0==Object.keys(t).length)return n?"[]":"{}";let r="\n";for(let s in t)Object.hasOwnProperty.call(t,s)&&(r+=e.repeat(i+1),n?r+="- "+J(t[s],e,i+1):s.includes(": ")?(r+=J(s,e,i+1),r+=": "+J(t[s],e,i+1)):r+=s+": "+J(t[s],e,i+1),r+="\n");return r}if("string"==typeof t)return JSON.stringify(t);if(null==t)return"null";if(!!t==t||+t==t)return JSON.stringify(t);throw new Error("Non-implemented parsing for "+t);var n}function $(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;var i="";return"number"==typeof e?i=" ".repeat(Math.min(10,e)):"string"==typeof e&&(i=e.slice(0,10)),J(t,i,-1)}class q{constructor(t,e,i){this.startingLine=i||0,this.lineIndex=-1;let n=[];for(let e=0;e=e;)t.push(this.next());return new q(t,this.indentString,this.getLineNumber()-t.length)}next(){if(this.finished())throw new Error("Trying to next finished generator");return this.lineIndex++,this.getLine()}peek(){return this.getLine(this.lineIndex+1)}finished(){return this.lineIndex==this.lines.length-1}getLine(t){return(t=void 0!==t?t:this.lineIndex)>=this.lines.length?null:this.lines[t][0]}findIndentString(){for(let[t]of this.lines)if(t.trim()&&t.replace(/^\s+/,"")!=t)return t.match(/^(\s+)/)[1];return""}indentLevel(t){(t=void 0!==t?t:this.lineIndex)<0&&(t=0);let e=0,i=this.getLine(t);for(;i.startsWith(this.indentString);)i=i.slice(this.indentString.length),e++;return e}}function Q(t,e){let i;for(t.indentLevel();!t.finished();){let e,n,r,s=t.next().trim(),a=s.match(/^(.*?):(?: |$)/),o=s.match(/#!([\w<,>]+)/);s.startsWith('"')&&(a=s.match(/^"(.*?)":(?: |$)/)),o&&(r=o[1],s=s.replace(o[0],"")),a?(i||(i={}),e=a[1],n=s.replace(a[0],"").trim()):s.startsWith("-")&&(i||(i=[]),n=s.slice(1).trim()),n=n?tt(n,r):Q(t.nextGroup(),r),Array.isArray(i)?i.push(n):i[e]=n}return e&&(i={type:e,data:i}),i}function tt(t,e){return t=JSON.parse(t),e&&(t={type:e,data:t}),t}function et(t){let e=t.replace(/\t/g,"\t").split("\n");return Q(new q(e))}function it(t){let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(it(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=it(n);return e}return t}function nt(t){switch(t){case"Boolean":case"Int32":case"UInt32":case"Single":case"Double":case"Char":case"String":case"":case"Vector2":case"Vector3":case"Vector4":case"Rectangle":case"Rect":return!0;default:return!1}}function rt(t){switch(t){case"Texture2D":case"TBin":case"Effect":case"BmFont":return!0;default:return!1}}function st(t){if(!t||"object"!=typeof t)return t;if("object"==typeof t&&t.hasOwnProperty("data")){let{type:e,data:i}=t;if(nt(e))return it(i);if(rt(e))return i=it(i),"Texture2D"===e?i.export="Texture2D.png":"Effect"===e?i.export="Effect.cso":"TBin"===e?i.export="TBin.tbin":"BmFont"===e&&(i.export="BmFont.xml"),i;if(e.startsWith("Nullable"))return null===i||null===i.data?null:st(i.data);t=it(i)}let e;if(Array.isArray(t)){e=[];for(let i of t)e.push(st(i));return e}if(t&&"object"==typeof t){e={};for(let[i,n]of Object.entries(t))e[i]=st(n);return e}return null}function at(t){const e={},{compressed:i,formatVersion:n,hidef:r,target:s}=t.header;let a=it(t.readers);e.xnbData={target:s,compressed:!!i,hiDef:r,readerData:a,numSharedResources:0};const h=it(t.content),l=o.simplifyType(a[0].type);let d=o.getReaderTypeList(l);"SpriteFont"===d[0]&&(d=["SpriteFont","Texture2D","List","Rectangle","List","Rectangle","List","Char",null,"List","Vector3","Nullable","Char",null],h.verticalSpacing=h.verticalLineSpacing,delete h.verticalLineSpacing);const{converted:f,extractedImages:c,extractedMaps:u}=function(t,e){let i=[],n=[];const{converted:r}=function t(r,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const o=e[a];if(nt(o))return{converted:{type:o,data:r},traversed:a};if(null===o)return{converted:r,traversed:a};if(o.startsWith("Nullable")){let i,n,[h,l=1]=o.split(":");if(l=+l,null===r)i=null,n=a+l;else if("object"!=typeof r||r&&0!==Object.keys(r).length){let{converted:e,traversed:o}=t(r,[...s],a+1);i=e,n=o}else i={type:e[a+1],data:it(r)},n=a+l;return{converted:{type:h,data:{data:i}},traversed:n}}if(rt(o))return"Texture2D"===o?(i.push({path:s.join(".")}),{converted:{type:o,data:{format:r.format}},traversed:a}):("TBin"===o&&n.push({path:s.join(".")}),{converted:{type:o,data:{}},traversed:a});let h;h=Array.isArray(r)?[]:{};let l=a,d=!0,f=!o.startsWith("Dictionary")&&!o.startsWith("Array")&&!o.startsWith("List");for(let[e,i]of Object.entries(r)){let i;i=o.startsWith("Dictionary")?a+2:o.startsWith("Array")||o.startsWith("List")?a+1:l+1;const{converted:n,traversed:c}=t(r[e],[...s,e],i);h[e]=n,f?l=c:d&&(l=c,d=!1)}return{converted:{type:o,data:h},traversed:l}}(t,[]);return{converted:r,extractedImages:i,extractedMaps:n}}(h,d);return e.content=f,c.length>0&&(e.extractedImages=c),u.length>0&&(e.extractedMaps=u),e}function ot(t){const e={},{compressed:i,readerData:n,hiDef:r,target:s}=t.xnbData;return e.header={target:s,formatVersion:5,compressed:i?"a"===s||"i"===s?64:128:0,hidef:r},e.readers=it(n),e.content=st(t.content),"SpriteFont"===o.simplifyType(e.readers[0].type)&&(e.content.verticalLineSpacing=e.content.verticalSpacing,delete e.content.verticalSpacing),e}function ht(t,e){if(t&&"object"==typeof t){if(t.hasOwnProperty(e))return{parent:t,value:t[e]};for(let i of Object.values(t))if(i||"object"==typeof i){let t=ht(i,e);if(t)return t}return null}}function lt(t){let e=t.match(/(.*)\.([^\s.]+)$/);return null===e?[t,null]:[e[1],e[2]]}function dt(t){switch(t){case"JSON":return"json";case"yaml":return"yaml";case"Texture2D":return"png";case"Effect":return"cso";case"TBin":return"tbin";case"BmFont":return"xml"}return"bin"}function ft(t){switch(t){case"JSON":return"application/json";case"yaml":return"text/plain";case"Texture2D":return"image/png";case"Effect":return"application/x-cso";case"BmFont":return"application/xml"}return"application/octet-stream"}function ct(t,e){return"function"==typeof Blob?{data:new Blob([t],{type:ft(e)}),extension:dt(e)}:{data:t,extension:dt(e)}}function ut(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=ht(t,"export");if(i){const{value:t}=i;let{type:e,data:n}=t;return"Texture2D"===e&&(n=G(t.width,t.height,new Uint8Array(n))),ct(n,e)}if(e){return ct(JSON.stringify(t,null,4),"JSON")}return null}function _t(t){let{yaml:e=!1,contentOnly:i=!1,fileName:n=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&i&&(e=!1),!t.hasOwnProperty("content"))throw new s("Invalid object!");const r=[],{content:a}=t,o=ut(a,i);if(null!==o&&r.push(o),i)return r;const h=JSON.stringify(t,((t,e)=>"export"===t?"string"==typeof n&&""!==n?"".concat(n,".").concat(dt(e.type)):"".concat(e.type,".").concat(dt(e.type)):e),4);let l=h;return e&&(l=$(at(t))),r.unshift(ct(l,e?"yaml":"JSON")),r}function wt(t){let e=t.toLowerCase();return"none"===e?0:"lz4"===e?64:null}async function pt(t){return"function"==typeof Blob&&t instanceof Blob?t.text():"function"==typeof Buffer&&t instanceof Buffer?t.toString():void 0}async function bt(t){return"function"==typeof Blob&&t instanceof Blob?t.arrayBuffer():"function"==typeof Buffer&&t instanceof Buffer?t.buffer:void 0}async function gt(t,e){if("png"===t){const t=await bt(e.png),i=Y(new Uint8Array(t));return{type:"Texture2D",data:i.data,width:i.width,height:i.height}}if("cso"===t){return{type:"Effect",data:await bt(e.cso)}}if("tbin"===t){return{type:"TBin",data:await bt(e.tbin)}}if("xml"===t){return{type:"BmFont",data:await pt(e.xml)}}}async function mt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{compression:i="default"}=e,n=t.json||t.yaml;if(!n)throw new s("There is no JSON or YAML file to pack!");const r=await pt(n);let a=null;a=t.json?JSON.parse(r):ot(et(r));let o=wt(i);if(null!==o&&(a.header.compressed=o),!a.hasOwnProperty("content"))throw new s("".concat(n.name,' does not have "content".'));const h=ht(a.content,"export");if(h){const{parent:e,value:i}=h,[,n]=lt(i);e.export=await gt(n,t)}return a}async function yt(t){if("undefined"!=typeof window){const[,e]=lt(t.name);if("xnb"!==e)return new Error("Invalid XNB File!");return vt(await t.arrayBuffer())}return vt(t.buffer)}function vt(t){return(new j).load(t)}function kt(t){const{content:e}=t,{data:i,extension:n}=ut(e,!0);return new Z(i,n)}function xt(t){let e={};for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};const n=xt(t);let r=[];for(let[t,e]of Object.entries(n))r.push(mt(e,i).then(Et).then((e=>"function"==typeof Blob?{name:t,data:new Blob([e],{type:"application/octet-stream"})}:{name:t,data:new Uint8Array(e)})));return e(r).then((t=>!0===i.debug?t:t.filter((t=>{let{status:e,value:i}=t;return"fulfilled"===e})).map((t=>{let{value:e}=t;return e}))))},t.setReaders=function(t){return o.setReaders(t)},t.unpackToContent=function(t){return yt(t).then(kt)},t.unpackToFiles=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{yaml:i=!1,contentOnly:n=!1,fileName:r=null}=e;"undefined"!=typeof window&&null===r&&(r=t.name);let[s]=lt(r);const a=t=>_t(t,{yaml:i,contentOnly:n,fileName:s});return yt(t).then(a)},t.unpackToXnbData=yt,t.xnbDataToContent=kt,t.xnbDataToFiles=_t,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/core/dist/core.module.js b/src/core/dist/core.module.js index 8c40cc2..1b4d0ba 100644 --- a/src/core/dist/core.module.js +++ b/src/core/dist/core.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { let mappedPromises = promises.map(p => { return p.then(value => { @@ -67,6 +76,22 @@ class XnbError extends Error { } +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + class TypeReader { static setReaders(readers) { TypeReader.readers = _objectSpread2({}, readers); @@ -108,13 +133,10 @@ class TypeReader { } static parseSubtypes(type) { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); return matches; } @@ -129,12 +151,8 @@ class TypeReader { } static getReaderTypeList(typeString) { - let { - type, - subtypes - } = TypeReader.getTypeInfo(typeString); - if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return TypeReader.readers["".concat(type, "Reader")].parseTypeList(subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); } static getReader(typeString) { @@ -1533,7 +1551,9 @@ class ReaderResolver { } getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } } } @@ -4680,6 +4700,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -4728,17 +4749,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -4825,6 +4865,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } diff --git a/src/core/libs/jsonToYaml.js b/src/core/libs/jsonToYaml.js index 34f4109..0efaa7f 100644 --- a/src/core/libs/jsonToYaml.js +++ b/src/core/libs/jsonToYaml.js @@ -154,6 +154,7 @@ function getObject(lineGroup, type) { let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); + let key, value, type; if(trimmedLine.startsWith('"')) { diff --git a/src/plugins-stardewvalley/Readers/ModFarmTypeReader.js b/src/plugins-stardewvalley/Readers/ModFarmTypeReader.js new file mode 100644 index 0000000..f2443d8 --- /dev/null +++ b/src/plugins-stardewvalley/Readers/ModFarmTypeReader.js @@ -0,0 +1,84 @@ +import {BaseReader, + NullableReader, + StringReader, + DictionaryReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * ModFarmType Reader + * @class + * @extends BaseReader + */ +export default class ModFarmTypeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + default: return false; + } + } + static parseTypeList() { + return ["ModFarmType", + "String", // ID + "String", // tooltipStringPath + "String", // mapName + "Nullable:1", "String", //iconTexture + "Nullable:1", "String", //worldMapTexture + "Nullable>:4", "Dictionary", "String", "String" //modData + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads ModFarmType from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableStringDictReader = new NullableReader( + new DictionaryReader( new StringReader() ) + ); + + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader( new StringReader() ); + const nullableStringDictReader = new NullableReader( + new DictionaryReader( new StringReader() ) + ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/ModLanguageReader.js b/src/plugins-stardewvalley/Readers/ModLanguageReader.js new file mode 100644 index 0000000..d410ddf --- /dev/null +++ b/src/plugins-stardewvalley/Readers/ModLanguageReader.js @@ -0,0 +1,115 @@ +import {BaseReader, + NullableReader, + StringReader, + BooleanReader, + Int32Reader, + SingleReader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * ModLanguage Reader + * @class + * @extends BaseReader + */ +export default class ModLanguageReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + default: return false; + } + } + static parseTypeList() { + return ["ModLanguage", + "String", // ID + "String", // languageCode + "String", // buttonTexture + null, // useLatinFont + "Nullable:1", "String", // fontFile + null, // fontPixelZoom + null, // fontApplyYOffset + null, // smallFontLineSpacing + null, // useGenderedCharacterTranslations + "Nullable:1", "String", //numberComma + "String", // numberComma + "String", // timeFormat + "String", // clockTimeFormat + "String" // clockDataFormat + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads ModLanguage from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader( new StringReader() ); + + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader( new StringReader() ); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/ModWallpaperOrFlooringReader.js b/src/plugins-stardewvalley/Readers/ModWallpaperOrFlooringReader.js new file mode 100644 index 0000000..9617b7d --- /dev/null +++ b/src/plugins-stardewvalley/Readers/ModWallpaperOrFlooringReader.js @@ -0,0 +1,72 @@ +import {BaseReader, + StringReader, + BooleanReader, + Int32Reader +} from "../../readers/src/readers.js"; //@xnb/readers + +/** + * ModWallpaperOrFlooring Reader + * @class + * @extends BaseReader + */ +export default class ModWallpaperOrFlooringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + default: return false; + } + } + static parseTypeList() { + return ["ModWallpaperOrFlooring", + "String", // ID + "String", // Texture + null, // IsFlooring + null // Count + ]; + } + static type() + { + return "Reflective"; + } + + /** + * Reads ModWallpaperOrFlooring from buffer. + * @param {BufferReader} buffer + * @param {ReaderResolver} resolver + * @returns {object} + */ + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + + this.writeIndex(buffer, resolver); + + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js index 2546997..7201115 100644 --- a/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js +++ b/src/plugins-stardewvalley/Readers/SpecialOrderObjectiveDataReader.js @@ -50,8 +50,6 @@ export default class SpecialOrderObjectiveDataReader extends BaseReader { } write(buffer, content, resolver) { - console.log(content); - const stringReader = new StringReader(); const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); diff --git a/src/plugins-stardewvalley/dist/index.cjs b/src/plugins-stardewvalley/dist/index.cjs new file mode 100644 index 0000000..b6e2e48 --- /dev/null +++ b/src/plugins-stardewvalley/dist/index.cjs @@ -0,0 +1,1395 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var readers = require('@xnb/readers'); + +class MovieSceneReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieScene", null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieData", "Nullable", 'String', null, 'String', 'String', "Nullable>", 'List', 'String', "List", ...MovieSceneReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const movieSceneListReader = new readers.ListReader(new MovieSceneReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } + +} + +class CharacterResponseReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["CharacterResponse", "Nullable:1", "String", "Nullable:1", "String", "Nullable:1", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialResponsesReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialResponses", "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableCharacterResponseReader = new readers.NullableReader(new CharacterResponseReader()); + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new readers.NullableReader(new CharacterResponseReader()); + this.writeIndex(buffer, resolver); + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieReactionReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieReaction", "String", "Nullable:1", "String", "Nullable>:2", "List", "String", "Nullable:25", ...SpecialResponsesReader.parseTypeList(), "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableSpecialResponsesReader = new readers.NullableReader(new SpecialResponsesReader()); + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableSpecialResponsesReader = new readers.NullableReader(new SpecialResponsesReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieCharacterReactionReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieCharacterReaction", "String", "Nullable>:34", "List", ...MovieReactionReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableReactionListReader = new readers.NullableReader(new readers.ListReader(new MovieReactionReader())); + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableReactionListReader = new readers.NullableReader(new readers.ListReader(new MovieReactionReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionItemDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionItemData", null, 'String', 'String', 'String', null, 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionTasteReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionTaste", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } + +} + +class FishPondRewardReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondReward': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondReward", null, null, null, null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const RequiredPopulation = int32Reader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } + +} + +class FishPondDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondData", "List", "String", null, "List", ...FishPondRewardReader.parseTypeList(), "Nullable>>:4", "Dictionary>", "Int32", "List", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringListDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.Int32Reader(), new readers.ListReader(new readers.StringReader()))); + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, resolver); + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new readers.ListReader(new readers.StringReader()); + const int32Reader = new readers.Int32Reader(); + const fishPondRewardListReader = new readers.ListReader(new FishPondRewardReader()); + const stringListDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.Int32Reader(), new readers.ListReader(new readers.StringReader()))); + this.writeIndex(buffer, resolver); + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, null); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } + +} + +class TailorItemRecipeReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["TailorItemRecipe", "Nullable>:2", "List", "String", "Nullable>:2", "List", "String", null, null, "Nullable>:2", "List", "String", "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + this.writeIndex(buffer, resolver); + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } + +} + +class RenovationValueReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RenovationValue", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Key = resolver.read(buffer); + const Value = resolver.read(buffer); + return { + Type, + Key, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RectReader extends readers.RectangleReader { + static isTypeOf(type) { + if (super.isTypeOf(type)) return true; + + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["Rect"]; + } + + static type() { + return "Reflective"; + } + + isValueType() { + return false; + } + +} + +class RectGroupReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RectGroup", "List", "Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Rects = resolver.read(buffer); + return { + Rects + }; + } + + write(buffer, content, resolver) { + const rectListReader = new readers.ListReader(new RectReader()); + this.writeIndex(buffer, resolver); + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } + +} + +class HomeRenovationReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["HomeRenovation", "String", "String", null, "List", ...RenovationValueReader.parseTypeList(), "List", ...RenovationValueReader.parseTypeList(), "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new readers.BooleanReader(); + const nullableRectGroupListReader = new readers.NullableReader(new readers.ListReader(new RectGroupReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const TextStrings = resolver.read(buffer); + const AnimationType = resolver.read(buffer); + const CheckForObstructions = booleanReader.read(buffer); + const Requirements = resolver.read(buffer); + const RenovateActions = resolver.read(buffer); + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); + const SpecialRect = nullableStringReader.read(buffer, resolver); + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new readers.BooleanReader(); + const stringReader = new readers.StringReader(); + const renovationValueListReader = new readers.ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new readers.NullableReader(new readers.ListReader(new RectGroupReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleData", "String", null, "String", "String", "String", null, null, "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleSetDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleSetData", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + return { + Bundles + }; + } + + write(buffer, content, resolver) { + const bundleListReader = new readers.ListReader(new BundleDataReader()); + this.writeIndex(buffer, resolver); + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomBundleDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomBundleData", "String", "String", "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(), "Nullable>:11", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableBundleSetListReader = new readers.NullableReader(new readers.ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new readers.NullableReader(new readers.ListReader(new BundleDataReader())); + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableBundleSetListReader = new readers.NullableReader(new readers.ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new readers.NullableReader(new readers.ListReader(new BundleDataReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementItemReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElementItem", "Nullable", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + return { + RequiredTags, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElement", "String", "List", ...RandomizedElementItemReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Name = resolver.read(buffer); + const Values = resolver.read(buffer); + return { + Name, + Values + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const itemListReader = new readers.ListReader(new RandomizedElementItemReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderObjectiveDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderObjectiveData", "String", "String", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const stringDictReader = new readers.DictionaryReader(new readers.StringReader(), new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderRewardDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderRewardData", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const stringDictReader = new readers.DictionaryReader(new readers.StringReader(), new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderData", "String", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), "List", ...SpecialOrderRewardDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableRandomizedElemListReader = new readers.NullableReader(new readers.ListReader(new RandomizedElementReader())); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); + return { + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableRandomizedElemListReader = new readers.NullableReader(new readers.ListReader(new RandomizedElementReader())); + const objectiveListReader = new readers.ListReader(new SpecialOrderObjectiveDataReader()); + const rewardListReader = new readers.ListReader(new SpecialOrderRewardDataReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver); + } + + isValueType() { + return false; + } + +} + +class ModFarmTypeReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModFarmType", "String", "String", "String", "Nullable:1", "String", "Nullable:1", "String", "Nullable>:4", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.StringReader())); + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } + +} + +class ModLanguageReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModLanguage", "String", "String", "String", null, "Nullable:1", "String", null, null, null, null, "Nullable:1", "String", "String", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const booleanReader = new readers.BooleanReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const booleanReader = new readers.BooleanReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } + +} + +class ModWallpaperOrFlooringReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModWallpaperOrFlooring", "String", "String", null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const booleanReader = new readers.BooleanReader(); + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const booleanReader = new readers.BooleanReader(); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } + +} + +exports.BundleDataReader = BundleDataReader; +exports.BundleSetDataReader = BundleSetDataReader; +exports.CharacterResponseReader = CharacterResponseReader; +exports.ConcessionItemDataReader = ConcessionItemDataReader; +exports.ConcessionTasteReader = ConcessionTasteReader; +exports.FishPondDataReader = FishPondDataReader; +exports.FishPondRewardReader = FishPondRewardReader; +exports.HomeRenovationReader = HomeRenovationReader; +exports.ModFarmTypeReader = ModFarmTypeReader; +exports.ModLanguageReader = ModLanguageReader; +exports.ModWallpaperOrFlooringReader = ModWallpaperOrFlooringReader; +exports.MovieCharacterReactionReader = MovieCharacterReactionReader; +exports.MovieDataReader = MovieDataReader; +exports.MovieReactionReader = MovieReactionReader; +exports.MovieSceneReader = MovieSceneReader; +exports.RandomBundleDataReader = RandomBundleDataReader; +exports.RandomizedElementItemReader = RandomizedElementItemReader; +exports.RandomizedElementReader = RandomizedElementReader; +exports.RectGroupReader = RectGroupReader; +exports.RectReader = RectReader; +exports.RenovationValueReader = RenovationValueReader; +exports.SpecialOrderDataReader = SpecialOrderDataReader; +exports.SpecialOrderObjectiveDataReader = SpecialOrderObjectiveDataReader; +exports.SpecialOrderRewardDataReader = SpecialOrderRewardDataReader; +exports.SpecialResponsesReader = SpecialResponsesReader; +exports.TailorItemRecipeReader = TailorItemRecipeReader; diff --git a/src/plugins-stardewvalley/dist/index.js b/src/plugins-stardewvalley/dist/index.js new file mode 100644 index 0000000..ac9ee17 --- /dev/null +++ b/src/plugins-stardewvalley/dist/index.js @@ -0,0 +1,1399 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@xnb/readers')) : + typeof define === 'function' && define.amd ? define(['exports', '@xnb/readers'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {}, global.XNB)); +})(this, (function (exports, readers) { 'use strict'; + + class MovieSceneReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieScene", null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + + } + + class MovieDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieData", "Nullable", 'String', null, 'String', 'String', "Nullable>", 'List', 'String', "List", ...MovieSceneReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const movieSceneListReader = new readers.ListReader(new MovieSceneReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } + + } + + class CharacterResponseReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["CharacterResponse", "Nullable:1", "String", "Nullable:1", "String", "Nullable:1", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } + + } + + class SpecialResponsesReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialResponses", "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableCharacterResponseReader = new readers.NullableReader(new CharacterResponseReader()); + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new readers.NullableReader(new CharacterResponseReader()); + this.writeIndex(buffer, resolver); + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } + + } + + class MovieReactionReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieReaction", "String", "Nullable:1", "String", "Nullable>:2", "List", "String", "Nullable:25", ...SpecialResponsesReader.parseTypeList(), "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableSpecialResponsesReader = new readers.NullableReader(new SpecialResponsesReader()); + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableSpecialResponsesReader = new readers.NullableReader(new SpecialResponsesReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + + } + + class MovieCharacterReactionReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieCharacterReaction", "String", "Nullable>:34", "List", ...MovieReactionReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableReactionListReader = new readers.NullableReader(new readers.ListReader(new MovieReactionReader())); + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableReactionListReader = new readers.NullableReader(new readers.ListReader(new MovieReactionReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } + + } + + class ConcessionItemDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionItemData", null, 'String', 'String', 'String', null, 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } + + } + + class ConcessionTasteReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionTaste", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } + + } + + class FishPondRewardReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondReward': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondReward", null, null, null, null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const RequiredPopulation = int32Reader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } + + } + + class FishPondDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondData", "List", "String", null, "List", ...FishPondRewardReader.parseTypeList(), "Nullable>>:4", "Dictionary>", "Int32", "List", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringListDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.Int32Reader(), new readers.ListReader(new readers.StringReader()))); + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, resolver); + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new readers.ListReader(new readers.StringReader()); + const int32Reader = new readers.Int32Reader(); + const fishPondRewardListReader = new readers.ListReader(new FishPondRewardReader()); + const stringListDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.Int32Reader(), new readers.ListReader(new readers.StringReader()))); + this.writeIndex(buffer, resolver); + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, null); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } + + } + + class TailorItemRecipeReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["TailorItemRecipe", "Nullable>:2", "List", "String", "Nullable>:2", "List", "String", null, null, "Nullable>:2", "List", "String", "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new readers.NullableReader(new readers.ListReader(new readers.StringReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const booleanReader = new readers.BooleanReader(); + const int32Reader = new readers.Int32Reader(); + this.writeIndex(buffer, resolver); + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } + + } + + class RenovationValueReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RenovationValue", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Key = resolver.read(buffer); + const Value = resolver.read(buffer); + return { + Type, + Key, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + + } + + class RectReader extends readers.RectangleReader { + static isTypeOf(type) { + if (super.isTypeOf(type)) return true; + + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["Rect"]; + } + + static type() { + return "Reflective"; + } + + isValueType() { + return false; + } + + } + + class RectGroupReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RectGroup", "List", "Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Rects = resolver.read(buffer); + return { + Rects + }; + } + + write(buffer, content, resolver) { + const rectListReader = new readers.ListReader(new RectReader()); + this.writeIndex(buffer, resolver); + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } + + } + + class HomeRenovationReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["HomeRenovation", "String", "String", null, "List", ...RenovationValueReader.parseTypeList(), "List", ...RenovationValueReader.parseTypeList(), "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new readers.BooleanReader(); + const nullableRectGroupListReader = new readers.NullableReader(new readers.ListReader(new RectGroupReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const TextStrings = resolver.read(buffer); + const AnimationType = resolver.read(buffer); + const CheckForObstructions = booleanReader.read(buffer); + const Requirements = resolver.read(buffer); + const RenovateActions = resolver.read(buffer); + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); + const SpecialRect = nullableStringReader.read(buffer, resolver); + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new readers.BooleanReader(); + const stringReader = new readers.StringReader(); + const renovationValueListReader = new readers.ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new readers.NullableReader(new readers.ListReader(new RectGroupReader())); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } + + } + + class BundleDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleData", "String", null, "String", "String", "String", null, null, "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } + + } + + class BundleSetDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleSetData", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + return { + Bundles + }; + } + + write(buffer, content, resolver) { + const bundleListReader = new readers.ListReader(new BundleDataReader()); + this.writeIndex(buffer, resolver); + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + + } + + class RandomBundleDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomBundleData", "String", "String", "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(), "Nullable>:11", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableBundleSetListReader = new readers.NullableReader(new readers.ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new readers.NullableReader(new readers.ListReader(new BundleDataReader())); + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableBundleSetListReader = new readers.NullableReader(new readers.ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new readers.NullableReader(new readers.ListReader(new BundleDataReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + + } + + class RandomizedElementItemReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElementItem", "Nullable", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + return { + RequiredTags, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + + } + + class RandomizedElementReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElement", "String", "List", ...RandomizedElementItemReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Name = resolver.read(buffer); + const Values = resolver.read(buffer); + return { + Name, + Values + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const itemListReader = new readers.ListReader(new RandomizedElementItemReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); + } + + isValueType() { + return false; + } + + } + + class SpecialOrderObjectiveDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderObjectiveData", "String", "String", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const stringDictReader = new readers.DictionaryReader(new readers.StringReader(), new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + + } + + class SpecialOrderRewardDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderRewardData", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const stringDictReader = new readers.DictionaryReader(new readers.StringReader(), new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + + } + + class SpecialOrderDataReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderData", "String", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), "List", ...SpecialOrderRewardDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableRandomizedElemListReader = new readers.NullableReader(new readers.ListReader(new RandomizedElementReader())); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); + return { + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableRandomizedElemListReader = new readers.NullableReader(new readers.ListReader(new RandomizedElementReader())); + const objectiveListReader = new readers.ListReader(new SpecialOrderObjectiveDataReader()); + const rewardListReader = new readers.ListReader(new SpecialOrderRewardDataReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver); + } + + isValueType() { + return false; + } + + } + + class ModFarmTypeReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModFarmType", "String", "String", "String", "Nullable:1", "String", "Nullable:1", "String", "Nullable>:4", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.StringReader())); + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const nullableStringDictReader = new readers.NullableReader(new readers.DictionaryReader(new readers.StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } + + } + + class ModLanguageReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModLanguage", "String", "String", "String", null, "Nullable:1", "String", null, null, null, null, "Nullable:1", "String", "String", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const booleanReader = new readers.BooleanReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new readers.StringReader(); + const int32Reader = new readers.Int32Reader(); + const floatReader = new readers.SingleReader(); + const booleanReader = new readers.BooleanReader(); + const nullableStringReader = new readers.NullableReader(new readers.StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } + + } + + class ModWallpaperOrFlooringReader extends readers.BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModWallpaperOrFlooring", "String", "String", null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new readers.Int32Reader(); + const booleanReader = new readers.BooleanReader(); + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new readers.Int32Reader(); + const booleanReader = new readers.BooleanReader(); + const stringReader = new readers.StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } + + } + + exports.BundleDataReader = BundleDataReader; + exports.BundleSetDataReader = BundleSetDataReader; + exports.CharacterResponseReader = CharacterResponseReader; + exports.ConcessionItemDataReader = ConcessionItemDataReader; + exports.ConcessionTasteReader = ConcessionTasteReader; + exports.FishPondDataReader = FishPondDataReader; + exports.FishPondRewardReader = FishPondRewardReader; + exports.HomeRenovationReader = HomeRenovationReader; + exports.ModFarmTypeReader = ModFarmTypeReader; + exports.ModLanguageReader = ModLanguageReader; + exports.ModWallpaperOrFlooringReader = ModWallpaperOrFlooringReader; + exports.MovieCharacterReactionReader = MovieCharacterReactionReader; + exports.MovieDataReader = MovieDataReader; + exports.MovieReactionReader = MovieReactionReader; + exports.MovieSceneReader = MovieSceneReader; + exports.RandomBundleDataReader = RandomBundleDataReader; + exports.RandomizedElementItemReader = RandomizedElementItemReader; + exports.RandomizedElementReader = RandomizedElementReader; + exports.RectGroupReader = RectGroupReader; + exports.RectReader = RectReader; + exports.RenovationValueReader = RenovationValueReader; + exports.SpecialOrderDataReader = SpecialOrderDataReader; + exports.SpecialOrderObjectiveDataReader = SpecialOrderObjectiveDataReader; + exports.SpecialOrderRewardDataReader = SpecialOrderRewardDataReader; + exports.SpecialResponsesReader = SpecialResponsesReader; + exports.TailorItemRecipeReader = TailorItemRecipeReader; + + Object.defineProperty(exports, '__esModule', { value: true }); + +})); diff --git a/src/plugins-stardewvalley/dist/index.min.js b/src/plugins-stardewvalley/dist/index.min.js new file mode 100644 index 0000000..d1a388c --- /dev/null +++ b/src/plugins-stardewvalley/dist/index.min.js @@ -0,0 +1,9 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),u=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),u.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...w.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new w),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=u,e.FishPondDataReader=R,e.FishPondRewardReader=w,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=f,e.ModWallpaperOrFlooringReader=x,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/plugins-stardewvalley/dist/index.module.js b/src/plugins-stardewvalley/dist/index.module.js new file mode 100644 index 0000000..4eacda1 --- /dev/null +++ b/src/plugins-stardewvalley/dist/index.module.js @@ -0,0 +1,1366 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +import { BaseReader, BooleanReader, Int32Reader, NullableReader, StringReader, ListReader, SingleReader, DictionaryReader, RectangleReader } from '@xnb/readers'; + +class MovieSceneReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieScene", null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieData", "Nullable", 'String', null, 'String', 'String', "Nullable>", 'List', 'String', "List", ...MovieSceneReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const movieSceneListReader = new ListReader(new MovieSceneReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } + +} + +class CharacterResponseReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["CharacterResponse", "Nullable:1", "String", "Nullable:1", "String", "Nullable:1", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialResponsesReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialResponses", "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + this.writeIndex(buffer, resolver); + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieReaction", "String", "Nullable:1", "String", "Nullable>:2", "List", "String", "Nullable:25", ...SpecialResponsesReader.parseTypeList(), "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieCharacterReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieCharacterReaction", "String", "Nullable>:34", "List", ...MovieReactionReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionItemDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionItemData", null, 'String', 'String', 'String', null, 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionTasteReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionTaste", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } + +} + +class FishPondRewardReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondReward': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondReward", null, null, null, null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const RequiredPopulation = int32Reader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } + +} + +class FishPondDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondData", "List", "String", null, "List", ...FishPondRewardReader.parseTypeList(), "Nullable>>:4", "Dictionary>", "Int32", "List", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, resolver); + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new ListReader(new StringReader()); + const int32Reader = new Int32Reader(); + const fishPondRewardListReader = new ListReader(new FishPondRewardReader()); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + this.writeIndex(buffer, resolver); + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, null); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } + +} + +class TailorItemRecipeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["TailorItemRecipe", "Nullable>:2", "List", "String", "Nullable>:2", "List", "String", null, null, "Nullable>:2", "List", "String", "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + this.writeIndex(buffer, resolver); + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } + +} + +class RenovationValueReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RenovationValue", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Key = resolver.read(buffer); + const Value = resolver.read(buffer); + return { + Type, + Key, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RectReader extends RectangleReader { + static isTypeOf(type) { + if (super.isTypeOf(type)) return true; + + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["Rect"]; + } + + static type() { + return "Reflective"; + } + + isValueType() { + return false; + } + +} + +class RectGroupReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RectGroup", "List", "Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Rects = resolver.read(buffer); + return { + Rects + }; + } + + write(buffer, content, resolver) { + const rectListReader = new ListReader(new RectReader()); + this.writeIndex(buffer, resolver); + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } + +} + +class HomeRenovationReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["HomeRenovation", "String", "String", null, "List", ...RenovationValueReader.parseTypeList(), "List", ...RenovationValueReader.parseTypeList(), "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const TextStrings = resolver.read(buffer); + const AnimationType = resolver.read(buffer); + const CheckForObstructions = booleanReader.read(buffer); + const Requirements = resolver.read(buffer); + const RenovateActions = resolver.read(buffer); + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); + const SpecialRect = nullableStringReader.read(buffer, resolver); + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + const renovationValueListReader = new ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleData", "String", null, "String", "String", "String", null, null, "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleSetDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleSetData", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + return { + Bundles + }; + } + + write(buffer, content, resolver) { + const bundleListReader = new ListReader(new BundleDataReader()); + this.writeIndex(buffer, resolver); + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomBundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomBundleData", "String", "String", "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(), "Nullable>:11", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementItemReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElementItem", "Nullable", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + return { + RequiredTags, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElement", "String", "List", ...RandomizedElementItemReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Name = resolver.read(buffer); + const Values = resolver.read(buffer); + return { + Name, + Values + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const itemListReader = new ListReader(new RandomizedElementItemReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderObjectiveDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderObjectiveData", "String", "String", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderRewardDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderRewardData", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderData", "String", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), "List", ...SpecialOrderRewardDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); + return { + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const objectiveListReader = new ListReader(new SpecialOrderObjectiveDataReader()); + const rewardListReader = new ListReader(new SpecialOrderRewardDataReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver); + } + + isValueType() { + return false; + } + +} + +class ModFarmTypeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModFarmType", "String", "String", "String", "Nullable:1", "String", "Nullable:1", "String", "Nullable>:4", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } + +} + +class ModLanguageReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModLanguage", "String", "String", "String", null, "Nullable:1", "String", null, null, null, null, "Nullable:1", "String", "String", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } + +} + +class ModWallpaperOrFlooringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModWallpaperOrFlooring", "String", "String", null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } + +} + +export { BundleDataReader, BundleSetDataReader, CharacterResponseReader, ConcessionItemDataReader, ConcessionTasteReader, FishPondDataReader, FishPondRewardReader, HomeRenovationReader, ModFarmTypeReader, ModLanguageReader, ModWallpaperOrFlooringReader, MovieCharacterReactionReader, MovieDataReader, MovieReactionReader, MovieSceneReader, RandomBundleDataReader, RandomizedElementItemReader, RandomizedElementReader, RectGroupReader, RectReader, RenovationValueReader, SpecialOrderDataReader, SpecialOrderObjectiveDataReader, SpecialOrderRewardDataReader, SpecialResponsesReader, TailorItemRecipeReader }; diff --git a/src/plugins-stardewvalley/readers.js b/src/plugins-stardewvalley/readers.js index 5e0d0bc..f9aa0bc 100644 --- a/src/plugins-stardewvalley/readers.js +++ b/src/plugins-stardewvalley/readers.js @@ -38,6 +38,13 @@ import RandomizedElementItemReader from "./Readers/RandomizedElementItemReader.j import SpecialOrderObjectiveDataReader from "./Readers/SpecialOrderObjectiveDataReader.js"; import SpecialOrderRewardDataReader from "./Readers/SpecialOrderRewardDataReader.js" +// mod farm type data:1.5.5 +import ModFarmTypeReader from "./Readers/ModFarmTypeReader.js"; +// mod language data:1.5.5 +import ModLanguageReader from "./Readers/ModLanguageReader.js"; +// mod wallpaper or flooring data:1.5.5 +import ModWallpaperOrFlooringReader from "./Readers/ModWallpaperOrFlooringReader.js"; + export { MovieSceneReader, MovieDataReader, @@ -68,5 +75,9 @@ export { RandomizedElementReader, RandomizedElementItemReader, SpecialOrderObjectiveDataReader, - SpecialOrderRewardDataReader + SpecialOrderRewardDataReader, + + ModFarmTypeReader, + ModLanguageReader, + ModWallpaperOrFlooringReader }; \ No newline at end of file diff --git a/src/readers/dist/readers.cjs b/src/readers/dist/readers.cjs index 9cc6846..ab6d541 100644 --- a/src/readers/dist/readers.cjs +++ b/src/readers/dist/readers.cjs @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -12,8 +21,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -44,6 +52,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -118,6 +130,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -335,6 +351,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -473,6 +493,10 @@ class ListReader extends BaseReader { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -510,14 +534,14 @@ class NullableReader extends BaseReader { return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -534,6 +558,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -562,7 +591,6 @@ class ReflectiveReader extends BaseReader { } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -574,6 +602,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2515,8 +2547,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/src/readers/dist/readers.es5.js b/src/readers/dist/readers.es5.js index 67306d0..31ff9ad 100644 --- a/src/readers/dist/readers.es5.js +++ b/src/readers/dist/readers.es5.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : @@ -1485,6 +1494,11 @@ value: function toString() { return this.type; } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return this.constructor.parseTypeList(); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -1498,8 +1512,7 @@ }, { key: "parseTypeList", value: function parseTypeList() { - var subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type()].concat(subtype); + return [this.type()]; } }, { key: "type", @@ -1600,6 +1613,11 @@ get: function get() { return "Array<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -1940,6 +1958,11 @@ get: function get() { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.key.parseTypeList(), this.value.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2148,6 +2171,11 @@ get: function get() { return "List<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [this.type].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2202,7 +2230,7 @@ return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } }, { key: "write", @@ -2211,7 +2239,7 @@ var resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; new BooleanReader(); - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -2229,6 +2257,12 @@ get: function get() { return "Nullable<".concat(this.reader.type, ">"); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + var inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length)].concat(inBlock); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -2274,7 +2308,6 @@ }, { key: "write", value: function write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } }, { @@ -2287,6 +2320,11 @@ get: function get() { return "".concat(this.reader.type); } + }, { + key: "parseTypeList", + value: function parseTypeList() { + return [].concat(this.reader.parseTypeList()); + } }], [{ key: "isTypeOf", value: function isTypeOf(type) { @@ -4052,6 +4090,27 @@ } } + /** @license + ----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + -------------------------------------------------------------------------- */ var DXT1_COMPRESSED_BYTES = 8; var DXT5_COMPRESSED_BYTES = 16; var COLORS = 4; @@ -4442,8 +4501,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } }, { key: "isValueType", diff --git a/src/readers/dist/readers.es5.min.js b/src/readers/dist/readers.es5.min.js index f5109c5..2e7c348 100644 --- a/src/readers/dist/readers.es5.min.js +++ b/src/readers/dist/readers.es5.min.js @@ -1,23 +1,31 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,n=function(t){try{return!!t()}catch(t){return!0}},i=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=function(t){return t&&t.Math==Math&&t},o=u("object"==typeof globalThis&&globalThis)||u("object"==typeof window&&window)||u("object"==typeof self&&self)||u("object"==typeof e&&e)||function(){return this}()||Function("return this")(),a=function(t){return"function"==typeof t},s=a,c=function(t){return"object"==typeof t?null!==t:s(t)},l=!n((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),f=l,h=Function.prototype,v=h.bind,y=h.call,p=f&&v.bind(y,y),d=f?function(t){return t&&p(t)}:function(t){return t&&function(){return y.apply(t,arguments)}},w=o.TypeError,m=function(t){if(null==t)throw w("Can't call method on "+t);return t},g=o.Object,k=function(t){return g(m(t))},b=k,_=d({}.hasOwnProperty),x=Object.hasOwn||function(t,e){return _(b(t),e)},S={exports:{}},T=o,O=Object.defineProperty,A=function(t,e){try{O(T,t,{value:e,configurable:!0,writable:!0})}catch(r){T[t]=e}return e},M=A,R="__core-js_shared__",z=o[R]||M(R,{}),V=z;(S.exports=function(t,e){return V[t]||(V[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.22.4",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.22.4/LICENSE",source:"https://github.com/zloirock/core-js"});var j,I,E=d,C=0,P=Math.random(),F=E(1..toString),B=function(t){return"Symbol("+(void 0===t?"":t)+")_"+F(++C+P,36)},D=o,U=a,X=function(t){return U(t)?t:void 0},L=function(t,e){return arguments.length<2?X(D[t]):D[t]&&D[t][e]},W=o,N=L("navigator","userAgent")||"",G=W.process,Y=W.Deno,q=G&&G.versions||Y&&Y.version,K=q&&q.v8;K&&(I=(j=K.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=o,tt=S.exports,et=x,rt=B,nt=$,it=H,ut=tt("wks"),ot=Q.Symbol,at=ot&&ot.for,st=it?ot:ot&&ot.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(ot,t)?ut[t]=ot[t]:ut[t]=it&&at?at(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,vt=ht({}.toString),yt=ht("".slice),pt=function(t){return yt(vt(t),8,-1)},dt=o,wt=ft,mt=a,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},St=o.String,Tt=function(t){try{return St(t)}catch(t){return"Object"}},Ot={},At=c,Mt=o.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=o,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Bt=l,Dt=Function.prototype.call,Ut=Bt?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},Xt=d({}.isPrototypeOf),Lt=L,Wt=a,Nt=Xt,Gt=H,Yt=o.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Lt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=a,Jt=Tt,Zt=o.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=a,ee=c,re=o.TypeError,ne=Ut,ie=c,ue=qt,oe=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},ae=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=o.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=oe(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),ae(t,e)},he=qt,ve=i,ye=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=o.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ve?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ye)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Se=Ot,Te=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Se.f(t,e,Te(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=a,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,Be,De,Ue=Ce.inspectSource,Xe=a,Le=Ue,We=o.WeakMap,Ne=Xe(We)&&/native code/.test(Le(We)),Ge=S.exports,Ye=B,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=o,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,or=Ze.WeakMap;if(Je||er.state){var ar=er.state||(er.state=new or),sr=$e(ar.get),cr=$e(ar.has),lr=$e(ar.set);Fe=function(t,e){if(cr(ar,t))throw new ur(ir);return e.facade=t,lr(ar,t,e),e},Be=function(t){return sr(ar,t)||{}},De=function(t){return cr(ar,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},Be=function(t){return tr(t,fr)?t[fr]:{}},De=function(t){return tr(t,fr)}}var hr={set:Fe,get:Be,has:De,enforce:function(t){return De(t)?Be(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=Be(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},vr=n,yr=a,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!vr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return yr(this)&&kr(this).source||mr(this)}),"toString");var Sr,Tr,Or,Ar=o,Mr=a,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=o,Er=x,Cr=a,Pr=k,Fr=jr,Br=Ke("IE_PROTO"),Dr=Ir.Object,Ur=Dr.prototype,Xr=Fr?Dr.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Br))return e[Br];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Dr?Ur:null},Lr=o,Wr=a,Nr=Lr.String,Gr=Lr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=o,Qr=a,tn=c,en=x,rn=xt,nn=Tt,un=Oe,on=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,o=!!n&&!!n.noTargetGet,a=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,a,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!o&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},an=Ot.f,sn=Xt,cn=Xr,ln=Jr,fn=ct,hn=B,vn=Hr.Int8Array,yn=vn&&vn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=vn&&cn(vn),mn=yn&&cn(yn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Sn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Tn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Sr in On)(Or=(Tr=Hr[Sr])&&Tr.prototype)?un(Or,xn,Tr):Sn=!1;for(Sr in An)(Or=(Tr=Hr[Sr])&&Tr.prototype)&&un(Or,xn,Tr);if((!Sn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr],wn);if((!Sn||!mn||mn===gn)&&(mn=wn.prototype,Sn))for(Sr in On)Hr[Sr]&&ln(Hr[Sr].prototype,mn);if(Sn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Sr in Tn=!0,an(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Sr]&&un(Hr[Sr],_n,Sr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Sn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Tn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||on(mn,t,r?e:Sn&&yn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return on(wn,t,r?e:Sn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||on(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=o.Object,Fn=In("".split),Bn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Dn=Math.ceil,Un=Math.floor,Xn=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Dn)(e)},Ln=Math.min,Wn=function(t){return t>0?Ln(Xn(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=a,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=L("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,oi=o,ai=Gn,si=ui,ci=c,li=ct("species"),fi=oi.Array,hi=function(t){var e;return ai(t)&&(e=t.constructor,(si(e)&&(e===fi||ai(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},vi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},yi=Bn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,o=7==t,a=5==t||u;return function(s,c,l,f){for(var h,v,y=pi(s),p=yi(y),d=vi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||o?g(s,0):void 0;w>m;m++)if((a||m in p)&&(v=d(h=p[m],m,y),t))if(e)k[m]=v;else if(v)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=Tt,xi=o.TypeError,Si=Ft,Ti=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Si(t).constructor;return void 0===n||null==(r=Si(n)[Oi])?e:Ti(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Bi=Ci(Fi.toString),Di=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Di.exec);function Xi(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Li(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:[];return[this.type()].concat(t)}},{key:"type",value:function(){return this.name.slice(0,-6)}}]),t}(),ru=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readUInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}}]),r}(eu),nu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new fu,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new fu,null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),o=0;o=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Su(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Tu(t)}for(var v=0;v0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,o=Bu(t),a=Bu(e);if(o<=a)u=r.slice();else{var s=[a,o];o=s[0],a=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Du(o,a,u,n,i)}function Xu(t,e,r,n,i){var u,o=Bu(t),a=Bu(e);if(o=128||!i)){var h=this._remap[a],v=(e[4*o+3]+1)/256;this._weights[h]+=u?v:1,this._remap[o]=h;break}}else this._remap[o]=-1}for(var y=0;y=n?t:(n=o,u)}),0);return i+=n,u}));if(ia&&(u=r[c],a=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,o=i.weights;return n.principle=ju(u,o),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),o=u.splatW,a=Vu.multiplyAdd(r,i,n);return{ax:u,aa:o,bx:a,bb:a.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),o=new Vu(2/3,2/3,2/3,4/9),a=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,o,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,o,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(a,Vu.add(r,n)).splatW}}),(function(r,n,i){return Xu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),o=r.computeOptimalPoints(u);return o.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),o=0;o15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=o)):(oi&&(i=o))}}n>i&&(n=i);i-n>8*l&255;n[o]=f,o++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function to(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),o=Hu(i);return[u,o,Qu(u,o,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,o,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),o=0;o<16;o++)for(var a=0;a<4;a++)t[4*o+a]=i[u[o]][a]}function eo(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ro(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function no(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,o=void 0===u?0:u,a=r.width,s=void 0===a?0:a,c=r.height,l=void 0===c?0:c,f=0;eo((function(r,n){var u=i+r,a=o+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),o=new Uint8Array(16),a=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var v=l>>3*h&7;o[a]=v,a++}}for(var y=0;y<16;++y)t[4*y+3]=u[o[y]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function oo(t,e,r,n,i){var u=0!=(1&(i=ro(i)))?8:16,o=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,o=e.width,a=void 0===o?0:o,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return eo((function(e,r){var i=n+e,o=u+r;if(i1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(4==n)s=fo(s,i,u,ao);else if(5==n)s=fo(s,i,u,so);else if(6==n)s=fo(s,i,u,co);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),po=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),wo=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),o=r.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));var a=r.read(t),s=t.read(a);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c0&&j[0]<4?1:+(j[0]+j[1])),!I&&N&&(!(j=N.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=N.match(/Chrome\/(\d+)/))&&(I=+j[1]);var J=I,Z=n,$=!!Object.getOwnPropertySymbols&&!Z((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&J&&J<41})),H=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Q=a,tt=T.exports,et=x,rt=B,nt=$,it=H,ut=tt("wks"),at=Q.Symbol,ot=at&&at.for,st=it?at:at&&at.withoutSetter||rt,ct=function(t){if(!et(ut,t)||!nt&&"string"!=typeof ut[t]){var e="Symbol."+t;nt&&et(at,t)?ut[t]=at[t]:ut[t]=it&&ot?ot(e):st(e)}return ut[t]},lt={};lt[ct("toStringTag")]="z";var ft="[object z]"===String(lt),ht=d,yt=ht({}.toString),vt=ht("".slice),pt=function(t){return vt(yt(t),8,-1)},dt=a,wt=ft,mt=o,gt=pt,kt=ct("toStringTag"),bt=dt.Object,_t="Arguments"==gt(function(){return arguments}()),xt=wt?gt:function(t){var e,r,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,e){try{return t[e]}catch(t){}}(e=bt(t),kt))?r:_t?gt(e):"Object"==(n=gt(e))&&mt(e.callee)?"Arguments":n},Tt=a.String,St=function(t){try{return Tt(t)}catch(t){return"Object"}},Ot={},At=c,Mt=a.document,Rt=At(Mt)&&At(Mt.createElement),zt=function(t){return Rt?Mt.createElement(t):{}},Vt=!i&&!n((function(){return 7!=Object.defineProperty(zt("div"),"a",{get:function(){return 7}}).a})),jt=i&&n((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),It=a,Et=c,Ct=It.String,Pt=It.TypeError,Ft=function(t){if(Et(t))return t;throw Pt(Ct(t)+" is not an object")},Bt=l,Dt=Function.prototype.call,Ut=Bt?Dt.bind(Dt):function(){return Dt.apply(Dt,arguments)},Lt=d({}.isPrototypeOf),Xt=X,Wt=o,Nt=Lt,Gt=H,Yt=a.Object,qt=Gt?function(t){return"symbol"==typeof t}:function(t){var e=Xt("Symbol");return Wt(e)&&Nt(e.prototype,Yt(t))},Kt=o,Jt=St,Zt=a.TypeError,$t=function(t){if(Kt(t))return t;throw Zt(Jt(t)+" is not a function")},Ht=$t,Qt=Ut,te=o,ee=c,re=a.TypeError,ne=Ut,ie=c,ue=qt,ae=function(t,e){var r=t[e];return null==r?void 0:Ht(r)},oe=function(t,e){var r,n;if("string"===e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;if(te(r=t.valueOf)&&!ee(n=Qt(r,t)))return n;if("string"!==e&&te(r=t.toString)&&!ee(n=Qt(r,t)))return n;throw re("Can't convert object to primitive value")},se=ct,ce=a.TypeError,le=se("toPrimitive"),fe=function(t,e){if(!ie(t)||ue(t))return t;var r,n=ae(t,le);if(n){if(void 0===e&&(e="default"),r=ne(n,t,e),!ie(r)||ue(r))return r;throw ce("Can't convert object to primitive value")}return void 0===e&&(e="number"),oe(t,e)},he=qt,ye=i,ve=Vt,pe=jt,de=Ft,we=function(t){var e=fe(t,"string");return he(e)?e:e+""},me=a.TypeError,ge=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be="enumerable",_e="configurable",xe="writable";Ot.f=ye?pe?function(t,e,r){if(de(t),e=we(e),de(r),"function"==typeof t&&"prototype"===e&&"value"in r&&xe in r&&!r.writable){var n=ke(t,e);n&&n.writable&&(t[e]=r.value,r={configurable:_e in r?r.configurable:n.configurable,enumerable:be in r?r.enumerable:n.enumerable,writable:!1})}return ge(t,e,r)}:ge:function(t,e,r){if(de(t),e=we(e),de(r),ve)try{return ge(t,e,r)}catch(t){}if("get"in r||"set"in r)throw me("Accessors not supported");return"value"in r&&(t[e]=r.value),t};var Te=Ot,Se=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},Oe=i?function(t,e,r){return Te.f(t,e,Se(1,r))}:function(t,e,r){return t[e]=r,t},Ae={exports:{}},Me=i,Re=x,ze=Function.prototype,Ve=Me&&Object.getOwnPropertyDescriptor,je=Re(ze,"name"),Ie={EXISTS:je,PROPER:je&&"something"===function(){}.name,CONFIGURABLE:je&&(!Me||Me&&Ve(ze,"name").configurable)},Ee=o,Ce=z,Pe=d(Function.toString);Ee(Ce.inspectSource)||(Ce.inspectSource=function(t){return Pe(t)});var Fe,Be,De,Ue=Ce.inspectSource,Le=o,Xe=Ue,We=a.WeakMap,Ne=Le(We)&&/native code/.test(Xe(We)),Ge=T.exports,Ye=B,qe=Ge("keys"),Ke=function(t){return qe[t]||(qe[t]=Ye(t))},Je=Ne,Ze=a,$e=d,He=c,Qe=Oe,tr=x,er=z,rr=Ke,nr={},ir="Object already initialized",ur=Ze.TypeError,ar=Ze.WeakMap;if(Je||er.state){var or=er.state||(er.state=new ar),sr=$e(or.get),cr=$e(or.has),lr=$e(or.set);Fe=function(t,e){if(cr(or,t))throw new ur(ir);return e.facade=t,lr(or,t,e),e},Be=function(t){return sr(or,t)||{}},De=function(t){return cr(or,t)}}else{var fr=rr("state");nr[fr]=!0,Fe=function(t,e){if(tr(t,fr))throw new ur(ir);return e.facade=t,Qe(t,fr,e),e},Be=function(t){return tr(t,fr)?t[fr]:{}},De=function(t){return tr(t,fr)}}var hr={set:Fe,get:Be,has:De,enforce:function(t){return De(t)?Be(t):Fe(t,{})},getterFor:function(t){return function(e){var r;if(!He(e)||(r=Be(e)).type!==t)throw ur("Incompatible receiver, "+t+" required");return r}}},yr=n,vr=o,pr=x,dr=Ot.f,wr=Ie.CONFIGURABLE,mr=Ue,gr=hr.enforce,kr=hr.get,br=!yr((function(){return 8!==dr((function(){}),"length",{value:8}).length})),_r=String(String).split("String"),xr=Ae.exports=function(t,e,r){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!pr(t,"name")||wr&&t.name!==e)&&dr(t,"name",{value:e,configurable:!0}),br&&r&&pr(r,"arity")&&t.length!==r.arity&&dr(t,"length",{value:r.arity});var n=gr(t);return pr(n,"source")||(n.source=_r.join("string"==typeof e?e:"")),t};Function.prototype.toString=xr((function(){return vr(this)&&kr(this).source||mr(this)}),"toString");var Tr,Sr,Or,Ar=a,Mr=o,Rr=Oe,zr=Ae.exports,Vr=A,jr=!n((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})),Ir=a,Er=x,Cr=o,Pr=k,Fr=jr,Br=Ke("IE_PROTO"),Dr=Ir.Object,Ur=Dr.prototype,Lr=Fr?Dr.getPrototypeOf:function(t){var e=Pr(t);if(Er(e,Br))return e[Br];var r=e.constructor;return Cr(r)&&e instanceof r?r.prototype:e instanceof Dr?Ur:null},Xr=a,Wr=o,Nr=Xr.String,Gr=Xr.TypeError,Yr=d,qr=Ft,Kr=function(t){if("object"==typeof t||Wr(t))return t;throw Gr("Can't set "+Nr(t)+" as a prototype")},Jr=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,r={};try{(t=Yr(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(r,[]),e=r instanceof Array}catch(t){}return function(r,n){return qr(r),Kr(n),e?t(r,n):r.__proto__=n,r}}():void 0),Zr=r,$r=i,Hr=a,Qr=o,tn=c,en=x,rn=xt,nn=St,un=Oe,an=function(t,e,r,n){var i=!!n&&!!n.unsafe,u=!!n&&!!n.enumerable,a=!!n&&!!n.noTargetGet,o=n&&void 0!==n.name?n.name:e;return Mr(r)&&zr(r,o,n),t===Ar?(u?t[e]=r:Vr(e,r),t):(i?!a&&t[e]&&(u=!0):delete t[e],u?t[e]=r:Rr(t,e,r),t)},on=Ot.f,sn=Lt,cn=Lr,ln=Jr,fn=ct,hn=B,yn=Hr.Int8Array,vn=yn&&yn.prototype,pn=Hr.Uint8ClampedArray,dn=pn&&pn.prototype,wn=yn&&cn(yn),mn=vn&&cn(vn),gn=Object.prototype,kn=Hr.TypeError,bn=fn("toStringTag"),_n=hn("TYPED_ARRAY_TAG"),xn=hn("TYPED_ARRAY_CONSTRUCTOR"),Tn=Zr&&!!ln&&"Opera"!==rn(Hr.opera),Sn=!1,On={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},An={BigInt64Array:8,BigUint64Array:8},Mn=function(t){if(!tn(t))return!1;var e=rn(t);return en(On,e)||en(An,e)};for(Tr in On)(Or=(Sr=Hr[Tr])&&Sr.prototype)?un(Or,xn,Sr):Tn=!1;for(Tr in An)(Or=(Sr=Hr[Tr])&&Sr.prototype)&&un(Or,xn,Sr);if((!Tn||!Qr(wn)||wn===Function.prototype)&&(wn=function(){throw kn("Incorrect invocation")},Tn))for(Tr in On)Hr[Tr]&&ln(Hr[Tr],wn);if((!Tn||!mn||mn===gn)&&(mn=wn.prototype,Tn))for(Tr in On)Hr[Tr]&&ln(Hr[Tr].prototype,mn);if(Tn&&cn(dn)!==mn&&ln(dn,mn),$r&&!en(mn,bn))for(Tr in Sn=!0,on(mn,bn,{get:function(){return tn(this)?this[_n]:void 0}}),On)Hr[Tr]&&un(Hr[Tr],_n,Tr);var Rn={NATIVE_ARRAY_BUFFER_VIEWS:Tn,TYPED_ARRAY_CONSTRUCTOR:xn,TYPED_ARRAY_TAG:Sn&&_n,aTypedArray:function(t){if(Mn(t))return t;throw kn("Target is not a typed array")},aTypedArrayConstructor:function(t){if(Qr(t)&&(!ln||sn(wn,t)))return t;throw kn(nn(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,r,n){if($r){if(r)for(var i in On){var u=Hr[i];if(u&&en(u.prototype,t))try{delete u.prototype[t]}catch(r){try{u.prototype[t]=e}catch(t){}}}mn[t]&&!r||an(mn,t,r?e:Tn&&vn[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,r){var n,i;if($r){if(ln){if(r)for(n in On)if((i=Hr[n])&&en(i,t))try{delete i[t]}catch(t){}if(wn[t]&&!r)return;try{return an(wn,t,r?e:Tn&&wn[t]||e)}catch(t){}}for(n in On)!(i=Hr[n])||i[t]&&!r||an(i,t,e)}},isView:function(t){if(!tn(t))return!1;var e=rn(t);return"DataView"===e||en(On,e)||en(An,e)},isTypedArray:Mn,TypedArray:wn,TypedArrayPrototype:mn},zn=$t,Vn=l,jn=d(d.bind),In=d,En=n,Cn=pt,Pn=a.Object,Fn=In("".split),Bn=En((function(){return!Pn("z").propertyIsEnumerable(0)}))?function(t){return"String"==Cn(t)?Fn(t,""):Pn(t)}:Pn,Dn=Math.ceil,Un=Math.floor,Ln=function(t){var e=+t;return e!=e||0===e?0:(e>0?Un:Dn)(e)},Xn=Math.min,Wn=function(t){return t>0?Xn(Ln(t),9007199254740991):0},Nn=pt,Gn=Array.isArray||function(t){return"Array"==Nn(t)},Yn=d,qn=n,Kn=o,Jn=xt,Zn=Ue,$n=function(){},Hn=[],Qn=X("Reflect","construct"),ti=/^\s*(?:class|function)\b/,ei=Yn(ti.exec),ri=!ti.exec($n),ni=function(t){if(!Kn(t))return!1;try{return Qn($n,Hn,t),!0}catch(t){return!1}},ii=function(t){if(!Kn(t))return!1;switch(Jn(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ri||!!ei(ti,Zn(t))}catch(t){return!0}};ii.sham=!0;var ui=!Qn||qn((function(){var t;return ni(ni.call)||!ni(Object)||!ni((function(){t=!0}))||t}))?ii:ni,ai=a,oi=Gn,si=ui,ci=c,li=ct("species"),fi=ai.Array,hi=function(t){var e;return oi(t)&&(e=t.constructor,(si(e)&&(e===fi||oi(e.prototype))||ci(e)&&null===(e=e[li]))&&(e=void 0)),void 0===e?fi:e},yi=function(t,e){return zn(t),void 0===e?t:Vn?jn(t,e):function(){return t.apply(e,arguments)}},vi=Bn,pi=k,di=function(t){return Wn(t.length)},wi=function(t,e){return new(hi(t))(0===e?0:e)},mi=d([].push),gi=function(t){var e=1==t,r=2==t,n=3==t,i=4==t,u=6==t,a=7==t,o=5==t||u;return function(s,c,l,f){for(var h,y,v=pi(s),p=vi(v),d=yi(c,l),w=di(p),m=0,g=f||wi,k=e?g(s,w):r||a?g(s,0):void 0;w>m;m++)if((o||m in p)&&(y=d(h=p[m],m,v),t))if(e)k[m]=y;else if(y)switch(t){case 3:return!0;case 5:return h;case 6:return m;case 2:mi(k,h)}else switch(t){case 4:return!1;case 7:mi(k,h)}return u?-1:n||i?i:k}},ki={forEach:gi(0),map:gi(1),filter:gi(2),some:gi(3),every:gi(4),find:gi(5),findIndex:gi(6),filterReject:gi(7)},bi=ui,_i=St,xi=a.TypeError,Ti=Ft,Si=function(t){if(bi(t))return t;throw xi(_i(t)+" is not a constructor")},Oi=ct("species"),Ai=function(t,e){var r,n=Ti(t).constructor;return void 0===n||null==(r=Ti(n)[Oi])?e:Si(r)},Mi=Rn.TYPED_ARRAY_CONSTRUCTOR,Ri=Rn.aTypedArrayConstructor,zi=ki.map,Vi=function(t){return Ri(Ai(t,t[Mi]))},ji=Rn.aTypedArray;(0,Rn.exportTypedArrayMethod)("map",(function(t){return zi(ji(this),t,arguments.length>1?arguments[1]:void 0,(function(t,e){return new(Vi(t))(e)}))}));var Ii=i,Ei=Ie.EXISTS,Ci=d,Pi=Ot.f,Fi=Function.prototype,Bi=Ci(Fi.toString),Di=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Ui=Ci(Di.exec);function Li(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Xi(t){for(var e=1;e")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ArrayReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu);function iu(t,e){if(!t||"object"!==Wi(t))throw new Error("Invalid Data!");for(var r=[],n=t.length,i=0;i>(t>>3&30)&3)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}}]),r}(eu),yu=function(t){Ki(r,t);var e=tu(r);function r(t,n){var i;if(Ni(this,r),null==t||null==n)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");return(i=e.call(this)).key=t,i.value=n,i}return Yi(r,[{key:"read",value:function(t,e){for(var r={},n=(new ru).read(t),i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.key.parseTypeList(),this.value.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),vu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readDouble()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}}]),r}(eu),pu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new ru).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new ru).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}}]),r}(eu),du=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readInt32()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}}]),r}(eu),wu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){for(var r=(new ru).read(t),n=[],i=0;i")}},{key:"parseTypeList",value:function(){return[this.type].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),mu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=new fu,n=t.peekByte(1);return n?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;new fu,null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"Nullable<".concat(this.reader.type,">")}},{key:"parseTypeList",value:function(){var t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length)].concat(t)}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),gu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;return Ni(this,r),(n=e.call(this)).reader=t,n}return Yi(r,[{key:"read",value:function(t,e){return this.reader.read(t,e)}},{key:"write",value:function(t,e,r){this.reader.write(t,e,this.reader.isValueType()?null:r)}},{key:"isValueType",value:function(){return!1}},{key:"type",get:function(){return"".concat(this.reader.type)}},{key:"parseTypeList",value:function(){return[].concat(this.reader.parseTypeList())}}],[{key:"isTypeOf",value:function(t){return"Microsoft.Xna.Framework.Content.ReflectiveReader"===t}},{key:"hasSubType",value:function(){return!0}}]),r}(eu),ku=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=new du;n.write(t,e.x,null),n.write(t,e.y,null),n.write(t,e.width,null),n.write(t,e.height,null)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}}]),r}(eu),bu=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){return t.readSingle()}},{key:"write",value:function(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}],[{key:"isTypeOf",value:function(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}}]),r}(eu),_u=256;function xu(t,e,r,n){for(var i=Array(n),u=0;u1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,n=Array(r),i=Math.abs(e/r),u=Array(r),a=0;a=Math.abs(i);){var l=c[0][0],f=c[0][1],h=xu(l,f,Tu(t[l][l],t[f][f],t[l][f]),r);t=Ou(h,t),u=Au(u,h),c=Su(t)}for(var y=0;y0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;Ni(this,t),this._values=[e,r,n]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"colorInt",get:function(){return this._values.map((function(t){var e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}},{key:"clone",value:function(){return new t(this.x,this.y,this.z)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}},{key:"toVec4",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new Vu(this.x,this.y,this.z,t)}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:e(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e;Ni(this,t),this._values=[e,r,n,i]}return Yi(t,[{key:"x",get:function(){return this._values[0]},set:function(t){this._values[0]=t}},{key:"y",get:function(){return this._values[1]},set:function(t){this._values[1]=t}},{key:"z",get:function(){return this._values[2]},set:function(t){this._values[2]=t}},{key:"w",get:function(){return this._values[3]},set:function(t){this._values[3]=t}},{key:"length",get:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}},{key:"lengthSq",get:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}},{key:"normalized",get:function(){return 0===this.length?null:t.multScalar(this,1/this.length)}},{key:"xyz",get:function(){return new zu(this.x,this.y,this.z)}},{key:"splatX",get:function(){return new t(this.x)}},{key:"splatY",get:function(){return new t(this.y)}},{key:"splatZ",get:function(){return new t(this.z)}},{key:"splatW",get:function(){return new t(this.w)}},{key:"clone",value:function(){return new t(this.x,this.y,this.z,this.w)}},{key:"set",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=n,this}},{key:"toVec3",value:function(){return this.xyz}},{key:"addVector",value:function(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}},{key:"addScaledVector",value:function(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}},{key:"subVector",value:function(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}},{key:"mult",value:function(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}},{key:"multVector",value:function(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}},{key:"reciprocal",value:function(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}},{key:"clamp",value:function(t,e){var r=function(r){return t>r?t:et?0:1>8,n[i+2]=255&e,n[i+3]=e>>8;for(var u=0;u<4;u++)n[i+4+u]=r[4*u+0]|r[4*u+1]<<2|r[4*u+2]<<4|r[4*u+3]<<6}function Uu(t,e,r,n,i){var u,a=Bu(t),o=Bu(e);if(a<=o)u=r.slice();else{var s=[o,a];a=s[0],o=s[1],u=r.map((function(t){return 0===t?1:1===t?0:t}))}Du(a,o,u,n,i)}function Lu(t,e,r,n,i){var u,a=Bu(t),o=Bu(e);if(a=128||!i)){var h=this._remap[o],y=(e[4*a+3]+1)/256;this._weights[h]+=u?y:1,this._remap[a]=h;break}}else this._remap[a]=-1}for(var v=0;v=n?t:(n=a,u)}),0);return i+=n,u}));if(io&&(u=r[c],o=l)}this.start=i.clampGrid().clone(),this.end=u.clampGrid().clone()}}}]),r}(Wu),Yu=function(t){Ki(r,t);var e=tu(r);function r(t){var n;Ni(this,r);(n=e.call(this,t)).iterationCount=t.flags&_u?8:1,n.bestError=1/0,n.metric=new Vu(1),0!=(32&n.flags)&&n.metric.set(.2126,.7152,.0722,0);var i=n.colors,u=i.points,a=i.weights;return n.principle=ju(u,a),n.order=new Uint8Array(128),n.pointsWeights=[],n.xSum_wSum=new Vu(0),n}return Yi(r,[{key:"constructOrdering",value:function(t,e){var r=this.makeOrder(t);return this.copyOrderToThisOrder(r,e),!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}},{key:"compress3",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[2],n=t[3],i=new Vu(.5,.5,.5,1/4),u=Vu.multiplyAdd(r,i,e),a=u.splatW,o=Vu.multiplyAdd(r,i,n);return{ax:u,aa:a,bx:o,bb:o.splatW,ab:Vu.multVector(r,i).splatW}}),(function(r,n,i){return Uu(r,n,i,t,e)}),2)}},{key:"compress4",value:function(t,e){this.compressBase((function(t){var e=t[0],r=t[1],n=t[2],i=t[3],u=new Vu(1/3,1/3,1/3,1/9),a=new Vu(2/3,2/3,2/3,4/9),o=new Vu(2/9),s=Vu.multiplyAdd(n,u,Vu.multiplyAdd(r,a,e)),c=s.splatW,l=Vu.multiplyAdd(r,u,Vu.multiplyAdd(n,a,i));return{ax:s,aa:c,bx:l,bb:l.splatW,ab:Vu.multVector(o,Vu.add(r,n)).splatW}}),(function(r,n,i){return Lu(r,n,i,t,e)}),3)}},{key:"compressBase",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);var i={start:new Vu(0),end:new Vu(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===n&&(i.bestK=0);for(var u=function(e,n){var u=t(e),a=r.computeOptimalPoints(u);return a.error2&&void 0!==arguments[2]?arguments[2]:2,n=this.colors.count,i=function(e,n,i){var u={bestI:e,bestJ:2===r?i:n,iteration:t};return 3===r&&(u.bestK=i),u},u=new Vu(0),a=0;a15?15:e}function Ku(t,e,r,n){var i=Ju(t,e,5),u=Ju(t,e,7);i.error<=u.error?function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:t<=5?7-t:t})),e,r)}else $u(n,i,u,e,r)}(i,r,n):function(t,e,r){var n=t.min,i=t.max,u=t.indices;if(n>i){$u(i,n,u.map((function(t){return 0===t?1:1===t?0:9-t})),e,r)}else $u(n,i,u,e,r)}(u,r,n)}function Ju(t,e,r){var n=function(t,e,r){for(var n=255,i=0,u=0;u<16;u++){if(0!=(e&1<i&&(i=a)):(ai&&(i=a))}}n>i&&(n=i);i-n>8*l&255;n[a]=f,a++}}}function Hu(t){var e=t>>11&31,r=t>>5&63,n=31&t;return[e<<3|e>>2,r<<2|r>>4,n<<3|n>>2,255]}function Qu(t,e,r){var n=t.map((function(t,n){return Math.floor(t*(1-r)+e[n]*r)}));return n[3]=255,n}function ta(t,e,r,n){for(var i=function(t,e,r){var n=t[e]|t[e+1]<<8,i=t[e+2]|t[e+3]<<8,u=Hu(n),a=Hu(i);return[u,a,Qu(u,a,r&&n<=i?.5:1/3),r&&n<=i?[0,0,0,0]:Qu(u,a,2/3)]}(e,r,n),u=function(t,e){for(var r=e+4,n=new Uint8Array(16),i=0;i<4;i++){var u=t[r+i];n[4*i+0]=3&u,n[4*i+1]=u>>2&3,n[4*i+2]=u>>4&3,n[4*i+3]=u>>6&3}return n}(e,r),a=0;a<16;a++)for(var o=0;o<4;o++)t[4*a+o]=i[u[a]][o]}function ea(t){for(var e=0;e<4;e++)for(var r=0;r<4;r++)t(r,e)}function ra(t){var e=7&t,r=280&t,n=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=_u&&(r=8),64!=n&&(n=32),e|r|n|128&t}function na(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.x,i=void 0===n?0:n,u=r.y,a=void 0===u?0:u,o=r.width,s=void 0===o?0:o,c=r.height,l=void 0===c?0:c,f=0;ea((function(r,n){var u=i+r,o=a+n;if(u>4}}(t,e,r):0!=(4&n)&&function(t,e,r){for(var n=e[r+0],i=e[r+1],u=Zu(n,i,n<=i?5:7),a=new Uint8Array(16),o=0,s=2,c=0;c<2;c++){for(var l=0,f=0;f<3;f++)l|=e[r+s]<<8*f,s++;for(var h=0;h<8;h++){var y=l>>3*h&7;a[o]=y,o++}}for(var v=0;v<16;++v)t[4*v+3]=u[a[v]]}(t,e,r)}function aa(t,e,r,n,i){var u=0!=(1&(i=ra(i)))?8:16,a=0;!function(t,e,r){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=e.x,n=void 0===r?0:r,i=e.y,u=void 0===i?0:i,a=e.width,o=void 0===a?0:a,s=e.height,c=void 0===s?0:s,l=new Uint8Array(64),f=0,h=0;return ea((function(e,r){var i=n+e,a=u+r;if(i1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));var o=r.read(t),s=t.read(o);if(4==n)s=fa(s,i,u,oa);else if(5==n)s=fa(s,i,u,sa);else if(6==n)s=fa(s,i,u,ca);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(var c=0;c","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}}]),r}(eu),pa=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=(new du).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}},{key:"write",value:function(t,e,r){this.writeIndex(t,r);var n=e.export.data;(new du).write(t,n.byteLength,null),t.concat(n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(t){return"xTile.Pipeline.TideReader"===t}}]),r}(eu),da=function(t){Ki(r,t);var e=tu(r);function r(){return Ni(this,r),e.apply(this,arguments)}return Yi(r,[{key:"read",value:function(t){var e=new du,r=new ru,n=e.read(t),i=r.read(t),u=r.read(t),a=r.read(t);a>1&&console.warn("Found mipcount of ".concat(a,", only the first will be used."));var o=r.read(t),s=t.read(o);if(0!=n)throw new Error("Compressed texture format is not supported!");for(var c=0;c 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -46,6 +54,10 @@ return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -120,6 +132,10 @@ return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -337,6 +353,10 @@ return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -475,6 +495,10 @@ return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -512,14 +536,14 @@ return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -536,6 +560,11 @@ return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -564,7 +593,6 @@ } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -576,6 +604,10 @@ return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2517,8 +2549,6 @@ } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { diff --git a/src/readers/dist/readers.min.js b/src/readers/dist/readers.min.js index ce43f36..04f1807 100644 --- a/src/readers/dist/readers.min.js +++ b/src/readers/dist/readers.min.js @@ -1,24 +1,31 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";class e{static isTypeOf(t){return!1}static hasSubType(){return!1}static parseTypeList(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return[this.type(),...t]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new o;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?e.read(t):this.reader.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null===e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class w extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const f=256;//! Use DXT1 compression. -//! Weight the colour by alpha during cluster fit (disabled by default). -function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function T(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...T(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function B(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class X{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class D{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class U extends D{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class P extends D{constructor(t){super(t);this.iterationCount=t.flags&f?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>B(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=f&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]} -/** @license - ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new w,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new w,a=new h(n),o=new ot,f=new c(new d),p=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),f.write(t,e.glyphs,r),f.write(t,e.cropping,r),p.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}console.log("writing complitd!")}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new w;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * + * Libsquish license : MIT + * ----------------------------------------------------------------------------- + * Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * -------------------------------------------------------------------------- +*/ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XNB={})}(this,(function(t){"use strict";class e{static isTypeOf(t){return!1}static hasSubType(){return!1}static parseTypeList(){return[this.type()]}static type(){return this.name.slice(0,-6)}isValueType(){return!0}get type(){return this.constructor.type()}read(t,e){throw new Error("Cannot invoke methods on abstract class.")}write(t,e,r){throw new Error("Cannot invoke methods on abstract class.")}writeIndex(t,e){null!=e&&t.write7BitNumber(Number.parseInt(e.getIndex(this))+1)}toString(){return this.type}parseTypeList(){return this.constructor.parseTypeList()}}class r extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.UInt32Reader":case"System.UInt32":return!0;default:return!1}}read(t){return t.readUInt32()}write(t,e,r){this.writeIndex(t,r),t.writeUInt32(e)}}const s=[55296,56320];function n(t){var e;if("number"==typeof t&&(t=[t]),null===(e=t)||void 0===e||!e.length)throw new Error("Invalid codeset!");return 1===t.length?t[0]:((1023&t[0])<<10)+(1023&t[1])+65536}function i(t){const e=function(t){const e=Array.from({length:t.length},((e,r)=>t.charCodeAt(r))),r=[];let i=0;for(;ie<128?t+1:e<2048?t+2:e<65536?t+3:t+4),0)}class a extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.StringReader":case"System.String":return!0;default:return!1}}read(t){let e=t.read7BitNumber();return t.readString(e)}write(t,e,r){this.writeIndex(t,r);const s=i(e);t.write7BitNumber(s),t.writeString(e)}isValueType(){return!1}}class o extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.BooleanReader":case"System.Boolean":return!0;default:return!1}}read(t){return Boolean(t.readInt())}write(t,e,r){this.writeIndex(t,r),t.writeByte(e)}}class l extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.CharReader":case"System.Char":return!0;default:return!1}}read(t){let e=this._getCharSize(t.peekInt());return t.readString(e)}write(t,e,r){this.writeIndex(t,r),t.writeString(e)}_getCharSize(t){return 1+(3841982464>>(t>>3&30)&3)}}class u extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Int32Reader":case"System.Int32":return!0;default:return!1}}read(t){return t.readInt32()}write(t,e,r){this.writeIndex(t,r),t.writeInt32(e)}}class c extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.ListReader":case"System.Collections.Generic.List":return!0;default:return!1}}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t,e){const s=(new r).read(t),n=[];for(let r=0;r")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}}class h extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.NullableReader"===t}static hasSubType(){return!0}constructor(t){super(),this.reader=t}read(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=new o;return t.peekByte(1)?null===e?(r.read(t),this.reader.read(t)):this.reader.isValueType()?this.reader.read(t):e.read(t):(r.read(t),null)}write(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null!==e?(null===r&&t.writeByte(1),this.reader.write(t,e,this.reader.isValueType()?null:r)):t.writeByte(0)}isValueType(){return!1}get type(){return"Nullable<".concat(this.reader.type,">")}parseTypeList(){const t=this.reader.parseTypeList();return["".concat(this.type,":").concat(t.length),...t]}}class d extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.RectangleReader":case"Microsoft.Xna.Framework.Rectangle":return!0;default:return!1}}read(t){const e=new u;return{x:e.read(t),y:e.read(t),width:e.read(t),height:e.read(t)}}write(t,e,r){this.writeIndex(t,r);const s=new u;s.write(t,e.x,null),s.write(t,e.y,null),s.write(t,e.width,null),s.write(t,e.height,null)}}class p extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.SingleReader":case"System.Single":return!0;default:return!1}}read(t){return t.readSingle()}write(t,e,r){this.writeIndex(t,r),t.writeSingle(e)}}const w=256;function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,s)}return r}function y(t){for(var e=1;e{let n=e.map((t=>t[s]));return{value:t[s],vec:n}}));return s.sort(((t,e)=>e.value-t.value)),[s.map((t=>{let{value:e}=t;return e})),s.map((t=>{let{vec:e}=t;return e}))]}function M(t){let[,[e]]=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e-7,r=t.length,s=Array(r),n=Math.abs(e/r),i=Array(r);for(let t=0;t=Math.abs(n);){let e=a[0][0],s=a[0][1],n=g(e,s,x(t[e][e],t[s][s],t[e][s]),r);t=_(n,t),i=b(i,n),a=v(t)}for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;this._values=[t,e,r]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}get normalized(){return 0===this.length?null:z.multScalar(this,1/this.length)}get colorInt(){return this._values.map((t=>{const e=parseInt(255*t+.5);return Math.max(Math.min(e,255),0)}))}clone(){return new z(this.x,this.y,this.z)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this}toVec4(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return new V(this.x,this.y,this.z,t)}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this}clamp(t,e){const r=r=>t>r?t:e{return Math.trunc((0>(r=t)?0:10&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;this._values=[t,e,r,s]}get x(){return this._values[0]}get y(){return this._values[1]}get z(){return this._values[2]}get w(){return this._values[3]}set x(t){this._values[0]=t}set y(t){this._values[1]=t}set z(t){this._values[2]=t}set w(t){this._values[3]=t}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}get lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}get normalized(){return 0===this.length?null:V.multScalar(this,1/this.length)}get xyz(){return new z(this.x,this.y,this.z)}get splatX(){return new V(this.x)}get splatY(){return new V(this.y)}get splatZ(){return new V(this.z)}get splatW(){return new V(this.w)}clone(){return new V(this.x,this.y,this.z,this.w)}set(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t;return this._values[0]=t,this._values[1]=e,this._values[2]=r,this._values[3]=s,this}toVec3(){return this.xyz}addVector(t){return this._values[0]+=t.x,this._values[1]+=t.y,this._values[2]+=t.z,this._values[3]+=t.w,this}addScaledVector(t,e){return this._values[0]+=t.x*e,this._values[1]+=t.y*e,this._values[2]+=t.z*e,this._values[3]+=t.w*e,this}subVector(t){return this._values[0]-=t.x,this._values[1]-=t.y,this._values[2]-=t.z,this._values[3]-=t.w,this}mult(t){return this._values[0]*=t,this._values[1]*=t,this._values[2]*=t,this._values[3]*=t,this}multVector(t){return this._values[0]*=t.x,this._values[1]*=t.y,this._values[2]*=t.z,this._values[3]*=t.w,this}reciprocal(){return this._values[0]=1/this._values[0],this._values[1]=1/this._values[1],this._values[2]=1/this._values[2],this._values[3]=1/this._values[3],this}clamp(t,e){const r=r=>t>r?t:e0>t?0:1Math.trunc(t(e)*r+.5)/r;return this._values[0]=e(this._values[0],31),this._values[1]=e(this._values[1],63),this._values[2]=e(this._values[2],31),this._values[3]=t(this._values[3]),this}truncate(){return this._values[0]=Math.trunc(this._values[0]),this._values[1]=Math.trunc(this._values[1]),this._values[2]=Math.trunc(this._values[2]),this._values[3]=Math.trunc(this._values[3]),this}normalize(){return this._values[0]/=this.length,this._values[1]/=this.length,this._values[2]/=this.length,this._values[3]/=this.length,this}toString(){return"Vec4( ".concat(this._values.join(", ")," )")}static add(t,e){return new V(t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w)}static sub(t,e){return new V(t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}static multScalar(t,e){return new V(t.x*e,t.y*e,t.z*e,t.w*e)}static multVector(t,e){return new V(t.x*e.x,t.y*e.y,t.z*e.z,t.w*e.w)}static interpolate(t,e,r){let s=V.multScalar(t,1-r),n=V.multScalar(e,r);return V.add(s,n)}static multiplyAdd(t,e,r){return new V(t.x*e.x+r.x,t.y*e.y+r.y,t.z*e.z+r.z,t.w*e.w+r.w)}static negativeMultiplySubtract(t,e,r){return new V(r.x-t.x*e.x,r.y-t.y*e.y,r.z-t.z*e.z,r.w-t.w*e.w)}static compareAnyLessThan(t,e){return t.x(r+=e[n],t.addScaledVector(s,e[n]),t)),new z(0));s.mult(1/r);let n=t.reduce(((t,r,n)=>{let i=e[n],a=z.sub(r,s);return t[0][0]+=a.x*a.x*i,t[0][1]+=a.x*a.y*i,t[0][2]+=a.x*a.z*i,t[1][1]+=a.y*a.y*i,t[1][2]+=a.y*a.z*i,t[2][2]+=a.z*a.z*i,t}),[[0,0,0],[0,0,0],[0,0,0]]);return n[1][0]=n[0][1],n[2][0]=n[0][2],n[2][1]=n[1][2],n}(t,e);return new z(...M(r))}const O=[[[0,0,0],[0,0,0]],[[0,0,1],[0,0,1]],[[0,0,2],[0,0,2]],[[0,0,3],[0,1,1]],[[0,0,4],[0,1,0]],[[1,0,3],[0,1,1]],[[1,0,2],[0,1,2]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,2,1]],[[1,0,2],[0,2,2]],[[1,0,3],[0,3,1]],[[1,0,4],[0,3,0]],[[2,0,3],[0,3,1]],[[2,0,2],[0,3,2]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,4,1]],[[2,0,2],[0,4,2]],[[2,0,3],[0,5,1]],[[2,0,4],[0,5,0]],[[3,0,3],[0,5,1]],[[3,0,2],[0,5,2]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,6,1]],[[3,0,2],[0,6,2]],[[3,0,3],[0,7,1]],[[3,0,4],[0,7,0]],[[4,0,4],[0,7,1]],[[4,0,3],[0,7,2]],[[4,0,2],[1,7,1]],[[4,0,1],[1,7,0]],[[4,0,0],[0,8,0]],[[4,0,1],[0,8,1]],[[4,0,2],[2,7,1]],[[4,0,3],[2,7,0]],[[4,0,4],[0,9,0]],[[5,0,3],[0,9,1]],[[5,0,2],[3,7,1]],[[5,0,1],[3,7,0]],[[5,0,0],[0,10,0]],[[5,0,1],[0,10,1]],[[5,0,2],[0,10,2]],[[5,0,3],[0,11,1]],[[5,0,4],[0,11,0]],[[6,0,3],[0,11,1]],[[6,0,2],[0,11,2]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,12,1]],[[6,0,2],[0,12,2]],[[6,0,3],[0,13,1]],[[6,0,4],[0,13,0]],[[7,0,3],[0,13,1]],[[7,0,2],[0,13,2]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,14,1]],[[7,0,2],[0,14,2]],[[7,0,3],[0,15,1]],[[7,0,4],[0,15,0]],[[8,0,4],[0,15,1]],[[8,0,3],[0,15,2]],[[8,0,2],[1,15,1]],[[8,0,1],[1,15,0]],[[8,0,0],[0,16,0]],[[8,0,1],[0,16,1]],[[8,0,2],[2,15,1]],[[8,0,3],[2,15,0]],[[8,0,4],[0,17,0]],[[9,0,3],[0,17,1]],[[9,0,2],[3,15,1]],[[9,0,1],[3,15,0]],[[9,0,0],[0,18,0]],[[9,0,1],[0,18,1]],[[9,0,2],[0,18,2]],[[9,0,3],[0,19,1]],[[9,0,4],[0,19,0]],[[10,0,3],[0,19,1]],[[10,0,2],[0,19,2]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,20,1]],[[10,0,2],[0,20,2]],[[10,0,3],[0,21,1]],[[10,0,4],[0,21,0]],[[11,0,3],[0,21,1]],[[11,0,2],[0,21,2]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,22,1]],[[11,0,2],[0,22,2]],[[11,0,3],[0,23,1]],[[11,0,4],[0,23,0]],[[12,0,4],[0,23,1]],[[12,0,3],[0,23,2]],[[12,0,2],[1,23,1]],[[12,0,1],[1,23,0]],[[12,0,0],[0,24,0]],[[12,0,1],[0,24,1]],[[12,0,2],[2,23,1]],[[12,0,3],[2,23,0]],[[12,0,4],[0,25,0]],[[13,0,3],[0,25,1]],[[13,0,2],[3,23,1]],[[13,0,1],[3,23,0]],[[13,0,0],[0,26,0]],[[13,0,1],[0,26,1]],[[13,0,2],[0,26,2]],[[13,0,3],[0,27,1]],[[13,0,4],[0,27,0]],[[14,0,3],[0,27,1]],[[14,0,2],[0,27,2]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,28,1]],[[14,0,2],[0,28,2]],[[14,0,3],[0,29,1]],[[14,0,4],[0,29,0]],[[15,0,3],[0,29,1]],[[15,0,2],[0,29,2]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,30,1]],[[15,0,2],[0,30,2]],[[15,0,3],[0,31,1]],[[15,0,4],[0,31,0]],[[16,0,4],[0,31,1]],[[16,0,3],[0,31,2]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[4,28,0]],[[16,0,1],[4,28,1]],[[16,0,2],[2,31,1]],[[16,0,3],[2,31,0]],[[16,0,4],[4,29,0]],[[17,0,3],[4,29,1]],[[17,0,2],[3,31,1]],[[17,0,1],[3,31,0]],[[17,0,0],[4,30,0]],[[17,0,1],[4,30,1]],[[17,0,2],[4,30,2]],[[17,0,3],[4,31,1]],[[17,0,4],[4,31,0]],[[18,0,3],[4,31,1]],[[18,0,2],[4,31,2]],[[18,0,1],[5,31,1]],[[18,0,0],[5,31,0]],[[18,0,1],[5,31,1]],[[18,0,2],[5,31,2]],[[18,0,3],[6,31,1]],[[18,0,4],[6,31,0]],[[19,0,3],[6,31,1]],[[19,0,2],[6,31,2]],[[19,0,1],[7,31,1]],[[19,0,0],[7,31,0]],[[19,0,1],[7,31,1]],[[19,0,2],[7,31,2]],[[19,0,3],[8,31,1]],[[19,0,4],[8,31,0]],[[20,0,4],[8,31,1]],[[20,0,3],[8,31,2]],[[20,0,2],[9,31,1]],[[20,0,1],[9,31,0]],[[20,0,0],[12,28,0]],[[20,0,1],[12,28,1]],[[20,0,2],[10,31,1]],[[20,0,3],[10,31,0]],[[20,0,4],[12,29,0]],[[21,0,3],[12,29,1]],[[21,0,2],[11,31,1]],[[21,0,1],[11,31,0]],[[21,0,0],[12,30,0]],[[21,0,1],[12,30,1]],[[21,0,2],[12,30,2]],[[21,0,3],[12,31,1]],[[21,0,4],[12,31,0]],[[22,0,3],[12,31,1]],[[22,0,2],[12,31,2]],[[22,0,1],[13,31,1]],[[22,0,0],[13,31,0]],[[22,0,1],[13,31,1]],[[22,0,2],[13,31,2]],[[22,0,3],[14,31,1]],[[22,0,4],[14,31,0]],[[23,0,3],[14,31,1]],[[23,0,2],[14,31,2]],[[23,0,1],[15,31,1]],[[23,0,0],[15,31,0]],[[23,0,1],[15,31,1]],[[23,0,2],[15,31,2]],[[23,0,3],[16,31,1]],[[23,0,4],[16,31,0]],[[24,0,4],[16,31,1]],[[24,0,3],[16,31,2]],[[24,0,2],[17,31,1]],[[24,0,1],[17,31,0]],[[24,0,0],[20,28,0]],[[24,0,1],[20,28,1]],[[24,0,2],[18,31,1]],[[24,0,3],[18,31,0]],[[24,0,4],[20,29,0]],[[25,0,3],[20,29,1]],[[25,0,2],[19,31,1]],[[25,0,1],[19,31,0]],[[25,0,0],[20,30,0]],[[25,0,1],[20,30,1]],[[25,0,2],[20,30,2]],[[25,0,3],[20,31,1]],[[25,0,4],[20,31,0]],[[26,0,3],[20,31,1]],[[26,0,2],[20,31,2]],[[26,0,1],[21,31,1]],[[26,0,0],[21,31,0]],[[26,0,1],[21,31,1]],[[26,0,2],[21,31,2]],[[26,0,3],[22,31,1]],[[26,0,4],[22,31,0]],[[27,0,3],[22,31,1]],[[27,0,2],[22,31,2]],[[27,0,1],[23,31,1]],[[27,0,0],[23,31,0]],[[27,0,1],[23,31,1]],[[27,0,2],[23,31,2]],[[27,0,3],[24,31,1]],[[27,0,4],[24,31,0]],[[28,0,4],[24,31,1]],[[28,0,3],[24,31,2]],[[28,0,2],[25,31,1]],[[28,0,1],[25,31,0]],[[28,0,0],[28,28,0]],[[28,0,1],[28,28,1]],[[28,0,2],[26,31,1]],[[28,0,3],[26,31,0]],[[28,0,4],[28,29,0]],[[29,0,3],[28,29,1]],[[29,0,2],[27,31,1]],[[29,0,1],[27,31,0]],[[29,0,0],[28,30,0]],[[29,0,1],[28,30,1]],[[29,0,2],[28,30,2]],[[29,0,3],[28,31,1]],[[29,0,4],[28,31,0]],[[30,0,3],[28,31,1]],[[30,0,2],[28,31,2]],[[30,0,1],[29,31,1]],[[30,0,0],[29,31,0]],[[30,0,1],[29,31,1]],[[30,0,2],[29,31,2]],[[30,0,3],[30,31,1]],[[30,0,4],[30,31,0]],[[31,0,3],[30,31,1]],[[31,0,2],[30,31,2]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],k=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[1,0,1],[0,2,1]],[[1,0,0],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,2],[0,3,0]],[[2,0,1],[0,4,1]],[[2,0,0],[0,4,0]],[[2,0,1],[0,5,1]],[[2,0,2],[0,5,0]],[[3,0,1],[0,6,1]],[[3,0,0],[0,6,0]],[[3,0,1],[0,7,1]],[[3,0,2],[0,7,0]],[[4,0,1],[0,8,1]],[[4,0,0],[0,8,0]],[[4,0,1],[0,9,1]],[[4,0,2],[0,9,0]],[[5,0,1],[0,10,1]],[[5,0,0],[0,10,0]],[[5,0,1],[0,11,1]],[[5,0,2],[0,11,0]],[[6,0,1],[0,12,1]],[[6,0,0],[0,12,0]],[[6,0,1],[0,13,1]],[[6,0,2],[0,13,0]],[[7,0,1],[0,14,1]],[[7,0,0],[0,14,0]],[[7,0,1],[0,15,1]],[[7,0,2],[0,15,0]],[[8,0,1],[0,16,1]],[[8,0,0],[0,16,0]],[[8,0,1],[0,17,1]],[[8,0,2],[0,17,0]],[[9,0,1],[0,18,1]],[[9,0,0],[0,18,0]],[[9,0,1],[0,19,1]],[[9,0,2],[0,19,0]],[[10,0,1],[0,20,1]],[[10,0,0],[0,20,0]],[[10,0,1],[0,21,1]],[[10,0,2],[0,21,0]],[[11,0,1],[0,22,1]],[[11,0,0],[0,22,0]],[[11,0,1],[0,23,1]],[[11,0,2],[0,23,0]],[[12,0,1],[0,24,1]],[[12,0,0],[0,24,0]],[[12,0,1],[0,25,1]],[[12,0,2],[0,25,0]],[[13,0,1],[0,26,1]],[[13,0,0],[0,26,0]],[[13,0,1],[0,27,1]],[[13,0,2],[0,27,0]],[[14,0,1],[0,28,1]],[[14,0,0],[0,28,0]],[[14,0,1],[0,29,1]],[[14,0,2],[0,29,0]],[[15,0,1],[0,30,1]],[[15,0,0],[0,30,0]],[[15,0,1],[0,31,1]],[[15,0,2],[0,31,0]],[[16,0,2],[1,31,1]],[[16,0,1],[1,31,0]],[[16,0,0],[0,32,0]],[[16,0,1],[2,31,0]],[[16,0,2],[0,33,0]],[[17,0,1],[3,31,0]],[[17,0,0],[0,34,0]],[[17,0,1],[4,31,0]],[[17,0,2],[0,35,0]],[[18,0,1],[5,31,0]],[[18,0,0],[0,36,0]],[[18,0,1],[6,31,0]],[[18,0,2],[0,37,0]],[[19,0,1],[7,31,0]],[[19,0,0],[0,38,0]],[[19,0,1],[8,31,0]],[[19,0,2],[0,39,0]],[[20,0,1],[9,31,0]],[[20,0,0],[0,40,0]],[[20,0,1],[10,31,0]],[[20,0,2],[0,41,0]],[[21,0,1],[11,31,0]],[[21,0,0],[0,42,0]],[[21,0,1],[12,31,0]],[[21,0,2],[0,43,0]],[[22,0,1],[13,31,0]],[[22,0,0],[0,44,0]],[[22,0,1],[14,31,0]],[[22,0,2],[0,45,0]],[[23,0,1],[15,31,0]],[[23,0,0],[0,46,0]],[[23,0,1],[0,47,1]],[[23,0,2],[0,47,0]],[[24,0,1],[0,48,1]],[[24,0,0],[0,48,0]],[[24,0,1],[0,49,1]],[[24,0,2],[0,49,0]],[[25,0,1],[0,50,1]],[[25,0,0],[0,50,0]],[[25,0,1],[0,51,1]],[[25,0,2],[0,51,0]],[[26,0,1],[0,52,1]],[[26,0,0],[0,52,0]],[[26,0,1],[0,53,1]],[[26,0,2],[0,53,0]],[[27,0,1],[0,54,1]],[[27,0,0],[0,54,0]],[[27,0,1],[0,55,1]],[[27,0,2],[0,55,0]],[[28,0,1],[0,56,1]],[[28,0,0],[0,56,0]],[[28,0,1],[0,57,1]],[[28,0,2],[0,57,0]],[[29,0,1],[0,58,1]],[[29,0,0],[0,58,0]],[[29,0,1],[0,59,1]],[[29,0,2],[0,59,0]],[[30,0,1],[0,60,1]],[[30,0,0],[0,60,0]],[[30,0,1],[0,61,1]],[[30,0,2],[0,61,0]],[[31,0,1],[0,62,1]],[[31,0,0],[0,62,0]],[[31,0,1],[0,63,1]],[[31,0,2],[0,63,0]],[[32,0,2],[1,63,1]],[[32,0,1],[1,63,0]],[[32,0,0],[16,48,0]],[[32,0,1],[2,63,0]],[[32,0,2],[16,49,0]],[[33,0,1],[3,63,0]],[[33,0,0],[16,50,0]],[[33,0,1],[4,63,0]],[[33,0,2],[16,51,0]],[[34,0,1],[5,63,0]],[[34,0,0],[16,52,0]],[[34,0,1],[6,63,0]],[[34,0,2],[16,53,0]],[[35,0,1],[7,63,0]],[[35,0,0],[16,54,0]],[[35,0,1],[8,63,0]],[[35,0,2],[16,55,0]],[[36,0,1],[9,63,0]],[[36,0,0],[16,56,0]],[[36,0,1],[10,63,0]],[[36,0,2],[16,57,0]],[[37,0,1],[11,63,0]],[[37,0,0],[16,58,0]],[[37,0,1],[12,63,0]],[[37,0,2],[16,59,0]],[[38,0,1],[13,63,0]],[[38,0,0],[16,60,0]],[[38,0,1],[14,63,0]],[[38,0,2],[16,61,0]],[[39,0,1],[15,63,0]],[[39,0,0],[16,62,0]],[[39,0,1],[16,63,1]],[[39,0,2],[16,63,0]],[[40,0,1],[17,63,1]],[[40,0,0],[17,63,0]],[[40,0,1],[18,63,1]],[[40,0,2],[18,63,0]],[[41,0,1],[19,63,1]],[[41,0,0],[19,63,0]],[[41,0,1],[20,63,1]],[[41,0,2],[20,63,0]],[[42,0,1],[21,63,1]],[[42,0,0],[21,63,0]],[[42,0,1],[22,63,1]],[[42,0,2],[22,63,0]],[[43,0,1],[23,63,1]],[[43,0,0],[23,63,0]],[[43,0,1],[24,63,1]],[[43,0,2],[24,63,0]],[[44,0,1],[25,63,1]],[[44,0,0],[25,63,0]],[[44,0,1],[26,63,1]],[[44,0,2],[26,63,0]],[[45,0,1],[27,63,1]],[[45,0,0],[27,63,0]],[[45,0,1],[28,63,1]],[[45,0,2],[28,63,0]],[[46,0,1],[29,63,1]],[[46,0,0],[29,63,0]],[[46,0,1],[30,63,1]],[[46,0,2],[30,63,0]],[[47,0,1],[31,63,1]],[[47,0,0],[31,63,0]],[[47,0,1],[32,63,1]],[[47,0,2],[32,63,0]],[[48,0,2],[33,63,1]],[[48,0,1],[33,63,0]],[[48,0,0],[48,48,0]],[[48,0,1],[34,63,0]],[[48,0,2],[48,49,0]],[[49,0,1],[35,63,0]],[[49,0,0],[48,50,0]],[[49,0,1],[36,63,0]],[[49,0,2],[48,51,0]],[[50,0,1],[37,63,0]],[[50,0,0],[48,52,0]],[[50,0,1],[38,63,0]],[[50,0,2],[48,53,0]],[[51,0,1],[39,63,0]],[[51,0,0],[48,54,0]],[[51,0,1],[40,63,0]],[[51,0,2],[48,55,0]],[[52,0,1],[41,63,0]],[[52,0,0],[48,56,0]],[[52,0,1],[42,63,0]],[[52,0,2],[48,57,0]],[[53,0,1],[43,63,0]],[[53,0,0],[48,58,0]],[[53,0,1],[44,63,0]],[[53,0,2],[48,59,0]],[[54,0,1],[45,63,0]],[[54,0,0],[48,60,0]],[[54,0,1],[46,63,0]],[[54,0,2],[48,61,0]],[[55,0,1],[47,63,0]],[[55,0,0],[48,62,0]],[[55,0,1],[48,63,1]],[[55,0,2],[48,63,0]],[[56,0,1],[49,63,1]],[[56,0,0],[49,63,0]],[[56,0,1],[50,63,1]],[[56,0,2],[50,63,0]],[[57,0,1],[51,63,1]],[[57,0,0],[51,63,0]],[[57,0,1],[52,63,1]],[[57,0,2],[52,63,0]],[[58,0,1],[53,63,1]],[[58,0,0],[53,63,0]],[[58,0,1],[54,63,1]],[[58,0,2],[54,63,0]],[[59,0,1],[55,63,1]],[[59,0,0],[55,63,0]],[[59,0,1],[56,63,1]],[[59,0,2],[56,63,0]],[[60,0,1],[57,63,1]],[[60,0,0],[57,63,0]],[[60,0,1],[58,63,1]],[[60,0,2],[58,63,0]],[[61,0,1],[59,63,1]],[[61,0,0],[59,63,0]],[[61,0,1],[60,63,1]],[[61,0,2],[60,63,0]],[[62,0,1],[61,63,1]],[[62,0,0],[61,63,0]],[[62,0,1],[62,63,1]],[[62,0,2],[62,63,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]],R=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,1]],[[0,0,2],[0,1,0]],[[0,0,3],[0,1,1]],[[0,0,4],[0,2,1]],[[1,0,3],[0,2,0]],[[1,0,2],[0,2,1]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[1,2,1]],[[1,0,2],[1,2,0]],[[1,0,3],[0,4,0]],[[1,0,4],[0,5,1]],[[2,0,3],[0,5,0]],[[2,0,2],[0,5,1]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[2,3,1]],[[2,0,2],[2,3,0]],[[2,0,3],[0,7,0]],[[2,0,4],[1,6,1]],[[3,0,3],[1,6,0]],[[3,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,9,1]],[[3,0,2],[0,10,1]],[[3,0,3],[0,10,0]],[[3,0,4],[2,7,1]],[[4,0,4],[2,7,0]],[[4,0,3],[0,11,0]],[[4,0,2],[1,10,1]],[[4,0,1],[1,10,0]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,1]],[[4,0,2],[0,13,0]],[[4,0,3],[0,13,1]],[[4,0,4],[0,14,1]],[[5,0,3],[0,14,0]],[[5,0,2],[2,11,1]],[[5,0,1],[2,11,0]],[[5,0,0],[0,15,0]],[[5,0,1],[1,14,1]],[[5,0,2],[1,14,0]],[[5,0,3],[0,16,0]],[[5,0,4],[0,17,1]],[[6,0,3],[0,17,0]],[[6,0,2],[0,17,1]],[[6,0,1],[0,18,1]],[[6,0,0],[0,18,0]],[[6,0,1],[2,15,1]],[[6,0,2],[2,15,0]],[[6,0,3],[0,19,0]],[[6,0,4],[1,18,1]],[[7,0,3],[1,18,0]],[[7,0,2],[0,20,0]],[[7,0,1],[0,21,1]],[[7,0,0],[0,21,0]],[[7,0,1],[0,21,1]],[[7,0,2],[0,22,1]],[[7,0,3],[0,22,0]],[[7,0,4],[2,19,1]],[[8,0,4],[2,19,0]],[[8,0,3],[0,23,0]],[[8,0,2],[1,22,1]],[[8,0,1],[1,22,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,1]],[[8,0,2],[0,25,0]],[[8,0,3],[0,25,1]],[[8,0,4],[0,26,1]],[[9,0,3],[0,26,0]],[[9,0,2],[2,23,1]],[[9,0,1],[2,23,0]],[[9,0,0],[0,27,0]],[[9,0,1],[1,26,1]],[[9,0,2],[1,26,0]],[[9,0,3],[0,28,0]],[[9,0,4],[0,29,1]],[[10,0,3],[0,29,0]],[[10,0,2],[0,29,1]],[[10,0,1],[0,30,1]],[[10,0,0],[0,30,0]],[[10,0,1],[2,27,1]],[[10,0,2],[2,27,0]],[[10,0,3],[0,31,0]],[[10,0,4],[1,30,1]],[[11,0,3],[1,30,0]],[[11,0,2],[4,24,0]],[[11,0,1],[1,31,1]],[[11,0,0],[1,31,0]],[[11,0,1],[1,31,1]],[[11,0,2],[2,30,1]],[[11,0,3],[2,30,0]],[[11,0,4],[2,31,1]],[[12,0,4],[2,31,0]],[[12,0,3],[4,27,0]],[[12,0,2],[3,30,1]],[[12,0,1],[3,30,0]],[[12,0,0],[4,28,0]],[[12,0,1],[3,31,1]],[[12,0,2],[3,31,0]],[[12,0,3],[3,31,1]],[[12,0,4],[4,30,1]],[[13,0,3],[4,30,0]],[[13,0,2],[6,27,1]],[[13,0,1],[6,27,0]],[[13,0,0],[4,31,0]],[[13,0,1],[5,30,1]],[[13,0,2],[5,30,0]],[[13,0,3],[8,24,0]],[[13,0,4],[5,31,1]],[[14,0,3],[5,31,0]],[[14,0,2],[5,31,1]],[[14,0,1],[6,30,1]],[[14,0,0],[6,30,0]],[[14,0,1],[6,31,1]],[[14,0,2],[6,31,0]],[[14,0,3],[8,27,0]],[[14,0,4],[7,30,1]],[[15,0,3],[7,30,0]],[[15,0,2],[8,28,0]],[[15,0,1],[7,31,1]],[[15,0,0],[7,31,0]],[[15,0,1],[7,31,1]],[[15,0,2],[8,30,1]],[[15,0,3],[8,30,0]],[[15,0,4],[10,27,1]],[[16,0,4],[10,27,0]],[[16,0,3],[8,31,0]],[[16,0,2],[9,30,1]],[[16,0,1],[9,30,0]],[[16,0,0],[12,24,0]],[[16,0,1],[9,31,1]],[[16,0,2],[9,31,0]],[[16,0,3],[9,31,1]],[[16,0,4],[10,30,1]],[[17,0,3],[10,30,0]],[[17,0,2],[10,31,1]],[[17,0,1],[10,31,0]],[[17,0,0],[12,27,0]],[[17,0,1],[11,30,1]],[[17,0,2],[11,30,0]],[[17,0,3],[12,28,0]],[[17,0,4],[11,31,1]],[[18,0,3],[11,31,0]],[[18,0,2],[11,31,1]],[[18,0,1],[12,30,1]],[[18,0,0],[12,30,0]],[[18,0,1],[14,27,1]],[[18,0,2],[14,27,0]],[[18,0,3],[12,31,0]],[[18,0,4],[13,30,1]],[[19,0,3],[13,30,0]],[[19,0,2],[16,24,0]],[[19,0,1],[13,31,1]],[[19,0,0],[13,31,0]],[[19,0,1],[13,31,1]],[[19,0,2],[14,30,1]],[[19,0,3],[14,30,0]],[[19,0,4],[14,31,1]],[[20,0,4],[14,31,0]],[[20,0,3],[16,27,0]],[[20,0,2],[15,30,1]],[[20,0,1],[15,30,0]],[[20,0,0],[16,28,0]],[[20,0,1],[15,31,1]],[[20,0,2],[15,31,0]],[[20,0,3],[15,31,1]],[[20,0,4],[16,30,1]],[[21,0,3],[16,30,0]],[[21,0,2],[18,27,1]],[[21,0,1],[18,27,0]],[[21,0,0],[16,31,0]],[[21,0,1],[17,30,1]],[[21,0,2],[17,30,0]],[[21,0,3],[20,24,0]],[[21,0,4],[17,31,1]],[[22,0,3],[17,31,0]],[[22,0,2],[17,31,1]],[[22,0,1],[18,30,1]],[[22,0,0],[18,30,0]],[[22,0,1],[18,31,1]],[[22,0,2],[18,31,0]],[[22,0,3],[20,27,0]],[[22,0,4],[19,30,1]],[[23,0,3],[19,30,0]],[[23,0,2],[20,28,0]],[[23,0,1],[19,31,1]],[[23,0,0],[19,31,0]],[[23,0,1],[19,31,1]],[[23,0,2],[20,30,1]],[[23,0,3],[20,30,0]],[[23,0,4],[22,27,1]],[[24,0,4],[22,27,0]],[[24,0,3],[20,31,0]],[[24,0,2],[21,30,1]],[[24,0,1],[21,30,0]],[[24,0,0],[24,24,0]],[[24,0,1],[21,31,1]],[[24,0,2],[21,31,0]],[[24,0,3],[21,31,1]],[[24,0,4],[22,30,1]],[[25,0,3],[22,30,0]],[[25,0,2],[22,31,1]],[[25,0,1],[22,31,0]],[[25,0,0],[24,27,0]],[[25,0,1],[23,30,1]],[[25,0,2],[23,30,0]],[[25,0,3],[24,28,0]],[[25,0,4],[23,31,1]],[[26,0,3],[23,31,0]],[[26,0,2],[23,31,1]],[[26,0,1],[24,30,1]],[[26,0,0],[24,30,0]],[[26,0,1],[26,27,1]],[[26,0,2],[26,27,0]],[[26,0,3],[24,31,0]],[[26,0,4],[25,30,1]],[[27,0,3],[25,30,0]],[[27,0,2],[28,24,0]],[[27,0,1],[25,31,1]],[[27,0,0],[25,31,0]],[[27,0,1],[25,31,1]],[[27,0,2],[26,30,1]],[[27,0,3],[26,30,0]],[[27,0,4],[26,31,1]],[[28,0,4],[26,31,0]],[[28,0,3],[28,27,0]],[[28,0,2],[27,30,1]],[[28,0,1],[27,30,0]],[[28,0,0],[28,28,0]],[[28,0,1],[27,31,1]],[[28,0,2],[27,31,0]],[[28,0,3],[27,31,1]],[[28,0,4],[28,30,1]],[[29,0,3],[28,30,0]],[[29,0,2],[30,27,1]],[[29,0,1],[30,27,0]],[[29,0,0],[28,31,0]],[[29,0,1],[29,30,1]],[[29,0,2],[29,30,0]],[[29,0,3],[29,30,1]],[[29,0,4],[29,31,1]],[[30,0,3],[29,31,0]],[[30,0,2],[29,31,1]],[[30,0,1],[30,30,1]],[[30,0,0],[30,30,0]],[[30,0,1],[30,31,1]],[[30,0,2],[30,31,0]],[[30,0,3],[30,31,1]],[[30,0,4],[31,30,1]],[[31,0,3],[31,30,0]],[[31,0,2],[31,30,1]],[[31,0,1],[31,31,1]],[[31,0,0],[31,31,0]]],I=[[[0,0,0],[0,0,0]],[[0,0,1],[0,1,0]],[[0,0,2],[0,2,0]],[[1,0,1],[0,3,1]],[[1,0,0],[0,3,0]],[[1,0,1],[0,4,0]],[[1,0,2],[0,5,0]],[[2,0,1],[0,6,1]],[[2,0,0],[0,6,0]],[[2,0,1],[0,7,0]],[[2,0,2],[0,8,0]],[[3,0,1],[0,9,1]],[[3,0,0],[0,9,0]],[[3,0,1],[0,10,0]],[[3,0,2],[0,11,0]],[[4,0,1],[0,12,1]],[[4,0,0],[0,12,0]],[[4,0,1],[0,13,0]],[[4,0,2],[0,14,0]],[[5,0,1],[0,15,1]],[[5,0,0],[0,15,0]],[[5,0,1],[0,16,0]],[[5,0,2],[1,15,0]],[[6,0,1],[0,17,0]],[[6,0,0],[0,18,0]],[[6,0,1],[0,19,0]],[[6,0,2],[3,14,0]],[[7,0,1],[0,20,0]],[[7,0,0],[0,21,0]],[[7,0,1],[0,22,0]],[[7,0,2],[4,15,0]],[[8,0,1],[0,23,0]],[[8,0,0],[0,24,0]],[[8,0,1],[0,25,0]],[[8,0,2],[6,14,0]],[[9,0,1],[0,26,0]],[[9,0,0],[0,27,0]],[[9,0,1],[0,28,0]],[[9,0,2],[7,15,0]],[[10,0,1],[0,29,0]],[[10,0,0],[0,30,0]],[[10,0,1],[0,31,0]],[[10,0,2],[9,14,0]],[[11,0,1],[0,32,0]],[[11,0,0],[0,33,0]],[[11,0,1],[2,30,0]],[[11,0,2],[0,34,0]],[[12,0,1],[0,35,0]],[[12,0,0],[0,36,0]],[[12,0,1],[3,31,0]],[[12,0,2],[0,37,0]],[[13,0,1],[0,38,0]],[[13,0,0],[0,39,0]],[[13,0,1],[5,30,0]],[[13,0,2],[0,40,0]],[[14,0,1],[0,41,0]],[[14,0,0],[0,42,0]],[[14,0,1],[6,31,0]],[[14,0,2],[0,43,0]],[[15,0,1],[0,44,0]],[[15,0,0],[0,45,0]],[[15,0,1],[8,30,0]],[[15,0,2],[0,46,0]],[[16,0,2],[0,47,0]],[[16,0,1],[1,46,0]],[[16,0,0],[0,48,0]],[[16,0,1],[0,49,0]],[[16,0,2],[0,50,0]],[[17,0,1],[2,47,0]],[[17,0,0],[0,51,0]],[[17,0,1],[0,52,0]],[[17,0,2],[0,53,0]],[[18,0,1],[4,46,0]],[[18,0,0],[0,54,0]],[[18,0,1],[0,55,0]],[[18,0,2],[0,56,0]],[[19,0,1],[5,47,0]],[[19,0,0],[0,57,0]],[[19,0,1],[0,58,0]],[[19,0,2],[0,59,0]],[[20,0,1],[7,46,0]],[[20,0,0],[0,60,0]],[[20,0,1],[0,61,0]],[[20,0,2],[0,62,0]],[[21,0,1],[8,47,0]],[[21,0,0],[0,63,0]],[[21,0,1],[1,62,0]],[[21,0,2],[1,63,0]],[[22,0,1],[10,46,0]],[[22,0,0],[2,62,0]],[[22,0,1],[2,63,0]],[[22,0,2],[3,62,0]],[[23,0,1],[11,47,0]],[[23,0,0],[3,63,0]],[[23,0,1],[4,62,0]],[[23,0,2],[4,63,0]],[[24,0,1],[13,46,0]],[[24,0,0],[5,62,0]],[[24,0,1],[5,63,0]],[[24,0,2],[6,62,0]],[[25,0,1],[14,47,0]],[[25,0,0],[6,63,0]],[[25,0,1],[7,62,0]],[[25,0,2],[7,63,0]],[[26,0,1],[16,45,0]],[[26,0,0],[8,62,0]],[[26,0,1],[8,63,0]],[[26,0,2],[9,62,0]],[[27,0,1],[16,48,0]],[[27,0,0],[9,63,0]],[[27,0,1],[10,62,0]],[[27,0,2],[10,63,0]],[[28,0,1],[16,51,0]],[[28,0,0],[11,62,0]],[[28,0,1],[11,63,0]],[[28,0,2],[12,62,0]],[[29,0,1],[16,54,0]],[[29,0,0],[12,63,0]],[[29,0,1],[13,62,0]],[[29,0,2],[13,63,0]],[[30,0,1],[16,57,0]],[[30,0,0],[14,62,0]],[[30,0,1],[14,63,0]],[[30,0,2],[15,62,0]],[[31,0,1],[16,60,0]],[[31,0,0],[15,63,0]],[[31,0,1],[24,46,0]],[[31,0,2],[16,62,0]],[[32,0,2],[16,63,0]],[[32,0,1],[17,62,0]],[[32,0,0],[25,47,0]],[[32,0,1],[17,63,0]],[[32,0,2],[18,62,0]],[[33,0,1],[18,63,0]],[[33,0,0],[27,46,0]],[[33,0,1],[19,62,0]],[[33,0,2],[19,63,0]],[[34,0,1],[20,62,0]],[[34,0,0],[28,47,0]],[[34,0,1],[20,63,0]],[[34,0,2],[21,62,0]],[[35,0,1],[21,63,0]],[[35,0,0],[30,46,0]],[[35,0,1],[22,62,0]],[[35,0,2],[22,63,0]],[[36,0,1],[23,62,0]],[[36,0,0],[31,47,0]],[[36,0,1],[23,63,0]],[[36,0,2],[24,62,0]],[[37,0,1],[24,63,0]],[[37,0,0],[32,47,0]],[[37,0,1],[25,62,0]],[[37,0,2],[25,63,0]],[[38,0,1],[26,62,0]],[[38,0,0],[32,50,0]],[[38,0,1],[26,63,0]],[[38,0,2],[27,62,0]],[[39,0,1],[27,63,0]],[[39,0,0],[32,53,0]],[[39,0,1],[28,62,0]],[[39,0,2],[28,63,0]],[[40,0,1],[29,62,0]],[[40,0,0],[32,56,0]],[[40,0,1],[29,63,0]],[[40,0,2],[30,62,0]],[[41,0,1],[30,63,0]],[[41,0,0],[32,59,0]],[[41,0,1],[31,62,0]],[[41,0,2],[31,63,0]],[[42,0,1],[32,61,0]],[[42,0,0],[32,62,0]],[[42,0,1],[32,63,0]],[[42,0,2],[41,46,0]],[[43,0,1],[33,62,0]],[[43,0,0],[33,63,0]],[[43,0,1],[34,62,0]],[[43,0,2],[42,47,0]],[[44,0,1],[34,63,0]],[[44,0,0],[35,62,0]],[[44,0,1],[35,63,0]],[[44,0,2],[44,46,0]],[[45,0,1],[36,62,0]],[[45,0,0],[36,63,0]],[[45,0,1],[37,62,0]],[[45,0,2],[45,47,0]],[[46,0,1],[37,63,0]],[[46,0,0],[38,62,0]],[[46,0,1],[38,63,0]],[[46,0,2],[47,46,0]],[[47,0,1],[39,62,0]],[[47,0,0],[39,63,0]],[[47,0,1],[40,62,0]],[[47,0,2],[48,46,0]],[[48,0,2],[40,63,0]],[[48,0,1],[41,62,0]],[[48,0,0],[41,63,0]],[[48,0,1],[48,49,0]],[[48,0,2],[42,62,0]],[[49,0,1],[42,63,0]],[[49,0,0],[43,62,0]],[[49,0,1],[48,52,0]],[[49,0,2],[43,63,0]],[[50,0,1],[44,62,0]],[[50,0,0],[44,63,0]],[[50,0,1],[48,55,0]],[[50,0,2],[45,62,0]],[[51,0,1],[45,63,0]],[[51,0,0],[46,62,0]],[[51,0,1],[48,58,0]],[[51,0,2],[46,63,0]],[[52,0,1],[47,62,0]],[[52,0,0],[47,63,0]],[[52,0,1],[48,61,0]],[[52,0,2],[48,62,0]],[[53,0,1],[56,47,0]],[[53,0,0],[48,63,0]],[[53,0,1],[49,62,0]],[[53,0,2],[49,63,0]],[[54,0,1],[58,46,0]],[[54,0,0],[50,62,0]],[[54,0,1],[50,63,0]],[[54,0,2],[51,62,0]],[[55,0,1],[59,47,0]],[[55,0,0],[51,63,0]],[[55,0,1],[52,62,0]],[[55,0,2],[52,63,0]],[[56,0,1],[61,46,0]],[[56,0,0],[53,62,0]],[[56,0,1],[53,63,0]],[[56,0,2],[54,62,0]],[[57,0,1],[62,47,0]],[[57,0,0],[54,63,0]],[[57,0,1],[55,62,0]],[[57,0,2],[55,63,0]],[[58,0,1],[56,62,1]],[[58,0,0],[56,62,0]],[[58,0,1],[56,63,0]],[[58,0,2],[57,62,0]],[[59,0,1],[57,63,1]],[[59,0,0],[57,63,0]],[[59,0,1],[58,62,0]],[[59,0,2],[58,63,0]],[[60,0,1],[59,62,1]],[[60,0,0],[59,62,0]],[[60,0,1],[59,63,0]],[[60,0,2],[60,62,0]],[[61,0,1],[60,63,1]],[[61,0,0],[60,63,0]],[[61,0,1],[61,62,0]],[[61,0,2],[61,63,0]],[[62,0,1],[62,62,1]],[[62,0,0],[62,62,0]],[[62,0,1],[62,63,0]],[[62,0,2],[63,62,0]],[[63,0,1],[63,63,1]],[[63,0,0],[63,63,0]]];function A(t,e){const r=parseInt(t+.5);return r<0?0:r}function C(t){return A(31*t.x)<<11|A(63*t.y)<<5|A(31*t.z)}function F(t,e,r,s,n){s[n+0]=255&t,s[n+1]=t>>8,s[n+2]=255&e,s[n+3]=e>>8;for(let t=0;t<4;t++)s[n+4+t]=r[4*t+0]|r[4*t+1]<<2|r[4*t+2]<<4|r[4*t+3]<<6}function E(t,e,r,s,n){let i,a=C(t),o=C(e);a<=o?i=r.slice():([a,o]=[o,a],i=r.map((t=>0===t?1:1===t?0:t))),F(a,o,i,s,n)}function B(t,e,r,s,n){let i,a=C(t),o=C(e);a3&(1^t)))):i=a==o?new Array(16).fill(0):r.slice(),F(a,o,i,s,n)}class L{constructor(t,e,r){this.flags=r,this._count=0,this._transparent=!1,this._remap=[],this._weights=[],this._points=[];const s=0!=(1&this.flags),n=0!=(128&this.flags);for(let r=0;r<16;r++){if(0!=(e&1<=128||!s)){const e=this._remap[i],s=(t[4*r+3]+1)/256;this._weights[e]+=n?s:1,this._remap[r]=e;break}}else this._remap[r]=-1}for(let t=0;t-1===e?3:t));e.forEach(((t,s)=>e[s]=r[s]))}remapIndices(t,e){const r=this._remap.map((e=>-1===e?3:t[e]));e.forEach(((t,s)=>e[s]=r[s]))}}class X{constructor(t){this.colors=t,this.flags=t.flags}compress(t,e){0!=(1&this.flags)?(this.compress3(t,e),this.colors.transparent||this.compress4(t,e)):this.compress4(t,e)}compress3(t,e){}compress4(t,e){}}class D extends X{constructor(t){super(t);const e=t.points[0];this.color=e.colorInt,this.start=new z(0),this.end=new z(0),this.index=0,this.error=1/0,this.bestError=1/0}compressBase(t,e){if(this.computeEndPoints(t),this.errorE(r,s,n,t,e)))}compress4(t,e){const r=[R,I,R];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computeEndPoints(t){this.error=1/0;for(let e=0;e<2;e++){const r=[];let s=0;for(let n=0;n<3;n++){const i=t[n],a=this.color[n];r[n]=i[a][e];const o=r[n][2];s+=o*o}s{let r=1/0;const n=t.reduce(((t,s,n)=>{const i=z.sub(e,s).multVector(this.metric).lengthSq;return i>=r?t:(r=i,n)}),0);return s+=r,n}));if(sE(r,s,n,t,e)))}compress4(t,e){const r=[this.start.clone(),this.end.clone(),z.interpolate(this.start,this.end,1/3),z.interpolate(this.start,this.end,2/3)];this.compressBase(r,((r,s,n)=>B(r,s,n,t,e)))}computePoints(){const{count:t,points:e,weights:r}=this.colors;if(t<=0)return;const s=S(e,r);let n,i,a,o;n=i=e[0],a=o=z.dot(n,s);for(let r=1;ro&&(i=e[r],o=t)}this.start=n.clampGrid().clone(),this.end=i.clampGrid().clone()}}class j extends X{constructor(t){super(t);this.iterationCount=t.flags&w?8:1,this.bestError=1/0,this.metric=new V(1),0!=(32&this.flags)&&this.metric.set(.2126,.7152,.0722,0);const{points:e,weights:r}=this.colors;this.principle=S(e,r),this.order=new Uint8Array(128),this.pointsWeights=[],this.xSum_wSum=new V(0)}constructOrdering(t,e){const r=this.makeOrder(t);this.copyOrderToThisOrder(r,e);return!!this.checkOrderUnique(r,e)&&(this.copyOrderWeight(r),!0)}compress3(t,e){this.compressBase((t=>{let[e,,r,s]=t;const n=new V(.5,.5,.5,1/4),i=V.multiplyAdd(r,n,e),a=i.splatW,o=V.multiplyAdd(r,n,s);return{ax:i,aa:a,bx:o,bb:o.splatW,ab:V.multVector(r,n).splatW}}),((r,s,n)=>E(r,s,n,t,e)),2)}compress4(t,e){this.compressBase((t=>{let[e,r,s,n]=t;const i=new V(1/3,1/3,1/3,1/9),a=new V(2/3,2/3,2/3,4/9),o=new V(2/9),l=V.multiplyAdd(s,i,V.multiplyAdd(r,a,e)),u=l.splatW,c=V.multiplyAdd(r,i,V.multiplyAdd(s,a,n));return{ax:l,aa:u,bx:c,bb:c.splatW,ab:V.multVector(o,V.add(r,s)).splatW}}),((r,s,n)=>B(r,s,n,t,e)),3)}compressBase(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;this.constructOrdering(this.principle,0);let s={start:new V(0),end:new V(0),error:this.bestError,iteration:0,bestI:0,bestJ:0};3===r&&(s.bestK=0);const n=(e,r)=>{const n=t(e),i=this.computeOptimalPoints(n);return i.errorz.dot(e,t)));return Array.from({length:e},((t,e)=>e)).sort(((t,e)=>s[t]-s[e]!=0?s[t]-s[e]:t-e))}copyOrderToThisOrder(t,e){const r=16*e;t.forEach(((t,e)=>{this.order[r+e]=t}))}checkOrderUnique(t,e){const{count:r}=this.colors;for(let s=0;s2&&void 0!==arguments[2]?arguments[2]:2;const{count:s}=this.colors,n=(e,s,n)=>{const i={bestI:e,bestJ:2===r?n:s,iteration:t};return 3===r&&(i.bestK=n),i};let i=new V(0);for(let t=0;t15?15:e}function W(t,e,r,s){let n=N(t,e,5),i=N(t,e,7);n.error<=i.error?function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:t<=5?7-t:t)),e,r)}else G(s,n,i,e,r)}(n,r,s):function(t,e,r){let{min:s,max:n,indices:i}=t;if(s>n){G(n,s,i.map((t=>0===t?1:1===t?0:9-t)),e,r)}else G(s,n,i,e,r)}(i,r,s)}function N(t,e,r){let{min:s,max:n}=function(t,e,r){let s=255,n=0;for(let i=0;i<16;i++){if(0==(e&1<n&&(n=a)):(an&&(n=a))}s>n&&(s=n);n-sMath.floor(((r-(n+1))*t+(n+1)*e)/r)))];return 5===r&&(s[6]=0,s[7]=255),s}function G(t,e,r,s,n){s[n]=t,s[n+1]=e;let i=0,a=n+2;for(let t=0;t<2;t++){let t=0;for(let e=0;e<8;++e){t|=r[i]<<3*e,i++}for(let e=0;e<3;++e){let r=t>>8*e&255;s[a]=r,a++}}}function K(t){const e=t>>11&31,r=t>>5&63,s=31&t;return[e<<3|e>>2,r<<2|r>>4,s<<3|s>>2,255]}function J(t,e,r){const s=t.map(((t,s)=>Math.floor(t*(1-r)+e[s]*r)));return s[3]=255,s}function Y(t,e,r,s){const n=function(t,e,r){const s=t[e]|t[e+1]<<8,n=t[e+2]|t[e+3]<<8,i=K(s),a=K(n);return[i,a,J(i,a,r&&s<=n?.5:1/3),r&&s<=n?[0,0,0,0]:J(i,a,2/3)]}(e,r,s),i=function(t,e){let r=e+4,s=new Uint8Array(16);for(let e=0;e<4;e++){let n=t[r+e];s[4*e+0]=3&n,s[4*e+1]=n>>2&3,s[4*e+2]=n>>4&3,s[4*e+3]=n>>6&3}return s}(e,r);for(let e=0;e<16;e++)for(let r=0;r<4;r++)t[4*e+r]=n[i[e]][r]}function Z(t){for(let e=0;e<4;e++)for(let r=0;r<4;r++)t(r,e)}function H(t){let e=7&t,r=280&t,s=96&t;return 2!=e&&4!=e&&(e=1),16!=r&&r!=w&&(r=8),64!=s&&(s=32),e|r|s|128&t}function Q(t,e){let{x:r=0,y:s=0,width:n=0,height:i=0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=0;Z((function(o,l){let u=r+o,c=s+l;if(u>4}}(t,e,r):0!=(4&s)&&function(t,e,r){let s=e[r+0],n=e[r+1],i=q(s,n,s<=n?5:7),a=new Uint8Array(16),o=0,l=2;for(let t=0;t<2;t++){let t=0;for(let s=0;s<3;s++)t|=e[r+l]<<8*s,l++;for(let e=0;e<8;e++){let r=t>>3*e&7;a[o]=r,o++}}for(let e=0;e<16;++e)t[4*e+3]=i[a[e]]}(t,e,r)}function et(t,e,r,s,n){const i=0!=(1&(n=H(n)))?8:16;let a=0;!function(t,e,r){for(let s=0;s1&&void 0!==arguments[1]?arguments[1]:{};const i=new Uint8Array(64);let a=0,o=0;return Z((function(l,u){let c=e+l,h=r+u;if(c1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(4==n)c=at(c,i,a,rt);else if(5==n)c=at(c,i,a,st);else if(6==n)c=at(c,i,a,nt);else{if(2==n)throw new Error("Texture2D format type ECT1 not implemented!");if(0!=n)throw new Error("Non-implemented Texture2D format type (".concat(n,") found."))}for(let t=0;t")}parseTypeList(){return[this.type,...this.reader.parseTypeList()]}},t.BaseReader=e,t.BmFontReader=class extends e{static isTypeOf(t){return"BmFont.XmlSourceReader"===t}read(t){const e=(new a).read(t);return{export:{type:this.type,data:e}}}write(t,e,r){this.writeIndex(t,r);(new a).write(t,e.export.data,null)}isValueType(){return!1}},t.BooleanReader=o,t.CharReader=l,t.DictionaryReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.DictionaryReader"===t}static hasSubType(){return!0}constructor(t,e){if(null==t||null==e)throw new Error("Cannot create instance of DictionaryReader without Key and Value.");super(),this.key=t,this.value=e}read(t,e){let s={};const n=(new r).read(t);for(let r=0;r")}parseTypeList(){return[this.type,...this.key.parseTypeList(),...this.value.parseTypeList()]}},t.DoubleReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.DoubleReader":case"System.Double":return!0;default:return!1}}read(t){return t.readDouble()}write(t,e,r){this.writeIndex(t,r),t.writeDouble(e)}},t.EffectReader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.EffectReader":case"Microsoft.Xna.Framework.Graphics.Effect":return!0;default:return!1}}read(t){const e=(new r).read(t),s=t.read(e);return{export:{type:this.type,data:s}}}write(t,e,s){this.writeIndex(t,s);const n=e.export.data;(new r).write(t,n.byteLength,null),t.concat(n)}isValueType(){return!1}},t.Int32Reader=u,t.LightweightTexture2DReader=class extends e{static isTypeOf(t){return"Microsoft.Xna.Framework.Content.Texture2DReader"===t}static type(){return"Texture2D"}read(t){const e=new u,s=new r;let n=e.read(t),i=s.read(t),a=s.read(t),o=s.read(t);o>1&&console.warn("Found mipcount of ".concat(o,", only the first will be used."));let l=s.read(t),c=t.read(l);if(0!=n)throw new Error("Compressed texture format is not supported!");for(let t=0;t","Rectangle","List","Rectangle","List","Char",null,null,"List","Vector3","Nullable","Char"]}read(t,e){const r=new u,s=new p,n=new h(new l);return{texture:e.read(t),glyphs:e.read(t),cropping:e.read(t),characterMap:e.read(t),verticalLineSpacing:r.read(t),horizontalSpacing:s.read(t),kerning:e.read(t),defaultCharacter:n.read(t)}}write(t,e,r){const s=new u,n=new l,i=new p,a=new h(n),o=new ot,w=new c(new d),f=new c(n),y=new c(new lt);this.writeIndex(t,r);try{o.write(t,e.texture,r),t.alloc(1e5),w.write(t,e.glyphs,r),w.write(t,e.cropping,r),f.write(t,e.characterMap,r),s.write(t,e.verticalLineSpacing,null),i.write(t,e.horizontalSpacing,null),y.write(t,e.kerning,r),a.write(t,e.defaultCharacter,null)}catch(t){throw t}}isValueType(){return!1}},t.StringReader=a,t.TBinReader=class extends e{static isTypeOf(t){return"xTile.Pipeline.TideReader"===t}read(t){let e=(new u).read(t),r=t.read(e);return{export:{type:this.type,data:r}}}write(t,e,r){this.writeIndex(t,r);const s=e.export.data;(new u).write(t,s.byteLength,null),t.concat(s)}isValueType(){return!1}},t.Texture2DReader=ot,t.UInt32Reader=r,t.Vector2Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector2Reader":case"Microsoft.Xna.Framework.Vector2":return!0;default:return!1}}read(t){const e=new p;return{x:e.read(t),y:e.read(t)}}},t.Vector3Reader=lt,t.Vector4Reader=class extends e{static isTypeOf(t){switch(t){case"Microsoft.Xna.Framework.Content.Vector4Reader":case"Microsoft.Xna.Framework.Vector4":return!0;default:return!1}}read(t){const e=new p;return{x:e.read(t),y:e.read(t),z:e.read(t),w:e.read(t)}}},Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/src/readers/dist/readers.module.js b/src/readers/dist/readers.module.js index e81fa92..070d6bd 100644 --- a/src/readers/dist/readers.module.js +++ b/src/readers/dist/readers.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + class BaseReader { static isTypeOf(type) { return false; @@ -8,8 +17,7 @@ class BaseReader { } static parseTypeList() { - let subtype = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - return [this.type(), ...subtype]; + return [this.type()]; } static type() { @@ -40,6 +48,10 @@ class BaseReader { return this.type; } + parseTypeList() { + return this.constructor.parseTypeList(); + } + } class UInt32Reader extends BaseReader { @@ -114,6 +126,10 @@ class ArrayReader extends BaseReader { return "Array<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } const UTF16_BITES = [0xD800, 0xDC00]; @@ -331,6 +347,10 @@ class DictionaryReader extends BaseReader { return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); } + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + } class DoubleReader extends BaseReader { @@ -469,6 +489,10 @@ class ListReader extends BaseReader { return "List<".concat(this.reader.type, ">"); } + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + } class NullableReader extends BaseReader { @@ -506,14 +530,14 @@ class NullableReader extends BaseReader { return this.reader.read(buffer); } - return this.reader.isValueType() ? resolver.read(buffer) : this.reader.read(buffer); + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); } write(buffer) { let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - if (content !== null) { + if (content === null) { buffer.writeByte(0); return; } @@ -530,6 +554,11 @@ class NullableReader extends BaseReader { return "Nullable<".concat(this.reader.type, ">"); } + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + } class ReflectiveReader extends BaseReader { @@ -558,7 +587,6 @@ class ReflectiveReader extends BaseReader { } write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); } @@ -570,6 +598,10 @@ class ReflectiveReader extends BaseReader { return "".concat(this.reader.type); } + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + } class RectangleReader extends BaseReader { @@ -2511,8 +2543,6 @@ class SpriteFontReader extends BaseReader { } catch (ex) { throw ex; } - - console.log("writing complitd!"); } isValueType() { From bac7fff1452de7a313dd520110fc9c150392e695 Mon Sep 17 00:00:00 2001 From: lybell Date: Wed, 25 May 2022 16:07:49 +0900 Subject: [PATCH 08/11] add readme for each packages --- api-ko.md | 34 + api.md | 34 + dist/plugins/stardewvalley/index.es5.min.js | 2 +- dist/plugins/stardewvalley/index.min.js | 2 +- dist/plugins/stardewvalley/index.module.js | 30 + docs/css/style.css | 7 +- docs/index.html | 16 +- .../xnb-core.module.js} | 2919 +++-------------- docs/js/libs/plugins/xnb-stardew.module.js | 1396 ++++++++ docs/js/libs/readers/xnb-readers.module.js | 2722 +++++++++++++++ docs/js/libs/src/App/BufferReader.js | 556 ---- docs/js/libs/src/App/BufferWriter.js | 208 -- .../src/App/Decompressor/LZXDecompressor.js | 88 - docs/js/libs/src/App/Decompressor/Lz4.js | 572 ---- docs/js/libs/src/App/Decompressor/Lzx.js | 769 ----- docs/js/libs/src/App/Decompressor/dxt.js | 327 -- .../App/Decompressor/dxt/alphaCompressor.js | 213 -- .../src/App/Decompressor/dxt/colorBlock.js | 111 - .../src/App/Decompressor/dxt/colorFits.js | 744 ----- .../libs/src/App/Decompressor/dxt/constant.js | 21 - .../src/App/Decompressor/dxt/decompressor.js | 163 - docs/js/libs/src/App/Decompressor/dxt/eigs.js | 162 - .../libs/src/App/Decompressor/dxt/lookup.js | 1041 ------ docs/js/libs/src/App/Decompressor/dxt/math.js | 448 --- .../js/libs/src/App/Decompressor/lz4/utils.js | 59 - .../js/libs/src/App/Decompressor/lz4/xxh32.js | 102 - docs/js/libs/src/App/ReaderResolver.js | 58 - docs/js/libs/src/App/Readers/ArrayReader.js | 87 - docs/js/libs/src/App/Readers/BaseReader.js | 80 - docs/js/libs/src/App/Readers/BmFontReader.js | 48 - docs/js/libs/src/App/Readers/BooleanReader.js | 40 - docs/js/libs/src/App/Readers/CharReader.js | 50 - .../libs/src/App/Readers/DictionaryReader.js | 106 - docs/js/libs/src/App/Readers/DoubleReader.js | 30 - docs/js/libs/src/App/Readers/EffectReader.js | 41 - docs/js/libs/src/App/Readers/Int32Reader.js | 30 - docs/js/libs/src/App/Readers/ListReader.js | 55 - .../js/libs/src/App/Readers/NullableReader.js | 62 - docs/js/libs/src/App/Readers/Readers.js | 48 - .../libs/src/App/Readers/RectangleReader.js | 42 - .../libs/src/App/Readers/ReflectiveReader.js | 29 - docs/js/libs/src/App/Readers/SingleReader.js | 23 - .../libs/src/App/Readers/SpriteFontReader.js | 84 - docs/js/libs/src/App/Readers/StringReader.js | 45 - docs/js/libs/src/App/Readers/TBinReader.js | 35 - .../libs/src/App/Readers/Texture2DReader.js | 113 - docs/js/libs/src/App/Readers/UInt32Reader.js | 30 - docs/js/libs/src/App/Readers/Vector2Reader.js | 24 - docs/js/libs/src/App/Readers/Vector3Reader.js | 33 - docs/js/libs/src/App/Readers/Vector4Reader.js | 25 - docs/js/libs/src/App/TypeReader.js | 174 - docs/js/libs/src/App/Xnb.js | 377 --- docs/js/libs/src/App/XnbData.js | 90 - docs/js/libs/src/Files.js | 280 -- docs/js/libs/src/Utils/Debug.js | 16 - docs/js/libs/src/Utils/UTF8ToString.js | 183 -- docs/js/libs/src/Utils/XnbError.js | 8 - docs/js/libs/src/Utils/xnbNodeConverter.js | 279 -- docs/js/libs/src/XnbUnpacker.js | 197 -- docs/js/libs/src/es5.js | 7 - docs/js/libs/src/libs/jsonToYaml.js | 220 -- docs/js/libs/src/libs/png.js | 1 - docs/js/libs/unpackWorker.js | 3 +- docs/js/libs/xnb.js | 39 + docs/js/pack.js | 29 +- docs/js/unpack.js | 7 +- docs/js/workerHelper.js | 2 +- src/core/readme.md | 16 + src/plugins-stardewvalley/LICENSE | 165 + src/plugins-stardewvalley/LICENSE-GPL.md | 674 ++++ .../Readers/RectReader.js | 9 + src/plugins-stardewvalley/dist/index.cjs | 30 + src/plugins-stardewvalley/dist/index.js | 30 + src/plugins-stardewvalley/dist/index.min.js | 2 +- .../dist/index.module.js | 30 + src/plugins-stardewvalley/package.json | 24 + src/plugins-stardewvalley/readme.md | 53 + src/readers/package.json | 2 +- src/readers/readme.md | 66 + 79 files changed, 5818 insertions(+), 11159 deletions(-) rename docs/js/libs/{xnb.module.js => core/xnb-core.module.js} (63%) create mode 100644 docs/js/libs/plugins/xnb-stardew.module.js create mode 100644 docs/js/libs/readers/xnb-readers.module.js delete mode 100644 docs/js/libs/src/App/BufferReader.js delete mode 100644 docs/js/libs/src/App/BufferWriter.js delete mode 100644 docs/js/libs/src/App/Decompressor/LZXDecompressor.js delete mode 100644 docs/js/libs/src/App/Decompressor/Lz4.js delete mode 100644 docs/js/libs/src/App/Decompressor/Lzx.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/alphaCompressor.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/colorBlock.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/colorFits.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/constant.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/decompressor.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/eigs.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/lookup.js delete mode 100644 docs/js/libs/src/App/Decompressor/dxt/math.js delete mode 100644 docs/js/libs/src/App/Decompressor/lz4/utils.js delete mode 100644 docs/js/libs/src/App/Decompressor/lz4/xxh32.js delete mode 100644 docs/js/libs/src/App/ReaderResolver.js delete mode 100644 docs/js/libs/src/App/Readers/ArrayReader.js delete mode 100644 docs/js/libs/src/App/Readers/BaseReader.js delete mode 100644 docs/js/libs/src/App/Readers/BmFontReader.js delete mode 100644 docs/js/libs/src/App/Readers/BooleanReader.js delete mode 100644 docs/js/libs/src/App/Readers/CharReader.js delete mode 100644 docs/js/libs/src/App/Readers/DictionaryReader.js delete mode 100644 docs/js/libs/src/App/Readers/DoubleReader.js delete mode 100644 docs/js/libs/src/App/Readers/EffectReader.js delete mode 100644 docs/js/libs/src/App/Readers/Int32Reader.js delete mode 100644 docs/js/libs/src/App/Readers/ListReader.js delete mode 100644 docs/js/libs/src/App/Readers/NullableReader.js delete mode 100644 docs/js/libs/src/App/Readers/Readers.js delete mode 100644 docs/js/libs/src/App/Readers/RectangleReader.js delete mode 100644 docs/js/libs/src/App/Readers/ReflectiveReader.js delete mode 100644 docs/js/libs/src/App/Readers/SingleReader.js delete mode 100644 docs/js/libs/src/App/Readers/SpriteFontReader.js delete mode 100644 docs/js/libs/src/App/Readers/StringReader.js delete mode 100644 docs/js/libs/src/App/Readers/TBinReader.js delete mode 100644 docs/js/libs/src/App/Readers/Texture2DReader.js delete mode 100644 docs/js/libs/src/App/Readers/UInt32Reader.js delete mode 100644 docs/js/libs/src/App/Readers/Vector2Reader.js delete mode 100644 docs/js/libs/src/App/Readers/Vector3Reader.js delete mode 100644 docs/js/libs/src/App/Readers/Vector4Reader.js delete mode 100644 docs/js/libs/src/App/TypeReader.js delete mode 100644 docs/js/libs/src/App/Xnb.js delete mode 100644 docs/js/libs/src/App/XnbData.js delete mode 100644 docs/js/libs/src/Files.js delete mode 100644 docs/js/libs/src/Utils/Debug.js delete mode 100644 docs/js/libs/src/Utils/UTF8ToString.js delete mode 100644 docs/js/libs/src/Utils/XnbError.js delete mode 100644 docs/js/libs/src/Utils/xnbNodeConverter.js delete mode 100644 docs/js/libs/src/XnbUnpacker.js delete mode 100644 docs/js/libs/src/es5.js delete mode 100644 docs/js/libs/src/libs/jsonToYaml.js delete mode 100644 docs/js/libs/src/libs/png.js create mode 100644 docs/js/libs/xnb.js create mode 100644 src/core/readme.md create mode 100644 src/plugins-stardewvalley/LICENSE create mode 100644 src/plugins-stardewvalley/LICENSE-GPL.md create mode 100644 src/plugins-stardewvalley/package.json create mode 100644 src/plugins-stardewvalley/readme.md create mode 100644 src/readers/readme.md diff --git a/api-ko.md b/api-ko.md index 9632ce5..289e9ab 100644 --- a/api-ko.md +++ b/api-ko.md @@ -96,9 +96,15 @@ XnbData를 Blob 배열로 반환합니다. 형식은 unpackToFiles과 동일합 ### pack( files : Flielist/Array, configs : Object ) - ``files`` (Filelist/Array) : xnb로 묶을 파일의 전체 리스트. json 파일 혹은 yaml 파일이 포함되어 있어야 합니다. - ``configs`` (Object) : 컨피그 설정 + - ``compression`` (String) : 압축 방식입니다. 기본값은 ``"default"``입니다. - ``debug`` (Boolean) : `true`로 설정할 시, 모든 파일의 성공 및 실패 결과가 반환됩니다. 패킹할 파일들이 들어 있는 리스트를 받아, 각각의 파일들을 xnb 파일로 변환합니다. 헤더의 정보가 들어 있는 json 파일 혹은 yaml 파일(XnbExtract와 호환됨)이 포함되어 있어야 합니다. +xnb.js에서 현재 지원하는 압축 방식은 다음과 같습니다. +- `"default"` : 헤더에 명시된 압축 방식을 가급적 사용하도록 동작합니다. LZ4 압축 방식으로 명시된 파일은 LZ4 압축을 사용합니다. 현재 버전에는 LZX 압축 알고리즘이 구현되어 있지 않기 때문에, LZX 압축 방식으로 명시된 파일은 압축하지 않습니다. +- `"none"` : 압축하지 않은 결과를 반환합니다. +- `"LZ4"` : LZ4 압축 방식을 사용합니다. `"default"`에 비해 작은 파일 크기를 보장합니다. XnbExtract가 LZ4 압축 해제를 지원하지 않으므로, 이 설정을 사용하여 압축 해제된 파일은 XnbExtract에서 열 수 없습니다.(Stardew Valley에서는 열 수 있습니다.) + Pack 함수는 브라우저 환경에서는 `` 엘리먼트의 `files`를 바로 넣을 수 있으나, node.js 환경에서는 `FileList` 객체가 없으므로, 각 원소가 `{name, data}` 오브젝트인 배열을 매개변수로 넣어야 합니다. `name`은 파일의 이름을, `data`는 파일의 실제 바이너리 버퍼를 의미합니다. node.js 환경에서 pack 함수를 사용하기 위해서는 다음의 예제를 참조하십시오. ```js @@ -118,6 +124,34 @@ const result = await pack(fileList); console.log(result); ``` +## Reader Plugins + +### setReaders( readers : Object\ ) +- ``readers`` (ArrayBuffer) : Reader + +xnb.js에서 사용하는 리더의 종류를 지정합니다. 특정한 Reader만 사용하고 싶을 때 유용합니다. +``readers``의 key는 xnb 파일의 헤더가 인식 가능한 자료명+Reader로, value는 BaseReader를 상속한 리더 클래스가 들어가야 합니다. 다음의 예제를 참조하십시오. +```js +import {setReaders} from "@xnb/core"; +import {LightweightTexture2DReader, StringReader} from "@xnb/readers"; + +setReaders({ + Texture2DReader : LightweightTexture2DReader, + StringReader : StringReader +}); +``` + +### addReaders( readers : Object\ ) +- ``readers`` (ArrayBuffer) : Reader + +xnb.js에서 사용하는 리더를 추가합니다. 플러그인을 추가하고 싶을 때 유용합니다. 다음의 예제를 참조하십시오. +```js +import {addReaders} from "xnb"; +import * as StardewReader from "@xnb/stardew-valley"; + +addReaders({...StardewReader}); +``` + ## Data Structure ### XnbData XnbData 객체는 Xnb 파일에서 추출된 헤더와 리더 정보, 컨텐츠가 포함된 오브젝트입니다. unpackToXnbData(), bufferToXnb()의 반환값입니다. 라이브러리를 worker로 활용해서 데이터를 언팩할 때, json 데이터를 XnbData 객체로 변환할 수 있습니다. diff --git a/api.md b/api.md index c961a28..8d25464 100644 --- a/api.md +++ b/api.md @@ -118,9 +118,15 @@ Convert XnbData to Files array. The format of the array is the same as that of ` ### pack( files : Flielist/Array, configs : Object ) - ``files`` (Filelist/Array) : A array of files to be packed to xnb. Json or yaml file must be included. - ``configs`` (Object) : configs + - ``compression`` (String) : Compression method. default is ``"default"``. - ``debug`` (Boolean) : If `true`, it returns the success and failure results of all files. Receive a list of files to pack and convert them into xnb files. The json or yaml file containing the information in the header must be included. Compatible with XnbExtract. +The compression methods currently supported by xnb.js are the following: +- `"default"` : Try to use the compression algorithm specified in the header. Files specified as LZ4 compression perform LZ4 compression. Because the LZX compression algorithm is not implemented, files specified as LZX compression are not compressed. +- `"none"` : Export the file with uncompressed data. +- `"LZ4"` : Use LZ4 compression. Ensure a smaller file size. Exported file is incompatible with XnbExtract because it cannot read xnb files compressed with LZ4. + You can directly put `Filelist` object in a browser environment. But in a node.js environment, there is no `FileList` object, so you must put an array whose elements are `{name, data}` objects as parameters. `name` means the name of the file and `data` means the actual binary buffer of the file. To use this in a node.js environment, see the following example: ```js @@ -140,6 +146,34 @@ const result = await pack(fileList); console.log(result); ``` +## Reader Plugins + +### setReaders( readers : Object\ ) +- ``readers`` (ArrayBuffer) : Reader + +Specifies the type of reader used by xnb.js. This is useful when you want to use only certain readers. +The key of ``readers`` should be a recognizable data name+Reader for the header of the xnb file, and the value should include the reader class that inherited the BaseReader. See the following example: +```js +import {setReaders} from "@xnb/core"; +import {LightweightTexture2DReader, StringReader} from "@xnb/readers"; + +setReaders({ + Texture2DReader : LightweightTexture2DReader, + StringReader : StringReader +}); +``` + +### addReaders( readers : Object\ ) +- ``readers`` (ArrayBuffer) : Reader + +Add the readers used by xnb.js. This is useful when you want to add plugins. See the following example: +```js +import {addReaders} from "xnb"; +import * as StardewReader from "@xnb/stardew-valley"; + +addReaders(StardewReader); +``` + ## Data Structure ### XnbData `XnbData` is the object included headers, readers data, and content data extracted from xnb file. `unpackToXnbData()`, and `bufferToXnb()` returns this. When unpacking xnb using the library as a worker, you can convert json data into XnbData objects. diff --git a/dist/plugins/stardewvalley/index.es5.min.js b/dist/plugins/stardewvalley/index.es5.min.js index 047d348..0077363 100644 --- a/dist/plugins/stardewvalley/index.es5.min.js +++ b/dist/plugins/stardewvalley/index.es5.min.js @@ -6,4 +6,4 @@ * xnb.js is licensed under the LGPL 3.0 License. * */ -!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,r){"use strict";function t(e){this.wrapped=e}function n(e){var r,n;function a(r,n){try{var u=e[r](n),l=u.value,o=l instanceof t;Promise.resolve(o?l.wrapped:l).then((function(e){o?a("return"===r?"return":"next",e):i(u.done?"return":"normal",e)}),(function(e){a("throw",e)}))}catch(e){i("throw",e)}}function i(e,t){switch(e){case"return":r.resolve({value:t,done:!0});break;case"throw":r.reject(t);break;default:r.resolve({value:t,done:!1})}(r=r.next)?a(r.key,r.arg):n=null}this._invoke=function(e,t){return new Promise((function(i,u){var l={key:e,arg:t,resolve:i,reject:u,next:null};n?n=n.next=l:(r=n=l,a(e,t))}))},"function"!=typeof e.return&&(this.return=void 0)}function a(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function i(e,r){for(var t=0;t","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),f=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.StringReader),i=new r.NullableReader(new r.ListReader(new r.StringReader));return{ID:a.read(e,t),SheetIndex:n.read(e),Title:t.read(e),Description:t.read(e),Tags:i.read(e,t),Scenes:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader,u=new r.NullableReader(new r.StringReader),l=new r.NullableReader(new r.ListReader(new r.StringReader)),o=new r.ListReader(new R);this.writeIndex(e,n),u.write(e,t.ID,n),a.write(e,t.SheetIndex,null),i.write(e,t.Title,n),i.write(e,t.Description,n),l.write(e,t.Tags,n),o.write(e,t.Scenes,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieData"===e}},{key:"parseTypeList",value:function(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List"].concat(R.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),v=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader);return{ResponsePoint:n.read(e,t),Script:n.read(e,t)||"",Text:n.read(e,t)||""}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),a.write(e,t.ResponsePoint,n),a.write(e,t.Script,n),a.write(e,t.Text,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}},{key:"parseTypeList",value:function(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),S=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new v);return{BeforeMovie:n.read(e,t),DuringMovie:n.read(e,t),AfterMovie:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new v);this.writeIndex(e,n),a.write(e,t.BeforeMovie,n),a.write(e,t.DuringMovie,n),a.write(e,t.AfterMovie,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}},{key:"parseTypeList",value:function(){return["SpecialResponses","Nullable:7"].concat(v.parseTypeList(),["Nullable:7"],v.parseTypeList(),["Nullable:7"],v.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),g=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.ListReader(new r.StringReader)),i=new r.NullableReader(new S);return{Tag:t.read(e),Response:n.read(e,t)||"like",Whitelist:a.read(e,t)||[],SpecialResponses:i.read(e,t),ID:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.ListReader(new r.StringReader)),l=new r.NullableReader(new S);this.writeIndex(e,n),a.write(e,t.Tag,n),i.write(e,t.Response,n),u.write(e,t.Whitelist,n),l.write(e,t.SpecialResponses,n),a.write(e,t.ID,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieReaction"===e}},{key:"parseTypeList",value:function(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25"].concat(S.parseTypeList(),["String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),T=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new g));return{NPCName:t.read(e),Reactions:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new g));this.writeIndex(e,n),a.write(e,t.NPCName,n),i.write(e,t.Reactions,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}},{key:"parseTypeList",value:function(){return["MovieCharacterReaction","String","Nullable>:34","List"].concat(g.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),k=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.ListReader(new r.StringReader));return{ID:n.read(e),Name:t.read(e),DisplayName:t.read(e),Description:t.read(e),Price:n.read(e),ItemTags:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader,u=new r.NullableReader(new r.ListReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.ID,null),i.write(e,t.Name,n),i.write(e,t.DisplayName,n),i.write(e,t.Description,n),a.write(e,t.Price,null),u.write(e,t.ItemTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}},{key:"parseTypeList",value:function(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),m=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new r.StringReader));return{Name:t.read(e),LovedTags:n.read(e,t),LikedTags:n.read(e,t),DislikedTags:n.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.Name,n),i.write(e,t.LovedTags,n),i.write(e,t.LikedTags,n),i.write(e,t.DislikedTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}},{key:"parseTypeList",value:function(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),h=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.SingleReader;return{RequiredPopulation:n.read(e),Chance:Math.round(1e5*a.read(e))/1e5,ItemId:n.read(e),MinQuantity:n.read(e),MaxQuantity:n.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.SingleReader;this.writeIndex(e,n),a.write(e,t.RequiredPopulation,null),i.write(e,t.Chance,null),a.write(e,t.ItemId,null),a.write(e,t.MinQuantity,null),a.write(e,t.MaxQuantity,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}},{key:"parseTypeList",value:function(){return["FishPondReward",null,null,null,null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),b=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.NullableReader(new r.DictionaryReader(new r.Int32Reader,new r.ListReader(new r.StringReader)));return{RequiredTags:t.read(e),SpawnTime:n.read(e),ProducedItems:t.read(e),PopulationGates:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new r.StringReader),i=new r.Int32Reader,u=new r.ListReader(new h),l=new r.NullableReader(new r.DictionaryReader(new r.Int32Reader,new r.ListReader(new r.StringReader)));this.writeIndex(e,n),a.write(e,t.RequiredTags,n),i.write(e,t.SpawnTime,null),u.write(e,t.ProducedItems,n),l.write(e,t.PopulationGates,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondData"===e}},{key:"parseTypeList",value:function(){return["FishPondData","List","String",null,"List"].concat(h.parseTypeList(),["Nullable>>:4","Dictionary>","Int32","List","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),L=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new r.StringReader)),a=new r.NullableReader(new r.StringReader),i=new r.BooleanReader,u=new r.Int32Reader;return{FirstItemTags:n.read(e,t),SecondItemTags:n.read(e,t),SpendingRightItem:i.read(e),CraftedItemID:u.read(e),CraftedItemIDs:n.read(e,t),CraftedItemColor:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.NullableReader(new r.ListReader(new r.StringReader)),i=new r.NullableReader(new r.StringReader),u=new r.BooleanReader,l=new r.Int32Reader;this.writeIndex(e,n),a.write(e,t.FirstItemTags,n),a.write(e,t.SecondItemTags,n),u.write(e,t.SpendingRightItem,null),l.write(e,t.CraftedItemID,null),a.write(e,t.CraftedItemIDs,n),i.write(e,t.CraftedItemColor,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}},{key:"parseTypeList",value:function(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),D=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Key:r.read(e),Value:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader;this.writeIndex(e,n),a.write(e,t.Type,n),a.write(e,t.Key,n),a.write(e,t.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}},{key:"parseTypeList",value:function(){return["RenovationValue","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),I=function(e){l(t,e);var r=w(t);function t(){return a(this,t),r.apply(this,arguments)}return u(t,[{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return!!p(o(t),"isTypeOf",this).call(this,e)||"StardewValley.GameData.HomeRenovations.Rect"===e}},{key:"parseTypeList",value:function(){return["Rect"]}},{key:"type",value:function(){return"Reflective"}}]),t}(r.RectangleReader),N=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Rects:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new I);this.writeIndex(e,n),a.write(e,t.Rects,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}},{key:"parseTypeList",value:function(){return["RectGroup","List","Rect"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),O=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.BooleanReader,a=new r.NullableReader(new r.ListReader(new N)),i=new r.NullableReader(new r.StringReader);return{TextStrings:t.read(e),AnimationType:t.read(e),CheckForObstructions:n.read(e),Requirements:t.read(e),RenovateActions:t.read(e),RectGroups:a.read(e,t),SpecialRect:i.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.BooleanReader,i=new r.StringReader,u=new r.ListReader(new D),l=new r.NullableReader(new r.ListReader(new N)),o=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),i.write(e,t.TextStrings,n),i.write(e,t.AnimationType,n),a.write(e,t.CheckForObstructions,null),u.write(e,t.Requirements,n),u.write(e,t.RenovateActions,n),l.write(e,t.RectGroups,n),o.write(e,t.SpecialRect,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}},{key:"parseTypeList",value:function(){return["HomeRenovation","String","String",null,"List"].concat(D.parseTypeList(),["List"],D.parseTypeList(),["Nullable>:4","List"],N.parseTypeList(),["Nullable","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),B=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader;return{Name:t.read(e),Index:n.read(e),Sprite:t.read(e),Color:t.read(e),Items:t.read(e),Pick:n.read(e),RequiredItems:n.read(e),Reward:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.StringReader;this.writeIndex(e,n),i.write(e,t.Name,n),a.write(e,t.Index,null),i.write(e,t.Sprite,n),i.write(e,t.Color,n),i.write(e,t.Items,n),a.write(e,t.Pick,null),a.write(e,t.RequiredItems,null),i.write(e,t.Reward,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleData"===e}},{key:"parseTypeList",value:function(){return["BundleData","String",null,"String","String","String",null,null,"String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),x=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Bundles:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.ListReader(new B);this.writeIndex(e,n),a.write(e,t.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleSetData"===e}},{key:"parseTypeList",value:function(){return["BundleSetData","List"].concat(B.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),V=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.ListReader(new x)),a=new r.NullableReader(new r.ListReader(new B));return{AreaName:t.read(e),Keys:t.read(e),BundleSets:n.read(e,t),Bundles:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.ListReader(new x)),u=new r.NullableReader(new r.ListReader(new B));this.writeIndex(e,n),a.write(e,t.AreaName,n),a.write(e,t.Keys,n),i.write(e,t.BundleSets,n),u.write(e,t.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomBundleData"===e}},{key:"parseTypeList",value:function(){return["RandomBundleData","String","String","Nullable>:13","List"].concat(x.parseTypeList(),["Nullable>:11","List"],B.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),M=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{RequiredTags:new r.NullableReader(new r.StringReader).read(e,t)||"",Value:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),i.write(e,t.RequiredTags,n),a.write(e,t.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElementItem"===e}},{key:"parseTypeList",value:function(){return["RandomizedElementItem","Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),C=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Name:r.read(e),Values:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.ListReader(new M);this.writeIndex(e,n),a.write(e,t.Name,n),i.write(e,t.Values,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElement"===e}},{key:"parseTypeList",value:function(){return["RandomizedElement","String","List"].concat(M.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),F=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Text:r.read(e),RequiredCount:r.read(e),Data:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.DictionaryReader(new r.StringReader,new r.StringReader);this.writeIndex(e,n),a.write(e,t.Type,n),a.write(e,t.Text,n),a.write(e,t.RequiredCount,n),i.write(e,t.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),P=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{Type:r.read(e),Data:r.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.DictionaryReader(new r.StringReader,new r.StringReader);this.writeIndex(e,n),a.write(e,t.Type,n),i.write(e,t.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),G=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.ListReader(new C));return{Name:t.read(e),Requester:t.read(e),Duration:t.read(e),Repeatable:n.read(e,t)||"False",RequiredTags:n.read(e,t)||"",OrderType:n.read(e,t)||"",SpecialRule:n.read(e,t)||"",Text:t.read(e),ItemToRemoveOnEnd:n.read(e,t),MailToRemoveOnEnd:n.read(e,t),RandomizedElements:a.read(e,t),Objectives:t.read(e),Rewards:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.ListReader(new C)),l=new r.ListReader(new F),o=new r.ListReader(new P);this.writeIndex(e,n),a.write(e,t.Name,n),a.write(e,t.Requester,n),a.write(e,t.Duration,n),i.write(e,t.Repeatable,n),i.write(e,t.RequiredTags,n),i.write(e,t.OrderType,n),i.write(e,t.SpecialRule,n),a.write(e,t.Text,n),i.write(e,t.ItemToRemoveOnEnd,n),i.write(e,t.MailToRemoveOnEnd,n),u.write(e,t.RandomizedElements,n),l.write(e,t.Objectives,n),o.write(e,t.Rewards,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List"].concat(C.parseTypeList(),["List"],F.parseTypeList(),["List"],P.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),j=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.NullableReader(new r.StringReader),a=new r.NullableReader(new r.DictionaryReader(new r.StringReader));return{ID:t.read(e),TooltipStringPath:t.read(e),MapName:t.read(e),IconTexture:n.read(e,t),WorldMapTexture:n.read(e,t),ModData:a.read(e,t)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.NullableReader(new r.StringReader),u=new r.NullableReader(new r.DictionaryReader(new r.StringReader));this.writeIndex(e,n),a.write(e,t.ID,n),a.write(e,t.TooltipStringPath,n),a.write(e,t.MapName,n),i.write(e,t.IconTexture,n),i.write(e,t.WorldMapTexture,n),u.write(e,t.ModData,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModFarmType"===e}},{key:"parseTypeList",value:function(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),E=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.SingleReader,i=new r.BooleanReader,u=new r.NullableReader(new r.StringReader);return{ID:t.read(e),LanguageCode:t.read(e),ButtonTexture:t.read(e),UseLatinFont:i.read(e),FontFile:u.read(e,t),FontPixelZoom:a.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:n.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:u.read(e,t),TimeFormat:t.read(e),ClockTimeFormat:t.read(e),ClockDateFormat:t.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.StringReader,i=new r.Int32Reader,u=new r.SingleReader,l=new r.BooleanReader,o=new r.NullableReader(new r.StringReader);this.writeIndex(e,n),a.write(e,t.ID,n),a.write(e,t.LanguageCode,n),a.write(e,t.ButtonTexture,n),l.write(e,t.UseLatinFont,null),o.write(e,t.FontFile,n),u.write(e,t.FontPixelZoom,null),l.write(e,t.FontApplyYOffset,null),i.write(e,t.SmallFontLineSpacing,null),l.write(e,t.UseGenderedCharacterTranslations,null),o.write(e,t.NumberComma,n),a.write(e,t.TimeFormat,n),a.write(e,t.ClockTimeFormat,n),a.write(e,t.ClockDateFormat,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModLanguage"===e}},{key:"parseTypeList",value:function(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader),q=function(e){l(n,e);var t=w(n);function n(){return a(this,n),t.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){var n=new r.Int32Reader,a=new r.BooleanReader;return{ID:t.read(e),Texture:t.read(e),IsFlooring:a.read(e),Count:n.read(e)}}},{key:"write",value:function(e,t,n){var a=new r.Int32Reader,i=new r.BooleanReader,u=new r.StringReader;this.writeIndex(e,n),u.write(e,t.ID,n),u.write(e,t.Texture,n),i.write(e,t.IsFlooring,null),a.write(e,t.Count,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}},{key:"parseTypeList",value:function(){return["ModWallpaperOrFlooring","String","String",null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(r.BaseReader);e.BundleDataReader=B,e.BundleSetDataReader=x,e.CharacterResponseReader=v,e.ConcessionItemDataReader=k,e.ConcessionTasteReader=m,e.FishPondDataReader=b,e.FishPondRewardReader=h,e.HomeRenovationReader=O,e.ModFarmTypeReader=j,e.ModLanguageReader=E,e.ModWallpaperOrFlooringReader=q,e.MovieCharacterReactionReader=T,e.MovieDataReader=f,e.MovieReactionReader=g,e.MovieSceneReader=R,e.RandomBundleDataReader=V,e.RandomizedElementItemReader=M,e.RandomizedElementReader=C,e.RectGroupReader=N,e.RectReader=I,e.RenovationValueReader=D,e.SpecialOrderDataReader=G,e.SpecialOrderObjectiveDataReader=F,e.SpecialOrderRewardDataReader=P,e.SpecialResponsesReader=S,e.TailorItemRecipeReader=L,Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";function r(e){this.wrapped=e}function n(e){var t,n;function a(t,n){try{var u=e[t](n),l=u.value,o=l instanceof r;Promise.resolve(o?l.wrapped:l).then((function(e){o?a("return"===t?"return":"next",e):i(u.done?"return":"normal",e)}),(function(e){a("throw",e)}))}catch(e){i("throw",e)}}function i(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?a(t.key,t.arg):n=null}this._invoke=function(e,r){return new Promise((function(i,u){var l={key:e,arg:r,resolve:i,reject:u,next:null};n?n=n.next=l:(t=n=l,a(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),f=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e,r),SheetIndex:n.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.Int32Reader,i=new t.StringReader,u=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new t.StringReader)),o=new t.ListReader(new R);this.writeIndex(e,n),u.write(e,r.ID,n),a.write(e,r.SheetIndex,null),i.write(e,r.Title,n),i.write(e,r.Description,n),l.write(e,r.Tags,n),o.write(e,r.Scenes,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieData"===e}},{key:"parseTypeList",value:function(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List"].concat(R.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),v=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.StringReader);return{ResponsePoint:n.read(e,r),Script:n.read(e,r)||"",Text:n.read(e,r)||""}}},{key:"write",value:function(e,r,n){var a=new t.NullableReader(new t.StringReader);this.writeIndex(e,n),a.write(e,r.ResponsePoint,n),a.write(e,r.Script,n),a.write(e,r.Text,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}},{key:"parseTypeList",value:function(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),S=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new v);return{BeforeMovie:n.read(e,r),DuringMovie:n.read(e,r),AfterMovie:n.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.NullableReader(new v);this.writeIndex(e,n),a.write(e,r.BeforeMovie,n),a.write(e,r.DuringMovie,n),a.write(e,r.AfterMovie,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}},{key:"parseTypeList",value:function(){return["SpecialResponses","Nullable:7"].concat(v.parseTypeList(),["Nullable:7"],v.parseTypeList(),["Nullable:7"],v.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),g=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.StringReader),a=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new S);return{Tag:r.read(e),Response:n.read(e,r)||"like",Whitelist:a.read(e,r)||[],SpecialResponses:i.read(e,r),ID:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.StringReader),u=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new S);this.writeIndex(e,n),a.write(e,r.Tag,n),i.write(e,r.Response,n),u.write(e,r.Whitelist,n),l.write(e,r.SpecialResponses,n),a.write(e,r.ID,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieReaction"===e}},{key:"parseTypeList",value:function(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25"].concat(S.parseTypeList(),["String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),k=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.ListReader(new g));return{NPCName:r.read(e),Reactions:n.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.ListReader(new g));this.writeIndex(e,n),a.write(e,r.NPCName,n),i.write(e,r.Reactions,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}},{key:"parseTypeList",value:function(){return["MovieCharacterReaction","String","Nullable>:34","List"].concat(g.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),T=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:n.read(e),ItemTags:a.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.Int32Reader,i=new t.StringReader,u=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,n),a.write(e,r.ID,null),i.write(e,r.Name,n),i.write(e,r.DisplayName,n),i.write(e,r.Description,n),a.write(e,r.Price,null),u.write(e,r.ItemTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}},{key:"parseTypeList",value:function(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),h=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:n.read(e,r),LikedTags:n.read(e,r),DislikedTags:n.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,n),a.write(e,r.Name,n),i.write(e,r.LovedTags,n),i.write(e,r.LikedTags,n),i.write(e,r.DislikedTags,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}},{key:"parseTypeList",value:function(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),m=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.SingleReader;return{RequiredPopulation:n.read(e),Chance:Math.round(1e5*a.read(e))/1e5,ItemId:n.read(e),MinQuantity:n.read(e),MaxQuantity:n.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,n),a.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),a.write(e,r.ItemId,null),a.write(e,r.MinQuantity,null),a.write(e,r.MaxQuantity,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}},{key:"parseTypeList",value:function(){return["FishPondReward",null,null,null,null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),b=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:n.read(e),ProducedItems:r.read(e),PopulationGates:a.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.ListReader(new t.StringReader),i=new t.Int32Reader,u=new t.ListReader(new m),l=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,n),a.write(e,r.RequiredTags,n),i.write(e,r.SpawnTime,null),u.write(e,r.ProducedItems,n),l.write(e,r.PopulationGates,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.FishPond.FishPondData"===e}},{key:"parseTypeList",value:function(){return["FishPondData","List","String",null,"List"].concat(m.parseTypeList(),["Nullable>>:4","Dictionary>","Int32","List","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),L=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.ListReader(new t.StringReader)),a=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,u=new t.Int32Reader;return{FirstItemTags:n.read(e,r),SecondItemTags:n.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:u.read(e),CraftedItemIDs:n.read(e,r),CraftedItemColor:a.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),u=new t.BooleanReader,l=new t.Int32Reader;this.writeIndex(e,n),a.write(e,r.FirstItemTags,n),a.write(e,r.SecondItemTags,n),u.write(e,r.SpendingRightItem,null),l.write(e,r.CraftedItemID,null),a.write(e,r.CraftedItemIDs,n),i.write(e,r.CraftedItemColor,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}},{key:"parseTypeList",value:function(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),D=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader;this.writeIndex(e,n),a.write(e,r.Type,n),a.write(e,r.Key,n),a.write(e,r.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}},{key:"parseTypeList",value:function(){return["RenovationValue","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),I=function(e){l(r,e);var t=w(r);function r(){return a(this,r),t.apply(this,arguments)}return u(r,[{key:"read",value:function(e){var t=p(o(r.prototype),"read",this).call(this,e);return{X:t.x,Y:t.y,Width:t.width,Height:t.height}}},{key:"write",value:function(e,t,n){var a=t.X,i=t.Y,u=t.Width,l=t.Height;p(o(r.prototype),"write",this).call(this,e,{x:a,y:i,width:u,height:l},n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return!!p(o(r),"isTypeOf",this).call(this,e)||"StardewValley.GameData.HomeRenovations.Rect"===e}},{key:"parseTypeList",value:function(){return["Rect"]}},{key:"type",value:function(){return"Reflective"}}]),r}(t.RectangleReader),N=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Rects:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.ListReader(new I);this.writeIndex(e,n),a.write(e,r.Rects,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}},{key:"parseTypeList",value:function(){return["RectGroup","List","Rect"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),O=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.BooleanReader,a=new t.NullableReader(new t.ListReader(new N)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:n.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:a.read(e,r),SpecialRect:i.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.BooleanReader,i=new t.StringReader,u=new t.ListReader(new D),l=new t.NullableReader(new t.ListReader(new N)),o=new t.NullableReader(new t.StringReader);this.writeIndex(e,n),i.write(e,r.TextStrings,n),i.write(e,r.AnimationType,n),a.write(e,r.CheckForObstructions,null),u.write(e,r.Requirements,n),u.write(e,r.RenovateActions,n),l.write(e,r.RectGroups,n),o.write(e,r.SpecialRect,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}},{key:"parseTypeList",value:function(){return["HomeRenovation","String","String",null,"List"].concat(D.parseTypeList(),["List"],D.parseTypeList(),["Nullable>:4","List"],N.parseTypeList(),["Nullable","String"])}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),x=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader;return{Name:r.read(e),Index:n.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:n.read(e),RequiredItems:n.read(e),Reward:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,n),i.write(e,r.Name,n),a.write(e,r.Index,null),i.write(e,r.Sprite,n),i.write(e,r.Color,n),i.write(e,r.Items,n),a.write(e,r.Pick,null),a.write(e,r.RequiredItems,null),i.write(e,r.Reward,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleData"===e}},{key:"parseTypeList",value:function(){return["BundleData","String",null,"String","String","String",null,null,"String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),B=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Bundles:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.ListReader(new x);this.writeIndex(e,n),a.write(e,r.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.BundleSetData"===e}},{key:"parseTypeList",value:function(){return["BundleSetData","List"].concat(x.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),V=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.ListReader(new B)),a=new t.NullableReader(new t.ListReader(new x));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:n.read(e,r),Bundles:a.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.ListReader(new B)),u=new t.NullableReader(new t.ListReader(new x));this.writeIndex(e,n),a.write(e,r.AreaName,n),a.write(e,r.Keys,n),i.write(e,r.BundleSets,n),u.write(e,r.Bundles,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomBundleData"===e}},{key:"parseTypeList",value:function(){return["RandomBundleData","String","String","Nullable>:13","List"].concat(B.parseTypeList(),["Nullable>:11","List"],x.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),M=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,n),i.write(e,r.RequiredTags,n),a.write(e,r.Value,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElementItem"===e}},{key:"parseTypeList",value:function(){return["RandomizedElementItem","Nullable","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),C=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Name:t.read(e),Values:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.ListReader(new M);this.writeIndex(e,n),a.write(e,r.Name,n),i.write(e,r.Values,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.RandomizedElement"===e}},{key:"parseTypeList",value:function(){return["RandomizedElement","String","List"].concat(M.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),F=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,n),a.write(e,r.Type,n),a.write(e,r.Text,n),a.write(e,r.RequiredCount,n),i.write(e,r.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),P=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,t){return{Type:t.read(e),Data:t.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,n),a.write(e,r.Type,n),i.write(e,r.Data,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),G=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.StringReader),a=new t.NullableReader(new t.ListReader(new C));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:n.read(e,r)||"False",RequiredTags:n.read(e,r)||"",OrderType:n.read(e,r)||"",SpecialRule:n.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:n.read(e,r),MailToRemoveOnEnd:n.read(e,r),RandomizedElements:a.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.StringReader),u=new t.NullableReader(new t.ListReader(new C)),l=new t.ListReader(new F),o=new t.ListReader(new P);this.writeIndex(e,n),a.write(e,r.Name,n),a.write(e,r.Requester,n),a.write(e,r.Duration,n),i.write(e,r.Repeatable,n),i.write(e,r.RequiredTags,n),i.write(e,r.OrderType,n),i.write(e,r.SpecialRule,n),a.write(e,r.Text,n),i.write(e,r.ItemToRemoveOnEnd,n),i.write(e,r.MailToRemoveOnEnd,n),u.write(e,r.RandomizedElements,n),l.write(e,r.Objectives,n),o.write(e,r.Rewards,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.SpecialOrderData"===e}},{key:"parseTypeList",value:function(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List"].concat(C.parseTypeList(),["List"],F.parseTypeList(),["List"],P.parseTypeList())}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),j=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.NullableReader(new t.StringReader),a=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:n.read(e,r),WorldMapTexture:n.read(e,r),ModData:a.read(e,r)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.NullableReader(new t.StringReader),u=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,n),a.write(e,r.ID,n),a.write(e,r.TooltipStringPath,n),a.write(e,r.MapName,n),i.write(e,r.IconTexture,n),i.write(e,r.WorldMapTexture,n),u.write(e,r.ModData,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModFarmType"===e}},{key:"parseTypeList",value:function(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),E=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.SingleReader,i=new t.BooleanReader,u=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:u.read(e,r),FontPixelZoom:a.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:n.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:u.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.StringReader,i=new t.Int32Reader,u=new t.SingleReader,l=new t.BooleanReader,o=new t.NullableReader(new t.StringReader);this.writeIndex(e,n),a.write(e,r.ID,n),a.write(e,r.LanguageCode,n),a.write(e,r.ButtonTexture,n),l.write(e,r.UseLatinFont,null),o.write(e,r.FontFile,n),u.write(e,r.FontPixelZoom,null),l.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),l.write(e,r.UseGenderedCharacterTranslations,null),o.write(e,r.NumberComma,n),a.write(e,r.TimeFormat,n),a.write(e,r.ClockTimeFormat,n),a.write(e,r.ClockDateFormat,n)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModLanguage"===e}},{key:"parseTypeList",value:function(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader),q=function(e){l(n,e);var r=w(n);function n(){return a(this,n),r.apply(this,arguments)}return u(n,[{key:"read",value:function(e,r){var n=new t.Int32Reader,a=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:a.read(e),Count:n.read(e)}}},{key:"write",value:function(e,r,n){var a=new t.Int32Reader,i=new t.BooleanReader,u=new t.StringReader;this.writeIndex(e,n),u.write(e,r.ID,n),u.write(e,r.Texture,n),i.write(e,r.IsFlooring,null),a.write(e,r.Count,null)}},{key:"isValueType",value:function(){return!1}}],[{key:"isTypeOf",value:function(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}},{key:"parseTypeList",value:function(){return["ModWallpaperOrFlooring","String","String",null,null]}},{key:"type",value:function(){return"Reflective"}}]),n}(t.BaseReader);e.BundleDataReader=x,e.BundleSetDataReader=B,e.CharacterResponseReader=v,e.ConcessionItemDataReader=T,e.ConcessionTasteReader=h,e.FishPondDataReader=b,e.FishPondRewardReader=m,e.HomeRenovationReader=O,e.ModFarmTypeReader=j,e.ModLanguageReader=E,e.ModWallpaperOrFlooringReader=q,e.MovieCharacterReactionReader=k,e.MovieDataReader=f,e.MovieReactionReader=g,e.MovieSceneReader=R,e.RandomBundleDataReader=V,e.RandomizedElementItemReader=M,e.RandomizedElementReader=C,e.RectGroupReader=N,e.RectReader=I,e.RenovationValueReader=D,e.SpecialOrderDataReader=G,e.SpecialOrderObjectiveDataReader=F,e.SpecialOrderRewardDataReader=P,e.SpecialResponsesReader=S,e.TailorItemRecipeReader=L,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/dist/plugins/stardewvalley/index.min.js b/dist/plugins/stardewvalley/index.min.js index d1a388c..06ab7b5 100644 --- a/dist/plugins/stardewvalley/index.min.js +++ b/dist/plugins/stardewvalley/index.min.js @@ -6,4 +6,4 @@ * xnb.js is licensed under the LGPL 3.0 License. * */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),u=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),u.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...w.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new w),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=u,e.FishPondDataReader=R,e.FishPondRewardReader=w,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=f,e.ModWallpaperOrFlooringReader=x,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),w=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),w.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...u.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new u),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}read(e){const{x:t,y:r,width:a,height:n}=super.read(e);return{X:t,Y:r,Width:a,Height:n}}write(e,t,r){const{X:a,Y:n,Width:i,Height:l}=t;super.write(e,{x:a,y:n,width:i,height:l},r)}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=w,e.FishPondDataReader=R,e.FishPondRewardReader=u,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=x,e.ModWallpaperOrFlooringReader=f,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/dist/plugins/stardewvalley/index.module.js b/dist/plugins/stardewvalley/index.module.js index 68f9d01..84fab53 100644 --- a/dist/plugins/stardewvalley/index.module.js +++ b/dist/plugins/stardewvalley/index.module.js @@ -661,6 +661,36 @@ class RectReader extends RectangleReader { return "Reflective"; } + read(buffer) { + const { + x, + y, + width, + height + } = super.read(buffer); + return { + X: x, + Y: y, + Width: width, + Height: height + }; + } + + write(buffer, content, resolver) { + const { + X: x, + Y: y, + Width: width, + Height: height + } = content; + super.write(buffer, { + x, + y, + width, + height + }, resolver); + } + isValueType() { return false; } diff --git a/docs/css/style.css b/docs/css/style.css index 7fd9858..28eef4c 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -294,8 +294,8 @@ main::-webkit-scrollbar-track, .result-image-box::-webkit-scrollbar-track { width: 48%; height: 150px; display: flex; - flex-direction: row; - flex-wrap: wrap; + flex-direction: column; + flex-wrap: nowrap; align-content: space-between; } @@ -313,7 +313,7 @@ main::-webkit-scrollbar-track, .result-image-box::-webkit-scrollbar-track { padding: 10px; flex-direction: column; justify-content: flex-start; - gap: 0px; + gap: 20px; overflow: auto; border-width: 8px; @@ -330,6 +330,7 @@ main::-webkit-scrollbar-track, .result-image-box::-webkit-scrollbar-track { .controller-wrapper{ width: 100%; + height: unset; gap: 10px; flex-direction: column; justify-content: center; diff --git a/docs/index.html b/docs/index.html index 42f7ec9..851f174 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,19 @@
-

Pack XNB

+
+

Pack XNB

+
+
+
+ + +
+ Returns the xnb file using the LZ4 compression algorithm.
+ Guarantees a smaller file size, but incompatible with XnbExtractor. +
+
+
@@ -83,7 +95,7 @@
-

Web XNB Converter v1.0.5 | Made by Lybell | Credit to Leonblade - original code(xnbcil) developer

+

Web XNB Converter v1.1.0 | Made by Lybell | Credit to Leonblade - original code(xnbcil) developer

diff --git a/docs/js/libs/xnb.module.js b/docs/js/libs/core/xnb-core.module.js similarity index 63% rename from docs/js/libs/xnb.module.js rename to docs/js/libs/core/xnb-core.module.js index b0071d8..1b4d0ba 100644 --- a/docs/js/libs/xnb.module.js +++ b/docs/js/libs/core/xnb-core.module.js @@ -1,3 +1,12 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettled.bind(Promise) : function (promises) { let mappedPromises = promises.map(p => { return p.then(value => { @@ -15,11 +24,161 @@ const __promise_allSettled = Promise.allSettled !== undefined ? Promise.allSettl return Promise.all(mappedPromises); }; +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class XnbError extends Error { + constructor() { + let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + super(message); + this.name = "XnbError"; + this.message = message; + Error.captureStackTrace(this, XnbError); + } + +} + +function removeExternBracket(str) { + let bracketStack = []; + let result = []; + + for (let i = 0; i < str.length; i++) { + let c = str[i]; + if (c === "[") bracketStack.push(i);else if (c === "]") { + let startPoint = bracketStack.pop(); + if (startPoint === undefined) throw new Error("Invalid Bracket Form!"); + if (bracketStack.length === 0) result.push(str.slice(startPoint + 1, i)); + } + } + + return result; +} + +class TypeReader { + static setReaders(readers) { + TypeReader.readers = _objectSpread2({}, readers); + } + + static addReaders(readers) { + TypeReader.readers = _objectSpread2(_objectSpread2({}, TypeReader.readers), readers); + } + + static makeSimplied(type, reader) { + let simple = type.split(/`|,/)[0]; + + if (reader.isTypeOf(simple)) { + if (reader.hasSubType()) { + let subtypes = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reader.type(), "<").concat(subtypes.join(","), ">"); + } else return reader.type(); + } + + return null; + } + + static simplifyType(type) { + let simple = type.split(/`|,/)[0]; + let isArray = simple.endsWith('[]'); + if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); + + if (simple === 'Microsoft.Xna.Framework.Content.ReflectiveReader') { + let reflectiveType = TypeReader.parseSubtypes(type).map(TypeReader.simplifyType.bind(TypeReader)); + return "".concat(reflectiveType); + } + + for (let reader of Object.values(TypeReader.readers)) { + let result = TypeReader.makeSimplied(type, reader); + if (result !== null) return result; + } + + throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + } + + static parseSubtypes(type) { + let subtype = type.slice(type.search("`") + 1); + subtype[0]; + subtype = removeExternBracket(subtype)[0]; + let matches = removeExternBracket(subtype); + return matches; + } + + static getTypeInfo(type) { + let mainType = type.match(/[^<]+/)[0]; + let subtypes = type.match(/<(.+)>/); + subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; + return { + type: mainType, + subtypes + }; + } + + static getReaderTypeList(typeString) { + let reader = TypeReader.getReader(typeString); + return reader.parseTypeList(); + } + + static getReader(typeString) { + let { + type, + subtypes + } = TypeReader.getTypeInfo(typeString); + subtypes = subtypes.map(TypeReader.getReader.bind(TypeReader)); + if (TypeReader.readers.hasOwnProperty("".concat(type, "Reader"))) return new TypeReader.readers["".concat(type, "Reader")](...subtypes); + throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); + } + + static getReaderFromRaw(typeString) { + const simplified = TypeReader.simplifyType(typeString); + return TypeReader.getReader(simplified); + } + +} + +_defineProperty(TypeReader, "readers", {}); + const UTF8_FIRST_BITES = [0xC0, 0xE0, 0xF0]; const UTF8_SECOND_BITES = 0x80; const UTF8_MASK = 0b111111; -const UTF16_BITES = [0xD800, 0xDC00]; -const UTF16_MASK = 0b1111111111; +const UTF16_BITES$1 = [0xD800, 0xDC00]; +const UTF16_MASK$1 = 0b1111111111; function UTF8Encode(code) { if (code < 0x80) return [code]; @@ -31,7 +190,7 @@ function UTF8Encode(code) { function UTF16Encode(code) { if (code < 0xFFFF) return [code]; code -= 0x10000; - return [UTF16_BITES[0] | code >> 10 & UTF16_MASK, UTF16_BITES[1] | code & UTF16_MASK]; + return [UTF16_BITES$1[0] | code >> 10 & UTF16_MASK$1, UTF16_BITES$1[1] | code & UTF16_MASK$1]; } function UTF8Decode(codeSet) { @@ -50,17 +209,17 @@ function UTF8Decode(codeSet) { return ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + (codeSet[3] ^ UTF8_SECOND_BITES); } -function UTF16Decode(codeSet) { +function UTF16Decode$1(codeSet) { var _codeSet2; if (typeof codeSet === "number") codeSet = [codeSet]; if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); const codeSetRange = codeSet.length; if (codeSetRange === 1) return codeSet[0]; - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; + return ((codeSet[0] & UTF16_MASK$1) << 10) + (codeSet[1] & UTF16_MASK$1) + 0x10000; } -function stringToUnicode(str) { +function stringToUnicode$1(str) { const utf16Map = Array.from({ length: str.length }, (_, i) => str.charCodeAt(i)); @@ -70,11 +229,11 @@ function stringToUnicode(str) { while (index < str.length) { let code = utf16Map[index]; - if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + if ((UTF16_BITES$1[0] & code) !== UTF16_BITES$1[0]) { result.push(code); index++; } else { - result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + result.push(UTF16Decode$1(utf16Map.slice(index, index + 2))); index += 2; } } @@ -136,7 +295,7 @@ function UnicodeToString(unicodeArr) { } function stringToUTF8(str) { - return UnicodeToUTF8(stringToUnicode(str)); + return UnicodeToUTF8(stringToUnicode$1(str)); } function UTF8ToString(utf8Array) { @@ -568,17 +727,43 @@ class BufferWriter { } -class XnbError extends Error { - constructor() { - let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - super(message); - this.name = this.constructor.name; - this.message = message; - Error.captureStackTrace(this, XnbError); - } - -} - +/** @license + * + * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons + * which is derived from libmspack by Stuart Cole. + * + * (C) 2003-2004 Stuart Caie. + * (C) 2011 Ali Scissons. + * (C) 2017 James Stine. + * + * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. + * + * + * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 + * LzxDecoder is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License (LGPL) version 2.1 + * + * MICROSOFT PUBLIC LICENSE + * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). + * + * Redistribution and use in source and binary forms, with or without modification, + * is permitted provided that redistributions of the source code retain the above + * copyright notices and this file header. + * + * Additional copyright notices should be appended to the list above. + * + * For details, see . + * + * + * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been + * acknowleded properly as it should have been back in 2017. + * + * Resources: + * + * cabextract/libmspack - http://http://www.cabextract.org.uk/ + * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs + * + */ const MIN_MATCH = 2; const NUM_CHARS = 256; const BLOCKTYPE = { @@ -1074,6 +1259,9 @@ class LZ4Utils { } +/** @license + * Original Code by: https://github.com/Benzinga/lz4js/ + */ const minMatch = 4; const minLength = 13; const searchLimit = 5; @@ -1124,7 +1312,7 @@ function compressBound(n) { return n + n / 255 + 16 | 0; } -function decompressBlock$1(src, dst) { +function decompressBlock(src, dst) { let sIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; let sLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : src.length - 2 * sIndex; let dIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; @@ -1152,2531 +1340,223 @@ function decompressBlock$1(src, dst) { } } - if (sIndex >= sEnd) { - break; - } - - mLength = token & 0xf; - mOffset = src[sIndex++] | src[sIndex++] << 8; - - if (mLength === 0xf) { - while (true) { - mLength += src[sIndex]; - - if (src[sIndex++] !== 0xff) { - break; - } - } - } - - mLength += minMatch; - - if (hasCopyWithin && mOffset === 1) { - dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); - dIndex += mLength; - } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { - dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); - dIndex += mLength; - } else { - for (i = dIndex - mOffset, n = i + mLength; i < n;) { - dst[dIndex++] = dst[i++] | 0; - } - } - } - - return dIndex; -} - -function compressBlock(src, dst, sIndex, sLength, hashTable) { - var mIndex, mAnchor, mLength, mOffset, mStep; - var literalCount, dIndex, sEnd, n; - dIndex = 0; - sEnd = sLength + sIndex; - mAnchor = sIndex; - - if (sLength >= minLength) { - var searchMatchCount = (1 << skipTrigger) + 3; - - while (sIndex + minMatch < sEnd - searchLimit) { - var seq = LZ4Utils.readU32(src, sIndex); - var hash = LZ4Utils.hashU32(seq) >>> 0; - hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; - mIndex = hashTable[hash] - 1; - hashTable[hash] = sIndex + 1; - - if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { - mStep = searchMatchCount++ >> skipTrigger; - sIndex += mStep; - continue; - } - - searchMatchCount = (1 << skipTrigger) + 3; - literalCount = sIndex - mAnchor; - mOffset = sIndex - mIndex; - sIndex += minMatch; - mIndex += minMatch; - mLength = sIndex; - - while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { - sIndex++; - mIndex++; - } - - mLength = sIndex - mLength; - var token = mLength < mlMask ? mLength : mlMask; - - if (literalCount >= runMask) { - dst[dIndex++] = (runMask << mlBits) + token; - - for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - - dst[dIndex++] = n; - } else { - dst[dIndex++] = (literalCount << mlBits) + token; - } - - for (var i = 0; i < literalCount; i++) { - dst[dIndex++] = src[mAnchor + i]; - } - - dst[dIndex++] = mOffset; - dst[dIndex++] = mOffset >> 8; - - if (mLength >= mlMask) { - for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - - dst[dIndex++] = n; - } - - mAnchor = sIndex; - } - } - - if (mAnchor === 0) { - return 0; - } - - literalCount = sEnd - mAnchor; - - if (literalCount >= runMask) { - dst[dIndex++] = runMask << mlBits; - - for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - - dst[dIndex++] = n; - } else { - dst[dIndex++] = literalCount << mlBits; - } - - sIndex = mAnchor; - - while (sIndex < sEnd) { - dst[dIndex++] = src[sIndex++]; - } - - return dIndex; -} - -function compressSingleBlock(src, dst) { - clearHashTable(); - return compressBlock(src, dst, 0, src.length, hashTable); -} - -class ReaderResolver { - constructor(readers) { - this.readers = readers; - } - - read(buffer) { - let index = buffer.read7BitNumber() - 1; - if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); - return this.readers[index].read(buffer, this); - } - - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } - - getIndex(reader) { - for (let i in this.readers) if (reader.toString() == this.readers[i].toString()) return i; - } - -} - -class BaseReader { - isValueType() { - return true; - } - - get type() { - return this.constructor.name.slice(0, -6); - } - - read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - writeIndex(buffer, resolver) { - if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); - } - - toString() { - return this.type; - } - -} - -function UTF8Length(str) { - const codes = stringToUnicode(str); - return codes.reduce((sum, unicode) => { - if (unicode < 0x80) return sum + 1; - if (unicode < 0x800) return sum + 2; - if (unicode < 0x10000) return sum + 3; - return sum + 4; - }, 0); -} - -class StringReader extends BaseReader { - read(buffer) { - let length = buffer.read7BitNumber(); - return buffer.readString(length); - } - - write(buffer, string, resolver) { - this.writeIndex(buffer, resolver); - const size = UTF8Length(string); - buffer.write7BitNumber(size); - buffer.writeString(string); - } - - isValueType() { - return false; - } - -} - -class UInt32Reader extends BaseReader { - read(buffer) { - return buffer.readUInt32(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); - } - -} - -class ArrayReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } - - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - let size = uint32Reader.read(buffer); - let array = []; - - for (let i = 0; i < size; i++) { - let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - array.push(value); - } - - return array; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, resolver); - - for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); - } - - isValueType() { - return false; - } - - get type() { - return "Array<".concat(this.reader.type, ">"); - } - -} - -class BmFontReader extends BaseReader { - read(buffer) { - const stringReader = new StringReader(); - const xml = stringReader.read(buffer); - return { - export: { - type: this.type, - data: xml - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); - } - - isValueType() { - return false; - } - -} - -class BooleanReader extends BaseReader { - read(buffer) { - return Boolean(buffer.readInt()); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } - -} - -class CharReader extends BaseReader { - read(buffer) { - let charSize = this._getCharSize(buffer.peekInt()); - - return buffer.readString(charSize); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } - - _getCharSize(byte) { - return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; - } - -} - -class DictionaryReader extends BaseReader { - constructor(key, value) { - if (key == undefined || value == undefined) throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - super(); - this.key = key; - this.value = value; - } - - read(buffer, resolver) { - let dictionary = {}; - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - for (let i = 0; i < size; i++) { - let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - dictionary[key] = value; - } - - return dictionary; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(Object.keys(content).length); - - for (let key of Object.keys(content)) { - this.key.write(buffer, key, this.key.isValueType() ? null : resolver); - this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); - } - } - - isValueType() { - return false; - } - - get type() { - return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); - } - -} - -class DoubleReader extends BaseReader { - read(buffer) { - return buffer.readDouble(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } - -} - -class EffectReader extends BaseReader { - read(buffer) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const bytecode = buffer.read(size); - return { - export: { - type: this.type, - data: bytecode - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } - - isValueType() { - return false; - } - -} - -class Int32Reader extends BaseReader { - read(buffer) { - return buffer.readInt32(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); - } - -} - -class ListReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } - - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - const list = []; - - for (let i = 0; i < size; i++) { - const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } - - return list; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); - - for (let data of Object.values(content)) { - this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); - } - } - - get type() { - return "List<".concat(this.reader.type, ">"); - } - -} - -class NullableReader extends BaseReader { - constructor(reader) { - super(); - this.reader = reader; - } - - read(buffer, resolver) { - const booleanReader = new BooleanReader(); - const hasValue = booleanReader.read(buffer); - return hasValue ? this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer) : null; - } - - write(buffer, content, resolver) { - buffer.writeByte(content != null); - if (content != null) this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); - } - - isValueType() { - return false; - } - - get type() { - return "Nullable<".concat(this.reader.type, ">"); - } - -} - -class RectangleReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const x = int32Reader.read(buffer); - const y = int32Reader.read(buffer); - const width = int32Reader.read(buffer); - const height = int32Reader.read(buffer); - return { - x, - y, - width, - height - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); - } - -} - -class SingleReader extends BaseReader { - read(buffer) { - return buffer.readSingle(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); - } - -} - -const kDxt1 = 1 << 0; -const kDxt3 = 1 << 1; -const kDxt5 = 1 << 2; -const kColourIterativeClusterFit = 1 << 8; -const kColourClusterFit = 1 << 3; -const kColourRangeFit = 1 << 4; -const kColourMetricPerceptual = 1 << 5; -const kColourMetricUniform = 1 << 6; -const kWeightColourByAlpha = 1 << 7; - -function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); - - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); - } - - return keys; -} - -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - - return target; -} - -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } - - return obj; -} - -function Rot(theta) { - let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; - return Mat; -} - -function Rij(k, l, theta, N) { - let Mat = Array(N); - - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } - - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = (i === j) * 1.0; - } - } - - let Rotij = Rot(theta); - Mat[k][k] = Rotij[0][0]; - Mat[l][l] = Rotij[1][1]; - Mat[k][l] = Rotij[0][1]; - Mat[l][k] = Rotij[1][0]; - return Mat; -} - -function getTheta(aii, ajj, aij) { - let th = 0.0; - let denom = ajj - aii; - - if (Math.abs(denom) <= 1E-12) { - th = Math.PI / 4.0; - } else { - th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); - } - - return th; -} - -function getAij(Mij) { - let N = Mij.length; - let maxMij = 0.0; - let maxIJ = [0, 1]; - - for (let i = 0; i < N; i++) { - for (let j = i + 1; j < N; j++) { - if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { - maxMij = Math.abs(Mij[i][j]); - maxIJ = [i, j]; - } - } - } - - return [maxIJ, maxMij]; -} - -function unitary(U, H) { - let N = U.length; - let Mat = Array(N); - - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } - - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; - - for (let k = 0; k < N; k++) { - for (let l = 0; l < N; l++) { - Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; - } - } - } - } - - return Mat; -} - -function AxB(A, B) { - let N = A.length; - let Mat = Array(N); - - for (let i = 0; i < N; i++) { - Mat[i] = Array(N); - } - - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Mat[i][j] = 0; - - for (let k = 0; k < N; k++) { - Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; - } - } - } - - return Mat; -} - -function eigens(Hij) { - let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; - let N = Hij.length; - let Ei = Array(N); - let e0 = Math.abs(convergence / N); - let Sij = Array(N); - - for (let i = 0; i < N; i++) { - Sij[i] = Array(N); - } - - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - Sij[i][j] = (i === j) * 1.0; - } - } - - let Vab = getAij(Hij); - - while (Math.abs(Vab[1]) >= Math.abs(e0)) { - let i = Vab[0][0]; - let j = Vab[0][1]; - let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); - let Gij = Rij(i, j, psi, N); - Hij = unitary(Gij, Hij); - Sij = AxB(Sij, Gij); - Vab = getAij(Hij); - } - - for (let i = 0; i < N; i++) { - Ei[i] = Hij[i][i]; - } - - return sorting(Ei, Sij); -} - -function sorting(values, vectors) { - let eigsCount = values.length; - vectors.length; - let pairs = Array.from({ - length: eigsCount - }, (_, i) => { - let vector = vectors.map(v => v[i]); - return { - value: values[i], - vec: vector - }; - }); - pairs.sort((a, b) => b.value - a.value); - let sortedValues = pairs.map(_ref => { - let { - value - } = _ref; - return value; - }); - let sortedVectors = pairs.map(_ref2 => { - let { - vec - } = _ref2; - return vec; - }); - return [sortedValues, sortedVectors]; -} - -function dominentPrincipalVector(matrix) { - let [, [dominentVector]] = eigens(matrix); - return dominentVector; -} - -class Vec3 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values = [x, y, z]; - } - - get x() { - return this._values[0]; - } - - get y() { - return this._values[1]; - } - - get z() { - return this._values[2]; - } - - set x(value) { - this._values[0] = value; - } - - set y(value) { - this._values[1] = value; - } - - set z(value) { - this._values[2] = value; - } - - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } - - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - - get normalized() { - if (this.length === 0) return null; - return Vec3.multScalar(this, 1 / this.length); - } - - get colorInt() { - const floatToInt = value => { - const result = parseInt(value * 255 + 0.5); - return Math.max(Math.min(result, 255), 0); - }; - - return this._values.map(floatToInt); - } - - clone() { - return new Vec3(this.x, this.y, this.z); - } - - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - return this; - } - - toVec4() { - let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - return new Vec4(this.x, this.y, this.z, w); - } - - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - return this; - } - - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - return this; - } - - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - return this; - } - - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - return this; - } - - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; - - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - return this; - } - - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - return this; - } - - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - return this; - } - - toString() { - return "Vec3( ".concat(this._values.join(", "), " )"); - } - - static add(a, b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - static sub(a, b) { - return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); - } - - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static multScalar(a, scalar) { - return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); - } - - static multVector(a, b) { - return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); - } - - static interpolate(a, b, p) { - let a_ = Vec3.multScalar(a, 1 - p); - let b_ = Vec3.multScalar(b, p); - return Vec3.add(a_, b_); - } - -} - -class Vec4 { - constructor() { - let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values = [x, y, z, w]; - } - - get x() { - return this._values[0]; - } - - get y() { - return this._values[1]; - } - - get z() { - return this._values[2]; - } - - get w() { - return this._values[3]; - } - - set x(value) { - this._values[0] = value; - } - - set y(value) { - this._values[1] = value; - } - - set z(value) { - this._values[2] = value; - } - - set w(value) { - this._values[3] = value; - } - - get length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); - } - - get lengthSq() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; - } - - get normalized() { - if (this.length === 0) return null; - return Vec4.multScalar(this, 1 / this.length); - } - - get xyz() { - return new Vec3(this.x, this.y, this.z); - } - - get splatX() { - return new Vec4(this.x); - } - - get splatY() { - return new Vec4(this.y); - } - - get splatZ() { - return new Vec4(this.z); - } - - get splatW() { - return new Vec4(this.w); - } - - clone() { - return new Vec4(this.x, this.y, this.z, this.w); - } - - set(x) { - let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; - let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; - let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; - this._values[0] = x; - this._values[1] = y; - this._values[2] = z; - this._values[3] = w; - return this; - } - - toVec3() { - return this.xyz; - } - - addVector(v) { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - return this; - } - - addScaledVector(v, scalar) { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - return this; - } - - subVector(v) { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - return this; - } - - mult(scalar) { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - return this; - } - - multVector(vec) { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - return this; - } - - reciprocal() { - this._values[0] = 1 / this._values[0]; - this._values[1] = 1 / this._values[1]; - this._values[2] = 1 / this._values[2]; - this._values[3] = 1 / this._values[3]; - return this; - } - - clamp(min, max) { - const clamper = v => min > v ? min : max < v ? max : v; - - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - return this; - } - - clampGrid() { - const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; - - const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; - - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - return this; - } - - truncate() { - this._values[0] = Math.trunc(this._values[0]); - this._values[1] = Math.trunc(this._values[1]); - this._values[2] = Math.trunc(this._values[2]); - this._values[3] = Math.trunc(this._values[3]); - return this; - } - - normalize() { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - return this; - } - - toString() { - return "Vec4( ".concat(this._values.join(", "), " )"); - } - - static add(a, b) { - return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); - } - - static sub(a, b) { - return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); - } - - static dot(a, b) { - return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; - } - - static multScalar(a, scalar) { - return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); - } - - static multVector(a, b) { - return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); - } - - static interpolate(a, b, p) { - let a_ = Vec4.multScalar(a, 1 - p); - let b_ = Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } - - static multiplyAdd(a, b, c) { - return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); - } - - static negativeMultiplySubtract(a, b, c) { - return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); - } - - static compareAnyLessThan(left, right) { - return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; - } - -} - -function computeWeightedCovariance(values, weights) { - let total = 0; - let mean = values.reduce((sum, value, i) => { - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1 / total); - let covariance = values.reduce((sum, value, i) => { - let weight = weights[i]; - let v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; - sum[0][1] += v.x * v.y * weight; - sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; - sum[1][2] += v.y * v.z * weight; - sum[2][2] += v.z * v.z * weight; - return sum; - }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - return covariance; -} - -function computePCA(values, weights) { - const covariance = computeWeightedCovariance(values, weights); - return new Vec3(...dominentPrincipalVector(covariance)); -} - -const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; -const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; -const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; - -function floatToInt(value, limit) { - const integer = parseInt(value + 0.5); - if (integer < 0) return 0; - if (integer > limit) return integer; - return integer; -} - -function floatTo565(color) { - const r = floatToInt(31.0 * color.x, 31); - const g = floatToInt(63.0 * color.y, 63); - const b = floatToInt(31.0 * color.z, 31); - return r << 11 | g << 5 | b; -} - -function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { - result[blockOffset + 0] = firstColor & 0xff; - result[blockOffset + 1] = firstColor >> 8; - result[blockOffset + 2] = secondColor & 0xff; - result[blockOffset + 3] = secondColor >> 8; - - for (let y = 0; y < 4; y++) { - result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; - } -} - -function writeColourBlock3(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; - - if (firstColor <= secondColor) { - remapped = indices.slice(); - } else { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); - } - - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} - -function writeColourBlock4(start, end, indices, result, blockOffset) { - let firstColor = floatTo565(start); - let secondColor = floatTo565(end); - let remapped; - - if (firstColor < secondColor) { - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map(index => (index ^ 0x1) & 0x3); - } else if (firstColor == secondColor) { - remapped = new Array(16).fill(0); - } else { - remapped = indices.slice(); - } - - writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); -} - -class ColorSet { - constructor(rgba, mask, flags) { - this.flags = flags; - this._count = 0; - this._transparent = false; - this._remap = []; - this._weights = []; - this._points = []; - const isDxt1 = (this.flags & kDxt1) != 0; - const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; - - for (let i = 0; i < 16; i++) { - const bit = 1 << i; - - if ((mask & bit) == 0) { - this._remap[i] = -1; - continue; - } - - if (isDxt1 && rgba[4 * i + 3] < 128) { - this._remap[i] = -1; - this._transparent = true; - continue; - } - - for (let j = 0;; j++) { - if (j == i) { - const r = rgba[4 * i] / 255.0; - const g = rgba[4 * i + 1] / 255.0; - const b = rgba[4 * i + 2] / 255.0; - const a = (rgba[4 * i + 3] + 1) / 256.0; - this._points[this._count] = new Vec3(r, g, b); - this._weights[this._count] = weightByAlpha ? a : 1.0; - this._remap[i] = this._count; - this._count++; - break; - } - - const oldbit = 1 << j; - const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); - - if (match) { - const index = this._remap[j]; - const w = (rgba[4 * i + 3] + 1) / 256.0; - this._weights[index] += weightByAlpha ? w : 1.0; - this._remap[i] = index; - break; - } - } - } - - for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); - } - - get transparent() { - return this._transparent; - } - - get count() { - return this._count; - } - - get points() { - return Object.freeze(this._points.slice()); - } - - get weights() { - return Object.freeze(this._weights.slice()); - } - - remapIndicesSingle(singleIndex, target) { - const result = this._remap.map(index => index === -1 ? 3 : singleIndex); - - target.forEach((_, i) => target[i] = result[i]); - } - - remapIndices(indexMap, target) { - const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); - - target.forEach((_, i) => target[i] = result[i]); - } - -} - -class ColorFit { - constructor(colorSet) { - this.colors = colorSet; - this.flags = colorSet.flags; - } - - compress(result, offset) { - const isDxt1 = (this.flags & kDxt1) != 0; - - if (isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } else this.compress4(result, offset); - } - - compress3(result, offset) {} - - compress4(result, offset) {} - -} - -class SingleColourFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const singleColor = colorSet.points[0]; - this.color = singleColor.colorInt; - this.start = new Vec3(0); - this.end = new Vec3(0); - this.index = 0; - this.error = Infinity; - this.bestError = Infinity; - } - - compressBase(lookups, saveFunc) { - this.computeEndPoints(lookups); - - if (this.error < this.bestError) { - const indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - this.bestError = this.error; - } - } - - compress3(result, offset) { - const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - - this.compressBase(lookups, saveFunc); - } - - compress4(result, offset) { - const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - - this.compressBase(lookups, saveFunc); - } - - computeEndPoints(lookups) { - this.error = Infinity; - - for (let index = 0; index < 2; index++) { - const sources = []; - let error = 0; - - for (let channel = 0; channel < 3; channel++) { - const lookup = lookups[channel]; - const target = this.color[channel]; - sources[channel] = lookup[target][index]; - const diff = sources[channel][2]; - error += diff * diff; - } - - if (error < this.error) { - this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); - this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); - this.index = 2 * index; - this.error = error; - } - } - } - -} - -class RangeFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - this.metric = new Vec3(1); - - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722); - } - - this.start = new Vec3(0); - this.end = new Vec3(0); - this.bestError = Infinity; - this.computePoints(); - } - - compressBase(codes, saveFunc) { - const { - points: values - } = this.colors; - let error = 0; - const closest = values.map(color => { - let minDist = Infinity; - const packedIndex = codes.reduce((idx, code, j) => { - const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; - if (dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - error += minDist; - return packedIndex; - }); - - if (error < this.bestError) { - let indices = new Uint8Array(16); - this.colors.remapIndices(closest, indices); - saveFunc(this.start, this.end, indices); - this.bestError = error; - } - } - - compress3(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - - this.compressBase(codes, saveFunc); - } - - compress4(result, offset) { - const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; - - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - - this.compressBase(codes, saveFunc); - } - - computePoints() { - const { - count, - points: values, - weights - } = this.colors; - if (count <= 0) return; - const principle = computePCA(values, weights); - let start, end, min, max; - start = end = values[0]; - min = max = Vec3.dot(start, principle); - - for (let i = 1; i < count; i++) { - let value = Vec3.dot(values[i], principle); - - if (value < min) { - start = values[i]; - min = value; - } else if (value > max) { - end = values[i]; - max = value; - } - } - - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); - } - -} - -class ClusterFit extends ColorFit { - constructor(colorSet) { - super(colorSet); - const kMaxIterations = 8; - this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; - this.bestError = Infinity; - this.metric = new Vec4(1); - - if ((this.flags & kColourMetricPerceptual) !== 0) { - this.metric.set(0.2126, 0.7152, 0.0722, 0); - } - - const { - points: values, - weights - } = this.colors; - this.principle = computePCA(values, weights); - this.order = new Uint8Array(16 * kMaxIterations); - this.pointsWeights = []; - this.xSum_wSum = new Vec4(0); - } - - constructOrdering(axis, iteration) { - const currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration); - const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if (!uniqueOrder) return false; - this.copyOrderWeight(currentOrder); - return true; - } - - compress3(result, offset) { - const aabbx = _ref => { - let [part0,, part1, part2] = _ref; - const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); - const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - - this.compressBase(aabbx, saveFunc, 2); - } - - compress4(result, offset) { - const aabbx = _ref2 => { - let [part0, part1, part2, part3] = _ref2; - const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); - const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); - const const2_9 = new Vec4(2 / 9); - const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); - const alpha2_sum = alphax_sum.splatW; - const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); - const beta2_sum = betax_sum.splatW; - const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - return { - ax: alphax_sum, - aa: alpha2_sum, - bx: betax_sum, - bb: beta2_sum, - ab: alphabeta_sum - }; - }; - - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - - this.compressBase(aabbx, saveFunc, 3); - } - - compressBase(aabbFunc, saveFunc) { - let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - this.constructOrdering(this.principle, 0); - let best = { - start: new Vec4(0), - end: new Vec4(0), - error: this.bestError, - iteration: 0, - bestI: 0, - bestJ: 0 - }; - if (repeater === 3) best.bestK = 0; - - const leastSquares = (parts, internalIndices) => { - const aabbx = aabbFunc(parts); - const internalBest = this.computeOptimalPoints(aabbx); - - if (internalBest.error < best.error) { - best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); - return true; - } - - return false; - }; - - for (let iterationIndex = 0;;) { - this.clusterIterate(iterationIndex, leastSquares, repeater); - if (best.iteration != iterationIndex) break; - iterationIndex++; - if (iterationIndex == this.iterationCount) break; - const newAxis = Vec4.sub(best.end, best.start).xyz; - if (!this.constructOrdering(newAxis, iterationIndex)) break; - } - - if (best.error < this.bestError) this.saveBlock(best, saveFunc); - } - - makeOrder(axis) { - const { - count, - points: values - } = this.colors; - const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); - return Array.from({ - length: count - }, (_, i) => i).sort((a, b) => { - if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; - return a - b; - }); - } - - copyOrderToThisOrder(order, iteration) { - const orderOffset = iteration * 16; - order.forEach((ord, i) => { - this.order[orderOffset + i] = ord; - }); - } - - checkOrderUnique(order, iteration) { - const { - count - } = this.colors; - - for (let it = 0; it < iteration; it++) { - let prevOffset = it * 16; - let same = true; - - for (let i = 0; i < count; i++) { - if (order[i] !== this.order[prevOffset + i]) { - same = false; - break; - } - } - - if (same) return false; - } - - return true; - } - - copyOrderWeight(order) { - const { - count, - points: unweighted, - weights - } = this.colors; - this.xSum_wSum.set(0); - - for (let i = 0; i < count; i++) { - const j = order[i]; - const p = unweighted[j].toVec4(1); - const w = new Vec4(weights[j]); - const x = Vec4.multVector(p, w); - this.pointsWeights[i] = x; - this.xSum_wSum.addVector(x); - } - } - - computeOptimalPoints(vectorPoint) { - const { - ax, - bx, - aa, - bb, - ab - } = vectorPoint; - const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); - let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); - let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); - a.clampGrid(); - b.clampGrid(); - let error = this.computeError(_objectSpread2({ - a, - b - }, vectorPoint)); - return { - start: a, - end: b, - error - }; - } - - computeError(_ref3) { - let { - a, - b, - ax, - bx, - aa, - bb, - ab - } = _ref3; - const two = new Vec4(2); - const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); - const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); - const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); - const e4 = Vec4.multiplyAdd(two, e3, e1); - const e5 = Vec4.multVector(e4, this.metric); - return e5.x + e5.y + e5.z; - } - - saveBlock(best, writeFunc) { - const { - count - } = this.colors; - const { - start, - end, - iteration, - error, - bestI, - bestJ, - bestK = -1 - } = best; - const orderOffset = iteration * 16; - const unordered = new Uint8Array(16); - - const mapper = m => { - if (m < bestI) return 0; - if (m < bestJ) return 2; - if (m < bestK) return 3; - return 1; - }; - - for (let i = 0; i < count; i++) { - unordered[this.order[orderOffset + i]] = mapper(i); - } - - const bestIndices = new Uint8Array(16); - this.colors.remapIndices(unordered, bestIndices); - writeFunc(start.xyz, end.xyz, bestIndices); - this.bestError = error; - } - - clusterIterate(index, func) { - let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; - const { - count - } = this.colors; - - const indexMapper = (i, j, k) => { - const mapper = { - bestI: i, - bestJ: iterCount === 2 ? k : j, - iteration: index - }; - if (iterCount === 3) mapper.bestK = k; - return mapper; - }; - - let part0 = new Vec4(0.0); - - for (let i = 0; i < count; i++) { - let part1 = new Vec4(0.0); - - for (let j = i;;) { - let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); - const kmin = j == 0 ? 1 : j; - - for (let k = kmin;;) { - const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - if (k == count) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } - - if (iterCount === 2) break; - if (j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; - } - - part0.addVector(this.pointsWeights[i]); - } - } - -} - -function quantise(alpha) { - const GRID = 15; - let result = Math.floor(alpha * (GRID / 255) + 0.5); - if (result < 0) return 0; - if (result > GRID) return GRID; - return result; -} - -function compressAlphaDxt3(rgba, mask, result, offset) { - for (let i = 0; i < 8; i++) { - let quant1 = quantise(rgba[8 * i + 3]); - let quant2 = quantise(rgba[8 * i + 7]); - const bit1 = 1 << 2 * i; - const bit2 = 1 << 2 * i + 1; - if ((mask & bit1) == 0) quant1 = 0; - if ((mask & bit2) == 0) quant2 = 0; - result[offset + i] = quant1 | quant2 << 4; - } -} - -function compressAlphaDxt5(rgba, mask, result, offset) { - let step5 = interpolateAlpha(rgba, mask, 5); - let step7 = interpolateAlpha(rgba, mask, 7); - if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); -} - -function interpolateAlpha(rgba, mask, steps) { - let { - min, - max - } = setAlphaRange(rgba, mask, steps); - let code = setAlphaCodeBook(min, max, steps); - let indices = new Uint8Array(16); - let error = fitCodes(rgba, mask, code, indices); - return { - min, - max, - indices, - error - }; -} - -function setAlphaRange(rgba, mask, steps) { - let min = 255; - let max = 0; - - for (let i = 0; i < 16; i++) { - let bit = 1 << i; - if ((mask & bit) == 0) continue; - let value = rgba[4 * i + 3]; - - if (steps === 5) { - if (value !== 0 && value < min) min = value; - if (value !== 255 && value > max) max = value; - } else { - if (value < min) min = value; - if (value > max) max = value; - } - } - - if (min > max) min = max; - if (max - min < steps) max = Math.min(min + steps, 255); - if (max - min < steps) min = Math.max(max - steps, 0); - return { - min, - max - }; -} - -function setAlphaCodeBook(min, max, steps) { - let codes = [min, max, ...Array.from({ - length: steps - 1 - }, (_, i) => { - return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); - })]; - - if (steps === 5) { - codes[6] = 0; - codes[7] = 255; - } - - return codes; -} - -function fitCodes(rgba, mask, codes, indices) { - let err = 0; - - for (let i = 0; i < 16; ++i) { - let bit = 1 << i; - - if ((mask & bit) == 0) { - indices[i] = 0; - continue; - } - - let value = rgba[4 * i + 3]; - let least = Infinity; - let index = 0; - - for (let j = 0; j < 8; ++j) { - let dist = value - codes[j]; - dist *= dist; - - if (dist < least) { - least = dist; - index = j; - } - } - - indices[i] = index; - err += least; - } - - return err; -} - -function writeAlphaBlock5(_ref, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref; - - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - if (index <= 5) return 7 - index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} - -function writeAlphaBlock7(_ref2, result, offset) { - let { - min: alpha0, - max: alpha1, - indices - } = _ref2; - - if (alpha0 > alpha1) { - const swapped = indices.map(index => { - if (index === 0) return 1; - if (index === 1) return 0; - return 9 - index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} - -function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { - result[offset] = alpha0; - result[offset + 1] = alpha1; - let indicesPointer = 0; - let resultPointer = offset + 2; - - for (let i = 0; i < 2; i++) { - let value = 0; - - for (let j = 0; j < 8; ++j) { - let index = indices[indicesPointer]; - value |= index << 3 * j; - indicesPointer++; - } - - for (let j = 0; j < 3; ++j) { - let byte = value >> 8 * j & 0xff; - result[resultPointer] = byte; - resultPointer++; - } - } -} - -function unpack565(color16bit) { - const red = color16bit >> 11 & 0x1f; - const green = color16bit >> 5 & 0x3f; - const blue = color16bit & 0x1f; - return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; -} - -function interpolateColorArray(a, b, amount) { - const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); - result[3] = 255; - return result; -} - -function unpackColorCodes(block, offset, isDxt1) { - const color1 = block[offset] | block[offset + 1] << 8; - const color2 = block[offset + 2] | block[offset + 3] << 8; - const unpackedColor1 = unpack565(color1); - const unpackedColor2 = unpack565(color2); - return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; -} - -function unpackIndices(block, blockOffset) { - let offset = blockOffset + 4; - let result = new Uint8Array(16); - - for (let i = 0; i < 4; i++) { - let packedIndices = block[offset + i]; - result[i * 4 + 0] = packedIndices & 0x3; - result[i * 4 + 1] = packedIndices >> 2 & 0x3; - result[i * 4 + 2] = packedIndices >> 4 & 0x3; - result[i * 4 + 3] = packedIndices >> 6 & 0x3; - } - - return result; -} - -function decompressColor(rgba, block, offset, isDxt1) { - const colorCode = unpackColorCodes(block, offset, isDxt1); - const indices = unpackIndices(block, offset); - - for (let i = 0; i < 16; i++) { - for (let j = 0; j < 4; j++) { - rgba[4 * i + j] = colorCode[indices[i]][j]; - } - } -} - -function decompressAlphaDxt3(rgba, block, offset) { - for (let i = 0; i < 8; ++i) { - let quant = block[offset + i]; - let lo = quant & 0x0f; - let hi = quant & 0xf0; - rgba[8 * i + 3] = lo | lo << 4; - rgba[8 * i + 7] = hi | hi >> 4; - } -} - -function decompressAlphaDxt5(rgba, block, offset) { - let alpha0 = block[offset + 0]; - let alpha1 = block[offset + 1]; - let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); - let indices = new Uint8Array(16); - let indicePointer = 0; - let bytePointer = 2; - - for (let i = 0; i < 2; i++) { - let value = 0; - - for (let j = 0; j < 3; j++) { - let byte = block[offset + bytePointer]; - value |= byte << 8 * j; - bytePointer++; - } - - for (let j = 0; j < 8; j++) { - let index = value >> 3 * j & 0x7; - indices[indicePointer] = index; - indicePointer++; + if (sIndex >= sEnd) { + break; } - } - for (let i = 0; i < 16; ++i) { - rgba[4 * i + 3] = codes[indices[i]]; - } -} + mLength = token & 0xf; + mOffset = src[sIndex++] | src[sIndex++] << 8; -const DXT1_COMPRESSED_BYTES = 8; -const DXT5_COMPRESSED_BYTES = 16; -const COLORS = 4; -const DECOMPRESSED_BLOCK_SIZE = 16; + if (mLength === 0xf) { + while (true) { + mLength += src[sIndex]; -function blockRepeat(width, height, func) { - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - func(x, y); + if (src[sIndex++] !== 0xff) { + break; + } + } } - } -} -function rectRepeat(func) { - for (let y = 0; y < 4; y++) { - for (let x = 0; x < 4; x++) { - func(x, y); + mLength += minMatch; + + if (hasCopyWithin && mOffset === 1) { + dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); + dIndex += mLength; + } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { + dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); + dIndex += mLength; + } else { + for (i = dIndex - mOffset, n = i + mLength; i < n;) { + dst[dIndex++] = dst[i++] | 0; + } } } -} -function FixFlags(flags) { - let method = flags & (kDxt1 | kDxt3 | kDxt5); - let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); - let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); - const extra = flags & kWeightColourByAlpha; - if (method != kDxt3 && method != kDxt5) method = kDxt1; - if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; - if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; - return method | fit | metric | extra; + return dIndex; } -function GetStorageRequirements(width, height, flags) { - flags = FixFlags(flags); - const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); - const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - return blockcount * blocksize; -} +function compressBlock(src, dst, sIndex, sLength, hashTable) { + var mIndex, mAnchor, mLength, mOffset, mStep; + var literalCount, dIndex, sEnd, n; + dIndex = 0; + sEnd = sLength + sIndex; + mAnchor = sIndex; -function extractColorBlock(img) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - let mask = 0; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; - - if (sx < width && sy < height) { - let sourceColorOffset = COLORS * (width * sy + sx); - - for (let i = 0; i < COLORS; i++) { - block[blockColorOffset++] = img[sourceColorOffset++]; + if (sLength >= minLength) { + var searchMatchCount = (1 << skipTrigger) + 3; + + while (sIndex + minMatch < sEnd - searchLimit) { + var seq = LZ4Utils.readU32(src, sIndex); + var hash = LZ4Utils.hashU32(seq) >>> 0; + hash = (hash >> 16 ^ hash) >>> 0 & 0xffff; + mIndex = hashTable[hash] - 1; + hashTable[hash] = sIndex + 1; + + if (mIndex < 0 || sIndex - mIndex >>> 16 > 0 || LZ4Utils.readU32(src, mIndex) !== seq) { + mStep = searchMatchCount++ >> skipTrigger; + sIndex += mStep; + continue; } - mask |= 1 << 4 * py + px; - } else blockColorOffset += COLORS; - }); - return { - block, - mask - }; -} + searchMatchCount = (1 << skipTrigger) + 3; + literalCount = sIndex - mAnchor; + mOffset = sIndex - mIndex; + sIndex += minMatch; + mIndex += minMatch; + mLength = sIndex; -function copyBuffer(result, block) { - let { - x = 0, - y = 0, - width = 0, - height = 0 - } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - let blockColorOffset = 0; - rectRepeat(function (px, py) { - let sx = x + px; - let sy = y + py; - - if (sx < width && sy < height) { - let resultColorOffset = COLORS * (width * sy + sx); - - for (let i = 0; i < COLORS; i++) { - result[resultColorOffset + i] = block[blockColorOffset++]; + while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { + sIndex++; + mIndex++; } - } else blockColorOffset += COLORS; - }); -} -function getCompressor(colorSet) { - if (colorSet.count === 1) return new SingleColourFit(colorSet); - if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); - return new ClusterFit(colorSet); -} + mLength = sIndex - mLength; + var token = mLength < mlMask ? mLength : mlMask; -function CompressMasked(rgba, mask, result, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - const colors = new ColorSet(rgba, mask, flags); - const compressor = getCompressor(colors); - compressor.compress(result, offset + colorOffset); - if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); -} + if (literalCount >= runMask) { + dst[dIndex++] = (runMask << mlBits) + token; -function decompressBlock(result, block, offset, flags) { - flags = FixFlags(flags); - let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; - decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); - if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); -} + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } -function compressImage(source, width, height, result, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let targetBlockPointer = 0; - blockRepeat(width, height, function (x, y) { - const { - block: sourceRGBA, - mask - } = extractColorBlock(source, { - x, - y, - width, - height - }); - CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); - targetBlockPointer += bytesPerBlock; - }); -} + dst[dIndex++] = n; + } else { + dst[dIndex++] = (literalCount << mlBits) + token; + } -function decompressImage(result, width, height, source, flags) { - flags = FixFlags(flags); - const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; - let sourceBlockPointer = 0; - - for (let y = 0; y < height; y += 4) { - for (let x = 0; x < width; x += 4) { - const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); - decompressBlock(targetRGBA, source, sourceBlockPointer, flags); - copyBuffer(result, targetRGBA, { - x, - y, - width, - height - }); - sourceBlockPointer += bytesPerBlock; - } - } -} + for (var i = 0; i < literalCount; i++) { + dst[dIndex++] = src[mAnchor + i]; + } -const flags = { - DXT1: kDxt1, - DXT3: kDxt3, - DXT5: kDxt5, - ColourIterativeClusterFit: kColourIterativeClusterFit, - ColourClusterFit: kColourClusterFit, - ColourRangeFit: kColourRangeFit, - ColourMetricPerceptual: kColourMetricPerceptual, - ColourMetricUniform: kColourMetricUniform, - WeightColourByAlpha: kWeightColourByAlpha -}; + dst[dIndex++] = mOffset; + dst[dIndex++] = mOffset >> 8; -function compress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = GetStorageRequirements(width, height, flags); - const result = new Uint8Array(targetSize); - compressImage(source, width, height, result, flags); - return result; -} + if (mLength >= mlMask) { + for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; + } -function decompress(inputData, width, height, flags) { - let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; - const targetSize = width * height * 4; - const result = new Uint8Array(targetSize); - decompressImage(result, width, height, source, flags); - return result; -} + dst[dIndex++] = n; + } -class Texture2DReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - let format = int32Reader.read(buffer); - let width = uint32Reader.read(buffer); - let height = uint32Reader.read(buffer); - let mipCount = uint32Reader.read(buffer); - if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); - let dataSize = uint32Reader.read(buffer); - let data = buffer.read(dataSize); - if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } else if (format != 0) throw new XnbError("Non-implemented Texture2D format type (".concat(format, ") found.")); - - for (let i = 0; i < data.length; i += 4) { - let inverseAlpha = 255 / data[i + 3]; - data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + mAnchor = sIndex; } + } - return { - format, - export: { - type: this.type, - data, - width, - height - } - }; + if (mAnchor === 0) { + return 0; } - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - this.writeIndex(buffer, resolver); - const width = content.export.width; - const height = content.export.height; - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - let data = content.export.data; + literalCount = sEnd - mAnchor; + + if (literalCount >= runMask) { + dst[dIndex++] = runMask << mlBits; - for (let i = 0; i < data.length; i += 4) { - const alpha = data[i + 3] / 255; - data[i] = Math.floor(data[i] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); + for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { + dst[dIndex++] = 0xff; } - if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); + dst[dIndex++] = n; + } else { + dst[dIndex++] = literalCount << mlBits; } - isValueType() { - return false; + sIndex = mAnchor; + + while (sIndex < sEnd) { + dst[dIndex++] = src[sIndex++]; } + return dIndex; } -class Vector3Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - return { - x, - y, - z - }; - } +function compressSingleBlock(src, dst) { + clearHashTable(); + return compressBlock(src, dst, 0, src.length, hashTable); +} - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; } -class SpriteFontReader extends BaseReader { - read(buffer, resolver) { - const int32Reader = new Int32Reader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(new CharReader()); - const texture = resolver.read(buffer); - const glyphs = resolver.read(buffer); - const cropping = resolver.read(buffer); - const characterMap = resolver.read(buffer); - const verticalLineSpacing = int32Reader.read(buffer); - const horizontalSpacing = singleReader.read(buffer); - const kerning = resolver.read(buffer); - const defaultCharacter = nullableCharReader.read(buffer); - return { - texture, - glyphs, - cropping, - characterMap, - verticalLineSpacing, - horizontalSpacing, - kerning, - defaultCharacter - }; - } +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const charReader = new CharReader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(charReader); - const texture2DReader = new Texture2DReader(); - const rectangleListReader = new ListReader(new RectangleReader()); - const charListReader = new ListReader(charReader); - const vector3ListReader = new ListReader(new Vector3Reader()); - this.writeIndex(buffer, resolver); + while (index < str.length) { + let code = utf16Map[index]; - try { - texture2DReader.write(buffer, content.texture, resolver); - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } catch (ex) { - throw ex; + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; } - - console.log("writing complitd!"); } - isValueType() { - return false; - } + return result; +} +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); } -class TBinReader extends BaseReader { +class StringReaderCore { read(buffer) { - const int32Reader = new Int32Reader(); - let size = int32Reader.read(buffer); - let data = buffer.read(size); - return { - export: { - type: this.type, - data - } - }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); + let length = buffer.read7BitNumber(); + return buffer.readString(length); } - isValueType() { - return false; + write(buffer, string) { + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); } } -class Vector2Reader extends BaseReader { - read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - return { - x, - y - }; +class ReaderResolver { + constructor(readers) { + this.readers = readers; } -} - -class Vector4Reader extends BaseReader { read(buffer) { - const singleReader = new SingleReader(); - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - let w = singleReader.read(buffer); - return { - x, - y, - z, - w - }; + let index = buffer.read7BitNumber() - 1; + if (this.readers[index] == null) throw new XnbError("Invalid reader index ".concat(index)); + return this.readers[index].read(buffer, this); } -} - -const Readers = { - ArrayReader, - BaseReader, - BmFontReader, - BooleanReader, - CharReader, - DictionaryReader, - DoubleReader, - EffectReader, - Int32Reader, - ListReader, - NullableReader, - RectangleReader, - SingleReader, - SpriteFontReader, - StringReader, - TBinReader, - Texture2DReader, - UInt32Reader, - Vector2Reader, - Vector3Reader, - Vector4Reader -}; - -const simplifyType = type => { - let simple = type.split(/`|,/)[0]; - let isArray = simple.endsWith('[]'); - if (isArray) return "Array<".concat(simplifyType(simple.slice(0, -2)), ">"); - - switch (simple) { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; - - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; - - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; - - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; - - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - let subtypes = parseSubtypes(type).map(simplifyType); - return "Dictionary<".concat(subtypes[0], ",").concat(subtypes[1], ">"); - - case 'Microsoft.Xna.Framework.Content.ArrayReader': - let arrayType = parseSubtypes(type).map(simplifyType); - return "Array<".concat(arrayType, ">"); - - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - let listType = parseSubtypes(type).map(simplifyType); - return "List<".concat(listType, ">"); - - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; - - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; - - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; - - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; - - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; - - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; - - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; - - case 'xTile.Pipeline.TideReader': - return 'TBin'; - - case 'BmFont.XmlSourceReader': - return 'BmFont'; - - default: - throw new XnbError("Non-implemented type found, cannot resolve type \"".concat(simple, "\", \"").concat(type, "\".")); + write(buffer, content) { + this.readers[0].write(buffer, content, this); } -}; - -const parseSubtypes = type => { - let subtype = type.split('`')[1]; - subtype.slice(0, 1); - subtype = subtype.slice(2, -1); - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); - return matches; -}; -const getTypeInfo = type => { - let mainType = type.match(/[^<]+/)[0]; - let subtypes = type.match(/<(.+)>/); - subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; - return { - type: mainType, - subtypes - }; -}; + getIndex(reader) { + for (let i = 0, len = this.readers.length; i < len; i++) { + if (reader.toString() === this.readers[i].toString()) return i; + } + } -const getReader = typeString => { - let { - type, - subtypes - } = getTypeInfo(typeString); - subtypes = subtypes.map(getReader); - if (Readers.hasOwnProperty("".concat(type, "Reader"))) return new Readers["".concat(type, "Reader")](...subtypes); - throw new XnbError("Invalid reader type \"".concat(typeString, "\" passed, unable to resolve!")); -}; +} class XnbData { constructor(header, readers, content) { @@ -3854,21 +1734,20 @@ class XnbConverter { const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); const trimmedArray = new Uint8Array(trimmed); const decompressed = new Uint8Array(decompressedSize); - decompressBlock$1(trimmedArray, decompressed); + decompressBlock(trimmedArray, decompressed); this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; } } let count = this.buffer.read7BitNumber(); - const stringReader = new StringReader(); + const stringReader = new StringReaderCore(); const readers = []; for (let i = 0; i < count; i++) { const type = stringReader.read(this.buffer); const version = this.buffer.readInt32(); - const simpleType = simplifyType(type); - const reader = getReader(simpleType); + const reader = TypeReader.getReaderFromRaw(type); this.readers.push(reader); readers.push({ type, @@ -3891,7 +1770,7 @@ class XnbConverter { convert(json) { const buffer = new BufferWriter(); - const stringReader = new StringReader(); + const stringReader = new StringReaderCore(); let { target, formatVersion, @@ -3912,7 +1791,7 @@ class XnbConverter { buffer.write7BitNumber(json.readers.length); for (let reader of json.readers) { - this.readers.push(getReader(simplifyType(reader.type))); + this.readers.push(TypeReader.getReaderFromRaw(reader.type)); stringReader.write(buffer, reader.type); buffer.writeUInt32(reader.version); } @@ -6811,6 +4690,9 @@ function isPrimitiveReaderType(reader) { switch (reader) { case 'Boolean': case 'Int32': + case 'UInt32': + case 'Single': + case 'Double': case 'Char': case 'String': case '': @@ -6818,6 +4700,7 @@ function isPrimitiveReaderType(reader) { case 'Vector3': case 'Vector4': case 'Rectangle': + case 'Rect': return true; default: @@ -6866,17 +4749,36 @@ function convertJsonContentsToXnbNode(raw, readers) { } if (reader.startsWith('Nullable')) { + let nullableData, trav; + let [readerType, blockTraversed = 1] = reader.split(":"); + blockTraversed = +blockTraversed; + + if (obj === null) { + nullableData = null; + trav = index + blockTraversed; + } else if (typeof obj === "object" && (!obj || Object.keys(obj).length === 0)) { + nullableData = { + type: readers[index + 1], + data: deepCopy(obj) + }; + trav = index + blockTraversed; + } else { + let { + converted, + traversed + } = recursiveConvert(obj, [...path], index + 1); + nullableData = converted; + trav = traversed; + } + return { converted: { - type: reader, + type: readerType, data: { - data: { - type: readers[index + 1], - data: obj - } + data: nullableData } }, - traversed: index + 1 + traversed: trav }; } @@ -6919,11 +4821,7 @@ function convertJsonContentsToXnbNode(raw, readers) { for (let [key, value] of Object.entries(obj)) { let newIndex; - - if (reader.startsWith("Dictionary")) { - if (getTypeInfo(reader).subtypes[1] === readers[index + 2]) newIndex = index + 2;else newIndex = index + 1; - } else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; - + if (reader.startsWith("Dictionary")) newIndex = index + 2;else if (reader.startsWith("Array") || reader.startsWith("List")) newIndex = index + 1;else newIndex = traversed + 1; const { converted, traversed: nexter @@ -6967,6 +4865,11 @@ function convertJsonContentsFromXnbNode(obj) { return data; } + if (type.startsWith("Nullable")) { + if (data === null || data.data === null) return null; + return convertJsonContentsFromXnbNode(data.data); + } + obj = deepCopy(data); } @@ -7012,12 +4915,8 @@ function toXnbNodeData(json) { numSharedResources: 0 }; const rawContent = deepCopy(json.content); - let readersTypeList = readerData.map(_ref => { - let { - type - } = _ref; - return simplifyType(type); - }); + const mainReader = TypeReader.simplifyType(readerData[0].type); + let readersTypeList = TypeReader.getReaderTypeList(mainReader); if (readersTypeList[0] === 'SpriteFont') { readersTypeList = ['SpriteFont', 'Texture2D', 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, 'List', 'Vector3', 'Nullable', 'Char', null]; @@ -7053,7 +4952,7 @@ function fromXnbNodeData(json) { result.readers = deepCopy(readerData); result.content = convertJsonContentsFromXnbNode(json.content); - if (simplifyType(result.readers[0].type) === 'SpriteFont') { + if (TypeReader.simplifyType(result.readers[0].type) === 'SpriteFont') { result.content.verticalLineSpacing = result.content.verticalSpacing; delete result.content.verticalSpacing; } @@ -7476,4 +5375,12 @@ function pack(files) { }); } -export { XnbContent, XnbData, bufferToContents, bufferToXnb, pack, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; +function setReaders(readers) { + return TypeReader.setReaders(readers); +} + +function addReaders(readers) { + return TypeReader.addReaders(readers); +} + +export { XnbContent, XnbData, addReaders, bufferToContents, bufferToXnb, pack, setReaders, unpackToContent, unpackToFiles, unpackToXnbData, xnbDataToContent, exportFiles as xnbDataToFiles }; diff --git a/docs/js/libs/plugins/xnb-stardew.module.js b/docs/js/libs/plugins/xnb-stardew.module.js new file mode 100644 index 0000000..4e74540 --- /dev/null +++ b/docs/js/libs/plugins/xnb-stardew.module.js @@ -0,0 +1,1396 @@ +/** + * @xnb/stardewvalley 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * special thanks to Concernedape(Stardew Valley Producer), 진의(Unoffical XnbCli updater) + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ +import { BaseReader, BooleanReader, Int32Reader, NullableReader, StringReader, ListReader, SingleReader, DictionaryReader, RectangleReader } from '../readers/xnb-readers.module.js'; + +class MovieSceneReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieScene': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieScene", null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', "Nullable", 'String', null, "Nullable", 'String', 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + let Image = int32Reader.read(buffer, null); + let Music = nullableStringReader.read(buffer, resolver); + let Sound = nullableStringReader.read(buffer, resolver); + let MessageDelay = int32Reader.read(buffer, null); + let Script = nullableStringReader.read(buffer, resolver); + let Text = nullableStringReader.read(buffer, resolver); + let Shake = booleanReader.read(buffer); + let ResponsePoint = nullableStringReader.read(buffer, resolver); + let ID = resolver.read(buffer); + return { + Image, + Music, + Sound, + MessageDelay, + Script, + Text, + Shake, + ResponsePoint, + ID + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.Image, null); + nullableStringReader.write(buffer, content.Music, resolver); + nullableStringReader.write(buffer, content.Sound, resolver); + int32Reader.write(buffer, content.MessageDelay, null); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + booleanReader.write(buffer, content.Shake, null); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieData", "Nullable", 'String', null, 'String', 'String', "Nullable>", 'List', 'String', "List", ...MovieSceneReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = nullableStringReader.read(buffer, resolver); + let SheetIndex = int32Reader.read(buffer); + let Title = resolver.read(buffer); + let Description = resolver.read(buffer); + let Tags = nullableStringListReader.read(buffer, resolver); + let Scenes = resolver.read(buffer); + return { + ID, + SheetIndex, + Title, + Description, + Tags, + Scenes + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const movieSceneListReader = new ListReader(new MovieSceneReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ID, resolver); + int32Reader.write(buffer, content.SheetIndex, null); + stringReader.write(buffer, content.Title, resolver); + stringReader.write(buffer, content.Description, resolver); + nullableStringListReader.write(buffer, content.Tags, resolver); + movieSceneListReader.write(buffer, content.Scenes, resolver); + } + + isValueType() { + return false; + } + +} + +class CharacterResponseReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.CharacterResponse': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["CharacterResponse", "Nullable:1", "String", "Nullable:1", "String", "Nullable:1", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const ResponsePoint = nullableStringReader.read(buffer, resolver); + const Script = nullableStringReader.read(buffer, resolver) || ""; + const Text = nullableStringReader.read(buffer, resolver) || ""; + return { + ResponsePoint, + Script, + Text + }; + } + + write(buffer, content, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.ResponsePoint, resolver); + nullableStringReader.write(buffer, content.Script, resolver); + nullableStringReader.write(buffer, content.Text, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialResponsesReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.SpecialResponses': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialResponses", "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList(), "Nullable:7", ...CharacterResponseReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + const BeforeMovie = nullableCharacterResponseReader.read(buffer, resolver); + const DuringMovie = nullableCharacterResponseReader.read(buffer, resolver); + const AfterMovie = nullableCharacterResponseReader.read(buffer, resolver); + return { + BeforeMovie, + DuringMovie, + AfterMovie + }; + } + + write(buffer, content, resolver) { + const nullableCharacterResponseReader = new NullableReader(new CharacterResponseReader()); + this.writeIndex(buffer, resolver); + nullableCharacterResponseReader.write(buffer, content.BeforeMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.DuringMovie, resolver); + nullableCharacterResponseReader.write(buffer, content.AfterMovie, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieReaction", "String", "Nullable:1", "String", "Nullable>:2", "List", "String", "Nullable:25", ...SpecialResponsesReader.parseTypeList(), "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + const Tag = resolver.read(buffer); + const Response = nullableStringReader.read(buffer, resolver) || "like"; + const Whitelist = nullableStringListReader.read(buffer, resolver) || []; + const SpecialResponses = nullableSpecialResponsesReader.read(buffer, resolver); + const ID = resolver.read(buffer); + return { + Tag, + Response, + Whitelist, + SpecialResponses, + ID + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableSpecialResponsesReader = new NullableReader(new SpecialResponsesReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Tag, resolver); + nullableStringReader.write(buffer, content.Response, resolver); + nullableStringListReader.write(buffer, content.Whitelist, resolver); + nullableSpecialResponsesReader.write(buffer, content.SpecialResponses, resolver); + stringReader.write(buffer, content.ID, resolver); + } + + isValueType() { + return false; + } + +} + +class MovieCharacterReactionReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.MovieCharacterReaction': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["MovieCharacterReaction", "String", "Nullable>:34", "List", ...MovieReactionReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + const NPCName = resolver.read(buffer); + const Reactions = nullableReactionListReader.read(buffer, resolver); + return { + NPCName, + Reactions + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableReactionListReader = new NullableReader(new ListReader(new MovieReactionReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.NPCName, resolver); + nullableReactionListReader.write(buffer, content.Reactions, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionItemDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionItemData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionItemData", null, 'String', 'String', 'String', null, 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let ID = int32Reader.read(buffer); + let Name = resolver.read(buffer); + let DisplayName = resolver.read(buffer); + let Description = resolver.read(buffer); + let Price = int32Reader.read(buffer); + let ItemTags = nullableStringListReader.read(buffer, resolver); + return { + ID, + Name, + DisplayName, + Description, + Price, + ItemTags + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.ID, null); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.DisplayName, resolver); + stringReader.write(buffer, content.Description, resolver); + int32Reader.write(buffer, content.Price, null); + nullableStringListReader.write(buffer, content.ItemTags, resolver); + } + + isValueType() { + return false; + } + +} + +class ConcessionTasteReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Movies.ConcessionTaste': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ConcessionTaste", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String', 'Nullable>:2', "List", 'String']; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + let Name = resolver.read(buffer); + let LovedTags = nullableStringListReader.read(buffer, resolver); + let LikedTags = nullableStringListReader.read(buffer, resolver); + let DislikedTags = nullableStringListReader.read(buffer, resolver); + return { + Name, + LovedTags, + LikedTags, + DislikedTags + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + nullableStringListReader.write(buffer, content.LovedTags, resolver); + nullableStringListReader.write(buffer, content.LikedTags, resolver); + nullableStringListReader.write(buffer, content.DislikedTags, resolver); + } + + isValueType() { + return false; + } + +} + +class FishPondRewardReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondReward': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondReward", null, null, null, null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const RequiredPopulation = int32Reader.read(buffer); + const Chance = Math.round(floatReader.read(buffer) * 100000) / 100000; + const ItemId = int32Reader.read(buffer); + const MinQuantity = int32Reader.read(buffer); + const MaxQuantity = int32Reader.read(buffer); + return { + RequiredPopulation, + Chance, + ItemId, + MinQuantity, + MaxQuantity + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + this.writeIndex(buffer, resolver); + int32Reader.write(buffer, content.RequiredPopulation, null); + floatReader.write(buffer, content.Chance, null); + int32Reader.write(buffer, content.ItemId, null); + int32Reader.write(buffer, content.MinQuantity, null); + int32Reader.write(buffer, content.MaxQuantity, null); + } + + isValueType() { + return false; + } + +} + +class FishPondDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.FishPond.FishPondData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["FishPondData", "List", "String", null, "List", ...FishPondRewardReader.parseTypeList(), "Nullable>>:4", "Dictionary>", "Int32", "List", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + const RequiredTags = resolver.read(buffer); + const SpawnTime = int32Reader.read(buffer); + const ProducedItems = resolver.read(buffer); + const PopulationGates = stringListDictReader.read(buffer, resolver); + return { + RequiredTags, + SpawnTime, + ProducedItems, + PopulationGates + }; + } + + write(buffer, content, resolver) { + const stringListReader = new ListReader(new StringReader()); + const int32Reader = new Int32Reader(); + const fishPondRewardListReader = new ListReader(new FishPondRewardReader()); + const stringListDictReader = new NullableReader(new DictionaryReader(new Int32Reader(), new ListReader(new StringReader()))); + this.writeIndex(buffer, resolver); + stringListReader.write(buffer, content.RequiredTags, resolver); + int32Reader.write(buffer, content.SpawnTime, null); + fishPondRewardListReader.write(buffer, content.ProducedItems, resolver); + stringListDictReader.write(buffer, content.PopulationGates, resolver); + } + + isValueType() { + return false; + } + +} + +class TailorItemRecipeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.Crafting.TailorItemRecipe': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["TailorItemRecipe", "Nullable>:2", "List", "String", "Nullable>:2", "List", "String", null, null, "Nullable>:2", "List", "String", "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + const FirstItemTags = nullableStringListReader.read(buffer, resolver); + const SecondItemTags = nullableStringListReader.read(buffer, resolver); + const SpendingRightItem = booleanReader.read(buffer); + const CraftedItemID = int32Reader.read(buffer); + const CraftedItemIDs = nullableStringListReader.read(buffer, resolver); + const CraftedItemColor = nullableStringReader.read(buffer, resolver); + return { + FirstItemTags, + SecondItemTags, + SpendingRightItem, + CraftedItemID, + CraftedItemIDs, + CraftedItemColor + }; + } + + write(buffer, content, resolver) { + const nullableStringListReader = new NullableReader(new ListReader(new StringReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const booleanReader = new BooleanReader(); + const int32Reader = new Int32Reader(); + this.writeIndex(buffer, resolver); + nullableStringListReader.write(buffer, content.FirstItemTags, resolver); + nullableStringListReader.write(buffer, content.SecondItemTags, resolver); + booleanReader.write(buffer, content.SpendingRightItem, null); + int32Reader.write(buffer, content.CraftedItemID, null); + nullableStringListReader.write(buffer, content.CraftedItemIDs, resolver); + nullableStringReader.write(buffer, content.CraftedItemColor, resolver); + } + + isValueType() { + return false; + } + +} + +class RenovationValueReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RenovationValue': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RenovationValue", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Key = resolver.read(buffer); + const Value = resolver.read(buffer); + return { + Type, + Key, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Key, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RectReader extends RectangleReader { + static isTypeOf(type) { + if (super.isTypeOf(type)) return true; + + switch (type) { + case 'StardewValley.GameData.HomeRenovations.Rect': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer) { + const { + x, + y, + width, + height + } = super.read(buffer); + return { + X: x, + Y: y, + Width: width, + Height: height + }; + } + + write(buffer, content, resolver) { + const { + X: x, + Y: y, + Width: width, + Height: height + } = content; + super.write(buffer, { + x, + y, + width, + height + }, resolver); + } + + isValueType() { + return false; + } + +} + +class RectGroupReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.RectGroup': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RectGroup", "List", "Rect"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Rects = resolver.read(buffer); + return { + Rects + }; + } + + write(buffer, content, resolver) { + const rectListReader = new ListReader(new RectReader()); + this.writeIndex(buffer, resolver); + rectListReader.write(buffer, content.Rects, resolver); + } + + isValueType() { + return false; + } + +} + +class HomeRenovationReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.HomeRenovations.HomeRenovation': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["HomeRenovation", "String", "String", null, "List", ...RenovationValueReader.parseTypeList(), "List", ...RenovationValueReader.parseTypeList(), "Nullable>:4", "List", ...RectGroupReader.parseTypeList(), "Nullable", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const booleanReader = new BooleanReader(); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + const TextStrings = resolver.read(buffer); + const AnimationType = resolver.read(buffer); + const CheckForObstructions = booleanReader.read(buffer); + const Requirements = resolver.read(buffer); + const RenovateActions = resolver.read(buffer); + const RectGroups = nullableRectGroupListReader.read(buffer, resolver); + const SpecialRect = nullableStringReader.read(buffer, resolver); + return { + TextStrings, + AnimationType, + CheckForObstructions, + Requirements, + RenovateActions, + RectGroups, + SpecialRect + }; + } + + write(buffer, content, resolver) { + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + const renovationValueListReader = new ListReader(new RenovationValueReader()); + const nullableRectGroupListReader = new NullableReader(new ListReader(new RectGroupReader())); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.TextStrings, resolver); + stringReader.write(buffer, content.AnimationType, resolver); + booleanReader.write(buffer, content.CheckForObstructions, null); + renovationValueListReader.write(buffer, content.Requirements, resolver); + renovationValueListReader.write(buffer, content.RenovateActions, resolver); + nullableRectGroupListReader.write(buffer, content.RectGroups, resolver); + nullableStringReader.write(buffer, content.SpecialRect, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleData", "String", null, "String", "String", "String", null, null, "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + let Name = resolver.read(buffer); + let Index = int32Reader.read(buffer); + let Sprite = resolver.read(buffer); + let Color = resolver.read(buffer); + let Items = resolver.read(buffer); + let Pick = int32Reader.read(buffer); + let RequiredItems = int32Reader.read(buffer); + let Reward = resolver.read(buffer); + return { + Name, + Index, + Sprite, + Color, + Items, + Pick, + RequiredItems, + Reward + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + int32Reader.write(buffer, content.Index, null); + stringReader.write(buffer, content.Sprite, resolver); + stringReader.write(buffer, content.Color, resolver); + stringReader.write(buffer, content.Items, resolver); + int32Reader.write(buffer, content.Pick, null); + int32Reader.write(buffer, content.RequiredItems, null); + stringReader.write(buffer, content.Reward, resolver); + } + + isValueType() { + return false; + } + +} + +class BundleSetDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.BundleSetData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["BundleSetData", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + let Bundles = resolver.read(buffer); + return { + Bundles + }; + } + + write(buffer, content, resolver) { + const bundleListReader = new ListReader(new BundleDataReader()); + this.writeIndex(buffer, resolver); + bundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomBundleDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomBundleData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomBundleData", "String", "String", "Nullable>:13", "List", ...BundleSetDataReader.parseTypeList(), "Nullable>:11", "List", ...BundleDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + let AreaName = resolver.read(buffer); + let Keys = resolver.read(buffer); + let BundleSets = nullableBundleSetListReader.read(buffer, resolver); + let Bundles = nullableBundleListReader.read(buffer, resolver); + return { + AreaName, + Keys, + BundleSets, + Bundles + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableBundleSetListReader = new NullableReader(new ListReader(new BundleSetDataReader())); + const nullableBundleListReader = new NullableReader(new ListReader(new BundleDataReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.AreaName, resolver); + stringReader.write(buffer, content.Keys, resolver); + nullableBundleSetListReader.write(buffer, content.BundleSets, resolver); + nullableBundleListReader.write(buffer, content.Bundles, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementItemReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElementItem': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElementItem", "Nullable", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const Value = resolver.read(buffer); + return { + RequiredTags, + Value + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + stringReader.write(buffer, content.Value, resolver); + } + + isValueType() { + return false; + } + +} + +class RandomizedElementReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.RandomizedElement': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["RandomizedElement", "String", "List", ...RandomizedElementItemReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Name = resolver.read(buffer); + const Values = resolver.read(buffer); + return { + Name, + Values + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const itemListReader = new ListReader(new RandomizedElementItemReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + itemListReader.write(buffer, content.Values, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderObjectiveDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderObjectiveData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderObjectiveData", "String", "String", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Text = resolver.read(buffer); + const RequiredCount = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Text, + RequiredCount, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringReader.write(buffer, content.Text, resolver); + stringReader.write(buffer, content.RequiredCount, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderRewardDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderRewardData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderRewardData", "String", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const Type = resolver.read(buffer); + const Data = resolver.read(buffer); + return { + Type, + Data + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const stringDictReader = new DictionaryReader(new StringReader(), new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Type, resolver); + stringDictReader.write(buffer, content.Data, resolver); + } + + isValueType() { + return false; + } + +} + +class SpecialOrderDataReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.SpecialOrderData': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpecialOrderData", "String", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "Nullable", "String", "String", "Nullable", "String", "Nullable", "String", "Nullable>:8", "List", ...RandomizedElementReader.parseTypeList(), "List", ...SpecialOrderObjectiveDataReader.parseTypeList(), "List", ...SpecialOrderRewardDataReader.parseTypeList()]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const Name = resolver.read(buffer); + const Requester = resolver.read(buffer); + const Duration = resolver.read(buffer); + const Repeatable = nullableStringReader.read(buffer, resolver) || "False"; + const RequiredTags = nullableStringReader.read(buffer, resolver) || ""; + const OrderType = nullableStringReader.read(buffer, resolver) || ""; + const SpecialRule = nullableStringReader.read(buffer, resolver) || ""; + const Text = resolver.read(buffer); + const ItemToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const MailToRemoveOnEnd = nullableStringReader.read(buffer, resolver); + const RandomizedElements = nullableRandomizedElemListReader.read(buffer, resolver); + const Objectives = resolver.read(buffer); + const Rewards = resolver.read(buffer); + return { + Name, + Requester, + Duration, + Repeatable, + RequiredTags, + OrderType, + SpecialRule, + Text, + ItemToRemoveOnEnd, + MailToRemoveOnEnd, + RandomizedElements, + Objectives, + Rewards + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableRandomizedElemListReader = new NullableReader(new ListReader(new RandomizedElementReader())); + const objectiveListReader = new ListReader(new SpecialOrderObjectiveDataReader()); + const rewardListReader = new ListReader(new SpecialOrderRewardDataReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.Name, resolver); + stringReader.write(buffer, content.Requester, resolver); + stringReader.write(buffer, content.Duration, resolver); + nullableStringReader.write(buffer, content.Repeatable, resolver); + nullableStringReader.write(buffer, content.RequiredTags, resolver); + nullableStringReader.write(buffer, content.OrderType, resolver); + nullableStringReader.write(buffer, content.SpecialRule, resolver); + stringReader.write(buffer, content.Text, resolver); + nullableStringReader.write(buffer, content.ItemToRemoveOnEnd, resolver); + nullableStringReader.write(buffer, content.MailToRemoveOnEnd, resolver); + nullableRandomizedElemListReader.write(buffer, content.RandomizedElements, resolver); + objectiveListReader.write(buffer, content.Objectives, resolver); + rewardListReader.write(buffer, content.Rewards, resolver); + } + + isValueType() { + return false; + } + +} + +class ModFarmTypeReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModFarmType': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModFarmType", "String", "String", "String", "Nullable:1", "String", "Nullable:1", "String", "Nullable>:4", "Dictionary", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + const ID = resolver.read(buffer); + const TooltipStringPath = resolver.read(buffer); + const MapName = resolver.read(buffer); + const IconTexture = nullableStringReader.read(buffer, resolver); + const WorldMapTexture = nullableStringReader.read(buffer, resolver); + const ModData = nullableStringDictReader.read(buffer, resolver); + return { + ID, + TooltipStringPath, + MapName, + IconTexture, + WorldMapTexture, + ModData + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const nullableStringDictReader = new NullableReader(new DictionaryReader(new StringReader())); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.TooltipStringPath, resolver); + stringReader.write(buffer, content.MapName, resolver); + nullableStringReader.write(buffer, content.IconTexture, resolver); + nullableStringReader.write(buffer, content.WorldMapTexture, resolver); + nullableStringDictReader.write(buffer, content.ModData, resolver); + } + + isValueType() { + return false; + } + +} + +class ModLanguageReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModLanguage': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModLanguage", "String", "String", "String", null, "Nullable:1", "String", null, null, null, null, "Nullable:1", "String", "String", "String", "String", "String"]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + const ID = resolver.read(buffer); + const LanguageCode = resolver.read(buffer); + const ButtonTexture = resolver.read(buffer); + const UseLatinFont = booleanReader.read(buffer); + const FontFile = nullableStringReader.read(buffer, resolver); + const FontPixelZoom = floatReader.read(buffer); + const FontApplyYOffset = booleanReader.read(buffer); + const SmallFontLineSpacing = int32Reader.read(buffer); + const UseGenderedCharacterTranslations = booleanReader.read(buffer); + const NumberComma = nullableStringReader.read(buffer, resolver); + const TimeFormat = resolver.read(buffer); + const ClockTimeFormat = resolver.read(buffer); + const ClockDateFormat = resolver.read(buffer); + return { + ID, + LanguageCode, + ButtonTexture, + UseLatinFont, + FontFile, + FontPixelZoom, + FontApplyYOffset, + SmallFontLineSpacing, + UseGenderedCharacterTranslations, + NumberComma, + TimeFormat, + ClockTimeFormat, + ClockDateFormat + }; + } + + write(buffer, content, resolver) { + const stringReader = new StringReader(); + const int32Reader = new Int32Reader(); + const floatReader = new SingleReader(); + const booleanReader = new BooleanReader(); + const nullableStringReader = new NullableReader(new StringReader()); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.LanguageCode, resolver); + stringReader.write(buffer, content.ButtonTexture, resolver); + booleanReader.write(buffer, content.UseLatinFont, null); + nullableStringReader.write(buffer, content.FontFile, resolver); + floatReader.write(buffer, content.FontPixelZoom, null); + booleanReader.write(buffer, content.FontApplyYOffset, null); + int32Reader.write(buffer, content.SmallFontLineSpacing, null); + booleanReader.write(buffer, content.UseGenderedCharacterTranslations, null); + nullableStringReader.write(buffer, content.NumberComma, resolver); + stringReader.write(buffer, content.TimeFormat, resolver); + stringReader.write(buffer, content.ClockTimeFormat, resolver); + stringReader.write(buffer, content.ClockDateFormat, resolver); + } + + isValueType() { + return false; + } + +} + +class ModWallpaperOrFlooringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'StardewValley.GameData.ModWallpaperOrFlooring': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["ModWallpaperOrFlooring", "String", "String", null, null]; + } + + static type() { + return "Reflective"; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const ID = resolver.read(buffer); + const Texture = resolver.read(buffer); + const IsFlooring = booleanReader.read(buffer); + const Count = int32Reader.read(buffer); + return { + ID, + Texture, + IsFlooring, + Count + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const booleanReader = new BooleanReader(); + const stringReader = new StringReader(); + this.writeIndex(buffer, resolver); + stringReader.write(buffer, content.ID, resolver); + stringReader.write(buffer, content.Texture, resolver); + booleanReader.write(buffer, content.IsFlooring, null); + int32Reader.write(buffer, content.Count, null); + } + + isValueType() { + return false; + } + +} + +export { BundleDataReader, BundleSetDataReader, CharacterResponseReader, ConcessionItemDataReader, ConcessionTasteReader, FishPondDataReader, FishPondRewardReader, HomeRenovationReader, ModFarmTypeReader, ModLanguageReader, ModWallpaperOrFlooringReader, MovieCharacterReactionReader, MovieDataReader, MovieReactionReader, MovieSceneReader, RandomBundleDataReader, RandomizedElementItemReader, RandomizedElementReader, RectGroupReader, RectReader, RenovationValueReader, SpecialOrderDataReader, SpecialOrderObjectiveDataReader, SpecialOrderRewardDataReader, SpecialResponsesReader, TailorItemRecipeReader }; diff --git a/docs/js/libs/readers/xnb-readers.module.js b/docs/js/libs/readers/xnb-readers.module.js new file mode 100644 index 0000000..070d6bd --- /dev/null +++ b/docs/js/libs/readers/xnb-readers.module.js @@ -0,0 +1,2722 @@ +/** + * xnb.js 1.1.0 + * made by Lybell( https://github.com/lybell-art/ ) + * This library is based on the XnbCli made by Leonblade. + * + * xnb.js is licensed under the LGPL 3.0 License. + * +*/ + +class BaseReader { + static isTypeOf(type) { + return false; + } + + static hasSubType() { + return false; + } + + static parseTypeList() { + return [this.type()]; + } + + static type() { + return this.name.slice(0, -6); + } + + isValueType() { + return true; + } + + get type() { + return this.constructor.type(); + } + + read(buffer, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + write(buffer, content, resolver) { + throw new Error('Cannot invoke methods on abstract class.'); + } + + writeIndex(buffer, resolver) { + if (resolver != null) buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); + } + + toString() { + return this.type; + } + + parseTypeList() { + return this.constructor.parseTypeList(); + } + +} + +class UInt32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.UInt32Reader': + case 'System.UInt32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readUInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(content); + } + +} + +class ArrayReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ArrayReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + let size = uint32Reader.read(buffer); + let array = []; + + for (let i = 0; i < size; i++) { + let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + array.push(value); + } + + return array; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, resolver); + + for (let i = 0; i < content.length; i++) this.reader.write(buffer, content[i], this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Array<".concat(this.reader.type, ">"); + } + + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + +} + +const UTF16_BITES = [0xD800, 0xDC00]; +const UTF16_MASK = 0b1111111111; + +function UTF16Decode(codeSet) { + var _codeSet2; + + if (typeof codeSet === "number") codeSet = [codeSet]; + if (!((_codeSet2 = codeSet) !== null && _codeSet2 !== void 0 && _codeSet2.length)) throw new Error("Invalid codeset!"); + const codeSetRange = codeSet.length; + if (codeSetRange === 1) return codeSet[0]; + return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; +} + +function stringToUnicode(str) { + const utf16Map = Array.from({ + length: str.length + }, (_, i) => str.charCodeAt(i)); + const result = []; + let index = 0; + + while (index < str.length) { + let code = utf16Map[index]; + + if ((UTF16_BITES[0] & code) !== UTF16_BITES[0]) { + result.push(code); + index++; + } else { + result.push(UTF16Decode(utf16Map.slice(index, index + 2))); + index += 2; + } + } + + return result; +} + +function UTF8Length(str) { + const codes = stringToUnicode(str); + return codes.reduce((sum, unicode) => { + if (unicode < 0x80) return sum + 1; + if (unicode < 0x800) return sum + 2; + if (unicode < 0x10000) return sum + 3; + return sum + 4; + }, 0); +} + +class StringReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.StringReader': + case 'System.String': + return true; + + default: + return false; + } + } + + read(buffer) { + let length = buffer.read7BitNumber(); + return buffer.readString(length); + } + + write(buffer, string, resolver) { + this.writeIndex(buffer, resolver); + const size = UTF8Length(string); + buffer.write7BitNumber(size); + buffer.writeString(string); + } + + isValueType() { + return false; + } + +} + +class BmFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'BmFont.XmlSourceReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const stringReader = new StringReader(); + const xml = stringReader.read(buffer); + return { + export: { + type: this.type, + data: xml + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const stringReader = new StringReader(); + stringReader.write(buffer, content.export.data, null); + } + + isValueType() { + return false; + } + +} + +class BooleanReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.BooleanReader': + case 'System.Boolean': + return true; + + default: + return false; + } + } + + read(buffer) { + return Boolean(buffer.readInt()); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeByte(content); + } + +} + +class CharReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.CharReader': + case 'System.Char': + return true; + + default: + return false; + } + } + + read(buffer) { + let charSize = this._getCharSize(buffer.peekInt()); + + return buffer.readString(charSize); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeString(content); + } + + _getCharSize(byte) { + return (0xE5000000 >> (byte >> 3 & 0x1e) & 3) + 1; + } + +} + +class DictionaryReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DictionaryReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(key, value) { + if (key == undefined || value == undefined) throw new Error('Cannot create instance of DictionaryReader without Key and Value.'); + super(); + this.key = key; + this.value = value; + } + + read(buffer, resolver) { + let dictionary = {}; + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + + for (let i = 0; i < size; i++) { + let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); + let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); + dictionary[key] = value; + } + + return dictionary; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeUInt32(Object.keys(content).length); + + for (let key of Object.keys(content)) { + this.key.write(buffer, key, this.key.isValueType() ? null : resolver); + this.value.write(buffer, content[key], this.value.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "Dictionary<".concat(this.key.type, ",").concat(this.value.type, ">"); + } + + parseTypeList() { + return [this.type, ...this.key.parseTypeList(), ...this.value.parseTypeList()]; + } + +} + +class DoubleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.DoubleReader': + case 'System.Double': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readDouble(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeDouble(content); + } + +} + +class EffectReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.EffectReader': + case 'Microsoft.Xna.Framework.Graphics.Effect': + return true; + + default: + return false; + } + } + + read(buffer) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const bytecode = buffer.read(size); + return { + export: { + type: this.type, + data: bytecode + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Int32Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Int32Reader': + case 'System.Int32': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readInt32(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeInt32(content); + } + +} + +class ListReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ListReader': + case 'System.Collections.Generic.List': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const uint32Reader = new UInt32Reader(); + const size = uint32Reader.read(buffer); + const list = []; + + for (let i = 0; i < size; i++) { + const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + list.push(value); + } + + return list; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const uint32Reader = new UInt32Reader(); + uint32Reader.write(buffer, content.length, null); + + for (let data of Object.values(content)) { + this.reader.write(buffer, data, this.reader.isValueType() ? null : resolver); + } + } + + isValueType() { + return false; + } + + get type() { + return "List<".concat(this.reader.type, ">"); + } + + parseTypeList() { + return [this.type, ...this.reader.parseTypeList()]; + } + +} + +class NullableReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.NullableReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer) { + let resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + const booleanReader = new BooleanReader(); + const hasValue = buffer.peekByte(1); + + if (!hasValue) { + booleanReader.read(buffer); + return null; + } + + if (resolver === null) { + booleanReader.read(buffer); + return this.reader.read(buffer); + } + + return this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); + } + + write(buffer) { + let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + let resolver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + if (content === null) { + buffer.writeByte(0); + return; + } + + if (resolver === null) buffer.writeByte(1); + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "Nullable<".concat(this.reader.type, ">"); + } + + parseTypeList() { + const inBlock = this.reader.parseTypeList(); + return ["".concat(this.type, ":").concat(inBlock.length), ...inBlock]; + } + +} + +class ReflectiveReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.ReflectiveReader': + return true; + + default: + return false; + } + } + + static hasSubType() { + return true; + } + + constructor(reader) { + super(); + this.reader = reader; + } + + read(buffer, resolver) { + const reflective = this.reader.read(buffer, resolver); + return reflective; + } + + write(buffer, content, resolver) { + this.reader.write(buffer, content, this.reader.isValueType() ? null : resolver); + } + + isValueType() { + return false; + } + + get type() { + return "".concat(this.reader.type); + } + + parseTypeList() { + return [...this.reader.parseTypeList()]; + } + +} + +class RectangleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.RectangleReader': + case 'Microsoft.Xna.Framework.Rectangle': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const x = int32Reader.read(buffer); + const y = int32Reader.read(buffer); + const width = int32Reader.read(buffer); + const height = int32Reader.read(buffer); + return { + x, + y, + width, + height + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content.x, null); + int32Reader.write(buffer, content.y, null); + int32Reader.write(buffer, content.width, null); + int32Reader.write(buffer, content.height, null); + } + +} + +class SingleReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SingleReader': + case 'System.Single': + return true; + + default: + return false; + } + } + + read(buffer) { + return buffer.readSingle(); + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + buffer.writeSingle(content); + } + +} + +const kDxt1 = 1 << 0; +const kDxt3 = 1 << 1; +const kDxt5 = 1 << 2; +const kColourIterativeClusterFit = 1 << 8; +const kColourClusterFit = 1 << 3; +const kColourRangeFit = 1 << 4; +const kColourMetricPerceptual = 1 << 5; +const kColourMetricUniform = 1 << 6; +const kWeightColourByAlpha = 1 << 7; + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function Rot(theta) { + let Mat = [[Math.cos(theta), Math.sin(theta)], [-Math.sin(theta), Math.cos(theta)]]; + return Mat; +} + +function Rij(k, l, theta, N) { + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = (i === j) * 1.0; + } + } + + let Rotij = Rot(theta); + Mat[k][k] = Rotij[0][0]; + Mat[l][l] = Rotij[1][1]; + Mat[k][l] = Rotij[0][1]; + Mat[l][k] = Rotij[1][0]; + return Mat; +} + +function getTheta(aii, ajj, aij) { + let th = 0.0; + let denom = ajj - aii; + + if (Math.abs(denom) <= 1E-12) { + th = Math.PI / 4.0; + } else { + th = 0.5 * Math.atan(2.0 * aij / (ajj - aii)); + } + + return th; +} + +function getAij(Mij) { + let N = Mij.length; + let maxMij = 0.0; + let maxIJ = [0, 1]; + + for (let i = 0; i < N; i++) { + for (let j = i + 1; j < N; j++) { + if (Math.abs(maxMij) <= Math.abs(Mij[i][j])) { + maxMij = Math.abs(Mij[i][j]); + maxIJ = [i, j]; + } + } + } + + return [maxIJ, maxMij]; +} + +function unitary(U, H) { + let N = U.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + for (let l = 0; l < N; l++) { + Mat[i][j] = Mat[i][j] + U[k][i] * H[k][l] * U[l][j]; + } + } + } + } + + return Mat; +} + +function AxB(A, B) { + let N = A.length; + let Mat = Array(N); + + for (let i = 0; i < N; i++) { + Mat[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Mat[i][j] = 0; + + for (let k = 0; k < N; k++) { + Mat[i][j] = Mat[i][j] + A[i][k] * B[k][j]; + } + } + } + + return Mat; +} + +function eigens(Hij) { + let convergence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1E-7; + let N = Hij.length; + let Ei = Array(N); + let e0 = Math.abs(convergence / N); + let Sij = Array(N); + + for (let i = 0; i < N; i++) { + Sij[i] = Array(N); + } + + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + Sij[i][j] = (i === j) * 1.0; + } + } + + let Vab = getAij(Hij); + + while (Math.abs(Vab[1]) >= Math.abs(e0)) { + let i = Vab[0][0]; + let j = Vab[0][1]; + let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); + let Gij = Rij(i, j, psi, N); + Hij = unitary(Gij, Hij); + Sij = AxB(Sij, Gij); + Vab = getAij(Hij); + } + + for (let i = 0; i < N; i++) { + Ei[i] = Hij[i][i]; + } + + return sorting(Ei, Sij); +} + +function sorting(values, vectors) { + let eigsCount = values.length; + vectors.length; + let pairs = Array.from({ + length: eigsCount + }, (_, i) => { + let vector = vectors.map(v => v[i]); + return { + value: values[i], + vec: vector + }; + }); + pairs.sort((a, b) => b.value - a.value); + let sortedValues = pairs.map(_ref => { + let { + value + } = _ref; + return value; + }); + let sortedVectors = pairs.map(_ref2 => { + let { + vec + } = _ref2; + return vec; + }); + return [sortedValues, sortedVectors]; +} + +function dominentPrincipalVector(matrix) { + let [, [dominentVector]] = eigens(matrix); + return dominentVector; +} + +class Vec3 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values = [x, y, z]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + get normalized() { + if (this.length === 0) return null; + return Vec3.multScalar(this, 1 / this.length); + } + + get colorInt() { + const floatToInt = value => { + const result = parseInt(value * 255 + 0.5); + return Math.max(Math.min(result, 255), 0); + }; + + return this._values.map(floatToInt); + } + + clone() { + return new Vec3(this.x, this.y, this.z); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + return this; + } + + toVec4() { + let w = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; + return new Vec4(this.x, this.y, this.z, w); + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + return this; + } + + toString() { + return "Vec3( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); + } + + static sub(a, b) { + return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z; + } + + static multScalar(a, scalar) { + return new Vec3(a.x * scalar, a.y * scalar, a.z * scalar); + } + + static multVector(a, b) { + return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); + } + + static interpolate(a, b, p) { + let a_ = Vec3.multScalar(a, 1 - p); + let b_ = Vec3.multScalar(b, p); + return Vec3.add(a_, b_); + } + +} + +class Vec4 { + constructor() { + let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values = [x, y, z, w]; + } + + get x() { + return this._values[0]; + } + + get y() { + return this._values[1]; + } + + get z() { + return this._values[2]; + } + + get w() { + return this._values[3]; + } + + set x(value) { + this._values[0] = value; + } + + set y(value) { + this._values[1] = value; + } + + set z(value) { + this._values[2] = value; + } + + set w(value) { + this._values[3] = value; + } + + get length() { + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + get lengthSq() { + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + } + + get normalized() { + if (this.length === 0) return null; + return Vec4.multScalar(this, 1 / this.length); + } + + get xyz() { + return new Vec3(this.x, this.y, this.z); + } + + get splatX() { + return new Vec4(this.x); + } + + get splatY() { + return new Vec4(this.y); + } + + get splatZ() { + return new Vec4(this.z); + } + + get splatW() { + return new Vec4(this.w); + } + + clone() { + return new Vec4(this.x, this.y, this.z, this.w); + } + + set(x) { + let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + let z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : x; + let w = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : x; + this._values[0] = x; + this._values[1] = y; + this._values[2] = z; + this._values[3] = w; + return this; + } + + toVec3() { + return this.xyz; + } + + addVector(v) { + this._values[0] += v.x; + this._values[1] += v.y; + this._values[2] += v.z; + this._values[3] += v.w; + return this; + } + + addScaledVector(v, scalar) { + this._values[0] += v.x * scalar; + this._values[1] += v.y * scalar; + this._values[2] += v.z * scalar; + this._values[3] += v.w * scalar; + return this; + } + + subVector(v) { + this._values[0] -= v.x; + this._values[1] -= v.y; + this._values[2] -= v.z; + this._values[3] -= v.w; + return this; + } + + mult(scalar) { + this._values[0] *= scalar; + this._values[1] *= scalar; + this._values[2] *= scalar; + this._values[3] *= scalar; + return this; + } + + multVector(vec) { + this._values[0] *= vec.x; + this._values[1] *= vec.y; + this._values[2] *= vec.z; + this._values[3] *= vec.w; + return this; + } + + reciprocal() { + this._values[0] = 1 / this._values[0]; + this._values[1] = 1 / this._values[1]; + this._values[2] = 1 / this._values[2]; + this._values[3] = 1 / this._values[3]; + return this; + } + + clamp(min, max) { + const clamper = v => min > v ? min : max < v ? max : v; + + this._values[0] = clamper(this._values[0]); + this._values[1] = clamper(this._values[1]); + this._values[2] = clamper(this._values[2]); + this._values[3] = clamper(this._values[3]); + return this; + } + + clampGrid() { + const clamper = v => 0 > v ? 0 : 1 < v ? 1 : v; + + const gridClamper = (value, grid) => Math.trunc(clamper(value) * grid + 0.5) / grid; + + this._values[0] = gridClamper(this._values[0], 31); + this._values[1] = gridClamper(this._values[1], 63); + this._values[2] = gridClamper(this._values[2], 31); + this._values[3] = clamper(this._values[3]); + return this; + } + + truncate() { + this._values[0] = Math.trunc(this._values[0]); + this._values[1] = Math.trunc(this._values[1]); + this._values[2] = Math.trunc(this._values[2]); + this._values[3] = Math.trunc(this._values[3]); + return this; + } + + normalize() { + this._values[0] /= this.length; + this._values[1] /= this.length; + this._values[2] /= this.length; + this._values[3] /= this.length; + return this; + } + + toString() { + return "Vec4( ".concat(this._values.join(", "), " )"); + } + + static add(a, b) { + return new Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + } + + static sub(a, b) { + return new Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + + static dot(a, b) { + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + } + + static multScalar(a, scalar) { + return new Vec4(a.x * scalar, a.y * scalar, a.z * scalar, a.w * scalar); + } + + static multVector(a, b) { + return new Vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + + static interpolate(a, b, p) { + let a_ = Vec4.multScalar(a, 1 - p); + let b_ = Vec4.multScalar(b, p); + return Vec4.add(a_, b_); + } + + static multiplyAdd(a, b, c) { + return new Vec4(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z, a.w * b.w + c.w); + } + + static negativeMultiplySubtract(a, b, c) { + return new Vec4(c.x - a.x * b.x, c.y - a.y * b.y, c.z - a.z * b.z, c.w - a.w * b.w); + } + + static compareAnyLessThan(left, right) { + return left.x < right.x || left.y < right.y || left.z < right.z || left.w < right.w; + } + +} + +function computeWeightedCovariance(values, weights) { + let total = 0; + let mean = values.reduce((sum, value, i) => { + total += weights[i]; + sum.addScaledVector(value, weights[i]); + return sum; + }, new Vec3(0)); + mean.mult(1 / total); + let covariance = values.reduce((sum, value, i) => { + let weight = weights[i]; + let v = Vec3.sub(value, mean); + sum[0][0] += v.x * v.x * weight; + sum[0][1] += v.x * v.y * weight; + sum[0][2] += v.x * v.z * weight; + sum[1][1] += v.y * v.y * weight; + sum[1][2] += v.y * v.z * weight; + sum[2][2] += v.z * v.z * weight; + return sum; + }, [[0, 0, 0], [0, 0, 0], [0, 0, 0]]); + covariance[1][0] = covariance[0][1]; + covariance[2][0] = covariance[0][2]; + covariance[2][1] = covariance[1][2]; + return covariance; +} + +function computePCA(values, weights) { + const covariance = computeWeightedCovariance(values, weights); + return new Vec3(...dominentPrincipalVector(covariance)); +} + +const lookup_5_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[0, 0, 2], [0, 0, 2]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 1, 0]], [[1, 0, 3], [0, 1, 1]], [[1, 0, 2], [0, 1, 2]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 2], [0, 2, 2]], [[1, 0, 3], [0, 3, 1]], [[1, 0, 4], [0, 3, 0]], [[2, 0, 3], [0, 3, 1]], [[2, 0, 2], [0, 3, 2]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 2], [0, 4, 2]], [[2, 0, 3], [0, 5, 1]], [[2, 0, 4], [0, 5, 0]], [[3, 0, 3], [0, 5, 1]], [[3, 0, 2], [0, 5, 2]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 2], [0, 6, 2]], [[3, 0, 3], [0, 7, 1]], [[3, 0, 4], [0, 7, 0]], [[4, 0, 4], [0, 7, 1]], [[4, 0, 3], [0, 7, 2]], [[4, 0, 2], [1, 7, 1]], [[4, 0, 1], [1, 7, 0]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 2], [2, 7, 1]], [[4, 0, 3], [2, 7, 0]], [[4, 0, 4], [0, 9, 0]], [[5, 0, 3], [0, 9, 1]], [[5, 0, 2], [3, 7, 1]], [[5, 0, 1], [3, 7, 0]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 2], [0, 10, 2]], [[5, 0, 3], [0, 11, 1]], [[5, 0, 4], [0, 11, 0]], [[6, 0, 3], [0, 11, 1]], [[6, 0, 2], [0, 11, 2]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 2], [0, 12, 2]], [[6, 0, 3], [0, 13, 1]], [[6, 0, 4], [0, 13, 0]], [[7, 0, 3], [0, 13, 1]], [[7, 0, 2], [0, 13, 2]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 2], [0, 14, 2]], [[7, 0, 3], [0, 15, 1]], [[7, 0, 4], [0, 15, 0]], [[8, 0, 4], [0, 15, 1]], [[8, 0, 3], [0, 15, 2]], [[8, 0, 2], [1, 15, 1]], [[8, 0, 1], [1, 15, 0]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 2], [2, 15, 1]], [[8, 0, 3], [2, 15, 0]], [[8, 0, 4], [0, 17, 0]], [[9, 0, 3], [0, 17, 1]], [[9, 0, 2], [3, 15, 1]], [[9, 0, 1], [3, 15, 0]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 2], [0, 18, 2]], [[9, 0, 3], [0, 19, 1]], [[9, 0, 4], [0, 19, 0]], [[10, 0, 3], [0, 19, 1]], [[10, 0, 2], [0, 19, 2]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 2], [0, 20, 2]], [[10, 0, 3], [0, 21, 1]], [[10, 0, 4], [0, 21, 0]], [[11, 0, 3], [0, 21, 1]], [[11, 0, 2], [0, 21, 2]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 2], [0, 22, 2]], [[11, 0, 3], [0, 23, 1]], [[11, 0, 4], [0, 23, 0]], [[12, 0, 4], [0, 23, 1]], [[12, 0, 3], [0, 23, 2]], [[12, 0, 2], [1, 23, 1]], [[12, 0, 1], [1, 23, 0]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 2], [2, 23, 1]], [[12, 0, 3], [2, 23, 0]], [[12, 0, 4], [0, 25, 0]], [[13, 0, 3], [0, 25, 1]], [[13, 0, 2], [3, 23, 1]], [[13, 0, 1], [3, 23, 0]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 2], [0, 26, 2]], [[13, 0, 3], [0, 27, 1]], [[13, 0, 4], [0, 27, 0]], [[14, 0, 3], [0, 27, 1]], [[14, 0, 2], [0, 27, 2]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 2], [0, 28, 2]], [[14, 0, 3], [0, 29, 1]], [[14, 0, 4], [0, 29, 0]], [[15, 0, 3], [0, 29, 1]], [[15, 0, 2], [0, 29, 2]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 2], [0, 30, 2]], [[15, 0, 3], [0, 31, 1]], [[15, 0, 4], [0, 31, 0]], [[16, 0, 4], [0, 31, 1]], [[16, 0, 3], [0, 31, 2]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [4, 28, 0]], [[16, 0, 1], [4, 28, 1]], [[16, 0, 2], [2, 31, 1]], [[16, 0, 3], [2, 31, 0]], [[16, 0, 4], [4, 29, 0]], [[17, 0, 3], [4, 29, 1]], [[17, 0, 2], [3, 31, 1]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [4, 30, 0]], [[17, 0, 1], [4, 30, 1]], [[17, 0, 2], [4, 30, 2]], [[17, 0, 3], [4, 31, 1]], [[17, 0, 4], [4, 31, 0]], [[18, 0, 3], [4, 31, 1]], [[18, 0, 2], [4, 31, 2]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 0], [5, 31, 0]], [[18, 0, 1], [5, 31, 1]], [[18, 0, 2], [5, 31, 2]], [[18, 0, 3], [6, 31, 1]], [[18, 0, 4], [6, 31, 0]], [[19, 0, 3], [6, 31, 1]], [[19, 0, 2], [6, 31, 2]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 0], [7, 31, 0]], [[19, 0, 1], [7, 31, 1]], [[19, 0, 2], [7, 31, 2]], [[19, 0, 3], [8, 31, 1]], [[19, 0, 4], [8, 31, 0]], [[20, 0, 4], [8, 31, 1]], [[20, 0, 3], [8, 31, 2]], [[20, 0, 2], [9, 31, 1]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [12, 28, 0]], [[20, 0, 1], [12, 28, 1]], [[20, 0, 2], [10, 31, 1]], [[20, 0, 3], [10, 31, 0]], [[20, 0, 4], [12, 29, 0]], [[21, 0, 3], [12, 29, 1]], [[21, 0, 2], [11, 31, 1]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [12, 30, 0]], [[21, 0, 1], [12, 30, 1]], [[21, 0, 2], [12, 30, 2]], [[21, 0, 3], [12, 31, 1]], [[21, 0, 4], [12, 31, 0]], [[22, 0, 3], [12, 31, 1]], [[22, 0, 2], [12, 31, 2]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 0], [13, 31, 0]], [[22, 0, 1], [13, 31, 1]], [[22, 0, 2], [13, 31, 2]], [[22, 0, 3], [14, 31, 1]], [[22, 0, 4], [14, 31, 0]], [[23, 0, 3], [14, 31, 1]], [[23, 0, 2], [14, 31, 2]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 0], [15, 31, 0]], [[23, 0, 1], [15, 31, 1]], [[23, 0, 2], [15, 31, 2]], [[23, 0, 3], [16, 31, 1]], [[23, 0, 4], [16, 31, 0]], [[24, 0, 4], [16, 31, 1]], [[24, 0, 3], [16, 31, 2]], [[24, 0, 2], [17, 31, 1]], [[24, 0, 1], [17, 31, 0]], [[24, 0, 0], [20, 28, 0]], [[24, 0, 1], [20, 28, 1]], [[24, 0, 2], [18, 31, 1]], [[24, 0, 3], [18, 31, 0]], [[24, 0, 4], [20, 29, 0]], [[25, 0, 3], [20, 29, 1]], [[25, 0, 2], [19, 31, 1]], [[25, 0, 1], [19, 31, 0]], [[25, 0, 0], [20, 30, 0]], [[25, 0, 1], [20, 30, 1]], [[25, 0, 2], [20, 30, 2]], [[25, 0, 3], [20, 31, 1]], [[25, 0, 4], [20, 31, 0]], [[26, 0, 3], [20, 31, 1]], [[26, 0, 2], [20, 31, 2]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 0], [21, 31, 0]], [[26, 0, 1], [21, 31, 1]], [[26, 0, 2], [21, 31, 2]], [[26, 0, 3], [22, 31, 1]], [[26, 0, 4], [22, 31, 0]], [[27, 0, 3], [22, 31, 1]], [[27, 0, 2], [22, 31, 2]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 0], [23, 31, 0]], [[27, 0, 1], [23, 31, 1]], [[27, 0, 2], [23, 31, 2]], [[27, 0, 3], [24, 31, 1]], [[27, 0, 4], [24, 31, 0]], [[28, 0, 4], [24, 31, 1]], [[28, 0, 3], [24, 31, 2]], [[28, 0, 2], [25, 31, 1]], [[28, 0, 1], [25, 31, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [28, 28, 1]], [[28, 0, 2], [26, 31, 1]], [[28, 0, 3], [26, 31, 0]], [[28, 0, 4], [28, 29, 0]], [[29, 0, 3], [28, 29, 1]], [[29, 0, 2], [27, 31, 1]], [[29, 0, 1], [27, 31, 0]], [[29, 0, 0], [28, 30, 0]], [[29, 0, 1], [28, 30, 1]], [[29, 0, 2], [28, 30, 2]], [[29, 0, 3], [28, 31, 1]], [[29, 0, 4], [28, 31, 0]], [[30, 0, 3], [28, 31, 1]], [[30, 0, 2], [28, 31, 2]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 0], [29, 31, 0]], [[30, 0, 1], [29, 31, 1]], [[30, 0, 2], [29, 31, 2]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [30, 31, 0]], [[31, 0, 3], [30, 31, 1]], [[31, 0, 2], [30, 31, 2]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_3 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[1, 0, 1], [0, 2, 1]], [[1, 0, 0], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 2], [0, 3, 0]], [[2, 0, 1], [0, 4, 1]], [[2, 0, 0], [0, 4, 0]], [[2, 0, 1], [0, 5, 1]], [[2, 0, 2], [0, 5, 0]], [[3, 0, 1], [0, 6, 1]], [[3, 0, 0], [0, 6, 0]], [[3, 0, 1], [0, 7, 1]], [[3, 0, 2], [0, 7, 0]], [[4, 0, 1], [0, 8, 1]], [[4, 0, 0], [0, 8, 0]], [[4, 0, 1], [0, 9, 1]], [[4, 0, 2], [0, 9, 0]], [[5, 0, 1], [0, 10, 1]], [[5, 0, 0], [0, 10, 0]], [[5, 0, 1], [0, 11, 1]], [[5, 0, 2], [0, 11, 0]], [[6, 0, 1], [0, 12, 1]], [[6, 0, 0], [0, 12, 0]], [[6, 0, 1], [0, 13, 1]], [[6, 0, 2], [0, 13, 0]], [[7, 0, 1], [0, 14, 1]], [[7, 0, 0], [0, 14, 0]], [[7, 0, 1], [0, 15, 1]], [[7, 0, 2], [0, 15, 0]], [[8, 0, 1], [0, 16, 1]], [[8, 0, 0], [0, 16, 0]], [[8, 0, 1], [0, 17, 1]], [[8, 0, 2], [0, 17, 0]], [[9, 0, 1], [0, 18, 1]], [[9, 0, 0], [0, 18, 0]], [[9, 0, 1], [0, 19, 1]], [[9, 0, 2], [0, 19, 0]], [[10, 0, 1], [0, 20, 1]], [[10, 0, 0], [0, 20, 0]], [[10, 0, 1], [0, 21, 1]], [[10, 0, 2], [0, 21, 0]], [[11, 0, 1], [0, 22, 1]], [[11, 0, 0], [0, 22, 0]], [[11, 0, 1], [0, 23, 1]], [[11, 0, 2], [0, 23, 0]], [[12, 0, 1], [0, 24, 1]], [[12, 0, 0], [0, 24, 0]], [[12, 0, 1], [0, 25, 1]], [[12, 0, 2], [0, 25, 0]], [[13, 0, 1], [0, 26, 1]], [[13, 0, 0], [0, 26, 0]], [[13, 0, 1], [0, 27, 1]], [[13, 0, 2], [0, 27, 0]], [[14, 0, 1], [0, 28, 1]], [[14, 0, 0], [0, 28, 0]], [[14, 0, 1], [0, 29, 1]], [[14, 0, 2], [0, 29, 0]], [[15, 0, 1], [0, 30, 1]], [[15, 0, 0], [0, 30, 0]], [[15, 0, 1], [0, 31, 1]], [[15, 0, 2], [0, 31, 0]], [[16, 0, 2], [1, 31, 1]], [[16, 0, 1], [1, 31, 0]], [[16, 0, 0], [0, 32, 0]], [[16, 0, 1], [2, 31, 0]], [[16, 0, 2], [0, 33, 0]], [[17, 0, 1], [3, 31, 0]], [[17, 0, 0], [0, 34, 0]], [[17, 0, 1], [4, 31, 0]], [[17, 0, 2], [0, 35, 0]], [[18, 0, 1], [5, 31, 0]], [[18, 0, 0], [0, 36, 0]], [[18, 0, 1], [6, 31, 0]], [[18, 0, 2], [0, 37, 0]], [[19, 0, 1], [7, 31, 0]], [[19, 0, 0], [0, 38, 0]], [[19, 0, 1], [8, 31, 0]], [[19, 0, 2], [0, 39, 0]], [[20, 0, 1], [9, 31, 0]], [[20, 0, 0], [0, 40, 0]], [[20, 0, 1], [10, 31, 0]], [[20, 0, 2], [0, 41, 0]], [[21, 0, 1], [11, 31, 0]], [[21, 0, 0], [0, 42, 0]], [[21, 0, 1], [12, 31, 0]], [[21, 0, 2], [0, 43, 0]], [[22, 0, 1], [13, 31, 0]], [[22, 0, 0], [0, 44, 0]], [[22, 0, 1], [14, 31, 0]], [[22, 0, 2], [0, 45, 0]], [[23, 0, 1], [15, 31, 0]], [[23, 0, 0], [0, 46, 0]], [[23, 0, 1], [0, 47, 1]], [[23, 0, 2], [0, 47, 0]], [[24, 0, 1], [0, 48, 1]], [[24, 0, 0], [0, 48, 0]], [[24, 0, 1], [0, 49, 1]], [[24, 0, 2], [0, 49, 0]], [[25, 0, 1], [0, 50, 1]], [[25, 0, 0], [0, 50, 0]], [[25, 0, 1], [0, 51, 1]], [[25, 0, 2], [0, 51, 0]], [[26, 0, 1], [0, 52, 1]], [[26, 0, 0], [0, 52, 0]], [[26, 0, 1], [0, 53, 1]], [[26, 0, 2], [0, 53, 0]], [[27, 0, 1], [0, 54, 1]], [[27, 0, 0], [0, 54, 0]], [[27, 0, 1], [0, 55, 1]], [[27, 0, 2], [0, 55, 0]], [[28, 0, 1], [0, 56, 1]], [[28, 0, 0], [0, 56, 0]], [[28, 0, 1], [0, 57, 1]], [[28, 0, 2], [0, 57, 0]], [[29, 0, 1], [0, 58, 1]], [[29, 0, 0], [0, 58, 0]], [[29, 0, 1], [0, 59, 1]], [[29, 0, 2], [0, 59, 0]], [[30, 0, 1], [0, 60, 1]], [[30, 0, 0], [0, 60, 0]], [[30, 0, 1], [0, 61, 1]], [[30, 0, 2], [0, 61, 0]], [[31, 0, 1], [0, 62, 1]], [[31, 0, 0], [0, 62, 0]], [[31, 0, 1], [0, 63, 1]], [[31, 0, 2], [0, 63, 0]], [[32, 0, 2], [1, 63, 1]], [[32, 0, 1], [1, 63, 0]], [[32, 0, 0], [16, 48, 0]], [[32, 0, 1], [2, 63, 0]], [[32, 0, 2], [16, 49, 0]], [[33, 0, 1], [3, 63, 0]], [[33, 0, 0], [16, 50, 0]], [[33, 0, 1], [4, 63, 0]], [[33, 0, 2], [16, 51, 0]], [[34, 0, 1], [5, 63, 0]], [[34, 0, 0], [16, 52, 0]], [[34, 0, 1], [6, 63, 0]], [[34, 0, 2], [16, 53, 0]], [[35, 0, 1], [7, 63, 0]], [[35, 0, 0], [16, 54, 0]], [[35, 0, 1], [8, 63, 0]], [[35, 0, 2], [16, 55, 0]], [[36, 0, 1], [9, 63, 0]], [[36, 0, 0], [16, 56, 0]], [[36, 0, 1], [10, 63, 0]], [[36, 0, 2], [16, 57, 0]], [[37, 0, 1], [11, 63, 0]], [[37, 0, 0], [16, 58, 0]], [[37, 0, 1], [12, 63, 0]], [[37, 0, 2], [16, 59, 0]], [[38, 0, 1], [13, 63, 0]], [[38, 0, 0], [16, 60, 0]], [[38, 0, 1], [14, 63, 0]], [[38, 0, 2], [16, 61, 0]], [[39, 0, 1], [15, 63, 0]], [[39, 0, 0], [16, 62, 0]], [[39, 0, 1], [16, 63, 1]], [[39, 0, 2], [16, 63, 0]], [[40, 0, 1], [17, 63, 1]], [[40, 0, 0], [17, 63, 0]], [[40, 0, 1], [18, 63, 1]], [[40, 0, 2], [18, 63, 0]], [[41, 0, 1], [19, 63, 1]], [[41, 0, 0], [19, 63, 0]], [[41, 0, 1], [20, 63, 1]], [[41, 0, 2], [20, 63, 0]], [[42, 0, 1], [21, 63, 1]], [[42, 0, 0], [21, 63, 0]], [[42, 0, 1], [22, 63, 1]], [[42, 0, 2], [22, 63, 0]], [[43, 0, 1], [23, 63, 1]], [[43, 0, 0], [23, 63, 0]], [[43, 0, 1], [24, 63, 1]], [[43, 0, 2], [24, 63, 0]], [[44, 0, 1], [25, 63, 1]], [[44, 0, 0], [25, 63, 0]], [[44, 0, 1], [26, 63, 1]], [[44, 0, 2], [26, 63, 0]], [[45, 0, 1], [27, 63, 1]], [[45, 0, 0], [27, 63, 0]], [[45, 0, 1], [28, 63, 1]], [[45, 0, 2], [28, 63, 0]], [[46, 0, 1], [29, 63, 1]], [[46, 0, 0], [29, 63, 0]], [[46, 0, 1], [30, 63, 1]], [[46, 0, 2], [30, 63, 0]], [[47, 0, 1], [31, 63, 1]], [[47, 0, 0], [31, 63, 0]], [[47, 0, 1], [32, 63, 1]], [[47, 0, 2], [32, 63, 0]], [[48, 0, 2], [33, 63, 1]], [[48, 0, 1], [33, 63, 0]], [[48, 0, 0], [48, 48, 0]], [[48, 0, 1], [34, 63, 0]], [[48, 0, 2], [48, 49, 0]], [[49, 0, 1], [35, 63, 0]], [[49, 0, 0], [48, 50, 0]], [[49, 0, 1], [36, 63, 0]], [[49, 0, 2], [48, 51, 0]], [[50, 0, 1], [37, 63, 0]], [[50, 0, 0], [48, 52, 0]], [[50, 0, 1], [38, 63, 0]], [[50, 0, 2], [48, 53, 0]], [[51, 0, 1], [39, 63, 0]], [[51, 0, 0], [48, 54, 0]], [[51, 0, 1], [40, 63, 0]], [[51, 0, 2], [48, 55, 0]], [[52, 0, 1], [41, 63, 0]], [[52, 0, 0], [48, 56, 0]], [[52, 0, 1], [42, 63, 0]], [[52, 0, 2], [48, 57, 0]], [[53, 0, 1], [43, 63, 0]], [[53, 0, 0], [48, 58, 0]], [[53, 0, 1], [44, 63, 0]], [[53, 0, 2], [48, 59, 0]], [[54, 0, 1], [45, 63, 0]], [[54, 0, 0], [48, 60, 0]], [[54, 0, 1], [46, 63, 0]], [[54, 0, 2], [48, 61, 0]], [[55, 0, 1], [47, 63, 0]], [[55, 0, 0], [48, 62, 0]], [[55, 0, 1], [48, 63, 1]], [[55, 0, 2], [48, 63, 0]], [[56, 0, 1], [49, 63, 1]], [[56, 0, 0], [49, 63, 0]], [[56, 0, 1], [50, 63, 1]], [[56, 0, 2], [50, 63, 0]], [[57, 0, 1], [51, 63, 1]], [[57, 0, 0], [51, 63, 0]], [[57, 0, 1], [52, 63, 1]], [[57, 0, 2], [52, 63, 0]], [[58, 0, 1], [53, 63, 1]], [[58, 0, 0], [53, 63, 0]], [[58, 0, 1], [54, 63, 1]], [[58, 0, 2], [54, 63, 0]], [[59, 0, 1], [55, 63, 1]], [[59, 0, 0], [55, 63, 0]], [[59, 0, 1], [56, 63, 1]], [[59, 0, 2], [56, 63, 0]], [[60, 0, 1], [57, 63, 1]], [[60, 0, 0], [57, 63, 0]], [[60, 0, 1], [58, 63, 1]], [[60, 0, 2], [58, 63, 0]], [[61, 0, 1], [59, 63, 1]], [[61, 0, 0], [59, 63, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 2], [60, 63, 0]], [[62, 0, 1], [61, 63, 1]], [[62, 0, 0], [61, 63, 0]], [[62, 0, 1], [62, 63, 1]], [[62, 0, 2], [62, 63, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; +const lookup_5_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 1]], [[0, 0, 2], [0, 1, 0]], [[0, 0, 3], [0, 1, 1]], [[0, 0, 4], [0, 2, 1]], [[1, 0, 3], [0, 2, 0]], [[1, 0, 2], [0, 2, 1]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [1, 2, 1]], [[1, 0, 2], [1, 2, 0]], [[1, 0, 3], [0, 4, 0]], [[1, 0, 4], [0, 5, 1]], [[2, 0, 3], [0, 5, 0]], [[2, 0, 2], [0, 5, 1]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [2, 3, 1]], [[2, 0, 2], [2, 3, 0]], [[2, 0, 3], [0, 7, 0]], [[2, 0, 4], [1, 6, 1]], [[3, 0, 3], [1, 6, 0]], [[3, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 2], [0, 10, 1]], [[3, 0, 3], [0, 10, 0]], [[3, 0, 4], [2, 7, 1]], [[4, 0, 4], [2, 7, 0]], [[4, 0, 3], [0, 11, 0]], [[4, 0, 2], [1, 10, 1]], [[4, 0, 1], [1, 10, 0]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 1]], [[4, 0, 2], [0, 13, 0]], [[4, 0, 3], [0, 13, 1]], [[4, 0, 4], [0, 14, 1]], [[5, 0, 3], [0, 14, 0]], [[5, 0, 2], [2, 11, 1]], [[5, 0, 1], [2, 11, 0]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [1, 14, 1]], [[5, 0, 2], [1, 14, 0]], [[5, 0, 3], [0, 16, 0]], [[5, 0, 4], [0, 17, 1]], [[6, 0, 3], [0, 17, 0]], [[6, 0, 2], [0, 17, 1]], [[6, 0, 1], [0, 18, 1]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [2, 15, 1]], [[6, 0, 2], [2, 15, 0]], [[6, 0, 3], [0, 19, 0]], [[6, 0, 4], [1, 18, 1]], [[7, 0, 3], [1, 18, 0]], [[7, 0, 2], [0, 20, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 21, 1]], [[7, 0, 2], [0, 22, 1]], [[7, 0, 3], [0, 22, 0]], [[7, 0, 4], [2, 19, 1]], [[8, 0, 4], [2, 19, 0]], [[8, 0, 3], [0, 23, 0]], [[8, 0, 2], [1, 22, 1]], [[8, 0, 1], [1, 22, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 1]], [[8, 0, 2], [0, 25, 0]], [[8, 0, 3], [0, 25, 1]], [[8, 0, 4], [0, 26, 1]], [[9, 0, 3], [0, 26, 0]], [[9, 0, 2], [2, 23, 1]], [[9, 0, 1], [2, 23, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [1, 26, 1]], [[9, 0, 2], [1, 26, 0]], [[9, 0, 3], [0, 28, 0]], [[9, 0, 4], [0, 29, 1]], [[10, 0, 3], [0, 29, 0]], [[10, 0, 2], [0, 29, 1]], [[10, 0, 1], [0, 30, 1]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [2, 27, 1]], [[10, 0, 2], [2, 27, 0]], [[10, 0, 3], [0, 31, 0]], [[10, 0, 4], [1, 30, 1]], [[11, 0, 3], [1, 30, 0]], [[11, 0, 2], [4, 24, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 0], [1, 31, 0]], [[11, 0, 1], [1, 31, 1]], [[11, 0, 2], [2, 30, 1]], [[11, 0, 3], [2, 30, 0]], [[11, 0, 4], [2, 31, 1]], [[12, 0, 4], [2, 31, 0]], [[12, 0, 3], [4, 27, 0]], [[12, 0, 2], [3, 30, 1]], [[12, 0, 1], [3, 30, 0]], [[12, 0, 0], [4, 28, 0]], [[12, 0, 1], [3, 31, 1]], [[12, 0, 2], [3, 31, 0]], [[12, 0, 3], [3, 31, 1]], [[12, 0, 4], [4, 30, 1]], [[13, 0, 3], [4, 30, 0]], [[13, 0, 2], [6, 27, 1]], [[13, 0, 1], [6, 27, 0]], [[13, 0, 0], [4, 31, 0]], [[13, 0, 1], [5, 30, 1]], [[13, 0, 2], [5, 30, 0]], [[13, 0, 3], [8, 24, 0]], [[13, 0, 4], [5, 31, 1]], [[14, 0, 3], [5, 31, 0]], [[14, 0, 2], [5, 31, 1]], [[14, 0, 1], [6, 30, 1]], [[14, 0, 0], [6, 30, 0]], [[14, 0, 1], [6, 31, 1]], [[14, 0, 2], [6, 31, 0]], [[14, 0, 3], [8, 27, 0]], [[14, 0, 4], [7, 30, 1]], [[15, 0, 3], [7, 30, 0]], [[15, 0, 2], [8, 28, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 0], [7, 31, 0]], [[15, 0, 1], [7, 31, 1]], [[15, 0, 2], [8, 30, 1]], [[15, 0, 3], [8, 30, 0]], [[15, 0, 4], [10, 27, 1]], [[16, 0, 4], [10, 27, 0]], [[16, 0, 3], [8, 31, 0]], [[16, 0, 2], [9, 30, 1]], [[16, 0, 1], [9, 30, 0]], [[16, 0, 0], [12, 24, 0]], [[16, 0, 1], [9, 31, 1]], [[16, 0, 2], [9, 31, 0]], [[16, 0, 3], [9, 31, 1]], [[16, 0, 4], [10, 30, 1]], [[17, 0, 3], [10, 30, 0]], [[17, 0, 2], [10, 31, 1]], [[17, 0, 1], [10, 31, 0]], [[17, 0, 0], [12, 27, 0]], [[17, 0, 1], [11, 30, 1]], [[17, 0, 2], [11, 30, 0]], [[17, 0, 3], [12, 28, 0]], [[17, 0, 4], [11, 31, 1]], [[18, 0, 3], [11, 31, 0]], [[18, 0, 2], [11, 31, 1]], [[18, 0, 1], [12, 30, 1]], [[18, 0, 0], [12, 30, 0]], [[18, 0, 1], [14, 27, 1]], [[18, 0, 2], [14, 27, 0]], [[18, 0, 3], [12, 31, 0]], [[18, 0, 4], [13, 30, 1]], [[19, 0, 3], [13, 30, 0]], [[19, 0, 2], [16, 24, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 0], [13, 31, 0]], [[19, 0, 1], [13, 31, 1]], [[19, 0, 2], [14, 30, 1]], [[19, 0, 3], [14, 30, 0]], [[19, 0, 4], [14, 31, 1]], [[20, 0, 4], [14, 31, 0]], [[20, 0, 3], [16, 27, 0]], [[20, 0, 2], [15, 30, 1]], [[20, 0, 1], [15, 30, 0]], [[20, 0, 0], [16, 28, 0]], [[20, 0, 1], [15, 31, 1]], [[20, 0, 2], [15, 31, 0]], [[20, 0, 3], [15, 31, 1]], [[20, 0, 4], [16, 30, 1]], [[21, 0, 3], [16, 30, 0]], [[21, 0, 2], [18, 27, 1]], [[21, 0, 1], [18, 27, 0]], [[21, 0, 0], [16, 31, 0]], [[21, 0, 1], [17, 30, 1]], [[21, 0, 2], [17, 30, 0]], [[21, 0, 3], [20, 24, 0]], [[21, 0, 4], [17, 31, 1]], [[22, 0, 3], [17, 31, 0]], [[22, 0, 2], [17, 31, 1]], [[22, 0, 1], [18, 30, 1]], [[22, 0, 0], [18, 30, 0]], [[22, 0, 1], [18, 31, 1]], [[22, 0, 2], [18, 31, 0]], [[22, 0, 3], [20, 27, 0]], [[22, 0, 4], [19, 30, 1]], [[23, 0, 3], [19, 30, 0]], [[23, 0, 2], [20, 28, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 0], [19, 31, 0]], [[23, 0, 1], [19, 31, 1]], [[23, 0, 2], [20, 30, 1]], [[23, 0, 3], [20, 30, 0]], [[23, 0, 4], [22, 27, 1]], [[24, 0, 4], [22, 27, 0]], [[24, 0, 3], [20, 31, 0]], [[24, 0, 2], [21, 30, 1]], [[24, 0, 1], [21, 30, 0]], [[24, 0, 0], [24, 24, 0]], [[24, 0, 1], [21, 31, 1]], [[24, 0, 2], [21, 31, 0]], [[24, 0, 3], [21, 31, 1]], [[24, 0, 4], [22, 30, 1]], [[25, 0, 3], [22, 30, 0]], [[25, 0, 2], [22, 31, 1]], [[25, 0, 1], [22, 31, 0]], [[25, 0, 0], [24, 27, 0]], [[25, 0, 1], [23, 30, 1]], [[25, 0, 2], [23, 30, 0]], [[25, 0, 3], [24, 28, 0]], [[25, 0, 4], [23, 31, 1]], [[26, 0, 3], [23, 31, 0]], [[26, 0, 2], [23, 31, 1]], [[26, 0, 1], [24, 30, 1]], [[26, 0, 0], [24, 30, 0]], [[26, 0, 1], [26, 27, 1]], [[26, 0, 2], [26, 27, 0]], [[26, 0, 3], [24, 31, 0]], [[26, 0, 4], [25, 30, 1]], [[27, 0, 3], [25, 30, 0]], [[27, 0, 2], [28, 24, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 0], [25, 31, 0]], [[27, 0, 1], [25, 31, 1]], [[27, 0, 2], [26, 30, 1]], [[27, 0, 3], [26, 30, 0]], [[27, 0, 4], [26, 31, 1]], [[28, 0, 4], [26, 31, 0]], [[28, 0, 3], [28, 27, 0]], [[28, 0, 2], [27, 30, 1]], [[28, 0, 1], [27, 30, 0]], [[28, 0, 0], [28, 28, 0]], [[28, 0, 1], [27, 31, 1]], [[28, 0, 2], [27, 31, 0]], [[28, 0, 3], [27, 31, 1]], [[28, 0, 4], [28, 30, 1]], [[29, 0, 3], [28, 30, 0]], [[29, 0, 2], [30, 27, 1]], [[29, 0, 1], [30, 27, 0]], [[29, 0, 0], [28, 31, 0]], [[29, 0, 1], [29, 30, 1]], [[29, 0, 2], [29, 30, 0]], [[29, 0, 3], [29, 30, 1]], [[29, 0, 4], [29, 31, 1]], [[30, 0, 3], [29, 31, 0]], [[30, 0, 2], [29, 31, 1]], [[30, 0, 1], [30, 30, 1]], [[30, 0, 0], [30, 30, 0]], [[30, 0, 1], [30, 31, 1]], [[30, 0, 2], [30, 31, 0]], [[30, 0, 3], [30, 31, 1]], [[30, 0, 4], [31, 30, 1]], [[31, 0, 3], [31, 30, 0]], [[31, 0, 2], [31, 30, 1]], [[31, 0, 1], [31, 31, 1]], [[31, 0, 0], [31, 31, 0]]]; +const lookup_6_4 = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 1], [0, 1, 0]], [[0, 0, 2], [0, 2, 0]], [[1, 0, 1], [0, 3, 1]], [[1, 0, 0], [0, 3, 0]], [[1, 0, 1], [0, 4, 0]], [[1, 0, 2], [0, 5, 0]], [[2, 0, 1], [0, 6, 1]], [[2, 0, 0], [0, 6, 0]], [[2, 0, 1], [0, 7, 0]], [[2, 0, 2], [0, 8, 0]], [[3, 0, 1], [0, 9, 1]], [[3, 0, 0], [0, 9, 0]], [[3, 0, 1], [0, 10, 0]], [[3, 0, 2], [0, 11, 0]], [[4, 0, 1], [0, 12, 1]], [[4, 0, 0], [0, 12, 0]], [[4, 0, 1], [0, 13, 0]], [[4, 0, 2], [0, 14, 0]], [[5, 0, 1], [0, 15, 1]], [[5, 0, 0], [0, 15, 0]], [[5, 0, 1], [0, 16, 0]], [[5, 0, 2], [1, 15, 0]], [[6, 0, 1], [0, 17, 0]], [[6, 0, 0], [0, 18, 0]], [[6, 0, 1], [0, 19, 0]], [[6, 0, 2], [3, 14, 0]], [[7, 0, 1], [0, 20, 0]], [[7, 0, 0], [0, 21, 0]], [[7, 0, 1], [0, 22, 0]], [[7, 0, 2], [4, 15, 0]], [[8, 0, 1], [0, 23, 0]], [[8, 0, 0], [0, 24, 0]], [[8, 0, 1], [0, 25, 0]], [[8, 0, 2], [6, 14, 0]], [[9, 0, 1], [0, 26, 0]], [[9, 0, 0], [0, 27, 0]], [[9, 0, 1], [0, 28, 0]], [[9, 0, 2], [7, 15, 0]], [[10, 0, 1], [0, 29, 0]], [[10, 0, 0], [0, 30, 0]], [[10, 0, 1], [0, 31, 0]], [[10, 0, 2], [9, 14, 0]], [[11, 0, 1], [0, 32, 0]], [[11, 0, 0], [0, 33, 0]], [[11, 0, 1], [2, 30, 0]], [[11, 0, 2], [0, 34, 0]], [[12, 0, 1], [0, 35, 0]], [[12, 0, 0], [0, 36, 0]], [[12, 0, 1], [3, 31, 0]], [[12, 0, 2], [0, 37, 0]], [[13, 0, 1], [0, 38, 0]], [[13, 0, 0], [0, 39, 0]], [[13, 0, 1], [5, 30, 0]], [[13, 0, 2], [0, 40, 0]], [[14, 0, 1], [0, 41, 0]], [[14, 0, 0], [0, 42, 0]], [[14, 0, 1], [6, 31, 0]], [[14, 0, 2], [0, 43, 0]], [[15, 0, 1], [0, 44, 0]], [[15, 0, 0], [0, 45, 0]], [[15, 0, 1], [8, 30, 0]], [[15, 0, 2], [0, 46, 0]], [[16, 0, 2], [0, 47, 0]], [[16, 0, 1], [1, 46, 0]], [[16, 0, 0], [0, 48, 0]], [[16, 0, 1], [0, 49, 0]], [[16, 0, 2], [0, 50, 0]], [[17, 0, 1], [2, 47, 0]], [[17, 0, 0], [0, 51, 0]], [[17, 0, 1], [0, 52, 0]], [[17, 0, 2], [0, 53, 0]], [[18, 0, 1], [4, 46, 0]], [[18, 0, 0], [0, 54, 0]], [[18, 0, 1], [0, 55, 0]], [[18, 0, 2], [0, 56, 0]], [[19, 0, 1], [5, 47, 0]], [[19, 0, 0], [0, 57, 0]], [[19, 0, 1], [0, 58, 0]], [[19, 0, 2], [0, 59, 0]], [[20, 0, 1], [7, 46, 0]], [[20, 0, 0], [0, 60, 0]], [[20, 0, 1], [0, 61, 0]], [[20, 0, 2], [0, 62, 0]], [[21, 0, 1], [8, 47, 0]], [[21, 0, 0], [0, 63, 0]], [[21, 0, 1], [1, 62, 0]], [[21, 0, 2], [1, 63, 0]], [[22, 0, 1], [10, 46, 0]], [[22, 0, 0], [2, 62, 0]], [[22, 0, 1], [2, 63, 0]], [[22, 0, 2], [3, 62, 0]], [[23, 0, 1], [11, 47, 0]], [[23, 0, 0], [3, 63, 0]], [[23, 0, 1], [4, 62, 0]], [[23, 0, 2], [4, 63, 0]], [[24, 0, 1], [13, 46, 0]], [[24, 0, 0], [5, 62, 0]], [[24, 0, 1], [5, 63, 0]], [[24, 0, 2], [6, 62, 0]], [[25, 0, 1], [14, 47, 0]], [[25, 0, 0], [6, 63, 0]], [[25, 0, 1], [7, 62, 0]], [[25, 0, 2], [7, 63, 0]], [[26, 0, 1], [16, 45, 0]], [[26, 0, 0], [8, 62, 0]], [[26, 0, 1], [8, 63, 0]], [[26, 0, 2], [9, 62, 0]], [[27, 0, 1], [16, 48, 0]], [[27, 0, 0], [9, 63, 0]], [[27, 0, 1], [10, 62, 0]], [[27, 0, 2], [10, 63, 0]], [[28, 0, 1], [16, 51, 0]], [[28, 0, 0], [11, 62, 0]], [[28, 0, 1], [11, 63, 0]], [[28, 0, 2], [12, 62, 0]], [[29, 0, 1], [16, 54, 0]], [[29, 0, 0], [12, 63, 0]], [[29, 0, 1], [13, 62, 0]], [[29, 0, 2], [13, 63, 0]], [[30, 0, 1], [16, 57, 0]], [[30, 0, 0], [14, 62, 0]], [[30, 0, 1], [14, 63, 0]], [[30, 0, 2], [15, 62, 0]], [[31, 0, 1], [16, 60, 0]], [[31, 0, 0], [15, 63, 0]], [[31, 0, 1], [24, 46, 0]], [[31, 0, 2], [16, 62, 0]], [[32, 0, 2], [16, 63, 0]], [[32, 0, 1], [17, 62, 0]], [[32, 0, 0], [25, 47, 0]], [[32, 0, 1], [17, 63, 0]], [[32, 0, 2], [18, 62, 0]], [[33, 0, 1], [18, 63, 0]], [[33, 0, 0], [27, 46, 0]], [[33, 0, 1], [19, 62, 0]], [[33, 0, 2], [19, 63, 0]], [[34, 0, 1], [20, 62, 0]], [[34, 0, 0], [28, 47, 0]], [[34, 0, 1], [20, 63, 0]], [[34, 0, 2], [21, 62, 0]], [[35, 0, 1], [21, 63, 0]], [[35, 0, 0], [30, 46, 0]], [[35, 0, 1], [22, 62, 0]], [[35, 0, 2], [22, 63, 0]], [[36, 0, 1], [23, 62, 0]], [[36, 0, 0], [31, 47, 0]], [[36, 0, 1], [23, 63, 0]], [[36, 0, 2], [24, 62, 0]], [[37, 0, 1], [24, 63, 0]], [[37, 0, 0], [32, 47, 0]], [[37, 0, 1], [25, 62, 0]], [[37, 0, 2], [25, 63, 0]], [[38, 0, 1], [26, 62, 0]], [[38, 0, 0], [32, 50, 0]], [[38, 0, 1], [26, 63, 0]], [[38, 0, 2], [27, 62, 0]], [[39, 0, 1], [27, 63, 0]], [[39, 0, 0], [32, 53, 0]], [[39, 0, 1], [28, 62, 0]], [[39, 0, 2], [28, 63, 0]], [[40, 0, 1], [29, 62, 0]], [[40, 0, 0], [32, 56, 0]], [[40, 0, 1], [29, 63, 0]], [[40, 0, 2], [30, 62, 0]], [[41, 0, 1], [30, 63, 0]], [[41, 0, 0], [32, 59, 0]], [[41, 0, 1], [31, 62, 0]], [[41, 0, 2], [31, 63, 0]], [[42, 0, 1], [32, 61, 0]], [[42, 0, 0], [32, 62, 0]], [[42, 0, 1], [32, 63, 0]], [[42, 0, 2], [41, 46, 0]], [[43, 0, 1], [33, 62, 0]], [[43, 0, 0], [33, 63, 0]], [[43, 0, 1], [34, 62, 0]], [[43, 0, 2], [42, 47, 0]], [[44, 0, 1], [34, 63, 0]], [[44, 0, 0], [35, 62, 0]], [[44, 0, 1], [35, 63, 0]], [[44, 0, 2], [44, 46, 0]], [[45, 0, 1], [36, 62, 0]], [[45, 0, 0], [36, 63, 0]], [[45, 0, 1], [37, 62, 0]], [[45, 0, 2], [45, 47, 0]], [[46, 0, 1], [37, 63, 0]], [[46, 0, 0], [38, 62, 0]], [[46, 0, 1], [38, 63, 0]], [[46, 0, 2], [47, 46, 0]], [[47, 0, 1], [39, 62, 0]], [[47, 0, 0], [39, 63, 0]], [[47, 0, 1], [40, 62, 0]], [[47, 0, 2], [48, 46, 0]], [[48, 0, 2], [40, 63, 0]], [[48, 0, 1], [41, 62, 0]], [[48, 0, 0], [41, 63, 0]], [[48, 0, 1], [48, 49, 0]], [[48, 0, 2], [42, 62, 0]], [[49, 0, 1], [42, 63, 0]], [[49, 0, 0], [43, 62, 0]], [[49, 0, 1], [48, 52, 0]], [[49, 0, 2], [43, 63, 0]], [[50, 0, 1], [44, 62, 0]], [[50, 0, 0], [44, 63, 0]], [[50, 0, 1], [48, 55, 0]], [[50, 0, 2], [45, 62, 0]], [[51, 0, 1], [45, 63, 0]], [[51, 0, 0], [46, 62, 0]], [[51, 0, 1], [48, 58, 0]], [[51, 0, 2], [46, 63, 0]], [[52, 0, 1], [47, 62, 0]], [[52, 0, 0], [47, 63, 0]], [[52, 0, 1], [48, 61, 0]], [[52, 0, 2], [48, 62, 0]], [[53, 0, 1], [56, 47, 0]], [[53, 0, 0], [48, 63, 0]], [[53, 0, 1], [49, 62, 0]], [[53, 0, 2], [49, 63, 0]], [[54, 0, 1], [58, 46, 0]], [[54, 0, 0], [50, 62, 0]], [[54, 0, 1], [50, 63, 0]], [[54, 0, 2], [51, 62, 0]], [[55, 0, 1], [59, 47, 0]], [[55, 0, 0], [51, 63, 0]], [[55, 0, 1], [52, 62, 0]], [[55, 0, 2], [52, 63, 0]], [[56, 0, 1], [61, 46, 0]], [[56, 0, 0], [53, 62, 0]], [[56, 0, 1], [53, 63, 0]], [[56, 0, 2], [54, 62, 0]], [[57, 0, 1], [62, 47, 0]], [[57, 0, 0], [54, 63, 0]], [[57, 0, 1], [55, 62, 0]], [[57, 0, 2], [55, 63, 0]], [[58, 0, 1], [56, 62, 1]], [[58, 0, 0], [56, 62, 0]], [[58, 0, 1], [56, 63, 0]], [[58, 0, 2], [57, 62, 0]], [[59, 0, 1], [57, 63, 1]], [[59, 0, 0], [57, 63, 0]], [[59, 0, 1], [58, 62, 0]], [[59, 0, 2], [58, 63, 0]], [[60, 0, 1], [59, 62, 1]], [[60, 0, 0], [59, 62, 0]], [[60, 0, 1], [59, 63, 0]], [[60, 0, 2], [60, 62, 0]], [[61, 0, 1], [60, 63, 1]], [[61, 0, 0], [60, 63, 0]], [[61, 0, 1], [61, 62, 0]], [[61, 0, 2], [61, 63, 0]], [[62, 0, 1], [62, 62, 1]], [[62, 0, 0], [62, 62, 0]], [[62, 0, 1], [62, 63, 0]], [[62, 0, 2], [63, 62, 0]], [[63, 0, 1], [63, 63, 1]], [[63, 0, 0], [63, 63, 0]]]; + +function floatToInt(value, limit) { + const integer = parseInt(value + 0.5); + if (integer < 0) return 0; + if (integer > limit) return integer; + return integer; +} + +function floatTo565(color) { + const r = floatToInt(31.0 * color.x, 31); + const g = floatToInt(63.0 * color.y, 63); + const b = floatToInt(31.0 * color.z, 31); + return r << 11 | g << 5 | b; +} + +function writeColourBlock(firstColor, secondColor, indices, result, blockOffset) { + result[blockOffset + 0] = firstColor & 0xff; + result[blockOffset + 1] = firstColor >> 8; + result[blockOffset + 2] = secondColor & 0xff; + result[blockOffset + 3] = secondColor >> 8; + + for (let y = 0; y < 4; y++) { + result[blockOffset + 4 + y] = indices[4 * y + 0] | indices[4 * y + 1] << 2 | indices[4 * y + 2] << 4 | indices[4 * y + 3] << 6; + } +} + +function writeColourBlock3(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor <= secondColor) { + remapped = indices.slice(); + } else { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => index === 0 ? 1 : index === 1 ? 0 : index); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +function writeColourBlock4(start, end, indices, result, blockOffset) { + let firstColor = floatTo565(start); + let secondColor = floatTo565(end); + let remapped; + + if (firstColor < secondColor) { + [firstColor, secondColor] = [secondColor, firstColor]; + remapped = indices.map(index => (index ^ 0x1) & 0x3); + } else if (firstColor == secondColor) { + remapped = new Array(16).fill(0); + } else { + remapped = indices.slice(); + } + + writeColourBlock(firstColor, secondColor, remapped, result, blockOffset); +} + +class ColorSet { + constructor(rgba, mask, flags) { + this.flags = flags; + this._count = 0; + this._transparent = false; + this._remap = []; + this._weights = []; + this._points = []; + const isDxt1 = (this.flags & kDxt1) != 0; + const weightByAlpha = (this.flags & kWeightColourByAlpha) != 0; + + for (let i = 0; i < 16; i++) { + const bit = 1 << i; + + if ((mask & bit) == 0) { + this._remap[i] = -1; + continue; + } + + if (isDxt1 && rgba[4 * i + 3] < 128) { + this._remap[i] = -1; + this._transparent = true; + continue; + } + + for (let j = 0;; j++) { + if (j == i) { + const r = rgba[4 * i] / 255.0; + const g = rgba[4 * i + 1] / 255.0; + const b = rgba[4 * i + 2] / 255.0; + const a = (rgba[4 * i + 3] + 1) / 256.0; + this._points[this._count] = new Vec3(r, g, b); + this._weights[this._count] = weightByAlpha ? a : 1.0; + this._remap[i] = this._count; + this._count++; + break; + } + + const oldbit = 1 << j; + const match = (mask & oldbit) != 0 && rgba[4 * i] == rgba[4 * j] && rgba[4 * i + 1] == rgba[4 * j + 1] && rgba[4 * i + 2] == rgba[4 * j + 2] && (rgba[4 * j + 3] >= 128 || !isDxt1); + + if (match) { + const index = this._remap[j]; + const w = (rgba[4 * i + 3] + 1) / 256.0; + this._weights[index] += weightByAlpha ? w : 1.0; + this._remap[i] = index; + break; + } + } + } + + for (let i = 0; i < this._count; ++i) this._weights[i] = Math.sqrt(this._weights[i]); + } + + get transparent() { + return this._transparent; + } + + get count() { + return this._count; + } + + get points() { + return Object.freeze(this._points.slice()); + } + + get weights() { + return Object.freeze(this._weights.slice()); + } + + remapIndicesSingle(singleIndex, target) { + const result = this._remap.map(index => index === -1 ? 3 : singleIndex); + + target.forEach((_, i) => target[i] = result[i]); + } + + remapIndices(indexMap, target) { + const result = this._remap.map(index => index === -1 ? 3 : indexMap[index]); + + target.forEach((_, i) => target[i] = result[i]); + } + +} + +class ColorFit { + constructor(colorSet) { + this.colors = colorSet; + this.flags = colorSet.flags; + } + + compress(result, offset) { + const isDxt1 = (this.flags & kDxt1) != 0; + + if (isDxt1) { + this.compress3(result, offset); + if (!this.colors.transparent) this.compress4(result, offset); + } else this.compress4(result, offset); + } + + compress3(result, offset) {} + + compress4(result, offset) {} + +} + +class SingleColourFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const singleColor = colorSet.points[0]; + this.color = singleColor.colorInt; + this.start = new Vec3(0); + this.end = new Vec3(0); + this.index = 0; + this.error = Infinity; + this.bestError = Infinity; + } + + compressBase(lookups, saveFunc) { + this.computeEndPoints(lookups); + + if (this.error < this.bestError) { + const indices = new Uint8Array(16); + this.colors.remapIndicesSingle(this.index, indices); + saveFunc(this.start, this.end, indices); + this.bestError = this.error; + } + } + + compress3(result, offset) { + const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + compress4(result, offset) { + const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(lookups, saveFunc); + } + + computeEndPoints(lookups) { + this.error = Infinity; + + for (let index = 0; index < 2; index++) { + const sources = []; + let error = 0; + + for (let channel = 0; channel < 3; channel++) { + const lookup = lookups[channel]; + const target = this.color[channel]; + sources[channel] = lookup[target][index]; + const diff = sources[channel][2]; + error += diff * diff; + } + + if (error < this.error) { + this.start = new Vec3(sources[0][0] / 31.0, sources[1][0] / 63.0, sources[2][0] / 31.0); + this.end = new Vec3(sources[0][1] / 31.0, sources[1][1] / 63.0, sources[2][1] / 31.0); + this.index = 2 * index; + this.error = error; + } + } + } + +} + +class RangeFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + this.metric = new Vec3(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722); + } + + this.start = new Vec3(0); + this.end = new Vec3(0); + this.bestError = Infinity; + this.computePoints(); + } + + compressBase(codes, saveFunc) { + const { + points: values + } = this.colors; + let error = 0; + const closest = values.map(color => { + let minDist = Infinity; + const packedIndex = codes.reduce((idx, code, j) => { + const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; + if (dist >= minDist) return idx; + minDist = dist; + return j; + }, 0); + error += minDist; + return packedIndex; + }); + + if (error < this.bestError) { + let indices = new Uint8Array(16); + this.colors.remapIndices(closest, indices); + saveFunc(this.start, this.end, indices); + this.bestError = error; + } + } + + compress3(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 0.5)]; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + compress4(result, offset) { + const codes = [this.start.clone(), this.end.clone(), Vec3.interpolate(this.start, this.end, 1 / 3), Vec3.interpolate(this.start, this.end, 2 / 3)]; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(codes, saveFunc); + } + + computePoints() { + const { + count, + points: values, + weights + } = this.colors; + if (count <= 0) return; + const principle = computePCA(values, weights); + let start, end, min, max; + start = end = values[0]; + min = max = Vec3.dot(start, principle); + + for (let i = 1; i < count; i++) { + let value = Vec3.dot(values[i], principle); + + if (value < min) { + start = values[i]; + min = value; + } else if (value > max) { + end = values[i]; + max = value; + } + } + + this.start = start.clampGrid().clone(); + this.end = end.clampGrid().clone(); + } + +} + +class ClusterFit extends ColorFit { + constructor(colorSet) { + super(colorSet); + const kMaxIterations = 8; + this.iterationCount = colorSet.flags & kColourIterativeClusterFit ? kMaxIterations : 1; + this.bestError = Infinity; + this.metric = new Vec4(1); + + if ((this.flags & kColourMetricPerceptual) !== 0) { + this.metric.set(0.2126, 0.7152, 0.0722, 0); + } + + const { + points: values, + weights + } = this.colors; + this.principle = computePCA(values, weights); + this.order = new Uint8Array(16 * kMaxIterations); + this.pointsWeights = []; + this.xSum_wSum = new Vec4(0); + } + + constructOrdering(axis, iteration) { + const currentOrder = this.makeOrder(axis); + this.copyOrderToThisOrder(currentOrder, iteration); + const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); + if (!uniqueOrder) return false; + this.copyOrderWeight(currentOrder); + return true; + } + + compress3(result, offset) { + const aabbx = _ref => { + let [part0,, part1, part2] = _ref; + const const1_2 = new Vec4(1 / 2, 1 / 2, 1 / 2, 1 / 4); + const alphax_sum = Vec4.multiplyAdd(part1, const1_2, part0); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_2, part2); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 2); + } + + compress4(result, offset) { + const aabbx = _ref2 => { + let [part0, part1, part2, part3] = _ref2; + const const1_3 = new Vec4(1 / 3, 1 / 3, 1 / 3, 1 / 9); + const const2_3 = new Vec4(2 / 3, 2 / 3, 2 / 3, 4 / 9); + const const2_9 = new Vec4(2 / 9); + const alphax_sum = Vec4.multiplyAdd(part2, const1_3, Vec4.multiplyAdd(part1, const2_3, part0)); + const alpha2_sum = alphax_sum.splatW; + const betax_sum = Vec4.multiplyAdd(part1, const1_3, Vec4.multiplyAdd(part2, const2_3, part3)); + const beta2_sum = betax_sum.splatW; + const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; + return { + ax: alphax_sum, + aa: alpha2_sum, + bx: betax_sum, + bb: beta2_sum, + ab: alphabeta_sum + }; + }; + + const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); + + this.compressBase(aabbx, saveFunc, 3); + } + + compressBase(aabbFunc, saveFunc) { + let repeater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + this.constructOrdering(this.principle, 0); + let best = { + start: new Vec4(0), + end: new Vec4(0), + error: this.bestError, + iteration: 0, + bestI: 0, + bestJ: 0 + }; + if (repeater === 3) best.bestK = 0; + + const leastSquares = (parts, internalIndices) => { + const aabbx = aabbFunc(parts); + const internalBest = this.computeOptimalPoints(aabbx); + + if (internalBest.error < best.error) { + best = _objectSpread2(_objectSpread2({}, internalBest), internalIndices); + return true; + } + + return false; + }; + + for (let iterationIndex = 0;;) { + this.clusterIterate(iterationIndex, leastSquares, repeater); + if (best.iteration != iterationIndex) break; + iterationIndex++; + if (iterationIndex == this.iterationCount) break; + const newAxis = Vec4.sub(best.end, best.start).xyz; + if (!this.constructOrdering(newAxis, iterationIndex)) break; + } + + if (best.error < this.bestError) this.saveBlock(best, saveFunc); + } + + makeOrder(axis) { + const { + count, + points: values + } = this.colors; + const dotProducts = values.map((color, i) => Vec3.dot(color, axis)); + return Array.from({ + length: count + }, (_, i) => i).sort((a, b) => { + if (dotProducts[a] - dotProducts[b] != 0) return dotProducts[a] - dotProducts[b]; + return a - b; + }); + } + + copyOrderToThisOrder(order, iteration) { + const orderOffset = iteration * 16; + order.forEach((ord, i) => { + this.order[orderOffset + i] = ord; + }); + } + + checkOrderUnique(order, iteration) { + const { + count + } = this.colors; + + for (let it = 0; it < iteration; it++) { + let prevOffset = it * 16; + let same = true; + + for (let i = 0; i < count; i++) { + if (order[i] !== this.order[prevOffset + i]) { + same = false; + break; + } + } + + if (same) return false; + } + + return true; + } + + copyOrderWeight(order) { + const { + count, + points: unweighted, + weights + } = this.colors; + this.xSum_wSum.set(0); + + for (let i = 0; i < count; i++) { + const j = order[i]; + const p = unweighted[j].toVec4(1); + const w = new Vec4(weights[j]); + const x = Vec4.multVector(p, w); + this.pointsWeights[i] = x; + this.xSum_wSum.addVector(x); + } + } + + computeOptimalPoints(vectorPoint) { + const { + ax, + bx, + aa, + bb, + ab + } = vectorPoint; + const factor = Vec4.negativeMultiplySubtract(ab, ab, Vec4.multVector(aa, bb)).reciprocal(); + let a = Vec4.negativeMultiplySubtract(bx, ab, Vec4.multVector(ax, bb)).multVector(factor); + let b = Vec4.negativeMultiplySubtract(ax, ab, Vec4.multVector(bx, aa)).multVector(factor); + a.clampGrid(); + b.clampGrid(); + let error = this.computeError(_objectSpread2({ + a, + b + }, vectorPoint)); + return { + start: a, + end: b, + error + }; + } + + computeError(_ref3) { + let { + a, + b, + ax, + bx, + aa, + bb, + ab + } = _ref3; + const two = new Vec4(2); + const e1 = Vec4.multiplyAdd(Vec4.multVector(a, a), aa, Vec4.multVector(b, b).multVector(bb)); + const e2 = Vec4.negativeMultiplySubtract(a, ax, Vec4.multVector(a, b).multVector(ab)); + const e3 = Vec4.negativeMultiplySubtract(b, bx, e2); + const e4 = Vec4.multiplyAdd(two, e3, e1); + const e5 = Vec4.multVector(e4, this.metric); + return e5.x + e5.y + e5.z; + } + + saveBlock(best, writeFunc) { + const { + count + } = this.colors; + const { + start, + end, + iteration, + error, + bestI, + bestJ, + bestK = -1 + } = best; + const orderOffset = iteration * 16; + const unordered = new Uint8Array(16); + + const mapper = m => { + if (m < bestI) return 0; + if (m < bestJ) return 2; + if (m < bestK) return 3; + return 1; + }; + + for (let i = 0; i < count; i++) { + unordered[this.order[orderOffset + i]] = mapper(i); + } + + const bestIndices = new Uint8Array(16); + this.colors.remapIndices(unordered, bestIndices); + writeFunc(start.xyz, end.xyz, bestIndices); + this.bestError = error; + } + + clusterIterate(index, func) { + let iterCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; + const { + count + } = this.colors; + + const indexMapper = (i, j, k) => { + const mapper = { + bestI: i, + bestJ: iterCount === 2 ? k : j, + iteration: index + }; + if (iterCount === 3) mapper.bestK = k; + return mapper; + }; + + let part0 = new Vec4(0.0); + + for (let i = 0; i < count; i++) { + let part1 = new Vec4(0.0); + + for (let j = i;;) { + let preLastPart = j == 0 ? this.pointsWeights[0].clone() : new Vec4(0.0); + const kmin = j == 0 ? 1 : j; + + for (let k = kmin;;) { + const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); + func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); + if (k == count) break; + preLastPart.addVector(this.pointsWeights[k]); + k++; + } + + if (iterCount === 2) break; + if (j === count) break; + part1.addVector(this.pointsWeights[j]); + j++; + } + + part0.addVector(this.pointsWeights[i]); + } + } + +} + +function quantise(alpha) { + const GRID = 15; + let result = Math.floor(alpha * (GRID / 255) + 0.5); + if (result < 0) return 0; + if (result > GRID) return GRID; + return result; +} + +function compressAlphaDxt3(rgba, mask, result, offset) { + for (let i = 0; i < 8; i++) { + let quant1 = quantise(rgba[8 * i + 3]); + let quant2 = quantise(rgba[8 * i + 7]); + const bit1 = 1 << 2 * i; + const bit2 = 1 << 2 * i + 1; + if ((mask & bit1) == 0) quant1 = 0; + if ((mask & bit2) == 0) quant2 = 0; + result[offset + i] = quant1 | quant2 << 4; + } +} + +function compressAlphaDxt5(rgba, mask, result, offset) { + let step5 = interpolateAlpha(rgba, mask, 5); + let step7 = interpolateAlpha(rgba, mask, 7); + if (step5.error <= step7.error) writeAlphaBlock5(step5, result, offset);else writeAlphaBlock7(step7, result, offset); +} + +function interpolateAlpha(rgba, mask, steps) { + let { + min, + max + } = setAlphaRange(rgba, mask, steps); + let code = setAlphaCodeBook(min, max, steps); + let indices = new Uint8Array(16); + let error = fitCodes(rgba, mask, code, indices); + return { + min, + max, + indices, + error + }; +} + +function setAlphaRange(rgba, mask, steps) { + let min = 255; + let max = 0; + + for (let i = 0; i < 16; i++) { + let bit = 1 << i; + if ((mask & bit) == 0) continue; + let value = rgba[4 * i + 3]; + + if (steps === 5) { + if (value !== 0 && value < min) min = value; + if (value !== 255 && value > max) max = value; + } else { + if (value < min) min = value; + if (value > max) max = value; + } + } + + if (min > max) min = max; + if (max - min < steps) max = Math.min(min + steps, 255); + if (max - min < steps) min = Math.max(max - steps, 0); + return { + min, + max + }; +} + +function setAlphaCodeBook(min, max, steps) { + let codes = [min, max, ...Array.from({ + length: steps - 1 + }, (_, i) => { + return Math.floor(((steps - (i + 1)) * min + (i + 1) * max) / steps); + })]; + + if (steps === 5) { + codes[6] = 0; + codes[7] = 255; + } + + return codes; +} + +function fitCodes(rgba, mask, codes, indices) { + let err = 0; + + for (let i = 0; i < 16; ++i) { + let bit = 1 << i; + + if ((mask & bit) == 0) { + indices[i] = 0; + continue; + } + + let value = rgba[4 * i + 3]; + let least = Infinity; + let index = 0; + + for (let j = 0; j < 8; ++j) { + let dist = value - codes[j]; + dist *= dist; + + if (dist < least) { + least = dist; + index = j; + } + } + + indices[i] = index; + err += least; + } + + return err; +} + +function writeAlphaBlock5(_ref, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + if (index <= 5) return 7 - index; + return index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock7(_ref2, result, offset) { + let { + min: alpha0, + max: alpha1, + indices + } = _ref2; + + if (alpha0 > alpha1) { + const swapped = indices.map(index => { + if (index === 0) return 1; + if (index === 1) return 0; + return 9 - index; + }); + writeAlphaBlock(alpha1, alpha0, swapped, result, offset); + } else writeAlphaBlock(alpha0, alpha1, indices, result, offset); +} + +function writeAlphaBlock(alpha0, alpha1, indices, result, offset) { + result[offset] = alpha0; + result[offset + 1] = alpha1; + let indicesPointer = 0; + let resultPointer = offset + 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 8; ++j) { + let index = indices[indicesPointer]; + value |= index << 3 * j; + indicesPointer++; + } + + for (let j = 0; j < 3; ++j) { + let byte = value >> 8 * j & 0xff; + result[resultPointer] = byte; + resultPointer++; + } + } +} + +function unpack565(color16bit) { + const red = color16bit >> 11 & 0x1f; + const green = color16bit >> 5 & 0x3f; + const blue = color16bit & 0x1f; + return [red << 3 | red >> 2, green << 2 | green >> 4, blue << 3 | blue >> 2, 255]; +} + +function interpolateColorArray(a, b, amount) { + const result = a.map((aColor, i) => Math.floor(aColor * (1 - amount) + b[i] * amount)); + result[3] = 255; + return result; +} + +function unpackColorCodes(block, offset, isDxt1) { + const color1 = block[offset] | block[offset + 1] << 8; + const color2 = block[offset + 2] | block[offset + 3] << 8; + const unpackedColor1 = unpack565(color1); + const unpackedColor2 = unpack565(color2); + return [unpackedColor1, unpackedColor2, isDxt1 && color1 <= color2 ? interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 2) : interpolateColorArray(unpackedColor1, unpackedColor2, 1 / 3), isDxt1 && color1 <= color2 ? [0, 0, 0, 0] : interpolateColorArray(unpackedColor1, unpackedColor2, 2 / 3)]; +} + +function unpackIndices(block, blockOffset) { + let offset = blockOffset + 4; + let result = new Uint8Array(16); + + for (let i = 0; i < 4; i++) { + let packedIndices = block[offset + i]; + result[i * 4 + 0] = packedIndices & 0x3; + result[i * 4 + 1] = packedIndices >> 2 & 0x3; + result[i * 4 + 2] = packedIndices >> 4 & 0x3; + result[i * 4 + 3] = packedIndices >> 6 & 0x3; + } + + return result; +} + +function decompressColor(rgba, block, offset, isDxt1) { + const colorCode = unpackColorCodes(block, offset, isDxt1); + const indices = unpackIndices(block, offset); + + for (let i = 0; i < 16; i++) { + for (let j = 0; j < 4; j++) { + rgba[4 * i + j] = colorCode[indices[i]][j]; + } + } +} + +function decompressAlphaDxt3(rgba, block, offset) { + for (let i = 0; i < 8; ++i) { + let quant = block[offset + i]; + let lo = quant & 0x0f; + let hi = quant & 0xf0; + rgba[8 * i + 3] = lo | lo << 4; + rgba[8 * i + 7] = hi | hi >> 4; + } +} + +function decompressAlphaDxt5(rgba, block, offset) { + let alpha0 = block[offset + 0]; + let alpha1 = block[offset + 1]; + let codes = setAlphaCodeBook(alpha0, alpha1, alpha0 <= alpha1 ? 5 : 7); + let indices = new Uint8Array(16); + let indicePointer = 0; + let bytePointer = 2; + + for (let i = 0; i < 2; i++) { + let value = 0; + + for (let j = 0; j < 3; j++) { + let byte = block[offset + bytePointer]; + value |= byte << 8 * j; + bytePointer++; + } + + for (let j = 0; j < 8; j++) { + let index = value >> 3 * j & 0x7; + indices[indicePointer] = index; + indicePointer++; + } + } + + for (let i = 0; i < 16; ++i) { + rgba[4 * i + 3] = codes[indices[i]]; + } +} + +/** @license +----------------------------------------------------------------------------- + Copyright (c) 2006 Simon Brown si@sjbrown.co.uk + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------- */ +const DXT1_COMPRESSED_BYTES = 8; +const DXT5_COMPRESSED_BYTES = 16; +const COLORS = 4; +const DECOMPRESSED_BLOCK_SIZE = 16; + +function blockRepeat(width, height, func) { + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + func(x, y); + } + } +} + +function rectRepeat(func) { + for (let y = 0; y < 4; y++) { + for (let x = 0; x < 4; x++) { + func(x, y); + } + } +} + +function FixFlags(flags) { + let method = flags & (kDxt1 | kDxt3 | kDxt5); + let fit = flags & (kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit); + let metric = flags & (kColourMetricPerceptual | kColourMetricUniform); + const extra = flags & kWeightColourByAlpha; + if (method != kDxt3 && method != kDxt5) method = kDxt1; + if (fit != kColourRangeFit && fit != kColourIterativeClusterFit) fit = kColourClusterFit; + if (metric != kColourMetricUniform) metric = kColourMetricPerceptual; + return method | fit | metric | extra; +} + +function GetStorageRequirements(width, height, flags) { + flags = FixFlags(flags); + const blockcount = Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4); + const blocksize = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + return blockcount * blocksize; +} + +function extractColorBlock(img) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const block = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + let mask = 0; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let sourceColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + block[blockColorOffset++] = img[sourceColorOffset++]; + } + + mask |= 1 << 4 * py + px; + } else blockColorOffset += COLORS; + }); + return { + block, + mask + }; +} + +function copyBuffer(result, block) { + let { + x = 0, + y = 0, + width = 0, + height = 0 + } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let blockColorOffset = 0; + rectRepeat(function (px, py) { + let sx = x + px; + let sy = y + py; + + if (sx < width && sy < height) { + let resultColorOffset = COLORS * (width * sy + sx); + + for (let i = 0; i < COLORS; i++) { + result[resultColorOffset + i] = block[blockColorOffset++]; + } + } else blockColorOffset += COLORS; + }); +} + +function getCompressor(colorSet) { + if (colorSet.count === 1) return new SingleColourFit(colorSet); + if ((colorSet.flags & kColourRangeFit) != 0 || colorSet.count == 0) return new RangeFit(colorSet); + return new ClusterFit(colorSet); +} + +function CompressMasked(rgba, mask, result, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + const colors = new ColorSet(rgba, mask, flags); + const compressor = getCompressor(colors); + compressor.compress(result, offset + colorOffset); + if ((flags & kDxt3) !== 0) compressAlphaDxt3(rgba, mask, result, offset);else if ((flags & kDxt5) !== 0) compressAlphaDxt5(rgba, mask, result, offset); +} + +function decompressBlock(result, block, offset, flags) { + flags = FixFlags(flags); + let colorOffset = (flags & (kDxt3 | kDxt5)) !== 0 ? 8 : 0; + decompressColor(result, block, offset + colorOffset, (flags & kDxt1) !== 0); + if ((flags & kDxt3) !== 0) decompressAlphaDxt3(result, block, offset);else if ((flags & kDxt5) !== 0) decompressAlphaDxt5(result, block, offset); +} + +function compressImage(source, width, height, result, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let targetBlockPointer = 0; + blockRepeat(width, height, function (x, y) { + const { + block: sourceRGBA, + mask + } = extractColorBlock(source, { + x, + y, + width, + height + }); + CompressMasked(sourceRGBA, mask, result, targetBlockPointer, flags); + targetBlockPointer += bytesPerBlock; + }); +} + +function decompressImage(result, width, height, source, flags) { + flags = FixFlags(flags); + const bytesPerBlock = (flags & kDxt1) !== 0 ? DXT1_COMPRESSED_BYTES : DXT5_COMPRESSED_BYTES; + let sourceBlockPointer = 0; + + for (let y = 0; y < height; y += 4) { + for (let x = 0; x < width; x += 4) { + const targetRGBA = new Uint8Array(DECOMPRESSED_BLOCK_SIZE * COLORS); + decompressBlock(targetRGBA, source, sourceBlockPointer, flags); + copyBuffer(result, targetRGBA, { + x, + y, + width, + height + }); + sourceBlockPointer += bytesPerBlock; + } + } +} + +const flags = { + DXT1: kDxt1, + DXT3: kDxt3, + DXT5: kDxt5, + ColourIterativeClusterFit: kColourIterativeClusterFit, + ColourClusterFit: kColourClusterFit, + ColourRangeFit: kColourRangeFit, + ColourMetricPerceptual: kColourMetricPerceptual, + ColourMetricUniform: kColourMetricUniform, + WeightColourByAlpha: kWeightColourByAlpha +}; + +function compress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = GetStorageRequirements(width, height, flags); + const result = new Uint8Array(targetSize); + compressImage(source, width, height, result, flags); + return result; +} + +function decompress(inputData, width, height, flags) { + let source = inputData instanceof ArrayBuffer ? new Uint8Array(inputData) : inputData; + const targetSize = width * height * 4; + const result = new Uint8Array(targetSize); + decompressImage(result, width, height, source, flags); + return result; +} + +class Texture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format == 4) data = decompress(data, width, height, flags.DXT1);else if (format == 5) data = decompress(data, width, height, flags.DXT3);else if (format == 6) data = decompress(data, width, height, flags.DXT5);else if (format == 2) { + throw new Error('Texture2D format type ECT1 not implemented!'); + } else if (format != 0) throw new Error("Non-implemented Texture2D format type (".concat(format, ") found.")); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + const width = content.export.width; + const height = content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + if (content.format == 4) data = compress(data, width, height, flags.DXT1);else if (content.format == 5) data = compress(data, width, height, flags.DXT3);else if (content.format == 6) data = compress(data, width, height, flags.DXT5); + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class Vector3Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector3Reader': + case 'Microsoft.Xna.Framework.Vector3': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + return { + x, + y, + z + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const singleReader = new SingleReader(); + singleReader.write(buffer, content.x, null); + singleReader.write(buffer, content.y, null); + singleReader.write(buffer, content.z, null); + } + +} + +class SpriteFontReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.SpriteFontReader': + return true; + + default: + return false; + } + } + + static parseTypeList() { + return ["SpriteFont", "Texture2D", 'List', 'Rectangle', 'List', 'Rectangle', 'List', 'Char', null, null, 'List', 'Vector3', 'Nullable', 'Char']; + } + + read(buffer, resolver) { + const int32Reader = new Int32Reader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(new CharReader()); + const texture = resolver.read(buffer); + const glyphs = resolver.read(buffer); + const cropping = resolver.read(buffer); + const characterMap = resolver.read(buffer); + const verticalLineSpacing = int32Reader.read(buffer); + const horizontalSpacing = singleReader.read(buffer); + const kerning = resolver.read(buffer); + const defaultCharacter = nullableCharReader.read(buffer); + return { + texture, + glyphs, + cropping, + characterMap, + verticalLineSpacing, + horizontalSpacing, + kerning, + defaultCharacter + }; + } + + write(buffer, content, resolver) { + const int32Reader = new Int32Reader(); + const charReader = new CharReader(); + const singleReader = new SingleReader(); + const nullableCharReader = new NullableReader(charReader); + const texture2DReader = new Texture2DReader(); + const rectangleListReader = new ListReader(new RectangleReader()); + const charListReader = new ListReader(charReader); + const vector3ListReader = new ListReader(new Vector3Reader()); + this.writeIndex(buffer, resolver); + + try { + texture2DReader.write(buffer, content.texture, resolver); + buffer.alloc(100000); + rectangleListReader.write(buffer, content.glyphs, resolver); + rectangleListReader.write(buffer, content.cropping, resolver); + charListReader.write(buffer, content.characterMap, resolver); + int32Reader.write(buffer, content.verticalLineSpacing, null); + singleReader.write(buffer, content.horizontalSpacing, null); + vector3ListReader.write(buffer, content.kerning, resolver); + nullableCharReader.write(buffer, content.defaultCharacter, null); + } catch (ex) { + throw ex; + } + } + + isValueType() { + return false; + } + +} + +class TBinReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'xTile.Pipeline.TideReader': + return true; + + default: + return false; + } + } + + read(buffer) { + const int32Reader = new Int32Reader(); + let size = int32Reader.read(buffer); + let data = buffer.read(size); + return { + export: { + type: this.type, + data + } + }; + } + + write(buffer, content, resolver) { + this.writeIndex(buffer, resolver); + const data = content.export.data; + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, data.byteLength, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + +} + +class LightweightTexture2DReader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Texture2DReader': + return true; + + default: + return false; + } + } + + static type() { + return "Texture2D"; + } + + read(buffer) { + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + let format = int32Reader.read(buffer); + let width = uint32Reader.read(buffer); + let height = uint32Reader.read(buffer); + let mipCount = uint32Reader.read(buffer); + if (mipCount > 1) console.warn("Found mipcount of ".concat(mipCount, ", only the first will be used.")); + let dataSize = uint32Reader.read(buffer); + let data = buffer.read(dataSize); + if (format != 0) throw new Error("Compressed texture format is not supported!"); + + for (let i = 0; i < data.length; i += 4) { + let inverseAlpha = 255 / data[i + 3]; + data[i] = Math.min(Math.ceil(data[i] * inverseAlpha), 255); + data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); + data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); + } + + return { + format, + export: { + type: this.type, + data, + width, + height + } + }; + } + + write(buffer, content, resolver) { + if (content.format != 0) throw new Error("Compressed texture format is not supported!"); + const int32Reader = new Int32Reader(); + const uint32Reader = new UInt32Reader(); + this.writeIndex(buffer, resolver); + content.export.width; + content.export.height; + int32Reader.write(buffer, content.format, null); + uint32Reader.write(buffer, content.export.width, null); + uint32Reader.write(buffer, content.export.height, null); + uint32Reader.write(buffer, 1, null); + let data = content.export.data; + + for (let i = 0; i < data.length; i += 4) { + const alpha = data[i + 3] / 255; + data[i] = Math.floor(data[i] * alpha); + data[i + 1] = Math.floor(data[i + 1] * alpha); + data[i + 2] = Math.floor(data[i + 2] * alpha); + } + + uint32Reader.write(buffer, data.length, null); + buffer.concat(data); + } + + isValueType() { + return false; + } + + get type() { + return "Texture2D"; + } + +} + +class Vector2Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector2Reader': + case 'Microsoft.Xna.Framework.Vector2': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + return { + x, + y + }; + } + +} + +class Vector4Reader extends BaseReader { + static isTypeOf(type) { + switch (type) { + case 'Microsoft.Xna.Framework.Content.Vector4Reader': + case 'Microsoft.Xna.Framework.Vector4': + return true; + + default: + return false; + } + } + + read(buffer) { + const singleReader = new SingleReader(); + let x = singleReader.read(buffer); + let y = singleReader.read(buffer); + let z = singleReader.read(buffer); + let w = singleReader.read(buffer); + return { + x, + y, + z, + w + }; + } + +} + +export { ArrayReader, BaseReader, BmFontReader, BooleanReader, CharReader, DictionaryReader, DoubleReader, EffectReader, Int32Reader, LightweightTexture2DReader, ListReader, NullableReader, RectangleReader, ReflectiveReader, SingleReader, SpriteFontReader, StringReader, TBinReader, Texture2DReader, UInt32Reader, Vector2Reader, Vector3Reader, Vector4Reader }; diff --git a/docs/js/libs/src/App/BufferReader.js b/docs/js/libs/src/App/BufferReader.js deleted file mode 100644 index cca9e6a..0000000 --- a/docs/js/libs/src/App/BufferReader.js +++ /dev/null @@ -1,556 +0,0 @@ -import {UTF8ToString} from "../utils/UTF8ToString.js"; - -const LITTLE_ENDIAN = true; -const BIG_ENDIAN = false; - -class BufferReader { - - /** - * Creates instance of Reader class. - * @constructor - * @param {ArrayBuffer} target buffer to trace - */ - constructor(buffer, endianus = LITTLE_ENDIAN) { - /** - * Sets the endianness of the buffer stream - * @private - * @type {Number} - */ - this._endianus = endianus; - - /** - * internal buffer for the reader - * @private - * @type {ArrayBuffer} - */ - this._buffer = buffer.slice(); - - /** - * internal buffer for the reader - * @private - * @type {DataView} - */ - this._dataView = new DataView(this._buffer); - - /** - * Seek index for the internal buffer. - * @private - * @type {Number} - */ - this._offset = 0; - - /** - * Bit offset for bit reading. - * @private - * @type {Number} - */ - this._bitOffset = 0; - } - - /** - * Seeks to a specific index in the buffer. - * @public - * @param {Number} index Sets the buffer seek index. - * @param {Number} origin Location to seek from - */ - seek(index, origin = this._offset) { - const offset = this._offset; - this._offset = Math.max(origin + Number.parseInt(index), 0); - if (this._offset < 0 || this._offset > this.buffer.length) - throw new RangeError(`Buffer seek out of bounds! ${this._offset} ${this.buffer.length}`); - return this._offset - offset; - } - - /** - * Gets the seek index of the buffer. - * @public - * @property bytePosition - * @return {Number} Reurns the buffer seek index. - */ - get bytePosition() { - return Number.parseInt(this._offset); - } - - /** - * Sets the seek index of the buffer. - * @public - * @property bytePosition - * @param {Number} value - */ - set bytePosition(value) { - this._offset = value; - } - - /** - * Gets the current position for bit reading. - * @public - * @property _bitPosition - * @returns {Number} - */ - get bitPosition() { - return Number.parseInt(this._bitOffset); - } - - /** - * Sets the bit position clamped at 16-bit frames - * @public - * @property bitPosition - * @param {Number} offset - */ - set bitPosition(offset) { - // when rewinding, reset it back to - if (offset < 0) offset = 16 - offset; - // set the offset and clamp to 16-bit frame - this._bitOffset = offset % 16; - // get byte seek for bit ranges that wrap past 16-bit frames - const byteSeek = ((offset - (Math.abs(offset) % 16)) / 16) * 2; - // seek ahead for overflow on 16-bit frames - this.seek(byteSeek); - } - - /** - * Get the buffer size. - * @public - * @property size - * @return {Number} Returns the size of the buffer. - */ - get size() { - return this.buffer.byteLength; - } - - /** - * Returns the buffer. - * @public - * @property buffer - * @returns {Buffer} Returns the internal buffer. - */ - get buffer() { - return this._buffer; - } - - /** - * Writes another buffer into this buffer. - * @public - * @method write - * @param {Buffer} buffer - * @param {Number} targetIndex - * @param {Number} sourceIndex - * @param {Number} length - */ - - copyFrom(buffer, targetIndex = 0, sourceIndex = 0, length = buffer.byteLength) { - const sourceView = new Uint8Array(buffer); - const isOverflow = this.buffer.byteLength < length + targetIndex; - - let targetBuffer = this.buffer; - let targetView = this._dataView; - - // we need to resize the buffer to fit the contents - if (isOverflow) { - // create a temporary buffer of the new size - targetBuffer = new ArrayBuffer(this.buffer.byteLength + (length + targetIndex - this.buffer.byteLength)); - targetView = new DataView(targetBuffer); - // copy our buffer into the temp buffer - for(let i=0; i 0) { - // peek in a 16-bit value - const peek = this._dataView.getUint16(this._offset, true); - - // clamp bits into the 16-bit frame we have left only read in as much as we have left - const bitsInFrame = Math.min(Math.max(bitsLeft, 0), 16 - this.bitPosition); - // set the offset based on current position in and bit count - const offset = 16 - this.bitPosition - bitsInFrame; - - // create mask and shift the mask up to the offset << - // and then shift the return back down into mask space >> - const value = (peek & (2 ** bitsInFrame - 1 << offset)) >> offset; - - // remove the bits we read from what we have left - bitsLeft -= bitsInFrame; - // add the bits read to the bit position - this.bitPosition += bitsInFrame; - - // assign read with the value shifted over for reading in loops - read |= value << bitsLeft; - } - - // return the read bits - return read; - } - - /** - * Used to peek bits. - * @public - * @method peekLZXBits - * @param {Number} bits - * @returns {Number} - */ - peekLZXBits(bits) { - // get the current bit position to store - let bitPosition = this.bitPosition; - // get the current byte position to store - let bytePosition = this.bytePosition; - - // read the bits like normal - const read = this.readLZXBits(bits); - - // just rewind the bit position, this will also rewind bytes where needed - this.bitPosition = bitPosition; - // restore the byte position - this.bytePosition = bytePosition; - - // return the peeked value - return read; - } - - /** - * Reads a 16-bit integer from a LZX bitstream - * - * bytes are reverse as the bitstream sequences 16 bit integers stored as LSB -> MSB (bytes) - * abc[...]xyzABCDEF as bits would be stored as: - * [ijklmnop][abcdefgh][yzABCDEF][qrstuvwx] - * - * @public - * @method readLZXInt16 - * @param {Boolean} seek - * @returns {Number} - */ - readLZXInt16(seek = true) { - // read in the next two bytes worth of data - const lsB = this.readByte(); - const msB = this.readByte(); - - // rewind the seek head - if (!seek) - this.seek(-2); - - // set the value - return (lsB << 8) | msB; - } - - /** - * Aligns to 16-bit offset. - * @public - * @method align - */ - align() { - if (this.bitPosition > 0) - this.bitPosition += 16 - this.bitPosition; - } -} - -// export the BufferReader class -export default BufferReader; diff --git a/docs/js/libs/src/App/BufferWriter.js b/docs/js/libs/src/App/BufferWriter.js deleted file mode 100644 index 5453e12..0000000 --- a/docs/js/libs/src/App/BufferWriter.js +++ /dev/null @@ -1,208 +0,0 @@ -import {stringToUTF8} from "../utils/UTF8ToString.js"; -const PENDING = true; - -class BufferWriter { - - constructor(size = 2048) { - /** - * internal buffer for the writer - * @private - * @type {ArrayBuffer} - */ - this._buffer = new ArrayBuffer(size); - /** - * internal buffer for the reader - * @private - * @type {DataView} - */ - this._dataView = new DataView(this._buffer); - - /** - * Seek index for the internal buffer. - * @private - * @type {Number} - */ - this.bytePosition = 0; - } - - /** - * Returns the buffer. - * @public - * @property buffer - * @returns {Buffer} Returns the internal buffer. - */ - get buffer() { - return this._buffer; - } - - //Reconnect the DataView to the current ArrayBuffer - reconnectDataView() { - this._dataView = new DataView(this._buffer); - } - - // trim the buffer to the byte position - trim(pending = false) { - this._buffer = this.buffer.slice(0,this.bytePosition); - if(!pending) this.reconnectDataView(); - } - - /** - * Allocates number of bytes into the buffer and assigns more space if needed - * @param {Number} bytes Number of bytes to allocate into the buffer - */ - alloc(bytes) { - if (this._buffer.byteLength <= this.bytePosition + bytes) { - const tBuffer = new ArrayBuffer(this._buffer.byteLength + bytes); - const tDataView = new DataView(tBuffer); - - for(let i=0; i> 7; - if (number) byte |= 0x80; - this._dataView.setUint8(this.bytePosition, byte); - this.bytePosition++; - } - while (number); - } - -} - -// export the BufferWriter class -export default BufferWriter; diff --git a/docs/js/libs/src/App/Decompressor/LZXDecompressor.js b/docs/js/libs/src/App/Decompressor/LZXDecompressor.js deleted file mode 100644 index 784929c..0000000 --- a/docs/js/libs/src/App/Decompressor/LZXDecompressor.js +++ /dev/null @@ -1,88 +0,0 @@ -import Lzx from "./Lzx.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -import Debug from "../../Utils/Debug.js"; -import XnbError from "../../Utils/XnbError.js"; - -/** - * Used to compress and decompress LZX. - * @class - * @public - */ -class Presser { - - /** - * Decompress a certain amount of bytes. - * @public - * @static - * @param {BufferReader} buffer - * @returns {Buffer} - */ - static decompress(buffer, compressedTodo, decompressedTodo) { - // current index into the buffer - let pos = 0; - - // allocate variables for block and frame size - let block_size; - let frame_size; - - // create the LZX instance with 16-bit window frame - const lzx = new Lzx(16); - - // the full decompressed array - let decompressed = new BufferWriter(decompressedTodo); - let z = 0; - - // loop over the bytes left - while (pos < compressedTodo) { - // flag is for determining if frame_size is fixed or not - const flag = buffer.readByte(); - - // if flag is set to 0xFF that means we will read in frame size - if (flag == 0xFF) { - // read in the frame size - frame_size = buffer.readLZXInt16(); - // read in the block size - block_size = buffer.readLZXInt16(); - // advance the byte position forward - pos += 5; - } - else { - // rewind the buffer - buffer.seek(-1); - // read in the block size - block_size = buffer.readLZXInt16(this.buffer); - // set the frame size - frame_size = 0x8000; - // advance byte position forward - pos += 2; - } - - // ensure the block and frame size aren't empty - if (block_size == 0 || frame_size == 0) - break; - - // ensure the block and frame size don't exceed size of integers - if (block_size > 0x10000 || frame_size > 0x10000) - throw new XnbError('Invalid size read in compression content.'); - - Debug(`Block Size: ${block_size}, Frame Size: ${frame_size}`); - - // decompress the file based on frame and block size - decompressed.write(lzx.decompress(buffer, frame_size, block_size)); - - // increase position counter - pos += block_size; - } - - // we have finished decompressing the file - console.log('File has been successfully decompressed!'); - - // return a decompressed buffer - decompressed.trim(); - return decompressed.buffer; - } -} - -export default Presser; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/Lz4.js b/docs/js/libs/src/App/Decompressor/Lz4.js deleted file mode 100644 index 7ccba8c..0000000 --- a/docs/js/libs/src/App/Decompressor/Lz4.js +++ /dev/null @@ -1,572 +0,0 @@ -// Original Code by: https://github.com/Benzinga/lz4js/ - -// lz4.js - An implementation of Lz4 in plain JavaScript. - -import xxh_hash from './lz4/xxh32.js'; -import util from './lz4/utils.js'; - -// Constants -// -- - -// Compression format parameters/constants. -const minMatch = 4; -const minLength = 13; -const searchLimit = 5; -const skipTrigger = 6; -const hashSize = 1 << 16; - -// Token constants. -const mlBits = 4; -const mlMask = (1 << mlBits) - 1; -const runBits = 4; -const runMask = (1 << runBits) - 1; - -// Shared buffers -const blockBuf = makeBuffer(5 << 20); -const hashTable = makeHashTable(); - -// Frame constants. -const magicNum = 0x184D2204; - -// Frame descriptor flags. -const fdContentChksum = 0x4; -const fdContentSize = 0x8; -const fdBlockChksum = 0x10; -// const fdBlockIndep = 0x20; -const fdVersion = 0x40; -const fdVersionMask = 0xC0; - -// Block sizes. -const bsUncompressed = 0x80000000; -const bsDefault = 7; -const bsShift = 4; -const bsMask = 7; -const bsMap = { - 4: 0x10000, - 5: 0x40000, - 6: 0x100000, - 7: 0x400000 -}; - -// Utility functions/primitives -// -- - -// Makes our hashtable. On older browsers, may return a plain array. -function makeHashTable () { - try { - return new Uint32Array(hashSize); - } catch (error) { - const hashTable = new Array(hashSize); - - for (var i = 0; i < hashSize; i++) { - hashTable[i] = 0; - } - - return hashTable; - } -} - -// Clear hashtable. -function clearHashTable (table) { - for (var i = 0; i < hashSize; i++) { - hashTable[i] = 0; - } -} - -// Makes a byte buffer. On older browsers, may return a plain array. -function makeBuffer (size) { - try { - return new Uint8Array(size); - } catch (error) { - var buf = new Array(size); - - for (var i = 0; i < size; i++) { - buf[i] = 0; - } - - return buf; - } -} - -function sliceArray (array, start, end) { - if (typeof array.buffer !== undefined) { - if (Uint8Array.prototype.slice) { - return array.slice(start, end); - } else { - // Uint8Array#slice polyfill. - var len = array.length; - - // Calculate start. - start = start | 0; - start = (start < 0) ? Math.max(len + start, 0) : Math.min(start, len); - - // Calculate end. - end = (end === undefined) ? len : end | 0; - end = (end < 0) ? Math.max(len + end, 0) : Math.min(end, len); - - // Copy into new array. - var arraySlice = new Uint8Array(end - start); - for (var i = start, n = 0; i < end;) { - arraySlice[n++] = array[i++]; - } - - return arraySlice; - } - } else { - // Assume normal array. - return array.slice(start, end); - } -} - -// Implementation -// -- - -// Calculates an upper bound for lz4 compression. -function compressBound (n) { - return (n + (n / 255) + 16) | 0; -}; - -// Calculates an upper bound for lz4 decompression, by reading the data. -function decompressBound (src) { - var sIndex = 0; - - // Read magic number - if (util.readU32(src, sIndex) !== magicNum) { - throw new Error('invalid magic number'); - } - - sIndex += 4; - - // Read descriptor - var descriptor = src[sIndex++]; - - // Check version - if ((descriptor & fdVersionMask) !== fdVersion) { - throw new Error('incompatible descriptor version ' + (descriptor & fdVersionMask)); - } - - // Read flags - var useBlockSum = (descriptor & fdBlockChksum) !== 0; - var useContentSize = (descriptor & fdContentSize) !== 0; - - // Read block size - var bsIdx = (src[sIndex++] >> bsShift) & bsMask; - - if (bsMap[bsIdx] === undefined) { - throw new Error('invalid block size ' + bsIdx); - } - - var maxBlockSize = bsMap[bsIdx]; - - // Get content size - if (useContentSize) { - return util.readU64(src, sIndex); - } - - // Checksum - sIndex++; - - // Read blocks. - var maxSize = 0; - while (true) { - var blockSize = util.readU32(src, sIndex); - sIndex += 4; - - if (blockSize & bsUncompressed) { - blockSize &= ~bsUncompressed; - maxSize += blockSize; - } else if (blockSize > 0) { - maxSize += maxBlockSize; - } - - if (blockSize === 0) { - return maxSize; - } - - if (useBlockSum) { - sIndex += 4; - } - - sIndex += blockSize; - } -}; - -// Decompresses a block of Lz4. -function decompressBlock (src, dst, sIndex=0, sLength=src.length-2*sIndex, dIndex=0) { - var mLength, mOffset, sEnd, n, i; - var hasCopyWithin = dst.copyWithin !== undefined && dst.fill !== undefined; - - // Setup initial state. - sEnd = sIndex + sLength; - - // Consume entire input block. - while (sIndex < sEnd) { - var token = src[sIndex++]; - - // Copy literals. - var literalCount = (token >> 4); - if (literalCount > 0) { - // Parse length. - if (literalCount === 0xf) { - while (true) { - literalCount += src[sIndex]; - if (src[sIndex++] !== 0xff) { - break; - } - } - } - - // Copy literals - for (n = sIndex + literalCount; sIndex < n;) { - dst[dIndex++] = src[sIndex++]; - } - } - - if (sIndex >= sEnd) { - break; - } - - // Copy match. - mLength = (token & 0xf); - - // Parse offset. - mOffset = src[sIndex++] | (src[sIndex++] << 8); - - // Parse length. - if (mLength === 0xf) { - while (true) { - mLength += src[sIndex]; - if (src[sIndex++] !== 0xff) { - break; - } - } - } - - mLength += minMatch; - - // Copy match - // prefer to use typedarray.copyWithin for larger matches - // NOTE: copyWithin doesn't work as required by LZ4 for overlapping sequences - // e.g. mOffset=1, mLength=30 (repeach char 30 times) - // we special case the repeat char w/ array.fill - if (hasCopyWithin && mOffset === 1) { - dst.fill(dst[dIndex - 1] | 0, dIndex, dIndex + mLength); - dIndex += mLength; - } else if (hasCopyWithin && mOffset > mLength && mLength > 31) { - dst.copyWithin(dIndex, dIndex - mOffset, dIndex - mOffset + mLength); - dIndex += mLength; - } else { - for (i = dIndex - mOffset, n = i + mLength; i < n;) { - dst[dIndex++] = dst[i++] | 0; - } - } - } - - return dIndex; -}; - -// Compresses a block with Lz4. -function compressBlock (src, dst, sIndex, sLength, hashTable) { - var mIndex, mAnchor, mLength, mOffset, mStep; - var literalCount, dIndex, sEnd, n; - - // Setup initial state. - dIndex = 0; - sEnd = sLength + sIndex; - mAnchor = sIndex; - - // Process only if block is large enough. - if (sLength >= minLength) { - var searchMatchCount = (1 << skipTrigger) + 3; - - // Consume until last n literals (Lz4 spec limitation.) - while (sIndex + minMatch < sEnd - searchLimit) { - var seq = util.readU32(src, sIndex); - var hash = util.hashU32(seq) >>> 0; - - // Crush hash to 16 bits. - hash = ((hash >> 16) ^ hash) >>> 0 & 0xffff; - - // Look for a match in the hashtable. NOTE: remove one; see below. - mIndex = hashTable[hash] - 1; - - // Put pos in hash table. NOTE: add one so that zero = invalid. - hashTable[hash] = sIndex + 1; - - // Determine if there is a match (within range.) - if (mIndex < 0 || ((sIndex - mIndex) >>> 16) > 0 || util.readU32(src, mIndex) !== seq) { - mStep = searchMatchCount++ >> skipTrigger; - sIndex += mStep; - continue; - } - - searchMatchCount = (1 << skipTrigger) + 3; - - // Calculate literal count and offset. - literalCount = sIndex - mAnchor; - mOffset = sIndex - mIndex; - - // We've already matched one word, so get that out of the way. - sIndex += minMatch; - mIndex += minMatch; - - // Determine match length. - // N.B.: mLength does not include minMatch, Lz4 adds it back - // in decoding. - mLength = sIndex; - while (sIndex < sEnd - searchLimit && src[sIndex] === src[mIndex]) { - sIndex++; - mIndex++; - } - mLength = sIndex - mLength; - - // Write token + literal count. - var token = mLength < mlMask ? mLength : mlMask; - if (literalCount >= runMask) { - dst[dIndex++] = (runMask << mlBits) + token; - for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - dst[dIndex++] = n; - } else { - dst[dIndex++] = (literalCount << mlBits) + token; - } - - // Write literals. - for (var i = 0; i < literalCount; i++) { - dst[dIndex++] = src[mAnchor + i]; - } - - // Write offset. - dst[dIndex++] = mOffset; - dst[dIndex++] = (mOffset >> 8); - - // Write match length. - if (mLength >= mlMask) { - for (n = mLength - mlMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - dst[dIndex++] = n; - } - - // Move the anchor. - mAnchor = sIndex; - } - } - - // Nothing was encoded. - if (mAnchor === 0) { - return 0; - } - - // Write remaining literals. - // Write literal token+count. - literalCount = sEnd - mAnchor; - if (literalCount >= runMask) { - dst[dIndex++] = (runMask << mlBits); - for (n = literalCount - runMask; n >= 0xff; n -= 0xff) { - dst[dIndex++] = 0xff; - } - dst[dIndex++] = n; - } else { - dst[dIndex++] = (literalCount << mlBits); - } - - // Write literals. - sIndex = mAnchor; - while (sIndex < sEnd) { - dst[dIndex++] = src[sIndex++]; - } - - return dIndex; -}; - -function compressSingleBlock (src, dst) { - // Clear the hashtable. - clearHashTable(hashTable); - - return compressBlock(src, dst, 0, src.length, hashTable); -} - -// Decompresses a frame of Lz4 data. -function decompressFrame (src, dst) { - var useBlockSum, useContentSum, useContentSize, descriptor; - var sIndex = 0; - var dIndex = 0; - - // Read magic number - if (util.readU32(src, sIndex) !== magicNum) { - throw new Error('invalid magic number'); - } - - sIndex += 4; - - // Read descriptor - descriptor = src[sIndex++]; - - // Check version - if ((descriptor & fdVersionMask) !== fdVersion) { - throw new Error('incompatible descriptor version'); - } - - // Read flags - useBlockSum = (descriptor & fdBlockChksum) !== 0; - useContentSum = (descriptor & fdContentChksum) !== 0; - useContentSize = (descriptor & fdContentSize) !== 0; - - // Read block size - var bsIdx = (src[sIndex++] >> bsShift) & bsMask; - - if (bsMap[bsIdx] === undefined) { - throw new Error('invalid block size'); - } - - if (useContentSize) { - // TODO: read content size - sIndex += 8; - } - - sIndex++; - - // Read blocks. - while (true) { - var compSize; - - compSize = util.readU32(src, sIndex); - sIndex += 4; - - if (compSize === 0) { - break; - } - - if (useBlockSum) { - // TODO: read block checksum - sIndex += 4; - } - - // Check if block is compressed - if ((compSize & bsUncompressed) !== 0) { - // Mask off the 'uncompressed' bit - compSize &= ~bsUncompressed; - - // Copy uncompressed data into destination buffer. - for (var j = 0; j < compSize; j++) { - dst[dIndex++] = src[sIndex++]; - } - } else { - // Decompress into blockBuf - dIndex = decompressBlock(src, dst, sIndex, compSize, dIndex); - sIndex += compSize; - } - } - - if (useContentSum) { - // TODO: read content checksum - sIndex += 4; - } - - return dIndex; -}; - -// Compresses data to an Lz4 frame. -function compressFrame (src, dst) { - var dIndex = 0; - - // Write magic number. - util.writeU32(dst, dIndex, magicNum); - dIndex += 4; - - // Descriptor flags. - dst[dIndex++] = fdVersion; - dst[dIndex++] = bsDefault << bsShift; - - // Descriptor checksum. - dst[dIndex] = xxh_hash(0, dst, 4, dIndex - 4) >> 8; - dIndex++; - - // Write blocks. - var maxBlockSize = bsMap[bsDefault]; - var remaining = src.length; - var sIndex = 0; - - // Clear the hashtable. - clearHashTable(hashTable); - - // Split input into blocks and write. - while (remaining > 0) { - var compSize = 0; - var blockSize = remaining > maxBlockSize ? maxBlockSize : remaining; - - compSize = compressBlock(src, blockBuf, sIndex, blockSize, hashTable); - - if (compSize > blockSize || compSize === 0) { - // Output uncompressed. - util.writeU32(dst, dIndex, 0x80000000 | blockSize); - dIndex += 4; - - for (var z = sIndex + blockSize; sIndex < z;) { - dst[dIndex++] = src[sIndex++]; - } - - remaining -= blockSize; - } else { - // Output compressed. - util.writeU32(dst, dIndex, compSize); - dIndex += 4; - - for (var j = 0; j < compSize;) { - dst[dIndex++] = blockBuf[j++]; - } - - sIndex += blockSize; - remaining -= blockSize; - } - } - - // Write blank end block. - util.writeU32(dst, dIndex, 0); - dIndex += 4; - - return dIndex; -}; - -// Decompresses a buffer containing an Lz4 frame. maxSize is optional; if not -// provided, a maximum size will be determined by examining the data. The -// buffer returned will always be perfectly-sized. -function decompress (src, maxSize) { - var dst, size; - - if (maxSize === undefined) { - maxSize = decompressBound(src); - } - dst = makeBuffer(maxSize); - size = decompressFrame(src, dst); - - if (size !== maxSize) { - dst = sliceArray(dst, 0, size); - } - - return dst; -}; - -// Compresses a buffer to an Lz4 frame. maxSize is optional; if not provided, -// a buffer will be created based on the theoretical worst output size for a -// given input size. The buffer returned will always be perfectly-sized. -function compress (src, maxSize) { - var dst, size; - - if (maxSize === undefined) { - maxSize = compressBound(src.length); - } - - dst = makeBuffer(maxSize); - size = compressFrame(src, dst); - - if (size !== maxSize) { - dst = sliceArray(dst, 0, size); - } - - return dst; -}; - -export {makeBuffer, compressBound, decompressBound, decompressBlock, compressBlock, compressSingleBlock, decompressFrame, compressFrame, decompress, compress}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/Lzx.js b/docs/js/libs/src/App/Decompressor/Lzx.js deleted file mode 100644 index fc8ca0a..0000000 --- a/docs/js/libs/src/App/Decompressor/Lzx.js +++ /dev/null @@ -1,769 +0,0 @@ -/** - * - * This file is heavily based on MonoGame's implementation of their LzxDecoder attributed to Ali Scissons - * which is derived from libmspack by Stuart Cole. - * - * (C) 2003-2004 Stuart Caie. - * (C) 2011 Ali Scissons. - * (C) 2017 James Stine. - * - * The LZX method was created by Johnathan Forbes and Tomi Poutanen, adapted by Microsoft Corporation. - * - */ - -/** - * GNU LESSER GENERAL PUBLIC LICENSE version 2.1 - * LzxDecoder is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - */ - -/** - * MICROSOFT PUBLIC LICENSE - * This source code a derivative on LzxDecoder and is subject to the terms of the Microsoft Public License (Ms-PL). - * - * Redistribution and use in source and binary forms, with or without modification, - * is permitted provided that redistributions of the source code retain the above - * copyright notices and this file header. - * - * Additional copyright notices should be appended to the list above. - * - * For details, see . - * - */ - -/** - * I made the mistake of not including this license years ago. Big thanks to everyone involved and license has now been - * acknowleded properly as it should have been back in 2017. - * - * Resources: - * - * cabextract/libmspack - http://http://www.cabextract.org.uk/ - * MonoGame LzxDecoder.cs - https://github.com/MonoGame/MonoGame/blob/master/MonoGame.Framework/Content/LzxDecoder.cs - * - */ - -import BufferReader from "../BufferReader.js"; -import Debug from "../../Utils/Debug.js"; -import XnbError from "../../Utils/XnbError.js"; - - -// LZX Constants -const MIN_MATCH = 2; // smallest allowable match length -const MAX_MATCH = 257; // largest allowable match length -const NUM_CHARS = 256; // number of uncompressed character types -const BLOCKTYPE = { - INVALID: 0, - VERBATIM: 1, - ALIGNED: 2, - UNCOMPRESSED: 3 -}; -const PRETREE_NUM_ELEMENTS = 20; -const ALIGNED_NUM_ELEMENTS = 8; // aligned offset tree elements -const NUM_PRIMARY_LENGTHS = 7; -const NUM_SECONDARY_LENGTHS = 249; // number of elements in length tree - -// LZX Huffman Constants -const PRETREE_MAXSYMBOLS = PRETREE_NUM_ELEMENTS; -const PRETREE_TABLEBITS = 6; -const MAINTREE_MAXSYMBOLS = NUM_CHARS + 50 * 8; -const MAINTREE_TABLEBITS = 12; -const LENGTH_MAXSYMBOLS = NUM_SECONDARY_LENGTHS + 1; -const LENGTH_TABLEBITS = 12; -const ALIGNED_MAXSYMBOLS = ALIGNED_NUM_ELEMENTS; -const ALIGNED_TABLEBITS = 7; -const LENTABLE_SAFETY = 64; // table decoding overruns are allowed - -/** - * LZX Static Data Tables - * - * LZX uses 'position slots' to represent match offsets. For every match, - * a small 'position slot' number and a small offset from that slot are - * encoded instead of one large offset. - * - * Lzx.position_base[] is an index to the position slot bases - * - * Lzx.extra_bits[] states how many bits of offset-from-base data is needed. - */ - -/** - * Used to compress and decompress LZX format buffer. - * @class - * @public - */ -class Lzx { - - /** - * Creates an instance of LZX with a given window frame. - * @constructor - * @param {Number} window_bits - */ - constructor(window_bits) { - // get the window size from window bits - this.window_size = 1 << window_bits; - - // LZX supports window sizes of 2^15 (32 KB) to 2^21 (2 MB) - if (window_bits < 15 || window_bits > 21) - throw new XnbError('Window size out of range!'); - - // initialize static tables - if (!Lzx.extra_bits.length) { - for (let i = 0, j = 0; i <= 50; i += 2) { - Lzx.extra_bits[i] = Lzx.extra_bits[i + 1] = j; - if (i != 0 && j < 17) - j++; - } - } - if (!Lzx.position_base.length) { - for (let i = 0, j = 0; i <= 50; i++) { - Lzx.position_base[i] = j; - j += 1 << Lzx.extra_bits[i]; - } - } - - Debug(`Extra Bits:`); - Debug(JSON.stringify(Lzx.extra_bits)); - Debug(`Position Base:`); - Debug(JSON.stringify(Lzx.position_base)); - - /** - * calculate required position slots - * - * window bits: 15 16 17 18 19 20 21 - * position slots: 30 32 34 36 38 42 50 - */ - const posn_slots = (window_bits == 21 ? 50 : (window_bits == 20 ? 42 : window_bits << 1)); - - // repeated offsets - this.R0 = this.R1 = this.R2 = 1; - // set the number of main elements - this.main_elements = NUM_CHARS + (posn_slots << 3); - // state of header being read used for when looping over multiple blocks - this.header_read = false; - // set the block remaining - this.block_remaining = 0; - // set the default block type - this.block_type = BLOCKTYPE.INVALID; - // window position - this.window_posn = 0; - - // frequently used tables - this.pretree_table = []; - this.pretree_len = []; - this.aligned_table = []; - this.aligned_len = []; - this.length_table = []; - this.length_len = []; - this.maintree_table = []; - this.maintree_len = []; - - // initialize main tree and length tree for use with delta operations - for (let i = 0; i < MAINTREE_MAXSYMBOLS; i++) - this.maintree_len[i] = 0; - for (let i = 0; i < NUM_SECONDARY_LENGTHS; i++) - this.length_len[i] = 0; - - // the decompression window - this.win = []; - } - - /** - * Decompress the buffer with given frame and block size - * @param {BufferReader} buffer - * @param {Number} frame_size - * @param {Number} block_size - * @returns {Number[]} - */ - decompress(buffer, frame_size, block_size) { - - // read header if we haven't already - if (!this.header_read) { - // read the intel call - const intel = buffer.readLZXBits(1); - - Debug(`Intel: 0b${intel.toString(2)} = ${intel}`); - - // don't care about intel e8 - if (intel != 0) - throw new XnbError(`Intel E8 Call found, invalid for XNB files.`); - - // the header has been read - this.header_read = true; - } - - // set what's left to go to the frame size - let togo = frame_size; - - // loop over what's left of the frame - while (togo > 0) { - - // this is a new block - if (this.block_remaining == 0) { - // read in the block type - this.block_type = buffer.readLZXBits(3); - - Debug(`Blocktype: 0b${this.block_type.toString(2).padStart(3,'0')} = ${this.block_type}`); - - // read 24-bit value for uncompressed bytes in this block - const hi = buffer.readLZXBits(16); - const lo = buffer.readLZXBits(8); - // number of uncompressed bytes for this block left - this.block_remaining = (hi << 8) | lo; - - Debug(`Block Remaining: ${this.block_remaining}`); - - // switch over the valid block types - switch (this.block_type) { - case BLOCKTYPE.ALIGNED: - // aligned offset tree - for (let i = 0; i < 8; i++) - this.aligned_len[i] = buffer.readLZXBits(3); - // decode table for aligned tree - this.aligned_table = this.decodeTable( - ALIGNED_MAXSYMBOLS, - ALIGNED_TABLEBITS, - this.aligned_len - ); - // NOTE: rest of aligned block type is the same as verbatim block type - case BLOCKTYPE.VERBATIM: - // read the first 256 elements for main tree - this.readLengths(buffer, this.maintree_len, 0, 256); - // read the rest of the elements for the main tree - this.readLengths(buffer, this.maintree_len, 256, this.main_elements); - // decode the main tree into a table - this.maintree_table = this.decodeTable( - MAINTREE_MAXSYMBOLS, - MAINTREE_TABLEBITS, - this.maintree_len - ); - // read path lengths for the length tree - this.readLengths(buffer, this.length_len, 0, NUM_SECONDARY_LENGTHS); - // decode the length tree - this.length_table = this.decodeTable( - LENGTH_MAXSYMBOLS, - LENGTH_TABLEBITS, - this.length_len - ); - break; - case BLOCKTYPE.UNCOMPRESSED: - // align the bit buffer to byte range - buffer.align(); - // read the offsets - this.R0 = buffer.readInt32(); - this.R1 = buffer.readInt32(); - this.R2 = buffer.readInt32(); - break; - default: - throw new XnbError(`Invalid Blocktype Found: ${this.block_type}`); - break; - } - } - - // iterate over the block remaining - let this_run = this.block_remaining; - - // loop over the bytes left in the buffer to run out our output - while ((this_run = this.block_remaining) > 0 && togo > 0) { - // if this run is somehow higher than togo then just cap it - if (this_run > togo) - this_run = togo; - - // reduce togo and block remaining by this iteration - togo -= this_run; - this.block_remaining -= this_run; - - // apply 2^x-1 mask - this.window_posn &= this.window_size - 1; - // run cannot exceed frame size - if (this.window_posn + this_run > this.window_size) - throw new XnbError('Cannot run outside of window frame.'); - - switch (this.block_type) { - case BLOCKTYPE.ALIGNED: - while (this_run > 0) { - // get the element of this run - let main_element = this.readHuffSymbol( - buffer, - this.maintree_table, - this.maintree_len, - MAINTREE_MAXSYMBOLS, - MAINTREE_TABLEBITS - ); - - // main element is an unmatched character - if (main_element < NUM_CHARS) { - this.win[this.window_posn++] = main_element; - this_run--; - continue; - } - - main_element -= NUM_CHARS; - - let length_footer; - - let match_length = main_element & NUM_PRIMARY_LENGTHS; - if (match_length == NUM_PRIMARY_LENGTHS) { - // get the length footer - length_footer = this.readHuffSymbol( - buffer, - this.length_table, - this.length_len, - LENGTH_MAXSYMBOLS, - LENGTH_TABLEBITS - ); - // increase match length by the footer - match_length += length_footer; - } - match_length += MIN_MATCH; - - let match_offset = main_element >> 3; - - if (match_offset > 2) { - // not repeated offset - let extra = Lzx.extra_bits[match_offset]; - match_offset = Lzx.position_base[match_offset] - 2; - if (extra > 3) { - // verbatim and aligned bits - extra -= 3; - let verbatim_bits = buffer.readLZXBits(extra); - match_offset += verbatim_bits << 3; - let aligned_bits = this.readHuffSymbol( - buffer, - this.aligned_table, - this.aligned_len, - ALIGNED_MAXSYMBOLS, - ALIGNED_TABLEBITS - ); - match_offset += aligned_bits; - } - else if (extra == 3) { - // aligned bits only - match_offset += this.readHuffSymbol( - buffer, - this.aligned_table, - this.aligned_len, - ALIGNED_MAXSYMBOLS, - ALIGNED_TABLEBITS - ); - } - else if (extra > 0) - // verbatim bits only - match_offset += buffer.readLZXBits(extra); - else - match_offset = 1; // ??? - - // update repeated offset LRU queue - this.R2 = this.R1; - this.R1 = this.R0; - this.R0 = match_offset; - } - else if (match_offset === 0) { - match_offset = this.R0; - } - else if (match_offset == 1) { - match_offset = this.R1; - this.R1 = this.R0; - this.R0 = match_offset; - } - else { - match_offset = this.R2; - this.R2 = this.R0; - this.R0 = match_offset; - } - - let rundest = this.window_posn; - let runsrc; - this_run -= match_length; - - // copy any wrapped around source data - if (this.window_posn >= match_offset) - runsrc = rundest - match_offset; // no wrap - else { - runsrc = rundest + (this.window_size - match_offset); - let copy_length = match_offset - this.window_posn; - if (copy_length < match_length) { - match_length -= copy_length; - this.window_posn += copy_length; - while (copy_length-- > 0) - this.win[rundest++] = this.win[runsrc++]; - runsrc = 0; - } - } - this.window_posn += match_length; - - // copy match data - no worrries about destination wraps - while (match_length-- > 0) - this.win[rundest++] = this.win[runsrc++]; - } - break; - - case BLOCKTYPE.VERBATIM: - while (this_run > 0) { - // get the element of this run - let main_element = this.readHuffSymbol( - buffer, - this.maintree_table, - this.maintree_len, - MAINTREE_MAXSYMBOLS, - MAINTREE_TABLEBITS - ); - - // main element is an unmatched character - if (main_element < NUM_CHARS) { - this.win[this.window_posn++] = main_element; - this_run--; - continue; - } - - // match: NUM_CHARS + ((slot << 3) | length_header (3 bits)) - - main_element -= NUM_CHARS; - - let length_footer; - - let match_length = main_element & NUM_PRIMARY_LENGTHS; - if (match_length == NUM_PRIMARY_LENGTHS) { - // read the length footer - length_footer = this.readHuffSymbol( - buffer, - this.length_table, - this.length_len, - LENGTH_MAXSYMBOLS, - LENGTH_TABLEBITS - ); - match_length += length_footer; - } - match_length += MIN_MATCH; - - let match_offset = main_element >> 3; - - if (match_offset > 2) { - // not repeated offset - if (match_offset != 3) { - let extra = Lzx.extra_bits[match_offset]; - let verbatim_bits = buffer.readLZXBits(extra); - match_offset = Lzx.position_base[match_offset] - 2 + verbatim_bits; - } - else - match_offset = 1; - - // update repeated offset LRU queue - this.R2 = this.R1; - this.R1 = this.R0; - this.R0 = match_offset; - } - else if (match_offset === 0) { - match_offset = this.R0; - } - else if (match_offset == 1) { - match_offset = this.R1; - this.R1 = this.R0; - this.R0 = match_offset; - } - else { - match_offset = this.R2; - this.R2 = this.R0; - this.R0 = match_offset; - } - - let rundest = this.window_posn; - let runsrc; - this_run -= match_length; - - // copy any wrapped around source data - if (this.window_posn >= match_offset) - runsrc = rundest - match_offset; // no wrap - else { - runsrc = rundest + (this.window_size - match_offset); - let copy_length = match_offset - this.window_posn; - if (copy_length < match_length) { - match_length -= copy_length; - this.window_posn += copy_length; - while (copy_length-- > 0) - this.win[rundest++] = this.win[runsrc++]; - runsrc = 0; - } - } - this.window_posn += match_length; - - // copy match data - no worrries about destination wraps - while (match_length-- > 0) - this.win[rundest++] = this.win[runsrc++]; - } - break; - - case BLOCKTYPE.UNCOMPRESSED: - if ((buffer.bytePosition + this_run) > block_size) - throw new XnbError('Overrun!' + block_size + ' ' + buffer.bytePosition + ' ' + this_run); - for (let i = 0; i < this_run; i++) - this.win[window_posn + i] = buffer.buffer[buffer.bytePosition + i]; - buffer.bytePosition += this_run; - this.window_posn += this_run; - break; - - default: - throw new XnbError('Invalid blocktype specified!'); - } - } - } - - // there is still more left - if (togo != 0) - throw new XnbError('EOF reached with data left to go.'); - - // ensure the buffer is aligned - buffer.align(); - - // get the start window position - const start_window_pos = ((this.window_posn == 0) ? this.window_size : this.window_posn) - frame_size; - - // return the window - return this.win.slice(start_window_pos, start_window_pos + frame_size); - } - - /** - * Reads in code lengths for symbols first to last in the given table - * The code lengths are stored in their own special LZX way. - * @public - * @method readLengths - * @param {BufferReader} buffer - * @param {Array} table - * @param {Number} first - * @param {Number} last - * @returns {Array} - */ - readLengths(buffer, table, first, last) { - // read in the 4-bit pre-tree deltas - for (let i = 0; i < 20; i++) - this.pretree_len[i] = buffer.readLZXBits(4); - - // create pre-tree table from lengths - this.pretree_table = this.decodeTable( - PRETREE_MAXSYMBOLS, - PRETREE_TABLEBITS, - this.pretree_len - ); - - // loop through the lengths from first to last - for (let i = first; i < last;) { - - // read in the huffman symbol - let symbol = this.readHuffSymbol( - buffer, - this.pretree_table, - this.pretree_len, - PRETREE_MAXSYMBOLS, - PRETREE_TABLEBITS - ); - - // code = 17, run of ([read 4 bits] + 4) zeros - if (symbol == 17) { - // read in number of zeros as a 4-bit number + 4 - let zeros = buffer.readLZXBits(4) + 4; - // iterate over zeros counter and add them to the table - while (zeros-- != 0) - table[i++] = 0; - } - // code = 18, run of ([read 5 bits] + 20) zeros - else if (symbol == 18) { - // read in number of zeros as a 5-bit number + 20 - let zeros = buffer.readLZXBits(5) + 20; - // add the number of zeros into the table array - while (zeros-- != 0) - table[i++] = 0; - } - // code = 19 run of ([read 1 bit] + 4) [read huffman symbol] - else if (symbol == 19) { - // read for how many of the same huffman symbol to repeat - let same = buffer.readLZXBits(1) + 4; - // read another huffman symbol - symbol = this.readHuffSymbol( - buffer, - this.pretree_table, - this.pretree_len, - PRETREE_MAXSYMBOLS, - PRETREE_TABLEBITS - ); - symbol = table[i] - symbol; - if (symbol < 0) symbol += 17; - while (same-- != 0) - table[i++] = symbol; - } - // code 0 -> 16, delta current length entry - else { - symbol = table[i] - symbol; - if (symbol < 0) symbol += 17; - table[i++] = symbol; - } - } - - // return the table created - return table; - } - - /** - * Build a decode table from a canonical huffman lengths table - * @public - * @method makeDecodeTable - * @param {Number} symbols Total number of symbols in tree. - * @param {Number} bits Any symbols less than this can be decoded in one lookup of table. - * @param {Number[]} length Table for lengths of given table to decode. - * @returns {Number[]} Decoded table, length should be ((1<> 1; - - // loop across all bit positions - for (let bit_num = 1; bit_num <= bits; bit_num++) { - // loop over the symbols we're decoding - for (let symbol = 0; symbol < symbols; symbol++) { - // if the symbol isn't in this iteration of length then just ignore - if (length[symbol] == bit_num) { - let leaf = pos; - // if the position has gone past the table mask then we're overrun - if ((pos += bit_mask) > table_mask) { - Debug(length[symbol]); - Debug(`pos: ${pos}, bit_mask: ${bit_mask}, table_mask: ${table_mask}`); - Debug(`bit_num: ${bit_num}, bits: ${bits}`); - Debug(`symbol: ${symbol}, symbols: ${symbols}`); - throw new XnbError('Overrun table!'); - } - // fill all possible lookups of this symbol with the symbol itself - let fill = bit_mask; - while (fill-- > 0) - table[leaf++] = symbol; - } - } - // advance bit mask down the bit positions - bit_mask >>= 1; - } - - // exit with success if table is complete - if (pos == table_mask) - return table; - - // mark all remaining table entries as unused - for (let symbol = pos; symbol < table_mask; symbol++) - table[symbol] = 0xFFFF; - - // next_symbol = base of allocation for long codes - let next_symbol = ((table_mask >> 1) < symbols) ? symbols : (table_mask >> 1); - - // allocate space for 16-bit values - pos <<= 16; - table_mask <<= 16; - bit_mask = 1 << 15; - - // loop again over the bits - for (let bit_num = bits + 1; bit_num <= 16; bit_num++) { - // loop over the symbol range - for (let symbol = 0; symbol < symbols; symbol++) { - // if the current length iteration doesn't mach our bit then just ignore - if (length[symbol] != bit_num) - continue; - - // get leaf shifted away from 16 bit padding - let leaf = pos >> 16; - - // loop over fill to flood table with - for (let fill = 0; fill < (bit_num - bits); fill++) { - // if this path hasn't been taken yet, 'allocate' two entries - if (table[leaf] == 0xFFFF) { - table[(next_symbol << 1)] = 0xFFFF; - table[(next_symbol << 1) + 1] = 0xFFFF; - table[leaf] = next_symbol++; - } - - // follow the path and select either left or right for the next bit - leaf = table[leaf] << 1; - if ((pos >> (15 - fill)) & 1) - leaf++; - } - table[leaf] = symbol - - // bit position has overun the table mask - if ((pos += bit_mask) > table_mask) - throw new XnbError('Overrun table during decoding.'); - } - bit_mask >>= 1; - } - - // we have reached table mask - if (pos == table_mask) - return table; - - // something else went wrong - throw new XnbError('Decode table did not reach table mask.'); - } - - /** - * Decodes the next huffman symbol from the bitstream. - * @public - * @method readHuffSymbol - * @param {BufferReader} buffer - * @param {Number[]} table - * @param {Number[]} length - * @param {Number} symbols - * @param {Number} bits - * @returns {Number} - */ - readHuffSymbol(buffer, table, length, symbols, bits) { - // peek the specified bits ahead - let bit = (buffer.peekLZXBits(32) >>> 0); // (>>> 0) allows us to get a 32-bit uint - let i = table[buffer.peekLZXBits(bits)]; - - // if our table is accessing a symbol beyond our range - if (i >= symbols) { - let j = 1 << (32 - bits); - do { - j >>= 1; - i <<= 1; - i |= (bit & j) != 0 ? 1 : 0; - if (j == 0) - return 0; - } - while ((i = table[i]) >= symbols) - } - - // seek past this many bits - buffer.bitPosition += length[i]; - - // return the symbol - return i; - } - - /** - * Sets the shortest match. - * @param {Number} X - */ - set RRR(X) { - // No match, R2 <- R1, R1 <- R0, R0 <- X - if (this.R0 != X && this.R1 != X && this.R2 != X) { - // shift all offsets down - this.R2 = this.R1; - this.R1 = this.R0; - this.R0 = X; - } - // X = R1, Swap R0 <-> R1 - else if (this.R1 == X) { - let R1 = this.R1; - this.R1 = this.R0; - this.R0 = R1; - } - // X = R2, Swap R0 <-> R2 - else if (this.R2 == X) { - let R2 = this.R2; - this.R2 = this.R0; - this.R0 = R2; - } - } -} - -Lzx.position_base = []; -Lzx.extra_bits = []; - -export default Lzx; diff --git a/docs/js/libs/src/App/Decompressor/dxt.js b/docs/js/libs/src/App/Decompressor/dxt.js deleted file mode 100644 index 5cc2d77..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt.js +++ /dev/null @@ -1,327 +0,0 @@ -/* ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */ - -import {kDxt1, kDxt3, kDxt5, - kColourIterativeClusterFit, kColourClusterFit, kColourRangeFit, - kColourMetricPerceptual, kColourMetricUniform, kWeightColourByAlpha -} from "./dxt/constant.js"; -import {ColorSet, SingleColourFit, RangeFit, ClusterFit} from "./dxt/colorFits.js"; -import {compressAlphaDxt3, compressAlphaDxt5} from "./dxt/alphaCompressor.js"; -import {decompressColor, decompressAlphaDxt3, decompressAlphaDxt5} from "./dxt/decompressor.js"; - -//internal constant(deconstructing) -const DXT1_COMPRESSED_BYTES = 8; -const DXT5_COMPRESSED_BYTES = 16; -const COLORS = 4; -const DECOMPRESSED_BLOCK_SIZE = 16; - - -//---------------------------------------------------------------------------// - - -/** - * image-block repeat function - * @param {function(int, int)} callback function to perform per iteration - * @param {int} x-coord - * @param {int} y-coord - */ -function blockRepeat(width, height, func) -{ - for(let y=0;y GRID) return GRID; - return result; -} - -function compressAlphaDxt3(rgba, mask, result, offset) -{ - // quantise and pack the alpha values pairwise - // repeat by 1byte (= 4bit * 2) - - for( let i = 0; i < 8; i++ ) - { - // quantise down to 4 bits - let quant1 = quantise( rgba[8*i + 3] ); - let quant2 = quantise( rgba[8*i + 7] ); - - // set alpha to zero where masked - const bit1 = 1 << ( 2*i ); - const bit2 = 1 << ( 2*i + 1 ); - if( ( mask & bit1 ) == 0 ) quant1 = 0; - if( ( mask & bit2 ) == 0 ) quant2 = 0; - - // pack into the byte - result[offset + i] = quant1 | ( quant2 << 4 ); - } - -} - -function compressAlphaDxt5(rgba, mask, result, offset) -{ - let step5 = interpolateAlpha(rgba, mask, 5); - let step7 = interpolateAlpha(rgba, mask, 7); - - // save the block with least error - if( step5.error <= step7.error ) writeAlphaBlock5( step5, result, offset ); - else writeAlphaBlock7( step7, result, offset); -} - - -function interpolateAlpha(rgba, mask, steps) -{ - let {min, max} = setAlphaRange(rgba, mask, steps); - - let code = setAlphaCodeBook(min, max, steps); - - let indices = new Uint8Array(16); - let error = fitCodes(rgba, mask, code, indices); - - return {min, max, indices, error}; -} - -function setAlphaRange(rgba, mask, steps) -{ - let min = 255; - let max = 0; - - for( let i = 0; i < 16; i++ ) - { - // check this pixel is valid - let bit = 1 << i; - if( ( mask & bit ) == 0 ) continue; - - // incorporate into the min/max - let value = rgba[4*i + 3]; - - if(steps === 5) - { - if(value !== 0 && value < min) min = value; - if(value !== 255 && value > max) max = value; - } - else - { - if(value < min) min = value; - if(value > max) max = value; - } - } - - // handle the case that no valid range was found - if(min > max) min = max; - - // fix range - if(max - min < steps) max = Math.min(min + steps, 255); - if(max - min < steps) min = Math.max(max - steps, 0); - - return {min, max}; -} - -function setAlphaCodeBook(min, max, steps) -{ - // set up the alpha code book - let codes = [min, max, ...Array.from({length:steps-1}, (_,i)=>{ - return Math.floor( ( (steps - (i+1) ) * min + (i+1) * max ) / steps ); - })]; - if(steps === 5) - { - codes[6] = 0; - codes[7] = 255; - } - return codes; -} - -function fitCodes(rgba, mask, codes, indices) -{ - // fit each alpha value to the codebook - let err = 0; - for( let i = 0; i < 16; ++i ) - { - // check this pixel is valid - let bit = 1 << i; - if( ( mask & bit ) == 0 ) - { - // use the first code - indices[i] = 0; - continue; - } - - // find the least error and corresponding index - let value = rgba[4*i + 3]; - let least = Infinity; - let index = 0; - for( let j = 0; j < 8; ++j ) - { - // get the squared error from this code - let dist = value - codes[j]; - dist *= dist; - - // compare with the best so far - if( dist < least ) - { - least = dist; - index = j; - } - } - - // save this index and accumulate the error - indices[i] = index; - err += least; - } - - // return the total error - return err; -} - -function writeAlphaBlock5({min:alpha0, max:alpha1, indices}, result, offset) -{ - // check the relative values of the endpoints - if( alpha0 > alpha1 ) - { - //swap the indices; - const swapped = indices.map((index)=>{ - if(index === 0) return 1; - if(index === 1) return 0; - if(index <= 5) return 7-index; - return index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } - else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} - -function writeAlphaBlock7({min:alpha0, max:alpha1, indices}, result, offset) -{ - // check the relative values of the endpoints - if( alpha0 > alpha1 ) - { - //swap the indices; - const swapped = indices.map((index)=>{ - if(index === 0) return 1; - if(index === 1) return 0; - return 9-index; - }); - writeAlphaBlock(alpha1, alpha0, swapped, result, offset); - } - else writeAlphaBlock(alpha0, alpha1, indices, result, offset); -} - -function writeAlphaBlock(alpha0, alpha1, indices, result, offset) -{ - // write the first two bytes - result[offset] = alpha0; - result[offset + 1] = alpha1; - - // pack the indices with 3 bits each - let indicesPointer = 0; - let resultPointer = offset + 2; - - for( let i = 0; i < 2; i++ ) - { - // pack 8 3-bit values - let value = 0; - for( let j = 0; j < 8; ++j ) - { - let index = indices[indicesPointer]; - value |= ( index << 3*j ); - indicesPointer++; - } - - // store in 3 bytes - for( let j = 0; j < 3; ++j ) - { - let byte = ( value >> 8*j ) & 0xff; - result[resultPointer] = byte; - resultPointer++; - } - } -} - - -export {compressAlphaDxt3, compressAlphaDxt5, setAlphaCodeBook}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/colorBlock.js b/docs/js/libs/src/App/Decompressor/dxt/colorBlock.js deleted file mode 100644 index 33350b2..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/colorBlock.js +++ /dev/null @@ -1,111 +0,0 @@ -import {Vec3} from "./math.js"; - -function floatToInt(value, limit) -{ - // use ANSI round-to-zero behaviour to get round-to-nearest - const integer = parseInt( value + 0.5 ); - - // clamp to the limit - if(integer < 0) return 0; - if(integer > limit) return integer; - return integer; -} - -function floatTo565( color ) -{ - // get the components in the correct range - const r = floatToInt( 31.0*color.x, 31 ); - const g = floatToInt( 63.0*color.y, 63 ); - const b = floatToInt( 31.0*color.z, 31 ); - - // pack into a single value - return ( r << 11 ) | ( g << 5 ) | b; -} - -/** - * @param {int} packed 16bit first color - * @param {int} packed 16bit second color - * @param {Array(int)} each pixel block's index data - * @param {Uint8Array} the array to save result - * @param {int} the array's offset - */ -function writeColourBlock( firstColor, secondColor, indices, result, blockOffset ) -{ - // write the endpoints as little endian - result[blockOffset + 0] = firstColor & 0xff ; - result[blockOffset + 1] = firstColor >> 8 ; - result[blockOffset + 2] = secondColor & 0xff ; - result[blockOffset + 3] = secondColor >> 8 ; - - // write the indices as big endian like [33221100] - for( let y = 0; y < 4; y++ ) - { - result[blockOffset + 4 + y] = ( indices[4*y + 0] | - ( indices[4*y + 1] << 2 ) | - ( indices[4*y + 2] << 4 ) | - ( indices[4*y + 3] << 6 ) ); - } -} - - -/** - * @param {Vec3} first color - * @param {Vec3} second color - * @param {Array(int)} each pixel block's index data - * @param {Uint8Array} the array to save result - * @param {int} the array's offset - */ -function writeColourBlock3( start, end, indices, result, blockOffset ) -{ - // get the packed values - let firstColor = floatTo565( start ); - let secondColor = floatTo565( end ); - - // remap the indices - let remapped; - if( firstColor <= secondColor ) - { - // use the indices directly - remapped = indices.slice(); - } - else - { - // swap a and b - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map((index) => (index===0) ? 1 : ( (index===1) ? 0 : index) ); - } - - // write the block - writeColourBlock( firstColor, secondColor, remapped, result, blockOffset ); -} - -function writeColourBlock4( start, end, indices, result, blockOffset ) -{ - // get the packed values - let firstColor = floatTo565( start ); - let secondColor = floatTo565( end ); - - // remap the indices - let remapped; - if( firstColor < secondColor ) - { - // swap a and b - [firstColor, secondColor] = [secondColor, firstColor]; - remapped = indices.map((index) => (index^0x1) & 0x3); - } - else if( firstColor == secondColor ) - { - // use index 0 - remapped = new Array(16).fill(0); - } - else - { - // use the indices directly - remapped = indices.slice(); - } - - // write the block - writeColourBlock( firstColor, secondColor, remapped, result, blockOffset ); -} - -export {writeColourBlock3, writeColourBlock4}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/colorFits.js b/docs/js/libs/src/App/Decompressor/dxt/colorFits.js deleted file mode 100644 index 1fa650e..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/colorFits.js +++ /dev/null @@ -1,744 +0,0 @@ -/* ----------------------------------------------------------------------------- - Copyright (c) 2006 Simon Brown si@sjbrown.co.uk - Copyright (c) 2007 Ignacio Castano icastano@nvidia.com - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------- */ - -import {kDxt1, kDxt3, kDxt5, - kColourIterativeClusterFit, kColourClusterFit, kColourRangeFit, - kColourMetricPerceptual, kColourMetricUniform, kWeightColourByAlpha -} from "./constant.js"; -import {Vec3, Vec4, computePCA} from "./math.js"; -import {lookup_5_3, lookup_6_3, lookup_5_4, lookup_6_4} from "./lookup.js"; -import {writeColourBlock3, writeColourBlock4} from "./colorBlock.js"; - -class ColorSet -{ - constructor(rgba, mask, flags) - { - /** - * this colorset's flags - * @public - * @type {Number} - */ - this.flags = flags; - /** - * the number of colors - * @private - * @type {Number} - */ - this._count = 0; - /** - * the number of colors - * @private - * @type {boolean} - */ - this._transparent = false; - - /** - * the indices of color - * @private - * @type {Array(Number)} - */ - this._remap = []; - /** - * Weighted by how many colors there are - * @private - * @type {Array(Number)} - */ - this._weights = []; - /** - * the color data - * @private - * @type {Array(Vec3)} - */ - this._points = []; - - const isDxt1 = ( (this.flags & kDxt1) != 0); - const weightByAlpha = ( (this.flags & kWeightColourByAlpha ) != 0); - - // create the minimal set - for( let i = 0; i < 16; i++ ) - { - // check this pixel is enabled - const bit = 1 << i; - if( ( mask & bit ) == 0 ) - { - this._remap[i] = -1; - continue; - } - - // check for transparent pixels when using dxt1 - if( isDxt1 && rgba[4*i + 3] < 128 ) - { - this._remap[i] = -1; - this._transparent = true; - continue; - } - - // loop over previous points for a match - for( let j = 0;; j++ ) - { - // allocate a new point - if( j == i ) - { - // normalise coordinates to [0,1] - const r = rgba[4*i] / 255.0; - const g = rgba[4*i + 1] / 255.0; - const b = rgba[4*i + 2] / 255.0; - - // ensure there is always non-zero weight even for zero alpha - const a = ( rgba[4*i + 3] + 1 ) / 256.0; - - // add the point - this._points[this._count] = new Vec3( r, g, b ); - this._weights[this._count] = ( weightByAlpha ? a : 1.0 ); - this._remap[i] = this._count; - - // advance - this._count++; - break; - } - - // check for a match - const oldbit = 1 << j; - const match = ( ( mask & oldbit ) != 0 ) - && ( rgba[4*i] == rgba[4*j] ) - && ( rgba[4*i + 1] == rgba[4*j + 1] ) - && ( rgba[4*i + 2] == rgba[4*j + 2] ) - && ( rgba[4*j + 3] >= 128 || !isDxt1 ); - if( match ) - { - // get the index of the match - const index = this._remap[j]; - - // ensure there is always non-zero weight even for zero alpha - const w = ( rgba[4*i + 3] + 1 ) / 256.0; - - // map to this point and increase the weight - this._weights[index] += ( weightByAlpha ? w : 1.0 ); - this._remap[i] = index; - break; - } - } - } - - // square root the weights - for( let i = 0; i < this._count; ++i ) - this._weights[i] = Math.sqrt( this._weights[i] ); - } - - get transparent() - { - return this._transparent; - } - get count() - { - return this._count; - } - get points() - { - return Object.freeze(this._points.slice()); - } - get weights() - { - return Object.freeze(this._weights.slice()); - } - - /** - * @param {int} index no - * @param {Uint8Array} Colormap index to store the result - */ - remapIndicesSingle(singleIndex, target) - { - const result = this._remap.map((index)=>index===-1 ? 3 : singleIndex); - target.forEach((_,i)=>target[i]=result[i]); - } - /** - * @example - * this.remap=[0,1,2,3, 2,2,3,4, 3,4,6,6, 7,5,5,0] - * indexMap = [0,0,1,1,2,2,3,3] - * target(result) => [0,0,1,1, 1,1,1,2, 1,1,3,3, 3,2,2,0] - * @param {Uint8Array} map of index numbers to fill - * @param {Uint8Array} Colormap index to store the result - */ - remapIndices(indexMap, target) - { - const result = this._remap.map((index)=>index===-1 ? 3 : indexMap[index]); - target.forEach((_,i)=>target[i]=result[i]); - } -} - -class ColorFit -{ - constructor(colorSet) - { - this.colors = colorSet; - this.flags = colorSet.flags; - } - compress(result, offset) - { - const isDxt1 = ( (this.flags & kDxt1) != 0); - if(isDxt1) { - this.compress3(result, offset); - if (!this.colors.transparent) this.compress4(result, offset); - } - else this.compress4(result, offset); - } - compress3(result, offset){} - compress4(result, offset){} -} - -class SingleColourFit extends ColorFit -{ - constructor(colorSet) - { - super(colorSet); - - // grab the single colour - const singleColor = colorSet.points[0]; - this.color = singleColor.colorInt; - - // private property - this.start = new Vec3(0); - this.end = new Vec3(0); - this.index = 0; - - this.error = Infinity; - this.bestError = Infinity; - } - compressBase(lookups, saveFunc) - { - this.computeEndPoints(lookups); - - if(this.error < this.bestError) - { - const indices = new Uint8Array(16); - this.colors.remapIndicesSingle(this.index, indices); - saveFunc(this.start, this.end, indices); - - this.bestError = this.error; - } - } - compress3(result, offset) - { - const lookups = [lookup_5_3, lookup_6_3, lookup_5_3]; - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - - this.compressBase(lookups, saveFunc); - } - compress4(result, offset) - { - const lookups = [lookup_5_4, lookup_6_4, lookup_5_4]; - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - - this.compressBase(lookups, saveFunc); - } - computeEndPoints(lookups) - { - // check each index combination (endpoint or intermediate) - this.error = Infinity; - for( let index = 0; index < 2; index++ ) - { - // check the error for this codebook index - const sources = []; //source : [channel][start/end/error] - let error = 0; - for( let channel = 0; channel < 3; channel++ ) - { - // grab the lookup table and index for this channel - const lookup = lookups[channel]; //lookup : [rgb-raw index][startpoint/midpoint] - const target = this.color[channel]; - - // store a pointer to the source for this channel - sources[channel] = lookup[target][index]; - - // accumulate the error - const diff = sources[channel][2]; - error += diff*diff; - } - - // keep it if the error is lower - if( error < this.error ) - { - this.start = new Vec3( - sources[0][0]/31.0, - sources[1][0]/63.0, - sources[2][0]/31.0 - ); - this.end = new Vec3( - sources[0][1]/31.0, - sources[1][1]/63.0, - sources[2][1]/31.0 - ); - this.index = 2*index ; // 0:startpoint, 2:midpoint - this.error = error; - } - } - } -} - -class RangeFit extends ColorFit -{ - constructor(colorSet) - { - super(colorSet); - - this.metric = new Vec3(1); - if( (this.flags & kColourMetricPerceptual) !== 0) - { - this.metric.set(0.2126, 0.7152, 0.0722); - } - - // private property - this.start = new Vec3(0); - this.end = new Vec3(0); - - this.bestError = Infinity; - - //compute start&end points - this.computePoints(); - } - compressBase(codes, saveFunc) - { - const {points:values} = this.colors; - - let error = 0; - - // Map the closest code of each color - const closest = values.map((color)=>{ - let minDist = Infinity; - - // find the closest code - const packedIndex = codes.reduce((idx, code, j)=>{ - const dist = Vec3.sub(color, code).multVector(this.metric).lengthSq; - - if(dist >= minDist) return idx; - minDist = dist; - return j; - }, 0); - - // accumulate the error - error += minDist; - - // save the index - return packedIndex; - }); - - // save this scheme if it wins - if( error < this.bestError ) - { - // remap the indices - let indices = new Uint8Array(16); - this.colors.remapIndices( closest, indices ); - - // save the block - saveFunc( this.start, this.end, indices ); - - // save the error - this.bestError = error; - } - } - compress3(result, offset) - { - const codes=[ - this.start.clone(), - this.end.clone(), - Vec3.interpolate(this.start, this.end, 0.5) - ]; - - const saveFunc = (start, end, indices) => writeColourBlock3(start, end, indices, result, offset); - - this.compressBase(codes, saveFunc); - } - compress4(result, offset) - { - const codes=[ - this.start.clone(), - this.end.clone(), - Vec3.interpolate(this.start, this.end, 1/3), - Vec3.interpolate(this.start, this.end, 2/3), - ]; - - const saveFunc = (start, end, indices) => writeColourBlock4(start, end, indices, result, offset); - - this.compressBase(codes, saveFunc); - } - computePoints() - { - const {count, points:values, weights} = this.colors; - if(count <= 0) return; - - //dimension regression - const principle = computePCA(values, weights); - - let start, end, min, max; - - start=end=values[0]; - min=max=Vec3.dot(start, principle); - - //compute the range - for(let i=1; i max) - { - end = values[i]; - max = value; - } - } - - // clamp to the grid and save - this.start = start.clampGrid().clone(); - this.end = end.clampGrid().clone(); - } -} - - -class ClusterFit extends ColorFit -{ - constructor(colorSet) - { - super(colorSet); - - // set the iteration count - const kMaxIterations = 8; - this.iterationCount = (colorSet.flags & kColourIterativeClusterFit) ? kMaxIterations : 1; - - // initialise the best error - this.bestError = Infinity; - - // initialise the metric - this.metric = new Vec4(1); - if( (this.flags & kColourMetricPerceptual) !== 0) - { - this.metric.set(0.2126, 0.7152, 0.0722, 0); - } - - // dimension regression - const {points:values, weights} = this.colors; - this.principle = computePCA(values, weights); - - // private property - this.order = new Uint8Array(16 * kMaxIterations); - this.pointsWeights=[]; //Array(Vec4)[16] - this.xSum_wSum = new Vec4(0); //Vec4 - } - - /* - * main Logics - */ - constructOrdering(axis, iteration) - { - const currentOrder = this.makeOrder(axis); - this.copyOrderToThisOrder(currentOrder, iteration) - - const uniqueOrder = this.checkOrderUnique(currentOrder, iteration); - if(!uniqueOrder) return false; - - this.copyOrderWeight(currentOrder); - - return true; - } - compress3(result, offset) - { - const aabbx = ([part0, , part1, part2])=>{ - const const1_2 = new Vec4(1/2, 1/2, 1/2, 1/4); - - const alphax_sum = Vec4.multiplyAdd( part1, const1_2, part0 ); - const alpha2_sum = alphax_sum.splatW; - - const betax_sum = Vec4.multiplyAdd( part1, const1_2, part2 ); - const beta2_sum = betax_sum.splatW; - - const alphabeta_sum = Vec4.multVector(part1, const1_2).splatW; - - return { - ax:alphax_sum, - aa:alpha2_sum, - bx:betax_sum, - bb:beta2_sum, - ab:alphabeta_sum - } - }; - const saveFunc = (start, end, indices)=>writeColourBlock3(start, end, indices, result, offset); - this.compressBase(aabbx, saveFunc, 2); - } - compress4(result, offset) - { - const aabbx = ([part0, part1, part2, part3])=>{ - const const1_3 = new Vec4(1/3, 1/3, 1/3, 1/9); - const const2_3 = new Vec4(2/3, 2/3, 2/3, 4/9); - const const2_9 = new Vec4(2/9); - - const alphax_sum = Vec4.multiplyAdd( part2, const1_3, Vec4.multiplyAdd( part1, const2_3, part0 ) ); - const alpha2_sum = alphax_sum.splatW; - - const betax_sum = Vec4.multiplyAdd( part1, const1_3, Vec4.multiplyAdd( part2, const2_3, part3 ) ); - const beta2_sum = betax_sum.splatW; - - const alphabeta_sum = Vec4.multVector(const2_9, Vec4.add(part1, part2)).splatW; - - return { - ax:alphax_sum, - aa:alpha2_sum, - bx:betax_sum, - bb:beta2_sum, - ab:alphabeta_sum - } - }; - const saveFunc = (start, end, indices)=>writeColourBlock4(start, end, indices, result, offset); - this.compressBase(aabbx, saveFunc, 3); - } - compressBase(aabbFunc, saveFunc, repeater=2) - { - // prepare an ordering using the principle axis - this.constructOrdering(this.principle, 0); - - // check all possible clusters and iterate on the total order - let best = { - start : new Vec4(0), - end : new Vec4(0), - error : this.bestError, - iteration : 0, - bestI : 0, - bestJ : 0, - }; - if(repeater === 3) best.bestK = 0; - - // inner least squares terms function - const leastSquares = (parts, internalIndices)=>{ - const aabbx = aabbFunc(parts); - - const internalBest = this.computeOptimalPoints(aabbx); - - if(internalBest.error < best.error) - { - // keep the solution if it wins - best = {...internalBest, ...internalIndices}; - return true; - } - return false; - }; - - // loop over iterations (we avoid the case that all points in first or last cluster) - for( let iterationIndex = 0;; ) - { - this.clusterIterate(iterationIndex, leastSquares, repeater); - - // stop if we didn't improve in this iteration - if( best.iteration != iterationIndex ) break; - - // advance if possible - iterationIndex++; - if( iterationIndex == this.iterationCount ) break; - - // stop if a new iteration is an ordering that has already been tried - const newAxis = Vec4.sub( best.end, best.start ).xyz; - if( !this.constructOrdering( newAxis, iterationIndex ) ) break; - } - - // save the block if win - if(best.error < this.bestError) this.saveBlock(best, saveFunc); - } - - /* - * for constructOrdering function - */ - makeOrder(axis) - { - const {count, points:values} = this.colors; - - // map dot products and stable sort - // result : [1st index of color, 2nd index of color, ...] - const dotProducts=values.map((color, i)=>Vec3.dot(color, axis)); - return Array.from({length:count},(_,i)=>i) - .sort((a,b)=>{ - if(dotProducts[a]-dotProducts[b] != 0) return dotProducts[a]-dotProducts[b]; - return a-b; - }); - } - copyOrderToThisOrder(order, iteration) - { - //copy currentOrder array to this.order - const orderOffset = iteration * 16; - order.forEach((ord, i)=>{ - this.order[orderOffset + i] = ord; - }); - } - checkOrderUnique(order, iteration) - { - // check this ordering is unique - const {count} = this.colors; - - for(let it =0; it{ - if(m < bestI) return 0; - if(m < bestJ) return 2; - if(m < bestK) return 3; - return 1; - } - for(let i=0; i{ - const mapper = { - bestI:i, - bestJ:( iterCount === 2 ? k : j ), - iteration : index - }; - if(iterCount === 3) mapper.bestK = k; - return mapper; - }; - - // first cluster [0,i) is at the start - let part0 = new Vec4( 0.0 ); - for( let i = 0; i < count; i++ ) - { - // second cluster [i,j) is half along - let part1 = new Vec4( 0.0 ); - for( let j = i;; ) - { - // third cluster [j,k) is two thirds along - let preLastPart = ( j == 0 ) ? this.pointsWeights[0].clone() : new Vec4(0.0); - const kmin = ( j == 0 ) ? 1 : j; - for( let k = kmin;; ) - { - // last cluster [k,count) is at the end - const restPart = Vec4.sub(this.xSum_wSum, preLastPart).subVector(part1).subVector(part0); - - func([part0, part1, preLastPart, restPart], indexMapper(i, j, k)); - - // advance - if( k == count ) break; - preLastPart.addVector(this.pointsWeights[k]); - k++; - } - - // if iterCount === 2(=using Compress3), j iteration is not used - if(iterCount === 2) break; - - // advance - if(j === count) break; - part1.addVector(this.pointsWeights[j]); - j++; - } - // advance - part0.addVector(this.pointsWeights[i]); - } - } -} - - -export {ColorSet, SingleColourFit, RangeFit, ClusterFit}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/constant.js b/docs/js/libs/src/App/Decompressor/dxt/constant.js deleted file mode 100644 index 9a9ce93..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/constant.js +++ /dev/null @@ -1,21 +0,0 @@ -//constant values -const kDxt1 = ( 1 << 0 ); //! Use DXT1 compression. -const kDxt3 = ( 1 << 1 ); //! Use DXT3 compression. -const kDxt5 = ( 1 << 2 ); //! Use DXT5 compression. -const kColourIterativeClusterFit = ( 1 << 8 ); //! Use a very slow but very high quality colour compressor. -const kColourClusterFit = ( 1 << 3 ); //! Use a slow but high quality colour compressor (the default). -const kColourRangeFit = ( 1 << 4 ); //! Use a fast but low quality colour compressor. -const kColourMetricPerceptual = ( 1 << 5 ); //! Use a perceptual metric for colour error (the default). -const kColourMetricUniform = ( 1 << 6 ); //! Use a uniform metric for colour error. -const kWeightColourByAlpha = ( 1 << 7 ); //! Weight the colour by alpha during cluster fit (disabled by default). - -export {kDxt1, - kDxt3, - kDxt5, - kColourIterativeClusterFit, - kColourClusterFit, - kColourRangeFit, - kColourMetricPerceptual, - kColourMetricUniform, - kWeightColourByAlpha -}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/decompressor.js b/docs/js/libs/src/App/Decompressor/dxt/decompressor.js deleted file mode 100644 index b4d9c4b..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/decompressor.js +++ /dev/null @@ -1,163 +0,0 @@ -import {setAlphaCodeBook} from "./alphaCompressor.js"; - -function unpack565(color16bit) -{ - // get the components in the stored range - const red = (color16bit >> 11) & 0x1f; - const green = (color16bit >> 5) & 0x3f; - const blue = color16bit & 0x1f; - - // scale up to 8 bits - return [ - ( red << 3 ) | ( red >> 2 ), - ( green << 2 ) | ( green >> 4 ), - ( blue << 3 ) | ( blue >> 2 ), - 255 - ]; -} - -function interpolateColorArray(a, b, amount) -{ - const result = a.map((aColor, i)=>Math.floor( aColor * (1-amount) + b[i] * amount) ); - result[3] = 255; - return result; -} - -function unpackColorCodes(block, offset, isDxt1) -{ - const color1 = block[offset] | (block[offset+1] << 8); - const color2 = block[offset+2] | (block[offset+3] << 8); - - const unpackedColor1 = unpack565(color1); - const unpackedColor2 = unpack565(color2); - - return [ - unpackedColor1, - unpackedColor2, - ( isDxt1 && color1 <= color2 ) ? - interpolateColorArray(unpackedColor1, unpackedColor2, 1/2) : - interpolateColorArray(unpackedColor1, unpackedColor2, 1/3), - ( isDxt1 && color1 <= color2 ) ? [0, 0, 0, 0] : - interpolateColorArray(unpackedColor1, unpackedColor2, 2/3) - ]; -} - -function unpackIndices(block, blockOffset) -{ - // unpack the indices - let offset = blockOffset + 4; - let result = new Uint8Array(16); - for(let i=0;i < 4; i++) - { - let packedIndices = block[offset + i]; - result[i*4 + 0] = packedIndices & 0x3; - result[i*4 + 1] = (packedIndices>>2) & 0x3; - result[i*4 + 2] = (packedIndices>>4) & 0x3; - result[i*4 + 3] = (packedIndices>>6) & 0x3; - } - return result; -} - - -/** - * @param {Uint8Array} Buffer in which the decompressed result will be stored - * @param {Uint8Array} compressed data - * @param {int} compressed data's offset - * @param {boolean} is using DXT1 - */ - -function decompressColor(rgba, block, offset, isDxt1) -{ - const colorCode = unpackColorCodes(block, offset, isDxt1); - const indices = unpackIndices(block, offset); - - // store out the colours - for( let i = 0; i < 16; i++ ) - { - for( let j = 0; j < 4; j++ ) { - rgba[4*i + j] = colorCode[ indices[i]][j]; - } - } -} -/* - compressed color bites are like this: - [color1(low)] - [color1(high)] - [color2(low)] - [color2(high)] - [id3|id2|id1|id0] - [id7|id6|id5|id4] - [id11|id10|id9|id8] - [id15|id14|id13|id12] -*/ - - -/** - * @param {Uint8Array} Buffer in which the decompressed result will be stored - * @param {Uint8Array} compressed data - * @param {int} compressed data's offset - */ -function decompressAlphaDxt3(rgba, block, offset) -{ - // unpack the alpha values pairwise - for( let i = 0; i < 8; ++i ) - { - // quantise down to 4 bits - let quant = block[offset + i]; - - // unpack the values - let lo = quant & 0x0f; - let hi = quant & 0xf0; - - // convert back up to bytes - rgba[8*i + 3] = lo | ( lo << 4 ); - rgba[8*i + 7] = hi | ( hi >> 4 ); - } -} - -/** - * @param {Uint8Array} Buffer in which the decompressed result will be stored - * @param {Uint8Array} compressed data - * @param {int} compressed data's offset - */ -function decompressAlphaDxt5(rgba, block, offset) -{ - // get the two alpha values - let alpha0 = block[offset + 0]; - let alpha1 = block[offset + 1]; - - // compare the values to build the codebook - let codes = setAlphaCodeBook(alpha0, alpha1, (alpha0 <= alpha1) ? 5 : 7); - - // decode the indices - let indices = new Uint8Array(16); - let indicePointer = 0; - let bytePointer = 2; - - for( let i = 0; i < 2; i++ ) - { - // grab 3 bytes - let value = 0; - for( let j = 0; j < 3; j++ ) - { - let byte = block[offset + bytePointer]; - value |= ( byte << 8*j ); - bytePointer++; - } - - // unpack 8 3-bit values from it - for( let j = 0; j < 8; j++ ) - { - let index = ( value >> 3*j ) & 0x7; - indices[indicePointer] = index; - indicePointer++; - } - } - - // write out the indexed codebook values - for( let i = 0; i < 16; ++i ) { - rgba[4*i + 3] = codes[indices[i]]; - } -} - -export {decompressColor, decompressAlphaDxt3, decompressAlphaDxt5}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/eigs.js b/docs/js/libs/src/App/Decompressor/dxt/eigs.js deleted file mode 100644 index 67ef201..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/eigs.js +++ /dev/null @@ -1,162 +0,0 @@ -/* - * get Eigen-values and Eigen-vectors from symmetric matrix - * I can use it directly because covarience matrix is symmetric - Lybell - * from DiagonalizeJS : https://github.com/arkajitmandal/DiagonalizeJS - * made by Arkajit Mandal - */ - -// Rotation Matrix -function Rot(theta){ - let Mat = [[Math.cos(theta),Math.sin(theta)],[-Math.sin(theta),Math.cos(theta)]]; - return Mat -} -// Givens Matrix -function Rij(k,l,theta,N){ - let Mat = Array(N) - for (let i = 0; i= Math.abs(e0)){ - // block index to be rotated - let i = Vab[0][0]; - let j = Vab[0][1]; - // get theta - let psi = getTheta(Hij[i][i], Hij[j][j], Hij[i][j]); - // Givens matrix - let Gij = Rij(i,j,psi,N); - // rotate Hamiltonian using Givens - Hij = unitary(Gij,Hij); - // Update vectors - Sij = AxB(Sij,Gij); - // update error - Vab = getAij(Hij); - } - for (let i = 0; i{ - let vector = vectors.map((v)=>v[i]); - return {value:values[i], vec:vector}; - }); - pairs.sort((a,b)=>b.value - a.value); - - let sortedValues = pairs.map(({value})=>value); - let sortedVectors = pairs.map(({vec})=>vec); - return [sortedValues, sortedVectors]; -} - -function dominentPrincipalVector(matrix) -{ - let [,[dominentVector]] = eigens(matrix); - return dominentVector; -} - -export {eigens, dominentPrincipalVector}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/lookup.js b/docs/js/libs/src/App/Decompressor/dxt/lookup.js deleted file mode 100644 index ad5d570..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/lookup.js +++ /dev/null @@ -1,1041 +0,0 @@ -const lookup_5_3 = -[ - [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], - [ [ 0, 0, 1 ], [ 0, 0, 1 ] ], - [ [ 0, 0, 2 ], [ 0, 0, 2 ] ], - [ [ 0, 0, 3 ], [ 0, 1, 1 ] ], - [ [ 0, 0, 4 ], [ 0, 1, 0 ] ], - [ [ 1, 0, 3 ], [ 0, 1, 1 ] ], - [ [ 1, 0, 2 ], [ 0, 1, 2 ] ], - [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], - [ [ 1, 0, 0 ], [ 0, 2, 0 ] ], - [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], - [ [ 1, 0, 2 ], [ 0, 2, 2 ] ], - [ [ 1, 0, 3 ], [ 0, 3, 1 ] ], - [ [ 1, 0, 4 ], [ 0, 3, 0 ] ], - [ [ 2, 0, 3 ], [ 0, 3, 1 ] ], - [ [ 2, 0, 2 ], [ 0, 3, 2 ] ], - [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], - [ [ 2, 0, 0 ], [ 0, 4, 0 ] ], - [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], - [ [ 2, 0, 2 ], [ 0, 4, 2 ] ], - [ [ 2, 0, 3 ], [ 0, 5, 1 ] ], - [ [ 2, 0, 4 ], [ 0, 5, 0 ] ], - [ [ 3, 0, 3 ], [ 0, 5, 1 ] ], - [ [ 3, 0, 2 ], [ 0, 5, 2 ] ], - [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], - [ [ 3, 0, 0 ], [ 0, 6, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], - [ [ 3, 0, 2 ], [ 0, 6, 2 ] ], - [ [ 3, 0, 3 ], [ 0, 7, 1 ] ], - [ [ 3, 0, 4 ], [ 0, 7, 0 ] ], - [ [ 4, 0, 4 ], [ 0, 7, 1 ] ], - [ [ 4, 0, 3 ], [ 0, 7, 2 ] ], - [ [ 4, 0, 2 ], [ 1, 7, 1 ] ], - [ [ 4, 0, 1 ], [ 1, 7, 0 ] ], - [ [ 4, 0, 0 ], [ 0, 8, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 8, 1 ] ], - [ [ 4, 0, 2 ], [ 2, 7, 1 ] ], - [ [ 4, 0, 3 ], [ 2, 7, 0 ] ], - [ [ 4, 0, 4 ], [ 0, 9, 0 ] ], - [ [ 5, 0, 3 ], [ 0, 9, 1 ] ], - [ [ 5, 0, 2 ], [ 3, 7, 1 ] ], - [ [ 5, 0, 1 ], [ 3, 7, 0 ] ], - [ [ 5, 0, 0 ], [ 0, 10, 0 ] ], - [ [ 5, 0, 1 ], [ 0, 10, 1 ] ], - [ [ 5, 0, 2 ], [ 0, 10, 2 ] ], - [ [ 5, 0, 3 ], [ 0, 11, 1 ] ], - [ [ 5, 0, 4 ], [ 0, 11, 0 ] ], - [ [ 6, 0, 3 ], [ 0, 11, 1 ] ], - [ [ 6, 0, 2 ], [ 0, 11, 2 ] ], - [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], - [ [ 6, 0, 0 ], [ 0, 12, 0 ] ], - [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], - [ [ 6, 0, 2 ], [ 0, 12, 2 ] ], - [ [ 6, 0, 3 ], [ 0, 13, 1 ] ], - [ [ 6, 0, 4 ], [ 0, 13, 0 ] ], - [ [ 7, 0, 3 ], [ 0, 13, 1 ] ], - [ [ 7, 0, 2 ], [ 0, 13, 2 ] ], - [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], - [ [ 7, 0, 0 ], [ 0, 14, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], - [ [ 7, 0, 2 ], [ 0, 14, 2 ] ], - [ [ 7, 0, 3 ], [ 0, 15, 1 ] ], - [ [ 7, 0, 4 ], [ 0, 15, 0 ] ], - [ [ 8, 0, 4 ], [ 0, 15, 1 ] ], - [ [ 8, 0, 3 ], [ 0, 15, 2 ] ], - [ [ 8, 0, 2 ], [ 1, 15, 1 ] ], - [ [ 8, 0, 1 ], [ 1, 15, 0 ] ], - [ [ 8, 0, 0 ], [ 0, 16, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 16, 1 ] ], - [ [ 8, 0, 2 ], [ 2, 15, 1 ] ], - [ [ 8, 0, 3 ], [ 2, 15, 0 ] ], - [ [ 8, 0, 4 ], [ 0, 17, 0 ] ], - [ [ 9, 0, 3 ], [ 0, 17, 1 ] ], - [ [ 9, 0, 2 ], [ 3, 15, 1 ] ], - [ [ 9, 0, 1 ], [ 3, 15, 0 ] ], - [ [ 9, 0, 0 ], [ 0, 18, 0 ] ], - [ [ 9, 0, 1 ], [ 0, 18, 1 ] ], - [ [ 9, 0, 2 ], [ 0, 18, 2 ] ], - [ [ 9, 0, 3 ], [ 0, 19, 1 ] ], - [ [ 9, 0, 4 ], [ 0, 19, 0 ] ], - [ [ 10, 0, 3 ], [ 0, 19, 1 ] ], - [ [ 10, 0, 2 ], [ 0, 19, 2 ] ], - [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], - [ [ 10, 0, 0 ], [ 0, 20, 0 ] ], - [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], - [ [ 10, 0, 2 ], [ 0, 20, 2 ] ], - [ [ 10, 0, 3 ], [ 0, 21, 1 ] ], - [ [ 10, 0, 4 ], [ 0, 21, 0 ] ], - [ [ 11, 0, 3 ], [ 0, 21, 1 ] ], - [ [ 11, 0, 2 ], [ 0, 21, 2 ] ], - [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], - [ [ 11, 0, 0 ], [ 0, 22, 0 ] ], - [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], - [ [ 11, 0, 2 ], [ 0, 22, 2 ] ], - [ [ 11, 0, 3 ], [ 0, 23, 1 ] ], - [ [ 11, 0, 4 ], [ 0, 23, 0 ] ], - [ [ 12, 0, 4 ], [ 0, 23, 1 ] ], - [ [ 12, 0, 3 ], [ 0, 23, 2 ] ], - [ [ 12, 0, 2 ], [ 1, 23, 1 ] ], - [ [ 12, 0, 1 ], [ 1, 23, 0 ] ], - [ [ 12, 0, 0 ], [ 0, 24, 0 ] ], - [ [ 12, 0, 1 ], [ 0, 24, 1 ] ], - [ [ 12, 0, 2 ], [ 2, 23, 1 ] ], - [ [ 12, 0, 3 ], [ 2, 23, 0 ] ], - [ [ 12, 0, 4 ], [ 0, 25, 0 ] ], - [ [ 13, 0, 3 ], [ 0, 25, 1 ] ], - [ [ 13, 0, 2 ], [ 3, 23, 1 ] ], - [ [ 13, 0, 1 ], [ 3, 23, 0 ] ], - [ [ 13, 0, 0 ], [ 0, 26, 0 ] ], - [ [ 13, 0, 1 ], [ 0, 26, 1 ] ], - [ [ 13, 0, 2 ], [ 0, 26, 2 ] ], - [ [ 13, 0, 3 ], [ 0, 27, 1 ] ], - [ [ 13, 0, 4 ], [ 0, 27, 0 ] ], - [ [ 14, 0, 3 ], [ 0, 27, 1 ] ], - [ [ 14, 0, 2 ], [ 0, 27, 2 ] ], - [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], - [ [ 14, 0, 0 ], [ 0, 28, 0 ] ], - [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], - [ [ 14, 0, 2 ], [ 0, 28, 2 ] ], - [ [ 14, 0, 3 ], [ 0, 29, 1 ] ], - [ [ 14, 0, 4 ], [ 0, 29, 0 ] ], - [ [ 15, 0, 3 ], [ 0, 29, 1 ] ], - [ [ 15, 0, 2 ], [ 0, 29, 2 ] ], - [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], - [ [ 15, 0, 0 ], [ 0, 30, 0 ] ], - [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], - [ [ 15, 0, 2 ], [ 0, 30, 2 ] ], - [ [ 15, 0, 3 ], [ 0, 31, 1 ] ], - [ [ 15, 0, 4 ], [ 0, 31, 0 ] ], - [ [ 16, 0, 4 ], [ 0, 31, 1 ] ], - [ [ 16, 0, 3 ], [ 0, 31, 2 ] ], - [ [ 16, 0, 2 ], [ 1, 31, 1 ] ], - [ [ 16, 0, 1 ], [ 1, 31, 0 ] ], - [ [ 16, 0, 0 ], [ 4, 28, 0 ] ], - [ [ 16, 0, 1 ], [ 4, 28, 1 ] ], - [ [ 16, 0, 2 ], [ 2, 31, 1 ] ], - [ [ 16, 0, 3 ], [ 2, 31, 0 ] ], - [ [ 16, 0, 4 ], [ 4, 29, 0 ] ], - [ [ 17, 0, 3 ], [ 4, 29, 1 ] ], - [ [ 17, 0, 2 ], [ 3, 31, 1 ] ], - [ [ 17, 0, 1 ], [ 3, 31, 0 ] ], - [ [ 17, 0, 0 ], [ 4, 30, 0 ] ], - [ [ 17, 0, 1 ], [ 4, 30, 1 ] ], - [ [ 17, 0, 2 ], [ 4, 30, 2 ] ], - [ [ 17, 0, 3 ], [ 4, 31, 1 ] ], - [ [ 17, 0, 4 ], [ 4, 31, 0 ] ], - [ [ 18, 0, 3 ], [ 4, 31, 1 ] ], - [ [ 18, 0, 2 ], [ 4, 31, 2 ] ], - [ [ 18, 0, 1 ], [ 5, 31, 1 ] ], - [ [ 18, 0, 0 ], [ 5, 31, 0 ] ], - [ [ 18, 0, 1 ], [ 5, 31, 1 ] ], - [ [ 18, 0, 2 ], [ 5, 31, 2 ] ], - [ [ 18, 0, 3 ], [ 6, 31, 1 ] ], - [ [ 18, 0, 4 ], [ 6, 31, 0 ] ], - [ [ 19, 0, 3 ], [ 6, 31, 1 ] ], - [ [ 19, 0, 2 ], [ 6, 31, 2 ] ], - [ [ 19, 0, 1 ], [ 7, 31, 1 ] ], - [ [ 19, 0, 0 ], [ 7, 31, 0 ] ], - [ [ 19, 0, 1 ], [ 7, 31, 1 ] ], - [ [ 19, 0, 2 ], [ 7, 31, 2 ] ], - [ [ 19, 0, 3 ], [ 8, 31, 1 ] ], - [ [ 19, 0, 4 ], [ 8, 31, 0 ] ], - [ [ 20, 0, 4 ], [ 8, 31, 1 ] ], - [ [ 20, 0, 3 ], [ 8, 31, 2 ] ], - [ [ 20, 0, 2 ], [ 9, 31, 1 ] ], - [ [ 20, 0, 1 ], [ 9, 31, 0 ] ], - [ [ 20, 0, 0 ], [ 12, 28, 0 ] ], - [ [ 20, 0, 1 ], [ 12, 28, 1 ] ], - [ [ 20, 0, 2 ], [ 10, 31, 1 ] ], - [ [ 20, 0, 3 ], [ 10, 31, 0 ] ], - [ [ 20, 0, 4 ], [ 12, 29, 0 ] ], - [ [ 21, 0, 3 ], [ 12, 29, 1 ] ], - [ [ 21, 0, 2 ], [ 11, 31, 1 ] ], - [ [ 21, 0, 1 ], [ 11, 31, 0 ] ], - [ [ 21, 0, 0 ], [ 12, 30, 0 ] ], - [ [ 21, 0, 1 ], [ 12, 30, 1 ] ], - [ [ 21, 0, 2 ], [ 12, 30, 2 ] ], - [ [ 21, 0, 3 ], [ 12, 31, 1 ] ], - [ [ 21, 0, 4 ], [ 12, 31, 0 ] ], - [ [ 22, 0, 3 ], [ 12, 31, 1 ] ], - [ [ 22, 0, 2 ], [ 12, 31, 2 ] ], - [ [ 22, 0, 1 ], [ 13, 31, 1 ] ], - [ [ 22, 0, 0 ], [ 13, 31, 0 ] ], - [ [ 22, 0, 1 ], [ 13, 31, 1 ] ], - [ [ 22, 0, 2 ], [ 13, 31, 2 ] ], - [ [ 22, 0, 3 ], [ 14, 31, 1 ] ], - [ [ 22, 0, 4 ], [ 14, 31, 0 ] ], - [ [ 23, 0, 3 ], [ 14, 31, 1 ] ], - [ [ 23, 0, 2 ], [ 14, 31, 2 ] ], - [ [ 23, 0, 1 ], [ 15, 31, 1 ] ], - [ [ 23, 0, 0 ], [ 15, 31, 0 ] ], - [ [ 23, 0, 1 ], [ 15, 31, 1 ] ], - [ [ 23, 0, 2 ], [ 15, 31, 2 ] ], - [ [ 23, 0, 3 ], [ 16, 31, 1 ] ], - [ [ 23, 0, 4 ], [ 16, 31, 0 ] ], - [ [ 24, 0, 4 ], [ 16, 31, 1 ] ], - [ [ 24, 0, 3 ], [ 16, 31, 2 ] ], - [ [ 24, 0, 2 ], [ 17, 31, 1 ] ], - [ [ 24, 0, 1 ], [ 17, 31, 0 ] ], - [ [ 24, 0, 0 ], [ 20, 28, 0 ] ], - [ [ 24, 0, 1 ], [ 20, 28, 1 ] ], - [ [ 24, 0, 2 ], [ 18, 31, 1 ] ], - [ [ 24, 0, 3 ], [ 18, 31, 0 ] ], - [ [ 24, 0, 4 ], [ 20, 29, 0 ] ], - [ [ 25, 0, 3 ], [ 20, 29, 1 ] ], - [ [ 25, 0, 2 ], [ 19, 31, 1 ] ], - [ [ 25, 0, 1 ], [ 19, 31, 0 ] ], - [ [ 25, 0, 0 ], [ 20, 30, 0 ] ], - [ [ 25, 0, 1 ], [ 20, 30, 1 ] ], - [ [ 25, 0, 2 ], [ 20, 30, 2 ] ], - [ [ 25, 0, 3 ], [ 20, 31, 1 ] ], - [ [ 25, 0, 4 ], [ 20, 31, 0 ] ], - [ [ 26, 0, 3 ], [ 20, 31, 1 ] ], - [ [ 26, 0, 2 ], [ 20, 31, 2 ] ], - [ [ 26, 0, 1 ], [ 21, 31, 1 ] ], - [ [ 26, 0, 0 ], [ 21, 31, 0 ] ], - [ [ 26, 0, 1 ], [ 21, 31, 1 ] ], - [ [ 26, 0, 2 ], [ 21, 31, 2 ] ], - [ [ 26, 0, 3 ], [ 22, 31, 1 ] ], - [ [ 26, 0, 4 ], [ 22, 31, 0 ] ], - [ [ 27, 0, 3 ], [ 22, 31, 1 ] ], - [ [ 27, 0, 2 ], [ 22, 31, 2 ] ], - [ [ 27, 0, 1 ], [ 23, 31, 1 ] ], - [ [ 27, 0, 0 ], [ 23, 31, 0 ] ], - [ [ 27, 0, 1 ], [ 23, 31, 1 ] ], - [ [ 27, 0, 2 ], [ 23, 31, 2 ] ], - [ [ 27, 0, 3 ], [ 24, 31, 1 ] ], - [ [ 27, 0, 4 ], [ 24, 31, 0 ] ], - [ [ 28, 0, 4 ], [ 24, 31, 1 ] ], - [ [ 28, 0, 3 ], [ 24, 31, 2 ] ], - [ [ 28, 0, 2 ], [ 25, 31, 1 ] ], - [ [ 28, 0, 1 ], [ 25, 31, 0 ] ], - [ [ 28, 0, 0 ], [ 28, 28, 0 ] ], - [ [ 28, 0, 1 ], [ 28, 28, 1 ] ], - [ [ 28, 0, 2 ], [ 26, 31, 1 ] ], - [ [ 28, 0, 3 ], [ 26, 31, 0 ] ], - [ [ 28, 0, 4 ], [ 28, 29, 0 ] ], - [ [ 29, 0, 3 ], [ 28, 29, 1 ] ], - [ [ 29, 0, 2 ], [ 27, 31, 1 ] ], - [ [ 29, 0, 1 ], [ 27, 31, 0 ] ], - [ [ 29, 0, 0 ], [ 28, 30, 0 ] ], - [ [ 29, 0, 1 ], [ 28, 30, 1 ] ], - [ [ 29, 0, 2 ], [ 28, 30, 2 ] ], - [ [ 29, 0, 3 ], [ 28, 31, 1 ] ], - [ [ 29, 0, 4 ], [ 28, 31, 0 ] ], - [ [ 30, 0, 3 ], [ 28, 31, 1 ] ], - [ [ 30, 0, 2 ], [ 28, 31, 2 ] ], - [ [ 30, 0, 1 ], [ 29, 31, 1 ] ], - [ [ 30, 0, 0 ], [ 29, 31, 0 ] ], - [ [ 30, 0, 1 ], [ 29, 31, 1 ] ], - [ [ 30, 0, 2 ], [ 29, 31, 2 ] ], - [ [ 30, 0, 3 ], [ 30, 31, 1 ] ], - [ [ 30, 0, 4 ], [ 30, 31, 0 ] ], - [ [ 31, 0, 3 ], [ 30, 31, 1 ] ], - [ [ 31, 0, 2 ], [ 30, 31, 2 ] ], - [ [ 31, 0, 1 ], [ 31, 31, 1 ] ], - [ [ 31, 0, 0 ], [ 31, 31, 0 ] ] -]; - -const lookup_6_3 = -[ - [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], - [ [ 0, 0, 1 ], [ 0, 1, 1 ] ], - [ [ 0, 0, 2 ], [ 0, 1, 0 ] ], - [ [ 1, 0, 1 ], [ 0, 2, 1 ] ], - [ [ 1, 0, 0 ], [ 0, 2, 0 ] ], - [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], - [ [ 1, 0, 2 ], [ 0, 3, 0 ] ], - [ [ 2, 0, 1 ], [ 0, 4, 1 ] ], - [ [ 2, 0, 0 ], [ 0, 4, 0 ] ], - [ [ 2, 0, 1 ], [ 0, 5, 1 ] ], - [ [ 2, 0, 2 ], [ 0, 5, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 6, 1 ] ], - [ [ 3, 0, 0 ], [ 0, 6, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 7, 1 ] ], - [ [ 3, 0, 2 ], [ 0, 7, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 8, 1 ] ], - [ [ 4, 0, 0 ], [ 0, 8, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 9, 1 ] ], - [ [ 4, 0, 2 ], [ 0, 9, 0 ] ], - [ [ 5, 0, 1 ], [ 0, 10, 1 ] ], - [ [ 5, 0, 0 ], [ 0, 10, 0 ] ], - [ [ 5, 0, 1 ], [ 0, 11, 1 ] ], - [ [ 5, 0, 2 ], [ 0, 11, 0 ] ], - [ [ 6, 0, 1 ], [ 0, 12, 1 ] ], - [ [ 6, 0, 0 ], [ 0, 12, 0 ] ], - [ [ 6, 0, 1 ], [ 0, 13, 1 ] ], - [ [ 6, 0, 2 ], [ 0, 13, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 14, 1 ] ], - [ [ 7, 0, 0 ], [ 0, 14, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 15, 1 ] ], - [ [ 7, 0, 2 ], [ 0, 15, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 16, 1 ] ], - [ [ 8, 0, 0 ], [ 0, 16, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 17, 1 ] ], - [ [ 8, 0, 2 ], [ 0, 17, 0 ] ], - [ [ 9, 0, 1 ], [ 0, 18, 1 ] ], - [ [ 9, 0, 0 ], [ 0, 18, 0 ] ], - [ [ 9, 0, 1 ], [ 0, 19, 1 ] ], - [ [ 9, 0, 2 ], [ 0, 19, 0 ] ], - [ [ 10, 0, 1 ], [ 0, 20, 1 ] ], - [ [ 10, 0, 0 ], [ 0, 20, 0 ] ], - [ [ 10, 0, 1 ], [ 0, 21, 1 ] ], - [ [ 10, 0, 2 ], [ 0, 21, 0 ] ], - [ [ 11, 0, 1 ], [ 0, 22, 1 ] ], - [ [ 11, 0, 0 ], [ 0, 22, 0 ] ], - [ [ 11, 0, 1 ], [ 0, 23, 1 ] ], - [ [ 11, 0, 2 ], [ 0, 23, 0 ] ], - [ [ 12, 0, 1 ], [ 0, 24, 1 ] ], - [ [ 12, 0, 0 ], [ 0, 24, 0 ] ], - [ [ 12, 0, 1 ], [ 0, 25, 1 ] ], - [ [ 12, 0, 2 ], [ 0, 25, 0 ] ], - [ [ 13, 0, 1 ], [ 0, 26, 1 ] ], - [ [ 13, 0, 0 ], [ 0, 26, 0 ] ], - [ [ 13, 0, 1 ], [ 0, 27, 1 ] ], - [ [ 13, 0, 2 ], [ 0, 27, 0 ] ], - [ [ 14, 0, 1 ], [ 0, 28, 1 ] ], - [ [ 14, 0, 0 ], [ 0, 28, 0 ] ], - [ [ 14, 0, 1 ], [ 0, 29, 1 ] ], - [ [ 14, 0, 2 ], [ 0, 29, 0 ] ], - [ [ 15, 0, 1 ], [ 0, 30, 1 ] ], - [ [ 15, 0, 0 ], [ 0, 30, 0 ] ], - [ [ 15, 0, 1 ], [ 0, 31, 1 ] ], - [ [ 15, 0, 2 ], [ 0, 31, 0 ] ], - [ [ 16, 0, 2 ], [ 1, 31, 1 ] ], - [ [ 16, 0, 1 ], [ 1, 31, 0 ] ], - [ [ 16, 0, 0 ], [ 0, 32, 0 ] ], - [ [ 16, 0, 1 ], [ 2, 31, 0 ] ], - [ [ 16, 0, 2 ], [ 0, 33, 0 ] ], - [ [ 17, 0, 1 ], [ 3, 31, 0 ] ], - [ [ 17, 0, 0 ], [ 0, 34, 0 ] ], - [ [ 17, 0, 1 ], [ 4, 31, 0 ] ], - [ [ 17, 0, 2 ], [ 0, 35, 0 ] ], - [ [ 18, 0, 1 ], [ 5, 31, 0 ] ], - [ [ 18, 0, 0 ], [ 0, 36, 0 ] ], - [ [ 18, 0, 1 ], [ 6, 31, 0 ] ], - [ [ 18, 0, 2 ], [ 0, 37, 0 ] ], - [ [ 19, 0, 1 ], [ 7, 31, 0 ] ], - [ [ 19, 0, 0 ], [ 0, 38, 0 ] ], - [ [ 19, 0, 1 ], [ 8, 31, 0 ] ], - [ [ 19, 0, 2 ], [ 0, 39, 0 ] ], - [ [ 20, 0, 1 ], [ 9, 31, 0 ] ], - [ [ 20, 0, 0 ], [ 0, 40, 0 ] ], - [ [ 20, 0, 1 ], [ 10, 31, 0 ] ], - [ [ 20, 0, 2 ], [ 0, 41, 0 ] ], - [ [ 21, 0, 1 ], [ 11, 31, 0 ] ], - [ [ 21, 0, 0 ], [ 0, 42, 0 ] ], - [ [ 21, 0, 1 ], [ 12, 31, 0 ] ], - [ [ 21, 0, 2 ], [ 0, 43, 0 ] ], - [ [ 22, 0, 1 ], [ 13, 31, 0 ] ], - [ [ 22, 0, 0 ], [ 0, 44, 0 ] ], - [ [ 22, 0, 1 ], [ 14, 31, 0 ] ], - [ [ 22, 0, 2 ], [ 0, 45, 0 ] ], - [ [ 23, 0, 1 ], [ 15, 31, 0 ] ], - [ [ 23, 0, 0 ], [ 0, 46, 0 ] ], - [ [ 23, 0, 1 ], [ 0, 47, 1 ] ], - [ [ 23, 0, 2 ], [ 0, 47, 0 ] ], - [ [ 24, 0, 1 ], [ 0, 48, 1 ] ], - [ [ 24, 0, 0 ], [ 0, 48, 0 ] ], - [ [ 24, 0, 1 ], [ 0, 49, 1 ] ], - [ [ 24, 0, 2 ], [ 0, 49, 0 ] ], - [ [ 25, 0, 1 ], [ 0, 50, 1 ] ], - [ [ 25, 0, 0 ], [ 0, 50, 0 ] ], - [ [ 25, 0, 1 ], [ 0, 51, 1 ] ], - [ [ 25, 0, 2 ], [ 0, 51, 0 ] ], - [ [ 26, 0, 1 ], [ 0, 52, 1 ] ], - [ [ 26, 0, 0 ], [ 0, 52, 0 ] ], - [ [ 26, 0, 1 ], [ 0, 53, 1 ] ], - [ [ 26, 0, 2 ], [ 0, 53, 0 ] ], - [ [ 27, 0, 1 ], [ 0, 54, 1 ] ], - [ [ 27, 0, 0 ], [ 0, 54, 0 ] ], - [ [ 27, 0, 1 ], [ 0, 55, 1 ] ], - [ [ 27, 0, 2 ], [ 0, 55, 0 ] ], - [ [ 28, 0, 1 ], [ 0, 56, 1 ] ], - [ [ 28, 0, 0 ], [ 0, 56, 0 ] ], - [ [ 28, 0, 1 ], [ 0, 57, 1 ] ], - [ [ 28, 0, 2 ], [ 0, 57, 0 ] ], - [ [ 29, 0, 1 ], [ 0, 58, 1 ] ], - [ [ 29, 0, 0 ], [ 0, 58, 0 ] ], - [ [ 29, 0, 1 ], [ 0, 59, 1 ] ], - [ [ 29, 0, 2 ], [ 0, 59, 0 ] ], - [ [ 30, 0, 1 ], [ 0, 60, 1 ] ], - [ [ 30, 0, 0 ], [ 0, 60, 0 ] ], - [ [ 30, 0, 1 ], [ 0, 61, 1 ] ], - [ [ 30, 0, 2 ], [ 0, 61, 0 ] ], - [ [ 31, 0, 1 ], [ 0, 62, 1 ] ], - [ [ 31, 0, 0 ], [ 0, 62, 0 ] ], - [ [ 31, 0, 1 ], [ 0, 63, 1 ] ], - [ [ 31, 0, 2 ], [ 0, 63, 0 ] ], - [ [ 32, 0, 2 ], [ 1, 63, 1 ] ], - [ [ 32, 0, 1 ], [ 1, 63, 0 ] ], - [ [ 32, 0, 0 ], [ 16, 48, 0 ] ], - [ [ 32, 0, 1 ], [ 2, 63, 0 ] ], - [ [ 32, 0, 2 ], [ 16, 49, 0 ] ], - [ [ 33, 0, 1 ], [ 3, 63, 0 ] ], - [ [ 33, 0, 0 ], [ 16, 50, 0 ] ], - [ [ 33, 0, 1 ], [ 4, 63, 0 ] ], - [ [ 33, 0, 2 ], [ 16, 51, 0 ] ], - [ [ 34, 0, 1 ], [ 5, 63, 0 ] ], - [ [ 34, 0, 0 ], [ 16, 52, 0 ] ], - [ [ 34, 0, 1 ], [ 6, 63, 0 ] ], - [ [ 34, 0, 2 ], [ 16, 53, 0 ] ], - [ [ 35, 0, 1 ], [ 7, 63, 0 ] ], - [ [ 35, 0, 0 ], [ 16, 54, 0 ] ], - [ [ 35, 0, 1 ], [ 8, 63, 0 ] ], - [ [ 35, 0, 2 ], [ 16, 55, 0 ] ], - [ [ 36, 0, 1 ], [ 9, 63, 0 ] ], - [ [ 36, 0, 0 ], [ 16, 56, 0 ] ], - [ [ 36, 0, 1 ], [ 10, 63, 0 ] ], - [ [ 36, 0, 2 ], [ 16, 57, 0 ] ], - [ [ 37, 0, 1 ], [ 11, 63, 0 ] ], - [ [ 37, 0, 0 ], [ 16, 58, 0 ] ], - [ [ 37, 0, 1 ], [ 12, 63, 0 ] ], - [ [ 37, 0, 2 ], [ 16, 59, 0 ] ], - [ [ 38, 0, 1 ], [ 13, 63, 0 ] ], - [ [ 38, 0, 0 ], [ 16, 60, 0 ] ], - [ [ 38, 0, 1 ], [ 14, 63, 0 ] ], - [ [ 38, 0, 2 ], [ 16, 61, 0 ] ], - [ [ 39, 0, 1 ], [ 15, 63, 0 ] ], - [ [ 39, 0, 0 ], [ 16, 62, 0 ] ], - [ [ 39, 0, 1 ], [ 16, 63, 1 ] ], - [ [ 39, 0, 2 ], [ 16, 63, 0 ] ], - [ [ 40, 0, 1 ], [ 17, 63, 1 ] ], - [ [ 40, 0, 0 ], [ 17, 63, 0 ] ], - [ [ 40, 0, 1 ], [ 18, 63, 1 ] ], - [ [ 40, 0, 2 ], [ 18, 63, 0 ] ], - [ [ 41, 0, 1 ], [ 19, 63, 1 ] ], - [ [ 41, 0, 0 ], [ 19, 63, 0 ] ], - [ [ 41, 0, 1 ], [ 20, 63, 1 ] ], - [ [ 41, 0, 2 ], [ 20, 63, 0 ] ], - [ [ 42, 0, 1 ], [ 21, 63, 1 ] ], - [ [ 42, 0, 0 ], [ 21, 63, 0 ] ], - [ [ 42, 0, 1 ], [ 22, 63, 1 ] ], - [ [ 42, 0, 2 ], [ 22, 63, 0 ] ], - [ [ 43, 0, 1 ], [ 23, 63, 1 ] ], - [ [ 43, 0, 0 ], [ 23, 63, 0 ] ], - [ [ 43, 0, 1 ], [ 24, 63, 1 ] ], - [ [ 43, 0, 2 ], [ 24, 63, 0 ] ], - [ [ 44, 0, 1 ], [ 25, 63, 1 ] ], - [ [ 44, 0, 0 ], [ 25, 63, 0 ] ], - [ [ 44, 0, 1 ], [ 26, 63, 1 ] ], - [ [ 44, 0, 2 ], [ 26, 63, 0 ] ], - [ [ 45, 0, 1 ], [ 27, 63, 1 ] ], - [ [ 45, 0, 0 ], [ 27, 63, 0 ] ], - [ [ 45, 0, 1 ], [ 28, 63, 1 ] ], - [ [ 45, 0, 2 ], [ 28, 63, 0 ] ], - [ [ 46, 0, 1 ], [ 29, 63, 1 ] ], - [ [ 46, 0, 0 ], [ 29, 63, 0 ] ], - [ [ 46, 0, 1 ], [ 30, 63, 1 ] ], - [ [ 46, 0, 2 ], [ 30, 63, 0 ] ], - [ [ 47, 0, 1 ], [ 31, 63, 1 ] ], - [ [ 47, 0, 0 ], [ 31, 63, 0 ] ], - [ [ 47, 0, 1 ], [ 32, 63, 1 ] ], - [ [ 47, 0, 2 ], [ 32, 63, 0 ] ], - [ [ 48, 0, 2 ], [ 33, 63, 1 ] ], - [ [ 48, 0, 1 ], [ 33, 63, 0 ] ], - [ [ 48, 0, 0 ], [ 48, 48, 0 ] ], - [ [ 48, 0, 1 ], [ 34, 63, 0 ] ], - [ [ 48, 0, 2 ], [ 48, 49, 0 ] ], - [ [ 49, 0, 1 ], [ 35, 63, 0 ] ], - [ [ 49, 0, 0 ], [ 48, 50, 0 ] ], - [ [ 49, 0, 1 ], [ 36, 63, 0 ] ], - [ [ 49, 0, 2 ], [ 48, 51, 0 ] ], - [ [ 50, 0, 1 ], [ 37, 63, 0 ] ], - [ [ 50, 0, 0 ], [ 48, 52, 0 ] ], - [ [ 50, 0, 1 ], [ 38, 63, 0 ] ], - [ [ 50, 0, 2 ], [ 48, 53, 0 ] ], - [ [ 51, 0, 1 ], [ 39, 63, 0 ] ], - [ [ 51, 0, 0 ], [ 48, 54, 0 ] ], - [ [ 51, 0, 1 ], [ 40, 63, 0 ] ], - [ [ 51, 0, 2 ], [ 48, 55, 0 ] ], - [ [ 52, 0, 1 ], [ 41, 63, 0 ] ], - [ [ 52, 0, 0 ], [ 48, 56, 0 ] ], - [ [ 52, 0, 1 ], [ 42, 63, 0 ] ], - [ [ 52, 0, 2 ], [ 48, 57, 0 ] ], - [ [ 53, 0, 1 ], [ 43, 63, 0 ] ], - [ [ 53, 0, 0 ], [ 48, 58, 0 ] ], - [ [ 53, 0, 1 ], [ 44, 63, 0 ] ], - [ [ 53, 0, 2 ], [ 48, 59, 0 ] ], - [ [ 54, 0, 1 ], [ 45, 63, 0 ] ], - [ [ 54, 0, 0 ], [ 48, 60, 0 ] ], - [ [ 54, 0, 1 ], [ 46, 63, 0 ] ], - [ [ 54, 0, 2 ], [ 48, 61, 0 ] ], - [ [ 55, 0, 1 ], [ 47, 63, 0 ] ], - [ [ 55, 0, 0 ], [ 48, 62, 0 ] ], - [ [ 55, 0, 1 ], [ 48, 63, 1 ] ], - [ [ 55, 0, 2 ], [ 48, 63, 0 ] ], - [ [ 56, 0, 1 ], [ 49, 63, 1 ] ], - [ [ 56, 0, 0 ], [ 49, 63, 0 ] ], - [ [ 56, 0, 1 ], [ 50, 63, 1 ] ], - [ [ 56, 0, 2 ], [ 50, 63, 0 ] ], - [ [ 57, 0, 1 ], [ 51, 63, 1 ] ], - [ [ 57, 0, 0 ], [ 51, 63, 0 ] ], - [ [ 57, 0, 1 ], [ 52, 63, 1 ] ], - [ [ 57, 0, 2 ], [ 52, 63, 0 ] ], - [ [ 58, 0, 1 ], [ 53, 63, 1 ] ], - [ [ 58, 0, 0 ], [ 53, 63, 0 ] ], - [ [ 58, 0, 1 ], [ 54, 63, 1 ] ], - [ [ 58, 0, 2 ], [ 54, 63, 0 ] ], - [ [ 59, 0, 1 ], [ 55, 63, 1 ] ], - [ [ 59, 0, 0 ], [ 55, 63, 0 ] ], - [ [ 59, 0, 1 ], [ 56, 63, 1 ] ], - [ [ 59, 0, 2 ], [ 56, 63, 0 ] ], - [ [ 60, 0, 1 ], [ 57, 63, 1 ] ], - [ [ 60, 0, 0 ], [ 57, 63, 0 ] ], - [ [ 60, 0, 1 ], [ 58, 63, 1 ] ], - [ [ 60, 0, 2 ], [ 58, 63, 0 ] ], - [ [ 61, 0, 1 ], [ 59, 63, 1 ] ], - [ [ 61, 0, 0 ], [ 59, 63, 0 ] ], - [ [ 61, 0, 1 ], [ 60, 63, 1 ] ], - [ [ 61, 0, 2 ], [ 60, 63, 0 ] ], - [ [ 62, 0, 1 ], [ 61, 63, 1 ] ], - [ [ 62, 0, 0 ], [ 61, 63, 0 ] ], - [ [ 62, 0, 1 ], [ 62, 63, 1 ] ], - [ [ 62, 0, 2 ], [ 62, 63, 0 ] ], - [ [ 63, 0, 1 ], [ 63, 63, 1 ] ], - [ [ 63, 0, 0 ], [ 63, 63, 0 ] ] -]; - -const lookup_5_4 = -[ - [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], - [ [ 0, 0, 1 ], [ 0, 1, 1 ] ], - [ [ 0, 0, 2 ], [ 0, 1, 0 ] ], - [ [ 0, 0, 3 ], [ 0, 1, 1 ] ], - [ [ 0, 0, 4 ], [ 0, 2, 1 ] ], - [ [ 1, 0, 3 ], [ 0, 2, 0 ] ], - [ [ 1, 0, 2 ], [ 0, 2, 1 ] ], - [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], - [ [ 1, 0, 0 ], [ 0, 3, 0 ] ], - [ [ 1, 0, 1 ], [ 1, 2, 1 ] ], - [ [ 1, 0, 2 ], [ 1, 2, 0 ] ], - [ [ 1, 0, 3 ], [ 0, 4, 0 ] ], - [ [ 1, 0, 4 ], [ 0, 5, 1 ] ], - [ [ 2, 0, 3 ], [ 0, 5, 0 ] ], - [ [ 2, 0, 2 ], [ 0, 5, 1 ] ], - [ [ 2, 0, 1 ], [ 0, 6, 1 ] ], - [ [ 2, 0, 0 ], [ 0, 6, 0 ] ], - [ [ 2, 0, 1 ], [ 2, 3, 1 ] ], - [ [ 2, 0, 2 ], [ 2, 3, 0 ] ], - [ [ 2, 0, 3 ], [ 0, 7, 0 ] ], - [ [ 2, 0, 4 ], [ 1, 6, 1 ] ], - [ [ 3, 0, 3 ], [ 1, 6, 0 ] ], - [ [ 3, 0, 2 ], [ 0, 8, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], - [ [ 3, 0, 0 ], [ 0, 9, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], - [ [ 3, 0, 2 ], [ 0, 10, 1 ] ], - [ [ 3, 0, 3 ], [ 0, 10, 0 ] ], - [ [ 3, 0, 4 ], [ 2, 7, 1 ] ], - [ [ 4, 0, 4 ], [ 2, 7, 0 ] ], - [ [ 4, 0, 3 ], [ 0, 11, 0 ] ], - [ [ 4, 0, 2 ], [ 1, 10, 1 ] ], - [ [ 4, 0, 1 ], [ 1, 10, 0 ] ], - [ [ 4, 0, 0 ], [ 0, 12, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 13, 1 ] ], - [ [ 4, 0, 2 ], [ 0, 13, 0 ] ], - [ [ 4, 0, 3 ], [ 0, 13, 1 ] ], - [ [ 4, 0, 4 ], [ 0, 14, 1 ] ], - [ [ 5, 0, 3 ], [ 0, 14, 0 ] ], - [ [ 5, 0, 2 ], [ 2, 11, 1 ] ], - [ [ 5, 0, 1 ], [ 2, 11, 0 ] ], - [ [ 5, 0, 0 ], [ 0, 15, 0 ] ], - [ [ 5, 0, 1 ], [ 1, 14, 1 ] ], - [ [ 5, 0, 2 ], [ 1, 14, 0 ] ], - [ [ 5, 0, 3 ], [ 0, 16, 0 ] ], - [ [ 5, 0, 4 ], [ 0, 17, 1 ] ], - [ [ 6, 0, 3 ], [ 0, 17, 0 ] ], - [ [ 6, 0, 2 ], [ 0, 17, 1 ] ], - [ [ 6, 0, 1 ], [ 0, 18, 1 ] ], - [ [ 6, 0, 0 ], [ 0, 18, 0 ] ], - [ [ 6, 0, 1 ], [ 2, 15, 1 ] ], - [ [ 6, 0, 2 ], [ 2, 15, 0 ] ], - [ [ 6, 0, 3 ], [ 0, 19, 0 ] ], - [ [ 6, 0, 4 ], [ 1, 18, 1 ] ], - [ [ 7, 0, 3 ], [ 1, 18, 0 ] ], - [ [ 7, 0, 2 ], [ 0, 20, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 21, 1 ] ], - [ [ 7, 0, 0 ], [ 0, 21, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 21, 1 ] ], - [ [ 7, 0, 2 ], [ 0, 22, 1 ] ], - [ [ 7, 0, 3 ], [ 0, 22, 0 ] ], - [ [ 7, 0, 4 ], [ 2, 19, 1 ] ], - [ [ 8, 0, 4 ], [ 2, 19, 0 ] ], - [ [ 8, 0, 3 ], [ 0, 23, 0 ] ], - [ [ 8, 0, 2 ], [ 1, 22, 1 ] ], - [ [ 8, 0, 1 ], [ 1, 22, 0 ] ], - [ [ 8, 0, 0 ], [ 0, 24, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 25, 1 ] ], - [ [ 8, 0, 2 ], [ 0, 25, 0 ] ], - [ [ 8, 0, 3 ], [ 0, 25, 1 ] ], - [ [ 8, 0, 4 ], [ 0, 26, 1 ] ], - [ [ 9, 0, 3 ], [ 0, 26, 0 ] ], - [ [ 9, 0, 2 ], [ 2, 23, 1 ] ], - [ [ 9, 0, 1 ], [ 2, 23, 0 ] ], - [ [ 9, 0, 0 ], [ 0, 27, 0 ] ], - [ [ 9, 0, 1 ], [ 1, 26, 1 ] ], - [ [ 9, 0, 2 ], [ 1, 26, 0 ] ], - [ [ 9, 0, 3 ], [ 0, 28, 0 ] ], - [ [ 9, 0, 4 ], [ 0, 29, 1 ] ], - [ [ 10, 0, 3 ], [ 0, 29, 0 ] ], - [ [ 10, 0, 2 ], [ 0, 29, 1 ] ], - [ [ 10, 0, 1 ], [ 0, 30, 1 ] ], - [ [ 10, 0, 0 ], [ 0, 30, 0 ] ], - [ [ 10, 0, 1 ], [ 2, 27, 1 ] ], - [ [ 10, 0, 2 ], [ 2, 27, 0 ] ], - [ [ 10, 0, 3 ], [ 0, 31, 0 ] ], - [ [ 10, 0, 4 ], [ 1, 30, 1 ] ], - [ [ 11, 0, 3 ], [ 1, 30, 0 ] ], - [ [ 11, 0, 2 ], [ 4, 24, 0 ] ], - [ [ 11, 0, 1 ], [ 1, 31, 1 ] ], - [ [ 11, 0, 0 ], [ 1, 31, 0 ] ], - [ [ 11, 0, 1 ], [ 1, 31, 1 ] ], - [ [ 11, 0, 2 ], [ 2, 30, 1 ] ], - [ [ 11, 0, 3 ], [ 2, 30, 0 ] ], - [ [ 11, 0, 4 ], [ 2, 31, 1 ] ], - [ [ 12, 0, 4 ], [ 2, 31, 0 ] ], - [ [ 12, 0, 3 ], [ 4, 27, 0 ] ], - [ [ 12, 0, 2 ], [ 3, 30, 1 ] ], - [ [ 12, 0, 1 ], [ 3, 30, 0 ] ], - [ [ 12, 0, 0 ], [ 4, 28, 0 ] ], - [ [ 12, 0, 1 ], [ 3, 31, 1 ] ], - [ [ 12, 0, 2 ], [ 3, 31, 0 ] ], - [ [ 12, 0, 3 ], [ 3, 31, 1 ] ], - [ [ 12, 0, 4 ], [ 4, 30, 1 ] ], - [ [ 13, 0, 3 ], [ 4, 30, 0 ] ], - [ [ 13, 0, 2 ], [ 6, 27, 1 ] ], - [ [ 13, 0, 1 ], [ 6, 27, 0 ] ], - [ [ 13, 0, 0 ], [ 4, 31, 0 ] ], - [ [ 13, 0, 1 ], [ 5, 30, 1 ] ], - [ [ 13, 0, 2 ], [ 5, 30, 0 ] ], - [ [ 13, 0, 3 ], [ 8, 24, 0 ] ], - [ [ 13, 0, 4 ], [ 5, 31, 1 ] ], - [ [ 14, 0, 3 ], [ 5, 31, 0 ] ], - [ [ 14, 0, 2 ], [ 5, 31, 1 ] ], - [ [ 14, 0, 1 ], [ 6, 30, 1 ] ], - [ [ 14, 0, 0 ], [ 6, 30, 0 ] ], - [ [ 14, 0, 1 ], [ 6, 31, 1 ] ], - [ [ 14, 0, 2 ], [ 6, 31, 0 ] ], - [ [ 14, 0, 3 ], [ 8, 27, 0 ] ], - [ [ 14, 0, 4 ], [ 7, 30, 1 ] ], - [ [ 15, 0, 3 ], [ 7, 30, 0 ] ], - [ [ 15, 0, 2 ], [ 8, 28, 0 ] ], - [ [ 15, 0, 1 ], [ 7, 31, 1 ] ], - [ [ 15, 0, 0 ], [ 7, 31, 0 ] ], - [ [ 15, 0, 1 ], [ 7, 31, 1 ] ], - [ [ 15, 0, 2 ], [ 8, 30, 1 ] ], - [ [ 15, 0, 3 ], [ 8, 30, 0 ] ], - [ [ 15, 0, 4 ], [ 10, 27, 1 ] ], - [ [ 16, 0, 4 ], [ 10, 27, 0 ] ], - [ [ 16, 0, 3 ], [ 8, 31, 0 ] ], - [ [ 16, 0, 2 ], [ 9, 30, 1 ] ], - [ [ 16, 0, 1 ], [ 9, 30, 0 ] ], - [ [ 16, 0, 0 ], [ 12, 24, 0 ] ], - [ [ 16, 0, 1 ], [ 9, 31, 1 ] ], - [ [ 16, 0, 2 ], [ 9, 31, 0 ] ], - [ [ 16, 0, 3 ], [ 9, 31, 1 ] ], - [ [ 16, 0, 4 ], [ 10, 30, 1 ] ], - [ [ 17, 0, 3 ], [ 10, 30, 0 ] ], - [ [ 17, 0, 2 ], [ 10, 31, 1 ] ], - [ [ 17, 0, 1 ], [ 10, 31, 0 ] ], - [ [ 17, 0, 0 ], [ 12, 27, 0 ] ], - [ [ 17, 0, 1 ], [ 11, 30, 1 ] ], - [ [ 17, 0, 2 ], [ 11, 30, 0 ] ], - [ [ 17, 0, 3 ], [ 12, 28, 0 ] ], - [ [ 17, 0, 4 ], [ 11, 31, 1 ] ], - [ [ 18, 0, 3 ], [ 11, 31, 0 ] ], - [ [ 18, 0, 2 ], [ 11, 31, 1 ] ], - [ [ 18, 0, 1 ], [ 12, 30, 1 ] ], - [ [ 18, 0, 0 ], [ 12, 30, 0 ] ], - [ [ 18, 0, 1 ], [ 14, 27, 1 ] ], - [ [ 18, 0, 2 ], [ 14, 27, 0 ] ], - [ [ 18, 0, 3 ], [ 12, 31, 0 ] ], - [ [ 18, 0, 4 ], [ 13, 30, 1 ] ], - [ [ 19, 0, 3 ], [ 13, 30, 0 ] ], - [ [ 19, 0, 2 ], [ 16, 24, 0 ] ], - [ [ 19, 0, 1 ], [ 13, 31, 1 ] ], - [ [ 19, 0, 0 ], [ 13, 31, 0 ] ], - [ [ 19, 0, 1 ], [ 13, 31, 1 ] ], - [ [ 19, 0, 2 ], [ 14, 30, 1 ] ], - [ [ 19, 0, 3 ], [ 14, 30, 0 ] ], - [ [ 19, 0, 4 ], [ 14, 31, 1 ] ], - [ [ 20, 0, 4 ], [ 14, 31, 0 ] ], - [ [ 20, 0, 3 ], [ 16, 27, 0 ] ], - [ [ 20, 0, 2 ], [ 15, 30, 1 ] ], - [ [ 20, 0, 1 ], [ 15, 30, 0 ] ], - [ [ 20, 0, 0 ], [ 16, 28, 0 ] ], - [ [ 20, 0, 1 ], [ 15, 31, 1 ] ], - [ [ 20, 0, 2 ], [ 15, 31, 0 ] ], - [ [ 20, 0, 3 ], [ 15, 31, 1 ] ], - [ [ 20, 0, 4 ], [ 16, 30, 1 ] ], - [ [ 21, 0, 3 ], [ 16, 30, 0 ] ], - [ [ 21, 0, 2 ], [ 18, 27, 1 ] ], - [ [ 21, 0, 1 ], [ 18, 27, 0 ] ], - [ [ 21, 0, 0 ], [ 16, 31, 0 ] ], - [ [ 21, 0, 1 ], [ 17, 30, 1 ] ], - [ [ 21, 0, 2 ], [ 17, 30, 0 ] ], - [ [ 21, 0, 3 ], [ 20, 24, 0 ] ], - [ [ 21, 0, 4 ], [ 17, 31, 1 ] ], - [ [ 22, 0, 3 ], [ 17, 31, 0 ] ], - [ [ 22, 0, 2 ], [ 17, 31, 1 ] ], - [ [ 22, 0, 1 ], [ 18, 30, 1 ] ], - [ [ 22, 0, 0 ], [ 18, 30, 0 ] ], - [ [ 22, 0, 1 ], [ 18, 31, 1 ] ], - [ [ 22, 0, 2 ], [ 18, 31, 0 ] ], - [ [ 22, 0, 3 ], [ 20, 27, 0 ] ], - [ [ 22, 0, 4 ], [ 19, 30, 1 ] ], - [ [ 23, 0, 3 ], [ 19, 30, 0 ] ], - [ [ 23, 0, 2 ], [ 20, 28, 0 ] ], - [ [ 23, 0, 1 ], [ 19, 31, 1 ] ], - [ [ 23, 0, 0 ], [ 19, 31, 0 ] ], - [ [ 23, 0, 1 ], [ 19, 31, 1 ] ], - [ [ 23, 0, 2 ], [ 20, 30, 1 ] ], - [ [ 23, 0, 3 ], [ 20, 30, 0 ] ], - [ [ 23, 0, 4 ], [ 22, 27, 1 ] ], - [ [ 24, 0, 4 ], [ 22, 27, 0 ] ], - [ [ 24, 0, 3 ], [ 20, 31, 0 ] ], - [ [ 24, 0, 2 ], [ 21, 30, 1 ] ], - [ [ 24, 0, 1 ], [ 21, 30, 0 ] ], - [ [ 24, 0, 0 ], [ 24, 24, 0 ] ], - [ [ 24, 0, 1 ], [ 21, 31, 1 ] ], - [ [ 24, 0, 2 ], [ 21, 31, 0 ] ], - [ [ 24, 0, 3 ], [ 21, 31, 1 ] ], - [ [ 24, 0, 4 ], [ 22, 30, 1 ] ], - [ [ 25, 0, 3 ], [ 22, 30, 0 ] ], - [ [ 25, 0, 2 ], [ 22, 31, 1 ] ], - [ [ 25, 0, 1 ], [ 22, 31, 0 ] ], - [ [ 25, 0, 0 ], [ 24, 27, 0 ] ], - [ [ 25, 0, 1 ], [ 23, 30, 1 ] ], - [ [ 25, 0, 2 ], [ 23, 30, 0 ] ], - [ [ 25, 0, 3 ], [ 24, 28, 0 ] ], - [ [ 25, 0, 4 ], [ 23, 31, 1 ] ], - [ [ 26, 0, 3 ], [ 23, 31, 0 ] ], - [ [ 26, 0, 2 ], [ 23, 31, 1 ] ], - [ [ 26, 0, 1 ], [ 24, 30, 1 ] ], - [ [ 26, 0, 0 ], [ 24, 30, 0 ] ], - [ [ 26, 0, 1 ], [ 26, 27, 1 ] ], - [ [ 26, 0, 2 ], [ 26, 27, 0 ] ], - [ [ 26, 0, 3 ], [ 24, 31, 0 ] ], - [ [ 26, 0, 4 ], [ 25, 30, 1 ] ], - [ [ 27, 0, 3 ], [ 25, 30, 0 ] ], - [ [ 27, 0, 2 ], [ 28, 24, 0 ] ], - [ [ 27, 0, 1 ], [ 25, 31, 1 ] ], - [ [ 27, 0, 0 ], [ 25, 31, 0 ] ], - [ [ 27, 0, 1 ], [ 25, 31, 1 ] ], - [ [ 27, 0, 2 ], [ 26, 30, 1 ] ], - [ [ 27, 0, 3 ], [ 26, 30, 0 ] ], - [ [ 27, 0, 4 ], [ 26, 31, 1 ] ], - [ [ 28, 0, 4 ], [ 26, 31, 0 ] ], - [ [ 28, 0, 3 ], [ 28, 27, 0 ] ], - [ [ 28, 0, 2 ], [ 27, 30, 1 ] ], - [ [ 28, 0, 1 ], [ 27, 30, 0 ] ], - [ [ 28, 0, 0 ], [ 28, 28, 0 ] ], - [ [ 28, 0, 1 ], [ 27, 31, 1 ] ], - [ [ 28, 0, 2 ], [ 27, 31, 0 ] ], - [ [ 28, 0, 3 ], [ 27, 31, 1 ] ], - [ [ 28, 0, 4 ], [ 28, 30, 1 ] ], - [ [ 29, 0, 3 ], [ 28, 30, 0 ] ], - [ [ 29, 0, 2 ], [ 30, 27, 1 ] ], - [ [ 29, 0, 1 ], [ 30, 27, 0 ] ], - [ [ 29, 0, 0 ], [ 28, 31, 0 ] ], - [ [ 29, 0, 1 ], [ 29, 30, 1 ] ], - [ [ 29, 0, 2 ], [ 29, 30, 0 ] ], - [ [ 29, 0, 3 ], [ 29, 30, 1 ] ], - [ [ 29, 0, 4 ], [ 29, 31, 1 ] ], - [ [ 30, 0, 3 ], [ 29, 31, 0 ] ], - [ [ 30, 0, 2 ], [ 29, 31, 1 ] ], - [ [ 30, 0, 1 ], [ 30, 30, 1 ] ], - [ [ 30, 0, 0 ], [ 30, 30, 0 ] ], - [ [ 30, 0, 1 ], [ 30, 31, 1 ] ], - [ [ 30, 0, 2 ], [ 30, 31, 0 ] ], - [ [ 30, 0, 3 ], [ 30, 31, 1 ] ], - [ [ 30, 0, 4 ], [ 31, 30, 1 ] ], - [ [ 31, 0, 3 ], [ 31, 30, 0 ] ], - [ [ 31, 0, 2 ], [ 31, 30, 1 ] ], - [ [ 31, 0, 1 ], [ 31, 31, 1 ] ], - [ [ 31, 0, 0 ], [ 31, 31, 0 ] ] -]; - -const lookup_6_4 = -[ - [ [ 0, 0, 0 ], [ 0, 0, 0 ] ], - [ [ 0, 0, 1 ], [ 0, 1, 0 ] ], - [ [ 0, 0, 2 ], [ 0, 2, 0 ] ], - [ [ 1, 0, 1 ], [ 0, 3, 1 ] ], - [ [ 1, 0, 0 ], [ 0, 3, 0 ] ], - [ [ 1, 0, 1 ], [ 0, 4, 0 ] ], - [ [ 1, 0, 2 ], [ 0, 5, 0 ] ], - [ [ 2, 0, 1 ], [ 0, 6, 1 ] ], - [ [ 2, 0, 0 ], [ 0, 6, 0 ] ], - [ [ 2, 0, 1 ], [ 0, 7, 0 ] ], - [ [ 2, 0, 2 ], [ 0, 8, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 9, 1 ] ], - [ [ 3, 0, 0 ], [ 0, 9, 0 ] ], - [ [ 3, 0, 1 ], [ 0, 10, 0 ] ], - [ [ 3, 0, 2 ], [ 0, 11, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 12, 1 ] ], - [ [ 4, 0, 0 ], [ 0, 12, 0 ] ], - [ [ 4, 0, 1 ], [ 0, 13, 0 ] ], - [ [ 4, 0, 2 ], [ 0, 14, 0 ] ], - [ [ 5, 0, 1 ], [ 0, 15, 1 ] ], - [ [ 5, 0, 0 ], [ 0, 15, 0 ] ], - [ [ 5, 0, 1 ], [ 0, 16, 0 ] ], - [ [ 5, 0, 2 ], [ 1, 15, 0 ] ], - [ [ 6, 0, 1 ], [ 0, 17, 0 ] ], - [ [ 6, 0, 0 ], [ 0, 18, 0 ] ], - [ [ 6, 0, 1 ], [ 0, 19, 0 ] ], - [ [ 6, 0, 2 ], [ 3, 14, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 20, 0 ] ], - [ [ 7, 0, 0 ], [ 0, 21, 0 ] ], - [ [ 7, 0, 1 ], [ 0, 22, 0 ] ], - [ [ 7, 0, 2 ], [ 4, 15, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 23, 0 ] ], - [ [ 8, 0, 0 ], [ 0, 24, 0 ] ], - [ [ 8, 0, 1 ], [ 0, 25, 0 ] ], - [ [ 8, 0, 2 ], [ 6, 14, 0 ] ], - [ [ 9, 0, 1 ], [ 0, 26, 0 ] ], - [ [ 9, 0, 0 ], [ 0, 27, 0 ] ], - [ [ 9, 0, 1 ], [ 0, 28, 0 ] ], - [ [ 9, 0, 2 ], [ 7, 15, 0 ] ], - [ [ 10, 0, 1 ], [ 0, 29, 0 ] ], - [ [ 10, 0, 0 ], [ 0, 30, 0 ] ], - [ [ 10, 0, 1 ], [ 0, 31, 0 ] ], - [ [ 10, 0, 2 ], [ 9, 14, 0 ] ], - [ [ 11, 0, 1 ], [ 0, 32, 0 ] ], - [ [ 11, 0, 0 ], [ 0, 33, 0 ] ], - [ [ 11, 0, 1 ], [ 2, 30, 0 ] ], - [ [ 11, 0, 2 ], [ 0, 34, 0 ] ], - [ [ 12, 0, 1 ], [ 0, 35, 0 ] ], - [ [ 12, 0, 0 ], [ 0, 36, 0 ] ], - [ [ 12, 0, 1 ], [ 3, 31, 0 ] ], - [ [ 12, 0, 2 ], [ 0, 37, 0 ] ], - [ [ 13, 0, 1 ], [ 0, 38, 0 ] ], - [ [ 13, 0, 0 ], [ 0, 39, 0 ] ], - [ [ 13, 0, 1 ], [ 5, 30, 0 ] ], - [ [ 13, 0, 2 ], [ 0, 40, 0 ] ], - [ [ 14, 0, 1 ], [ 0, 41, 0 ] ], - [ [ 14, 0, 0 ], [ 0, 42, 0 ] ], - [ [ 14, 0, 1 ], [ 6, 31, 0 ] ], - [ [ 14, 0, 2 ], [ 0, 43, 0 ] ], - [ [ 15, 0, 1 ], [ 0, 44, 0 ] ], - [ [ 15, 0, 0 ], [ 0, 45, 0 ] ], - [ [ 15, 0, 1 ], [ 8, 30, 0 ] ], - [ [ 15, 0, 2 ], [ 0, 46, 0 ] ], - [ [ 16, 0, 2 ], [ 0, 47, 0 ] ], - [ [ 16, 0, 1 ], [ 1, 46, 0 ] ], - [ [ 16, 0, 0 ], [ 0, 48, 0 ] ], - [ [ 16, 0, 1 ], [ 0, 49, 0 ] ], - [ [ 16, 0, 2 ], [ 0, 50, 0 ] ], - [ [ 17, 0, 1 ], [ 2, 47, 0 ] ], - [ [ 17, 0, 0 ], [ 0, 51, 0 ] ], - [ [ 17, 0, 1 ], [ 0, 52, 0 ] ], - [ [ 17, 0, 2 ], [ 0, 53, 0 ] ], - [ [ 18, 0, 1 ], [ 4, 46, 0 ] ], - [ [ 18, 0, 0 ], [ 0, 54, 0 ] ], - [ [ 18, 0, 1 ], [ 0, 55, 0 ] ], - [ [ 18, 0, 2 ], [ 0, 56, 0 ] ], - [ [ 19, 0, 1 ], [ 5, 47, 0 ] ], - [ [ 19, 0, 0 ], [ 0, 57, 0 ] ], - [ [ 19, 0, 1 ], [ 0, 58, 0 ] ], - [ [ 19, 0, 2 ], [ 0, 59, 0 ] ], - [ [ 20, 0, 1 ], [ 7, 46, 0 ] ], - [ [ 20, 0, 0 ], [ 0, 60, 0 ] ], - [ [ 20, 0, 1 ], [ 0, 61, 0 ] ], - [ [ 20, 0, 2 ], [ 0, 62, 0 ] ], - [ [ 21, 0, 1 ], [ 8, 47, 0 ] ], - [ [ 21, 0, 0 ], [ 0, 63, 0 ] ], - [ [ 21, 0, 1 ], [ 1, 62, 0 ] ], - [ [ 21, 0, 2 ], [ 1, 63, 0 ] ], - [ [ 22, 0, 1 ], [ 10, 46, 0 ] ], - [ [ 22, 0, 0 ], [ 2, 62, 0 ] ], - [ [ 22, 0, 1 ], [ 2, 63, 0 ] ], - [ [ 22, 0, 2 ], [ 3, 62, 0 ] ], - [ [ 23, 0, 1 ], [ 11, 47, 0 ] ], - [ [ 23, 0, 0 ], [ 3, 63, 0 ] ], - [ [ 23, 0, 1 ], [ 4, 62, 0 ] ], - [ [ 23, 0, 2 ], [ 4, 63, 0 ] ], - [ [ 24, 0, 1 ], [ 13, 46, 0 ] ], - [ [ 24, 0, 0 ], [ 5, 62, 0 ] ], - [ [ 24, 0, 1 ], [ 5, 63, 0 ] ], - [ [ 24, 0, 2 ], [ 6, 62, 0 ] ], - [ [ 25, 0, 1 ], [ 14, 47, 0 ] ], - [ [ 25, 0, 0 ], [ 6, 63, 0 ] ], - [ [ 25, 0, 1 ], [ 7, 62, 0 ] ], - [ [ 25, 0, 2 ], [ 7, 63, 0 ] ], - [ [ 26, 0, 1 ], [ 16, 45, 0 ] ], - [ [ 26, 0, 0 ], [ 8, 62, 0 ] ], - [ [ 26, 0, 1 ], [ 8, 63, 0 ] ], - [ [ 26, 0, 2 ], [ 9, 62, 0 ] ], - [ [ 27, 0, 1 ], [ 16, 48, 0 ] ], - [ [ 27, 0, 0 ], [ 9, 63, 0 ] ], - [ [ 27, 0, 1 ], [ 10, 62, 0 ] ], - [ [ 27, 0, 2 ], [ 10, 63, 0 ] ], - [ [ 28, 0, 1 ], [ 16, 51, 0 ] ], - [ [ 28, 0, 0 ], [ 11, 62, 0 ] ], - [ [ 28, 0, 1 ], [ 11, 63, 0 ] ], - [ [ 28, 0, 2 ], [ 12, 62, 0 ] ], - [ [ 29, 0, 1 ], [ 16, 54, 0 ] ], - [ [ 29, 0, 0 ], [ 12, 63, 0 ] ], - [ [ 29, 0, 1 ], [ 13, 62, 0 ] ], - [ [ 29, 0, 2 ], [ 13, 63, 0 ] ], - [ [ 30, 0, 1 ], [ 16, 57, 0 ] ], - [ [ 30, 0, 0 ], [ 14, 62, 0 ] ], - [ [ 30, 0, 1 ], [ 14, 63, 0 ] ], - [ [ 30, 0, 2 ], [ 15, 62, 0 ] ], - [ [ 31, 0, 1 ], [ 16, 60, 0 ] ], - [ [ 31, 0, 0 ], [ 15, 63, 0 ] ], - [ [ 31, 0, 1 ], [ 24, 46, 0 ] ], - [ [ 31, 0, 2 ], [ 16, 62, 0 ] ], - [ [ 32, 0, 2 ], [ 16, 63, 0 ] ], - [ [ 32, 0, 1 ], [ 17, 62, 0 ] ], - [ [ 32, 0, 0 ], [ 25, 47, 0 ] ], - [ [ 32, 0, 1 ], [ 17, 63, 0 ] ], - [ [ 32, 0, 2 ], [ 18, 62, 0 ] ], - [ [ 33, 0, 1 ], [ 18, 63, 0 ] ], - [ [ 33, 0, 0 ], [ 27, 46, 0 ] ], - [ [ 33, 0, 1 ], [ 19, 62, 0 ] ], - [ [ 33, 0, 2 ], [ 19, 63, 0 ] ], - [ [ 34, 0, 1 ], [ 20, 62, 0 ] ], - [ [ 34, 0, 0 ], [ 28, 47, 0 ] ], - [ [ 34, 0, 1 ], [ 20, 63, 0 ] ], - [ [ 34, 0, 2 ], [ 21, 62, 0 ] ], - [ [ 35, 0, 1 ], [ 21, 63, 0 ] ], - [ [ 35, 0, 0 ], [ 30, 46, 0 ] ], - [ [ 35, 0, 1 ], [ 22, 62, 0 ] ], - [ [ 35, 0, 2 ], [ 22, 63, 0 ] ], - [ [ 36, 0, 1 ], [ 23, 62, 0 ] ], - [ [ 36, 0, 0 ], [ 31, 47, 0 ] ], - [ [ 36, 0, 1 ], [ 23, 63, 0 ] ], - [ [ 36, 0, 2 ], [ 24, 62, 0 ] ], - [ [ 37, 0, 1 ], [ 24, 63, 0 ] ], - [ [ 37, 0, 0 ], [ 32, 47, 0 ] ], - [ [ 37, 0, 1 ], [ 25, 62, 0 ] ], - [ [ 37, 0, 2 ], [ 25, 63, 0 ] ], - [ [ 38, 0, 1 ], [ 26, 62, 0 ] ], - [ [ 38, 0, 0 ], [ 32, 50, 0 ] ], - [ [ 38, 0, 1 ], [ 26, 63, 0 ] ], - [ [ 38, 0, 2 ], [ 27, 62, 0 ] ], - [ [ 39, 0, 1 ], [ 27, 63, 0 ] ], - [ [ 39, 0, 0 ], [ 32, 53, 0 ] ], - [ [ 39, 0, 1 ], [ 28, 62, 0 ] ], - [ [ 39, 0, 2 ], [ 28, 63, 0 ] ], - [ [ 40, 0, 1 ], [ 29, 62, 0 ] ], - [ [ 40, 0, 0 ], [ 32, 56, 0 ] ], - [ [ 40, 0, 1 ], [ 29, 63, 0 ] ], - [ [ 40, 0, 2 ], [ 30, 62, 0 ] ], - [ [ 41, 0, 1 ], [ 30, 63, 0 ] ], - [ [ 41, 0, 0 ], [ 32, 59, 0 ] ], - [ [ 41, 0, 1 ], [ 31, 62, 0 ] ], - [ [ 41, 0, 2 ], [ 31, 63, 0 ] ], - [ [ 42, 0, 1 ], [ 32, 61, 0 ] ], - [ [ 42, 0, 0 ], [ 32, 62, 0 ] ], - [ [ 42, 0, 1 ], [ 32, 63, 0 ] ], - [ [ 42, 0, 2 ], [ 41, 46, 0 ] ], - [ [ 43, 0, 1 ], [ 33, 62, 0 ] ], - [ [ 43, 0, 0 ], [ 33, 63, 0 ] ], - [ [ 43, 0, 1 ], [ 34, 62, 0 ] ], - [ [ 43, 0, 2 ], [ 42, 47, 0 ] ], - [ [ 44, 0, 1 ], [ 34, 63, 0 ] ], - [ [ 44, 0, 0 ], [ 35, 62, 0 ] ], - [ [ 44, 0, 1 ], [ 35, 63, 0 ] ], - [ [ 44, 0, 2 ], [ 44, 46, 0 ] ], - [ [ 45, 0, 1 ], [ 36, 62, 0 ] ], - [ [ 45, 0, 0 ], [ 36, 63, 0 ] ], - [ [ 45, 0, 1 ], [ 37, 62, 0 ] ], - [ [ 45, 0, 2 ], [ 45, 47, 0 ] ], - [ [ 46, 0, 1 ], [ 37, 63, 0 ] ], - [ [ 46, 0, 0 ], [ 38, 62, 0 ] ], - [ [ 46, 0, 1 ], [ 38, 63, 0 ] ], - [ [ 46, 0, 2 ], [ 47, 46, 0 ] ], - [ [ 47, 0, 1 ], [ 39, 62, 0 ] ], - [ [ 47, 0, 0 ], [ 39, 63, 0 ] ], - [ [ 47, 0, 1 ], [ 40, 62, 0 ] ], - [ [ 47, 0, 2 ], [ 48, 46, 0 ] ], - [ [ 48, 0, 2 ], [ 40, 63, 0 ] ], - [ [ 48, 0, 1 ], [ 41, 62, 0 ] ], - [ [ 48, 0, 0 ], [ 41, 63, 0 ] ], - [ [ 48, 0, 1 ], [ 48, 49, 0 ] ], - [ [ 48, 0, 2 ], [ 42, 62, 0 ] ], - [ [ 49, 0, 1 ], [ 42, 63, 0 ] ], - [ [ 49, 0, 0 ], [ 43, 62, 0 ] ], - [ [ 49, 0, 1 ], [ 48, 52, 0 ] ], - [ [ 49, 0, 2 ], [ 43, 63, 0 ] ], - [ [ 50, 0, 1 ], [ 44, 62, 0 ] ], - [ [ 50, 0, 0 ], [ 44, 63, 0 ] ], - [ [ 50, 0, 1 ], [ 48, 55, 0 ] ], - [ [ 50, 0, 2 ], [ 45, 62, 0 ] ], - [ [ 51, 0, 1 ], [ 45, 63, 0 ] ], - [ [ 51, 0, 0 ], [ 46, 62, 0 ] ], - [ [ 51, 0, 1 ], [ 48, 58, 0 ] ], - [ [ 51, 0, 2 ], [ 46, 63, 0 ] ], - [ [ 52, 0, 1 ], [ 47, 62, 0 ] ], - [ [ 52, 0, 0 ], [ 47, 63, 0 ] ], - [ [ 52, 0, 1 ], [ 48, 61, 0 ] ], - [ [ 52, 0, 2 ], [ 48, 62, 0 ] ], - [ [ 53, 0, 1 ], [ 56, 47, 0 ] ], - [ [ 53, 0, 0 ], [ 48, 63, 0 ] ], - [ [ 53, 0, 1 ], [ 49, 62, 0 ] ], - [ [ 53, 0, 2 ], [ 49, 63, 0 ] ], - [ [ 54, 0, 1 ], [ 58, 46, 0 ] ], - [ [ 54, 0, 0 ], [ 50, 62, 0 ] ], - [ [ 54, 0, 1 ], [ 50, 63, 0 ] ], - [ [ 54, 0, 2 ], [ 51, 62, 0 ] ], - [ [ 55, 0, 1 ], [ 59, 47, 0 ] ], - [ [ 55, 0, 0 ], [ 51, 63, 0 ] ], - [ [ 55, 0, 1 ], [ 52, 62, 0 ] ], - [ [ 55, 0, 2 ], [ 52, 63, 0 ] ], - [ [ 56, 0, 1 ], [ 61, 46, 0 ] ], - [ [ 56, 0, 0 ], [ 53, 62, 0 ] ], - [ [ 56, 0, 1 ], [ 53, 63, 0 ] ], - [ [ 56, 0, 2 ], [ 54, 62, 0 ] ], - [ [ 57, 0, 1 ], [ 62, 47, 0 ] ], - [ [ 57, 0, 0 ], [ 54, 63, 0 ] ], - [ [ 57, 0, 1 ], [ 55, 62, 0 ] ], - [ [ 57, 0, 2 ], [ 55, 63, 0 ] ], - [ [ 58, 0, 1 ], [ 56, 62, 1 ] ], - [ [ 58, 0, 0 ], [ 56, 62, 0 ] ], - [ [ 58, 0, 1 ], [ 56, 63, 0 ] ], - [ [ 58, 0, 2 ], [ 57, 62, 0 ] ], - [ [ 59, 0, 1 ], [ 57, 63, 1 ] ], - [ [ 59, 0, 0 ], [ 57, 63, 0 ] ], - [ [ 59, 0, 1 ], [ 58, 62, 0 ] ], - [ [ 59, 0, 2 ], [ 58, 63, 0 ] ], - [ [ 60, 0, 1 ], [ 59, 62, 1 ] ], - [ [ 60, 0, 0 ], [ 59, 62, 0 ] ], - [ [ 60, 0, 1 ], [ 59, 63, 0 ] ], - [ [ 60, 0, 2 ], [ 60, 62, 0 ] ], - [ [ 61, 0, 1 ], [ 60, 63, 1 ] ], - [ [ 61, 0, 0 ], [ 60, 63, 0 ] ], - [ [ 61, 0, 1 ], [ 61, 62, 0 ] ], - [ [ 61, 0, 2 ], [ 61, 63, 0 ] ], - [ [ 62, 0, 1 ], [ 62, 62, 1 ] ], - [ [ 62, 0, 0 ], [ 62, 62, 0 ] ], - [ [ 62, 0, 1 ], [ 62, 63, 0 ] ], - [ [ 62, 0, 2 ], [ 63, 62, 0 ] ], - [ [ 63, 0, 1 ], [ 63, 63, 1 ] ], - [ [ 63, 0, 0 ], [ 63, 63, 0 ] ] -]; - -export {lookup_5_3, lookup_6_3, lookup_5_4, lookup_6_4}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/dxt/math.js b/docs/js/libs/src/App/Decompressor/dxt/math.js deleted file mode 100644 index d39ee6d..0000000 --- a/docs/js/libs/src/App/Decompressor/dxt/math.js +++ /dev/null @@ -1,448 +0,0 @@ -import {dominentPrincipalVector} from "./eigs.js"; - -class Vec3 -{ - constructor(x=0, y=x, z=x) - { - this._values = [x, y, z]; - } - get x() - { - return this._values[0]; - } - get y() - { - return this._values[1]; - } - get z() - { - return this._values[2]; - } - set x(value) - { - this._values[0]=value; - } - set y(value) - { - this._values[1]=value; - } - set z(value) - { - this._values[2]=value; - } - get length() - { - return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); - } - get lengthSq() - { - return this.x*this.x + this.y*this.y + this.z*this.z; - } - get normalized() - { - if(this.length === 0) return null; - return Vec3.multScalar(this, 1/this.length); - } - get colorInt() - { - const floatToInt = (value)=>{ - const result = parseInt( (value * 255) + 0.5 ); - return Math.max(Math.min(result, 255), 0); - } - return this._values.map(floatToInt); - } - clone() - { - return new Vec3(this.x, this.y, this.z); - } - set(x, y=x, z=x) - { - this._values[0]=x; - this._values[1]=y; - this._values[2]=z; - - return this; - } - toVec4(w=1) - { - return new Vec4(this.x, this.y, this.z, w); - } - addVector(v) - { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - - return this; - } - addScaledVector(v, scalar) - { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - - return this; - } - mult(scalar) - { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - - return this; - } - multVector(vec) - { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - - return this; - } - clamp(min, max) - { - const clamper = (v)=>(min > v) ? min : ( (max < v) ? max : v ); - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - - return this; - } - clampGrid() - { - const clamper = (v)=>(0 > v) ? 0 : ( (1 < v) ? 1 : v ); - const gridClamper = (value, grid)=>Math.trunc(clamper(value) * grid + 0.5) / grid; - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - - return this; - } - normalize() - { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - - return this; - } - toString() - { - return `Vec3( ${this._values.join(", ")} )`; - } - static add(a, b) - { - return new Vec3(a.x+b.x, a.y+b.y, a.z+b.z); - } - static sub(a, b) - { - return new Vec3(a.x-b.x, a.y-b.y, a.z-b.z); - } - static dot(a, b) - { - return (a.x*b.x)+(a.y*b.y)+(a.z*b.z); - } - static multScalar(a, scalar) - { - return new Vec3(a.x*scalar, a.y*scalar, a.z*scalar); - } - static multVector(a, b) - { - return new Vec3(a.x*b.x, a.y*b.y, a.z*b.z); - } - static interpolate(a, b, p) - { - let a_=Vec3.multScalar(a, 1-p); - let b_=Vec3.multScalar(b, p); - return Vec3.add(a_, b_); - } -} - - -class Vec4 -{ - constructor(x=0, y=x, z=x, w=x) - { - this._values = [x, y, z, w]; - } - get x() - { - return this._values[0]; - } - get y() - { - return this._values[1]; - } - get z() - { - return this._values[2]; - } - get w() - { - return this._values[3]; - } - set x(value) - { - this._values[0]=value; - } - set y(value) - { - this._values[1]=value; - } - set z(value) - { - this._values[2]=value; - } - set w(value) - { - this._values[3]=value; - } - get length() - { - return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z + this.w*this.w); - } - get lengthSq() - { - return this.x*this.x + this.y*this.y + this.z*this.z + this.w*this.w; - } - get normalized() - { - if(this.length === 0) return null; - return Vec4.multScalar(this, 1/this.length); - } - get xyz() - { - return new Vec3(this.x, this.y, this.z); - } - // idk what is "splat", but these functions returns new Vec4 filled with (x,x,x,x). - get splatX() - { - return new Vec4(this.x); - } - get splatY() - { - return new Vec4(this.y); - } - get splatZ() - { - return new Vec4(this.z); - } - get splatW() - { - return new Vec4(this.w); - } - clone() - { - return new Vec4(this.x, this.y, this.z, this.w); - } - set(x, y=x, z=x, w=x) - { - this._values[0]=x; - this._values[1]=y; - this._values[2]=z; - this._values[3]=w; - - return this; - } - toVec3() - { - return this.xyz; - } - addVector(v) - { - this._values[0] += v.x; - this._values[1] += v.y; - this._values[2] += v.z; - this._values[3] += v.w; - - return this; - } - addScaledVector(v, scalar) - { - this._values[0] += v.x * scalar; - this._values[1] += v.y * scalar; - this._values[2] += v.z * scalar; - this._values[3] += v.w * scalar; - - return this; - } - subVector(v) - { - this._values[0] -= v.x; - this._values[1] -= v.y; - this._values[2] -= v.z; - this._values[3] -= v.w; - - return this; - } - mult(scalar) - { - this._values[0] *= scalar; - this._values[1] *= scalar; - this._values[2] *= scalar; - this._values[3] *= scalar; - - return this; - } - multVector(vec) - { - this._values[0] *= vec.x; - this._values[1] *= vec.y; - this._values[2] *= vec.z; - this._values[3] *= vec.w; - - return this; - } - reciprocal() - { - this._values[0] = 1/this._values[0]; - this._values[1] = 1/this._values[1]; - this._values[2] = 1/this._values[2]; - this._values[3] = 1/this._values[3]; - - return this; - } - clamp(min, max) - { - const clamper = (v)=>(min > v) ? min : ( (max < v) ? max : v ); - this._values[0] = clamper(this._values[0]); - this._values[1] = clamper(this._values[1]); - this._values[2] = clamper(this._values[2]); - this._values[3] = clamper(this._values[3]); - - return this; - } - clampGrid() - { - const clamper = (v)=>(0 > v) ? 0 : ( (1 < v) ? 1 : v ); - const gridClamper = (value, grid)=>Math.trunc(clamper(value) * grid + 0.5) / grid; - this._values[0] = gridClamper(this._values[0], 31); - this._values[1] = gridClamper(this._values[1], 63); - this._values[2] = gridClamper(this._values[2], 31); - this._values[3] = clamper(this._values[3]); - - return this; - } - truncate() - { - this._values[0]= Math.trunc(this._values[0]); - this._values[1]= Math.trunc(this._values[1]); - this._values[2]= Math.trunc(this._values[2]); - this._values[3]= Math.trunc(this._values[3]); - - return this; - } - normalize() - { - this._values[0] /= this.length; - this._values[1] /= this.length; - this._values[2] /= this.length; - this._values[3] /= this.length; - - return this; - } - toString() - { - return `Vec4( ${this._values.join(", ")} )`; - } - static add(a, b) - { - return new Vec4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w); - } - static sub(a, b) - { - return new Vec4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w); - } - static dot(a, b) - { - return (a.x*b.x)+(a.y*b.y)+(a.z*b.z)+(a.w*b.w); - } - static multScalar(a, scalar) - { - return new Vec4(a.x*scalar, a.y*scalar, a.z*scalar, a.w*scalar); - } - static multVector(a, b) - { - return new Vec4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w); - } - static interpolate(a, b, p) - { - let a_=Vec4.multScalar(a, 1-p); - let b_=Vec4.multScalar(b, p); - return Vec4.add(a_, b_); - } - // returns a*b + c - static multiplyAdd(a, b, c) - { - return new Vec4( - a.x*b.x+c.x, - a.y*b.y+c.y, - a.z*b.z+c.z, - a.w*b.w+c.w); - } - // returns c - a*b - static negativeMultiplySubtract(a, b, c) - { - return new Vec4( - c.x-a.x*b.x, - c.y-a.y*b.y, - c.z-a.z*b.z, - c.w-a.w*b.w); - } - static compareAnyLessThan(left, right) - { - return (left.x < right.x - || left.y < right.y - || left.z < right.z - || left.w < right.w); - } -} - - - - -function computeWeightedCovariance(values, weights) -{ - //compute the mean vector - let total = 0; - let mean = values.reduce((sum, value, i)=>{ - total += weights[i]; - sum.addScaledVector(value, weights[i]); - return sum; - }, new Vec3(0)); - mean.mult(1/total); - - //compute the covariance matrix - //sigma( (x-m)*(x-m)^T ) - - // [0(xx) 1(xy) 2(xz)] - // [1(xy) 3(yy) 4(yz)] - // [2(xz) 4(yz) 5(zz)] - let covariance = values.reduce((sum, value, i)=>{ - let weight = weights[i]; - let v = Vec3.sub(value, mean); - sum[0][0] += v.x * v.x * weight; sum[0][1] += v.x * v.y * weight; sum[0][2] += v.x * v.z * weight; - sum[1][1] += v.y * v.y * weight; sum[1][2] += v.y * v.z * weight; sum[2][2] += v.z * v.z * weight; - - return sum; - }, [[0,0,0], - [0,0,0], - [0,0,0]]); - - //post-processing - covariance[1][0] = covariance[0][1]; - covariance[2][0] = covariance[0][2]; - covariance[2][1] = covariance[1][2]; - // there is no need to divide by total since the eigenvector of the scalar multiplied matrix - // is the same as the eigenvector of the original matrix. - - return covariance; -} - -function computePCA(values, weights) -{ - const covariance = computeWeightedCovariance(values, weights); - return new Vec3(...dominentPrincipalVector(covariance) ); -} - -export {Vec3, Vec4, computePCA}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/lz4/utils.js b/docs/js/libs/src/App/Decompressor/lz4/utils.js deleted file mode 100644 index 948b515..0000000 --- a/docs/js/libs/src/App/Decompressor/lz4/utils.js +++ /dev/null @@ -1,59 +0,0 @@ -// Original Code by: https://github.com/Benzinga/lz4js/ - -export default class LZ4Utils -{ - // Simple hash function, from: http://burtleburtle.net/bob/hash/integer.html. - // Chosen because it doesn't use multiply and achieves full avalanche. - static hashU32(a) { - a = a | 0; - a = a + 2127912214 + (a << 12) | 0; - a = a ^ -949894596 ^ a >>> 19; - a = a + 374761393 + (a << 5) | 0; - a = a + -744332180 ^ a << 9; - a = a + -42973499 + (a << 3) | 0; - return a ^ -1252372727 ^ a >>> 16 | 0; - } - - // Reads a 64-bit little-endian integer from an array. - static readU64(b, n){ - var x = 0; - x |= b[n++] << 0; - x |= b[n++] << 8; - x |= b[n++] << 16; - x |= b[n++] << 24; - x |= b[n++] << 32; - x |= b[n++] << 40; - x |= b[n++] << 48; - x |= b[n++] << 56; - return x; - } - - // Reads a 32-bit little-endian integer from an array. - static readU32(b, n) { - var x = 0; - x |= b[n++] << 0; - x |= b[n++] << 8; - x |= b[n++] << 16; - x |= b[n++] << 24; - return x; - } - - // Writes a 32-bit little-endian integer from an array. - static writeU32(b, n, x) { - b[n++] = (x >> 0) & 0xff; - b[n++] = (x >> 8) & 0xff; - b[n++] = (x >> 16) & 0xff; - b[n++] = (x >> 24) & 0xff; - } - - // Multiplies two numbers using 32-bit integer multiplication. - // Algorithm from Emscripten. - static imul(a, b) { - var ah = a >>> 16; - var al = a & 65535; - var bh = b >>> 16; - var bl = b & 65535; - - return al * bl + (ah * bl + al * bh << 16) | 0; - }; -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Decompressor/lz4/xxh32.js b/docs/js/libs/src/App/Decompressor/lz4/xxh32.js deleted file mode 100644 index 91cbfdc..0000000 --- a/docs/js/libs/src/App/Decompressor/lz4/xxh32.js +++ /dev/null @@ -1,102 +0,0 @@ -// xxh32.js - implementation of xxhash32 in plain JavaScript -import util from './utils.js'; - -// xxhash32 primes -const prime1 = 0x9e3779b1; -const prime2 = 0x85ebca77; -const prime3 = 0xc2b2ae3d; -const prime4 = 0x27d4eb2f; -const prime5 = 0x165667b1; - -// Utility functions/primitives -// -- - -function rotl32 (x, r) { - x = x | 0; - r = r | 0; - - return x >>> (32 - r | 0) | x << r | 0; -} - -function rotmul32 (h, r, m) { - h = h | 0; - r = r | 0; - m = m | 0; - - return util.imul(h >>> (32 - r | 0) | h << r, m) | 0; -} - -function shiftxor32 (h, s) { - h = h | 0; - s = s | 0; - - return h >>> s ^ h | 0; -} - -// Implementation -// -- - -function xxhapply (h, src, m0, s, m1) { - return rotmul32(util.imul(src, m0) + h, s, m1); -} - -function xxh1 (h, src, index) { - return rotmul32((h + util.imul(src[index], prime5)), 11, prime1); -} - -function xxh4 (h, src, index) { - return xxhapply(h, util.readU32(src, index), prime3, 17, prime4); -} - -function xxh16 (h, src, index) { - return [ - xxhapply(h[0], util.readU32(src, index + 0), prime2, 13, prime1), - xxhapply(h[1], util.readU32(src, index + 4), prime2, 13, prime1), - xxhapply(h[2], util.readU32(src, index + 8), prime2, 13, prime1), - xxhapply(h[3], util.readU32(src, index + 12), prime2, 13, prime1) - ]; -} - -function xxh32 (seed, src, index, len) { - var h, l; - l = len; - if (len >= 16) { - h = [ - seed + prime1 + prime2, - seed + prime2, - seed, - seed - prime1 - ]; - - while (len >= 16) { - h = xxh16(h, src, index); - - index += 16; - len -= 16; - } - - h = rotl32(h[0], 1) + rotl32(h[1], 7) + rotl32(h[2], 12) + rotl32(h[3], 18) + l; - } else { - h = (seed + prime5 + len) >>> 0; - } - - while (len >= 4) { - h = xxh4(h, src, index); - - index += 4; - len -= 4; - } - - while (len > 0) { - h = xxh1(h, src, index); - - index++; - len--; - } - - h = shiftxor32(util.imul(shiftxor32(util.imul(shiftxor32(h, 15), prime2), 13), prime3), 16); - - return h >>> 0; -} - -export default xxh32; \ No newline at end of file diff --git a/docs/js/libs/src/App/ReaderResolver.js b/docs/js/libs/src/App/ReaderResolver.js deleted file mode 100644 index ebccefc..0000000 --- a/docs/js/libs/src/App/ReaderResolver.js +++ /dev/null @@ -1,58 +0,0 @@ -import BufferReader from "./BufferReader.js"; -import XnbError from "../Utils/XnbError.js"; - -/** - * Class used to read the XNB types using the readers - * @class - */ -class ReaderResolver { - /** - * Creating a new instance of ReaderResolver - * @constructor - * @param {BaseReader[]} readers Array of BaseReaders - */ - constructor(readers) { - /** - * Array of base readers - * @type {BaseReader[]} - */ - this.readers = readers; - } - - /** - * Read the XNB file contents - * @method read - * @public - * @param {BufferReader} buffer The buffer to read from. - */ - read(buffer) { - // read the index of which reader to use - let index = buffer.read7BitNumber() - 1; - if (this.readers[index] == null) - throw new XnbError(`Invalid reader index ${index}`); - // read the buffer using the selected reader - return this.readers[index].read(buffer, this); - } - - /** - * Writes the XNB file contents - * @param {BufferWriter} buffer - * @param {Object} content - */ - write(buffer, content) { - this.readers[0].write(buffer, content, this); - } - - /** - * Returns the index of the reader - * @param {BaseReader} reader - * @param {Number} - */ - getIndex(reader) { - for (let i in this.readers) - if (reader.toString() == this.readers[i].toString()) - return i; - } -} - -export default ReaderResolver; \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/ArrayReader.js b/docs/js/libs/src/App/Readers/ArrayReader.js deleted file mode 100644 index 6c52d78..0000000 --- a/docs/js/libs/src/App/Readers/ArrayReader.js +++ /dev/null @@ -1,87 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import UInt32Reader from "./UInt32Reader.js"; - -/** - * Array Reader - * @class - * @extends BaseReader - */ -export default class ArrayReader extends BaseReader { - - /** - * Constructor for the ArrayReader - * @param {BaseReader} reader The reader used for the array elements - */ - constructor(reader) { - super(); - /** @type {BaseReader} */ - this.reader = reader; - } - - static checkTypeIs(rawReader) - { - switch(rawReader) - { - case 'Microsoft.Xna.Framework.Content.ArrayReader': return true; - default return false; - } - } - static hasSubType() - { - return true; - } - - /** - * Reads Array from buffer. - * @param {BufferReader} buffer - * @param {ReaderResolver} resolver - * @returns {Array} - */ - read(buffer, resolver) { - // create a uint32 reader - const uint32Reader = new UInt32Reader(); - // read the number of elements in the array - let size = uint32Reader.read(buffer); - // create local array - let array = []; - - // loop size number of times for the array elements - for (let i = 0; i < size; i++) { - // get value from buffer - let value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - // push into local array - array.push(value); - } - - // return the array - return array; - } - - /** - * Writes Array into buffer - * @param {BufferWriter} buffer - * @param {Array} data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - // write the index - this.writeIndex(buffer, resolver); - // create a uint32 reader - const uint32Reader = new UInt32Reader(); - // write the number of elements in the array - uint32Reader.write(buffer, content.length, resolver); - - // loop over array to write array contents - for (let i = 0; i < content.length; i++) - this.reader.write(buffer, content[i], (this.reader.isValueType() ? null : resolver)); - } - - isValueType() { - return false; - } - - get type() { - return `Array<${this.reader.type}>`; - } -} diff --git a/docs/js/libs/src/App/Readers/BaseReader.js b/docs/js/libs/src/App/Readers/BaseReader.js deleted file mode 100644 index 8b160b0..0000000 --- a/docs/js/libs/src/App/Readers/BaseReader.js +++ /dev/null @@ -1,80 +0,0 @@ -import XnbError from "../../Utils/XnbError.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import ReaderResolver from "../ReaderResolver.js"; - -/** - * Base class for all readers. - * @abstract - * @class - */ -export default class BaseReader { - - static checkTypeIs(rawReader) - { - return false; - } - static hasSubType() - { - return false; - } - - /** - * Returns if type normally requires a special reader. - * @public - * @method - * @returns {Boolean} Returns true if type is primitive. - */ - isValueType() { - return true; - } - - /** - * Returns string type of reader - * @public - * @property - * @returns {string} - */ - get type() { - return this.constructor.name.slice(0, -6); - } - - /** - * Reads the buffer by the specification of the type reader. - * @public - * @param {BufferReader} buffer The buffer to read from. - * @param {ReaderResolver} resolver The content reader to resolve readers from. - * @returns {mixed} Returns the type as specified by the type reader. - */ - read(buffer, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - /** - * Writes into the buffer - * @param {BufferWriter} buffer The buffer to write to - * @param {Mixed} data The data to parse to write to the buffer - * @param {ReaderResolver} resolver ReaderResolver to write non-primitive types - */ - write(buffer, content, resolver) { - throw new XnbError('Cannot invoke methods on abstract class.'); - } - - /** - * Writes the index of this reader to the buffer - * @param {BufferWriter} buffer - * @param {ReaderResolver} resolver - */ - writeIndex(buffer, resolver) { - if (resolver != null) - buffer.write7BitNumber(Number.parseInt(resolver.getIndex(this)) + 1); - } - - /** - * When printing out in a string. - * @returns {String} - */ - toString() { - return this.type; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/BmFontReader.js b/docs/js/libs/src/App/Readers/BmFontReader.js deleted file mode 100644 index d1adce6..0000000 --- a/docs/js/libs/src/App/Readers/BmFontReader.js +++ /dev/null @@ -1,48 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import StringReader from "./StringReader.js"; - -/** - * BmFont Reader - * @class - * @extends BaseReader - */ -export default class BmFontReader extends BaseReader { - static checkTypeIs(rawReader) - { - switch(rawReader) - { - case 'BmFont.XmlSourceReader': return true; - default return false; - } - } - - /** - * Reads BmFont from buffer. - * @param {BufferReader} buffer - * @returns {Object} - */ - read(buffer) { - const stringReader = new StringReader(); - const xml = stringReader.read(buffer); - return { export: { type: this.type, data: xml } }; - } - - /** - * Writes BmFont into buffer - * @param {BufferWriter} buffer - * @param {Mixed} data - * @param {ReaderResolver} - */ - write(buffer, content, resolver) { - // write index of reader - this.writeIndex(buffer, resolver); - const stringReader = new StringReader(); - stringReader.write(buffer, content.export.data, null); - } - - isValueType() { - return false; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/BooleanReader.js b/docs/js/libs/src/App/Readers/BooleanReader.js deleted file mode 100644 index 4d58c6b..0000000 --- a/docs/js/libs/src/App/Readers/BooleanReader.js +++ /dev/null @@ -1,40 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * Boolean Reader - * @class - * @extends BaseReader - */ -export default class BooleanReader extends BaseReader { - static checkTypeIs(rawReader) - { - switch(rawReader) - { - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': return true; - default return false; - } - } - - /** - * Reads Boolean from buffer. - * @param {BufferReader} buffer - * @returns {Boolean} - */ - read(buffer) { - return Boolean(buffer.readInt()); - } - - /** - * Writes Boolean into buffer - * @param {BufferWriter} buffer - * @param {Mixed} data - * @param {ReaderResolver} - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeByte(content); - } -} diff --git a/docs/js/libs/src/App/Readers/CharReader.js b/docs/js/libs/src/App/Readers/CharReader.js deleted file mode 100644 index cfa5351..0000000 --- a/docs/js/libs/src/App/Readers/CharReader.js +++ /dev/null @@ -1,50 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * Char Reader - * @class - * @extends BaseReader - */ -export default class CharReader extends BaseReader { - static checkTypeIs(rawReader) - { - switch(rawReader) - { - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': return true; - default return false; - } - } - - /** - * Reads Char from the buffer. - * @param {BufferReader} buffer - * @returns {String} - */ - read(buffer) { - let charSize = this._getCharSize(buffer.peekInt()); - return buffer.readString(charSize); - } - - /** - * Writes Char into buffer - * @param {BufferWriter} buffer - * @param {Mixed} data - * @param {ReaderResolver} - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeString(content); - } - - /** - * Gets size of char for some special characters that are more than one byte. - * @param {Number} byte - * @returns {Number} - */ - _getCharSize(byte) { - return (( 0xE5000000 >> (( byte >> 3 ) & 0x1e )) & 3 ) + 1; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/DictionaryReader.js b/docs/js/libs/src/App/Readers/DictionaryReader.js deleted file mode 100644 index 124ce13..0000000 --- a/docs/js/libs/src/App/Readers/DictionaryReader.js +++ /dev/null @@ -1,106 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import ReaderResolver from "../ReaderResolver.js"; -import UInt32Reader from "./UInt32Reader.js"; -import XnbError from "../../Utils/XnbError.js"; - -/** - * Dictionary Reader - * @class - * @extends BaseReader - */ -export default class DictionaryReader extends BaseReader { - static checkTypeIs(rawReader) - { - switch(rawReader) - { - case 'Microsoft.Xna.Framework.Content.DictionaryReader': return true; - default return false; - } - } - static hasSubType() - { - return true; - } - - /** - * Constructor for DictionaryReader. - * @constructor - * @param {BaseReader} key The BaseReader for the dictionary key. - * @param {BaseReader} value The BaseReader for the dictionary value. - */ - constructor(key, value) { - // verify key and value are specified - if (key == undefined || value == undefined) - throw new XnbError('Cannot create instance of DictionaryReader without Key and Value.'); - - // call base constructor - super(); - - /** @type {BaseReader} */ - this.key = key; - /** @type {BaseReader} */ - this.value = value; - } - - /** - * Reads Dictionary from buffer. - * @param {BufferReader} buffer Buffer to read from. - * @param {ReaderResolver} resolver ReaderResolver to read non-primitive types. - * @returns {object} - */ - read(buffer, resolver) { - // the dictionary to return - let dictionary = {}; - - // read in the size of the dictionary - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - // loop over the size of the dictionary and read in the data - for (let i = 0; i < size; i++) { - // get the key - let key = this.key.isValueType() ? this.key.read(buffer) : resolver.read(buffer); - // get the value - let value = this.value.isValueType() ? this.value.read(buffer) : resolver.read(buffer); - - // assign KV pair to the dictionary - dictionary[key] = value; - } - - // return the dictionary object - return dictionary; - } - - /** - * Writes Dictionary into buffer - * @param {BufferWriter} buffer - * @param {Object} data The data to parse for the - * @param {ReaderResolver} resolver ReaderResolver to write non-primitive types - * @returns {Buffer} buffer instance with the data in it - */ - write(buffer, content, resolver) { - // write the index - this.writeIndex(buffer, resolver); - - // write the amount of entries in the Dictionary - buffer.writeUInt32(Object.keys(content).length); - - // loop over the entries - for (let key of Object.keys(content)) { - // write the key - this.key.write(buffer, key, (this.key.isValueType() ? null : resolver)); - // write the value - this.value.write(buffer, content[key], (this.value.isValueType() ? null : resolver)); - } - } - - isValueType() { - return false; - } - - get type() { - return `Dictionary<${this.key.type},${this.value.type}>`; - } -} diff --git a/docs/js/libs/src/App/Readers/DoubleReader.js b/docs/js/libs/src/App/Readers/DoubleReader.js deleted file mode 100644 index 4acf6a5..0000000 --- a/docs/js/libs/src/App/Readers/DoubleReader.js +++ /dev/null @@ -1,30 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * Double Reader - * @class - * @extends BaseReader - */ -export default class DoubleReader extends BaseReader { - /** - * Reads Double from buffer. - * @param {BufferReader} buffer - * @returns {Number} - */ - read(buffer) { - return buffer.readDouble(); - } - - /** - * Writes Double into buffer - * @param {BufferWriter} buffer - * @param {Mixed} data - * @param {ReaderResolver} - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeDouble(content); - } -} diff --git a/docs/js/libs/src/App/Readers/EffectReader.js b/docs/js/libs/src/App/Readers/EffectReader.js deleted file mode 100644 index 7aea0f7..0000000 --- a/docs/js/libs/src/App/Readers/EffectReader.js +++ /dev/null @@ -1,41 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import UInt32Reader from "./UInt32Reader.js"; - -/** - * Effect Reader - * @class - * @extends BaseReader - */ -export default class EffectReader extends BaseReader { - - read(buffer) { - const uint32Reader = new UInt32Reader(); - - const size = uint32Reader.read(buffer); - const bytecode = buffer.read(size); - - return { export: { type: this.type, data: bytecode } }; - } - - /** - * Writes Effects into the buffer - * @param {BufferWriter} buffer - * @param {Mixed} data The data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - - const data = content.export.data; - const uint32Reader = new UInt32Reader(); - - uint32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } - - isValueType() { - return false; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/Int32Reader.js b/docs/js/libs/src/App/Readers/Int32Reader.js deleted file mode 100644 index d95892d..0000000 --- a/docs/js/libs/src/App/Readers/Int32Reader.js +++ /dev/null @@ -1,30 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * Int32 Reader - * @class - * @extends BaseReader - */ -export default class Int32Reader extends BaseReader { - /** - * Reads Int32 from buffer. - * @param {BufferReader} buffer - * @returns {Number} - */ - read(buffer) { - return buffer.readInt32(); - } - - /** - * Writes Int32 and returns buffer - * @param {BufferWriter} buffer - * @param {Number} content - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/ListReader.js b/docs/js/libs/src/App/Readers/ListReader.js deleted file mode 100644 index 54e2da2..0000000 --- a/docs/js/libs/src/App/Readers/ListReader.js +++ /dev/null @@ -1,55 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import ReaderResolver from "../ReaderResolver.js"; -import UInt32Reader from "./UInt32Reader.js"; - -/** - * List Reader - * @class - * @extends BaseReader - */ -export default class ListReader extends BaseReader { - constructor(reader) { - super(); - /** @type {BaseReader} */ - this.reader = reader; - } - - /** - * Reads List from buffer. - * @param {BufferReader} buffer - * @param {ReaderResolver} resolver - * @returns {Array} - */ - read(buffer, resolver) { - const uint32Reader = new UInt32Reader(); - const size = uint32Reader.read(buffer); - - const list = []; - for (let i = 0; i < size; i++) { - const value = this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer); - list.push(value); - } - return list; - } - - /** - * Writes List into the buffer - * @param {BufferWriter} buffer - * @param {Mixed} data The data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const uint32Reader = new UInt32Reader(); - uint32Reader.write(buffer, content.length, null); - for (let data of Object.values(content) ) - { - this.reader.write(buffer, data, (this.reader.isValueType() ? null : resolver)); - } - } - - get type() { - return `List<${this.reader.type}>`; - } -} diff --git a/docs/js/libs/src/App/Readers/NullableReader.js b/docs/js/libs/src/App/Readers/NullableReader.js deleted file mode 100644 index 5535c68..0000000 --- a/docs/js/libs/src/App/Readers/NullableReader.js +++ /dev/null @@ -1,62 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import ReaderResolver from "../ReaderResolver.js"; -import BooleanReader from "./BooleanReader.js"; - -/** - * Nullable Reader - * @class - * @extends BaseReader - */ -export default class NullableReader extends BaseReader { - /** - * @constructor - * @param {BaseReader} reader - */ - constructor(reader) { - super(); - /** - * Nullable type - * @type {BaseReader} - */ - this.reader = reader; - } - - /** - * Reads Nullable type from buffer. - * @param {BufferReader} buffer - * @param {ReaderResolver} resolver - * @returns {mixed|null} - */ - read(buffer, resolver) { - // get an instance of boolean reader - const booleanReader = new BooleanReader(); - // read in if the nullable has a value or not - const hasValue = booleanReader.read(buffer); - - // return the value - return (hasValue ? (this.reader.isValueType() ? this.reader.read(buffer) : resolver.read(buffer)) : null); - } - - /** - * Writes Nullable into the buffer - * @param {BufferWriter} buffer - * @param {Mixed} data The data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - //this.writeIndex(buffer, resolver); - const booleanReader = new BooleanReader(); - buffer.writeByte(content != null); - if (content != null) - this.reader.write(buffer, content, (this.reader.isValueType() ? null : resolver)); - } - - isValueType() { - return false; - } - - get type() { - return `Nullable<${this.reader.type}>`; - } -} diff --git a/docs/js/libs/src/App/Readers/Readers.js b/docs/js/libs/src/App/Readers/Readers.js deleted file mode 100644 index b410e8f..0000000 --- a/docs/js/libs/src/App/Readers/Readers.js +++ /dev/null @@ -1,48 +0,0 @@ -import ArrayReader from "./ArrayReader.js"; -import BaseReader from "./BaseReader.js"; -import BmFontReader from "./BmFontReader.js"; -import BooleanReader from "./BooleanReader.js"; -import CharReader from "./CharReader.js"; -import DictionaryReader from "./DictionaryReader.js"; -import DoubleReader from "./DoubleReader.js"; -import EffectReader from "./EffectReader.js"; -import Int32Reader from "./Int32Reader.js"; -import ListReader from "./ListReader.js"; -import NullableReader from "./NullableReader.js"; -import RectangleReader from "./RectangleReader.js"; -import SingleReader from "./SingleReader.js"; -import SpriteFontReader from "./SpriteFontReader.js"; -import StringReader from "./StringReader.js"; -import TBinReader from "./TBinReader.js"; -import Texture2DReader from "./Texture2DReader.js"; -import UInt32Reader from "./UInt32Reader.js"; -import Vector2Reader from "./Vector2Reader.js"; -import Vector3Reader from "./Vector3Reader.js"; -import Vector4Reader from "./Vector4Reader.js"; - - -const Readers = { - ArrayReader, - BaseReader, - BmFontReader, - BooleanReader, - CharReader, - DictionaryReader, - DoubleReader, - EffectReader, - Int32Reader, - ListReader, - NullableReader, - RectangleReader, - SingleReader, - SpriteFontReader, - StringReader, - TBinReader, - Texture2DReader, - UInt32Reader, - Vector2Reader, - Vector3Reader, - Vector4Reader -}; - -export {Readers}; diff --git a/docs/js/libs/src/App/Readers/RectangleReader.js b/docs/js/libs/src/App/Readers/RectangleReader.js deleted file mode 100644 index 6ceb385..0000000 --- a/docs/js/libs/src/App/Readers/RectangleReader.js +++ /dev/null @@ -1,42 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import Int32Reader from "./Int32Reader.js"; - -/** - * Rectangle Reader - * @class - * @extends BaseReader - */ -export default class RectangleReader extends BaseReader { - /** - * Reads Rectangle from buffer. - * @param {BufferReader} buffer - * @returns {object} - */ - read(buffer) { - const int32Reader = new Int32Reader(); - - const x = int32Reader.read(buffer); - const y = int32Reader.read(buffer); - const width = int32Reader.read(buffer); - const height = int32Reader.read(buffer); - - return { x, y, width, height }; - } - - /** - * Writes Effects into the buffer - * @param {BufferWriter} buffer - * @param {Mixed} data The data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, content.x, null); - int32Reader.write(buffer, content.y, null); - int32Reader.write(buffer, content.width, null); - int32Reader.write(buffer, content.height, null); - } -} diff --git a/docs/js/libs/src/App/Readers/ReflectiveReader.js b/docs/js/libs/src/App/Readers/ReflectiveReader.js deleted file mode 100644 index c6e2c4f..0000000 --- a/docs/js/libs/src/App/Readers/ReflectiveReader.js +++ /dev/null @@ -1,29 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * Reflective Reader - * @class - * @extends BaseReader - */ -export default class ReflectiveReader extends BaseReader { - /** - * Reads Reflection data from buffer. - * @param {BufferReader} buffer - * @returns {Mixed} - */ - read(buffer) { - - } - - /** - * Writes Reflection data and returns buffer - * @param {BufferWriter} buffer - * @param {Number} content - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeInt32(content); - } -} diff --git a/docs/js/libs/src/App/Readers/SingleReader.js b/docs/js/libs/src/App/Readers/SingleReader.js deleted file mode 100644 index 9ba6b77..0000000 --- a/docs/js/libs/src/App/Readers/SingleReader.js +++ /dev/null @@ -1,23 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; - -/** - * Single Reader - * @class - * @extends BaseReader - */ -export default class SingleReader extends BaseReader { - /** - * Reads Single from the buffer. - * @param {BufferReader} buffer - * @returns {Number} - */ - read(buffer) { - return buffer.readSingle(); - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeSingle(content); - } -} diff --git a/docs/js/libs/src/App/Readers/SpriteFontReader.js b/docs/js/libs/src/App/Readers/SpriteFontReader.js deleted file mode 100644 index 0e6f8b0..0000000 --- a/docs/js/libs/src/App/Readers/SpriteFontReader.js +++ /dev/null @@ -1,84 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import Int32Reader from "./Int32Reader.js"; -import SingleReader from "./SingleReader.js"; -import NullableReader from "./NullableReader.js"; -import CharReader from "./CharReader.js"; -import Texture2DReader from "./Texture2DReader.js"; -import ListReader from "./ListReader.js"; -import RectangleReader from "./RectangleReader.js"; -import Vector3Reader from "./Vector3Reader.js"; - -/** - * SpriteFont Reader - * @class - * @extends BaseReader - */ -export default class SpriteFontReader extends BaseReader { - /** - * Reads SpriteFont from buffer. - * @param {BufferReader} buffer - * @param {ReaderResolver} resolver - * @returns {object} - */ - read(buffer, resolver) { - const int32Reader = new Int32Reader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(new CharReader()); - - const texture = resolver.read(buffer) - const glyphs = resolver.read(buffer); - const cropping = resolver.read(buffer);; - const characterMap = resolver.read(buffer); - const verticalLineSpacing = int32Reader.read(buffer); - const horizontalSpacing = singleReader.read(buffer); - const kerning = resolver.read(buffer); - const defaultCharacter = nullableCharReader.read(buffer); - - return { - texture, - glyphs, - cropping, - characterMap, - verticalLineSpacing, - horizontalSpacing, - kerning, - defaultCharacter - }; - } - - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const charReader = new CharReader(); - const singleReader = new SingleReader(); - const nullableCharReader = new NullableReader(charReader); - const texture2DReader = new Texture2DReader(); - const rectangleListReader = new ListReader(new RectangleReader()); - const charListReader = new ListReader(charReader); - const vector3ListReader = new ListReader(new Vector3Reader()); - - this.writeIndex(buffer, resolver); - - try { - texture2DReader.write(buffer, content.texture, resolver); - // Allocate space in the buffer in advance to minimize reallocation to improve performance. - buffer.alloc(100000); - rectangleListReader.write(buffer, content.glyphs, resolver); - rectangleListReader.write(buffer, content.cropping, resolver); - charListReader.write(buffer, content.characterMap, resolver); - int32Reader.write(buffer, content.verticalLineSpacing, null); - singleReader.write(buffer, content.horizontalSpacing, null); - vector3ListReader.write(buffer, content.kerning, resolver); - nullableCharReader.write(buffer, content.defaultCharacter, null); - } - catch (ex) { - throw ex; - } - - console.log("writing complitd!"); - } - - isValueType() { - return false; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/StringReader.js b/docs/js/libs/src/App/Readers/StringReader.js deleted file mode 100644 index 27d444e..0000000 --- a/docs/js/libs/src/App/Readers/StringReader.js +++ /dev/null @@ -1,45 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import ReaderResolver from "../ReaderResolver.js"; -import {UTF8Length} from "../../Utils/UTF8ToString.js"; - -/** - * String Reader - * @class - * @extends BaseReader - */ -export default class StringReader extends BaseReader { - /** - * Reads String from buffer. - * @param {BufferReader} buffer - * @returns {String} - */ - read(buffer) { - // read in the length of the string - let length = buffer.read7BitNumber(); - // read in the UTF-8 encoded string - return buffer.readString(length); - } - - /** - * Writes the string to the buffer. - * @param {BufferWriter} buffer - * @param {String} string - * @param {ReaderResolver} resolver - */ - write(buffer, string, resolver) { - // write the index - this.writeIndex(buffer, resolver); - // get the size of UTF-8 encoded string - const size = UTF8Length(string); - // write the length of the string - buffer.write7BitNumber(size); - // write the string - buffer.writeString(string); - } - - isValueType() { - return false; - } -} diff --git a/docs/js/libs/src/App/Readers/TBinReader.js b/docs/js/libs/src/App/Readers/TBinReader.js deleted file mode 100644 index c37d54f..0000000 --- a/docs/js/libs/src/App/Readers/TBinReader.js +++ /dev/null @@ -1,35 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; -import Int32Reader from "./Int32Reader.js"; - -/** - * TBin Reader - * @class - * @extends BaseReader - */ -export default class TBinReader extends BaseReader { - read(buffer) { - const int32Reader = new Int32Reader(); - - // read in the size of the data block - let size = int32Reader.read(buffer); - // read in the data block - let data = buffer.read(size); - - // return the data - return { export: { type: this.type, data } }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const data = content.export.data; - const int32Reader = new Int32Reader(); - int32Reader.write(buffer, data.byteLength, null); - buffer.concat(data); - } - - isValueType() { - return false; - } -} diff --git a/docs/js/libs/src/App/Readers/Texture2DReader.js b/docs/js/libs/src/App/Readers/Texture2DReader.js deleted file mode 100644 index 17a4fac..0000000 --- a/docs/js/libs/src/App/Readers/Texture2DReader.js +++ /dev/null @@ -1,113 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import Int32Reader from "./Int32Reader.js"; -import UInt32Reader from "./UInt32Reader.js"; -import * as dxt from "../Decompressor/dxt.js"; -import Debug from "../../Utils/Debug.js"; -import XnbError from "../../Utils/XnbError.js"; - -/** - * Texture2D Reader - * @class - * @extends BaseReader - */ -export default class Texture2DReader extends BaseReader { - /** - * Reads Texture2D from buffer. - * @param {BufferReader} buffer - * @returns {object} - */ - read(buffer) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - - let format = int32Reader.read(buffer); - let width = uint32Reader.read(buffer); - let height = uint32Reader.read(buffer); - let mipCount = uint32Reader.read(buffer); - - if (mipCount > 1) - console.warn(`Found mipcount of ${mipCount}, only the first will be used.`); - - let dataSize = uint32Reader.read(buffer); - let data = buffer.read(dataSize); - - if (format == 4) - data = dxt.decompress(data, width, height, dxt.flags.DXT1); - else if (format == 5) - data = dxt.decompress(data, width, height, dxt.flags.DXT3); - else if (format == 6) - data = dxt.decompress(data, width, height, dxt.flags.DXT5); - else if (format == 2) { - // require('fs').writeFileSync('texture.bin', data); - throw new XnbError('Texture2D format type ECT1 not implemented!'); - } - else if (format != 0) - throw new XnbError(`Non-implemented Texture2D format type (${format}) found.`); - - // add the alpha channel into the image - for(let i = 0; i < data.length; i += 4) { - let inverseAlpha = 255 / data[i + 3]; - data[i ] = Math.min(Math.ceil(data[i ] * inverseAlpha), 255); - data[i + 1] = Math.min(Math.ceil(data[i + 1] * inverseAlpha), 255); - data[i + 2] = Math.min(Math.ceil(data[i + 2] * inverseAlpha), 255); - } - - return { - format, - export: { - type: this.type, - data, - width, - height - } - }; - } - - /** - * Writes Texture2D into the buffer - * @param {BufferWriter} buffer - * @param {Mixed} data The data - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - const int32Reader = new Int32Reader(); - const uint32Reader = new UInt32Reader(); - - this.writeIndex(buffer, resolver); - - const width = content.export.width; - const height = content.export.height; - - Debug(`Width: ${width}, Height: ${height}`); - Debug(`Format: ${content.format}`); - - int32Reader.write(buffer, content.format, null); - uint32Reader.write(buffer, content.export.width, null); - uint32Reader.write(buffer, content.export.height, null); - uint32Reader.write(buffer, 1, null); - - let data = content.export.data; - - for (let i = 0; i < data.length; i += 4) { - const alpha = data[i + 3] / 255; - data[i ] = Math.floor(data[i ] * alpha); - data[i + 1] = Math.floor(data[i + 1] * alpha); - data[i + 2] = Math.floor(data[i + 2] * alpha); - } - - if (content.format == 4) - data = dxt.compress(data, width, height, dxt.flags.DXT1); - else if (content.format == 5) - data = dxt.compress(data, width, height, dxt.flags.DXT3); - else if (content.format == 6) - data = dxt.compress(data, width, height, dxt.flags.DXT5); - - uint32Reader.write(buffer, data.length, null); - buffer.concat(data); - } - - isValueType() { - return false; - } -} diff --git a/docs/js/libs/src/App/Readers/UInt32Reader.js b/docs/js/libs/src/App/Readers/UInt32Reader.js deleted file mode 100644 index 628cb7f..0000000 --- a/docs/js/libs/src/App/Readers/UInt32Reader.js +++ /dev/null @@ -1,30 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import BufferWriter from "../BufferWriter.js"; - -/** - * UInt32 Reader - * @class - * @extends BaseReader - */ -export default class UInt32Reader extends BaseReader { - /** - * Reads UInt32 from buffer. - * @param {BufferReader} buffer - * @returns {Number} - */ - read(buffer) { - return buffer.readUInt32(); - } - - /** - * - * @param {BufferWriter} buffer - * @param {Number} content - * @param {ReaderResolver} resolver - */ - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - buffer.writeUInt32(content); - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/Readers/Vector2Reader.js b/docs/js/libs/src/App/Readers/Vector2Reader.js deleted file mode 100644 index 3ada817..0000000 --- a/docs/js/libs/src/App/Readers/Vector2Reader.js +++ /dev/null @@ -1,24 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import SingleReader from "./SingleReader.js"; - -/** - * Vector2 Reader - * @class - * @extends BaseReader - */ -export default class Vector2Reader extends BaseReader { - /** - * Reads Vector2 from buffer. - * @param {BufferReader} buffer - * @returns {object} - */ - read(buffer) { - const singleReader = new SingleReader(); - - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - - return { x, y }; - } -} diff --git a/docs/js/libs/src/App/Readers/Vector3Reader.js b/docs/js/libs/src/App/Readers/Vector3Reader.js deleted file mode 100644 index 9967268..0000000 --- a/docs/js/libs/src/App/Readers/Vector3Reader.js +++ /dev/null @@ -1,33 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import SingleReader from "./SingleReader.js"; - -/** - * Vector3 Reader - * @class - * @extends BaseReader - */ -export default class Vector3Reader extends BaseReader { - /** - * Reads Vector3 from buffer. - * @param {BufferReader} buffer - * @returns {object} - */ - read(buffer) { - const singleReader = new SingleReader(); - - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - - return { x, y, z }; - } - - write(buffer, content, resolver) { - this.writeIndex(buffer, resolver); - const singleReader = new SingleReader(); - singleReader.write(buffer, content.x, null); - singleReader.write(buffer, content.y, null); - singleReader.write(buffer, content.z, null); - } -} diff --git a/docs/js/libs/src/App/Readers/Vector4Reader.js b/docs/js/libs/src/App/Readers/Vector4Reader.js deleted file mode 100644 index f790571..0000000 --- a/docs/js/libs/src/App/Readers/Vector4Reader.js +++ /dev/null @@ -1,25 +0,0 @@ -import BaseReader from "./BaseReader.js"; -import BufferReader from "../BufferReader.js"; -import SingleReader from "./SingleReader.js"; -/** - * Vector4 Reader - * @class - * @extends BaseReader - */ -export default class Vector4Reader extends BaseReader { - /** - * Reads Vector4 from buffer. - * @param {BufferReader} buffer - * @returns {object} - */ - read(buffer) { - const singleReader = new SingleReader(); - - let x = singleReader.read(buffer); - let y = singleReader.read(buffer); - let z = singleReader.read(buffer); - let w = singleReader.read(buffer); - - return { x, y, z, w }; - } -} \ No newline at end of file diff --git a/docs/js/libs/src/App/TypeReader.js b/docs/js/libs/src/App/TypeReader.js deleted file mode 100644 index 7252164..0000000 --- a/docs/js/libs/src/App/TypeReader.js +++ /dev/null @@ -1,174 +0,0 @@ -import XnbError from "../Utils/XnbError.js"; -import Debug from "../Utils/Debug.js"; -import {Readers} from "./Readers/Readers.js"; - -/** - * Used to simplify type from XNB file. - * @function simplifyType - * @param {String} type The long verbose type read from XNB file. - * @returns {String} returns shorthand simplified type for use within this tool. - */ -const simplifyType = type => { - // gets the first part of the type - let simple = type.split(/`|,/)[0]; - - Debug(`Type: ${simple}`); - - // check if its an array or not - let isArray = simple.endsWith('[]'); - // if its an array then get the array type - if (isArray) - return `Array<${simplifyType(simple.slice(0, -2))}>`; - - // switch over the possible types regisered with this tool - switch (simple) { - - // Boolean - case 'Microsoft.Xna.Framework.Content.BooleanReader': - case 'System.Boolean': - return 'Boolean'; - - // Char - case 'Microsoft.Xna.Framework.Content.CharReader': - case 'System.Char': - return 'Char'; - - // Int32 - case 'Microsoft.Xna.Framework.Content.Int32Reader': - case 'System.Int32': - return 'Int32'; - - // String - case 'Microsoft.Xna.Framework.Content.StringReader': - case 'System.String': - return 'String'; - - // Dictionary - case 'Microsoft.Xna.Framework.Content.DictionaryReader': - let subtypes = parseSubtypes(type).map(simplifyType); - return `Dictionary<${subtypes[0]},${subtypes[1]}>`; - - // Array - case 'Microsoft.Xna.Framework.Content.ArrayReader': - let arrayType = parseSubtypes(type).map(simplifyType); - return `Array<${arrayType}>`; - - // List - case 'Microsoft.Xna.Framework.Content.ListReader': - case 'System.Collections.Generic.List': - let listType = parseSubtypes(type).map(simplifyType); - return `List<${listType}>`; - - // Texture2D - case 'Microsoft.Xna.Framework.Content.Texture2DReader': - return 'Texture2D'; - - // Vector2 - case 'Microsoft.Xna.Framework.Content.Vector2Reader': - case 'Microsoft.Xna.Framework.Vector2': - return 'Vector2'; - - // Vector3 - case 'Microsoft.Xna.Framework.Content.Vector3Reader': - case 'Microsoft.Xna.Framework.Vector3': - return 'Vector3'; - - // Vector3 - case 'Microsoft.Xna.Framework.Content.Vector4Reader': - case 'Microsoft.Xna.Framework.Vector4': - return 'Vector4'; - - // SpriteFont - case 'Microsoft.Xna.Framework.Content.SpriteFontReader': - return 'SpriteFont'; - - // Rectangle - case 'Microsoft.Xna.Framework.Content.RectangleReader': - case 'Microsoft.Xna.Framework.Rectangle': - return 'Rectangle'; - - // Effect - case 'Microsoft.Xna.Framework.Content.EffectReader': - case 'Microsoft.Xna.Framework.Graphics.Effect': - return 'Effect'; - - // xTile TBin - case 'xTile.Pipeline.TideReader': - return 'TBin'; - - // BmFont - case 'BmFont.XmlSourceReader': - return 'BmFont'; - - // unimplemented type catch - default: - throw new XnbError(`Non-implemented type found, cannot resolve type "${simple}", "${type}".`); - } -} - -/** - * Parses subtypes from a type like Dictionary or List - * @function parseSubtypes - * @param {String} type The type to parse with subtypes in. - * @returns {String[]} returns an array of subtypes - */ -const parseSubtypes = type => { - // split the string by the ` after the type - let subtype = type.split('`')[1]; - // get the number of types following the ` in type string - let count = subtype.slice(0, 1); - - // get the contents of the wrapped array - subtype = subtype.slice(2, -1); - - // regex pattern to match the subtypes - let pattern = /\[(([a-zA-Z0-9\.\,\=\`]+)(\[\])?(\, |\])){1,}/g; - // get matches - let matches = subtype.match(pattern).map(e => { - return e.slice(1, -1); - }); - - // return the matches - return matches; -} - - -/** - * Get type info from simple type - * @param {String} type Simple type to get info from. - * @returns {Object} returns an object containing information about the type. - */ -const getTypeInfo = type => { - // get type before angle brackets for complex types - let mainType = type.match(/[^<]+/)[0]; - // get the subtypes within brackets - let subtypes = type.match(/<(.+)>/); - - // if we do have subtypes then split and trim them - subtypes = subtypes ? subtypes[1].split(',').map(type => type.trim()) : []; - - // return info object - return { type: mainType, subtypes }; -} - -/** - * Gets an XnbReader instance based on type. - * @function getReader - * @param {String} type The simplified type to get reader based off of. - * @returns {BaseReader} returns an instance of BaseReader for given type. - */ -const getReader = typeString => { - // get type info for complex types - let {type, subtypes} = getTypeInfo(typeString); - // loop over subtypes and resolve readers for them - subtypes = subtypes.map(getReader); - - // if we have a reader then use one - if (Readers.hasOwnProperty(`${type}Reader`)) - return new (Readers[`${type}Reader`])(...subtypes); - - // throw an error as type is not supported - throw new XnbError(`Invalid reader type "${typeString}" passed, unable to resolve!`); -} - -export {simplifyType, parseSubtypes, getTypeInfo, getReader}; \ No newline at end of file diff --git a/docs/js/libs/src/App/Xnb.js b/docs/js/libs/src/App/Xnb.js deleted file mode 100644 index aea13f6..0000000 --- a/docs/js/libs/src/App/Xnb.js +++ /dev/null @@ -1,377 +0,0 @@ -import BufferReader from "./BufferReader.js"; -import BufferWriter from "./BufferWriter.js"; - -import Presser from "./Decompressor/LZXDecompressor.js"; -import {decompressBlock as LZ4_decompressBlock, - compressBound as LZ4_compressBound, - compressSingleBlock as LZ4_compressBlock} from "./Decompressor/Lz4.js"; - -import StringReader from "./Readers/StringReader.js"; -import { simplifyType, getReader } from "./TypeReader.js"; -import ReaderResolver from './ReaderResolver.js'; - -import XnbError from "../Utils/XnbError.js"; -import Debug from "../Utils/Debug.js"; - -import {XnbData} from "./XnbData.js"; - -// "constants" for this class -const HIDEF_MASK = 0x1; -const COMPRESSED_LZ4_MASK = 0x40; -const COMPRESSED_LZX_MASK = 0x80; -const XNB_COMPRESSED_PROLOGUE_SIZE = 14; - -/** - * XNB file class used to read and write XNB files - * @class - * @public - */ -class XnbConverter { - - /** - * Creates new instance of Xnb class - * @constructor - */ - constructor() { - // target platform - this.target = ''; - // format version - this.formatVersion = 0; - // HiDef flag - this.hidef = false; - // Compressed flag - this.compressed = false; - // compression type - this.compressionType = 0; - // the XNB buffer reader - this.buffer = null; - // the file size - this.fileSize = 0; - - /** - * Array of readers that are used by the XNB file. - * @type {BaseReader[]} - */ - this.readers = []; - - /** - * Array of shared resources - * @type {Array} - */ - this.sharedResources = []; - } - - /** - * Loads a file into the XNB class. - * @param {ArrayBuffer} XNB file's array buffer - */ - load(arrayBuffer) { - - // create a new instance of reader - this.buffer = new BufferReader(arrayBuffer); - - - // validate the XNB file header - this._validateHeader(); - - // we validated the file successfully - console.info('XNB file validated successfully!'); - - - // read the file size - this.fileSize = this.buffer.readUInt32(); - - // verify the size - if (this.buffer.size != this.fileSize) - throw new XnbError('XNB file has been truncated!'); - - // print out the file size - Debug(`File size: ${this.fileSize} bytes.`); - - - - // if the file is compressed then we need to decompress it - if (this.compressed) { - // get the decompressed size - const decompressedSize = this.buffer.readUInt32(); - Debug(`Uncompressed size: ${decompressedSize} bytes.`); - - // decompress LZX format - if (this.compressionType == COMPRESSED_LZX_MASK) { - // get the amount of data to compress - const compressedTodo = this.fileSize - XNB_COMPRESSED_PROLOGUE_SIZE; - // decompress the buffer based on the file size - const decompressed = Presser.decompress(this.buffer, compressedTodo, decompressedSize); - // copy the decompressed buffer into the file buffer - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - // reset the byte seek head to read content - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - // decompress LZ4 format - - else if (this.compressionType == COMPRESSED_LZ4_MASK) { - // allocate Uint8 Array for LZ4 decode - const trimmed = this.buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - - // decode the trimmed buffer into decompressed buffer - const decompressed = new Uint8Array(decompressedSize); - LZ4_decompressBlock(trimmedArray, decompressed); - // copy the decompressed buffer into our buffer - this.buffer.copyFrom(decompressed, XNB_COMPRESSED_PROLOGUE_SIZE, 0, decompressedSize); - // reset the byte seek head to read content - this.buffer.bytePosition = XNB_COMPRESSED_PROLOGUE_SIZE; - } - } - - Debug(`Reading from byte position: ${this.buffer.bytePosition}`); - - - // NOTE: assuming the buffer is now decompressed - - // get the 7-bit value for readers - let count = this.buffer.read7BitNumber(); - // log how many readers there are - Debug(`Readers: ${count}`); - - - // create an instance of string reader - const stringReader = new StringReader(); - - // a local copy of readers for the export - const readers = []; - - - console.log(this.buffer); - - // loop over the number of readers we have - for (let i = 0; i < count; i++) { - // read the type - const type = stringReader.read(this.buffer); - // read the version - const version = this.buffer.readInt32(); - - // get the reader for this type - const simpleType = simplifyType(type); - const reader = getReader(simpleType); - - // add reader to the list - this.readers.push(reader); - // add local reader - readers.push({ type, version }); - } - - // get the 7-bit value for shared resources - const shared = this.buffer.read7BitNumber(); - - // log the shared resources count - Debug(`Shared Resources: ${shared}`); - - // don't accept shared resources since SDV XNB files don't have any - if (shared != 0) - throw new XnbError(`Unexpected (${shared}) shared resources.`); - - // create content reader from the readers loaded - const content = new ReaderResolver(this.readers); - // read the content in - const result = content.read(this.buffer); - - // we loaded the XNB file successfully - console.log('Successfuly read XNB file!'); - - // return the loaded XNB object - return new XnbData({ - target: this.target, - formatVersion: this.formatVersion, - hidef: this.hidef, - compressed: this.compressed - }, - readers, result); - } - - /** - * Converts JSON into XNB file structure - * @param {Object} The JSON to convert into a XNB file - */ - - convert(json) { - // the output buffer for this file - const buffer = new BufferWriter(); - - // create an instance of string reader - const stringReader = new StringReader(); - - // set the header information - let {target, formatVersion, hidef, compressed} = json.header; - - this.target = target; - this.formatVersion = formatVersion; - this.hidef = hidef; - - const lz4Compression = (this.target == 'a' || this.target == 'i') || ((compressed & COMPRESSED_LZ4_MASK) != 0); - this.compressed = lz4Compression ? true : false; // support android LZ4 compression - - // write the header into the buffer - buffer.writeString("XNB"); - buffer.writeString(this.target); - buffer.writeByte(this.formatVersion); - // write the LZ4 mask for android compression only - // todo:LZX compression. There are currently NO open source libraries implementing the LZX compression algorithm. - buffer.writeByte(this.hidef | ((this.compressed && lz4Compression) ? COMPRESSED_LZ4_MASK : 0)); - - // write temporary filesize - buffer.writeUInt32(0); - - // write the decompression size temporarily if android - if (lz4Compression) - buffer.writeUInt32(0); - - Debug("Header data written successfully!"); - - // write the amount of readers - buffer.write7BitNumber(json.readers.length); - - // loop over the readers and load the types - for (let reader of json.readers) { - this.readers.push(getReader(simplifyType(reader.type))); // simplyify the type then get the reader of it - stringReader.write(buffer, reader.type); - buffer.writeUInt32(reader.version); - } - - Debug("Reader data written successfully!"); - - // write 0 shared resources - buffer.write7BitNumber(0); - - // create reader resolver for content and write it - const content = new ReaderResolver(this.readers); - - // write the content to the reader resolver - content.write(buffer, json.content); - - Debug("Content data written successfully!"); - - // trim excess space in the buffer - // NOTE: this buffer allocates default with 500 bytes - buffer.trim(); - - // LZ4 compression - if (lz4Compression) { - // allocate Uint8 Array for LZ4 encode - const trimmed = buffer.buffer.slice(XNB_COMPRESSED_PROLOGUE_SIZE); - const trimmedArray = new Uint8Array(trimmed); - - let compressedSize = LZ4_compressBound(trimmedArray.length); - - // create a buffer for the compressed data - let compressed = new Uint8Array(compressedSize); - - // compress the data into the buffer - compressedSize = LZ4_compressBlock(trimmedArray, compressed); - compressed = compressed.slice(0, compressedSize); - - // write the file size & decompressed size into the buffer - buffer.bytePosition = 6; - buffer.writeUInt32(XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - buffer.writeUInt32(trimmedArray.length); - - // write compressed data - buffer.concat(compressed); - - // slice off the excess - let returnBuffer = buffer.buffer.slice(0, XNB_COMPRESSED_PROLOGUE_SIZE + compressedSize); - - // return the buffer - return returnBuffer; - } - - // write the file size into the buffer - let fileSize = buffer.bytePosition; - buffer.bytePosition = 6; - buffer.writeUInt32(fileSize, 6); - - // return the buffer - return buffer.buffer; - } - - /** - * Ensures the XNB file header is valid. - * @private - * @method _validateHeader - */ - _validateHeader() { - // ensure buffer isn't null - if (this.buffer == null) - throw new XnbError('Buffer is null'); - - // get the magic from the beginning of the file - const magic = this.buffer.readString(3); - // check to see if the magic is correct - if (magic != 'XNB') - throw new XnbError(`Invalid file magic found, expecting "XNB", found "${magic}"`); - - // debug print that valid XNB magic was found - Debug('Valid XNB magic found!'); - - // load the target platform - this.target = this.buffer.readString(1).toLowerCase(); - - // read the target platform - switch (this.target) { - case 'w': - Debug('Target platform: Microsoft Windows'); - break; - case 'm': - Debug('Target platform: Windows Phone 7'); - break; - case 'x': - Debug('Target platform: Xbox 360'); - break; - case 'a': - Debug('Target platform: Android'); - break; - case 'i': - Debug('Target platform: iOS'); - break; - default: - console.warn(`Invalid target platform "${this.target}" found.`); - break; - } - - // read the format version - this.formatVersion = this.buffer.readByte(); - - // read the XNB format version - switch (this.formatVersion) { - case 0x3: - Debug('XNB Format Version: XNA Game Studio 3.0'); - break; - case 0x4: - Debug('XNB Format Version: XNA Game Studio 3.1'); - break; - case 0x5: - Debug('XNB Format Version: XNA Game Studio 4.0'); - break; - default: - console.warn(`XNB Format Version 0x${this.formatVersion.toString(16)} unknown.`); - break; - } - - // read the flag bits - const flags = this.buffer.readByte(1); - // get the HiDef flag - this.hidef = (flags & HIDEF_MASK) != 0; - // get the compressed flag - this.compressed = (flags & COMPRESSED_LZX_MASK) || (flags & COMPRESSED_LZ4_MASK) != 0; - // set the compression type - // NOTE: probably a better way to do both lines but sticking with this for now - this.compressionType = (flags & COMPRESSED_LZX_MASK) != 0 ? COMPRESSED_LZX_MASK : ((flags & COMPRESSED_LZ4_MASK) ? COMPRESSED_LZ4_MASK : 0); - // debug content information - Debug(`Content: ${(this.hidef ? 'HiDef' : 'Reach')}`); - // log compressed state - Debug(`Compressed: ${this.compressed}, ${this.compressionType == COMPRESSED_LZX_MASK ? 'LZX' : 'LZ4'}`); - } - -} - -export default XnbConverter; \ No newline at end of file diff --git a/docs/js/libs/src/App/XnbData.js b/docs/js/libs/src/App/XnbData.js deleted file mode 100644 index 2555fa1..0000000 --- a/docs/js/libs/src/App/XnbData.js +++ /dev/null @@ -1,90 +0,0 @@ -class XnbData { - constructor(header, readers, content) - { - let {target, formatVersion, hidef, compressed} = header; - this.header = {target, formatVersion, hidef, compressed}; - this.readers = readers; - this.content = content; - } - get target() - { - switch(this.header?.target){ - case 'w': return "Microsoft Windows"; - case 'm': return "Windows Phone 7"; - case 'x': return "Xbox 360"; - case 'a': return "Android"; - case 'i': return "iOS"; - default: return "Unknown"; - } - - } - get formatVersion() - { - switch (this.header?.formatVersion) { - case 0x3: return "XNA Game Studio 3.0"; - case 0x4: return "XNA Game Studio 3.1"; - case 0x5: return "XNA Game Studio 4.0"; - default: return "Unknown"; - } - } - get hidef() - { - return !!(this.header?.hidef); - } - get compressed() - { - return !!(this.header?.compressed); - } - - get contentType() - { - let {export:raw} = this.content; - if(raw !== undefined) return raw.type; - return "JSON"; - } - get rawContent() - { - let {export:raw} = this.content; - if(raw !== undefined) return raw.data; - return JSON.stringify(this.content, (key, value)=>{ - if(key === "export") return value.type; - return value; - }, 4); - } - stringify() - { - return JSON.stringify({ - header:this.header, - readers:this.readers, - content:this.content - }, null, 4); - } - toString() - { - return this.stringify(); - } -} - -function extensionToDatatype(extension) -{ - switch(extension) - { - case "json": return "JSON"; - case "yaml": return "yaml"; - case "png": return "Texture2D"; - case "cso": return "Effect"; - case 'tbin': return "TBin"; - case 'xml': return "BmFont"; - } - return "Others"; -} - -class XnbContent { - constructor(data, ext) - { - this.type = extensionToDatatype(ext); - this.content = data; - } -} - -export {XnbData, XnbContent}; \ No newline at end of file diff --git a/docs/js/libs/src/Files.js b/docs/js/libs/src/Files.js deleted file mode 100644 index 1096567..0000000 --- a/docs/js/libs/src/Files.js +++ /dev/null @@ -1,280 +0,0 @@ -import XnbError from "./Utils/XnbError.js"; -import {toPNG, fromPNG} from "./libs/png.js"; -import {stringifyYaml, parseYaml} from "./libs/jsonToYaml.js"; -import {toXnbNodeData, fromXnbNodeData} from "./Utils/xnbNodeConverter.js"; - - -function searchElement(parent, element) -{ - // ensure object is defined and is an object - if (!parent || typeof parent != 'object') return; - - // if property exists then return it - if (parent.hasOwnProperty(element)) { - return { parent, value: parent[element] }; - } - - // search the objects for keys - for(let child of Object.values(parent)) { - if (!!child || typeof child == 'object') { - let found = searchElement(child, element); - if(found) return found; - } - } - - return null; -} - -function extractFileName(fullname) -{ - let matcher = fullname.match(/(.*)\.([^\s.]+)$/); - if(matcher === null) return [fullname,null]; - return [ matcher[1], matcher[2] ]; -} - -function getExtension(dataType) -{ - switch(dataType) - { - // json data - case "JSON": return "json"; - // yaml data - case "yaml": return "yaml"; - // png image - case "Texture2D": return "png"; - // compiled effects - case "Effect": return "cso"; - // tbin map file - case 'TBin': return "tbin"; - // BmFont Xml - case 'BmFont': return "xml"; - } - return "bin"; -} - -function getMimeType(dataType) -{ - switch(dataType) - { - // json data - case "JSON": return "application/json"; - // yaml data - case "yaml": return "text/plain"; - // png image - case "Texture2D": return "image/png"; - // compiled effects - case "Effect": return "application/x-cso"; - // BmFont Xml - case 'BmFont': return "application/xml"; - } - return "application/octet-stream"; -} - -function makeBlob(data, dataType) -{ - //blob is avaliable - if(typeof Blob === "function") return { - data : new Blob([data], {type : getMimeType(dataType)}), - extension : getExtension(dataType) - }; - return { - data : data, - extension : getExtension(dataType) - }; -} - -function exportContent(content, jsonContent=false) -{ - let found = searchElement(content, "export"); - if (found) - { - const {value} = found; - let {type:dataType, data} = value; - - // transform to png - if(dataType === "Texture2D") - { - data = toPNG( value.width, value.height, new Uint8Array(data) ); - } - - return makeBlob(data, dataType); - } - - // if contentOnly == true, export json data file - if(jsonContent) - { - let contentJson = JSON.stringify(content, null, 4); - return makeBlob(contentJson, "JSON"); - } - - return null; -} - - -/** @api - * decompressed xnb object to real file blobs. - * @param {XnbData} decompressed xnb objects (returned by bufferToXnb() / Xnb.load()) - * @param {Object} config (yaml:export file as yaml, - * contentOnly:export content file only, - * fileName:exported files's name) (optional) - */ -function exportFiles(xnbObject, {yaml:isYaml=false, contentOnly=false, fileName=null}={}) -{ - // set config - if(isYaml && contentOnly) isYaml = false; - - // ensure we have content field - if (!xnbObject.hasOwnProperty('content')) throw new XnbError('Invalid object!'); - - const blobs = []; - const {content} = xnbObject; - - // export content files - const contentBlob = exportContent(content, contentOnly); - if(contentBlob !== null) blobs.push(contentBlob); - - if(contentOnly) return blobs; - - // export json/yaml header files - const resultJSON = JSON.stringify(xnbObject, (key, value)=>{ - if(key === "export") - { - if(typeof fileName == "string" && fileName !== "") - { - return `${fileName}.${getExtension(value.type)}`; - } - return `${value.type}.${getExtension(value.type)}`; - } - return value; - }, 4); - - let result = resultJSON; - if(isYaml) result=stringifyYaml( toXnbNodeData(xnbObject) ); - - blobs.unshift( makeBlob(result, isYaml ? "yaml" : "JSON") ); - - return blobs; -} - - -function resolveCompression(compressionString) -{ - let str=compressionString.toLowerCase(); - if(str === "none") return 0; - if(str === "lz4") return 0x40; -// if(str === "lzx") return 0x80; - return null; -} - -/** - * @param {Blob/Buffer} input Blob/Buffer - * @return {Promise} promise returns text - */ -async function readBlobasText(blob) -{ - if(typeof Blob === "function" && blob instanceof Blob) return blob.text(); - else if(typeof Buffer === "function" && blob instanceof Buffer) return blob.toString(); -} - -/** - * @param {Blob/Buffer} input Blob/Buffer - * @return {Promise} promise returns text - */ -async function readBlobasArrayBuffer(blob) -{ - if(typeof Blob === "function" && blob instanceof Blob) return blob.arrayBuffer(); - else if(typeof Buffer === "function" && blob instanceof Buffer) return blob.buffer; -} - - -async function readExternFiles(extension, files) -{ - // Texture2D to PNG - if(extension === "png") - { - // get binary file - const rawPng = await readBlobasArrayBuffer(files.png); - // get the png data - const png = fromPNG(new Uint8Array(rawPng) ); - return { - type: "Texture2D", - data: png.data, - width: png.width, - height: png.height - }; - } - - // Compiled Effects - if(extension === "cso") - { - const data = await readBlobasArrayBuffer(files.cso); - return { - type: "Effect", - data - }; - } - - // TBin Map - if(extension === "tbin") - { - const data = await readBlobasArrayBuffer(files.tbin); - return { - type: "TBin", - data - }; - } - - // BmFont Xml - if(extension === "xml") - { - const data = await readBlobasText(files.xml); - return { - type: "BmFont", - data - }; - } -} - - -/** - * file objects to json file to compress. - * @param {Object} to compress files - * @param {Object} config (compression:default, none, LZ4, LZX(currently unsupported)) (optional) - */ -async function resolveImports(files, configs={}) -{ - const {compression="default"} = configs; - - const jsonFile = files.json || files.yaml; - if(!jsonFile) throw new XnbError("There is no JSON or YAML file to pack!"); - - //parse json/yaml data - const rawText = await readBlobasText(jsonFile); - let jsonData = null; - if(files.json) jsonData = JSON.parse(rawText); - else jsonData = fromXnbNodeData( parseYaml(rawText) ); - - // apply configuration data - let compressBits = resolveCompression(compression); - if(compressBits !== null) jsonData.header.compressed = compressBits; - - // need content - if (!jsonData.hasOwnProperty('content')) { - throw new XnbError(`${jsonFile.name} does not have "content".`); - } - - const found = searchElement(jsonData.content, "export"); - - if(found) - { - const {parent, value} = found; - const [,extension] = extractFileName(value); - parent.export = await readExternFiles(extension, files); - } - - return jsonData; -} - - - -export { exportContent, exportFiles, resolveImports, extractFileName, makeBlob }; \ No newline at end of file diff --git a/docs/js/libs/src/Utils/Debug.js b/docs/js/libs/src/Utils/Debug.js deleted file mode 100644 index 4093f29..0000000 --- a/docs/js/libs/src/Utils/Debug.js +++ /dev/null @@ -1,16 +0,0 @@ -function Debug(str, ...args) -{ - if(Debug.__isVisible) console.log(str, ...args); -} - -Debug.__isVisible=false; - -Debug.setVisible=function(state) { - Debug.__isVisible=state; -} - -if(globalThis !== undefined) globalThis.Debug = Debug; // ES2020 -else if(window !== undefined) window.Debug = Debug; // Browser -else if(global !== undefined) global.Debug = Debug; // Node.js - -export default Debug; \ No newline at end of file diff --git a/docs/js/libs/src/Utils/UTF8ToString.js b/docs/js/libs/src/Utils/UTF8ToString.js deleted file mode 100644 index 7ab013c..0000000 --- a/docs/js/libs/src/Utils/UTF8ToString.js +++ /dev/null @@ -1,183 +0,0 @@ -const UTF8_FIRST_BITES=[0xC0, 0xE0, 0xF0]; -const UTF8_SECOND_BITES=0x80; -const UTF8_MASK=0b111111; - -const UTF16_BITES=[0xD800, 0xDC00]; -const UTF16_MASK=0b1111111111; - -function UTF8Encode(code) -{ - //0x0000 ~ 0x007F - if(code < 0x80) return [code]; - - //0x0080 ~ 0x07FF - if(code < 0x800) return [ - UTF8_FIRST_BITES[0] | (code >> 6), - UTF8_SECOND_BITES | (code & UTF8_MASK) - ]; - - //0x0800 ~ 0xFFFF - if(code < 0x10000) return [ - UTF8_FIRST_BITES[1] | (code >> 12), - UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), - UTF8_SECOND_BITES | (code & UTF8_MASK) - ]; - - //0x10000 ~ - return [ - UTF8_FIRST_BITES[2] | (code >> 18), - UTF8_SECOND_BITES | ( (code >> 12) & UTF8_MASK ), - UTF8_SECOND_BITES | ( (code >> 6) & UTF8_MASK ), - UTF8_SECOND_BITES | ( code & UTF8_MASK ) - ]; -} - -function UTF16Encode(code) -{ - //0x0000 ~ 0xFFFF - if(code < 0xFFFF) return [code]; - - //0x10000 ~ - code -= 0x10000; - return [ - UTF16_BITES[0] | ( (code >> 10) & UTF16_MASK ), - UTF16_BITES[1] | ( code & UTF16_MASK ) - ]; -} - -function UTF8Decode(codeSet) -{ - if(typeof codeSet === "number") codeSet=[codeSet]; - if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); - - const codeSetRange = codeSet.length; - - //0x0000 ~ 0x007F - if(codeSetRange === 1) return codeSet[0]; - - //0x0080 ~ 0x07FF - if(codeSetRange === 2) return ((codeSet[0] ^ UTF8_FIRST_BITES[0]) << 6) + (codeSet[1] ^ UTF8_SECOND_BITES); - - //0x0800 ~ 0xFFFF - if(codeSetRange === 3) { - return ( ((codeSet[0] ^ UTF8_FIRST_BITES[1]) << 12) + - ((codeSet[1] ^ UTF8_SECOND_BITES) << 6) + - (codeSet[2] ^ UTF8_SECOND_BITES) ); - } - - //0x10000 ~ - return ( ((codeSet[0] ^ UTF8_FIRST_BITES[2]) << 18) + - ((codeSet[1] ^ UTF8_SECOND_BITES) << 12) + - ((codeSet[2] ^ UTF8_SECOND_BITES) << 6) + - (codeSet[3] ^ UTF8_SECOND_BITES) ); -} - -function UTF16Decode(codeSet) -{ - if(typeof codeSet === "number") codeSet=[codeSet]; - if(!(codeSet?.length) ) throw new Error("Invalid codeset!"); - - const codeSetRange = codeSet.length; - - //0x0000 ~ 0xFFFF - if(codeSetRange === 1) return codeSet[0]; - - //0x10000 ~ - return ((codeSet[0] & UTF16_MASK) << 10) + (codeSet[1] & UTF16_MASK) + 0x10000; -} - -function stringToUnicode(str) -{ - const utf16Map = Array.from({length:str.length}, (_,i)=>str.charCodeAt(i)); - const result=[]; - let index=0; - while(index < str.length) { - let code = utf16Map[index]; - if( (UTF16_BITES[0] & code) !== UTF16_BITES[0] ) { - result.push( code ); - index++; - } - else { - result.push( UTF16Decode(utf16Map.slice(index, index+2)) ); - index+=2; - } - } - return result; -} - -function UTF8ToUnicode(codes) -{ - const dataArray = (codes instanceof ArrayBuffer) ? new Uint8Array(codes) : codes; - - const result=[]; - let index=0; - while(index < dataArray.length) { - let headerCode = dataArray[index]; - if((headerCode & 0x80) === 0) { - result.push(headerCode); - index++; - } - else if(headerCode < UTF8_FIRST_BITES[1]) { - result.push( UTF8Decode(dataArray.slice(index, index+2)) ); - index+=2; - } - else if(headerCode < UTF8_FIRST_BITES[2]) { - result.push( UTF8Decode(dataArray.slice(index, index+3)) ); - index+=3; - } - else{ - result.push( UTF8Decode(dataArray.slice(index, index+4)) ); - index+=4; - } - } - return result; -} - -function UnicodeToUTF8(unicodeArr) -{ - const result = []; - for(let code of unicodeArr) { - result.push(...UTF8Encode(code)); - } - return result; -} - -function UnicodeToString(unicodeArr) -{ - const result = []; - for(let code of unicodeArr) { - result.push(...UTF16Encode(code)); - } - - //for bigger strings - const blockSize = 32768; - let resultStr = ""; - for(let i=0; i{ - if(unicode < 0x80) return sum+1; - if(unicode < 0x800) return sum+2; - if(unicode < 0x10000) return sum+3; - return sum+4; - }, 0); -} - -export {stringToUTF8, UTF8ToString, UTF8Length}; \ No newline at end of file diff --git a/docs/js/libs/src/Utils/XnbError.js b/docs/js/libs/src/Utils/XnbError.js deleted file mode 100644 index 7706111..0000000 --- a/docs/js/libs/src/Utils/XnbError.js +++ /dev/null @@ -1,8 +0,0 @@ -export default class XnbError extends Error { - constructor(message = '') { - super(message); - this.name = this.constructor.name; - this.message = message; - Error.captureStackTrace(this, XnbError); - } -} \ No newline at end of file diff --git a/docs/js/libs/src/Utils/xnbNodeConverter.js b/docs/js/libs/src/Utils/xnbNodeConverter.js deleted file mode 100644 index 09b55e9..0000000 --- a/docs/js/libs/src/Utils/xnbNodeConverter.js +++ /dev/null @@ -1,279 +0,0 @@ -import {simplifyType, getTypeInfo} from "../App/TypeReader.js"; - -function deepCopy(obj) -{ - let newObj; - if(Array.isArray(obj)) - { - newObj=[]; - for(let item of obj) - { - newObj.push(deepCopy(item)); - } - return newObj; - } - - if(!!obj && typeof obj === "object") - { - newObj={}; - for(let [key, value] of Object.entries(obj)) - { - newObj[key] = deepCopy(value); - } - return newObj; - } - - return obj; -} - -function isPrimitiveReaderType(reader) -{ - switch(reader) - { - case 'Boolean': - case 'Int32': - case 'Char': - case 'String': - case '': - - case 'Vector2': - case 'Vector3': - case 'Vector4': - case 'Rectangle': - return true; - default: return false; - } -} - -function isExportReaderType(reader) -{ - switch(reader) - { - case 'Texture2D': - case 'TBin': - case 'Effect': - case 'BmFont': - return true; - default: return false; - } -} - -function convertJsonContentsToXnbNode(raw, readers) -{ - let extractedImages = []; - let extractedMaps = []; - - const {converted} = (function recursiveConvert(obj, path, index=0) - { - const reader = readers[index]; - - //primitive - if(isPrimitiveReaderType(reader)) - { - return { - converted : { type:reader, data:obj }, - traversed : index - }; - } - - //null reader - if(reader === null) - { - return { - converted : obj, - traversed : index - }; - } - - //nullable - if(reader.startsWith('Nullable')) - { - return { - converted: { - type: reader, - data: {data:{ type:readers[index+1], data:obj } } - }, - traversed: index + 1 - }; - } - - //exportable - if(isExportReaderType(reader)) - { - //texture2D - if(reader === 'Texture2D') - { - extractedImages.push( {path:path.join('.')} ); - return { - converted : { type:reader, data:{format : obj.format} }, - traversed : index - }; - } - //tbin - if(reader === 'TBin') - { - extractedMaps.push( {path:path.join('.')} ); - } - return { - converted: { type:reader, data:{} }, - traversed: index - }; - } - - // complex data(list, dictionary, spritefont, etc...) - let data; - if(Array.isArray(obj)) data=[]; - else data={}; - - let traversed = index; - let first = true; - let isComplex = ( !reader.startsWith("Dictionary") && !reader.startsWith("Array") && !reader.startsWith("List") ); - - for(let [key, value] of Object.entries(obj)) - { - let newIndex; - if( reader.startsWith("Dictionary") ) { - if(getTypeInfo(reader).subtypes[1] === readers[index+2]) newIndex = index+2; - else newIndex = index+1; - } - else if( reader.startsWith("Array") || reader.startsWith("List")) newIndex = index+1; - else newIndex = traversed + 1; - - const {converted, traversed:nexter} = recursiveConvert( obj[key], [...path, key], newIndex ); - data[key] = converted; - if(isComplex) traversed = nexter; - else if(first) - { - traversed = nexter; - first = false; - } - } - - return { - converted : { type:reader, data }, - traversed - }; - })(raw, []); - - return { converted, extractedImages, extractedMaps }; -} - -// convert from inner json content of XnbExtract -// remove {type:"aaa" data:"..."} and pick only "..." -function convertJsonContentsFromXnbNode(obj) -{ - if( !obj || typeof obj !== "object" ) return obj; - if(typeof obj === "object" && obj.hasOwnProperty("data")) - { - let {type, data} = obj; - - if(isPrimitiveReaderType(type)) return deepCopy(data); - if(isExportReaderType(type)) - { - data = deepCopy(data); - if(type === "Texture2D") data.export = "Texture2D.png"; - else if(type === "Effect") data.export = "Effect.cso"; - else if(type === "TBin") data.export = "TBin.tbin"; - else if(type === "BmFont") data.export = "BmFont.xml"; - - return data; - } - obj = deepCopy(data); - } - - let newObj; - if(Array.isArray(obj)) - { - newObj=[]; - for(let item of obj) - { - newObj.push(convertJsonContentsFromXnbNode(item)); - } - return newObj; - } - - if(!!obj && typeof obj === "object") - { - newObj={}; - for(let [key, value] of Object.entries(obj)) - { - newObj[key] = convertJsonContentsFromXnbNode(value); - } - return newObj; - } - - return null; -} - -// convert json file to yaml compatible with XnbExtract -function toXnbNodeData(json) -{ - const toYamlJson = {}; - const {compressed, formatVersion, hidef:hiDef, target} = json.header; - let readerData = deepCopy(json.readers); - - // set header - toYamlJson.xnbData = { - target, - compressed:!!compressed, - hiDef, - readerData, - numSharedResources : 0 - }; - - // set contents - const rawContent = deepCopy(json.content); - let readersTypeList = readerData.map( ({type})=>simplifyType(type) ); - if(readersTypeList[0] === 'SpriteFont') - { - readersTypeList = ['SpriteFont', - 'Texture2D', - 'List', 'Rectangle', - 'List', 'Rectangle', - 'List', 'Char', - null, - 'List', 'Vector3', - 'Nullable', 'Char', - null]; - - rawContent.verticalSpacing = rawContent.verticalLineSpacing; - delete rawContent.verticalLineSpacing; - } - - const { converted, extractedImages, extractedMaps } = convertJsonContentsToXnbNode(rawContent, readersTypeList); - - toYamlJson.content = converted; - if(extractedImages.length > 0) toYamlJson.extractedImages = extractedImages; - if(extractedMaps.length > 0) toYamlJson.extractedMaps = extractedMaps; - - return toYamlJson; -} - -function fromXnbNodeData(json) -{ - const result = {}; - - // set header data - const {compressed, readerData, hiDef:hidef, target} = json.xnbData; - result.header = { - target, - formatVersion : 5, - compressed : compressed ? ( (target === 'a' || target === 'i') ? 0x40 : 0x80 ) : 0, - hidef - } - result.readers = deepCopy(readerData); - - // set content data - result.content = convertJsonContentsFromXnbNode(json.content); - - // this program uses verticalLineSpacing, not verticalSpacing - if( simplifyType(result.readers[0].type) === 'SpriteFont' ) - { - result.content.verticalLineSpacing = result.content.verticalSpacing; - delete result.content.verticalSpacing; - } - - return result; -} - -export {toXnbNodeData, fromXnbNodeData}; \ No newline at end of file diff --git a/docs/js/libs/src/XnbUnpacker.js b/docs/js/libs/src/XnbUnpacker.js deleted file mode 100644 index 997d8fe..0000000 --- a/docs/js/libs/src/XnbUnpacker.js +++ /dev/null @@ -1,197 +0,0 @@ -import XnbConverter from "./App/Xnb.js"; -import {XnbData, XnbContent} from "./App/XnbData.js"; -import {exportFiles, exportContent, resolveImports, extractFileName} from "./Files.js"; - -const xnb = new XnbConverterMaker(); - -/*----------------------------------------------------------------------------*/ -/*................................Unpack XNB..................................*/ -/*----------------------------------------------------------------------------*/ - -/** @api - * Asynchronously reads the file into binary and then unpacks the json data. - * XNB -> arrayBuffer -> XnbData - * @param {File / Buffer} file - * @return {XnbData} JSON data with headers - */ -async function unpackToXnbData(file) -{ - // browser - if( typeof window !== "undefined" ) { - // ensure that the input file has the right extension - const [,extension] = extractFileName(file.name); - - if(extension !== "xnb") { - return new Error("Invalid XNB File!"); - } - - //read the file as a binary file - const buffer = await file.arrayBuffer(); - return bufferToXnb(buffer); - } - // node.js - return bufferToXnb(file.buffer); -} - -/** @api - * Asynchronously reads the file into binary and then return content file. - * XNB -> arrayBuffer -> XnbData -> Content - * @param {File / Buffer} file - * @return {XnbContent} exported Content Object - */ -function unpackToContent(file) -{ - return unpackToXnbData(file).then(xnbDataToContent); -} - -/** @api - * Asynchronously reads the file into binary and then unpacks the contents and remake to Blobs array. - * XNB -> arrayBuffer -> XnbData -> Files - * @param {File / Buffer} file - * @param {Object} config (yaml:export file as yaml, contentOnly:export content file only, fileName:file name(for node.js)) - * @return {Array} exported Files Blobs - */ -function unpackToFiles(file, configs={}) -{ - let {yaml=false, contentOnly=false, fileName:name=null} = configs; - if(typeof window !== "undefined" && name === null) name = file.name; - - let [fileName] = extractFileName(name); - const exporter = xnbObject => exportFiles(xnbObject, {yaml, contentOnly, fileName}); - return unpackToXnbData(file).then(exporter); -} - - -/** @api - * reads the buffer and then unpacks. - * arrayBuffer -> XnbData - * @param {ArrayBuffer} buffer - * @return {XnbData} the loaded XNB json - */ -function bufferToXnb(buffer) -{ - const xnb = new XnbConverter(); - return xnb.load(buffer); -} - -/** @api - * reads the buffer and then unpacks the contents. - * arrayBuffer -> XnbData -> Content - * @param {ArrayBuffer} buffer - * @return {XnbContent} exported Content Object - */ -function bufferToContents(buffer) -{ - const xnb = new XnbConverter(); - const xnbData = xnb.load(buffer); - return xnbDataToContent(xnbData); -} - -/** @api - * remove header from the loaded XNB Object - * XnbData -> Content - * @param {XnbData} the loaded XNB object include headers - * @return {XnbContent} exported Content Object - */ -function xnbDataToContent(loadedXnb) -{ - const {content} = loadedXnb; - const {data, extension} = exportContent(content, true); - return new XnbContent(data, extension); -} - - - -/*----------------------------------------------------------------------------*/ -/*.................................Pack XNB...................................*/ -/*----------------------------------------------------------------------------*/ - -/** @api - * reads the json and then unpacks the contents. - * @param {FileList/Array} to pack json data - * @return {Object/Object} packed XNB Array Buffer - */ -function fileMapper(files) -{ - let returnMap = {}; - for(let i=0; i{ - //blob is avaliable - if(typeof Blob === "function") return { - name:fileName, - data:new Blob([buffer], {type : "application/octet-stream"}) - }; - return { - name:fileName, - data:new Uint8Array(buffer) - }; - }) - ); - } - return Promise.allSettled(promises).then(blobArray => { - if(configs.debug === true) return blobArray; - - return blobArray.filter( ({status, value})=>status === "fulfilled" ) - .map( ({value})=>value ); - }); -} - -/*----------------------------------------------------------------------------*/ -/*.........................Additional Reader Plugin...........................*/ -/*----------------------------------------------------------------------------*/ - -export {unpackToXnbData, - unpackToContent, - unpackToFiles, - - bufferToXnb, - bufferToContents, - - xnbDataToContent, - exportFiles as xnbDataToFiles, - pack, - XnbData, - XnbContent -}; diff --git a/docs/js/libs/src/es5.js b/docs/js/libs/src/es5.js deleted file mode 100644 index 08c2d94..0000000 --- a/docs/js/libs/src/es5.js +++ /dev/null @@ -1,7 +0,0 @@ -import "core-js/modules/es.promise.js"; -import "regenerator-runtime/runtime.js"; -import "core-js/modules/es.object.get-own-property-descriptors.js"; -import "core-js/modules/es.function.name.js"; -import "core-js/modules/es.typed-array.map.js"; - -export * from "./XnbUnpacker.js"; \ No newline at end of file diff --git a/docs/js/libs/src/libs/jsonToYaml.js b/docs/js/libs/src/libs/jsonToYaml.js deleted file mode 100644 index 34f4109..0000000 --- a/docs/js/libs/src/libs/jsonToYaml.js +++ /dev/null @@ -1,220 +0,0 @@ -/** - * from https://github.com/draivin/XNBNode - * XnbExtract is using this code to parse yaml - */ - - -function isTypeObject(object) { - return object && object.hasOwnProperty('type') && object.hasOwnProperty('data'); -} -function stringify (o, gap, indentation) { - if(isTypeObject(o)) { - let s = stringify(o.data, gap, indentation); - if(s.includes('\n')) { - return ' #!' + o.type + s; - } else { - return s + ' #!' + o.type; - } - } else if(o && 'object' === typeof o) { - - let isArray = Array.isArray(o); - if(Object.keys(o).length == 0) { - if(isArray) return '[]'; - else return '{}'; - } - - let s = '\n'; - - - for(let k in o) { - if(Object.hasOwnProperty.call(o, k)) { - s += gap.repeat(indentation + 1); - if (isArray) { - s += '- ' + stringify(o[k], gap, indentation + 1); - } else { - if(k.includes(': ')) { - s += stringify(k, gap, indentation + 1); - s += ': ' + stringify(o[k], gap, indentation + 1); - } else { - s += k + ': ' + stringify(o[k], gap, indentation + 1); - } - } - s += '\n'; - } - } - - return s; - } else if ('string' === typeof o) { - return JSON.stringify(o); - } else if ('undefined' === typeof o || o === null) { - return 'null'; - } else if (!!o == o || +o == o) { //boolean & number - return JSON.stringify(o); - } else { - throw new Error('Non-implemented parsing for ' + o); - } -} - -function preStringify(object, space=4) { - var gap = '' - if(typeof space == 'number') { - gap = ' '.repeat(Math.min(10, space)) - } else if(typeof space == 'string') { - gap = space.slice(0, 10) - } - - return stringify(object, gap, -1) -} - -class LineGenerator { - constructor(lines, indentString, startingLine) { - this.startingLine = startingLine || 0; - this.lineIndex = -1; - - let filteredLines = []; - for(let i = 0; i < lines.length; i++) { - let trimmedLine = lines[i].trim(); - if(trimmedLine !== '') { - filteredLines.push([lines[i], i]); - } - } - - this.lines = filteredLines; - - this.indentString = indentString || this.findIndentString(); - } - - getLineNumber() { - return this.startingLine + this.lineIndex; - } - - nextGroup() { - let lines = []; - let baseIndent = this.indentLevel(this.lineIndex + 1); - - while(!this.finished() && this.indentLevel(this.lineIndex + 1) >= baseIndent) { - lines.push(this.next()); - } - - return new LineGenerator(lines, this.indentString, this.getLineNumber() - lines.length); - } - - next() { - if(this.finished()) throw new Error('Trying to next finished generator'); - this.lineIndex++; - return this.getLine(); - } - - peek() { - return this.getLine(this.lineIndex + 1); - } - - finished() { - return this.lineIndex == this.lines.length - 1; - } - - getLine(index) { - index = (index !== undefined) ? index : this.lineIndex; - if(index >= this.lines.length) return null; - return this.lines[index][0]; - } - - findIndentString() { - for(let [line] of this.lines) { - if(!line.trim() || line.replace(/^\s+/,"") == line) continue; - return line.match(/^(\s+)/)[1]; - } - - return ''; - } - - indentLevel(index) { - index = (index !== undefined) ? index : this.lineIndex; - if(index < 0) index = 0; - let indentLevel = 0; - let line = this.getLine(index); - - while(line.startsWith(this.indentString)) { - line = line.slice(this.indentString.length); - indentLevel++; - } - - return indentLevel; - } -} - -function getObject(lineGroup, type) { - let object; - - let baseIndent = lineGroup.indentLevel(); - - while(!lineGroup.finished()) { - let line = lineGroup.next() - let trimmedLine = line.trim(); - - let keyMatch = trimmedLine.match(/^(.*?):(?: |$)/); - let typeMatch = trimmedLine.match(/#!([\w<,>]+)/); - let key, value, type; - - if(trimmedLine.startsWith('"')) { - keyMatch = trimmedLine.match(/^"(.*?)":(?: |$)/); - } - - if(typeMatch) { - type = typeMatch[1]; - trimmedLine = trimmedLine.replace(typeMatch[0], ''); - } - - if(keyMatch) { - if(!object) object = {}; - - key = keyMatch[1]; - value = trimmedLine.replace(keyMatch[0], '').trim(); - } else if(trimmedLine.startsWith('-')) { - if(!object) object = []; - value = trimmedLine.slice(1).trim(); - } - - if(value) { - value = getValue(value, type); - } else { - value = getObject(lineGroup.nextGroup(), type); - } - - if(Array.isArray(object)) { - object.push(value); - } else { - object[key] = value; - } - } - - if(type) { - object = { - type: type, - data: object - }; - } - - return object; -} - -function getValue(value, type) { - value = JSON.parse(value); - if(type) { - value = { - type: type, - data: value - }; - } - - return value; -} - -function parse(str) { - let lines = str.replace(/\t/g, ' ').split('\n'); - let lineGenerator = new LineGenerator(lines); - - return getObject(lineGenerator); -} - -export {preStringify as stringifyYaml, parse as parseYaml}; \ No newline at end of file diff --git a/docs/js/libs/src/libs/png.js b/docs/js/libs/src/libs/png.js deleted file mode 100644 index 32cbf23..0000000 --- a/docs/js/libs/src/libs/png.js +++ /dev/null @@ -1 +0,0 @@ -var t={396:function(){!function(t){if(t.TextEncoder&&t.TextDecoder)return!1;function e(t="utf-8"){if("utf-8"!==t)throw new RangeError(`Failed to construct 'TextEncoder': The encoding label provided ('${t}') is invalid.`)}function i(t="utf-8",e={fatal:!1}){if("utf-8"!==t)throw new RangeError(`Failed to construct 'TextDecoder': The encoding label provided ('${t}') is invalid.`);if(e.fatal)throw new Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.")}Object.defineProperty(e.prototype,"encoding",{value:"utf-8"}),e.prototype.encode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to encode: the 'stream' option is unsupported.");let i=0;const n=t.length;let r=0,s=Math.max(32,n+(n>>1)+7),a=new Uint8Array(s>>3<<3);for(;i=55296&&e<=56319){if(i=55296&&e<=56319)continue}if(r+4>a.length){s+=8,s*=1+i/t.length*2,s=s>>3<<3;const e=new Uint8Array(s);e.set(a),a=e}if(0!=(4294967168&e)){if(0==(4294965248&e))a[r++]=e>>6&31|192;else if(0==(4294901760&e))a[r++]=e>>12&15|224,a[r++]=e>>6&63|128;else{if(0!=(4292870144&e))continue;a[r++]=e>>18&7|240,a[r++]=e>>12&63|128,a[r++]=e>>6&63|128}a[r++]=63&e|128}else a[r++]=e}return a.slice(0,r)},Object.defineProperty(i.prototype,"encoding",{value:"utf-8"}),Object.defineProperty(i.prototype,"fatal",{value:!1}),Object.defineProperty(i.prototype,"ignoreBOM",{value:!1}),i.prototype.decode=function(t,e={stream:!1}){if(e.stream)throw new Error("Failed to decode: the 'stream' option is unsupported.");const i=new Uint8Array(t);let n=0;const r=i.length,s=[];for(;n65535&&(e-=65536,s.push(e>>>10&1023|55296),e=56320|1023&e),s.push(e)}}return String.fromCharCode.apply(null,s)},t.TextEncoder=e,t.TextDecoder=i}("undefined"!=typeof window?window:"undefined"!=typeof self?self:this)}},e={};function i(n){var r=e[n];if(void 0!==r)return r.exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,i),s.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};(()=>{i.d(n,{P:()=>Mi,m:()=>Fi}),i(396);const t=new TextDecoder("utf-8"),e=new TextEncoder;class r{constructor(t=8192,e={}){let i=!1;"number"==typeof t?t=new ArrayBuffer(t):(i=!0,this.lastWrittenByte=t.byteLength);const n=e.offset?e.offset>>>0:0,s=t.byteLength-n;let a=n;(ArrayBuffer.isView(t)||t instanceof r)&&(t.byteLength!==t.buffer.byteLength&&(a=t.byteOffset+n),t=t.buffer),this.lastWrittenByte=i?s:0,this.buffer=t,this.length=s,this.byteLength=s,this.byteOffset=a,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,a,s),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){const e=new Uint8Array(t);for(let i=0;ithis.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function s(t){let e=t.length;for(;--e>=0;)t[e]=0}const a=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),o=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),h=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),l=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),d=new Array(576);s(d);const _=new Array(60);s(_);const f=new Array(512);s(f);const c=new Array(256);s(c);const u=new Array(29);s(u);const w=new Array(30);function p(t,e,i,n,r){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=t&&t.length}let g,b,m;function k(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}s(w);const y=t=>t<256?f[t]:f[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},E=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<{E(t,i[2*e],i[2*e+1])},x=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},U=(t,e,i)=>{const n=new Array(16);let r,s,a=0;for(r=1;r<=15;r++)n[r]=a=a+i[r-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=x(n[e]++,e))}},z=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},R=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},N=(t,e,i,n)=>{const r=2*e,s=2*i;return t[r]{const n=t.heap[i];let r=i<<1;for(;r<=t.heap_len&&(r{let n,r,s,h,l=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*l]<<8|t.pending_buf[t.d_buf+2*l+1],r=t.pending_buf[t.l_buf+l],l++,0===n?A(t,r,e):(s=c[r],A(t,s+256+1,e),h=a[s],0!==h&&(r-=u[s],E(t,r,h)),n--,s=y(n),A(t,s,i),h=o[s],0!==h&&(n-=w[s],E(t,n,h)))}while(l{const i=e.dyn_tree,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=573,a=0;a>1;a>=1;a--)T(t,i,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],T(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,i[2*h]=i[2*a]+i[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,i[2*a+1]=i[2*o+1]=h,t.heap[1]=h++,T(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,n=e.max_code,r=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,d,_,f,c,u,w=0;for(f=0;f<=15;f++)t.bl_count[f]=0;for(i[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)d=t.heap[l],f=i[2*i[2*d+1]+1]+1,f>h&&(f=h,w++),i[2*d+1]=f,d>n||(t.bl_count[f]++,c=0,d>=o&&(c=a[d-o]),u=i[2*d],t.opt_len+=u*(f+c),s&&(t.static_len+=u*(r[2*d+1]+c)));if(0!==w){do{for(f=h-1;0===t.bl_count[f];)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[h]--,w-=2}while(w>0);for(f=h;0!==f;f--)for(d=t.bl_count[f];0!==d;)_=t.heap[--l],_>n||(i[2*_+1]!==f&&(t.opt_len+=(f-i[2*_+1])*i[2*_],i[2*_+1]=f),d--)}})(t,e),U(i,l,t.bl_count)},B=(t,e,i)=>{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(i+1)+1]=65535,n=0;n<=i;n++)r=a,a=e[2*(n+1)+1],++o{let n,r,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),n=0;n<=i;n++)if(r=a,a=e[2*(n+1)+1],!(++o{E(t,0+(n?1:0),3),((t,e,i,n)=>{R(t),v(t,i),v(t,~i),t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i})(t,e,i)};var S={_tr_init:t=>{D||((()=>{let t,e,i,n,r;const s=new Array(16);for(i=0,n=0;n<28;n++)for(u[n]=i,t=0;t<1<>=7;n<30;n++)for(w[n]=r<<7,t=0;t<1<{let r,s,a=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),L(t,t.l_desc),L(t,t.d_desc),a=(t=>{let e;for(B(t,t.dyn_ltree,t.l_desc.max_code),B(t,t.dyn_dtree,t.d_desc.max_code),L(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*l[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&-1!==e?I(t,e,i,n):4===t.strategy||s===r?(E(t,2+(n?1:0),3),O(t,d,_)):(E(t,4+(n?1:0),3),((t,e,i,n)=>{let r;for(E(t,e-257,5),E(t,i-1,5),E(t,n-4,4),r=0;r(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&i,t.last_lit++,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(c[i]+256+1)]++,t.dyn_dtree[2*y(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{E(t,2,3),A(t,256,d),(t=>{16===t.bi_valid?(v(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}},Z=(t,e,i,n)=>{let r=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{r=r+e[n++]|0,s=s+r|0}while(--a);r%=65521,s%=65521}return r|s<<16|0};const F=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var n=0;n<8;n++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var M=(t,e,i,n)=>{const r=F,s=n+i;t^=-1;for(let i=n;i>>8^r[255&(t^e[i])];return-1^t},P={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},H={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:W,_tr_stored_block:K,_tr_flush_block:$,_tr_tally:Y,_tr_align:j}=S,{Z_NO_FLUSH:G,Z_PARTIAL_FLUSH:X,Z_FULL_FLUSH:V,Z_FINISH:q,Z_BLOCK:J,Z_OK:Q,Z_STREAM_END:tt,Z_STREAM_ERROR:et,Z_DATA_ERROR:it,Z_BUF_ERROR:nt,Z_DEFAULT_COMPRESSION:rt,Z_FILTERED:st,Z_HUFFMAN_ONLY:at,Z_RLE:ot,Z_FIXED:ht,Z_DEFAULT_STRATEGY:lt,Z_UNKNOWN:dt,Z_DEFLATED:_t}=H,ft=258,ct=262,ut=103,wt=113,pt=666,gt=(t,e)=>(t.msg=P[e],e),bt=t=>(t<<1)-(t>4?9:0),mt=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let kt=(t,e,i)=>(e<{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},vt=(t,e)=>{$(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,yt(t.strm)},Et=(t,e)=>{t.pending_buf[t.pending++]=e},At=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},xt=(t,e,i,n)=>{let r=t.avail_in;return r>n&&(r=n),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),i),1===t.state.wrap?t.adler=Z(t.adler,e,r,i):2===t.state.wrap&&(t.adler=M(t.adler,e,r,i)),t.next_in+=r,t.total_in+=r,r)},Ut=(t,e)=>{let i,n,r=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-ct?t.strstart-(t.w_size-ct):0,l=t.window,d=t.w_mask,_=t.prev,f=t.strstart+ft;let c=l[s+a-1],u=l[s+a];t.prev_length>=t.good_match&&(r>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,l[i+a]===u&&l[i+a-1]===c&&l[i]===l[s]&&l[++i]===l[s+1]){s+=2,i++;do{}while(l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&l[++s]===l[++i]&&sa){if(t.match_start=e,a=n,n>=o)break;c=l[s+a-1],u=l[s+a]}}}while((e=_[e&d])>h&&0!=--r);return a<=t.lookahead?a:t.lookahead},zt=t=>{const e=t.w_size;let i,n,r,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-ct)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,i=n;do{r=t.head[--i],t.head[i]=r>=e?r-e:0}while(--n);n=e,i=n;do{r=t.prev[--i],t.prev[i]=r>=e?r-e:0}while(--n);s+=e}if(0===t.strm.avail_in)break;if(n=xt(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=n,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=kt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=kt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead{let i,n;for(;;){if(t.lookahead=3&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-ct&&(t.match_length=Ut(t,i)),t.match_length>=3)if(n=Y(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=kt(t,t.ins_h,t.window[t.strstart+1]);else n=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2},Nt=(t,e)=>{let i,n,r;for(;;){if(t.lookahead=3&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==i&&t.prev_length4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,n=Y(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=kt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,n&&(vt(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(n=Y(t,0,t.window[t.strstart-1]),n&&vt(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=Y(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2};function Tt(t,e,i,n,r){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=n,this.func=r}const Ot=[new Tt(0,0,0,0,((t,e)=>{let i=65535;for(i>t.pending_buf_size-5&&(i=t.pending_buf_size-5);;){if(t.lookahead<=1){if(zt(t),0===t.lookahead&&e===G)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const n=t.block_start+i;if((0===t.strstart||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,vt(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-ct&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(vt(t,!1),t.strm.avail_out),1)})),new Tt(4,4,8,4,Rt),new Tt(4,5,16,8,Rt),new Tt(4,6,32,32,Rt),new Tt(4,4,16,16,Nt),new Tt(8,16,32,32,Nt),new Tt(8,16,128,128,Nt),new Tt(8,32,128,256,Nt),new Tt(32,128,258,1024,Nt),new Tt(32,258,258,4096,Nt)];function Lt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=_t,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),mt(this.dyn_ltree),mt(this.dyn_dtree),mt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),mt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),mt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Bt=t=>{if(!t||!t.state)return gt(t,et);t.total_in=t.total_out=0,t.data_type=dt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:wt,t.adler=2===e.wrap?0:1,e.last_flush=G,W(e),Q},Ct=t=>{const e=Bt(t);var i;return e===Q&&((i=t.state).window_size=2*i.w_size,mt(i.head),i.max_lazy_match=Ot[i.level].max_lazy,i.good_match=Ot[i.level].good_length,i.nice_match=Ot[i.level].nice_length,i.max_chain_length=Ot[i.level].max_chain,i.strstart=0,i.block_start=0,i.lookahead=0,i.insert=0,i.match_length=i.prev_length=2,i.match_available=0,i.ins_h=0),e},Dt=(t,e,i,n,r,s)=>{if(!t)return et;let a=1;if(e===rt&&(e=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>9||i!==_t||n<8||n>15||e<0||e>9||s<0||s>ht)return gt(t,et);8===n&&(n=9);const o=new Lt;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<t&&t.state?2!==t.state.wrap?et:(t.state.gzhead=e,Q):et,Zt=(t,e)=>{let i,n;if(!t||!t.state||e>J||e<0)return t?gt(t,et):et;const r=t.state;if(!t.output||!t.input&&0!==t.avail_in||r.status===pt&&e!==q)return gt(t,0===t.avail_out?nt:et);r.strm=t;const s=r.last_flush;if(r.last_flush=e,42===r.status)if(2===r.wrap)t.adler=0,Et(r,31),Et(r,139),Et(r,8),r.gzhead?(Et(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Et(r,255&r.gzhead.time),Et(r,r.gzhead.time>>8&255),Et(r,r.gzhead.time>>16&255),Et(r,r.gzhead.time>>24&255),Et(r,9===r.level?2:r.strategy>=at||r.level<2?4:0),Et(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Et(r,255&r.gzhead.extra.length),Et(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=M(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69):(Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,0),Et(r,9===r.level?2:r.strategy>=at||r.level<2?4:0),Et(r,3),r.status=wt);else{let e=_t+(r.w_bits-8<<4)<<8,i=-1;i=r.strategy>=at||r.level<2?0:r.level<6?1:6===r.level?2:3,e|=i<<6,0!==r.strstart&&(e|=32),e+=31-e%31,r.status=wt,At(r,e),0!==r.strstart&&(At(r,t.adler>>>16),At(r,65535&t.adler)),t.adler=1}if(69===r.status)if(r.gzhead.extra){for(i=r.pending;r.gzindex<(65535&r.gzhead.extra.length)&&(r.pending!==r.pending_buf_size||(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending!==r.pending_buf_size));)Et(r,255&r.gzhead.extra[r.gzindex]),r.gzindex++;r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex===r.gzhead.extra.length&&(r.gzindex=0,r.status=73)}else r.status=73;if(73===r.status)if(r.gzhead.name){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.gzindex=0,r.status=91)}else r.status=91;if(91===r.status)if(r.gzhead.comment){i=r.pending;do{if(r.pending===r.pending_buf_size&&(r.gzhead.hcrc&&r.pending>i&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),yt(t),i=r.pending,r.pending===r.pending_buf_size)){n=1;break}n=r.gzindexi&&(t.adler=M(t.adler,r.pending_buf,r.pending-i,i)),0===n&&(r.status=ut)}else r.status=ut;if(r.status===ut&&(r.gzhead.hcrc?(r.pending+2>r.pending_buf_size&&yt(t),r.pending+2<=r.pending_buf_size&&(Et(r,255&t.adler),Et(r,t.adler>>8&255),t.adler=0,r.status=wt)):r.status=wt),0!==r.pending){if(yt(t),0===t.avail_out)return r.last_flush=-1,Q}else if(0===t.avail_in&&bt(e)<=bt(s)&&e!==q)return gt(t,nt);if(r.status===pt&&0!==t.avail_in)return gt(t,nt);if(0!==t.avail_in||0!==r.lookahead||e!==G&&r.status!==pt){let i=r.strategy===at?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(zt(t),0===t.lookahead)){if(e===G)return 1;break}if(t.match_length=0,i=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(r,e):r.strategy===ot?((t,e)=>{let i,n,r,s;const a=t.window;for(;;){if(t.lookahead<=ft){if(zt(t),t.lookahead<=ft&&e===G)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=t.strstart+ft;do{}while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&rt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=Y(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=Y(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(vt(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===q?(vt(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(vt(t,!1),0===t.strm.avail_out)?1:2})(r,e):Ot[r.level].func(r,e);if(3!==i&&4!==i||(r.status=pt),1===i||3===i)return 0===t.avail_out&&(r.last_flush=-1),Q;if(2===i&&(e===X?j(r):e!==J&&(K(r,0,0,!1),e===V&&(mt(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),yt(t),0===t.avail_out))return r.last_flush=-1,Q}return e!==q?Q:r.wrap<=0?tt:(2===r.wrap?(Et(r,255&t.adler),Et(r,t.adler>>8&255),Et(r,t.adler>>16&255),Et(r,t.adler>>24&255),Et(r,255&t.total_in),Et(r,t.total_in>>8&255),Et(r,t.total_in>>16&255),Et(r,t.total_in>>24&255)):(At(r,t.adler>>>16),At(r,65535&t.adler)),yt(t),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?Q:tt)},Ft=t=>{if(!t||!t.state)return et;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&e!==ut&&e!==wt&&e!==pt?gt(t,et):(t.state=null,e===wt?gt(t,it):Q)},Mt=(t,e)=>{let i=e.length;if(!t||!t.state)return et;const n=t.state,r=n.wrap;if(2===r||1===r&&42!==n.status||n.lookahead)return et;if(1===r&&(t.adler=Z(t.adler,e,i,0)),n.wrap=0,i>=n.w_size){0===r&&(mt(n.head),n.strstart=0,n.block_start=0,n.insert=0);let t=new Uint8Array(n.w_size);t.set(e.subarray(i-n.w_size,i),0),e=t,i=n.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,zt(n);n.lookahead>=3;){let t=n.strstart,e=n.lookahead-2;do{n.ins_h=kt(n,n.ins_h,n.window[t+3-1]),n.prev[t&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=t,t++}while(--e);n.strstart=t,n.lookahead=2,zt(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,n.wrap=r,Q};const Pt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Ht=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)Pt(i,e)&&(t[e]=i[e])}}return t},Wt=t=>{let e=0;for(let i=0,n=t.length;i=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;$t[254]=$t[254]=1;var Yt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,n,r,s,a=t.length,o=0;for(r=0;r>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},jt=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let n,r;const s=new Array(2*i);for(r=0,n=0;n4)s[r++]=65533,n+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&n1?s[r++]=65533:e<65536?s[r++]=e:(e-=65536,s[r++]=55296|e>>10&1023,s[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Kt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let n=0;n{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+$t[t[i]]>e?i:e},Xt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Vt=Object.prototype.toString,{Z_NO_FLUSH:qt,Z_SYNC_FLUSH:Jt,Z_FULL_FLUSH:Qt,Z_FINISH:te,Z_OK:ee,Z_STREAM_END:ie,Z_DEFAULT_COMPRESSION:ne,Z_DEFAULT_STRATEGY:re,Z_DEFLATED:se}=H;function ae(t){this.options=Ht({level:ne,method:se,chunkSize:16384,windowBits:15,memLevel:8,strategy:re},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Xt,this.strm.avail_out=0;let i=It(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==ee)throw new Error(P[i]);if(e.header&&St(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Yt(e.dictionary):"[object ArrayBuffer]"===Vt.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=Mt(this.strm,t),i!==ee)throw new Error(P[i]);this._dict_set=!0}}function oe(t,e){const i=new ae(e);if(i.push(t,!0),i.err)throw i.msg||P[i.err];return i.result}ae.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize;let r,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?te:qt,"string"==typeof t?i.input=Yt(t):"[object ArrayBuffer]"===Vt.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(s===Jt||s===Qt)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(r=Zt(i,s),r===ie)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),r=Ft(this.strm),this.onEnd(r),this.ended=!0,r===ee;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},ae.prototype.onData=function(t){this.chunks.push(t)},ae.prototype.onEnd=function(t){t===ee&&(this.result=Wt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var he={Deflate:ae,deflate:oe,deflateRaw:function(t,e){return(e=e||{}).raw=!0,oe(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,oe(t,e)},constants:H},le=function(t,e){let i,n,r,s,a,o,h,l,d,_,f,c,u,w,p,g,b,m,k,y,v,E,A,x;const U=t.state;i=t.next_in,A=t.input,n=i+(t.avail_in-5),r=t.next_out,x=t.output,s=r-(e-t.avail_out),a=r+(t.avail_out-257),o=U.dmax,h=U.wsize,l=U.whave,d=U.wnext,_=U.window,f=U.hold,c=U.bits,u=U.lencode,w=U.distcode,p=(1<>>24,f>>>=m,c-=m,m=b>>>16&255,0===m)x[r++]=65535&b;else{if(!(16&m)){if(0==(64&m)){b=u[(65535&b)+(f&(1<>>=m,c-=m),c<15&&(f+=A[i++]<>>24,f>>>=m,c-=m,m=b>>>16&255,!(16&m)){if(0==(64&m)){b=w[(65535&b)+(f&(1<o){t.msg="invalid distance too far back",U.mode=30;break t}if(f>>>=m,c-=m,m=r-s,y>m){if(m=y-m,m>l&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(v=0,E=_,0===d){if(v+=h-m,m2;)x[r++]=E[v++],x[r++]=E[v++],x[r++]=E[v++],k-=3;k&&(x[r++]=E[v++],k>1&&(x[r++]=E[v++]))}else{v=r-y;do{x[r++]=x[v++],x[r++]=x[v++],x[r++]=x[v++],k-=3}while(k>2);k&&(x[r++]=x[v++],k>1&&(x[r++]=x[v++]))}break}}break}}while(i>3,i-=k,c-=k<<3,f&=(1<{const h=o.bits;let l,d,_,f,c,u,w=0,p=0,g=0,b=0,m=0,k=0,y=0,v=0,E=0,A=0,x=null,U=0;const z=new Uint16Array(16),R=new Uint16Array(16);let N,T,O,L=null,B=0;for(w=0;w<=15;w++)z[w]=0;for(p=0;p=1&&0===z[b];b--);if(m>b&&(m=b),0===b)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(g=1;g0&&(0===t||1!==b))return-1;for(R[1]=0,w=1;w<15;w++)R[w+1]=R[w]+z[w];for(p=0;p852||2===t&&E>592)return 1;for(;;){N=w-y,a[p]u?(T=L[B+a[p]],O=x[U+a[p]]):(T=96,O=0),l=1<>y)+d]=N<<24|T<<16|O|0}while(0!==d);for(l=1<>=1;if(0!==l?(A&=l-1,A+=l):A=0,p++,0==--z[w]){if(w===b)break;w=e[i+a[p]]}if(w>m&&(A&f)!==_){for(0===y&&(y=m),c+=g,k=w-y,v=1<852||2===t&&E>592)return 1;_=A&f,r[_]=m<<24|k<<16|c-s|0}}return 0!==A&&(r[c+A]=w-y<<24|64<<16|0),o.bits=m,0};const{Z_FINISH:we,Z_BLOCK:pe,Z_TREES:ge,Z_OK:be,Z_STREAM_END:me,Z_NEED_DICT:ke,Z_STREAM_ERROR:ye,Z_DATA_ERROR:ve,Z_MEM_ERROR:Ee,Z_BUF_ERROR:Ae,Z_DEFLATED:xe}=H,Ue=12,ze=30,Re=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function Ne(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Te=t=>{if(!t||!t.state)return ye;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,be},Oe=t=>{if(!t||!t.state)return ye;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,Te(t)},Le=(t,e)=>{let i;if(!t||!t.state)return ye;const n=t.state;return e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?ye:(null!==n.window&&n.wbits!==e&&(n.window=null),n.wrap=i,n.wbits=e,Oe(t))},Be=(t,e)=>{if(!t)return ye;const i=new Ne;t.state=i,i.window=null;const n=Le(t,e);return n!==be&&(t.state=null),n};let Ce,De,Ie=!0;const Se=t=>{if(Ie){Ce=new Int32Array(512),De=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(ue(1,t.lens,0,288,Ce,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;ue(2,t.lens,0,32,De,0,t.work,{bits:5}),Ie=!1}t.lencode=Ce,t.lenbits=9,t.distcode=De,t.distbits=5},Ze=(t,e,i,n)=>{let r;const s=t.state;return null===s.window&&(s.wsize=1<=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),s.window.set(e.subarray(i-n,i-n+r),s.wnext),(n-=r)?(s.window.set(e.subarray(i-n,i),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave{let i,n,r,s,a,o,h,l,d,_,f,c,u,w,p,g,b,m,k,y,v,E,A=0;const x=new Uint8Array(4);let U,z;const R=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return ye;i=t.state,i.mode===Ue&&(i.mode=13),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,_=o,f=h,E=be;t:for(;;)switch(i.mode){case 1:if(0===i.wrap){i.mode=13;break}for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=M(i.check,x,2,0),l=0,d=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=ze;break}if((15&l)!==xe){t.msg="unknown compression method",i.mode=ze;break}if(l>>>=4,d-=4,v=8+(15&l),0===i.wbits)i.wbits=v;else if(v>i.wbits){t.msg="invalid window size",i.mode=ze;break}i.dmax=1<>8&1),512&i.flags&&(x[0]=255&l,x[1]=l>>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0,i.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>8&255,x[2]=l>>>16&255,x[3]=l>>>24&255,i.check=M(i.check,x,4,0)),l=0,d=0,i.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>8),512&i.flags&&(x[0]=255&l,x[1]=l>>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0,i.mode=5;case 5:if(1024&i.flags){for(;d<16;){if(0===o)break t;o--,l+=n[s++]<>>8&255,i.check=M(i.check,x,2,0)),l=0,d=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&(c=i.length,c>o&&(c=o),c&&(i.head&&(v=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(s,s+c),v)),512&i.flags&&(i.check=M(i.check,n,c,s)),o-=c,s+=c,i.length-=c),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break t;c=0;do{v=n[s+c++],i.head&&v&&i.length<65536&&(i.head.name+=String.fromCharCode(v))}while(v&&c>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=Ue;break;case 10:for(;d<32;){if(0===o)break t;o--,l+=n[s++]<>>=7&d,d-=7&d,i.mode=27;break}for(;d<3;){if(0===o)break t;o--,l+=n[s++]<>>=1,d-=1,3&l){case 0:i.mode=14;break;case 1:if(Se(i),i.mode=20,e===ge){l>>>=2,d-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=ze}l>>>=2,d-=2;break;case 14:for(l>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,l+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",i.mode=ze;break}if(i.length=65535&l,l=0,d=0,i.mode=15,e===ge)break t;case 15:i.mode=16;case 16:if(c=i.length,c){if(c>o&&(c=o),c>h&&(c=h),0===c)break t;r.set(n.subarray(s,s+c),a),o-=c,s+=c,h-=c,a+=c,i.length-=c;break}i.mode=Ue;break;case 17:for(;d<14;){if(0===o)break t;o--,l+=n[s++]<>>=5,d-=5,i.ndist=1+(31&l),l>>>=5,d-=5,i.ncode=4+(15&l),l>>>=4,d-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=ze;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,d-=3}for(;i.have<19;)i.lens[R[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,U={bits:i.lenbits},E=ue(0,i.lens,0,19,i.lencode,0,i.work,U),i.lenbits=U.bits,E){t.msg="invalid code lengths set",i.mode=ze;break}i.have=0,i.mode=19;case 19:for(;i.have>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=p,d-=p,i.lens[i.have++]=b;else{if(16===b){for(z=p+2;d>>=p,d-=p,0===i.have){t.msg="invalid bit length repeat",i.mode=ze;break}v=i.lens[i.have-1],c=3+(3&l),l>>>=2,d-=2}else if(17===b){for(z=p+3;d>>=p,d-=p,v=0,c=3+(7&l),l>>>=3,d-=3}else{for(z=p+7;d>>=p,d-=p,v=0,c=11+(127&l),l>>>=7,d-=7}if(i.have+c>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=ze;break}for(;c--;)i.lens[i.have++]=v}}if(i.mode===ze)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=ze;break}if(i.lenbits=9,U={bits:i.lenbits},E=ue(1,i.lens,0,i.nlen,i.lencode,0,i.work,U),i.lenbits=U.bits,E){t.msg="invalid literal/lengths set",i.mode=ze;break}if(i.distbits=6,i.distcode=i.distdyn,U={bits:i.distbits},E=ue(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,U),i.distbits=U.bits,E){t.msg="invalid distances set",i.mode=ze;break}if(i.mode=20,e===ge)break t;case 20:i.mode=21;case 21:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=l,i.bits=d,le(t,f),a=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,o=t.avail_in,l=i.hold,d=i.bits,i.mode===Ue&&(i.back=-1);break}for(i.back=0;A=i.lencode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,i.length=b,0===g){i.mode=26;break}if(32&g){i.back=-1,i.mode=Ue;break}if(64&g){t.msg="invalid literal/length code",i.mode=ze;break}i.extra=15&g,i.mode=22;case 22:if(i.extra){for(z=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;A=i.distcode[l&(1<>>24,g=A>>>16&255,b=65535&A,!(p<=d);){if(0===o)break t;o--,l+=n[s++]<>m)],p=A>>>24,g=A>>>16&255,b=65535&A,!(m+p<=d);){if(0===o)break t;o--,l+=n[s++]<>>=m,d-=m,i.back+=m}if(l>>>=p,d-=p,i.back+=p,64&g){t.msg="invalid distance code",i.mode=ze;break}i.offset=b,i.extra=15&g,i.mode=24;case 24:if(i.extra){for(z=i.extra;d>>=i.extra,d-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=ze;break}i.mode=25;case 25:if(0===h)break t;if(c=f-h,i.offset>c){if(c=i.offset-c,c>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=ze;break}c>i.wnext?(c-=i.wnext,u=i.wsize-c):u=i.wnext-c,c>i.length&&(c=i.length),w=i.window}else w=r,u=a-i.offset,c=i.length;c>h&&(c=h),h-=c,i.length-=c;do{r[a++]=w[u++]}while(--c);0===i.length&&(i.mode=21);break;case 26:if(0===h)break t;r[a++]=i.length,h--,i.mode=21;break;case 27:if(i.wrap){for(;d<32;){if(0===o)break t;o--,l|=n[s++]<{if(!t||!t.state)return ye;let e=t.state;return e.window&&(e.window=null),t.state=null,be},We=(t,e)=>{if(!t||!t.state)return ye;const i=t.state;return 0==(2&i.wrap)?ye:(i.head=e,e.done=!1,be)},Ke=(t,e)=>{const i=e.length;let n,r,s;return t&&t.state?(n=t.state,0!==n.wrap&&11!==n.mode?ye:11===n.mode&&(r=1,r=Z(r,e,i,0),r!==n.check)?ve:(s=Ze(t,e,i,i),s?(n.mode=31,Ee):(n.havedict=1,be))):ye},$e=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Ye=Object.prototype.toString,{Z_NO_FLUSH:je,Z_FINISH:Ge,Z_OK:Xe,Z_STREAM_END:Ve,Z_NEED_DICT:qe,Z_STREAM_ERROR:Je,Z_DATA_ERROR:Qe,Z_MEM_ERROR:ti}=H;function ei(t){this.options=Ht({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Xt,this.strm.avail_out=0;let i=Me(this.strm,e.windowBits);if(i!==Xe)throw new Error(P[i]);if(this.header=new $e,We(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Yt(e.dictionary):"[object ArrayBuffer]"===Ye.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=Ke(this.strm,e.dictionary),i!==Xe)))throw new Error(P[i])}function ii(t,e){const i=new ei(e);if(i.push(t),i.err)throw i.msg||P[i.err];return i.result}ei.prototype.push=function(t,e){const i=this.strm,n=this.options.chunkSize,r=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Ge:je,"[object ArrayBuffer]"===Ye.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),s=Pe(i,a),s===qe&&r&&(s=Ke(i,r),s===Xe?s=Pe(i,a):s===Qe&&(s=qe));i.avail_in>0&&s===Ve&&i.state.wrap>0&&0!==t[i.next_in];)Fe(i),s=Pe(i,a);switch(s){case Je:case Qe:case qe:case ti:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===Ve))if("string"===this.options.to){let t=Gt(i.output,i.next_out),e=i.next_out-t,r=jt(i.output,t);i.next_out=e,i.avail_out=n-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(r)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==Xe||0!==o){if(s===Ve)return s=He(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},ei.prototype.onData=function(t){this.chunks.push(t)},ei.prototype.onEnd=function(t){t===Xe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Wt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var ni={Inflate:ei,inflate:ii,inflateRaw:function(t,e){return(e=e||{}).raw=!0,ii(t,e)},ungzip:ii,constants:H};const{Deflate:ri,deflate:si,deflateRaw:ai,gzip:oi}=he,{Inflate:hi,inflate:li,inflateRaw:di,ungzip:_i}=ni;var fi=si,ci=hi,ui=li;const wi=[137,80,78,71,13,10,26,10],pi=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;pi[t]=e}const gi=4294967295;function bi(t,e){return(function(t,e,i){let n=4294967295;for(let t=0;t>>8;return n}(0,t,e)^gi)>>>0}var mi,ki,yi,vi;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(mi||(mi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(ki||(ki={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(yi||(yi={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(vi||(vi={}));const Ei=new Uint8Array(0),Ai=new Uint16Array([255]),xi=255===new Uint8Array(Ai.buffer)[0];class Ui extends r{constructor(t,e={}){super(t);const{checkCrc:i=!1}=e;this._checkCrc=i,this._inflator=new ci,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=ki.UNKNOWN,this._filterMethod=yi.UNKNOWN,this._interlaceMethod=vi.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;tthis._palette.length)throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${t} vs ${this._palette.length})`);let e=0;for(;e>8&255;this._png.data=t}else this._png.data=r;var l}}function zi(t,e,i){for(let n=0;n>1)&255}else{for(;s>1)&255;for(;s>1)&255}}function Oi(t,e,i,n,r){let s=0;if(0===i.length){for(;s0)return t;throw new TypeError(`${e} must be a positive integer`)}function Ii(t,e,i,n){for(let r=0;rnew Ci({width:t,height:e,data:i},undefined).encode(),Mi=t=>function(t,e){return new Ui(t,void 0).decode()}(t)})();var r=n.P,s=n.m;export{r as fromPNG,s as toPNG}; \ No newline at end of file diff --git a/docs/js/libs/unpackWorker.js b/docs/js/libs/unpackWorker.js index 58063f2..7d710d0 100644 --- a/docs/js/libs/unpackWorker.js +++ b/docs/js/libs/unpackWorker.js @@ -1,7 +1,6 @@ -import {bufferToXnb} from "./src/xnbUnpacker.js"; +import {bufferToXnb} from "./xnb.js"; onmessage = function(e) { - console.log(e.data); let result = bufferToXnb(e.data); console.log(result); postMessage(result); diff --git a/docs/js/libs/xnb.js b/docs/js/libs/xnb.js new file mode 100644 index 0000000..ceca6c8 --- /dev/null +++ b/docs/js/libs/xnb.js @@ -0,0 +1,39 @@ +import { + setReaders, + addReaders, + + unpackToXnbData, + unpackToContent, + unpackToFiles, + + bufferToXnb, + bufferToContents, + + xnbDataToContent, + xnbDataToFiles, + pack, + XnbData, + XnbContent +} from "./core/xnb-core.module.js"; // @xnb/core +import * as Reader from "./readers/xnb-readers.module.js"; // @xnb/readers +import * as StardewReader from "./plugins/xnb-stardew.module.js"; // @xnb/plugin-stardewValley + +setReaders({...Reader, ...StardewReader}); + +export { + Reader, + addReaders, + + unpackToXnbData, + unpackToContent, + unpackToFiles, + + bufferToXnb, + bufferToContents, + + xnbDataToContent, + xnbDataToFiles, + pack, + XnbData, + XnbContent +}; \ No newline at end of file diff --git a/docs/js/pack.js b/docs/js/pack.js index f89ab16..482713b 100644 --- a/docs/js/pack.js +++ b/docs/js/pack.js @@ -1,6 +1,8 @@ -import { pack } from "./libs/xnb.module.js"; +import { pack } from "./libs/xnb.js"; import zipDownloadMaker from "./zipDownloadMaker.js"; +const options = {compression:"default"}; + /******************************************************************************/ /* Add Event Listener */ /*----------------------------------------------------------------------------*/ @@ -14,6 +16,15 @@ function addEventlistener_pack() // add file import button const fileImportButton = document.getElementById("packButton"); fileImportButton.addEventListener("click", ()=>{fileImporter.click();}); + + // add checkbox event handler + const lz4Checker = document.getElementById("check_lz4"); + + lz4Checker.addEventListener("change", function(){ + options.compression = this.checked ? "LZ4" : "default"; + showCode(); + handleFiles.call(fileImporter); + }); } /******************************************************************************/ @@ -26,8 +37,8 @@ function handleFiles() showCode(); -// pack(this.files, {debug:true}).then((files)=>{console.log(files); return files;}); - pack(this.files).then(xnbPackToZip).catch(closeButton); +// pack(this.files, {...options, debug:true}).then((files)=>{console.log(files); return files;}); + pack(this.files, options).then(xnbPackToZip).catch(closeButton); } @@ -57,12 +68,20 @@ function closeButton() /*----------------------------------------------------------------------------*/ const codeBox = document.getElementById("code"); +function codeMaker(strings, {compression="default"}={}) +{ + let configList=[]; + if(compression !== "default") configList.push(`compression:${compression}`); + const configString = configList.length > 0 ? `, {${configList.join(", ")}}` : ""; + return strings[0] + configString + strings[1]; +} + function showCode() { -const code=`import { pack } from "./libs/xnb.module.js"; +const code=codeMaker`import { pack } from "./libs/xnb.module.js"; async function handleFile(files) { - return pack(files); + return pack(files${options}); }`; codeBox.textContent = code; } diff --git a/docs/js/unpack.js b/docs/js/unpack.js index 25ebf8b..4a91da1 100644 --- a/docs/js/unpack.js +++ b/docs/js/unpack.js @@ -1,5 +1,5 @@ import { bufferToXnb } from "./workerHelper.js"; -import { xnbDataToContent, xnbDataToFiles } from "./libs/xnb.module.js"; +import { xnbDataToContent, xnbDataToFiles } from "./libs/xnb.js"; import zipDownloadMaker from "./zipDownloadMaker.js"; const options = {yaml:false, contentOnly:false}; @@ -30,6 +30,7 @@ function addEventlistener_unpack() options.contentOnly = false; } showCode(); + handleFiles.call(fileImporter); }); contentOnlyChecker.addEventListener("change", function(){ options.contentOnly = this.checked; @@ -39,6 +40,7 @@ function addEventlistener_unpack() options.yaml = false; } showCode(); + handleFiles.call(fileImporter); }); } @@ -142,8 +144,9 @@ function extractFileName(fullname) return [ matcher[1], matcher[2] ]; } -function closeButton() +function closeButton(error) { + console.warn(error); zipper.inactiveDownloadButton(); } diff --git a/docs/js/workerHelper.js b/docs/js/workerHelper.js index 8dc014f..a95f2cb 100644 --- a/docs/js/workerHelper.js +++ b/docs/js/workerHelper.js @@ -1,4 +1,4 @@ -import {XnbData} from "./libs/xnb.module.js"; +import {XnbData} from "./libs/xnb.js"; const bufferToXnb = (function(){ const worker = new Worker("./js/libs/unpackWorker.js", {type:"module"}); diff --git a/src/core/readme.md b/src/core/readme.md new file mode 100644 index 0000000..0458930 --- /dev/null +++ b/src/core/readme.md @@ -0,0 +1,16 @@ +@xnb/core +---------------- +The core of xnb.js. +### Installation +```bash +npm install @xnb/core +``` +### Usage +```js +import {setReaders, unpackToXnbData} from "@xnb/core"; +import * as Readers from "@xnb/readers"; + +setReaders(Readers); + +unpackToXnbData(file); +``` \ No newline at end of file diff --git a/src/plugins-stardewvalley/LICENSE b/src/plugins-stardewvalley/LICENSE new file mode 100644 index 0000000..153d416 --- /dev/null +++ b/src/plugins-stardewvalley/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/src/plugins-stardewvalley/LICENSE-GPL.md b/src/plugins-stardewvalley/LICENSE-GPL.md new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/src/plugins-stardewvalley/LICENSE-GPL.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/src/plugins-stardewvalley/Readers/RectReader.js b/src/plugins-stardewvalley/Readers/RectReader.js index 1321ca6..833805e 100644 --- a/src/plugins-stardewvalley/Readers/RectReader.js +++ b/src/plugins-stardewvalley/Readers/RectReader.js @@ -21,6 +21,15 @@ export default class RectReader extends RectangleReader { { return "Reflective"; } + // The properties of the Rect data type in Stardew Valley are capitalized. + read(buffer) { + const {x, y, width, height} = super.read(buffer); + return { X:x, Y:y, Width:width, Height:height }; + } + write(buffer, content, resolver) { + const { X:x, Y:y, Width:width, Height:height } = content; + super.write(buffer, {x,y,width,height}, resolver); + } isValueType() { return false; diff --git a/src/plugins-stardewvalley/dist/index.cjs b/src/plugins-stardewvalley/dist/index.cjs index b6e2e48..2207f56 100644 --- a/src/plugins-stardewvalley/dist/index.cjs +++ b/src/plugins-stardewvalley/dist/index.cjs @@ -665,6 +665,36 @@ class RectReader extends readers.RectangleReader { return "Reflective"; } + read(buffer) { + const { + x, + y, + width, + height + } = super.read(buffer); + return { + X: x, + Y: y, + Width: width, + Height: height + }; + } + + write(buffer, content, resolver) { + const { + X: x, + Y: y, + Width: width, + Height: height + } = content; + super.write(buffer, { + x, + y, + width, + height + }, resolver); + } + isValueType() { return false; } diff --git a/src/plugins-stardewvalley/dist/index.js b/src/plugins-stardewvalley/dist/index.js index ac9ee17..08b9f05 100644 --- a/src/plugins-stardewvalley/dist/index.js +++ b/src/plugins-stardewvalley/dist/index.js @@ -665,6 +665,36 @@ return "Reflective"; } + read(buffer) { + const { + x, + y, + width, + height + } = super.read(buffer); + return { + X: x, + Y: y, + Width: width, + Height: height + }; + } + + write(buffer, content, resolver) { + const { + X: x, + Y: y, + Width: width, + Height: height + } = content; + super.write(buffer, { + x, + y, + width, + height + }, resolver); + } + isValueType() { return false; } diff --git a/src/plugins-stardewvalley/dist/index.min.js b/src/plugins-stardewvalley/dist/index.min.js index d1a388c..06ab7b5 100644 --- a/src/plugins-stardewvalley/dist/index.min.js +++ b/src/plugins-stardewvalley/dist/index.min.js @@ -6,4 +6,4 @@ * xnb.js is licensed under the LGPL 3.0 License. * */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),u=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),u.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...w.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new w),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=u,e.FishPondDataReader=R,e.FishPondRewardReader=w,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=f,e.ModWallpaperOrFlooringReader=x,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),w=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),w.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...u.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new u),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}read(e){const{x:t,y:r,width:a,height:n}=super.read(e);return{X:t,Y:r,Width:a,Height:n}}write(e,t,r){const{X:a,Y:n,Width:i,Height:l}=t;super.write(e,{x:a,y:n,width:i,height:l},r)}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=w,e.FishPondDataReader=R,e.FishPondRewardReader=u,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=x,e.ModWallpaperOrFlooringReader=f,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/plugins-stardewvalley/dist/index.module.js b/src/plugins-stardewvalley/dist/index.module.js index 4eacda1..2588cd1 100644 --- a/src/plugins-stardewvalley/dist/index.module.js +++ b/src/plugins-stardewvalley/dist/index.module.js @@ -661,6 +661,36 @@ class RectReader extends RectangleReader { return "Reflective"; } + read(buffer) { + const { + x, + y, + width, + height + } = super.read(buffer); + return { + X: x, + Y: y, + Width: width, + Height: height + }; + } + + write(buffer, content, resolver) { + const { + X: x, + Y: y, + Width: width, + Height: height + } = content; + super.write(buffer, { + x, + y, + width, + height + }, resolver); + } + isValueType() { return false; } diff --git a/src/plugins-stardewvalley/package.json b/src/plugins-stardewvalley/package.json new file mode 100644 index 0000000..1d6c4b3 --- /dev/null +++ b/src/plugins-stardewvalley/package.json @@ -0,0 +1,24 @@ +{ + "name": "@xnb/stardew-valley", + "version": "1.1.0", + "description": "The xnb.js reader plugin for Stardew Valley.", + "main": "./dist/index.js", + "module": "./dist/index.module.js", + "export": { + ".": { + "import": "./dist/index.module.js", + "require": "./dist/index.cjs" + } + }, + "files": [ + "dist" + ], + "keywords": [ + "xnb", + "converter", + "javascript", + "stardew-valley" + ], + "author": "Lybell", + "license": "LGPL-3.0-or-later" +} \ No newline at end of file diff --git a/src/plugins-stardewvalley/readme.md b/src/plugins-stardewvalley/readme.md new file mode 100644 index 0000000..9e8b50d --- /dev/null +++ b/src/plugins-stardewvalley/readme.md @@ -0,0 +1,53 @@ +@xnb/stardew-valley +---------------- +The xnb.js reader plugin for Stardew Valley. It was created to respond to the xnb file that stores custom data types added in Stardew Valley 1.4 and later. +### Installation +```bash +npm install @xnb/stardew-valley +``` +### Usage +```js +import {setReaders, unpackToXnbData} from "@xnb/core"; +import * as Readers from "@xnb/stardew-valley"; + +setReaders(Readers); + +unpackToXnbData(file); +``` +### Documentation + +#### Data Reader added in Stardew Valley 1.4 +- MovieSceneReader : A reader that can read and write **Movies.xnb**. + - MovieDataReader +- MovieCharacterReactionReader : A reader that can read and write **MoviesReactions.xnb**. + - MovieReactionReader + - SpecialResponsesReader + - CharacterResponseReader +- ConcessionItemDataReader : A reader that can read and write **Concessions.xnb**. +- ConcessionTasteReader : A reader that can read and write **ConcessionTastes.xnb**. +- FishPondDataReader : A reader that can read and write **FishPondData.xnb**. + - FishPondRewardReader +- TailorItemRecipeReader : A reader that can read and write **TailoringRecipes.xnb**. + +#### Data Reader added in Stardew Valley 1.5 +- HomeRenovationReader : A reader that can read and write **HomeRenovations.xnb**. + - RenovationValueReader + - RectGroupReader + - RectReader +- RandomBundleDataReader : A reader that can read and write **RandomBundles.xnb**. + - BundleSetDataReader + - BundleDataReader +- SpecialOrderDataReader : A reader that can read and write **SpecialOrders.xnb**. + - RandomizedElementReader + - RandomizedElementItemReader + - SpecialOrderObjectiveDataReader + - SpecialOrderRewardDataReader + +#### Data Reader added in Stardew Valley 1.5.5 +It is recommended to add data added in 1.5.5 using *contents patcher* instead of using this library. +- ModFarmTypeReader : A reader that can read and write **AdditionalFarms.xnb**. +- ModLanguageReader : A reader that can read and write **AdditionalLanguages.xnb**. +- ModWallpaperOrFlooringReader : A reader that can read and write **AdditionalWallpaperFlooring.xnb**. + +### Special Thanks +The implementation of the data reader added in the Stardew Valley 1.4 was referenced in the [XnbCli revision](https://blog.naver.com/khs3400/221852415116) made by 진의. Thank you for this. \ No newline at end of file diff --git a/src/readers/package.json b/src/readers/package.json index 1f8aad0..f56b9e0 100644 --- a/src/readers/package.json +++ b/src/readers/package.json @@ -21,4 +21,4 @@ ], "author": "Lybell", "license": "LGPL-3.0-or-later" -} +} \ No newline at end of file diff --git a/src/readers/readme.md b/src/readers/readme.md new file mode 100644 index 0000000..77d4139 --- /dev/null +++ b/src/readers/readme.md @@ -0,0 +1,66 @@ +@xnb/readers +---------------- +The basic readers of xnb.js. +### Installation +```bash +npm install @xnb/readers +``` +### Usage +```js +import {setReaders, unpackToXnbData} from "@xnb/core"; +import {Texture2DReader} from "@xnb/readers"; + +setReaders({Texture2DReader}); + +unpackToXnbData(file); +``` +### Documentation + +#### Abstract Class +- BaseReader : Base class for all readers. +#### Primitive Reader +All primitive type readers except StringReader do not use resolver. +```js +read(buffer, resolver) +{ + const int32Reader = new Int32Reader(); + const value = int32Reader.read(buffer); +} +write(buffer, content, resolver) +{ + const int32Reader = new Int32Reader(); + int32Reader.write(buffer, content, null); +} +``` +- Int32Reader : A reader that can read and write **int** type. +- UInt32Reader : A reader that can read and write **unsigned int** type. +- SingleReader : A reader that can read and write 4byte **float** type. +- DoubleReader : A reader that can read and write 8byte **double** type. +- BooleanReader : A reader that can read and write **boolean** type. +- CharReader : A reader that can read and write **char** type. +- StringReader : A reader that can read and write **String** type. +- Vector2Reader : A reader that can read and write **Vector2** type. +- Vector3Reader : A reader that can read and write **Vector3** type. +- Vector4Reader : A reader that can read and write **Vector4** type. +- Vector4Reader : A reader that can read and write **Vector4** type. +- RectangleReader: A reader that can read and write **Rectangle** type. +#### Sub-type Reader +- ArrayReader : A reader that can read and write **Array** type. +- ListReader : A reader that can read and write **List** type. +- DictionaryReader : A reader that can read and write **Dictionary** type. +- NullableReader : A reader that can read and write **Nullable** type. +- ReflectiveReader : A reader that can read and write **Reflective** type. +#### Complex-type Reader +- Texture2DReader : A reader that can read and write **Texture2D** type. Included DXT compression. +- LightweightTexture2DReader : A reader that can read and write **Texture2D** type. Excluded DXT compression. This is useful when you want to extract only sprite data that contains png data. +- BmFontReader : A reader that can read and write **BmFont** type. +- SpriteFontReader : A reader that can read and write **SpriteFont** type. +- EffectReader : A reader that can read and write **Effect** type. +- TBinReader : A reader that can read and write **tilemap** file. + +If you want use LightweightTexture2DReader, you should *rename* this reader to Texture2DReader when importing it. +```js +import {LightweightTexture2DReader as Texture2DReader} from "@xnb/readers"; + +setReaders({Texture2DReader}); +``` \ No newline at end of file From 31c5993fe4d385c7e9c1facffe3d3b3ca8fe0a0d Mon Sep 17 00:00:00 2001 From: lybell Date: Wed, 25 May 2022 16:12:30 +0900 Subject: [PATCH 09/11] Update package.json --- src/plugins-stardewvalley/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins-stardewvalley/package.json b/src/plugins-stardewvalley/package.json index 1d6c4b3..607b53a 100644 --- a/src/plugins-stardewvalley/package.json +++ b/src/plugins-stardewvalley/package.json @@ -20,5 +20,8 @@ "stardew-valley" ], "author": "Lybell", - "license": "LGPL-3.0-or-later" + "license": "LGPL-3.0-or-later", + "dependencies": { + "@xnb/readers": "^1.1.0" + } } \ No newline at end of file From 9902574e701a90873a528973058bdba5b87e6b2f Mon Sep 17 00:00:00 2001 From: lybell Date: Wed, 25 May 2022 16:38:22 +0900 Subject: [PATCH 10/11] organization fixed I couldn't make npm organization named "xnb"... --- builder/plugins-rollup.config.js | 22 ++-- package.json | 107 ++++++++++-------- src/core/package.json | 44 +++---- src/plugins-stardewvalley/dist/index.cjs | 2 +- src/plugins-stardewvalley/dist/index.js | 4 +- src/plugins-stardewvalley/dist/index.min.js | 2 +- .../dist/index.module.js | 2 +- src/plugins-stardewvalley/package.json | 4 +- src/readers/package.json | 2 +- 9 files changed, 100 insertions(+), 89 deletions(-) diff --git a/builder/plugins-rollup.config.js b/builder/plugins-rollup.config.js index 0f54884..e018191 100644 --- a/builder/plugins-rollup.config.js +++ b/builder/plugins-rollup.config.js @@ -21,7 +21,7 @@ function replaceDependency() { return { transform(code) { - code = code.replace('from "../../readers/src/readers.js"; //@xnb/readers', 'from "@xnb/readers";'); + code = code.replace('from "../../readers/src/readers.js"; //@xnb-js/readers', 'from "@xnb-js/readers";'); return { code: code, map: null @@ -34,7 +34,7 @@ function rejoinDependency() { return { renderChunk(code) { - code = code.replace('@xnb/readers', '../../readers/xnb-readers.module.js'); + code = code.replace('@xnb-js/readers', '../../readers/xnb-readers.module.js'); return code; } } @@ -61,10 +61,10 @@ function buildMaker(srcBase, srcName, distNode, distWeb) name: "XNB", format: 'umd', globals: { - "@xnb/readers": 'XNB' + "@xnb-js/readers": 'XNB' } }], - external: ['@xnb/readers'], + external: ['@xnb-js/readers'], plugins: [ replaceDependency(), ...makePlugins(false, false), @@ -79,10 +79,10 @@ function buildMaker(srcBase, srcName, distNode, distWeb) name: "XNB", format: 'umd', globals: { - "@xnb/readers": 'XNB' + "@xnb-js/readers": 'XNB' } }, - external: ['@xnb/readers'], + external: ['@xnb-js/readers'], plugins: [ replaceDependency(), ...makePlugins(true, false), @@ -98,7 +98,7 @@ function buildMaker(srcBase, srcName, distNode, distWeb) file: `${distWeb}.module.js`, format: 'esm' }], - external: ['@xnb/readers'], + external: ['@xnb-js/readers'], plugins: [ replaceDependency(), ...makePlugins(false, false), @@ -114,10 +114,10 @@ function buildMaker(srcBase, srcName, distNode, distWeb) name: "XNB", format: 'umd', globals: { - "@xnb/readers": 'XNB' + "@xnb-js/readers": 'XNB' } }, - external: ['@xnb/readers'], + external: ['@xnb-js/readers'], plugins: [ replaceDependency(), ...makePlugins(true, false), @@ -132,10 +132,10 @@ function buildMaker(srcBase, srcName, distNode, distWeb) name: "XNB", format: 'umd', globals: { - "@xnb/readers": 'XNB' + "@xnb-js/readers": 'XNB' } }, - external: ['@xnb/readers'], + external: ['@xnb-js/readers'], plugins: [ replaceDependency(), ...makePlugins(true, true), diff --git a/package.json b/package.json index 18dc419..dcbbfdf 100644 --- a/package.json +++ b/package.json @@ -1,49 +1,60 @@ { - "name": "xnb", - "version": "1.1.0", - "description": "Javascript XNB packing & unpacking library for es6.", - "main": "./dist/xnb.js", - "module": "./dist/xnb.module.js", - "export": { - ".": { - "import": "./dist/xnb.module.js", - "require": "./dist/xnb.cjs" - }, - "./core": { - "import": "./dist/core/xnb-core.module.js", - "require": "./dist/core/xnb-core.cjs" - }, - "./readers": { - "import": "./dist/readers/xnb-readers.module.js", - "require": "./dist/readers/xnb-readers.cjs" - } - }, - "files": [ - "dist", - "api.md" - ], - "scripts": { - "build": "rollup -c builder/rollup.config.js", - "build-core": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:1", - "build-readers": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:2", - "build-stardew": "rollup -c builder/plugins-rollup.config.js --environment BUILD_MODULE:0" - }, - "keywords": [ - "xnb", - "converter", - "javascript", - "stardew-valley" - ], - "author": "Lybell", - "license": "LGPL-3.0-or-later", - "devDependencies": { - "@babel/core": "^7.17.10", - "@babel/preset-env": "^7.17.10", - "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-commonjs": "^22.0.0", - "@rollup/plugin-node-resolve": "^13.3.0", - "core-js": "^3.22.4", - "rollup": "^2.72.1", - "rollup-plugin-terser": "^7.0.2" - } -} + "name": "xnb", + "version": "1.1.0", + "description": "Javascript XNB packing & unpacking library for es6.", + "main": "./dist/xnb.js", + "module": "./dist/xnb.module.js", + "export": { + ".": { + "import": "./dist/xnb.module.js", + "require": "./dist/xnb.cjs" + }, + "./core": { + "import": "./dist/core/xnb-core.module.js", + "require": "./dist/core/xnb-core.cjs" + }, + "./readers": { + "import": "./dist/readers/xnb-readers.module.js", + "require": "./dist/readers/xnb-readers.cjs" + } + }, + "files": [ + "dist", + "api.md" + ], + "scripts": { + "build": "rollup -c builder/rollup.config.js", + "build-core": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:1", + "build-readers": "rollup -c builder/rollup.config.js --environment BUILD_MODULE:2", + "build-stardew": "rollup -c builder/plugins-rollup.config.js --environment BUILD_MODULE:0" + }, + "keywords": [ + "xnb", + "converter", + "javascript", + "stardew-valley" + ], + "author": "Lybell", + "license": "LGPL-3.0-or-later", + "devDependencies": { + "@babel/core": "^7.17.10", + "@babel/preset-env": "^7.17.10", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.0", + "@rollup/plugin-node-resolve": "^13.3.0", + "core-js": "^3.22.4", + "rollup": "^2.72.1", + "rollup-plugin-terser": "^7.0.2" + }, + "directories": { + "doc": "docs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lybell-art/xnb-js.git" + }, + "bugs": { + "url": "https://github.com/lybell-art/xnb-js/issues" + }, + "homepage": "https://github.com/lybell-art/xnb-js#readme" +} \ No newline at end of file diff --git a/src/core/package.json b/src/core/package.json index 0d074f8..8506933 100644 --- a/src/core/package.json +++ b/src/core/package.json @@ -1,24 +1,24 @@ { - "name": "@xnb/core", - "version": "1.1.0", - "description": "The core of xnb.js.", - "main": "./dist/core.js", - "module": "./dist/core.module.js", - "export": { - ".": { - "import": "./dist/core.module.js", - "require": "./dist/core.cjs" - } - }, - "files": [ - "dist" - ], - "keywords": [ - "xnb", - "converter", - "javascript", - "stardew-valley" - ], - "author": "Lybell", - "license": "LGPL-3.0-or-later" + "name": "@xnb-js/core", + "version": "1.1.0", + "description": "The core of xnb.js.", + "main": "./dist/core.js", + "module": "./dist/core.module.js", + "export": { + ".": { + "import": "./dist/core.module.js", + "require": "./dist/core.cjs" + } + }, + "files": [ + "dist" + ], + "keywords": [ + "xnb", + "converter", + "javascript", + "stardew-valley" + ], + "author": "Lybell", + "license": "LGPL-3.0-or-later" } diff --git a/src/plugins-stardewvalley/dist/index.cjs b/src/plugins-stardewvalley/dist/index.cjs index 2207f56..7f9549c 100644 --- a/src/plugins-stardewvalley/dist/index.cjs +++ b/src/plugins-stardewvalley/dist/index.cjs @@ -10,7 +10,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var readers = require('@xnb/readers'); +var readers = require('@xnb-js/readers'); class MovieSceneReader extends readers.BaseReader { static isTypeOf(type) { diff --git a/src/plugins-stardewvalley/dist/index.js b/src/plugins-stardewvalley/dist/index.js index 08b9f05..d0c3b31 100644 --- a/src/plugins-stardewvalley/dist/index.js +++ b/src/plugins-stardewvalley/dist/index.js @@ -7,8 +7,8 @@ * */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@xnb/readers')) : - typeof define === 'function' && define.amd ? define(['exports', '@xnb/readers'], factory) : + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@xnb-js/readers')) : + typeof define === 'function' && define.amd ? define(['exports', '@xnb-js/readers'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.XNB = {}, global.XNB)); })(this, (function (exports, readers) { 'use strict'; diff --git a/src/plugins-stardewvalley/dist/index.min.js b/src/plugins-stardewvalley/dist/index.min.js index 06ab7b5..acde3e2 100644 --- a/src/plugins-stardewvalley/dist/index.min.js +++ b/src/plugins-stardewvalley/dist/index.min.js @@ -6,4 +6,4 @@ * xnb.js is licensed under the LGPL 3.0 License. * */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),w=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),w.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...u.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new u),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}read(e){const{x:t,y:r,width:a,height:n}=super.read(e);return{X:t,Y:r,Width:a,Height:n}}write(e,t,r){const{X:a,Y:n,Width:i,Height:l}=t;super.write(e,{x:a,y:n,width:i,height:l},r)}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=w,e.FishPondDataReader=R,e.FishPondRewardReader=u,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=x,e.ModWallpaperOrFlooringReader=f,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@xnb-js/readers")):"function"==typeof define&&define.amd?define(["exports","@xnb-js/readers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XNB={},e.XNB)}(this,(function(e,t){"use strict";class r extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieScene"===e}static parseTypeList(){return["MovieScene",null,"Nullable","String","Nullable","String",null,"Nullable","String","Nullable","String",null,"Nullable","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.Int32Reader,i=new t.NullableReader(new t.StringReader);return{Image:n.read(e,null),Music:i.read(e,r),Sound:i.read(e,r),MessageDelay:n.read(e,null),Script:i.read(e,r),Text:i.read(e,r),Shake:a.read(e),ResponsePoint:i.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.BooleanReader,i=new t.Int32Reader,l=new t.NullableReader(new t.StringReader),s=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Image,null),l.write(e,r.Music,a),l.write(e,r.Sound,a),i.write(e,r.MessageDelay,null),l.write(e,r.Script,a),l.write(e,r.Text,a),n.write(e,r.Shake,null),l.write(e,r.ResponsePoint,a),s.write(e,r.ID,a)}isValueType(){return!1}}class a extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieData"===e}static parseTypeList(){return["MovieData","Nullable","String",null,"String","String","Nullable>","List","String","List",...r.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.StringReader),i=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:n.read(e,r),SheetIndex:a.read(e),Title:r.read(e),Description:r.read(e),Tags:i.read(e,r),Scenes:r.read(e)}}write(e,a,n){const i=new t.Int32Reader,l=new t.StringReader,s=new t.NullableReader(new t.StringReader),d=new t.NullableReader(new t.ListReader(new t.StringReader)),w=new t.ListReader(new r);this.writeIndex(e,n),s.write(e,a.ID,n),i.write(e,a.SheetIndex,null),l.write(e,a.Title,n),l.write(e,a.Description,n),d.write(e,a.Tags,n),w.write(e,a.Scenes,n)}isValueType(){return!1}}class n extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.CharacterResponse"===e}static parseTypeList(){return["CharacterResponse","Nullable:1","String","Nullable:1","String","Nullable:1","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader);return{ResponsePoint:a.read(e,r),Script:a.read(e,r)||"",Text:a.read(e,r)||""}}write(e,r,a){const n=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ResponsePoint,a),n.write(e,r.Script,a),n.write(e,r.Text,a)}isValueType(){return!1}}class i extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.SpecialResponses"===e}static parseTypeList(){return["SpecialResponses","Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList(),"Nullable:7",...n.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new n);return{BeforeMovie:a.read(e,r),DuringMovie:a.read(e,r),AfterMovie:a.read(e,r)}}write(e,r,a){const i=new t.NullableReader(new n);this.writeIndex(e,a),i.write(e,r.BeforeMovie,a),i.write(e,r.DuringMovie,a),i.write(e,r.AfterMovie,a)}isValueType(){return!1}}class l extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieReaction"===e}static parseTypeList(){return["MovieReaction","String","Nullable:1","String","Nullable>:2","List","String","Nullable:25",...i.parseTypeList(),"String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new t.StringReader)),l=new t.NullableReader(new i);return{Tag:r.read(e),Response:a.read(e,r)||"like",Whitelist:n.read(e,r)||[],SpecialResponses:l.read(e,r),ID:r.read(e)}}write(e,r,a){const n=new t.StringReader,l=new t.NullableReader(new t.StringReader),s=new t.NullableReader(new t.ListReader(new t.StringReader)),d=new t.NullableReader(new i);this.writeIndex(e,a),n.write(e,r.Tag,a),l.write(e,r.Response,a),s.write(e,r.Whitelist,a),d.write(e,r.SpecialResponses,a),n.write(e,r.ID,a)}isValueType(){return!1}}class s extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.MovieCharacterReaction"===e}static parseTypeList(){return["MovieCharacterReaction","String","Nullable>:34","List",...l.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new l));return{NPCName:r.read(e),Reactions:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new l));this.writeIndex(e,a),n.write(e,r.NPCName,a),i.write(e,r.Reactions,a)}isValueType(){return!1}}class d extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionItemData"===e}static parseTypeList(){return["ConcessionItemData",null,"String","String","String",null,"Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.ListReader(new t.StringReader));return{ID:a.read(e),Name:r.read(e),DisplayName:r.read(e),Description:r.read(e),Price:a.read(e),ItemTags:n.read(e,r)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader,l=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,null),i.write(e,r.Name,a),i.write(e,r.DisplayName,a),i.write(e,r.Description,a),n.write(e,r.Price,null),l.write(e,r.ItemTags,a)}isValueType(){return!1}}class w extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Movies.ConcessionTaste"===e}static parseTypeList(){return["ConcessionTaste","String","Nullable>:2","List","String","Nullable>:2","List","String","Nullable>:2","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader));return{Name:r.read(e),LovedTags:a.read(e,r),LikedTags:a.read(e,r),DislikedTags:a.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.LovedTags,a),i.write(e,r.LikedTags,a),i.write(e,r.DislikedTags,a)}isValueType(){return!1}}class u extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondReward"===e}static parseTypeList(){return["FishPondReward",null,null,null,null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader;return{RequiredPopulation:a.read(e),Chance:Math.round(1e5*n.read(e))/1e5,ItemId:a.read(e),MinQuantity:a.read(e),MaxQuantity:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.SingleReader;this.writeIndex(e,a),n.write(e,r.RequiredPopulation,null),i.write(e,r.Chance,null),n.write(e,r.ItemId,null),n.write(e,r.MinQuantity,null),n.write(e,r.MaxQuantity,null)}isValueType(){return!1}}class R extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.FishPond.FishPondData"===e}static parseTypeList(){return["FishPondData","List","String",null,"List",...u.parseTypeList(),"Nullable>>:4","Dictionary>","Int32","List","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));return{RequiredTags:r.read(e),SpawnTime:a.read(e),ProducedItems:r.read(e),PopulationGates:n.read(e,r)}}write(e,r,a){const n=new t.ListReader(new t.StringReader),i=new t.Int32Reader,l=new t.ListReader(new u),s=new t.NullableReader(new t.DictionaryReader(new t.Int32Reader,new t.ListReader(new t.StringReader)));this.writeIndex(e,a),n.write(e,r.RequiredTags,a),i.write(e,r.SpawnTime,null),l.write(e,r.ProducedItems,a),s.write(e,r.PopulationGates,a)}isValueType(){return!1}}class o extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.Crafting.TailorItemRecipe"===e}static parseTypeList(){return["TailorItemRecipe","Nullable>:2","List","String","Nullable>:2","List","String",null,null,"Nullable>:2","List","String","Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new t.StringReader)),n=new t.NullableReader(new t.StringReader),i=new t.BooleanReader,l=new t.Int32Reader;return{FirstItemTags:a.read(e,r),SecondItemTags:a.read(e,r),SpendingRightItem:i.read(e),CraftedItemID:l.read(e),CraftedItemIDs:a.read(e,r),CraftedItemColor:n.read(e,r)}}write(e,r,a){const n=new t.NullableReader(new t.ListReader(new t.StringReader)),i=new t.NullableReader(new t.StringReader),l=new t.BooleanReader,s=new t.Int32Reader;this.writeIndex(e,a),n.write(e,r.FirstItemTags,a),n.write(e,r.SecondItemTags,a),l.write(e,r.SpendingRightItem,null),s.write(e,r.CraftedItemID,null),n.write(e,r.CraftedItemIDs,a),i.write(e,r.CraftedItemColor,a)}isValueType(){return!1}}class c extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RenovationValue"===e}static parseTypeList(){return["RenovationValue","String","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Key:t.read(e),Value:t.read(e)}}write(e,r,a){const n=new t.StringReader;this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Key,a),n.write(e,r.Value,a)}isValueType(){return!1}}class S extends t.RectangleReader{static isTypeOf(e){return!!super.isTypeOf(e)||"StardewValley.GameData.HomeRenovations.Rect"===e}static parseTypeList(){return["Rect"]}static type(){return"Reflective"}read(e){const{x:t,y:r,width:a,height:n}=super.read(e);return{X:t,Y:r,Width:a,Height:n}}write(e,t,r){const{X:a,Y:n,Width:i,Height:l}=t;super.write(e,{x:a,y:n,width:i,height:l},r)}isValueType(){return!1}}class p extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.RectGroup"===e}static parseTypeList(){return["RectGroup","List","Rect"]}static type(){return"Reflective"}read(e,t){return{Rects:t.read(e)}}write(e,r,a){const n=new t.ListReader(new S);this.writeIndex(e,a),n.write(e,r.Rects,a)}isValueType(){return!1}}class g extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.HomeRenovations.HomeRenovation"===e}static parseTypeList(){return["HomeRenovation","String","String",null,"List",...c.parseTypeList(),"List",...c.parseTypeList(),"Nullable>:4","List",...p.parseTypeList(),"Nullable","String"]}static type(){return"Reflective"}read(e,r){const a=new t.BooleanReader,n=new t.NullableReader(new t.ListReader(new p)),i=new t.NullableReader(new t.StringReader);return{TextStrings:r.read(e),AnimationType:r.read(e),CheckForObstructions:a.read(e),Requirements:r.read(e),RenovateActions:r.read(e),RectGroups:n.read(e,r),SpecialRect:i.read(e,r)}}write(e,r,a){const n=new t.BooleanReader,i=new t.StringReader,l=new t.ListReader(new c),s=new t.NullableReader(new t.ListReader(new p)),d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.TextStrings,a),i.write(e,r.AnimationType,a),n.write(e,r.CheckForObstructions,null),l.write(e,r.Requirements,a),l.write(e,r.RenovateActions,a),s.write(e,r.RectGroups,a),d.write(e,r.SpecialRect,a)}isValueType(){return!1}}class y extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleData"===e}static parseTypeList(){return["BundleData","String",null,"String","String","String",null,null,"String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader;return{Name:r.read(e),Index:a.read(e),Sprite:r.read(e),Color:r.read(e),Items:r.read(e),Pick:a.read(e),RequiredItems:a.read(e),Reward:r.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.StringReader;this.writeIndex(e,a),i.write(e,r.Name,a),n.write(e,r.Index,null),i.write(e,r.Sprite,a),i.write(e,r.Color,a),i.write(e,r.Items,a),n.write(e,r.Pick,null),n.write(e,r.RequiredItems,null),i.write(e,r.Reward,a)}isValueType(){return!1}}class T extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.BundleSetData"===e}static parseTypeList(){return["BundleSetData","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Bundles:t.read(e)}}write(e,r,a){const n=new t.ListReader(new y);this.writeIndex(e,a),n.write(e,r.Bundles,a)}isValueType(){return!1}}class m extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomBundleData"===e}static parseTypeList(){return["RandomBundleData","String","String","Nullable>:13","List",...T.parseTypeList(),"Nullable>:11","List",...y.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.ListReader(new T)),n=new t.NullableReader(new t.ListReader(new y));return{AreaName:r.read(e),Keys:r.read(e),BundleSets:a.read(e,r),Bundles:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.ListReader(new T)),l=new t.NullableReader(new t.ListReader(new y));this.writeIndex(e,a),n.write(e,r.AreaName,a),n.write(e,r.Keys,a),i.write(e,r.BundleSets,a),l.write(e,r.Bundles,a)}isValueType(){return!1}}class L extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElementItem"===e}static parseTypeList(){return["RandomizedElementItem","Nullable","String","String"]}static type(){return"Reflective"}read(e,r){return{RequiredTags:new t.NullableReader(new t.StringReader).read(e,r)||"",Value:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),i.write(e,r.RequiredTags,a),n.write(e,r.Value,a)}isValueType(){return!1}}class D extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.RandomizedElement"===e}static parseTypeList(){return["RandomizedElement","String","List",...L.parseTypeList()]}static type(){return"Reflective"}read(e,t){return{Name:t.read(e),Values:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.ListReader(new L);this.writeIndex(e,a),n.write(e,r.Name,a),i.write(e,r.Values,a)}isValueType(){return!1}}class I extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderObjectiveData"===e}static parseTypeList(){return["SpecialOrderObjectiveData","String","String","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Text:t.read(e),RequiredCount:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),n.write(e,r.Text,a),n.write(e,r.RequiredCount,a),i.write(e,r.Data,a)}isValueType(){return!1}}class N extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderRewardData"===e}static parseTypeList(){return["SpecialOrderRewardData","String","Dictionary","String","String"]}static type(){return"Reflective"}read(e,t){return{Type:t.read(e),Data:t.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.DictionaryReader(new t.StringReader,new t.StringReader);this.writeIndex(e,a),n.write(e,r.Type,a),i.write(e,r.Data,a)}isValueType(){return!1}}class b extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.SpecialOrderData"===e}static parseTypeList(){return["SpecialOrderData","String","String","String","Nullable","String","Nullable","String","Nullable","String","Nullable","String","String","Nullable","String","Nullable","String","Nullable>:8","List",...D.parseTypeList(),"List",...I.parseTypeList(),"List",...N.parseTypeList()]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.ListReader(new D));return{Name:r.read(e),Requester:r.read(e),Duration:r.read(e),Repeatable:a.read(e,r)||"False",RequiredTags:a.read(e,r)||"",OrderType:a.read(e,r)||"",SpecialRule:a.read(e,r)||"",Text:r.read(e),ItemToRemoveOnEnd:a.read(e,r),MailToRemoveOnEnd:a.read(e,r),RandomizedElements:n.read(e,r),Objectives:r.read(e),Rewards:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.ListReader(new D)),s=new t.ListReader(new I),d=new t.ListReader(new N);this.writeIndex(e,a),n.write(e,r.Name,a),n.write(e,r.Requester,a),n.write(e,r.Duration,a),i.write(e,r.Repeatable,a),i.write(e,r.RequiredTags,a),i.write(e,r.OrderType,a),i.write(e,r.SpecialRule,a),n.write(e,r.Text,a),i.write(e,r.ItemToRemoveOnEnd,a),i.write(e,r.MailToRemoveOnEnd,a),l.write(e,r.RandomizedElements,a),s.write(e,r.Objectives,a),d.write(e,r.Rewards,a)}isValueType(){return!1}}class v extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModFarmType"===e}static parseTypeList(){return["ModFarmType","String","String","String","Nullable:1","String","Nullable:1","String","Nullable>:4","Dictionary","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.NullableReader(new t.StringReader),n=new t.NullableReader(new t.DictionaryReader(new t.StringReader));return{ID:r.read(e),TooltipStringPath:r.read(e),MapName:r.read(e),IconTexture:a.read(e,r),WorldMapTexture:a.read(e,r),ModData:n.read(e,r)}}write(e,r,a){const n=new t.StringReader,i=new t.NullableReader(new t.StringReader),l=new t.NullableReader(new t.DictionaryReader(new t.StringReader));this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.TooltipStringPath,a),n.write(e,r.MapName,a),i.write(e,r.IconTexture,a),i.write(e,r.WorldMapTexture,a),l.write(e,r.ModData,a)}isValueType(){return!1}}class x extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModLanguage"===e}static parseTypeList(){return["ModLanguage","String","String","String",null,"Nullable:1","String",null,null,null,null,"Nullable:1","String","String","String","String","String"]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.SingleReader,i=new t.BooleanReader,l=new t.NullableReader(new t.StringReader);return{ID:r.read(e),LanguageCode:r.read(e),ButtonTexture:r.read(e),UseLatinFont:i.read(e),FontFile:l.read(e,r),FontPixelZoom:n.read(e),FontApplyYOffset:i.read(e),SmallFontLineSpacing:a.read(e),UseGenderedCharacterTranslations:i.read(e),NumberComma:l.read(e,r),TimeFormat:r.read(e),ClockTimeFormat:r.read(e),ClockDateFormat:r.read(e)}}write(e,r,a){const n=new t.StringReader,i=new t.Int32Reader,l=new t.SingleReader,s=new t.BooleanReader,d=new t.NullableReader(new t.StringReader);this.writeIndex(e,a),n.write(e,r.ID,a),n.write(e,r.LanguageCode,a),n.write(e,r.ButtonTexture,a),s.write(e,r.UseLatinFont,null),d.write(e,r.FontFile,a),l.write(e,r.FontPixelZoom,null),s.write(e,r.FontApplyYOffset,null),i.write(e,r.SmallFontLineSpacing,null),s.write(e,r.UseGenderedCharacterTranslations,null),d.write(e,r.NumberComma,a),n.write(e,r.TimeFormat,a),n.write(e,r.ClockTimeFormat,a),n.write(e,r.ClockDateFormat,a)}isValueType(){return!1}}class f extends t.BaseReader{static isTypeOf(e){return"StardewValley.GameData.ModWallpaperOrFlooring"===e}static parseTypeList(){return["ModWallpaperOrFlooring","String","String",null,null]}static type(){return"Reflective"}read(e,r){const a=new t.Int32Reader,n=new t.BooleanReader;return{ID:r.read(e),Texture:r.read(e),IsFlooring:n.read(e),Count:a.read(e)}}write(e,r,a){const n=new t.Int32Reader,i=new t.BooleanReader,l=new t.StringReader;this.writeIndex(e,a),l.write(e,r.ID,a),l.write(e,r.Texture,a),i.write(e,r.IsFlooring,null),n.write(e,r.Count,null)}isValueType(){return!1}}e.BundleDataReader=y,e.BundleSetDataReader=T,e.CharacterResponseReader=n,e.ConcessionItemDataReader=d,e.ConcessionTasteReader=w,e.FishPondDataReader=R,e.FishPondRewardReader=u,e.HomeRenovationReader=g,e.ModFarmTypeReader=v,e.ModLanguageReader=x,e.ModWallpaperOrFlooringReader=f,e.MovieCharacterReactionReader=s,e.MovieDataReader=a,e.MovieReactionReader=l,e.MovieSceneReader=r,e.RandomBundleDataReader=m,e.RandomizedElementItemReader=L,e.RandomizedElementReader=D,e.RectGroupReader=p,e.RectReader=S,e.RenovationValueReader=c,e.SpecialOrderDataReader=b,e.SpecialOrderObjectiveDataReader=I,e.SpecialOrderRewardDataReader=N,e.SpecialResponsesReader=i,e.TailorItemRecipeReader=o,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/plugins-stardewvalley/dist/index.module.js b/src/plugins-stardewvalley/dist/index.module.js index 2588cd1..fd23970 100644 --- a/src/plugins-stardewvalley/dist/index.module.js +++ b/src/plugins-stardewvalley/dist/index.module.js @@ -6,7 +6,7 @@ * xnb.js is licensed under the LGPL 3.0 License. * */ -import { BaseReader, BooleanReader, Int32Reader, NullableReader, StringReader, ListReader, SingleReader, DictionaryReader, RectangleReader } from '@xnb/readers'; +import { BaseReader, BooleanReader, Int32Reader, NullableReader, StringReader, ListReader, SingleReader, DictionaryReader, RectangleReader } from '@xnb-js/readers'; class MovieSceneReader extends BaseReader { static isTypeOf(type) { diff --git a/src/plugins-stardewvalley/package.json b/src/plugins-stardewvalley/package.json index 607b53a..3aa1f0c 100644 --- a/src/plugins-stardewvalley/package.json +++ b/src/plugins-stardewvalley/package.json @@ -1,5 +1,5 @@ { - "name": "@xnb/stardew-valley", + "name": "@xnb-js/stardew-valley", "version": "1.1.0", "description": "The xnb.js reader plugin for Stardew Valley.", "main": "./dist/index.js", @@ -22,6 +22,6 @@ "author": "Lybell", "license": "LGPL-3.0-or-later", "dependencies": { - "@xnb/readers": "^1.1.0" + "@xnb-js/readers": "^1.1.0" } } \ No newline at end of file diff --git a/src/readers/package.json b/src/readers/package.json index f56b9e0..d2224dd 100644 --- a/src/readers/package.json +++ b/src/readers/package.json @@ -1,5 +1,5 @@ { - "name": "@xnb/readers", + "name": "@xnb-js/readers", "version": "1.1.0", "description": "The basic readers of xnb.js.", "main": "./dist/readers.js", From 32c2f53cb1285c4b6a96f48d7e0552eb970d81e9 Mon Sep 17 00:00:00 2001 From: lybell Date: Wed, 25 May 2022 16:49:26 +0900 Subject: [PATCH 11/11] edited readme --- readme-ko.md | 62 ++++++++++++++++++++++++++++- readme.md | 8 ++-- src/core/readme.md | 8 ++-- src/plugins-stardewvalley/readme.md | 8 ++-- src/readers/readme.md | 6 +-- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/readme-ko.md b/readme-ko.md index dbf8077..af6b91b 100644 --- a/readme-ko.md +++ b/readme-ko.md @@ -20,11 +20,11 @@ xnb.js는 es6 모듈을 이용하여 불러오는 것을 권장합니다. #### ES6 모듈로 불러오기(권장) ```js -import * as XNB from "https://cdn.jsdelivr.net/npm/xnb@1.0.2/dist/xnb.module.js"; +import * as XNB from "https://cdn.jsdelivr.net/npm/xnb@1.1.0/dist/xnb.module.js"; ``` #### 스크립트 링크로 불러오기 ```html - + ``` 자신이 IE11 등 ES5를 지원해야 한다면, xnb.es5.min.js를 사용하는 것을 권장합니다. @@ -87,6 +87,64 @@ readFile("./Abigail.xnb") // read xnb file as Buffer ## API 이 [링크](https://github.com/lybell-art/xnb-js/blob/main/api-ko.md)를 참조하십시오. +## 커스텀 +xnb.js 1.1 업데이트 이후부터는 리더의 일부만 불러오거나, 커스텀 리더를 추가할 수 있습니다. + +### 일부 리더만 불러오기 +```js +import * as XNB from "@xnb-js/core"; +import { LightweightTexture2DReader as Texture2DReader } from "@xnb-js/readers"; + +XNB.setReaders({Texture2DReader}); + +xnb.unpackToXnbData(file); +``` + +### 커스텀 플러그인 추가 +```js +import * as XNB from "xnb"; + +// 커스텀 리더는 BaseReader를 상속해야 하며, 클래스의 이름은 Reader로 끝나야 합니다. +class CustomReader extends XNB.readers.BaseReader{ + static isTypeOf(type) { + // XNA game studio에서 사용되는 데이터 타입의 이름입니다. + // 데이터 타입이 읽히기를 원하면 true를, 아니면 false를 반환합니다. + } + static hasSubType() { + // 데이터 타입이 서브 타입을 가지고 있는지를 반환합니다. + // Array, List, Dictionary 등이 서브 타입을 가지고 있습니다. + } + static parseTypeList() { + // json 파일을 yaml 파일로 변환할 때 타입 데이터를 추가하기 위해 사용됩니다. + // 서브 리더가 실제로 사용하고 있는 순서의 간략화된 데이터 타입 문자열이 담긴 배열을 반환합니다. + } + static type() + { + // 간략화된 데이터 타입니다. 기본적으로 클래스 이름에서 Reader를 제외한 부분이 반환됩니다. + // 만약 클래스명이 실제 간략화된 데이터 타입과 다르다면, 실제 간략화할 데이터 타입을 반환해 주세요. + } + isValueType() { + // 데이터 타입이 원시 자료형인지를 반환합니다. + } + get type() { + // 리더의 문자열화된 타입을 반환합니다. + } + read(buffer, resolver) { + // 버퍼에서 데이터를 읽어오는 것을 구현합니다. + } + write(buffer, content, resolver) { + // 버퍼로 데이터를 쓰는 것을 구현합니다. + } + parseTypeList() { + // 서브 타입이 존재하는 타입의 경우, static 메소드가 아닌 이 메소드를 사용하시기 바랍니다. + } +} + +XNB.addReaders({CustomReader}); + +... +``` + ## 외부 리소스 xnb.js에는 dxt.js와 lz4.js, png.js가 번들링되어 있으며, dxt.js와 lz4.js는 es6 모듈에 최적화되어 재작성되었습니다. 원본 코드의 라이선스는 다음과 같습니다. diff --git a/readme.md b/readme.md index f319b99..941245e 100644 --- a/readme.md +++ b/readme.md @@ -20,11 +20,11 @@ You can load and use a library hosted online. Here's how to use it: #### Load as ES6 Module(Recommended) ```js -import * as XNB from "https://cdn.jsdelivr.net/npm/xnb@1.0.2/dist/xnb.module.js"; +import * as XNB from "https://cdn.jsdelivr.net/npm/xnb@1.1.0/dist/xnb.module.js"; ``` #### Load as UMD ```html - + ``` If you need to support ES5, such as IE11, I recommend using xnb.es5.min.js. @@ -92,8 +92,8 @@ After 1.1 update, you can load and use only a portion of the existing readers, o ### Load only part of existing readers ```js -import * as XNB from "@xnb/core"; -import { LightweightTexture2DReader as Texture2DReader } from "@xnb/readers"; +import * as XNB from "@xnb-js/core"; +import { LightweightTexture2DReader as Texture2DReader } from "@xnb-js/readers"; XNB.setReaders({Texture2DReader}); diff --git a/src/core/readme.md b/src/core/readme.md index 0458930..4424430 100644 --- a/src/core/readme.md +++ b/src/core/readme.md @@ -1,14 +1,14 @@ -@xnb/core +@xnb-js/core ---------------- The core of xnb.js. ### Installation ```bash -npm install @xnb/core +npm install @xnb-js/core ``` ### Usage ```js -import {setReaders, unpackToXnbData} from "@xnb/core"; -import * as Readers from "@xnb/readers"; +import {setReaders, unpackToXnbData} from "@xnb-js/core"; +import * as Readers from "@xnb-js/readers"; setReaders(Readers); diff --git a/src/plugins-stardewvalley/readme.md b/src/plugins-stardewvalley/readme.md index 9e8b50d..aa1790f 100644 --- a/src/plugins-stardewvalley/readme.md +++ b/src/plugins-stardewvalley/readme.md @@ -1,14 +1,14 @@ -@xnb/stardew-valley +@xnb-js/stardew-valley ---------------- The xnb.js reader plugin for Stardew Valley. It was created to respond to the xnb file that stores custom data types added in Stardew Valley 1.4 and later. ### Installation ```bash -npm install @xnb/stardew-valley +npm install @xnb-js/stardew-valley ``` ### Usage ```js -import {setReaders, unpackToXnbData} from "@xnb/core"; -import * as Readers from "@xnb/stardew-valley"; +import {setReaders, unpackToXnbData} from "@xnb-js/core"; +import * as Readers from "@xnb-js/stardew-valley"; setReaders(Readers); diff --git a/src/readers/readme.md b/src/readers/readme.md index 77d4139..d0f4265 100644 --- a/src/readers/readme.md +++ b/src/readers/readme.md @@ -1,4 +1,4 @@ -@xnb/readers +@xnb-js/readers ---------------- The basic readers of xnb.js. ### Installation @@ -7,8 +7,8 @@ npm install @xnb/readers ``` ### Usage ```js -import {setReaders, unpackToXnbData} from "@xnb/core"; -import {Texture2DReader} from "@xnb/readers"; +import {setReaders, unpackToXnbData} from "@xnb-js/core"; +import {Texture2DReader} from "@xnb-js/readers"; setReaders({Texture2DReader});