=== recent Fire3D.vue style/template changes (last commit) ===
5564353 Storybook: Rollenfoerderer-Produkte und Docking-Regeln, Fire3D/Service-Anpassungen
b05bebf Graph-Export-Button + Keyboard-Prototyp fürs Anbauen
ea77fdc Neue Einbaupunkte: GroupProcessor/DefaultCommandProcessor + ProductConfigurator/ProductBrowser/Fire3D
=== grep overflow/height/vh in visual + storybook ===
packages/frontend/src/components/visual/FireContextMenu.vue:68:    overflow: hidden;
packages/frontend/src/components/visual/ProductConfigurator.vue:58:    height: 100%;
packages/frontend/src/components/visual/ProductConfigurator.vue:59:    min-height: 0;
packages/frontend/src/components/visual/Fire3D.vue:246:    height: 100%;
packages/frontend/src/components/visual/Fire3D.vue:247:    min-height: 0;
packages/frontend/src/components/visual/Fire3D.vue:253:    height: 100%;
packages/frontend/src/components/visual/Fire3D.vue:254:    min-height: 0;
packages/frontend/src/components/visual/FireControls.vue:168:    overflow: hidden;
packages/frontend/src/components/visual/ProductEditorDemo.vue:93:    height: 100vh;
] = c; continue; }\n\n    let c_len = _utf8len[c];\n    // skip 5 & 6 byte codes\n    if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }\n\n    // apply mask on first byte\n    c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;\n    // join the rest\n    while (c_len > 1 && i < len) {\n      c = (c << 6) | (buf[i++] & 0x3f);\n      c_len--;\n    }\n\n    // terminated by end of string?\n    if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }\n\n    if (c < 0x10000) {\n      utf16buf[out++] = c;\n    } else {\n      c -= 0x10000;\n      utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);\n      utf16buf[out++] = 0xdc00 | (c & 0x3ff);\n    }\n  }\n\n  return buf2binstring(utf16buf, out);\n};\n\n\n// Calculate max possible position in utf8 buffer,\n// that will not break sequence. If that's not possible\n// - (very small limits) return max size as is.\n//\n// buf[] - utf8 bytes array\n// max   - length limit (mandatory);\nvar utf8border = (buf, max) => {\n\n  max = max || buf.length;\n  if (max > buf.length) { max = buf.length; }\n\n  // go back from last position, until start of sequence found\n  let pos = max - 1;\n  while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }\n\n  // Very small and broken sequence,\n  // return max, because we should return something anyway.\n  if (pos < 0) { return max; }\n\n  // If we came to start of buffer - that means buffer is too small,\n  // return max too.\n  if (pos === 0) { return max; }\n\n  return (pos + _utf8len[buf[pos]] > max) ? pos : max;\n};\n\nvar strings = {\n\tstring2buf: string2buf,\n\tbuf2string: buf2string,\n\tutf8border: utf8border\n};\n\n// (C) 1995-2013 Jean-loup Gailly and Mark Adler\n// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin\n//\n// This software is provided 'as-is', without any express or implied\n// warranty. In no event will the authors be held liable for any damages\n// arising from the use of this software.\n//\n// Permission is granted to anyone to use this software for any purpose,\n// including commercial applications, and to alter it and redistribute it\n// freely, subject to the following restrictions:\n//\n// 1. The origin of this software must not be misrepresented; you must not\n//   claim that you wrote the original software. If you use this software\n//   in a product, an acknowledgment in the product documentation would be\n//   appreciated but is not required.\n// 2. Altered source versions must be plainly marked as such, and must not be\n//   misrepresented as being the original software.\n// 3. This notice may not be removed or altered from any source distribution.\n\nfunction ZStream() {\n  /* next input byte */\n  this.input = null; // JS specific, because we have no pointers\n  this.next_in = 0;\n  /* number of bytes available at input */\n  this.avail_in = 0;\n  /* total number of input bytes read so far */\n  this.total_in = 0;\n  /* next output byte should be put there */\n  this.output = null; // JS specific, because we have no pointers\n  this.next_out = 0;\n  /* remaining free space at output */\n  this.avail_out = 0;\n  /* total number of bytes output so far */\n  this.total_out = 0;\n  /* last error message, NULL if no error */\n  this.msg = ''/*Z_NULL*/;\n  /* not visible by applications */\n  this.state = null;\n  /* best guess about the data type: binary or text */\n  this.data_type = 2/*Z_UNKNOWN*/;\n  /* adler32 value of the uncompressed data */\n  this.adler = 0;\n}\n\nvar zstream = ZStream;\n\nconst toString$1 = Object.prototype.toString;\n\n/* Public constants ==========================================================*/\n/* ===========================================================================*/\n\nconst {\n  Z_NO_FLUSH: Z_NO_FLUSH$1, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH: Z_FINISH$2,\n  Z_OK: Z_OK$2, Z_STREAM_END: Z_STREAM_END$2,\n  Z_DEFAULT_COMPRESSION,\n  Z_DEFAULT_STRATEGY,\n  Z_DEFLATED: Z_DEFLATED$1\n} = constants$2;\n\n/* ===========================================================================*/\n\n\n/**\n * class Deflate\n *\n * Generic JS-style wrapper for zlib calls. If you don't need\n * streaming behaviour - use more simple functions: [[deflate]],\n * [[deflateRaw]] and [[gzip]].\n **/\n\n/* internal\n * Deflate.chunks -> Array\n *\n * Chunks of output data, if [[Deflate#onData]] not overridden.\n **/\n\n/**\n * Deflate.result -> Uint8Array\n *\n * Compressed result, generated by default [[Deflate#onData]]\n * and [[Deflate#onEnd]] handlers. Filled after you push last chunk\n * (call [[Deflate#push]] with `Z_FINISH` / `true` param).\n **/\n\n/**\n * Deflate.err -> Number\n *\n * Error code after deflate finished. 0 (Z_OK) on success.\n * You will not need it in real life, because deflate errors\n * are possible only on wrong options or bad `onData` / `onEnd`\n * custom handlers.\n **/\n\n/**\n * Deflate.msg -> String\n *\n * Error message, if [[Deflate.err]] != 0\n **/\n\n\n/**\n * new Deflate(options)\n * - options (Object): zlib deflate options.\n *\n * Creates new deflator instance with specified params. Throws exception\n * on bad params. Supported options:\n *\n * - `level`\n * - `windowBits`\n * - `memLevel`\n * - `strategy`\n * - `dictionary`\n *\n * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)\n * for more information on these.\n *\n * Additional options, for internal needs:\n *\n * - `chunkSize` - size of generated data chunks (16K by default)\n * - `raw` (Boolean) - do raw deflate\n * - `gzip` (Boolean) - create gzip wrapper\n * - `header` (Object) - custom header for gzip\n *   - `text` (Boolean) - true if compressed data believed to be text\n *   - `time` (Number) - modification time, unix timestamp\n *   - `os` (Number) - operation system code\n *   - `extra` (Array) - array of bytes with extra data (max 65536)\n *   - `name` (String) - file name (binary string)\n *   - `comment` (String) - comment (binary string)\n *   - `hcrc` (Boolean) - true if header crc should be added\n *\n * ##### Example:\n *\n * ```javascript\n * const pako = require('pako')\n *   , chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9])\n *   , chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]);\n *\n * const deflate = new pako.Deflate({ level: 3});\n *\n * deflate.push(chunk1, false);\n * deflate.push(chunk2, true);  // true -> last chunk\n *\n * if (deflate.err) { throw new Error(deflate.err); }\n *\n * console.log(deflate.result);\n * ```\n **/\nfunction Deflate$1(options) {\n  this.options = common.assign({\n    level: Z_DEFAULT_COMPRESSION,\n    method: Z_DEFLATED$1,\n    chunkSize: 16384,\n    windowBits: 15,\n    memLevel: 8,\n    strategy: Z_DEFAULT_STRATEGY\n  }, options || {});\n\n  let opt = this.options;\n\n  if (opt.raw && (opt.windowBits > 0)) {\n    opt.windowBits = -opt.windowBits;\n  }\n\n  else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {\n    opt.windowBits += 16;\n  }\n\n  this.err    = 0;      // error code, if happens (0 = Z_OK)\n  this.msg    = '';     // error message\n  this.ended  = false;  // used to avoid multiple onEnd() calls\n  this.chunks = [];     // chunks of compressed data\n\n  this.strm = new zstream();\n  this.strm.avail_out = 0;\n\n  let status = deflate_1$2.deflateInit2(\n    this.strm,\n    opt.level,\n    opt.method,\n    opt.windowBits,\n    opt.memLevel,\n    opt.strategy\n  );\n\n  if (status !== Z_OK$2) {\n    throw new Error(messages[status]);\n  }\n\n  if (opt.header) {\n    deflate_1$2.deflateSetHeader(this.strm, opt.header);\n  }\n\n  if (opt.dictionary) {\n    let dict;\n    // Convert data if needed\n    if (typeof opt.dictionary === 'string') {\n      // If we need to compress text, change encoding to utf8.\n      dict = strings.string2buf(opt.dictionary);\n    } else if (toString$1.call(opt.dictionary) === '[object ArrayBuffer]') {\n      dict = new Uint8Array(opt.dictionary);\n    } else {\n      dict = opt.dictionary;\n    }\n\n    status = deflate_1$2.deflateSetDictionary(this.strm, dict);\n\n    if (status !== Z_OK$2) {\n      throw new Error(messages[status]);\n    }\n\n    this._dict_set = true;\n  }\n}\n\n/**\n * Deflate#push(data[, flush_mode]) -> Boolean\n * - data (Uint8Array|ArrayBuffer|String): input data. Strings will be\n *   converted to utf8 byte sequence.\n * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.\n *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.\n *\n * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with\n * new compressed chunks. Returns `true` on success. The last data block must\n * have `flush_mode` Z_FINISH (or `true`). That will flush internal pending\n * buffers and call [[Deflate#onEnd]].\n *\n * On fail call [[Deflate#onEnd]] with error code and return false.\n *\n * ##### Example\n *\n * ```javascript\n * push(chunk, false); // push one of data chunks\n * ...\n * push(chunk, true);  // push last chunk\n * ```\n **/\nDeflate$1.prototype.push = function (data, flush_mode) {\n  const strm = this.strm;\n  const chunkSize = this.options.chunkSize;\n  let status, _flush_mode;\n\n  if (this.ended) { return false; }\n\n  if (flush_mode === ~~flush_mode) _flush_mode = flush_mode;\n  else _flush_mode = flush_mode === true ? Z_FINISH$2 : Z_NO_FLUSH$1;\n\n  // Convert data if needed\n  if (typeof data === 'string') {\n    // If we need to compress text, change encoding to utf8.\n    strm.input = strings.string2buf(data);\n  } else if (toString$1.call(data) === '[object ArrayBuffer]') {\n    strm.input = new Uint8Array(data);\n  } else {\n    strm.input = data;\n  }\n\n  strm.next_in = 0;\n  strm.avail_in = strm.input.length;\n\n  for (;;) {\n    if (strm.avail_out === 0) {\n      strm.output = new Uint8Array(chunkSize);\n      strm.next_out = 0;\n      strm.avail_out = chunkSize;\n    }\n\n    // Make sure avail_out > 6 to avoid repeating markers\n    if ((_flush_mode === Z_SYNC_FLUSH || _flush_mode === Z_FULL_FLUSH) && strm.avail_out <= 6) {\n      this.onData(strm.output.subarray(0, strm.next_out));\n      strm.avail_out = 0;\n      continue;\n    }\n\n    status = deflate_1$2.deflate(strm, _flush_mode);\n\n    // Ended => flush and finish\n    if (status === Z_STREAM_END$2) {\n      if (strm.next_out > 0) {\n        this.onData(strm.output.subarray(0, strm.next_out));\n      }\n      status = deflate_1$2.deflateEnd(this.strm);\n      this.onEnd(status);\n      this.ended = true;\n      return status === Z_OK$2;\n    }\n\n    // Flush if out buffer full\n    if (strm.avail_out === 0) {\n      this.onData(strm.output);\n      continue;\n    }\n\n    // Flush if requested and has data\n    if (_flush_mode > 0 && strm.next_out > 0) {\n      this.onData(strm.output.subarray(0, strm.next_out));\n      strm.avail_out = 0;\n      continue;\n    }\n\n    if (strm.avail_in === 0) break;\n  }\n\n  return true;\n};\n\n\n/**\n * Deflate#onData(chunk) -> Void\n * - chunk (Uint8Array): output data.\n *\n * By default, stores data blocks in `chunks[]` property and glue\n * those in `onEnd`. Override this handler, if you need another behaviour.\n **/\nDeflate$1.prototype.onData = function (chunk) {\n  this.chunks.push(chunk);\n};\n\n\n/**\n * Deflate#onEnd(status) -> Void\n * - status (Number): deflate status. 0 (Z_OK) on success,\n *   other if not.\n *\n * Called once after you tell deflate that the input stream is\n * complete (Z_FINISH). By default - join collected chunks,\n * free memory and fill `results` / `err` properties.\n **/\nDeflate$1.prototype.onEnd = function (status) {\n  // On success - join\n  if (status === Z_OK$2) {\n    this.result = common.flattenChunks(this.chunks);\n  }\n  this.chunks = [];\n  this.err = status;\n  this.msg = this.strm.msg;\n};\n\n\n/**\n * deflate(data[, options]) -> Uint8Array\n * - data (Uint8Array|ArrayBuffer|String): input data to compress.\n * - options (Object): zlib deflate options.\n *\n * Compress `data` with deflate algorithm and `options`.\n *\n * Supported options are:\n *\n * - level\n * - windowBits\n * - memLevel\n * - strategy\n * - dictionary\n *\n * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)\n * for more information on these.\n *\n * Sugar (options):\n *\n * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify\n *   negative windowBits implicitly.\n *\n * ##### Example:\n *\n * ```javascript\n * const pako = require('pako')\n * const data = new Uint8Array([1,2,3,4,5,6,7,8,9]);\n *\n * console.log(pako.deflate(data));\n * ```\n **/\nfunction deflate$1(input, options) {\n  const deflator = new Deflate$1(options);\n\n  deflator.push(input, true);\n\n  // That will never happens, if you don't cheat with options :)\n  if (deflator.err) { throw deflator.msg || messages[deflator.err]; }\n\n  return deflator.result;\n}\n\n\n/**\n * deflateRaw(data[, options]) -> Uint8Array\n * - data (Uint8Array|ArrayBuffer|String): input data to compress.\n * - options (Object): zlib deflate options.\n *\n * The same as [[deflate]], but creates raw data, without wrapper\n * (header and adler32 crc).\n **/\nfunction deflateRaw$1(input, options) {\n  options = options || {};\n  options.raw = true;\n  return deflate$1(input, options);\n}\n\n\n/**\n * gzip(data[, options]) -> Uint8Array\n * - data (Uint8Array|ArrayBuffer|String): input data to compress.\n * - options (Object): zlib deflate options.\n *\n * The same as [[deflate]], but create gzip wrapper instead of\n * deflate one.\n **/\nfunction gzip$1(input, options) {\n  options = options || {};\n  options.gzip = true;\n  return deflate$1(input, options);\n}\n\n\nvar Deflate_1$1 = Deflate$1;\nvar deflate_2 = deflate$1;\nvar deflateRaw_1$1 = deflateRaw$1;\nvar gzip_1$1 = gzip$1;\nvar constants$1 = constants$2;\n\nvar deflate_1$1 = {\n\tDeflate: Deflate_1$1,\n\tdeflate: deflate_2,\n\tdeflateRaw: deflateRaw_1$1,\n\tgzip: gzip_1$1,\n\tconstants: constants$1\n};\n\n// (C) 1995-2013 Jean-loup Gailly and Mark Adler\n// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin\n//\n// This software is provided 'as-is', without any express or implied\n// warranty. In no event will the authors be held liable for any damages\n// arising from the use of this software.\n//\n// Permission is granted to anyone to use this software for any purpose,\n// including commercial applications, and to alter it and redistribute it\n// freely, subject to the following restrictions:\n//\n// 1. The origin of this software must not be misrepresented; you must not\n//   claim that you wrote the original software. If you use this software\n//   in a product, an acknowledgment in the product documentation would be\n//   appreciated but is not required.\n// 2. Altered source versions must be plainly marked as such, and must not be\n//   misrepresented as being the original software.\n// 3. This notice may not be removed or altered from any source distribution.\n\n// See state defs from inflate.js\nconst BAD$1 = 16209;       /* got a data error -- remain here until reset */\nconst TYPE$1 = 16191;      /* i: waiting for type bits, including last-flag bit */\n\n/*\n   Decode literal, length, and distance codes and write out the resulting\n   literal and match bytes until either not enough input or output is\n   available, an end-of-block is encountered, or a data error is encountered.\n   When large enough input and output buffers are supplied to inflate(), for\n   example, a 16K input buffer and a 64K output buffer, more than 95% of the\n   inflate execution time is spent in this routine.\n\n   Entry assumptions:\n\n        state.mode === LEN\n        strm.avail_in >= 6\n        strm.avail_out >= 258\n        start >= strm.avail_out\n        state.bits < 8\n\n   On return, state.mode is one of:\n\n        LEN -- ran out of enough output space or enough available input\n        TYPE -- reached end of block code, inflate() to interpret next block\n        BAD -- error in block data\n\n   Notes:\n\n    - The maximum input bits used by a length/distance pair is 15 bits for the\n      length code, 5 bits for the length extra, 15 bits for the distance code,\n      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.\n      Therefore if strm.avail_in >= 6, then there is enough input to avoid\n      checking for available input while decoding.\n\n    - The maximum bytes that a single length/distance pair can output is 258\n      bytes, which is the maximum length that can be coded.  inflate_fast()\n      requires strm.avail_out >= 258 for each loop to avoid checking for\n      output space.\n */\nvar inffast = function inflate_fast(strm, start) {\n  let _in;                    /* local strm.input */\n  let last;                   /* have enough input while in < last */\n  let _out;                   /* local strm.output */\n  let beg;                    /* inflate()'s initial strm.output */\n  let end;                    /* while out < end, enough space available */\n//#ifdef INFLATE_STRICT\n  let dmax;                   /* maximum distance from zlib header */\n//#endif\n  let wsize;                  /* window size or zero if not using window */\n  let whave;                  /* valid bytes in the window */\n  let wnext;                  /* window write index */\n  // Use `s_window` instead `window`, avoid conflict with instrumentation tools\n  let s_window;               /* allocated sliding window, if wsize != 0 */\n  let hold;                   /* local strm.hold */\n  let bits;                   /* local strm.bits */\n  let lcode;                  /* local strm.lencode */\n  let dcode;                  /* local strm.distcode */\n  let lmask;                  /* mask for first level of length codes */\n  let dmask;                  /* mask for first level of distance codes */\n  let here;                   /* retrieved table entry */\n  let op;                     /* code bits, operation, extra bits, or */\n                              /*  window position, window bytes to copy */\n  let len;                    /* match length, unused bytes */\n  let dist;                   /* match distance */\n  let from;                   /* where to copy match from */\n  let from_source;\n\n\n  let input, output; // JS specific, because we have no pointers\n\n  /* copy state to local variables */\n  const state = strm.state;\n  //here = state.here;\n  _in = strm.next_in;\n  input = strm.input;\n  last = _in + (strm.avail_in - 5);\n  _out = strm.next_out;\n  output = strm.output;\n  beg = _out - (start - strm.avail_out);\n  end = _out + (strm.avail_out - 257);\n//#ifdef INFLATE_STRICT\n  dmax = state.dmax;\n//#endif\n  wsize = state.wsize;\n  whave = state.whave;\n  wnext = state.wnext;\n  s_window = state.window;\n  hold = state.hold;\n  bits = state.bits;\n  lcode = state.lencode;\n  dcode = state.distcode;\n  lmask = (1 << state.lenbits) - 1;\n  dmask = (1 << state.distbits) - 1;\n\n\n  /* decode literals and length/distances until end-of-block or not enough\n     input data or output space */\n\n  top:\n  do {\n    if (bits < 15) {\n      hold += input[_in++] << bits;\n      bits += 8;\n      hold += input[_in++] << bits;\n      bits += 8;\n    }\n\n    here = lcode[hold & lmask];\n\n    dolen:\n    for (;;) { // Goto emulation\n      op = here >>> 24/*here.bits*/;\n      hold >>>= op;\n      bits -= op;\n      op = (here >>> 16) & 0xff/*here.op*/;\n      if (op === 0) {                          /* literal */\n        //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?\n        //        \"inflate:         literal '%c'\\n\" :\n        //        \"inflate:         literal 0x%02x\\n\", here.val));\n        output[_out++] = here & 0xffff/*here.val*/;\n      }\n      else if (op & 16) {                     /* length base */\n        len = here & 0xffff/*here.val*/;\n        op &= 15;                           /* number of extra bits */\n        if (op) {\n          if (bits < op) {\n            hold += input[_in++] << bits;\n            bits += 8;\n          }\n          len += hold & ((1 << op) - 1);\n          hold >>>= op;\n          bits -= op;\n        }\n        //Tracevv((stderr, \"inflate:         length %u\\n\", len));\n        if (bits < 15) {\n          hold += input[_in++] << bits;\n          bits += 8;\n          hold += input[_in++] << bits;\n          bits += 8;\n        }\n        here = dcode[hold & dmask];\n\n        dodist:\n        for (;;) { // goto emulation\n          op = here >>> 24/*here.bits*/;\n          hold >>>= op;\n          bits -= op;\n          op = (here >>> 16) & 0xff/*here.op*/;\n\n          if (op & 16) {                      /* distance base */\n            dist = here & 0xffff/*here.val*/;\n            op &= 15;                       /* number of extra bits */\n            if (bits < op) {\n              hold += input[_in++] << bits;\n              bits += 8;\n              if (bits < op) {\n                hold += input[_in++] << bits;\n                bits += 8;\n              }\n            }\n            dist += hold & ((1 << op) - 1);\n//#ifdef INFLATE_STRICT\n            if (dist > dmax) {\n              strm.msg = 'invalid distance too far back';\n              state.mode = BAD$1;\n              break top;\n            }\n//#endif\n            hold >>>= op;\n            bits -= op;\n            //Tracevv((stderr, \"inflate:         distance %u\\n\", dist));\n            op = _out - beg;                /* max distance in output */\n            if (dist > op) {                /* see if copy from window */\n              op = dist - op;               /* distance back in window */\n              if (op > whave) {\n                if (state.sane) {\n                  strm.msg = 'invalid distance too far back';\n                  state.mode = BAD$1;\n                  break top;\n                }\n\n// (!) This block is disabled in zlib defaults,\n// don't enable it for binary compatibility\n//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR\n//                if (len <= op - whave) {\n//                  do {\n//                    output[_out++] = 0;\n//                  } while (--len);\n//                  continue top;\n//                }\n//                len -= op - whave;\n//                do {\n//                  output[_out++] = 0;\n//                } while (--op > whave);\n//                if (op === 0) {\n//                  from = _out - dist;\n//                  do {\n//                    output[_out++] = output[from++];\n//                  } while (--len);\n//                  continue top;\n//                }\n//#endif\n              }\n              from = 0; // window index\n              from_source = s_window;\n              if (wnext === 0) {           /* very common case */\n                from += wsize - op;\n                if (op < len) {         /* some from window */\n                  len -= op;\n                  do {\n                    output[_out++] = s_window[from++];\n                  } while (--op);\n                  from = _out - dist;  /* rest from output */\n                  from_source = output;\n                }\n              }\n              else if (wnext < op) {      /* wrap around window */\n                from += wsize + wnext - op;\n                op -= wnext;\n                if (op < len) {         /* some from end of window */\n                  len -= op;\n                  do {\n                    output[_out++] = s_window[from++];\n                  } while (--op);\n                  from = 0;\n                  if (wnext < len) {  /* some from start of window */\n                    op = wnext;\n                    len -= op;\n                    do {\n                      output[_out++] = s_window[from++];\n                    } while (--op);\n                    from = _out - dist;      /* rest from output */\n                    from_source = output;\n                  }\n                }\n              }\n              else {                      /* contiguous in window */\n                from += wnext - op;\n                if (op < len) {         /* some from window */\n                  len -= op;\n                  do {\n                    output[_out++] = s_window[from++];\n                  } while (--op);\n                  from = _out - dist;  /* rest from output */\n                  from_source = output;\n                }\n              }\n              while (len > 2) {\n                output[_out++] = from_source[from++];\n                output[_out++] = from_source[from++];\n                output[_out++] = from_source[from++];\n                len -= 3;\n              }\n              if (len) {\n                output[_out++] = from_source[from++];\n                if (len > 1) {\n                  output[_out++] = from_source[from++];\n                }\n              }\n            }\n            else {\n              from = _out - dist;          /* copy direct from output */\n              do {                        /* minimum length is three */\n                output[_out++] = output[from++];\n                output[_out++] = output[from++];\n                output[_out++] = output[from++];\n                len -= 3;\n              } while (len > 2);\n              if (len) {\n                output[_out++] = output[from++];\n                if (len > 1) {\n                  output[_out++] = output[from++];\n                }\n              }\n            }\n          }\n          else if ((op & 64) === 0) {          /* 2nd level distance code */\n            here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];\n            continue dodist;\n          }\n          else {\n            strm.msg = 'invalid distance code';\n            state.mode = BAD$1;\n            break top;\n          }\n\n          break; // need to emulate goto via \"continue\"\n        }\n      }\n      else if ((op & 64) === 0) {              /* 2nd level length code */\n        here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];\n        continue dolen;\n      }\n      else if (op & 32) {                     /* end-of-block */\n        //Tracevv((stderr, \"inflate:         end of block\\n\"));\n        state.mode = TYPE$1;\n        break top;\n      }\n      else {\n        strm.msg = 'invalid literal/length code';\n        state.mode = BAD$1;\n        break top;\n      }\n\n      break; // need to emulate goto via \"continue\"\n    }\n  } while (_in < last && _out < end);\n\n  /* return unused bytes (on entry, bits < 8, so in won't go too far back) */\n  len = bits >> 3;\n  _in -= len;\n  bits -= len << 3;\n  hold &= (1 << bits) - 1;\n\n  /* update state and return */\n  strm.next_in = _in;\n  strm.next_out = _out;\n  strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));\n  strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));\n  state.hold = hold;\n  state.bits = bits;\n  return;\n};\n\n// (C) 1995-2013 Jean-loup Gailly and Mark Adler\n// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin\n//\n// This software is provided 'as-is', without any express or implied\n// warranty. In no event will the authors be held liable for any damages\n// arising from the use of this software.\n//\n// Permission is granted to anyone to use this software for any purpose,\n// including commercial applications, and to alter it and redistribute it\n// freely, subject to the following restrictions:\n//\n// 1. The origin of this software must not be misrepresented; you must not\n//   claim that you wrote the original software. If you use this software\n//   in a product, an acknowledgment in the product documentation would be\n//   appreciated but is not required.\n// 2. Altered source versions must be plainly marked as such, and must not be\n//   misrepresented as being the original software.\n// 3. This notice may not be removed or altered from any source distribution.\n\nconst MAXBITS = 15;\nconst ENOUGH_LENS$1 = 852;\nconst ENOUGH_DISTS$1 = 592;\n//const ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);\n\nconst CODES$1 = 0;\nconst LENS$1 = 1;\nconst DISTS$1 = 2;\n\nconst lbase = new Uint16Array([ /* Length codes 257..285 base */\n  3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,\n  35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0\n]);\n\nconst lext = new Uint8Array([ /* Length codes 257..285 extra */\n  16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,\n  19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78\n]);\n\nconst dbase = new Uint16Array([ /* Distance codes 0..29 base */\n  1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\n  257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\n  8193, 12289, 16385, 24577, 0, 0\n]);\n\nconst dext = new Uint8Array([ /* Distance codes 0..29 extra */\n  16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,\n  23, 23, 24, 24, 25, 25, 26, 26, 27, 27,\n  28, 28, 29, 29, 64, 64\n]);\n\nconst inflate_table = (type, lens, lens_index, codes, table, table_index, work, opts) =>\n{\n  const bits = opts.bits;\n      //here = opts.here; /* table entry for duplication */\n\n  let len = 0;               /* a code's length in bits */\n  let sym = 0;               /* index of code symbols */\n  let min = 0, max = 0;          /* minimum and maximum code lengths */\n  let root = 0;              /* number of index bits for root table */\n  let curr = 0;              /* number of index bits for current table */\n  let drop = 0;              /* code bits to drop for sub-table */\n  let left = 0;                   /* number of prefix codes available */\n  let used = 0;              /* code entries in table used */\n  let huff = 0;              /* Huffman code */\n  let incr;              /* for incrementing code, index */\n  let fill;              /* index for replicating entries */\n  let low;               /* low bits for current root entry */\n  let mask;              /* mask for low root bits */\n  let next;             /* next available space in table */\n  let base = null;     /* base value table to use */\n//  let shoextra;    /* extra bits table to use */\n  let match;                  /* use base and extra for symbol >= match */\n  const count = new Uint16Array(MAXBITS + 1); //[MAXBITS+1];    /* number of codes of each length */\n  const offs = new Uint16Array(MAXBITS + 1); //[MAXBITS+1];     /* offsets in table for each length */\n  let extra = null;\n\n  let here_bits, here_op, here_val;\n\n  /*\n   Process a set of code lengths to create a canonical Huffman code.  The\n   code lengths are lens[0..codes-1].  Each length corresponds to the\n   symbols 0..codes-1.  The Huffman code is generated by first sorting the\n   symbols by length from short to long, and retaining the symbol order\n   for codes with equal lengths.  Then the code starts with all zero bits\n   for the first code of the shortest length, and the codes are integer\n   increments for the same length, and zeros are appended as the length\n   increases.  For the deflate format, these bits are stored backwards\n   from their more natural integer increment ordering, and so when the\n   decoding tables are built in the large loop below, the integer codes\n   are incremented backwards.\n\n   This routine assumes, but does not check, that all of the entries in\n   lens[] are in the range 0..MAXBITS.  The caller must assure this.\n   1..MAXBITS is interpreted as that code length.  zero means that that\n   symbol does not occur in this code.\n\n   The codes are sorted by computing a count of codes for each length,\n   creating from that a table of starting indices for each length in the\n   sorted table, and then entering the symbols in order in the sorted\n   table.  The sorted table is work[], with that space being provided by\n   the caller.\n\n   The length counts are used for other purposes as well, i.e. finding\n   the minimum and maximum length codes, determining if there are any\n   codes at all, checking for a valid set of lengths, and looking ahead\n   at length counts to determine sub-table sizes when building the\n   decoding tables.\n   */\n\n  /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */\n  for (len = 0; len <= MAXBITS; len++) {\n    count[len] = 0;\n  }\n  for (sym = 0; sym < codes; sym++) {\n    count[lens[lens_index + sym]]++;\n  }\n\n  /* bound code lengths, force root to be within code lengths */\n  root = bits;\n  for (max = MAXBITS; max >= 1; max--) {\n    if (count[max] !== 0) { break; }\n  }\n  if (root > max) {\n    root = max;\n  }\n  if (max === 0) {                     /* no symbols to code at all */\n    //table.op[opts.table_index] = 64;  //here.op = (var char)64;    /* invalid code marker */\n    //table.bits[opts.table_index] = 1;   //here.bits = (var char)1;\n    //table.val[opts.table_index++] = 0;   //here.val = (var short)0;\n    table[table_index++] = (1 << 24) | (64 << 16) | 0;\n\n\n    //table.op[opts.table_index] = 64;\n    //table.bits[opts.table_index] = 1;\n    //table.val[opts.table_index++] = 0;\n    table[table_index++] = (1 << 24) | (64 << 16) | 0;\n\n    opts.bits = 1;\n    return 0;     /* no symbols, but wait for decoding to report error */\n  }\n  for (min = 1; min < max; min++) {\n    if (count[min] !== 0) { break; }\n  }\n  if (root < min) {\n    root = min;\n  }\n\n  /* check for an over-subscribed or incomplete set of lengths */\n  left = 1;\n  for (len = 1; len <= MAXBITS; len++) {\n    left <<= 1;\n    left -= count[len];\n    if (left < 0) {\n      return -1;\n    }        /* over-subscribed */\n  }\n  if (left > 0 && (type === CODES$1 || max !== 1)) {\n    return -1;                      /* incomplete set */\n  }\n\n  /* generate offsets into symbol table for each length for sorting */\n  offs[1] = 0;\n  for (len = 1; len < MAXBITS; len++) {\n    offs[len + 1] = offs[len] + count[len];\n  }\n\n  /* sort symbols by length, by symbol order within each length */\n  for (sym = 0; sym < codes; sym++) {\n    if (lens[lens_index + sym] !== 0) {\n      work[offs[lens[lens_index + sym]]++] = sym;\n    }\n  }\n\n  /*\n   Create and fill in decoding tables.  In this loop, the table being\n   filled is at next and has curr index bits.  The code being used is huff\n   with length len.  That code is converted to an index by dropping drop\n   bits off of the bottom.  For codes where len is less than drop + curr,\n   those top drop + curr - len bits are incremented through all values to\n   fill the table with replicated entries.\n\n   root is the number of index bits for the root table.  When len exceeds\n   root, sub-tables are created pointed to by the root entry with an index\n   of the low root bits of huff.  This is saved in low to check for when a\n   new sub-table should be started.  drop is zero when the root table is\n   being filled, and drop is root when sub-tables are being filled.\n\n   When a new sub-table is needed, it is necessary to look ahead in the\n   code lengths to determine what size sub-table is needed.  The length\n   counts are used for this, and so count[] is decremented as codes are\n   entered in the tables.\n\n   used keeps track of how many table entries have been allocated from the\n   provided *table space.  It is checked for LENS and DIST tables against\n   the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in\n   the initial root table size constants.  See the comments in inftrees.h\n   for more information.\n\n   sym increments through all symbols, and the loop terminates when\n   all codes of length max, i.e. all codes, have been processed.  This\n   routine permits incomplete codes, so another loop after this one fills\n   in the rest of the decoding tables with invalid code markers.\n   */\n\n  /* set up for code type */\n  // poor man optimization - use if-else instead of switch,\n  // to avoid deopts in old v8\n  if (type === CODES$1) {\n    base = extra = work;    /* dummy value--not used */\n    match = 20;\n\n  } else if (type === LENS$1) {\n    base = lbase;\n    extra = lext;\n    match = 257;\n\n  } else {                    /* DISTS */\n    base = dbase;\n    extra = dext;\n    match = 0;\n  }\n\n  /* initialize opts for loop */\n  huff = 0;                   /* starting code */\n  sym = 0;                    /* starting code symbol */\n  len = min;                  /* starting code length */\n  next = table_index;              /* current table to fill in */\n  curr = root;                /* current table index bits */\n  drop = 0;                   /* current bits to drop from code for index */\n  low = -1;                   /* trigger new sub-table when len > root */\n  used = 1 << root;          /* use root table entries */\n  mask = used - 1;            /* mask for comparing low */\n\n  /* check available table space */\n  if ((type === LENS$1 && used > ENOUGH_LENS$1) ||\n    (type === DISTS$1 && used > ENOUGH_DISTS$1)) {\n    return 1;\n  }\n\n  /* process all codes and make table entries */\n  for (;;) {\n    /* create table entry */\n    here_bits = len - drop;\n    if (work[sym] + 1 < match) {\n      here_op = 0;\n      here_val = work[sym];\n    }\n    else if (work[sym] >= match) {\n      here_op = extra[work[sym] - match];\n      here_val = base[work[sym] - match];\n    }\n    else {\n      here_op = 32 + 64;         /* end of block */\n      here_val = 0;\n    }\n\n    /* replicate for those indices with low len bits equal to huff */\n    incr = 1 << (len - drop);\n    fill = 1 << curr;\n    min = fill;                 /* save offset to next table */\n    do {\n      fill -= incr;\n      table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;\n    } while (fill !== 0);\n\n    /* backwards increment the len-bit code huff */\n    incr = 1 << (len - 1);\n    while (huff & incr) {\n      incr >>= 1;\n    }\n    if (incr !== 0) {\n      huff &= incr - 1;\n      huff += incr;\n    } else {\n      huff = 0;\n    }\n\n    /* go to next symbol, update count, len */\n    sym++;\n    if (--count[len] === 0) {\n      if (len === max) { break; }\n      len = lens[lens_index + work[sym]];\n    }\n\n    /* create new sub-table if needed */\n    if (len > root && (huff & mask) !== low) {\n      /* if first time, transition to sub-tables */\n      if (drop === 0) {\n        drop = root;\n      }\n\n      /* increment past last table */\n      next += min;            /* here min is 1 << curr */\n\n      /* determine length of next table */\n      curr = len - drop;\n      left = 1 << curr;\n      while (curr + drop < max) {\n        left -= count[curr + drop];\n        if (left <= 0) { break; }\n        curr++;\n        left <<= 1;\n      }\n\n      /* check for enough space */\n      used += 1 << curr;\n      if ((type === LENS$1 && used > ENOUGH_LENS$1) ||\n        (type === DISTS$1 && used > ENOUGH_DISTS$1)) {\n        return 1;\n      }\n\n      /* point entry in root table to sub-table */\n      low = huff & mask;\n      /*table.op[low] = curr;\n      table.bits[low] = root;\n      table.val[low] = next - opts.table_index;*/\n      table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;\n    }\n  }\n\n  /* fill in remaining table entry if code is incomplete (guaranteed to have\n   at most one remaining entry, since if the code is incomplete, the\n   maximum code length that was allowed to get this far is one bit) */\n  if (huff !== 0) {\n    //table.op[next + huff] = 64;            /* invalid code marker */\n    //table.bits[next + huff] = len - drop;\n    //table.val[next + huff] = 0;\n    table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;\n  }\n\n  /* set return parameters */\n  //opts.table_index += used;\n  opts.bits = root;\n  return 0;\n};\n\n\nvar inftrees = inflate_table;\n\n// (C) 1995-2013 Jean-loup Gailly and Mark Adler\n// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin\n//\n// This software is provided 'as-is', without any express or implied\n// warranty. In no event will the authors be held liable for any damages\n// arising from the use of this software.\n//\n// Permission is granted to anyone to use this software for any purpose,\n// including commercial applications, and to alter it and redistribute it\n// freely, subject to the following restrictions:\n//\n// 1. The origin of this software must not be misrepresented; you must not\n//   claim that you wrote the original software. If you use this software\n//   in a product, an acknowledgment in the product documentation would be\n//   appreciated but is not required.\n// 2. Altered source versions must be plainly marked as such, and must not be\n//   misrepresented as being the original software.\n// 3. This notice may not be removed or altered from any source distribution.\n\n\n\n\n\n\nconst CODES = 0;\nconst LENS = 1;\nconst DISTS = 2;\n\n/* Public constants ==========================================================*/\n/* ===========================================================================*/\n\nconst {\n  Z_FINISH: Z_FINISH$1, Z_BLOCK, Z_TREES,\n  Z_OK: Z_OK$1, Z_STREAM_END: Z_STREAM_END$1, Z_NEED_DICT: Z_NEED_DICT$1, Z_STREAM_ERROR: Z_STREAM_ERROR$1, Z_DATA_ERROR: Z_DATA_ERROR$1, Z_MEM_ERROR: Z_MEM_ERROR$1, Z_BUF_ERROR,\n  Z_DEFLATED\n} = constants$2;\n\n\n/* STATES ====================================================================*/\n/* ===========================================================================*/\n\n\nconst    HEAD = 16180;       /* i: waiting for magic header */\nconst    FLAGS = 16181;      /* i: waiting for method and flags (gzip) */\nconst    TIME = 16182;       /* i: waiting for modification time (gzip) */\nconst    OS = 16183;         /* i: waiting for extra flags and operating system (gzip) */\nconst    EXLEN = 16184;      /* i: waiting for extra length (gzip) */\nconst    EXTRA = 16185;      /* i: waiting for extra bytes (gzip) */\nconst    NAME = 16186;       /* i: waiting for end of file name (gzip) */\nconst    COMMENT = 16187;    /* i: waiting for end of comment (gzip) */\nconst    HCRC = 16188;       /* i: waiting for header crc (gzip) */\nconst    DICTID = 16189;    /* i: waiting for dictionary check value */\nconst    DICT = 16190;      /* waiting for inflateSetDictionary() call */\nconst        TYPE = 16191;      /* i: waiting for type bits, including last-flag bit */\nconst        TYPEDO = 16192;    /* i: same, but skip check to exit inflate on new block */\nconst        STORED = 16193;    /* i: waiting for stored size (length and complement) */\nconst        COPY_ = 16194;     /* i/o: same as COPY below, but only first time in */\nconst        COPY = 16195;      /* i/o: waiting for input or output to copy stored block */\nconst        TABLE = 16196;     /* i: waiting for dynamic block table lengths */\nconst        LENLENS = 16197;   /* i: waiting for code length code lengths */\nconst        CODELENS = 16198;  /* i: waiting for length/lit and distance code lengths */\nconst            LEN_ = 16199;      /* i: same as LEN below, but only first time in */\nconst            LEN = 16200;       /* i: waiting for length/lit/eob code */\nconst            LENEXT = 16201;    /* i: waiting for length extra bits */\nconst            DIST = 16202;      /* i: waiting for distance code */\nconst            DISTEXT = 16203;   /* i: waiting for distance extra bits */\nconst            MATCH = 16204;     /* o: waiting for output space to copy string */\nconst            LIT = 16205;       /* o: waiting for output space to write literal */\nconst    CHECK = 16206;     /* i: waiting for 32-bit check value */\nconst    LENGTH = 16207;    /* i: waiting for 32-bit length (gzip) */\nconst    DONE = 16208;      /* finished check, done -- remain here until reset */\nconst    BAD = 16209;       /* got a data error -- remain here until reset */\nconst    MEM = 16210;       /* got an inflate() memory error -- remain here until reset */\nconst    SYNC = 16211;      /* looking for synchronization bytes to restart inflate() */\n\n/* ===========================================================================*/\n\n\n\nconst ENOUGH_LENS = 852;\nconst ENOUGH_DISTS = 592;\n//const ENOUGH =  (ENOUGH_LENS+ENOUGH_DISTS);\n\nconst MAX_WBITS = 15;\n/* 32K LZ77 window */\nconst DEF_WBITS = MAX_WBITS;\n\n\nconst zswap32 = (q) => {\n\n  return  (((q >>> 24) & 0xff) +\n          ((q >>> 8) & 0xff00) +\n          ((q & 0xff00) << 8) +\n          ((q & 0xff) << 24));\n};\n\n\nfunction InflateState() {\n  this.strm = null;           /* pointer back to this zlib stream */\n  this.mode = 0;              /* current inflate mode */\n  this.last = false;          /* true if processing last block */\n  this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip,\n                                 bit 2 true to validate check value */\n  this.havedict = false;      /* true if dictionary provided */\n  this.flags = 0;             /* gzip header method and flags (0 if zlib), or\n                                 -1 if raw or no header yet */\n  this.dmax = 0;              /* zlib header max distance (INFLATE_STRICT) */\n  this.check = 0;             /* protected copy of check value */\n  this.total = 0;             /* protected copy of output count */\n  // TODO: may be {}\n  this.head = null;           /* where to save gzip header information */\n\n  /* sliding window */\n  this.wbits = 0;             /* log base 2 of requested window size */\n  this.wsize = 0;             /* window size or zero if not using window */\n  this.whave = 0;             /* valid bytes in the window */\n  this.wnext = 0;             /* window write index */\n  this.window = null;         /* allocated sliding window, if needed */\n\n  /* bit accumulator */\n  this.hold = 0;              /* input bit accumulator */\n  this.bits = 0;              /* number of bits in \"in\" */\n\n  /* for string and stored block copying */\n  this.length = 0;            /* literal or length of data to copy */\n  this.offset = 0;            /* distance back to copy string from */\n\n  /* for table and code decoding */\n  this.extra = 0;             /* extra bits needed */\n\n  /* fixed and dynamic code tables */\n  this.lencode = null;          /* starting table for length/literal codes */\n  this.distcode = null;         /* starting table for distance codes */\n  this.lenbits = 0;           /* index bits for lencode */\n  this.distbits = 0;          /* index bits for distcode */\n\n  /* dynamic table building */\n  this.ncode = 0;             /* number of code length code lengths */\n  this.nlen = 0;              /* number of length code lengths */\n  this.ndist = 0;             /* number of distance code lengths */\n  this.have = 0;              /* number of code lengths in lens[] */\n  this.next = null;              /* next available space in codes[] */\n\n  this.lens = new Uint16Array(320); /* temporary storage for code lengths */\n  this.work = new Uint16Array(288); /* work area for code table building */\n\n  /*\n   because we don't have pointers in js, we use lencode and distcode directly\n   as buffers so we don't need codes\n  */\n  //this.codes = new Int32Array(ENOUGH);       /* space for code tables */\n  this.lendyn = null;              /* dynamic table for length/literal codes (JS specific) */\n  this.distdyn = null;             /* dynamic table for distance codes (JS specific) */\n  this.sane = 0;                   /* if false, allow invalid distance too far */\n  this.back = 0;                   /* bits back of last unprocessed length/lit */\n  this.was = 0;                    /* initial length of match */\n}\n\n\nconst inflateStateCheck = (strm) => {\n\n  if (!strm) {\n    return 1;\n  }\n  const state = strm.state;\n  if (!state || state.strm !== strm ||\n    state.mode < HEAD || state.mode > SYNC) {\n    return 1;\n  }\n  return 0;\n};\n\n\nconst inflateResetKeep = (strm) => {\n\n  if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }\n  const state = strm.state;\n  strm.total_in = strm.total_out = state.total = 0;\n  strm.msg = ''; /*Z_NULL*/\n  if (state.wrap) {       /* to support ill-conceived Java test suite */\n    strm.adler = state.wrap & 1;\n  }\n  state.mode = HEAD;\n  state.last = 0;\n  state.havedict = 0;\n  state.flags = -1;\n  state.dmax = 32768;\n  state.head = null/*Z_NULL*/;\n  state.hold = 0;\n  state.bits = 0;\n  //state.lencode = state.distcode = state.next = state.codes;\n  state.lencode = state.lendyn = new Int32Array(ENOUGH_LENS);\n  state.distcode = state.distdyn = new Int32Array(ENOUGH_DISTS);\n\n  state.sane = 1;\n  state.back = -1;\n  //Tracev((stderr, \"inflate: reset\\n\"));\n  return Z_OK$1;\n};\n\n\nconst inflateReset = (strm) => {\n\n  if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }\n  const state = strm.state;\n  state.wsize = 0;\n  state.whave = 0;\n  state.wnext = 0;\n  return inflateResetKeep(strm);\n\n};\n\n\nconst inflateReset2 = (strm, windowBits) => {\n  let wrap;\n\n  /* get the state */\n  if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }\n  const state = strm.state;\n\n  /* extract wrap request from windowBits parameter */\n  if (windowBits < 0) {\n    wrap = 0;\n    windowBits = -windowBits;\n  }\n  else {\n    wrap = (windowBits >> 4) + 5;\n    if (windowBits < 48) {\n      windowBits &= 15;\n    }\n  }\n\n  /* set number of window bits, free window if different */\n  if (windowBits && (windowBits < 8 || windowBits > 15)) {\n    return Z_STREAM_ERROR$1;\n  }\n  if (state.window !== null && state.wbits !== windowBits) {\n    state.window = null;\n  }\n\n  /* update state and reset the rest of it */\n  state.wrap = wrap;\n  state.wbits = windowBits;\n  return inflateReset(strm);\n};\n\n\nconst inflateInit2 = (strm, windowBits) => {\n\n  if (!strm) { return Z_STREAM_ERROR$1; }\n  //strm.msg = Z_NULL;                 /* in case we return an error */\n\n  const state = new InflateState();\n\n  //if (state === Z_NULL) return Z_MEM_ERROR;\n  //Tracev((stderr, \"inflate: allocated\\n\"));\n  strm.state = state;\n  state.strm = strm;\n  state.window = null/*Z_NULL*/;\n  state.mode = HEAD;     /* to pass state test in inflateReset2() */\n  const ret = inflateReset2(strm, windowBits);\n  if (ret !== Z_OK$1) {\n    strm.state = null/*Z_NULL*/;\n  }\n  return ret;\n};\n\n\nconst inflateInit = (strm) => {\n\n  return inflateInit2(strm, DEF_WBITS);\n};\n\n\n/*\n Return state with length and distance decoding tables and index sizes set to\n fixed code decoding.  Normally this returns fixed tables from inffixed.h.\n If BUILDFIXED is defined, then instead this routine builds the tables the\n first time it's called, and returns those tables the first time and\n thereafter.  This reduces the size of the code by about 2K bytes, in\n exchange for a little execution time.  However, BUILDFIXED should not be\n used for threaded applications, since the rewriting of the tables and virgin\n may not be thread-safe.\n */\nlet virgin = true;\n\nlet lenfix, distfix; // We have no pointers in JS, so keep tables separate\n\n\nconst fixedtables = (state) => {\n\n  /* build fixed huffman tables if first call (may not be thread safe) */\n  if (virgin) {\n    lenfix = new Int32Array(512);\n    distfix = new Int32Array(32);\n\n    /* literal/length table */\n    let sym = 0;\n    while (sym < 144) { state.lens[sym++] = 8; }\n    while (sym < 256) { state.lens[sym++] = 9; }\n    while (sym < 280) { state.lens[sym++] = 7; }\n    while (sym < 288) { state.lens[sym++] = 8; }\n\n    inftrees(LENS,  state.lens, 0, 288, lenfix,   0, state.work, { bits: 9 });\n\n    /* distance table */\n    sym = 0;\n    while (sym < 32) { state.lens[sym++] = 5; }\n\n    inftrees(DISTS, state.lens, 0, 32,   distfix, 0, state.work, { bits: 5 });\n\n    /* do this just once */\n    virgin = false;\n  }\n\n  state.lencode = lenfix;\n  state.lenbits = 9;\n  state.distcode = distfix;\n  state.distbits = 5;\n};\n\n\n/*\n Update the window with the last wsize (normally 32K) bytes written before\n returning.  If window does not exist yet, create it.  This is only called\n when a window is already in use, or when output has been written during this\n inflate call, but the end of the deflate stream has not been reached yet.\n It is also called to create a window for dictionary data when a dictionary\n is loaded.\n\n Providing output buffers larger than 32K to inflate() should provide a speed\n advantage, since only the last 32K of output is copied to the sliding window\n upon return from inflate(), and since all distances after the first 32K of\n output will fall in the output data, making match copies simpler and faster.\n The advantage may be dependent on the size of the processor's data caches.\n */\nconst updatewindow = (strm, src, end, copy) => {\n\n  let dist;\n  const state = strm.state;\n\n  /* if it hasn't been done already, allocate space for the window */\n  if (state.window === null) {\n    state.wsize = 1 << state.wbits;\n    state.wnext = 0;\n    state.whave = 0;\n\n    state.window = new Uint8Array(state.wsize);\n  }\n\n  /* copy state->wsize or less output bytes into the circular window */\n  if (copy >= state.wsize) {\n    state.window.set(src.subarray(end - state.wsize, end), 0);\n    state.wnext = 0;\n    state.whave = state.wsize;\n  }\n  else {\n    dist = state.wsize - state.wnext;\n    if (dist > copy) {\n      dist = copy;\n    }\n    //zmemcpy(state->window + state->wnext, end - copy, dist);\n    state.window.set(src.subarray(end - copy, end - copy + dist), state.wnext);\n    copy -= dist;\n    if (copy) {\n      //zmemcpy(state->window, end - copy, copy);\n      state.window.set(src.subarray(end - copy, end), 0);\n      state.wnext = copy;\n      state.whave = state.wsize;\n    }\n    else {\n      state.wnext += dist;\n      if (state.wnext === state.wsize) { state.wnext = 0; }\n      if (state.whave < state.wsize) { state.whave += dist; }\n    }\n  }\n  return 0;\n};\n\n\nconst inflate$2 = (strm, flush) => {\n\n  let state;\n  let input, output;          // input/output buffers\n  let next;                   /* next input INDEX */\n  let put;                    /* next output INDEX */\n  let have, left;             /* available input and output */\n  let hold;                   /* bit buffer */\n  let bits;                   /* bits in bit buffer */\n  let _in, _out;              /* save starting available input and output */\n  let copy;                   /* number of stored or match bytes to copy */\n  let from;                   /* where to copy match bytes from */\n  let from_source;\n  let here = 0;               /* current decoding table entry */\n  let here_bits, here_op, here_val; // paked \"here\" denormalized (JS specific)\n  //let last;                   /* parent table entry */\n  let last_bits, last_op, last_val; // paked \"last\" denormalized (JS specific)\n  let len;                    /* length to copy for repeats, bits to drop */\n  let ret;                    /* return code */\n  const hbuf = new Uint8Array(4);    /* buffer for gzip header crc calculation */\n  let opts;\n\n  let n; // temporary variable for NEED_BITS\n\n  const order = /* permutation of code lengths */\n    new Uint8Array([ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ]);\n\n\n  if (inflateStateCheck(strm) || !strm.output ||\n      (!strm.input && strm.avail_in !== 0)) {\n    return Z_STREAM_ERROR$1;\n  }\n\n  state = strm.state;\n  if (state.mode === TYPE) { state.mode = TYPEDO; }    /* skip check */\n\n\n  //--- LOAD() ---\n  put = strm.next_out;\n  output = strm.output;\n  left = strm.avail_out;\n  next = strm.next_in;\n  input = strm.input;\n  have = strm.avail_in;\n  hold = state.hold;\n  bits = state.bits;\n  //---\n\n  _in = have;\n  _out = left;\n  ret = Z_OK$1;\n\n  inf_leave: // goto emulation\n  for (;;) {\n    switch (state.mode) {\n      case HEAD:\n        if (state.wrap === 0) {\n          state.mode = TYPEDO;\n          break;\n        }\n        //=== NEEDBITS(16);\n        while (bits < 16) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        if ((state.wrap & 2) && hold === 0x8b1f) {  /* gzip header */\n          if (state.wbits === 0) {\n            state.wbits = 15;\n          }\n          state.check = 0/*crc32(0L, Z_NULL, 0)*/;\n          //=== CRC2(state.check, hold);\n          hbuf[0] = hold & 0xff;\n          hbuf[1] = (hold >>> 8) & 0xff;\n          state.check = crc32_1(state.check, hbuf, 2, 0);\n          //===//\n\n          //=== INITBITS();\n          hold = 0;\n          bits = 0;\n          //===//\n          state.mode = FLAGS;\n          break;\n        }\n        if (state.head) {\n          state.head.done = false;\n        }\n        if (!(state.wrap & 1) ||   /* check if zlib header allowed */\n          (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {\n          strm.msg = 'incorrect header check';\n          state.mode = BAD;\n          break;\n        }\n        if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {\n          strm.msg = 'unknown compression method';\n          state.mode = BAD;\n          break;\n        }\n        //--- DROPBITS(4) ---//\n        hold >>>= 4;\n        bits -= 4;\n        //---//\n        len = (hold & 0x0f)/*BITS(4)*/ + 8;\n        if (state.wbits === 0) {\n          state.wbits = len;\n        }\n        if (len > 15 || len > state.wbits) {\n          strm.msg = 'invalid window size';\n          state.mode = BAD;\n          break;\n        }\n\n        // !!! pako patch. Force use `options.windowBits` if passed.\n        // Required to always use max window size by default.\n        state.dmax = 1 << state.wbits;\n        //state.dmax = 1 << len;\n\n        state.flags = 0;               /* indicate zlib header */\n        //Tracev((stderr, \"inflate:   zlib header ok\\n\"));\n        strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;\n        state.mode = hold & 0x200 ? DICTID : TYPE;\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        break;\n      case FLAGS:\n        //=== NEEDBITS(16); */\n        while (bits < 16) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        state.flags = hold;\n        if ((state.flags & 0xff) !== Z_DEFLATED) {\n          strm.msg = 'unknown compression method';\n          state.mode = BAD;\n          break;\n        }\n        if (state.flags & 0xe000) {\n          strm.msg = 'unknown header flags set';\n          state.mode = BAD;\n          break;\n        }\n        if (state.head) {\n          state.head.text = ((hold >> 8) & 1);\n        }\n        if ((state.flags & 0x0200) && (state.wrap & 4)) {\n          //=== CRC2(state.check, hold);\n          hbuf[0] = hold & 0xff;\n          hbuf[1] = (hold >>> 8) & 0xff;\n          state.check = crc32_1(state.check, hbuf, 2, 0);\n          //===//\n        }\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        state.mode = TIME;\n        /* falls through */\n      case TIME:\n        //=== NEEDBITS(32); */\n        while (bits < 32) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        if (state.head) {\n          state.head.time = hold;\n        }\n        if ((state.flags & 0x0200) && (state.wrap & 4)) {\n          //=== CRC4(state.check, hold)\n          hbuf[0] = hold & 0xff;\n          hbuf[1] = (hold >>> 8) & 0xff;\n          hbuf[2] = (hold >>> 16) & 0xff;\n          hbuf[3] = (hold >>> 24) & 0xff;\n          state.check = crc32_1(state.check, hbuf, 4, 0);\n          //===\n        }\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        state.mode = OS;\n        /* falls through */\n      case OS:\n        //=== NEEDBITS(16); */\n        while (bits < 16) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        if (state.head) {\n          state.head.xflags = (hold & 0xff);\n          state.head.os = (hold >> 8);\n        }\n        if ((state.flags & 0x0200) && (state.wrap & 4)) {\n          //=== CRC2(state.check, hold);\n          hbuf[0] = hold & 0xff;\n          hbuf[1] = (hold >>> 8) & 0xff;\n          state.check = crc32_1(state.check, hbuf, 2, 0);\n          //===//\n        }\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        state.mode = EXLEN;\n        /* falls through */\n      case EXLEN:\n        if (state.flags & 0x0400) {\n          //=== NEEDBITS(16); */\n          while (bits < 16) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          state.length = hold;\n          if (state.head) {\n            state.head.extra_len = hold;\n          }\n          if ((state.flags & 0x0200) && (state.wrap & 4)) {\n            //=== CRC2(state.check, hold);\n            hbuf[0] = hold & 0xff;\n            hbuf[1] = (hold >>> 8) & 0xff;\n            state.check = crc32_1(state.check, hbuf, 2, 0);\n            //===//\n          }\n          //=== INITBITS();\n          hold = 0;\n          bits = 0;\n          //===//\n        }\n        else if (state.head) {\n          state.head.extra = null/*Z_NULL*/;\n        }\n        state.mode = EXTRA;\n        /* falls through */\n      case EXTRA:\n        if (state.flags & 0x0400) {\n          copy = state.length;\n          if (copy > have) { copy = have; }\n          if (copy) {\n            if (state.head) {\n              len = state.head.extra_len - state.length;\n              if (!state.head.extra) {\n                // Use untyped array for more convenient processing later\n                state.head.extra = new Uint8Array(state.head.extra_len);\n              }\n              state.head.extra.set(\n                input.subarray(\n                  next,\n                  // extra field is limited to 65536 bytes\n                  // - no need for additional size check\n                  next + copy\n                ),\n                /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/\n                len\n              );\n              //zmemcpy(state.head.extra + len, next,\n              //        len + copy > state.head.extra_max ?\n              //        state.head.extra_max - len : copy);\n            }\n            if ((state.flags & 0x0200) && (state.wrap & 4)) {\n              state.check = crc32_1(state.check, input, copy, next);\n            }\n            have -= copy;\n            next += copy;\n            state.length -= copy;\n          }\n          if (state.length) { break inf_leave; }\n        }\n        state.length = 0;\n        state.mode = NAME;\n        /* falls through */\n      case NAME:\n        if (state.flags & 0x0800) {\n          if (have === 0) { break inf_leave; }\n          copy = 0;\n          do {\n            // TODO: 2 or 1 bytes?\n            len = input[next + copy++];\n            /* use constant limit because in js we should not preallocate memory */\n            if (state.head && len &&\n                (state.length < 65536 /*state.head.name_max*/)) {\n              state.head.name += String.fromCharCode(len);\n            }\n          } while (len && copy < have);\n\n          if ((state.flags & 0x0200) && (state.wrap & 4)) {\n            state.check = crc32_1(state.check, input, copy, next);\n          }\n          have -= copy;\n          next += copy;\n          if (len) { break inf_leave; }\n        }\n        else if (state.head) {\n          state.head.name = null;\n        }\n        state.length = 0;\n        state.mode = COMMENT;\n        /* falls through */\n      case COMMENT:\n        if (state.flags & 0x1000) {\n          if (have === 0) { break inf_leave; }\n          copy = 0;\n          do {\n            len = input[next + copy++];\n            /* use constant limit because in js we should not preallocate memory */\n            if (state.head && len &&\n                (state.length < 65536 /*state.head.comm_max*/)) {\n              state.head.comment += String.fromCharCode(len);\n            }\n          } while (len && copy < have);\n          if ((state.flags & 0x0200) && (state.wrap & 4)) {\n            state.check = crc32_1(state.check, input, copy, next);\n          }\n          have -= copy;\n          next += copy;\n          if (len) { break inf_leave; }\n        }\n        else if (state.head) {\n          state.head.comment = null;\n        }\n        state.mode = HCRC;\n        /* falls through */\n      case HCRC:\n        if (state.flags & 0x0200) {\n          //=== NEEDBITS(16); */\n          while (bits < 16) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          if ((state.wrap & 4) && hold !== (state.check & 0xffff)) {\n            strm.msg = 'header crc mismatch';\n            state.mode = BAD;\n            break;\n          }\n          //=== INITBITS();\n          hold = 0;\n          bits = 0;\n          //===//\n        }\n        if (state.head) {\n          state.head.hcrc = ((state.flags >> 9) & 1);\n          state.head.done = true;\n        }\n        strm.adler = state.check = 0;\n        state.mode = TYPE;\n        break;\n      case DICTID:\n        //=== NEEDBITS(32); */\n        while (bits < 32) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        strm.adler = state.check = zswap32(hold);\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        state.mode = DICT;\n        /* falls through */\n      case DICT:\n        if (state.havedict === 0) {\n          //--- RESTORE() ---\n          strm.next_out = put;\n          strm.avail_out = left;\n          strm.next_in = next;\n          strm.avail_in = have;\n          state.hold = hold;\n          state.bits = bits;\n          //---\n          return Z_NEED_DICT$1;\n        }\n        strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;\n        state.mode = TYPE;\n        /* falls through */\n      case TYPE:\n        if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }\n        /* falls through */\n      case TYPEDO:\n        if (state.last) {\n          //--- BYTEBITS() ---//\n          hold >>>= bits & 7;\n          bits -= bits & 7;\n          //---//\n          state.mode = CHECK;\n          break;\n        }\n        //=== NEEDBITS(3); */\n        while (bits < 3) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        state.last = (hold & 0x01)/*BITS(1)*/;\n        //--- DROPBITS(1) ---//\n        hold >>>= 1;\n        bits -= 1;\n        //---//\n\n        switch ((hold & 0x03)/*BITS(2)*/) {\n          case 0:                             /* stored block */\n            //Tracev((stderr, \"inflate:     stored block%s\\n\",\n            //        state.last ? \" (last)\" : \"\"));\n            state.mode = STORED;\n            break;\n          case 1:                             /* fixed block */\n            fixedtables(state);\n            //Tracev((stderr, \"inflate:     fixed codes block%s\\n\",\n            //        state.last ? \" (last)\" : \"\"));\n            state.mode = LEN_;             /* decode codes */\n            if (flush === Z_TREES) {\n              //--- DROPBITS(2) ---//\n              hold >>>= 2;\n              bits -= 2;\n              //---//\n              break inf_leave;\n            }\n            break;\n          case 2:                             /* dynamic block */\n            //Tracev((stderr, \"inflate:     dynamic codes block%s\\n\",\n            //        state.last ? \" (last)\" : \"\"));\n            state.mode = TABLE;\n            break;\n          case 3:\n            strm.msg = 'invalid block type';\n            state.mode = BAD;\n        }\n        //--- DROPBITS(2) ---//\n        hold >>>= 2;\n        bits -= 2;\n        //---//\n        break;\n      case STORED:\n        //--- BYTEBITS() ---// /* go to byte boundary */\n        hold >>>= bits & 7;\n        bits -= bits & 7;\n        //---//\n        //=== NEEDBITS(32); */\n        while (bits < 32) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {\n          strm.msg = 'invalid stored block lengths';\n          state.mode = BAD;\n          break;\n        }\n        state.length = hold & 0xffff;\n        //Tracev((stderr, \"inflate:       stored length %u\\n\",\n        //        state.length));\n        //=== INITBITS();\n        hold = 0;\n        bits = 0;\n        //===//\n        state.mode = COPY_;\n        if (flush === Z_TREES) { break inf_leave; }\n        /* falls through */\n      case COPY_:\n        state.mode = COPY;\n        /* falls through */\n      case COPY:\n        copy = state.length;\n        if (copy) {\n          if (copy > have) { copy = have; }\n          if (copy > left) { copy = left; }\n          if (copy === 0) { break inf_leave; }\n          //--- zmemcpy(put, next, copy); ---\n          output.set(input.subarray(next, next + copy), put);\n          //---//\n          have -= copy;\n          next += copy;\n          left -= copy;\n          put += copy;\n          state.length -= copy;\n          break;\n        }\n        //Tracev((stderr, \"inflate:       stored end\\n\"));\n        state.mode = TYPE;\n        break;\n      case TABLE:\n        //=== NEEDBITS(14); */\n        while (bits < 14) {\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n        }\n        //===//\n        state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;\n        //--- DROPBITS(5) ---//\n        hold >>>= 5;\n        bits -= 5;\n        //---//\n        state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;\n        //--- DROPBITS(5) ---//\n        hold >>>= 5;\n        bits -= 5;\n        //---//\n        state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;\n        //--- DROPBITS(4) ---//\n        hold >>>= 4;\n        bits -= 4;\n        //---//\n//#ifndef PKZIP_BUG_WORKAROUND\n        if (state.nlen > 286 || state.ndist > 30) {\n          strm.msg = 'too many length or distance symbols';\n          state.mode = BAD;\n          break;\n        }\n//#endif\n        //Tracev((stderr, \"inflate:       table sizes ok\\n\"));\n        state.have = 0;\n        state.mode = LENLENS;\n        /* falls through */\n      case LENLENS:\n        while (state.have < state.ncode) {\n          //=== NEEDBITS(3);\n          while (bits < 3) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);\n          //--- DROPBITS(3) ---//\n          hold >>>= 3;\n          bits -= 3;\n          //---//\n        }\n        while (state.have < 19) {\n          state.lens[order[state.have++]] = 0;\n        }\n        // We have separate tables & no pointers. 2 commented lines below not needed.\n        //state.next = state.codes;\n        //state.lencode = state.next;\n        // Switch to use dynamic table\n        state.lencode = state.lendyn;\n        state.lenbits = 7;\n\n        opts = { bits: state.lenbits };\n        ret = inftrees(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);\n        state.lenbits = opts.bits;\n\n        if (ret) {\n          strm.msg = 'invalid code lengths set';\n          state.mode = BAD;\n          break;\n        }\n        //Tracev((stderr, \"inflate:       code lengths ok\\n\"));\n        state.have = 0;\n        state.mode = CODELENS;\n        /* falls through */\n      case CODELENS:\n        while (state.have < state.nlen + state.ndist) {\n          for (;;) {\n            here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/\n            here_bits = here >>> 24;\n            here_op = (here >>> 16) & 0xff;\n            here_val = here & 0xffff;\n\n            if ((here_bits) <= bits) { break; }\n            //--- PULLBYTE() ---//\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n            //---//\n          }\n          if (here_val < 16) {\n            //--- DROPBITS(here.bits) ---//\n            hold >>>= here_bits;\n            bits -= here_bits;\n            //---//\n            state.lens[state.have++] = here_val;\n          }\n          else {\n            if (here_val === 16) {\n              //=== NEEDBITS(here.bits + 2);\n              n = here_bits + 2;\n              while (bits < n) {\n                if (have === 0) { break inf_leave; }\n                have--;\n                hold += input[next++] << bits;\n                bits += 8;\n              }\n              //===//\n              //--- DROPBITS(here.bits) ---//\n              hold >>>= here_bits;\n              bits -= here_bits;\n              //---//\n              if (state.have === 0) {\n                strm.msg = 'invalid bit length repeat';\n                state.mode = BAD;\n                break;\n              }\n              len = state.lens[state.have - 1];\n              copy = 3 + (hold & 0x03);//BITS(2);\n              //--- DROPBITS(2) ---//\n              hold >>>= 2;\n              bits -= 2;\n              //---//\n            }\n            else if (here_val === 17) {\n              //=== NEEDBITS(here.bits + 3);\n              n = here_bits + 3;\n              while (bits < n) {\n                if (have === 0) { break inf_leave; }\n                have--;\n                hold += input[next++] << bits;\n                bits += 8;\n              }\n              //===//\n              //--- DROPBITS(here.bits) ---//\n              hold >>>= here_bits;\n              bits -= here_bits;\n              //---//\n              len = 0;\n              copy = 3 + (hold & 0x07);//BITS(3);\n              //--- DROPBITS(3) ---//\n              hold >>>= 3;\n              bits -= 3;\n              //---//\n            }\n            else {\n              //=== NEEDBITS(here.bits + 7);\n              n = here_bits + 7;\n              while (bits < n) {\n                if (have === 0) { break inf_leave; }\n                have--;\n                hold += input[next++] << bits;\n                bits += 8;\n              }\n              //===//\n              //--- DROPBITS(here.bits) ---//\n              hold >>>= here_bits;\n              bits -= here_bits;\n              //---//\n              len = 0;\n              copy = 11 + (hold & 0x7f);//BITS(7);\n              //--- DROPBITS(7) ---//\n              hold >>>= 7;\n              bits -= 7;\n              //---//\n            }\n            if (state.have + copy > state.nlen + state.ndist) {\n              strm.msg = 'invalid bit length repeat';\n              state.mode = BAD;\n              break;\n            }\n            while (copy--) {\n              state.lens[state.have++] = len;\n            }\n          }\n        }\n\n        /* handle error breaks in while */\n        if (state.mode === BAD) { break; }\n\n        /* check for end-of-block code (better have one) */\n        if (state.lens[256] === 0) {\n          strm.msg = 'invalid code -- missing end-of-block';\n          state.mode = BAD;\n          break;\n        }\n\n        /* build code tables -- note: do not change the lenbits or distbits\n           values here (9 and 6) without reading the comments in inftrees.h\n           concerning the ENOUGH constants, which depend on those values */\n        state.lenbits = 9;\n\n        opts = { bits: state.lenbits };\n        ret = inftrees(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);\n        // We have separate tables & no pointers. 2 commented lines below not needed.\n        // state.next_index = opts.table_index;\n        state.lenbits = opts.bits;\n        // state.lencode = state.next;\n\n        if (ret) {\n          strm.msg = 'invalid literal/lengths set';\n          state.mode = BAD;\n          break;\n        }\n\n        state.distbits = 6;\n        //state.distcode.copy(state.codes);\n        // Switch to use dynamic table\n        state.distcode = state.distdyn;\n        opts = { bits: state.distbits };\n        ret = inftrees(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);\n        // We have separate tables & no pointers. 2 commented lines below not needed.\n        // state.next_index = opts.table_index;\n        state.distbits = opts.bits;\n        // state.distcode = state.next;\n\n        if (ret) {\n          strm.msg = 'invalid distances set';\n          state.mode = BAD;\n          break;\n        }\n        //Tracev((stderr, 'inflate:       codes ok\\n'));\n        state.mode = LEN_;\n        if (flush === Z_TREES) { break inf_leave; }\n        /* falls through */\n      case LEN_:\n        state.mode = LEN;\n        /* falls through */\n      case LEN:\n        if (have >= 6 && left >= 258) {\n          //--- RESTORE() ---\n          strm.next_out = put;\n          strm.avail_out = left;\n          strm.next_in = next;\n          strm.avail_in = have;\n          state.hold = hold;\n          state.bits = bits;\n          //---\n          inffast(strm, _out);\n          //--- LOAD() ---\n          put = strm.next_out;\n          output = strm.output;\n          left = strm.avail_out;\n          next = strm.next_in;\n          input = strm.input;\n          have = strm.avail_in;\n          hold = state.hold;\n          bits = state.bits;\n          //---\n\n          if (state.mode === TYPE) {\n            state.back = -1;\n          }\n          break;\n        }\n        state.back = 0;\n        for (;;) {\n          here = state.lencode[hold & ((1 << state.lenbits) - 1)];  /*BITS(state.lenbits)*/\n          here_bits = here >>> 24;\n          here_op = (here >>> 16) & 0xff;\n          here_val = here & 0xffff;\n\n          if (here_bits <= bits) { break; }\n          //--- PULLBYTE() ---//\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n          //---//\n        }\n        if (here_op && (here_op & 0xf0) === 0) {\n          last_bits = here_bits;\n          last_op = here_op;\n          last_val = here_val;\n          for (;;) {\n            here = state.lencode[last_val +\n                    ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];\n            here_bits = here >>> 24;\n            here_op = (here >>> 16) & 0xff;\n            here_val = here & 0xffff;\n\n            if ((last_bits + here_bits) <= bits) { break; }\n            //--- PULLBYTE() ---//\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n            //---//\n          }\n          //--- DROPBITS(last.bits) ---//\n          hold >>>= last_bits;\n          bits -= last_bits;\n          //---//\n          state.back += last_bits;\n        }\n        //--- DROPBITS(here.bits) ---//\n        hold >>>= here_bits;\n        bits -= here_bits;\n        //---//\n        state.back += here_bits;\n        state.length = here_val;\n        if (here_op === 0) {\n          //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?\n          //        \"inflate:         literal '%c'\\n\" :\n          //        \"inflate:         literal 0x%02x\\n\", here.val));\n          state.mode = LIT;\n          break;\n        }\n        if (here_op & 32) {\n          //Tracevv((stderr, \"inflate:         end of block\\n\"));\n          state.back = -1;\n          state.mode = TYPE;\n          break;\n        }\n        if (here_op & 64) {\n          strm.msg = 'invalid literal/length code';\n          state.mode = BAD;\n          break;\n        }\n        state.extra = here_op & 15;\n        state.mode = LENEXT;\n        /* falls through */\n      case LENEXT:\n        if (state.extra) {\n          //=== NEEDBITS(state.extra);\n          n = state.extra;\n          while (bits < n) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;\n          //--- DROPBITS(state.extra) ---//\n          hold >>>= state.extra;\n          bits -= state.extra;\n          //---//\n          state.back += state.extra;\n        }\n        //Tracevv((stderr, \"inflate:         length %u\\n\", state.length));\n        state.was = state.length;\n        state.mode = DIST;\n        /* falls through */\n      case DIST:\n        for (;;) {\n          here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/\n          here_bits = here >>> 24;\n          here_op = (here >>> 16) & 0xff;\n          here_val = here & 0xffff;\n\n          if ((here_bits) <= bits) { break; }\n          //--- PULLBYTE() ---//\n          if (have === 0) { break inf_leave; }\n          have--;\n          hold += input[next++] << bits;\n          bits += 8;\n          //---//\n        }\n        if ((here_op & 0xf0) === 0) {\n          last_bits = here_bits;\n          last_op = here_op;\n          last_val = here_val;\n          for (;;) {\n            here = state.distcode[last_val +\n                    ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];\n            here_bits = here >>> 24;\n            here_op = (here >>> 16) & 0xff;\n            here_val = here & 0xffff;\n\n            if ((last_bits + here_bits) <= bits) { break; }\n            //--- PULLBYTE() ---//\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n            //---//\n          }\n          //--- DROPBITS(last.bits) ---//\n          hold >>>= last_bits;\n          bits -= last_bits;\n          //---//\n          state.back += last_bits;\n        }\n        //--- DROPBITS(here.bits) ---//\n        hold >>>= here_bits;\n        bits -= here_bits;\n        //---//\n        state.back += here_bits;\n        if (here_op & 64) {\n          strm.msg = 'invalid distance code';\n          state.mode = BAD;\n          break;\n        }\n        state.offset = here_val;\n        state.extra = (here_op) & 15;\n        state.mode = DISTEXT;\n        /* falls through */\n      case DISTEXT:\n        if (state.extra) {\n          //=== NEEDBITS(state.extra);\n          n = state.extra;\n          while (bits < n) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;\n          //--- DROPBITS(state.extra) ---//\n          hold >>>= state.extra;\n          bits -= state.extra;\n          //---//\n          state.back += state.extra;\n        }\n//#ifdef INFLATE_STRICT\n        if (state.offset > state.dmax) {\n          strm.msg = 'invalid distance too far back';\n          state.mode = BAD;\n          break;\n        }\n//#endif\n        //Tracevv((stderr, \"inflate:         distance %u\\n\", state.offset));\n        state.mode = MATCH;\n        /* falls through */\n      case MATCH:\n        if (left === 0) { break inf_leave; }\n        copy = _out - left;\n        if (state.offset > copy) {         /* copy from window */\n          copy = state.offset - copy;\n          if (copy > state.whave) {\n            if (state.sane) {\n              strm.msg = 'invalid distance too far back';\n              state.mode = BAD;\n              break;\n            }\n// (!) This block is disabled in zlib defaults,\n// don't enable it for binary compatibility\n//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR\n//          Trace((stderr, \"inflate.c too far\\n\"));\n//          copy -= state.whave;\n//          if (copy > state.length) { copy = state.length; }\n//          if (copy > left) { copy = left; }\n//          left -= copy;\n//          state.length -= copy;\n//          do {\n//            output[put++] = 0;\n//          } while (--copy);\n//          if (state.length === 0) { state.mode = LEN; }\n//          break;\n//#endif\n          }\n          if (copy > state.wnext) {\n            copy -= state.wnext;\n            from = state.wsize - copy;\n          }\n          else {\n            from = state.wnext - copy;\n          }\n          if (copy > state.length) { copy = state.length; }\n          from_source = state.window;\n        }\n        else {                              /* copy from output */\n          from_source = output;\n          from = put - state.offset;\n          copy = state.length;\n        }\n        if (copy > left) { copy = left; }\n        left -= copy;\n        state.length -= copy;\n        do {\n          output[put++] = from_source[from++];\n        } while (--copy);\n        if (state.length === 0) { state.mode = LEN; }\n        break;\n      case LIT:\n        if (left === 0) { break inf_leave; }\n        output[put++] = state.length;\n        left--;\n        state.mode = LEN;\n        break;\n      case CHECK:\n        if (state.wrap) {\n          //=== NEEDBITS(32);\n          while (bits < 32) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            // Use '|' instead of '+' to make sure that result is signed\n            hold |= input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          _out -= left;\n          strm.total_out += _out;\n          state.total += _out;\n          if ((state.wrap & 4) && _out) {\n            strm.adler = state.check =\n                /*UPDATE_CHECK(state.check, put - _out, _out);*/\n                (state.flags ? crc32_1(state.check, output, _out, put - _out) : adler32_1(state.check, output, _out, put - _out));\n\n          }\n          _out = left;\n          // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too\n          if ((state.wrap & 4) && (state.flags ? hold : zswap32(hold)) !== state.check) {\n            strm.msg = 'incorrect data check';\n            state.mode = BAD;\n            break;\n          }\n          //=== INITBITS();\n          hold = 0;\n          bits = 0;\n          //===//\n          //Tracev((stderr, \"inflate:   check matches trailer\\n\"));\n        }\n        state.mode = LENGTH;\n        /* falls through */\n      case LENGTH:\n        if (state.wrap && state.flags) {\n          //=== NEEDBITS(32);\n          while (bits < 32) {\n            if (have === 0) { break inf_leave; }\n            have--;\n            hold += input[next++] << bits;\n            bits += 8;\n          }\n          //===//\n          if ((state.wrap & 4) && hold !== (state.total & 0xffffffff)) {\n            strm.msg = 'incorrect length check';\n            state.mode = BAD;\n            break;\n          }\n          //=== INITBITS();\n          hold = 0;\n          bits = 0;\n          //===//\n          //Tracev((stderr, \"inflate:   length matches trailer\\n\"));\n        }\n        state.mode = DONE;\n        /* falls through */\n      case DONE:\n        ret = Z_STREAM_END$1;\n        break inf_leave;\n      case BAD:\n        ret = Z_DATA_ERROR$1;\n        break inf_leave;\n      case MEM:\n        return Z_MEM_ERROR$1;\n      case SYNC:\n        /* falls through */\n      default:\n        return Z_STREAM_ERROR$1;\n    }\n  }\n\n  // inf_leave <- here is real place for \"goto inf_leave\", emulated via \"break inf_leave\"\n\n  /*\n     Return from inflate(), updating the total counts and the check value.\n     If there was no progress during the inflate() call, return a buffer\n     error.  Call updatewindow() to create and/or update the window state.\n     Note: a memory error from inflate() is non-recoverable.\n   */\n\n  //--- RESTORE() ---\n  strm.next_out = put;\n  strm.avail_out = left;\n  strm.next_in = next;\n  strm.avail_in = have;\n  state.hold = hold;\n  state.bits = bits;\n  //---\n\n  if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&\n                      (state.mode < CHECK || flush !== Z_FINISH$1))) {\n    if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) ;\n  }\n  _in -= strm.avail_in;\n  _out -= strm.avail_out;\n  strm.total_in += _in;\n  strm.total_out += _out;\n  state.total += _out;\n  if ((state.wrap & 4) && _out) {\n    strm.adler = state.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/\n      (state.flags ? crc32_1(state.check, output, _out, strm.next_out - _out) : adler32_1(state.check, output, _out, strm.next_out - _out));\n  }\n  strm.data_type = state.bits + (state.last ? 64 : 0) +\n                    (state.mode === TYPE ? 128 : 0) +\n                    (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);\n  if (((_in === 0 && _out === 0) || flush === Z_FINISH$1) && ret === Z_OK$1) {\n    ret = Z_BUF_ERROR;\n  }\n  return ret;\n};\n\n\nconst inflateEnd = (strm) => {\n\n  if (inflateStateCheck(strm)) {\n    return Z_STREAM_ERROR$1;\n  }\n\n  let state = strm.state;\n  if (state.window) {\n    state.window = null;\n  }\n  strm.state = null;\n  return Z_OK$1;\n};\n\n\nconst inflateGetHeader = (strm, head) => {\n\n  /* check state */\n  if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }\n  const state = strm.state;\n  if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR$1; }\n\n  /* save header structure */\n  state.head = head;\n  head.done = false;\n  return Z_OK$1;\n};\n\n\nconst inflateSetDictionary = (strm, dictionary) => {\n  const dictLength = dictionary.length;\n\n  let state;\n  let dictid;\n  let ret;\n\n  /* check state */\n  if (inflateStateCheck(strm)) { return Z_STREAM_ERROR$1; }\n  state = strm.state;\n\n  if (state.wrap !== 0 && state.mode !== DICT) {\n    return Z_STREAM_ERROR$1;\n  }\n\n  /* check for correct dictionary identifier */\n  if (state.mode === DICT) {\n    dictid = 1; /* adler32(0, null, 0)*/\n    /* dictid = adler32(dictid, dictionary, dictLength); */\n    dictid = adler32_1(dictid, dictionary, dictLength, 0);\n    if (dictid !== state.check) {\n      return Z_DATA_ERROR$1;\n    }\n  }\n  /* copy dictionary to window using updatewindow(), which will amend the\n   existing dictionary if appropriate */\n  ret = updatewindow(strm, dictionary, dictLength, dictLength);\n  if (ret) {\n    state.mode = MEM;\n    return Z_MEM_ERROR$1;\n  }\n  state.havedict = 1;\n  // Tracev((stderr, \"inflate:   dictionary set\\n\"));\n  return Z_OK$1;\n};\n\n\nvar inflateReset_1 = inflateReset;\nvar inflateReset2_1 = inflateReset2;\nvar inflateResetKeep_1 = inflateResetKeep;\nvar inflateInit_1 = inflateInit;\nvar inflateInit2_1 = inflateInit2;\nvar inflate_2$1 = inflate$2;\nvar inflateEnd_1 = inflateEnd;\nvar inflateGetHeader_1 = inflateGetHeader;\nvar inflateSetDictionary_1 = inflateSetDictionary;\nvar inflateInfo = 'pako inflate (from Nodeca project)';\n\n/* Not implemented\nmodule.exports.inflateCodesUsed = inflateCodesUsed;\nmodule.exports.inflateCopy = inflateCopy;\nmodule.exports.inflateGetDictionary = inflateGetDictionary;\nmodule.exports.inflateMark = inflateMark;\nmodule.exports.inflatePrime = inflatePrime;\nmodule.exports.inflateSync = inflateSync;\nmodule.exports.inflateSyncPoint = inflateSyncPoint;\nmodule.exports.inflateUndermine = inflateUndermine;\nmodule.exports.inflateValidate = inflateValidate;\n*/\n\nvar inflate_1$2 = {\n\tinflateReset: inflateReset_1,\n\tinflateReset2: inflateReset2_1,\n\tinflateResetKeep: inflateResetKeep_1,\n\tinflateInit: inflateInit_1,\n\tinflateInit2: inflateInit2_1,\n\tinflate: inflate_2$1,\n\tinflateEnd: inflateEnd_1,\n\tinflateGetHeader: inflateGetHeader_1,\n\tinflateSetDictionary: inflateSetDictionary_1,\n\tinflateInfo: inflateInfo\n};\n\n// (C) 1995-2013 Jean-loup Gailly and Mark Adler\n// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin\n//\n// This software is provided 'as-is', without any express or implied\n// warranty. In no event will the authors be held liable for any damages\n// arising from the use of this software.\n//\n// Permission is granted to anyone to use this software for any purpose,\n// including commercial applications, and to alter it and redistribute it\n// freely, subject to the following restrictions:\n//\n// 1. The origin of this software must not be misrepresented; you must not\n//   claim that you wrote the original software. If you use this software\n//   in a product, an acknowledgment in the product documentation would be\n//   appreciated but is not required.\n// 2. Altered source versions must be plainly marked as such, and must not be\n//   misrepresented as being the original software.\n// 3. This notice may not be removed or altered from any source distribution.\n\nfunction GZheader() {\n  /* true if compressed data believed to be text */\n  this.text       = 0;\n  /* modification time */\n  this.time       = 0;\n  /* extra flags (not used when writing a gzip file) */\n  this.xflags     = 0;\n  /* operating system */\n  this.os         = 0;\n  /* pointer to extra field or Z_NULL if none */\n  this.extra      = null;\n  /* extra field length (valid if extra != Z_NULL) */\n  this.extra_len  = 0; // Actually, we don't need it in JS,\n                       // but leave for few code modifications\n\n  //\n  // Setup limits is not necessary because in js we should not preallocate memory\n  // for inflate use constant limit in 65536 bytes\n  //\n\n  /* space at extra (only when reading header) */\n  // this.extra_max  = 0;\n  /* pointer to zero-terminated file name or Z_NULL */\n  this.name       = '';\n  /* space at name (only when reading header) */\n  // this.name_max   = 0;\n  /* pointer to zero-terminated comment or Z_NULL */\n  this.comment    = '';\n  /* space at comment (only when reading header) */\n  // this.comm_max   = 0;\n  /* true if there was or will be a header crc */\n  this.hcrc       = 0;\n  /* true when done reading gzip header (not used when writing a gzip file) */\n  this.done       = false;\n}\n\nvar gzheader = GZheader;\n\nconst toString = Object.prototype.toString;\n\n/* Public constants ==========================================================*/\n/* ===========================================================================*/\n\nconst {\n  Z_NO_FLUSH, Z_FINISH,\n  Z_OK, Z_STREAM_END, Z_NEED_DICT, Z_STREAM_ERROR, Z_DATA_ERROR, Z_MEM_ERROR\n} = constants$2;\n\n/* ===========================================================================*/\n\n\n/**\n * class Inflate\n *\n * Generic JS-style wrapper for zlib calls. If you don't need\n * streaming behaviour - use more simple functions: [[inflate]]\n * and [[inflateRaw]].\n **/\n\n/* internal\n * inflate.chunks -> Array\n *\n * Chunks of output data, if [[Inflate#onData]] not overridden.\n **/\n\n/**\n * Inflate.result -> Uint8Array|String\n *\n * Uncompressed result, generated by default [[Inflate#onData]]\n * and [[Inflate#onEnd]] handlers. Filled after you push last chunk\n * (call [[Inflate#push]] with `Z_FINISH` / `true` param).\n **/\n\n/**\n * Inflate.err -> Number\n *\n * Error code after inflate finished. 0 (Z_OK) on success.\n * Should be checked if broken data possible.\n **/\n\n/**\n * Inflate.msg -> String\n *\n * Error message, if [[Inflate.err]] != 0\n **/\n\n\n/**\n * new Inflate(options)\n * - options (Object): zlib inflate options.\n *\n * Creates new inflator instance with specified params. Throws exception\n * on bad params. Supported options:\n *\n * - `windowBits`\n * - `dictionary`\n *\n * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)\n * for more information on these.\n *\n * Additional options, for internal needs:\n *\n * - `chunkSize` - size of generated data chunks (16K by default)\n * - `raw` (Boolean) - do raw inflate\n * - `to` (String) - if equal to 'string', then result will be converted\n *   from utf8 to utf16 (javascript) string. When string output requested,\n *   chunk length can differ from `chunkSize`, depending on content.\n *\n * By default, when no options set, autodetect deflate/gzip data format via\n * wrapper header.\n *\n * ##### Example:\n *\n * ```javascript\n * const pako = require('pako')\n * const chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9])\n * const chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]);\n *\n * const inflate = new pako.Inflate({ level: 3});\n *\n * inflate.push(chunk1, false);\n * inflate.push(chunk2, true);  // true -> last chunk\n *\n * if (inflate.err) { throw new Error(inflate.err); }\n *\n * console.log(inflate.result);\n * ```\n **/\nfunction Inflate$1(options) {\n  this.options = common.assign({\n    chunkSize: 1024 * 64,\n    windowBits: 15,\n    to: ''\n  }, options || {});\n\n  const opt = this.options;\n\n  // Force window size for `raw` data, if not set directly,\n  // because we have no header for autodetect.\n  if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {\n    opt.windowBits = -opt.windowBits;\n    if (opt.windowBits === 0) { opt.windowBits = -15; }\n  }\n\n  // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate\n  if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&\n      !(options && options.windowBits)) {\n    opt.windowBits += 32;\n  }\n\n  // Gzip header has no info about windows size, we can do autodetect only\n  // for deflate. So, if window size not set, force it to max when gzip possible\n  if ((opt.windowBits > 15) && (opt.windowBits < 48)) {\n    // bit 3 (16) -> gzipped data\n    // bit 4 (32) -> autodetect gzip/deflate\n    if ((opt.windowBits & 15) === 0) {\n      opt.windowBits |= 15;\n    }\n  }\n\n  this.err    = 0;      // error code, if happens (0 = Z_OK)\n  this.msg    = '';     // error message\n  this.ended  = false;  // used to avoid multiple onEnd() calls\n  this.chunks = [];     // chunks of compressed data\n\n  this.strm   = new zstream();\n  this.strm.avail_out = 0;\n\n  let status  = inflate_1$2.inflateInit2(\n    this.strm,\n    opt.windowBits\n  );\n\n  if (status !== Z_OK) {\n    throw new Error(messages[status]);\n  }\n\n  this.header = new gzheader();\n\n  inflate_1$2.inflateGetHeader(this.strm, this.header);\n\n  // Setup dictionary\n  if (opt.dictionary) {\n    // Convert data if needed\n    if (typeof opt.dictionary === 'string') {\n      opt.dictionary = strings.string2buf(opt.dictionary);\n    } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {\n      opt.dictionary = new Uint8Array(opt.dictionary);\n    }\n    if (opt.raw) { //In raw mode we need to set the dictionary early\n      status = inflate_1$2.inflateSetDictionary(this.strm, opt.dictionary);\n      if (status !== Z_OK) {\n        throw new Error(messages[status]);\n      }\n    }\n  }\n}\n\n/**\n * Inflate#push(data[, flush_mode]) -> Boolean\n * - data (Uint8Array|ArrayBuffer): input data\n * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE\n *   flush modes. See constants. Skipped or `false` means Z_NO_FLUSH,\n *   `true` means Z_FINISH.\n *\n * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with\n * new output chunks. Returns `true` on success. If end of stream detected,\n * [[Inflate#onEnd]] will be called.\n *\n * `flush_mode` is not needed for normal operation, because end of stream\n * detected automatically. You may try to use it for advanced things, but\n * this functionality was not tested.\n *\n * On fail call [[Inflate#onEnd]] with error code and return false.\n *\n * ##### Example\n *\n * ```javascript\n * push(chunk, false); // push one of data chunks\n * ...\n * push(chunk, true);  // push last chunk\n * ```\n **/\nInflate$1.prototype.push = function (data, flush_mode) {\n  const strm = this.strm;\n  const chunkSize = this.options.chunkSize;\n  const dictionary = this.options.dictionary;\n  let status, _flush_mode, last_avail_out;\n\n  if (this.ended) return false;\n\n  if (flush_mode === ~~flush_mode) _flush_mode = flush_mode;\n  else _flush_mode = flush_mode === true ? Z_FINISH : Z_NO_FLUSH;\n\n  // Convert data if needed\n  if (toString.call(data) === '[object ArrayBuffer]') {\n    strm.input = new Uint8Array(data);\n  } else {\n    strm.input = data;\n  }\n\n  strm.next_in = 0;\n  strm.avail_in = strm.input.length;\n\n  for (;;) {\n    if (strm.avail_out === 0) {\n      strm.output = new Uint8Array(chunkSize);\n      strm.next_out = 0;\n      strm.avail_out = chunkSize;\n    }\n\n    status = inflate_1$2.inflate(strm, _flush_mode);\n\n    if (status === Z_NEED_DICT && dictionary) {\n      status = inflate_1$2.inflateSetDictionary(strm, dictionary);\n\n      if (status === Z_OK) {\n        status = inflate_1$2.inflate(strm, _flush_mode);\n      } else if (status === Z_DATA_ERROR) {\n        // Replace code with more verbose\n        status = Z_NEED_DICT;\n      }\n    }\n\n    // Skip snyc markers if more data follows and not raw mode\n    while (strm.avail_in > 0 &&\n           status === Z_STREAM_END &&\n           strm.state.wrap > 0 &&\n           data[strm.next_in] !== 0)\n    {\n      inflate_1$2.inflateReset(strm);\n      status = inflate_1$2.inflate(strm, _flush_mode);\n    }\n\n    switch (status) {\n      case Z_STREAM_ERROR:\n      case Z_DATA_ERROR:\n      case Z_NEED_DICT:\n      case Z_MEM_ERROR:\n        this.onEnd(status);\n        this.ended = true;\n        return false;\n    }\n\n    // Remember real `avail_out` value, because we may patch out buffer content\n    // to align utf8 strings boundaries.\n    last_avail_out = strm.avail_out;\n\n    if (strm.next_out) {\n      if (strm.avail_out === 0 || status === Z_STREAM_END) {\n\n        if (this.options.to === 'string') {\n\n          let next_out_utf8 = strings.utf8border(strm.output, strm.next_out);\n\n          let tail = strm.next_out - next_out_utf8;\n          let utf8str = strings.buf2string(strm.output, next_out_utf8);\n\n          // move tail & realign counters\n          strm.next_out = tail;\n          strm.avail_out = chunkSize - tail;\n          if (tail) strm.output.set(strm.output.subarray(next_out_utf8, next_out_utf8 + tail), 0);\n\n          this.onData(utf8str);\n\n        } else {\n          this.onData(strm.output.length === strm.next_out ? strm.output : strm.output.subarray(0, strm.next_out));\n        }\n      }\n    }\n\n    // Must repeat iteration if out buffer is full\n    if (status === Z_OK && last_avail_out === 0) continue;\n\n    // Finalize if end of stream reached.\n    if (status === Z_STREAM_END) {\n      status = inflate_1$2.inflateEnd(this.strm);\n      this.onEnd(status);\n      this.ended = true;\n      return true;\n    }\n\n    if (strm.avail_in === 0) break;\n  }\n\n  return true;\n};\n\n\n/**\n * Inflate#onData(chunk) -> Void\n * - chunk (Uint8Array|String): output data. When string output requested,\n *   each chunk will be string.\n *\n * By default, stores data blocks in `chunks[]` property and glue\n * those in `onEnd`. Override this handler, if you need another behaviour.\n **/\nInflate$1.prototype.onData = function (chunk) {\n  this.chunks.push(chunk);\n};\n\n\n/**\n * Inflate#onEnd(status) -> Void\n * - status (Number): inflate status. 0 (Z_OK) on success,\n *   other if not.\n *\n * Called either after you tell inflate that the input stream is\n * complete (Z_FINISH). By default - join collected chunks,\n * free memory and fill `results` / `err` properties.\n **/\nInflate$1.prototype.onEnd = function (status) {\n  // On success - join\n  if (status === Z_OK) {\n    if (this.options.to === 'string') {\n      this.result = this.chunks.join('');\n    } else {\n      this.result = common.flattenChunks(this.chunks);\n    }\n  }\n  this.chunks = [];\n  this.err = status;\n  this.msg = this.strm.msg;\n};\n\n\n/**\n * inflate(data[, options]) -> Uint8Array|String\n * - data (Uint8Array|ArrayBuffer): input data to decompress.\n * - options (Object): zlib inflate options.\n *\n * Decompress `data` with inflate/ungzip and `options`. Autodetect\n * format via wrapper header by default. That's why we don't provide\n * separate `ungzip` method.\n *\n * Supported options are:\n *\n * - windowBits\n *\n * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)\n * for more information.\n *\n * Sugar (options):\n *\n * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify\n *   negative windowBits implicitly.\n * - `to` (String) - if equal to 'string', then result will be converted\n *   from utf8 to utf16 (javascript) string. When string output requested,\n *   chunk length can differ from `chunkSize`, depending on content.\n *\n *\n * ##### Example:\n *\n * ```javascript\n * const pako = require('pako');\n * const input = pako.deflate(new Uint8Array([1,2,3,4,5,6,7,8,9]));\n * let output;\n *\n * try {\n *   output = pako.inflate(input);\n * } catch (err) {\n *   console.log(err);\n * }\n * ```\n **/\nfunction inflate$1(input, options) {\n  const inflator = new Inflate$1(options);\n\n  inflator.push(input);\n\n  // That will never happens, if you don't cheat with options :)\n  if (inflator.err) throw inflator.msg || messages[inflator.err];\n\n  return inflator.result;\n}\n\n\n/**\n * inflateRaw(data[, options]) -> Uint8Array|String\n * - data (Uint8Array|ArrayBuffer): input data to decompress.\n * - options (Object): zlib inflate options.\n *\n * The same as [[inflate]], but creates raw data, without wrapper\n * (header and adler32 crc).\n **/\nfunction inflateRaw$1(input, options) {\n  options = options || {};\n  options.raw = true;\n  return inflate$1(input, options);\n}\n\n\n/**\n * ungzip(data[, options]) -> Uint8Array|String\n * - data (Uint8Array|ArrayBuffer): input data to decompress.\n * - options (Object): zlib inflate options.\n *\n * Just shortcut to [[inflate]], because it autodetects format\n * by header.content. Done for convenience.\n **/\n\n\nvar Inflate_1$1 = Inflate$1;\nvar inflate_2 = inflate$1;\nvar inflateRaw_1$1 = inflateRaw$1;\nvar ungzip$1 = inflate$1;\nvar constants = constants$2;\n\nvar inflate_1$1 = {\n\tInflate: Inflate_1$1,\n\tinflate: inflate_2,\n\tinflateRaw: inflateRaw_1$1,\n\tungzip: ungzip$1,\n\tconstants: constants\n};\n\nconst { Deflate, deflate, deflateRaw, gzip } = deflate_1$1;\n\nconst { Inflate, inflate, inflateRaw, ungzip } = inflate_1$1;\n\n\n\nvar Deflate_1 = Deflate;\nvar deflate_1 = deflate;\nvar deflateRaw_1 = deflateRaw;\nvar gzip_1 = gzip;\nvar Inflate_1 = Inflate;\nvar inflate_1 = inflate;\nvar inflateRaw_1 = inflateRaw;\nvar ungzip_1 = ungzip;\nvar constants_1 = constants$2;\n\nvar pako = {\n\tDeflate: Deflate_1,\n\tdeflate: deflate_1,\n\tdeflateRaw: deflateRaw_1,\n\tgzip: gzip_1,\n\tInflate: Inflate_1,\n\tinflate: inflate_1,\n\tinflateRaw: inflateRaw_1,\n\tungzip: ungzip_1,\n\tconstants: constants_1\n};\n\nexport { Deflate_1 as Deflate, Inflate_1 as Inflate, constants_1 as constants, pako as default, deflate_1 as deflate, deflateRaw_1 as deflateRaw, gzip_1 as gzip, inflate_1 as inflate, inflateRaw_1 as inflateRaw, ungzip_1 as ungzip };\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {BinaryReader} from './binaryReader';\r\nimport {inflate} from 'pako';\r\nimport {FBXModel, FBXNode} from './model/fbxModel';\r\nimport {logMessage} from '@fire-visual/utils';\r\n\r\nexport class FbxBinaryReader extends BinaryReader {\r\n    private parsePropertyMap: { [key: string]: () => boolean | string | number | boolean[] | string[] | number[] | ArrayBuffer };\r\n\r\n    private parseArrayMap: { [key: string]: (length) => number[] | boolean[] };\r\n\r\n    private subNodeParser: Array<{\r\n        canParse:(name: string, node: Partial<FBXNode>, subNode: Partial<FBXNode>) => boolean,\r\n        execute: (name: string, node: Partial<FBXNode>, subNode: Partial<FBXNode>) => void\r\n    }>;\r\n\r\n    protected onInstantiate(): void {\r\n        this.parsePropertyMap = {\r\n            'C': this.getBoolean.bind(this),\r\n            'F': this.getFloat32.bind(this),\r\n            'D': this.getFloat64.bind(this),\r\n            'I': this.getInt32.bind(this),\r\n            'L': this.getInt64.bind(this),\r\n            'R': () => this.getArrayBuffer(this.getUint32()),\r\n            'S': () => this.getString(this.getUint32()),\r\n            'Y': this.getInt16.bind(this),\r\n            'b': () => this.parseListType('b'),\r\n            'c': () => this.parseListType('c'),\r\n            'd': () => this.parseListType('d'),\r\n            'f': () => this.parseListType('f'),\r\n            'i': () => this.parseListType('i'),\r\n            'l': () => this.parseListType('l'),\r\n        };\r\n        this.parseArrayMap = {\r\n            'b': this.getBooleanArray.bind(this),\r\n            'c': this.getBooleanArray.bind(this),\r\n            'f': this.getFloat32Array.bind(this),\r\n            'd': this.getFloat64Array.bind(this),\r\n            'i': this.getInt32Array.bind(this),\r\n            'l': this.getInt64Array.bind(this),\r\n        };\r\n        this.subNodeParser = [\r\n            {\r\n                canParse:(name, node, subNode) => subNode.singleProperty === true,\r\n                execute: (name, node, subNode) => {\r\n                    const value = subNode.propertyList[0];\r\n                    if (Array.isArray(value)) {\r\n                        node[subNode.name] = subNode;\r\n                        subNode.a = value;\r\n                    } else {\r\n                        node[subNode.name] = value;\r\n                    }\r\n                }\r\n            },\r\n            {\r\n                canParse:(name, node, subNode) => name === 'Connections' && subNode.name === 'C',\r\n                execute: (name, node, subNode) => {\r\n                    const array = [];\r\n                    subNode.propertyList.forEach(function (property, i) {\r\n                        // first Connection is FBX type (OO, OP, etc.). We'll discard these\r\n                        if (i !== 0) array.push(property);\r\n                    });\r\n                    if (node.connections === undefined) {\r\n                        node.connections = [];\r\n                    }\r\n                    node.connections.push(array);\r\n                }\r\n            },\r\n            {\r\n                canParse:(name, node, subNode) => subNode.name === 'Properties70',\r\n                execute: (name, node, subNode) => {\r\n                    Object.keys(subNode).forEach((k) => {\r\n                        node[k] = subNode[k];\r\n                    });\r\n                }\r\n            },\r\n            {\r\n                canParse:(name, node, subNode) => name === 'Properties70' && subNode.name === 'P',\r\n                execute: (name, node, subNode) => {\r\n                    let innerPropName = subNode.propertyList[0] as string;\r\n                    let innerPropType1 = subNode.propertyList[1] as string;\r\n                    const innerPropType2 = subNode.propertyList[2] as string;\r\n                    const innerPropFlag = subNode.propertyList[3];\r\n                    let innerPropValue;\r\n\r\n                    if (innerPropName.indexOf('Lcl ') === 0) {\r\n                        innerPropName = innerPropName.replace('Lcl ', 'Lcl_');\r\n                    }\r\n                    if (innerPropType1.indexOf('Lcl ') === 0) {\r\n                        innerPropType1 = innerPropType1.replace('Lcl ', 'Lcl_');\r\n                    }\r\n\r\n                    if (\r\n                        innerPropType1 === 'Color' ||\r\n                        innerPropType1 === 'ColorRGB' ||\r\n                        innerPropType1 === 'Vector' ||\r\n                        innerPropType1 === 'Vector3D' ||\r\n                        innerPropType1.indexOf('Lcl_') === 0\r\n                    ) {\r\n                        innerPropValue = [\r\n                            subNode.propertyList[4],\r\n                            subNode.propertyList[5],\r\n                            subNode.propertyList[6]\r\n                        ];\r\n                    } else {\r\n                        innerPropValue = subNode.propertyList[4];\r\n                    }\r\n\r\n                    // this will be copied to parent, see above\r\n                    node[innerPropName] = {\r\n                        type: innerPropType1,\r\n                        type2: innerPropType2,\r\n                        flag: innerPropFlag,\r\n                        value: innerPropValue\r\n                    };\r\n                }\r\n            },\r\n            {\r\n                canParse:(name, node, subNode) => node[subNode.name] === undefined,\r\n                execute: (name, node, subNode) => {\r\n                    if (typeof subNode.id === 'number') {\r\n                        node[subNode.name] = [];\r\n                        node[subNode.name][subNode.id] = subNode;\r\n                    } else {\r\n                        node[subNode.name] = subNode;\r\n                    }\r\n                }\r\n            },\r\n        ]\r\n    }\r\n\r\n    public parse(): FBXModel {\r\n        this.skip(23); // skip magic 23 bytes\r\n\r\n        const version = this.getUint32(),\r\n            allNodes: Partial<FBXModel> = {};\r\n\r\n        while (!this.endOfContent()) {\r\n            const node = this.parseNode(version);\r\n            if (node !== null) {\r\n                allNodes[node.name] = node;\r\n            }\r\n        }\r\n\r\n        return allNodes as FBXModel;\r\n    }\r\n\r\n    public endOfContent(): boolean {\r\n        if (this.size % 16 === 0) {\r\n            return ((this.offset + 160 + 16) & ~0xf) >= this.size;\r\n        } else {\r\n            return this.offset + 160 + 16 >= this.size;\r\n        }\r\n    }\r\n\r\n    private getNodeProperties(version: number): [number, number, number] {\r\n        if (version >= 7500) {\r\n            return [this.getUint64(), this.getUint64(), this.getUint64()];\r\n        } else {\r\n            return [this.getUint32(), this.getUint32(), this.getUint32()];\r\n        }\r\n    }\r\n\r\n    // recursively parse nodes until the end of the file is reached\r\n    public parseNode(version: number): Partial<FBXNode> {\r\n        const node: Partial<FBXNode> = {};\r\n\r\n        const [endOffset, numProperties] = this.getNodeProperties(version);\r\n\r\n        const nameLen = this.getUint8(),\r\n            name = this.getString(nameLen);\r\n\r\n        // Regards this node as NULL-record if endOffset is zero\r\n        if (endOffset === 0) {\r\n            return null;\r\n        }\r\n\r\n        const propertyList = [];\r\n\r\n        for (let i = 0; i < numProperties; i++) {\r\n            propertyList.push(this.parseProperty(this.getString(1)));\r\n        }\r\n\r\n        // Regards the first three elements in propertyList as id, attrName, and attrType\r\n        const id = propertyList.length > 0 ? propertyList[0] : '',\r\n            attrName = propertyList.length > 1 ? propertyList[1] : '',\r\n            attrType = propertyList.length > 2 ? propertyList[2] : '';\r\n\r\n        // check if this node represents just a single property\r\n        // like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}\r\n        node.singleProperty = numProperties === 1 && this.offset === endOffset;\r\n\r\n        while (endOffset > this.offset) {\r\n            const subNode = this.parseNode(version);\r\n\r\n            if (subNode !== null) {\r\n                this.parseSubNode(name, node, subNode);\r\n            }\r\n        }\r\n\r\n        node.propertyList = propertyList; // raw property list used by parent\r\n\r\n        if (typeof id === 'number') {\r\n            node.id = id;\r\n        }\r\n        if (attrName !== '') {\r\n            node.attrName = attrName;\r\n        }\r\n        if (attrType !== '') {\r\n            node.attrType = attrType;\r\n        }\r\n        if (name !== '') {\r\n            node.name = name;\r\n        }\r\n\r\n        return node;\r\n    }\r\n\r\n    public parseSubNode(name: string, node: Partial<FBXNode>, subNode: Partial<FBXNode>): void {\r\n        const parser = this.subNodeParser.find(parser => parser.canParse(name, node, subNode));\r\n        if(parser) {\r\n            parser.execute(name, node, subNode);\r\n        } else {\r\n            if (subNode.name === 'PoseNode') {\r\n                if (!Array.isArray(node[subNode.name])) {\r\n                    node[subNode.name] = [node[subNode.name]];\r\n                }\r\n\r\n                node[subNode.name].push(subNode);\r\n            } else if (node[subNode.name][subNode.id] === undefined) {\r\n                node[subNode.name][subNode.id] = subNode;\r\n            }\r\n        }\r\n    }\r\n\r\n    public parseProperty(type: string): boolean | string | number | boolean[] | string[] | number[] | ArrayBuffer {\r\n        if (!this.parsePropertyMap[type]) {\r\n            throw new Error(logMessage(this, 'parseProperty', `Unknown property type '${type}'`));\r\n        }\r\n        return this.parsePropertyMap[type]();\r\n    }\r\n\r\n    private parseListType(type: string): number[] | boolean[] {\r\n        const arrayLength = this.getUint32(),\r\n            encoding = this.getUint32(), // 0: non-compressed, 1: compressed\r\n            compressedLength = this.getUint32();\r\n\r\n        if (encoding === 0) {\r\n            return this.parseArray(type, arrayLength);\r\n        }\r\n\r\n        return new FbxBinaryReader(\r\n            inflate(new Uint8Array(this.getArrayBuffer(compressedLength))).buffer\r\n        ).parseArray(type, arrayLength);\r\n    }\r\n\r\n\r\n    private parseArray(type: string, length: number): number[] | boolean[] {\r\n        if (!this.parseArrayMap[type]) {\r\n            throw new Error(logMessage(this, 'parseArray', `Unknown array type '${type}'`));\r\n        }\r\n        return this.parseArrayMap[type](length);\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {FBXModel} from '../model/fbxModel';\r\nimport {FbxContext, FbxContextRelationships, FbxContextType} from '../fbxContext';\r\nimport {PropertyResolver} from '@fire-visual/di';\r\nimport {Logger, LoggerType} from '@fire-visual/utils';\r\nimport {GeometryModelType, MaterialModelType} from '../../../../model';\r\n\r\nexport abstract class ComponentTransformer {\r\n    @PropertyResolver({_type: LoggerType})\r\n    protected readonly logger: Logger;\r\n\r\n    @PropertyResolver({_type: FbxContextType})\r\n    protected readonly context: FbxContext;\r\n\r\n    constructor(public readonly settings: ComponentTransformer.Settings) {\r\n    }\r\n\r\n    protected get geometryMap(): { [key: string]: GeometryModelType } {\r\n        return this.context.geometryMap;\r\n    }\r\n\r\n    protected get materialMap(): { [key: string]: MaterialModelType } {\r\n        return this.context.materialMap;\r\n    }\r\n\r\n    protected get connections(): { [key: string]: FbxContextRelationships } {\r\n        return this.context.connections;\r\n    }\r\n\r\n    protected get data(): FBXModel {\r\n        return this.context.data;\r\n    }\r\n\r\n    protected get idForAsset(): string {\r\n        return this.context.idForAsset;\r\n    }\r\n}\r\n\r\nexport namespace ComponentTransformer {\r\n    export interface Settings {\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {FBXDeformer} from '../model/fbxModel';\r\nimport {Matrix4_4} from '@fire-visual/math';\r\nimport {ComponentTransformer} from './componentTransformer';\r\nimport {SkeletonModel} from '../model/skeletonModel';\r\nimport {FbxContextRelationships} from '../fbxContext';\r\nimport {logMessage} from '@fire-visual/utils';\r\n\r\n\r\nexport class DeformerTransformer extends ComponentTransformer {\r\n    // Parse nodes in FBXTree.Objects.Deformer\r\n    // Deformer node can contain skinning or Vertex AssetCache animation data, however only skinning is supported here\r\n    // Generates map of Skeleton-like objects for use later when generating and binding skeletons.\r\n    public execute(): { [key: number]: SkeletonModel } {\r\n        const skeletons: { [key: string]: SkeletonModel } = {};\r\n\r\n        if ('Deformer' in this.data.Objects) {\r\n            const DeformerNodes = this.data.Objects.Deformer;\r\n\r\n            for (const nodeID in DeformerNodes) {\r\n                const deformerNode = DeformerNodes[nodeID];\r\n\r\n                if (deformerNode.attrType === 'Skin') {\r\n                    const relationships = this.connections[parseInt(nodeID)];\r\n                    const skeleton = this.parseSkeleton(relationships, DeformerNodes);\r\n\r\n                    if (Array.isArray(relationships.parent)) {\r\n                        this.logger.warn(logMessage(this, 'execute', 'skeleton attached to more than one geometry is not supported.'))\r\n                        skeleton.geometryID = relationships.parent[0].key;\r\n                    }\r\n                    skeleton.ID = deformerNode.id;\r\n                    skeleton.geometryID = relationships.parent.key;\r\n\r\n                    skeletons[nodeID] = skeleton;\r\n                }\r\n            }\r\n        }\r\n\r\n        return skeletons;\r\n    }\r\n\r\n    // Parse single nodes in FBXTree.Objects.Deformer\r\n    // The top level deformer nodes have type 'Skin' and subDeformer nodes have type 'Cluster'\r\n    // Each skin node represents a skeleton and each cluster node represents a bone\r\n    private parseSkeleton(\r\n        relationShips: FbxContextRelationships,\r\n        deformerNodes: { [key: string]: FBXDeformer }\r\n    ): SkeletonModel {\r\n        const rawBones = [];\r\n\r\n        relationShips.children.forEach((child) => {\r\n            const subDeformerNode = deformerNodes[child.key];\r\n            if (subDeformerNode.attrType !== 'Cluster') {\r\n                return;\r\n            }\r\n\r\n            const rawBone = {\r\n                ID: child.key,\r\n                indices: [],\r\n                weights: [],\r\n                transform: Matrix4_4.create(subDeformerNode.Transform.a),\r\n                transformLink: Matrix4_4.create(subDeformerNode.TransformLink.a),\r\n                linkMode: subDeformerNode.Mode\r\n            };\r\n\r\n            if ('Indexes' in subDeformerNode) {\r\n                rawBone.indices = subDeformerNode.Indexes.a;\r\n                rawBone.weights = subDeformerNode.Weights.a;\r\n            }\r\n\r\n            rawBones.push(rawBone);\r\n        });\r\n\r\n        return {\r\n            rawBones: rawBones,\r\n            bones: []\r\n        };\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {ComponentTransformer} from './componentTransformer';\r\nimport {degreeToRad, Euler, EulerOrder, Transformation, Vector, Vector2, Vector3} from '@fire-visual/math';\r\nimport {SkeletonModel} from '../model/skeletonModel';\r\nimport {FBXColors, FBXGeometry, FBXMaterialIndices, FBXNormals, FBXUVs} from '../model/fbxModel';\r\nimport {BufferGeometryModel, FaceGeometryModel, FaceModel, GeometryModelType} from '../../../../model';\r\nimport {FbxContextRelationships} from '../fbxContext';\r\nimport {logMessage, notImplemented} from '@fire-visual/utils';\r\n\r\ninterface BufferInfo {\r\n    buffer: number[];\r\n    dataSize: number;\r\n    indices: number[];\r\n    mappingType: BufferMappingType;\r\n    referenceType: BufferReferenceType;\r\n}\r\n\r\ndeclare type BufferMappingType =\r\n    | 'ByPolygonVertex'\r\n    | 'ByPolygon'\r\n    | 'ByVertice'\r\n    | 'AllSame';\r\ndeclare type BufferReferenceType = 'IndexToDirect' | 'Direct';\r\n\r\ninterface FaceInfo {\r\n    index: number;\r\n    vertices: { index: number; value: number }[];\r\n}\r\n\r\ninterface BufferInfoContext {\r\n    vertices: number[],\r\n    indices: number[],\r\n    material: BufferInfo,\r\n    normal: BufferInfo,\r\n    uv: BufferInfo[],\r\n    color: BufferInfo\r\n}\r\n\r\nexport class GeometryTransformer extends ComponentTransformer {\r\n    private geometryTypeMap: {\r\n        [key: string]: (\r\n            geometryNode: FBXGeometry,\r\n            skeleton: SkeletonModel\r\n        ) => GeometryModelType\r\n    } = {\r\n        face: this.createFaceGeometry.bind(this),\r\n        buffer: this.createBufferGeometry.bind(this)\r\n    };\r\n\r\n    // Functions use the infoObject and given indices to return value array of geometry.\r\n    // Parameters:\r\n    // \t- polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).\r\n    // \t- polygonIndex - Index of polygon in geometry.\r\n    // \t- vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).\r\n    // \t- infoObject: can be materialInfo, normalInfo, UVInfo or colorInfo\r\n    // Index type:\r\n    //\t- Direct: index is same as polygonVertexIndex\r\n    //\t- IndexToDirect: infoObject has it's own set of indices\r\n    private getBufferData: {\r\n        [key: string]: {\r\n            [key: string]: (\r\n                faceInfo: FaceInfo,\r\n                bufferInfo: BufferInfo\r\n            ) => number[] | number[][];\r\n        };\r\n    } = {\r\n        ByPolygonVertex: {\r\n            Direct: (faceInfo, bufferInfo) => {\r\n                return faceInfo.vertices.map((v) => {\r\n                    return bufferInfo.buffer.slice(\r\n                        v.index * bufferInfo.dataSize,\r\n                        (v.index + 1) * bufferInfo.dataSize\r\n                    );\r\n                });\r\n            },\r\n\r\n            IndexToDirect: (faceInfo, bufferInfo) => {\r\n                return faceInfo.vertices.map((v) => {\r\n                    const index = bufferInfo.indices[v.index];\r\n                    return bufferInfo.buffer.slice(\r\n                        index * bufferInfo.dataSize,\r\n                        (index + 1) * bufferInfo.dataSize\r\n                    );\r\n                });\r\n            }\r\n        },\r\n        ByPolygon: {\r\n            Direct: (faceInfo, bufferInfo) => {\r\n                return bufferInfo.buffer.slice(\r\n                    faceInfo.index * bufferInfo.dataSize,\r\n                    (faceInfo.index + 1) * bufferInfo.dataSize\r\n                );\r\n            },\r\n\r\n            IndexToDirect: (faceInfo, bufferInfo) => {\r\n                const index = bufferInfo.indices[faceInfo.index];\r\n                return bufferInfo.buffer.slice(\r\n                    index * bufferInfo.dataSize,\r\n                    (index + 1) * bufferInfo.dataSize\r\n                );\r\n            }\r\n        },\r\n        ByVertice: {\r\n            Direct: (faceInfo, bufferInfo) => {\r\n                return faceInfo.vertices.map((v) => {\r\n                    const index = v.value;\r\n                    return bufferInfo.buffer.slice(\r\n                        index * bufferInfo.dataSize,\r\n                        (index + 1) * bufferInfo.dataSize\r\n                    );\r\n                });\r\n            }\r\n        },\r\n        AllSame: {\r\n            IndexToDirect: (faceInfo, bufferInfo) => {\r\n                return bufferInfo.buffer.slice(\r\n                    bufferInfo.indices[0] * bufferInfo.dataSize,\r\n                    (bufferInfo.indices[0] + 1) * bufferInfo.dataSize\r\n                );\r\n            }\r\n        }\r\n    };\r\n\r\n    // Parse nodes in FBXTree.Objects.Geometry\r\n    public execute(skeletons: { [key: string]: SkeletonModel }): { [key: string]: GeometryModelType } {\r\n        const geometryMap: { [key: string]: GeometryModelType } = {};\r\n\r\n        if ('Geometry' in this.data.Objects) {\r\n            const geometryNodes = this.data.Objects.Geometry;\r\n\r\n            for (const nodeID in geometryNodes) {\r\n                const relationships = this.connections[parseInt(nodeID)];\r\n\r\n                geometryMap[parseInt(nodeID)] = this.parseGeometry(\r\n                    relationships,\r\n                    geometryNodes[nodeID],\r\n                    skeletons\r\n                );\r\n            }\r\n        }\r\n\r\n        return geometryMap;\r\n    }\r\n\r\n    // Parse single node in FBXTree.Objects.Geometry\r\n    private parseGeometry(\r\n        relationships: FbxContextRelationships,\r\n        geometryNode: FBXGeometry,\r\n        skeletons: { [key: string]: SkeletonModel }\r\n    ): GeometryModelType {\r\n        if (geometryNode.attrType == 'Mesh') {\r\n            return this.parseMeshGeometry(\r\n                relationships,\r\n                geometryNode,\r\n                skeletons\r\n            );\r\n        }\r\n        //Line | NurbsCurve\r\n        this.logger.warn(logMessage(this, 'parseGeometry', `type '${geometryNode.attrType}' not implemented`))\r\n    }\r\n\r\n    // Parse single node mesh geometry in FBXTree.Objects.Geometry\r\n    private parseMeshGeometry(\r\n        relationships: FbxContextRelationships,\r\n        geometryNode: FBXGeometry,\r\n        skeletons: { [key: string]: SkeletonModel }\r\n    ): GeometryModelType {\r\n        const modelNode = this.data.Objects.Model[relationships.parent.key];\r\n\r\n        // don't create geometry if it is not associated with any models\r\n        if (!modelNode) {\r\n            return;\r\n        }\r\n\r\n        const skeleton = relationships.children.reduce<SkeletonModel>((skeleton, child) => {\r\n            if (skeletons[child.key] !== undefined) {\r\n                skeleton = skeletons[child.key];\r\n            }\r\n            return skeleton;\r\n        }, null);\r\n\r\n        const preTransform = new Transformation();\r\n\r\n        // TODO: if there is more than one model associated with the geometry, AND the models have\r\n        // different geometric transforms, then this will cause problems\r\n        // if ( modelNodes.length > 1 ) { }\r\n\r\n        if ('GeometricRotation' in modelNode) {\r\n            const [x, y, z] = modelNode.GeometricRotation.value.map(degreeToRad);\r\n            preTransform.rotation = Euler.toQuaternion(\r\n                new Euler(x, y, z, EulerOrder.ZYX)\r\n            );\r\n        }\r\n\r\n        if ('GeometricTranslation' in modelNode) {\r\n            preTransform.translation = Vector3.create(\r\n                modelNode.GeometricTranslation.value\r\n            );\r\n        }\r\n\r\n        if ('GeometricScaling' in modelNode) {\r\n            preTransform.scale = Vector3.create(modelNode.GeometricTranslation.value);\r\n        }\r\n\r\n        let geometryMapper = this.geometryTypeMap[this.context.geometryType];\r\n\r\n        if (!geometryMapper) {\r\n            this.logger.warn(logMessage(this, 'parseMeshGeometry', `can't convert input to the desired Type no mapping registered for '${this.context.geometryType}'`));\r\n            geometryMapper = this.geometryTypeMap['face'];\r\n        }\r\n\r\n        return geometryMapper(geometryNode, skeleton);\r\n    }\r\n\r\n    private createFaceGeometry(geometryNode: FBXGeometry, skeleton: SkeletonModel): FaceGeometryModel {\r\n        const bufferCtx = {\r\n            vertices: geometryNode.Vertices.a,\r\n            indices: geometryNode.PolygonVertexIndex.a,\r\n            material: this.getMaterials(geometryNode.LayerElementMaterial),\r\n            normal: this.getNormals(geometryNode.LayerElementNormal),\r\n            uv: this.getUVs(geometryNode.LayerElementUV),\r\n            color: this.getColors(geometryNode.LayerElementColor)\r\n        };\r\n\r\n        const uvsBuffer: number[][] = [];\r\n\r\n        if (skeleton) {\r\n            this.logger.info(notImplemented(this, 'createFaceGeometry', 'parse skeleton'));\r\n        }\r\n\r\n        const faces = this.getFaces(bufferCtx.indices).map(faceInfo => {\r\n            if (bufferCtx.uv) {\r\n                this.createUVs(uvsBuffer, faceInfo, bufferCtx.uv);\r\n            }\r\n            return this.createFace(faceInfo, bufferCtx);\r\n        });\r\n\r\n        const scaleFactor = this.context.scaleFactor;\r\n\r\n        const geometryModel: FaceGeometryModel = {\r\n            _resourceClass: 'geometry_face',\r\n            tags: [geometryNode.name],\r\n            faces: faces,\r\n            vertices: this.createArrayFromBuffer(\r\n                bufferCtx.vertices,\r\n                Vector3.DIMENSION,\r\n                Vector3.create\r\n            ).map((v) => v.multiply(scaleFactor).values)\r\n        };\r\n\r\n        uvsBuffer.forEach((uvBuffer, i) => {\r\n            if (!geometryModel.uvs) {\r\n                geometryModel.uvs = [];\r\n            }\r\n            geometryModel.uvs[i] = this.createArrayFromBuffer(\r\n                uvsBuffer[i],\r\n                Vector2.DIMENSION,\r\n                Vector2.create\r\n            ).map(v => v.values);\r\n        });\r\n        geometryModel.id = this.idForAsset;\r\n        return geometryModel;\r\n    }\r\n\r\n    private createFace(faceInfo: FaceInfo, bufferCtx: BufferInfoContext): FaceModel {\r\n        const normalData = bufferCtx.normal && this.getData(faceInfo, bufferCtx.normal) as Array<[number, number, number]>,\r\n            materialData = bufferCtx.material && this.getData(faceInfo, bufferCtx.material) as number[],\r\n            colorData = bufferCtx.color && this.getData(faceInfo, bufferCtx.color) as Array<[number, number, number]>;\r\n\r\n        let result: FaceModel;\r\n        for (let i = 2, j = 0; i < faceInfo.vertices.length; i++, j++) {\r\n            result = {\r\n                indices: [\r\n                    faceInfo.vertices[0].value,\r\n                    faceInfo.vertices[i - 1].value,\r\n                    faceInfo.vertices[i].value\r\n                ]\r\n            }\r\n            normalData && (result.vertexNormals = [\r\n                normalData[0],\r\n                normalData[i - 1],\r\n                normalData[i],\r\n            ]);\r\n            colorData && (result.vertexColors = [\r\n                colorData[0],\r\n                colorData[i - 1],\r\n                colorData[i],\r\n            ]);\r\n            materialData && (result.materialIndex = materialData[j]);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    private createUVs(uvsBuffer: number[][], faceInfo: FaceInfo, uvInfo: BufferInfo[]): void {\r\n        uvInfo.forEach((bufferInfo, uvIndex) => {\r\n            if (!uvsBuffer[uvIndex]) {\r\n                uvsBuffer[uvIndex] = [];\r\n            }\r\n            const uvData = this.getData(faceInfo, bufferInfo) as number[][];\r\n            faceInfo.vertices.forEach((vertex, i) => {\r\n                uvData[i].forEach((uv, j) => {\r\n                    const index = vertex.value * bufferInfo.dataSize + j;\r\n                    uvsBuffer[uvIndex][index] = uv;\r\n                });\r\n            });\r\n        });\r\n    }\r\n\r\n    private createBufferGeometry(geometryNode: FBXGeometry, skeleton: SkeletonModel): BufferGeometryModel {\r\n        const bufferCtx = {\r\n            vertices: geometryNode.Vertices.a,\r\n            indices: geometryNode.PolygonVertexIndex.a,\r\n            material: this.getMaterials(geometryNode.LayerElementMaterial),\r\n            normal: this.getNormals(geometryNode.LayerElementNormal),\r\n            uv: this.getUVs(geometryNode.LayerElementUV) || [],\r\n            color: this.getColors(geometryNode.LayerElementColor)\r\n        };\r\n\r\n        const geometryModel: BufferGeometryModel = {\r\n            _resourceClass: 'geometry_buffer',\r\n            tags: [geometryNode.name],\r\n            positions: []\r\n        };\r\n        bufferCtx.material && (geometryModel.materialIndices = []);\r\n        bufferCtx.normal && (geometryModel.normals = []);\r\n        bufferCtx.color && (geometryModel.colors = []);\r\n        bufferCtx.uv[0] && (geometryModel.uvs = []);\r\n        bufferCtx.uv[1] && (geometryModel.uvs2 = []);\r\n\r\n        if (skeleton) {\r\n            this.logger.warn(notImplemented(this, 'createBufferGeometry - parse skeleton'));\r\n        }\r\n\r\n        this.getFaces(bufferCtx.indices).forEach(faceInfo => this.addFaceToGeometry(faceInfo, bufferCtx, geometryModel));\r\n        const scaleFactor = this.context.scaleFactor;\r\n        geometryModel.positions = geometryModel.positions.map(v => v * scaleFactor);\r\n        geometryModel.id = this.idForAsset;\r\n        return geometryModel;\r\n    }\r\n\r\n    private addFaceToGeometry(faceInfo: FaceInfo, bufferCtx: BufferInfoContext, target: BufferGeometryModel): void {\r\n        const normalData = bufferCtx.normal && this.getData(faceInfo, bufferCtx.normal) as Array<[number, number, number]>,\r\n            materialData = bufferCtx.material && this.getData(faceInfo, bufferCtx.material) as number[],\r\n            colorData = bufferCtx.color && this.getData(faceInfo, bufferCtx.color) as Array<[number, number, number]>,\r\n            uvData = bufferCtx.uv[0] && this.getData(faceInfo, bufferCtx.uv[0]) as Array<[number, number]>,\r\n            uvData2 = bufferCtx.uv[1] && this.getData(faceInfo, bufferCtx.uv[1]) as Array<[number, number]>;\r\n        for (let i = 2, j = 0; i < faceInfo.vertices.length; i++, j++) {\r\n            const indices = [faceInfo.vertices[0].value * 3, faceInfo.vertices[i - 1].value * 3, faceInfo.vertices[i].value * 3];\r\n            target.positions.push(\r\n                bufferCtx.vertices[indices[0]],\r\n                bufferCtx.vertices[indices[0] + 1],\r\n                bufferCtx.vertices[indices[0] + 2],\r\n                bufferCtx.vertices[indices[1]],\r\n                bufferCtx.vertices[indices[1] + 1],\r\n                bufferCtx.vertices[indices[1] + 2],\r\n                bufferCtx.vertices[indices[2]],\r\n                bufferCtx.vertices[indices[2] + 1],\r\n                bufferCtx.vertices[indices[2] + 2],\r\n            );\r\n            target.normals && target.normals.push(\r\n                ...normalData[0],\r\n                ...normalData[i - 1],\r\n                ...normalData[i]\r\n            );\r\n            target.colors && target.colors.push(\r\n                ...colorData[0],\r\n                ...colorData[i - 1],\r\n                ...colorData[i]\r\n            );\r\n            target.uvs && target.uvs.push(\r\n                ...uvData[0],\r\n                ...uvData[i - 1],\r\n                ...uvData[i]\r\n            );\r\n            target.uvs2 && target.uvs2.push(\r\n                ...uvData2[0],\r\n                ...uvData2[i - 1],\r\n                ...uvData2[i]\r\n            )\r\n            target.materialIndices && target.materialIndices.push(materialData[j]);\r\n        }\r\n    }\r\n\r\n    private getMaterials(layerElement: FBXMaterialIndices[]): BufferInfo {\r\n        if (!layerElement?.length) {\r\n            return null;\r\n        }\r\n        const materialNode = layerElement[0];\r\n        if (materialNode.MappingInformationType === 'NoMappingInformation') {\r\n            return {\r\n                dataSize: 1,\r\n                buffer: [0],\r\n                indices: [0],\r\n                mappingType: 'AllSame',\r\n                referenceType: materialNode.ReferenceInformationType as BufferReferenceType\r\n            };\r\n        }\r\n\r\n        return {\r\n            dataSize: 1,\r\n            buffer: materialNode.Materials.a,\r\n            indices: materialNode.Materials.a.map((v, i) => i),\r\n            mappingType: materialNode.MappingInformationType as BufferMappingType,\r\n            referenceType: materialNode.ReferenceInformationType as BufferReferenceType\r\n        };\r\n    }\r\n\r\n    private getNormals(layerElement: FBXNormals[]): BufferInfo {\r\n        if (!layerElement?.length) {\r\n            return null;\r\n        }\r\n        const normalNode = layerElement[0];\r\n        let indexBuffer = [];\r\n        if (normalNode.ReferenceInformationType === 'IndexToDirect') {\r\n            indexBuffer = (normalNode.NormalIndex || normalNode.NormalsIndex).a;\r\n        }\r\n\r\n        return {\r\n            dataSize: 3,\r\n            buffer: normalNode.Normals.a,\r\n            indices: indexBuffer,\r\n            mappingType: normalNode.MappingInformationType as BufferMappingType,\r\n            referenceType: normalNode.ReferenceInformationType as BufferReferenceType\r\n        };\r\n    }\r\n\r\n    private getColors(layerElement: FBXColors[]): BufferInfo {\r\n        if (!layerElement?.length) {\r\n            return null;\r\n        }\r\n        const colorNode = layerElement[0];\r\n        let indexBuffer = [];\r\n        if (colorNode.ReferenceInformationType === 'IndexToDirect') {\r\n            indexBuffer = colorNode.ColorIndex.a;\r\n        }\r\n\r\n        return {\r\n            dataSize: 3,\r\n            buffer: colorNode.Colors.a,\r\n            indices: indexBuffer,\r\n            mappingType: colorNode.MappingInformationType as BufferMappingType,\r\n            referenceType: colorNode.ReferenceInformationType as BufferReferenceType\r\n        };\r\n    }\r\n\r\n    private getUVs(layerElement: FBXUVs[]): BufferInfo[] {\r\n        if (!layerElement?.length) {\r\n            return null;\r\n        }\r\n        return layerElement.map(uvNode => {\r\n            let indexBuffer = [];\r\n            if (uvNode.ReferenceInformationType === 'IndexToDirect') {\r\n                indexBuffer = uvNode.UVIndex.a;\r\n            }\r\n            return {\r\n                dataSize: 2,\r\n                buffer: uvNode.UV.a,\r\n                indices: indexBuffer,\r\n                mappingType: uvNode.MappingInformationType as BufferMappingType,\r\n                referenceType: uvNode.ReferenceInformationType as BufferReferenceType\r\n            };\r\n        });\r\n    }\r\n\r\n    private getData(faceInfo: FaceInfo, bufferInfo: BufferInfo) {\r\n        return this.getBufferData[bufferInfo.mappingType][\r\n            bufferInfo.referenceType\r\n            ](faceInfo, bufferInfo);\r\n    }\r\n\r\n    private createArrayFromBuffer<TVector extends Vector>(\r\n        buffer: number[],\r\n        size: number,\r\n        createEntity: (args: number[]) => TVector\r\n    ) {\r\n        const result: TVector[] = [];\r\n        for (let i = 0; i < buffer.length; i += size) {\r\n            result.push(createEntity(buffer.slice(i, i + size)));\r\n        }\r\n        return result;\r\n    }\r\n\r\n\r\n    private getFaces(indexBuffer: number[]): Array<FaceInfo> {\r\n        const result: FaceInfo[] = [];\r\n        let indices: number[] = [];\r\n\r\n        for (let i = 0; i < indexBuffer.length; i++) {\r\n            indices.push(i);\r\n            if (indexBuffer[i] < 0) {\r\n                result.push({\r\n                    index: result.length,\r\n                    vertices: indices.map(j => {\r\n                        const value = indexBuffer[j];\r\n                        return {\r\n                            index: j,\r\n                            value: value < 0 ? value ^ -1 : value\r\n                        };\r\n                    })\r\n                });\r\n                indices = [];\r\n            }\r\n        }\r\n        return result;\r\n    }\r\n}\r\n\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {notImplemented} from '@fire-visual/utils';\r\nimport {ComponentTransformer} from './componentTransformer';\r\n\r\nexport class ImageTransformer extends ComponentTransformer {\r\n    // Parse FBXTree.Objects.Video for embedded image data\r\n    // These images are connected to textures in FBXTree.Objects.Textures\r\n    // via FBXTree.Connections.\r\n    public execute(): { [key: string]: string } {\r\n        const images: { [key: string]: string } = {},\r\n            blobs = {};\r\n\r\n        if ('Video' in this.data.Objects) {\r\n            this.parseVideos(images);\r\n        }\r\n\r\n        for (const id in images) {\r\n            const filename = images[id];\r\n\r\n            if (blobs[filename] !== undefined) {\r\n                images[id] = blobs[filename];\r\n            } else {\r\n                images[id] = images[id].split('\\\\').pop();\r\n            }\r\n        }\r\n\r\n        return images;\r\n    }\r\n\r\n    private parseVideos(images: { [key: string]: string }): void {\r\n        const videoNodes = this.data.Objects.Video;\r\n\r\n        for (const nodeID in videoNodes) {\r\n            const videoNode = videoNodes[nodeID],\r\n                id = parseInt(nodeID);\r\n\r\n            images[id] = videoNode.Filename;\r\n\r\n            // raw image data is in videoNode.Content\r\n            if ('Content' in videoNode) {\r\n                const arrayBufferContent = videoNode.Content instanceof ArrayBuffer && videoNode.Content.byteLength > 0,\r\n                    base64Content = typeof videoNode.Content === 'string' && videoNode.Content !== '';\r\n\r\n                if (arrayBufferContent || base64Content) {\r\n                    this.logger.warn(notImplemented(this, 'execute - embedded images not implemented'));\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {ComponentTransformer} from './componentTransformer';\r\nimport {FBXMaterial} from '../model/fbxModel';\r\nimport {PhongMaterialModel, TextureModel} from '../../../../model';\r\nimport {MappingType} from '../../../../../rendering/asset/textureAsset/mappingType';\r\nimport {logMessage} from '@fire-visual/utils';\r\nimport {FBXContextRelationship} from '../fbxContext';\r\n\r\nexport class MaterialTransformer extends ComponentTransformer {\r\n    private parameterParser: Array<(materialNode: FBXMaterial, material: PhongMaterialModel) => void> = [];\r\n    private connectionParser: Array<{\r\n        canParse: (relationship: FBXContextRelationship) => boolean,\r\n        parse: (material: PhongMaterialModel, relationship: FBXContextRelationship, textureMap?: { [key: string]: Partial<TextureModel> }) => void\r\n    }> = [];\r\n\r\n    constructor(settings: ComponentTransformer.Settings) {\r\n        super(settings);\r\n        this.registerParameterParser();\r\n        this.registerConnectionParser();\r\n    }\r\n\r\n    public execute(textureMap: { [key: string]: Partial<TextureModel> }): { [key: string]: PhongMaterialModel } {\r\n        const result: { [key: string]: PhongMaterialModel } = {};\r\n\r\n        if ('Material' in this.data.Objects) {\r\n            const materialNodes = this.data.Objects.Material;\r\n\r\n            for (const nodeID in materialNodes) {\r\n                const material = this.parseMaterial(\r\n                    materialNodes[nodeID],\r\n                    textureMap\r\n                );\r\n\r\n                if (material !== null) {\r\n                    result[nodeID] = material;\r\n                }\r\n            }\r\n        }\r\n\r\n        return result;\r\n    }\r\n\r\n    private parseMaterial(materialNode: FBXMaterial, textureMap: { [key: string]: Partial<TextureModel> }): PhongMaterialModel {\r\n        const ID = materialNode.id;\r\n        // Ignore unused materials which don't have any connections.\r\n        if (!this.connections[ID]) {\r\n            this.logger.warn(logMessage(this, 'parseMaterial', `Skipping Material with id ${ID}, because it has no connections.`));\r\n            return null;\r\n        }\r\n\r\n        const result = this.parseMaterialParameters(\r\n            materialNode,\r\n            textureMap,\r\n            ID\r\n        );\r\n\r\n        result.id = this.idForAsset;\r\n        return result;\r\n    }\r\n\r\n    private registerParameterParser(): void {\r\n        this.parameterParser.push(\r\n            (node, material) => {\r\n                if (node.BumpFactor) {\r\n                    material.bumpScale = node.BumpFactor.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Diffuse) {\r\n                    material.diffuse = node.Diffuse.value;\r\n                } else if (node.DiffuseColor?.type === 'Color') {\r\n                    // The blender exporter exports diffuse here instead of in properties.Diffuse\r\n                    material.diffuse = node.DiffuseColor.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.DisplacementFactor) {\r\n                    material.displacementScale = node.DisplacementFactor.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Specular) {\r\n                    material.specular = node.Specular.value;\r\n                } else if (node.SpecularColor?.type === 'Color') {\r\n                    // The blender exporter exports specular color here instead of in properties.Specular\r\n                    material.specular = node.SpecularColor.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Shininess) {\r\n                    material.shininess = node.Shininess.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Reflectivity) {\r\n                    material.reflectivity = node.Reflectivity.value;\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Emissive) {\r\n                    material.emissive = node.Emissive.value;\r\n                } else if (node.EmissiveColor?.type === 'Color') {\r\n                    // The blender exporter exports emissive color here instead of in properties.Emissive\r\n                    material.emissive = node.EmissiveColor.value;\r\n                }\r\n                if (node.EmissiveFactor) {\r\n                    material.emissiveIntensity = parseFloat(node.EmissiveFactor.value);\r\n                }\r\n            },\r\n            (node, material) => {\r\n                if (node.Opacity) {\r\n                    material.opacity = parseFloat(node.Opacity.value);\r\n                }\r\n                if (material.opacity < 1.0) {\r\n                    material.transparent = true;\r\n                }\r\n            },\r\n        );\r\n    }\r\n\r\n    private registerConnectionParser(): void {\r\n        this.connectionParser.push(\r\n            {\r\n                canParse: (r) => r.relationship == 'Bump',\r\n                parse: (material, relationship, textures) => material.bump_map = textures[relationship.key]\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'DiffuseColor',\r\n                parse: (material, relationship, textures) => material.diffuse_map = this.getTexture(textures, relationship.key)\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'DisplacementColor',\r\n                parse: (material, relationship, textures) => material.displacement_map = this.getTexture(textures, relationship.key)\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'EmissiveColor',\r\n                parse: (material, relationship, textures) => material.emissive_map = this.getTexture(textures, relationship.key)\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'NormalMap',\r\n                parse: (material, relationship, textures) => material.normal_map = this.getTexture(textures, relationship.key)\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'ReflectionColor',\r\n                parse: (material, relationship, textures) => {\r\n                    material.environment_map = this.getTexture(textures, relationship.key);\r\n                    material.environment_map.mapping = MappingType.reflection_cubic;\r\n                }\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'SpecularColor',\r\n                parse: (material, relationship, textures) => material.specular_map = this.getTexture(textures, relationship.key)\r\n            },\r\n            {\r\n                canParse: (r) => r.relationship == 'TransparentColor',\r\n                parse: (material, relationship, textures) => {\r\n                    material.alpha_map = this.getTexture(textures, relationship.key);\r\n                    material.transparent = true;\r\n                }\r\n            }\r\n        );\r\n    }\r\n\r\n    // parse the texture map and return any textures associated with the material\r\n    private parseMaterialParameters(materialNode: FBXMaterial, textureMap: { [key: string]: Partial<TextureModel> }, ID: number): PhongMaterialModel {\r\n        const material: PhongMaterialModel = {_resourceClass: 'material_phong'};\r\n\r\n        this.parameterParser.forEach(parser => parser(materialNode, material));\r\n\r\n        this.connections[ID].children.forEach((relationship) => {\r\n            const parser = this.connectionParser.find(p => p.canParse(relationship));\r\n            if (parser) {\r\n                parser.parse(material, relationship, textureMap);\r\n            } else {\r\n                this.logger.warn(logMessage(this, 'parseMaterialParameters', `${relationship.relationship} map is not supported, skipping texture.`));\r\n            }\r\n        });\r\n\r\n        return material;\r\n    }\r\n\r\n    // get a texture from the textureMap for use by a material.\r\n    private getTexture(\r\n        textureMap: { [key: string]: Partial<TextureModel> },\r\n        id: number\r\n    ): Partial<TextureModel> {\r\n        // if the texture is a layered texture, just use the first layer and issue a warning\r\n        if (\r\n            'LayeredTexture' in this.data.Objects &&\r\n            id in this.data.Objects.LayeredTexture\r\n        ) {\r\n            this.logger.warn(logMessage(this, 'getTexture', 'Layered Textures are not support skipping all but the first layer'));\r\n            id = this.connections[id].children[0].key;\r\n        }\r\n\r\n        return textureMap[id];\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {degreeToRad, Euler, EulerOrder, Quaternion, Vector3} from '@fire-visual/math';\r\nimport {LightType} from '../../../../../rendering/component/lightComponent/lightType';\r\nimport {CameraType} from '../../../../../rendering/component/cameraComponent/cameraType';\r\nimport {ComponentTransformer} from './componentTransformer';\r\nimport {FBXObject} from '../model/fbxModel';\r\nimport {\r\n    CameraModel,\r\n    GeometryModelType,\r\n    HandleModel,\r\n    LightModel,\r\n    MaterialModelType,\r\n    RendererModel,\r\n    SceneGraphModel,\r\n    TransformModel\r\n} from '../../../../model';\r\nimport {FbxContextRelationships} from '../fbxContext';\r\nimport {logMessage} from '@fire-visual/utils';\r\n\r\ninterface LightContext {\r\n    type: number,\r\n    color: [number, number, number],\r\n    intensity: number,\r\n    distance: number,\r\n    decay: number\r\n}\r\n\r\nexport class SceneTransformer extends ComponentTransformer {\r\n    private nodeParserTypeMap: {\r\n        [key: string]: (\r\n            node: FBXObject,\r\n            relationships: FbxContextRelationships\r\n        ) => HandleModel\r\n    } = {\r\n        Camera: this.parseCamera.bind(this),\r\n        Light: this.parseLight.bind(this),\r\n        Mesh: this.parseMesh.bind(this),\r\n        NurbsCurve: this.parseNurbsCurve.bind(this),\r\n        Null: this.createHandleModel.bind(this)\r\n    };\r\n\r\n    private cameraSettingsParserMap: {\r\n        [key: string]: (\r\n            node: FBXObject\r\n        ) => CameraModel\r\n    } = {\r\n        0: this.createPerspectiveCameraSettings.bind(this),\r\n        1: this.createOrthographicCameraSettings.bind(this)\r\n    }\r\n\r\n    public execute(): SceneGraphModel {\r\n        const handles = this.parseHandles();\r\n        const result: SceneGraphModel = {_resourceClass: 'sceneGraph_entity', handles: handles.map(h => h[1])};\r\n\r\n        const modelNodes = this.data.Objects.Model;\r\n\r\n        handles.forEach((ctx) => {\r\n            const [id, handle] = ctx,\r\n                modelNode: FBXObject = modelNodes[id],\r\n                connection = this.connections[id];\r\n            this.setLookAtProperties(handle, modelNode);\r\n\r\n            const transform = handle.components.find((c) => TransformModel.isType(c)) as TransformModel;\r\n            transform.key = id.toString();\r\n            connection?.parent?.key && (transform.parentKey = connection.parent.key.toString());\r\n        });\r\n        return result;\r\n    }\r\n\r\n    private parseHandles(): [number, HandleModel][] {\r\n        const result: [number, HandleModel][] = [],\r\n            modelNodes = this.data.Objects.Model;\r\n\r\n        for (const nodeID in modelNodes) {\r\n            const id = parseInt(nodeID),\r\n                node = modelNodes[nodeID],\r\n                relationships = this.connections[id];\r\n\r\n            const parser = this.nodeParserTypeMap[node.attrType];\r\n            if (!parser) {\r\n                this.logger.info(logMessage(this, 'parseHandles', `unknown attrType '${node.attrType}'.`));\r\n                continue;\r\n            }\r\n            const model = parser(node, relationships);\r\n            if (!model) {\r\n                continue;\r\n            }\r\n            this.setHandleTransforms(model, node);\r\n            result.push([parseInt(nodeID), model]);\r\n        }\r\n        return result;\r\n    }\r\n\r\n    private parseCamera(node: FBXObject, relationships: FbxContextRelationships): HandleModel {\r\n        if (!this.context.loadCamera) {\r\n            return null;\r\n        }\r\n\r\n        const model = this.createHandleModel(node);\r\n        model.components.push(this.createCameraSettings(relationships));\r\n        return model;\r\n    }\r\n\r\n    private parseLight(node: FBXObject, relationships: FbxContextRelationships): HandleModel {\r\n        if (!this.context.loadLights) {\r\n            return null;\r\n        }\r\n        const model = this.createHandleModel(node);\r\n        model.components.push(this.createLightSettings(relationships));\r\n        return model;\r\n    }\r\n\r\n    private parseMesh(node: FBXObject, relationships: FbxContextRelationships): HandleModel {\r\n        if (!this.context.loadMeshes) {\r\n            return null;\r\n        }\r\n        const model = this.createHandleModel(node);\r\n        model.components.push(this.createMesh(relationships));\r\n        return model;\r\n    }\r\n\r\n    private parseNurbsCurve(node: FBXObject, relationships: FbxContextRelationships): HandleModel {\r\n        if (!this.context.loadNurbes) {\r\n            return null;\r\n        }\r\n        const model = this.createHandleModel(node);\r\n        model.components.push(this.createMesh(relationships));\r\n        return model;\r\n    }\r\n\r\n    private createHandleModel(node: FBXObject): HandleModel {\r\n        return {\r\n            tags: [node.attrName].filter(a => !!a),\r\n            active: true,\r\n            components: []\r\n        };\r\n    }\r\n\r\n    private createCameraSettings(relationships: FbxContextRelationships): CameraModel {\r\n        let cameraAttribute;\r\n\r\n        relationships.children.forEach((child) => {\r\n            cameraAttribute = this.data.Objects.NodeAttribute[child.key];\r\n        });\r\n\r\n        if (cameraAttribute === undefined) {\r\n            this.logger.warn(logMessage(this, 'createCameraSettings', `Unknown camera type`));\r\n            return;\r\n        }\r\n        const type = cameraAttribute.CameraProjectionType?.value || 0,\r\n            parser = this.cameraSettingsParserMap[type];\r\n        if (!parser) {\r\n            this.logger.warn(logMessage(this, 'createCameraSettings', `Unknown camera type '${type}'.`));\r\n            return;\r\n        }\r\n        return parser(cameraAttribute);\r\n    }\r\n\r\n    private createPerspectiveCameraSettings(cameraAttribute): CameraModel {\r\n        let nearClippingPlane = 1;\r\n        if (cameraAttribute.NearPlane !== undefined) {\r\n            nearClippingPlane = cameraAttribute.NearPlane.value / 1000;\r\n        }\r\n\r\n        let farClippingPlane = 1000;\r\n        if (cameraAttribute.FarPlane !== undefined) {\r\n            farClippingPlane = cameraAttribute.FarPlane.value / 1000;\r\n        }\r\n\r\n        let width = 1920,\r\n            height = 1080;\r\n\r\n        if (\r\n            cameraAttribute.AspectWidth !== undefined &&\r\n            cameraAttribute.AspectHeight !== undefined\r\n        ) {\r\n            width = cameraAttribute.AspectWidth.value;\r\n            height = cameraAttribute.AspectHeight.value;\r\n        }\r\n\r\n        const aspect = width / height;\r\n\r\n        let fov = 45;\r\n        if (cameraAttribute.FieldOfView !== undefined) {\r\n            fov = cameraAttribute.FieldOfView.value;\r\n        }\r\n\r\n        return {\r\n            _resourceClass: 'component_camera',\r\n            type: CameraType.perspective,\r\n            fov: fov,\r\n            aspect: aspect,\r\n            near: nearClippingPlane,\r\n            far: farClippingPlane\r\n        };\r\n    }\r\n\r\n    private createOrthographicCameraSettings(cameraAttribute): CameraModel {\r\n        let nearClippingPlane = 1;\r\n        if (cameraAttribute.NearPlane !== undefined) {\r\n            nearClippingPlane = cameraAttribute.NearPlane.value / 1000;\r\n        }\r\n\r\n        let farClippingPlane = 1000;\r\n        if (cameraAttribute.FarPlane !== undefined) {\r\n            farClippingPlane = cameraAttribute.FarPlane.value / 1000;\r\n        }\r\n\r\n        let width = 1920,\r\n            height = 1080;\r\n\r\n        if (\r\n            cameraAttribute.AspectWidth !== undefined &&\r\n            cameraAttribute.AspectHeight !== undefined\r\n        ) {\r\n            width = cameraAttribute.AspectWidth.value;\r\n            height = cameraAttribute.AspectHeight.value;\r\n        }\r\n\r\n        return {\r\n            _resourceClass: 'component_camera',\r\n            type: CameraType.orthographic,\r\n            left: -width / 2,\r\n            right: width / 2,\r\n            top: height / 2,\r\n            bottom: -height / 2,\r\n            near: nearClippingPlane,\r\n            far: farClippingPlane\r\n        };\r\n    }\r\n\r\n    private getLightContext(lightAttribute): LightContext {\r\n        const result = {\r\n            type: lightAttribute.LightType?.value || 0,\r\n            color: lightAttribute.Color?.value.map((v) => v / 256) || [1, 1, 1],\r\n            intensity: lightAttribute.Intensity?.value / 100 || 1,\r\n            distance: 0,\r\n            decay: 1\r\n        };\r\n        if (\r\n            lightAttribute.CastLightOnObject !== undefined &&\r\n            lightAttribute.CastLightOnObject.value === 0\r\n        ) {\r\n            result.intensity = 0;\r\n        }\r\n        if (lightAttribute.FarAttenuationEnd !== undefined) {\r\n            if (!(\r\n                lightAttribute.EnableFarAttenuation !== undefined &&\r\n                lightAttribute.EnableFarAttenuation.value === 0\r\n            )) {\r\n                result.distance = lightAttribute.FarAttenuationEnd.value;\r\n            }\r\n        }\r\n        return result;\r\n    }\r\n\r\n    private createLightModel(lightAttribute): Partial<LightModel> {\r\n        const ctx = this.getLightContext(lightAttribute);\r\n        switch (ctx.type) {\r\n            case 0: //point\r\n                return {\r\n                    type: LightType.point,\r\n                    color: ctx.color,\r\n                    intensity: ctx.intensity,\r\n                    distance: ctx.distance,\r\n                    decay: ctx.decay\r\n                };\r\n            case 1: //directional\r\n                return {\r\n                    type: LightType.directional,\r\n                    color: ctx.color,\r\n                    intensity: ctx.intensity\r\n                };\r\n            case 2: //spot\r\n            {\r\n                let angle = Math.PI / 3;\r\n\r\n                if (lightAttribute.InnerAngle !== undefined) {\r\n                    angle = degreeToRad(lightAttribute.InnerAngle.value);\r\n                }\r\n\r\n                let penumbra = 0;\r\n                if (lightAttribute.OuterAngle !== undefined) {\r\n                    penumbra = degreeToRad(lightAttribute.OuterAngle.value);\r\n                    penumbra = Math.max(penumbra, 1);\r\n                }\r\n\r\n                return {\r\n                    type: LightType.spot,\r\n                    color: ctx.color,\r\n                    intensity: ctx.intensity,\r\n                    distance: ctx.distance,\r\n                    angle: angle,\r\n                    penumbra: penumbra,\r\n                    decay: ctx.decay\r\n                };\r\n            }\r\n            default:\r\n                this.logger.warn(logMessage(this, 'createLightSettings', `Unknown light type ${lightAttribute.LightType.value}, defaulting to PointLight.`));\r\n                break;\r\n        }\r\n        return {\r\n            type: LightType.point,\r\n            color: ctx.color,\r\n            intensity: ctx.intensity\r\n        };\r\n    }\r\n\r\n    private createLightSettings(relationships: FbxContextRelationships): LightModel {\r\n        let model: Partial<LightModel> = null,\r\n            lightAttribute;\r\n\r\n        relationships.children.forEach((child) => {\r\n            const attr = this.data.Objects.NodeAttribute[child.key];\r\n\r\n            if (attr !== undefined) {\r\n                lightAttribute = attr;\r\n            }\r\n        });\r\n\r\n        if (lightAttribute !== undefined) {\r\n            model = this.createLightModel(lightAttribute);\r\n\r\n            if (lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1) {\r\n                model.castShadow = true;\r\n            }\r\n        }\r\n\r\n        return {_resourceClass: 'component_light', ...model};\r\n    }\r\n\r\n    private setLookAtProperties(handle: HandleModel, modelNode: FBXObject): void {\r\n        if ('LookAtProperty' in modelNode) {\r\n            const children = this.connections[handle.id].children;\r\n\r\n            children.forEach((child) => {\r\n                if (child.relationship === 'LookAtProperty') {\r\n                    const lookAtTarget = this.data.Objects.Model[child.key];\r\n\r\n                    if ('Lcl_Translation' in lookAtTarget) {\r\n                        const transform = handle.components.find((h) => h.key == 'transform') as TransformModel;\r\n                        transform.rotation = Quaternion.lookAt(\r\n                            (transform.translation as Vector3) || Vector3.one,\r\n                            new Vector3(...lookAtTarget.Lcl_Translation.value)\r\n                        ).values;\r\n                    }\r\n                }\r\n            });\r\n        }\r\n    }\r\n\r\n    private createMesh(relationships: FbxContextRelationships): RendererModel {\r\n        let geometry: GeometryModelType = null;\r\n        const materials: MaterialModelType[] = [];\r\n        relationships.children.forEach((child) => {\r\n            if (this.geometryMap[child.key]) {\r\n                geometry = this.geometryMap[child.key];\r\n            }\r\n            if (this.materialMap[child.key]) {\r\n                materials.push(this.materialMap[child.key]);\r\n            }\r\n            //TODO: unused Materials entfernen.\r\n        });\r\n\r\n        if ('colors' in geometry) {\r\n            materials.forEach((material) => {\r\n                material.vertexColor = true;\r\n            });\r\n        }\r\n        return {\r\n            _resourceClass: 'component_renderer',\r\n            type: 'static', //geometry.FBX_Deformer ? 'dynamic' : 'static',\r\n            geometry: geometry,\r\n            materials: materials\r\n        };\r\n    }\r\n\r\n\r\n    // parse the model node for transform details and apply them to the model\r\n    private setHandleTransforms(handle: Partial<HandleModel>, modelNode: FBXObject): void {\r\n        const settings: TransformModel = {_resourceClass: 'component_transform', active: true};\r\n        // http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_euler_html\r\n        if ('RotationOrder' in modelNode) {\r\n            const orderMapping = [\r\n                EulerOrder.XYZ, // default\r\n                EulerOrder.XZY,\r\n                EulerOrder.YZX,\r\n                EulerOrder.ZXY,\r\n                EulerOrder.YXZ,\r\n                EulerOrder.ZYX\r\n            ];\r\n\r\n            const value = parseInt(modelNode.RotationOrder.value, 10);\r\n\r\n            if (value > 0 && value < 6) {\r\n                settings['rotationOrder'] = orderMapping[value];\r\n\r\n                // Note: Euler order other than XYZ is currently not supported, so just display a warning for now\r\n                this.logger.warn(logMessage(this, 'setHandleTransforms', `unsupported Euler Order: ${orderMapping[value]}. Currently only XYZ order is supported. Animations and rotations may be incorrect.`));\r\n            } else if (value === 6) {\r\n                this.logger.warn(logMessage(this, 'setHandleTransforms', 'unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect.'));\r\n            }\r\n        }\r\n\r\n        if ('Lcl_Translation' in modelNode) {\r\n            settings.translation = modelNode.Lcl_Translation.value.map(v => this.context.scaleFactor * v) as [number, number, number];\r\n        }\r\n\r\n        if ('Lcl_Rotation' in modelNode) {\r\n            settings.rotation = modelNode.Lcl_Rotation.value.map(degreeToRad) as [number, number, number];\r\n        }\r\n\r\n        if ('Lcl_Scaling' in modelNode) {\r\n            settings.scale = modelNode.Lcl_Scaling.value;\r\n        }\r\n\r\n        if ('PreRotation' in modelNode) {\r\n            settings.rotation = (settings.rotation as Quaternion).multiply(Euler.toQuaternion(\r\n                new Euler(...modelNode.PreRotation.value.map(degreeToRad) as [number, number, number])\r\n            ));\r\n        }\r\n        handle.components.unshift(settings);\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {ComponentTransformer} from './componentTransformer';\r\nimport {FBXTexture} from '../model/fbxModel';\r\nimport {TextureModel} from '../../../../model/assetModel/textureModel';\r\nimport {WrapType} from '../../../../../rendering/asset/textureAsset/wrapType';\r\n\r\nexport class TextureTransformer extends ComponentTransformer {\r\n    execute(imageMap: { [key: string]: string }): { [key: string]: Partial<TextureModel> } {\r\n        const result: { [key: string]: TextureModel } = {};\r\n\r\n        if ('Texture' in this.data.Objects) {\r\n            const textureNodes = this.data.Objects.Texture;\r\n            for (const nodeID in textureNodes) {\r\n                result[nodeID] = this.parseTexture(\r\n                    textureNodes[nodeID],\r\n                    imageMap\r\n                );\r\n            }\r\n        }\r\n\r\n        return result;\r\n    }\r\n\r\n    // Parse individual node in FBXTree.Objects.Texture\r\n    private parseTexture(textureNode: FBXTexture, images: { [key: string]: string }): TextureModel {\r\n        const texture = this.loadTexture(textureNode, images);\r\n\r\n        texture.tags = [textureNode.attrName];\r\n\r\n        const valueU = textureNode.WrapModeU?.value || 0,\r\n            valueV = textureNode.WrapModeV?.value || 0;\r\n\r\n        // http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a\r\n        // 0: repeat(default), 1: clamp\r\n\r\n        texture.wrap = {\r\n            u: valueU === 0 ? WrapType.repeat : WrapType.clamp,\r\n            v: valueV === 0 ? WrapType.repeat : WrapType.clamp\r\n        }\r\n\r\n        if ('Scaling' in textureNode) {\r\n            const values = textureNode.Scaling.value;\r\n\r\n            texture.repeat = [values[0], values[1]];\r\n        }\r\n        return texture;\r\n    }\r\n\r\n    private loadTexture(textureNode: FBXTexture, images: { [key: string]: string }): TextureModel {\r\n        const children = this.connections[textureNode.id].children;\r\n\r\n        if (\r\n            children !== undefined &&\r\n            children.length > 0 &&\r\n            images[children[0].key] !== undefined\r\n        ) {\r\n            const key = `local/image/${images[children[0].key]}`;\r\n\r\n            return {\r\n                _resourceClass: 'texture_entity',\r\n                key: key,\r\n                images: [key]\r\n            }\r\n        }\r\n        return {\r\n            _resourceClass: 'texture_entity',\r\n            images: []\r\n        };\r\n    }\r\n}\r\n","import {DeformerTransformer} from './deformerTransformer';\r\nimport {GeometryTransformer} from './geometryTransformer';\r\nimport {ImageTransformer} from './imageTransformer';\r\nimport {MaterialTransformer} from './materialTransformer';\r\nimport {SceneTransformer} from './sceneTransformer';\r\nimport {TextureTransformer} from './textureTransformer';\r\n\r\nexport {\r\n    DeformerTransformer,\r\n    GeometryTransformer,\r\n    ImageTransformer,\r\n    MaterialTransformer,\r\n    SceneTransformer,\r\n    TextureTransformer\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\n\r\nimport {FbxParserSettings} from '../fbxParser.settings';\r\nimport {DependencyResolver, PropertyResolver} from '@fire-visual/di';\r\nimport {arrayBufferToString, Logger, LoggerType, logMessage} from '@fire-visual/utils';\r\nimport {FbxContext, FbxContextRelationships, FbxContextType} from './fbxContext';\r\nimport {FbxBinaryReader} from './fbxBinaryReader';\r\nimport {\r\n    DeformerTransformer,\r\n    GeometryTransformer,\r\n    ImageTransformer,\r\n    MaterialTransformer,\r\n    SceneTransformer,\r\n    TextureTransformer\r\n} from './componentTransformer';\r\nimport {FBXModel} from './model/fbxModel';\r\nimport {SceneGraphModel} from '../../../model';\r\n\r\nexport class FbxModelParser {\r\n    private static readonly FBX_FORMAT_HEADER = 'Kaydara FBX Binary ';\r\n\r\n    @PropertyResolver(DependencyResolver)\r\n    private readonly dependecyResolver: DependencyResolver;\r\n\r\n    @PropertyResolver({_type: LoggerType})\r\n    private readonly logger: Logger;\r\n\r\n    @PropertyResolver({_type: FbxContextType})\r\n    private readonly context: FbxContext;\r\n\r\n    constructor(public readonly settings: FbxModelParser.Settings) {\r\n    }\r\n\r\n    public async execute(): Promise<SceneGraphModel> {\r\n        const output = await this.evaluateInputType(this.settings.data);\r\n        if (output[0] == 'binary') {\r\n            this.context.data = new FbxBinaryReader(output[1]).parse();\r\n        }\r\n        if (output[0] == 'ascii') {\r\n            throw new Error('parseData - can\\'t import ASCII-FBX files.')\r\n        }\r\n        if (!this.context?.data) {\r\n            throw new Error('parseData - input couldn\\'t be parsed');\r\n        }\r\n        this.context.connections = this.parseConnections(this.context.data);\r\n        if (Object.keys(this.context.connections).length === 0) {\r\n            this.logger.debug(logMessage(this, 'parseData', 'parsed fbx contains no connections.'));\r\n        }\r\n        const imageMap = this.dependecyResolver.instance({constructorType: ImageTransformer}).execute();\r\n        const textureMap = this.dependecyResolver.instance({constructorType: TextureTransformer}).execute(imageMap);\r\n        this.context.materialMap = this.dependecyResolver.instance({constructorType: MaterialTransformer}).execute(textureMap);\r\n        const skeletonMap = this.dependecyResolver.instance({constructorType: DeformerTransformer}).execute();\r\n        this.context.geometryMap = this.dependecyResolver.instance({constructorType: GeometryTransformer}).execute(skeletonMap);\r\n\r\n        if (Object.keys(this.context.geometryMap).length === 0) {\r\n            this.logger.debug(logMessage(this, 'parseData', 'parsed fbx contains no geometries.'));\r\n        }\r\n\r\n        return this.dependecyResolver.instance({constructorType: SceneTransformer}).execute();\r\n    }\r\n\r\n    private async evaluateInputType(buffer: ArrayBuffer | Blob): Promise<['binary', ArrayBuffer] | ['ascii', string]> {\r\n        if (\r\n            buffer instanceof ArrayBuffer &&\r\n            buffer.byteLength >= FbxModelParser.FBX_FORMAT_HEADER.length &&\r\n            FbxModelParser.FBX_FORMAT_HEADER == arrayBufferToString(buffer, 0, FbxModelParser.FBX_FORMAT_HEADER.length)\r\n        ) {\r\n            return ['binary', buffer];\r\n        }\r\n        if (buffer instanceof Blob) {\r\n            const text = await buffer.text();\r\n            if (text.startsWith(FbxModelParser.FBX_FORMAT_HEADER)) {\r\n                return ['ascii', text];\r\n            }\r\n        }\r\n        throw new Error('Unknown format.');\r\n    }\r\n\r\n    private parseConnections(data: FBXModel): { [key: string]: FbxContextRelationships } {\r\n        const connectionMap: { [key: string]: FbxContextRelationships } = {};\r\n\r\n        if ('Connections' in data && !!data.Connections.connections) {\r\n            const rawConnections = data.Connections.connections;\r\n            rawConnections.forEach((rawConnection) => {\r\n                const [fromID, toID, relationship] = rawConnection;\r\n                if (!connectionMap[fromID]) {\r\n                    connectionMap[fromID] = {\r\n                        parent: null,\r\n                        children: []\r\n                    };\r\n                }\r\n                if (!connectionMap[fromID].parent) {\r\n                    connectionMap[fromID].parent = {\r\n                        key: toID,\r\n                        relationship: relationship\r\n                    };\r\n                }\r\n\r\n                if (!connectionMap[toID]) {\r\n                    connectionMap[toID] = {\r\n                        parent: null,\r\n                        children: []\r\n                    };\r\n                }\r\n                connectionMap[toID].children.push({\r\n                    key: fromID,\r\n                    relationship: relationship\r\n                });\r\n            });\r\n        }\r\n\r\n        return connectionMap;\r\n    }\r\n}\r\n\r\nexport namespace FbxModelParser {\r\n    export interface Settings {\r\n        key: string,\r\n        settings: FbxParserSettings;\r\n        data: ArrayBuffer\r\n    }\r\n}\r\n","//Info: DON'T SHORTEN IMPORTS\r\nimport {WorkerLogger, WorkerProcessor} from '@fire-visual/worker';\r\nimport {GeometryModelType, Model, SceneGraphModel} from '../../../model';\r\nimport {SceneGraphOptimizer} from './optimizer/sceneGraphOptimizer';\r\nimport {GeometryOptimizer} from './optimizer/geometryOptimizer';\r\nimport {FbxProcessorGeometryRequest, FbxProcessorRequestType, FbxProcessorSceneGraphRequest} from '../request';\r\nimport {FbxProcessorResponseType} from '../response';\r\nimport {Logger, LoggerType} from '@fire-visual/utils';\r\nimport {DependencyResolver} from '@fire-visual/di';\r\nimport {FbxModelParser} from './fbxModelParser';\r\nimport {FbxContext, FbxContextType} from './fbxContext';\r\nimport {FBXModel} from './model/fbxModel';\r\n\r\nexport class FbxProcessor extends WorkerProcessor<FbxProcessorRequestType, FbxProcessorResponseType> {\r\n\r\n    constructor() {\r\n        super();\r\n        this.registerMethodProcessor('geometryRequest', this.parseGeometry.bind(this));\r\n        this.registerMethodProcessor('sceneGraphRequest', this.parseSceneGraph.bind(this));\r\n    }\r\n\r\n    private static metricsMap: { key: number, value: string }[] = [\r\n        {key: 0.001, value: 'SI_KILOMETER'},\r\n        {key: 0.01, value: 'SI_METER'},\r\n        {key: 0.1, value: 'SI_DECIMETER'},\r\n        {key: 1, value: 'SI_CENTIMETER'},\r\n        {key: 10, value: 'SI_MILLIMETER'},\r\n        {key: 100, value: 'SI_DECIMETER'}\r\n    ];\r\n\r\n    private async parseGeometry(payload: FbxProcessorGeometryRequest['payload'], requestId: number): Promise<GeometryModelType> {\r\n        const ctx = new FbxContext(payload.key, payload.settings);\r\n        const dependencyResolver = new DependencyResolver(\r\n            {target: LoggerType, value: new WorkerLogger(this.port, {requestId})},\r\n            {target: FbxContextType, value: ctx}\r\n        );\r\n        const model = await dependencyResolver.instance({constructorType: FbxModelParser}, payload).execute();\r\n        const result = dependencyResolver.instance({constructorType: GeometryOptimizer}).execute(model).geometry as GeometryModelType;\r\n\r\n        return this.assureMetaDataOnModel(result, ctx.data, dependencyResolver.resolve(LoggerType));\r\n    }\r\n\r\n    private async parseSceneGraph(payload: FbxProcessorSceneGraphRequest['payload'], requestId: number): Promise<SceneGraphModel> {\r\n        const ctx = new FbxContext(payload.key, payload.settings);\r\n        const dependencyResolver = new DependencyResolver(\r\n            {target: LoggerType, value: new WorkerLogger(this.port, {requestId})},\r\n            {target: FbxContextType, value: ctx}\r\n        );\r\n        const model = await dependencyResolver.instance({constructorType: FbxModelParser}, payload).execute();\r\n        const result = dependencyResolver.instance({constructorType: SceneGraphOptimizer}).execute(model);\r\n        return this.assureMetaDataOnModel(result, ctx.data, dependencyResolver.resolve(LoggerType));\r\n    }\r\n\r\n    private assureMetaDataOnModel<TModel extends Model>(target: TModel, source: FBXModel, logger: Logger): TModel {\r\n        try {\r\n            const unitScaleFactor = source.GlobalSettings.UnitScaleFactor.value,\r\n                unitMapping = FbxProcessor.metricsMap.find(u => u.key == unitScaleFactor);\r\n            if (!unitMapping) {\r\n                throw new Error(`no valid unitMapping found for input ${unitScaleFactor}.`);\r\n            }\r\n            if (!target.meta) {\r\n                target.meta = {};\r\n            }\r\n            target.meta.lengthUnit = unitMapping.value;\r\n        } catch (e) {\r\n            logger.warn(e.message);\r\n        }\r\n        return target;\r\n    }\r\n}\r\n","import {FbxProcessor} from './fbxProcessor';\r\n\r\nFbxProcessor.create(globalThis as any);\r\n"],"names":[],"sourceRoot":""}
