diff --git a/package-lock.json b/package-lock.json index 248ba8d..bdc7824 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,15 @@ { "name": "nifti-reader-js", - "version": "0.6.2", + "version": "0.6.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nifti-reader-js", - "version": "0.6.2", + "version": "0.6.3", "license": "MIT", "dependencies": { - "fflate": "*", - "pako": "*" + "fflate": "*" }, "devDependencies": { "browserify": "*", @@ -2587,11 +2586,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/pako": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pako/-/pako-2.0.4.tgz", - "integrity": "sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==" - }, "node_modules/parents": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parents/-/parents-1.0.1.tgz", @@ -5764,11 +5758,6 @@ "p-limit": "^3.0.2" } }, - "pako": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pako/-/pako-2.0.4.tgz", - "integrity": "sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==" - }, "parents": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parents/-/parents-1.0.1.tgz", diff --git a/package.json b/package.json index 5c3ccbe..491d0de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nifti-reader-js", - "version": "0.6.2", + "version": "0.6.3", "description": "A JavaScript NIfTI file format reader.", "main": "src/nifti.js", "directories": { diff --git a/release/current/nifti-reader-min.js b/release/current/nifti-reader-min.js index 26aa731..897af31 100644 --- a/release/current/nifti-reader-min.js +++ b/release/current/nifti-reader-min.js @@ -1 +1 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.nifti=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;var i;for(i=0;i>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;ilen2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],2:[function(require,module,exports){(function(Buffer){(function(){"use strict";var base64=require("base64-js");var ieee754=require("ieee754");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;var K_MAX_LENGTH=2147483647;exports.kMaxLength=K_MAX_LENGTH;Buffer.TYPED_ARRAY_SUPPORT=typedArraySupport();if(!Buffer.TYPED_ARRAY_SUPPORT&&typeof console!=="undefined"&&typeof console.error==="function"){console.error("This browser lacks typed array (Uint8Array) support which is required by "+"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.")}function typedArraySupport(){try{var arr=new Uint8Array(1);arr.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}};return arr.foo()===42}catch(e){return false}}Object.defineProperty(Buffer.prototype,"parent",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.buffer}});Object.defineProperty(Buffer.prototype,"offset",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.byteOffset}});function createBuffer(length){if(length>K_MAX_LENGTH){throw new RangeError('The value "'+length+'" is invalid for option "size"')}var buf=new Uint8Array(length);buf.__proto__=Buffer.prototype;return buf}function Buffer(arg,encodingOrOffset,length){if(typeof arg==="number"){if(typeof encodingOrOffset==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return allocUnsafe(arg)}return from(arg,encodingOrOffset,length)}if(typeof Symbol!=="undefined"&&Symbol.species!=null&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true,enumerable:false,writable:false})}Buffer.poolSize=8192;function from(value,encodingOrOffset,length){if(typeof value==="string"){return fromString(value,encodingOrOffset)}if(ArrayBuffer.isView(value)){return fromArrayLike(value)}if(value==null){throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}if(isInstance(value,ArrayBuffer)||value&&isInstance(value.buffer,ArrayBuffer)){return fromArrayBuffer(value,encodingOrOffset,length)}if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var valueOf=value.valueOf&&value.valueOf();if(valueOf!=null&&valueOf!==value){return Buffer.from(valueOf,encodingOrOffset,length)}var b=fromObject(value);if(b)return b;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof value[Symbol.toPrimitive]==="function"){return Buffer.from(value[Symbol.toPrimitive]("string"),encodingOrOffset,length)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}Buffer.from=function(value,encodingOrOffset,length){return from(value,encodingOrOffset,length)};Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;function assertSize(size){if(typeof size!=="number"){throw new TypeError('"size" argument must be of type number')}else if(size<0){throw new RangeError('The value "'+size+'" is invalid for option "size"')}}function alloc(size,fill,encoding){assertSize(size);if(size<=0){return createBuffer(size)}if(fill!==undefined){return typeof encoding==="string"?createBuffer(size).fill(fill,encoding):createBuffer(size).fill(fill)}return createBuffer(size)}Buffer.alloc=function(size,fill,encoding){return alloc(size,fill,encoding)};function allocUnsafe(size){assertSize(size);return createBuffer(size<0?0:checked(size)|0)}Buffer.allocUnsafe=function(size){return allocUnsafe(size)};Buffer.allocUnsafeSlow=function(size){return allocUnsafe(size)};function fromString(string,encoding){if(typeof encoding!=="string"||encoding===""){encoding="utf8"}if(!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}var length=byteLength(string,encoding)|0;var buf=createBuffer(length);var actual=buf.write(string,encoding);if(actual!==length){buf=buf.slice(0,actual)}return buf}function fromArrayLike(array){var length=array.length<0?0:checked(array.length)|0;var buf=createBuffer(length);for(var i=0;i=K_MAX_LENGTH){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+K_MAX_LENGTH.toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return b!=null&&b._isBuffer===true&&b!==Buffer.prototype};Buffer.compare=function compare(a,b){if(isInstance(a,Uint8Array))a=Buffer.from(a,a.offset,a.byteLength);if(isInstance(b,Uint8Array))b=Buffer.from(b,b.offset,b.byteLength);if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i2&&arguments[2]===true;if(!mustMatch&&len===0)return 0;var loweredCase=false;for(;;){switch(encoding){case"ascii":case"latin1":case"binary":return len;case"utf8":case"utf-8":return utf8ToBytes(string).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return len*2;case"hex":return len>>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase){return mustMatch?-1:utf8ToBytes(string).length}encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"latin1":case"binary":return latin1Slice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;imax)str+=" ... ";return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(isInstance(target,Uint8Array)){target=Buffer.from(target,target.offset,target.byteLength)}if(!Buffer.isBuffer(target)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof target)}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset=+byteOffset;if(numberIsNaN(byteOffset)){byteOffset=dir?0:buffer.length-1}if(byteOffset<0)byteOffset=buffer.length+byteOffset;if(byteOffset>=buffer.length){if(dir)return-1;else byteOffset=buffer.length-1}else if(byteOffset<0){if(dir)byteOffset=0;else return-1}if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(buffer,val,byteOffset,encoding,dir)}else if(typeof val==="number"){val=val&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(dir){return Uint8Array.prototype.indexOf.call(buffer,val,byteOffset)}else{return Uint8Array.prototype.lastIndexOf.call(buffer,val,byteOffset)}}return arrayIndexOf(buffer,[val],byteOffset,encoding,dir)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(arr,val,byteOffset,encoding,dir){var indexSize=1;var arrLength=arr.length;var valLength=val.length;if(encoding!==undefined){encoding=String(encoding).toLowerCase();if(encoding==="ucs2"||encoding==="ucs-2"||encoding==="utf16le"||encoding==="utf-16le"){if(arr.length<2||val.length<2){return-1}indexSize=2;arrLength/=2;valLength/=2;byteOffset/=2}}function read(buf,i){if(indexSize===1){return buf[i]}else{return buf.readUInt16BE(i*indexSize)}}var i;if(dir){var foundIndex=-1;for(i=byteOffset;iarrLength)byteOffset=arrLength-valLength;for(i=byteOffset;i>=0;i--){var found=true;for(var j=0;jremaining){length=remaining}}var strLen=string.length;if(length>strLen/2){length=strLen/2}for(var i=0;i>>0;if(isFinite(length)){length=length>>>0;if(encoding===undefined)encoding="utf8"}else{encoding=length;length=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var remaining=this.length-offset;if(length===undefined||length>remaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"latin1":case"binary":return latin1Write(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){checkOffset(offset,byteLength,this.length)}var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);this[offset]=value&255;return offset+1};Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255;return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24;return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,4,34028234663852886e22,-34028234663852886e22)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,8,17976931348623157e292,-17976931348623157e292)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!Buffer.isBuffer(target))throw new TypeError("argument should be a Buffer");if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("Index out of range");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;--i){target[i+targetStart]=this[i+start]}}else{Uint8Array.prototype.set.call(target,this.subarray(start,end),targetStart)}return len};Buffer.prototype.fill=function fill(val,start,end,encoding){if(typeof val==="string"){if(typeof start==="string"){encoding=start;start=0;end=this.length}else if(typeof end==="string"){encoding=end;end=this.length}if(encoding!==undefined&&typeof encoding!=="string"){throw new TypeError("encoding must be a string")}if(typeof encoding==="string"&&!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}if(val.length===1){var code=val.charCodeAt(0);if(encoding==="utf8"&&code<128||encoding==="latin1"){val=code}}}else if(typeof val==="number"){val=val&255}if(start<0||this.length>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){for(var i=0;i=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isInstance(obj,type){return obj instanceof type||obj!=null&&obj.constructor!=null&&obj.constructor.name!=null&&obj.constructor.name===type.name}function numberIsNaN(obj){return obj!==obj}}).call(this)}).call(this,require("buffer").Buffer)},{"base64-js":1,buffer:2,ieee754:5}],3:[function(require,module,exports){"use strict";var node_worker_1=require("./node-worker.cjs");var u8=Uint8Array,u16=Uint16Array,u32=Uint32Array;var fleb=new u8([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]);var fdeb=new u8([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]);var clim=new u8([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);var freb=function(eb,start){var b=new u16(31);for(var i=0;i<31;++i){b[i]=start+=1<>>1|(i&21845)<<1;x=(x&52428)>>>2|(x&13107)<<2;x=(x&61680)>>>4|(x&3855)<<4;rev[i]=((x&65280)>>>8|(x&255)<<8)>>>1}var hMap=function(cd,mb,r){var s=cd.length;var i=0;var l=new u16(mb);for(;i>>rvb]=sv}}}}else{co=new u16(s);for(i=0;i>>15-cd[i]}}}return co};var flt=new u8(288);for(var i=0;i<144;++i)flt[i]=8;for(var i=144;i<256;++i)flt[i]=9;for(var i=256;i<280;++i)flt[i]=7;for(var i=280;i<288;++i)flt[i]=8;var fdt=new u8(32);for(var i=0;i<32;++i)fdt[i]=5;var flm=hMap(flt,9,0),flrm=hMap(flt,9,1);var fdm=hMap(fdt,5,0),fdrm=hMap(fdt,5,1);var max=function(a){var m=a[0];for(var i=1;im)m=a[i]}return m};var bits=function(d,p,m){var o=p/8|0;return(d[o]|d[o+1]<<8)>>(p&7)&m};var bits16=function(d,p){var o=p/8|0;return(d[o]|d[o+1]<<8|d[o+2]<<16)>>(p&7)};var shft=function(p){return(p+7)/8|0};var slc=function(v,s,e){if(s==null||s<0)s=0;if(e==null||e>v.length)e=v.length;var n=new(v.BYTES_PER_ELEMENT==2?u16:v.BYTES_PER_ELEMENT==4?u32:u8)(e-s);n.set(v.subarray(s,e));return n};exports.FlateErrorCode={UnexpectedEOF:0,InvalidBlockType:1,InvalidLengthLiteral:2,InvalidDistance:3,StreamFinished:4,NoStreamHandler:5,InvalidHeader:6,NoCallback:7,InvalidUTF8:8,ExtraFieldTooLong:9,InvalidDate:10,FilenameTooLong:11,StreamFinishing:12,InvalidZipData:13,UnknownCompressionMethod:14};var ec=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"];var err=function(ind,msg,nt){var e=new Error(msg||ec[ind]);e.code=ind;if(Error.captureStackTrace)Error.captureStackTrace(e,err);if(!nt)throw e;return e};var inflt=function(dat,buf,st){var sl=dat.length;if(!sl||st&&st.f&&!st.l)return buf||new u8(0);var noBuf=!buf||st;var noSt=!st||st.i;if(!st)st={};if(!buf)buf=new u8(sl*3);var cbuf=function(l){var bl=buf.length;if(l>bl){var nbuf=new u8(Math.max(bl*2,l));nbuf.set(buf);buf=nbuf}};var final=st.f||0,pos=st.p||0,bt=st.b||0,lm=st.l,dm=st.d,lbt=st.m,dbt=st.n;var tbts=sl*8;do{if(!lm){final=bits(dat,pos,1);var type=bits(dat,pos+1,3);pos+=3;if(!type){var s=shft(pos)+4,l=dat[s-4]|dat[s-3]<<8,t=s+l;if(t>sl){if(noSt)err(0);break}if(noBuf)cbuf(bt+l);buf.set(dat.subarray(s,t),bt);st.b=bt+=l,st.p=pos=t*8,st.f=final;continue}else if(type==1)lm=flrm,dm=fdrm,lbt=9,dbt=5;else if(type==2){var hLit=bits(dat,pos,31)+257,hcLen=bits(dat,pos+10,15)+4;var tl=hLit+bits(dat,pos+5,31)+1;pos+=14;var ldt=new u8(tl);var clt=new u8(19);for(var i=0;i>>4;if(s<16){ldt[i++]=s}else{var c=0,n=0;if(s==16)n=3+bits(dat,pos,3),pos+=2,c=ldt[i-1];else if(s==17)n=3+bits(dat,pos,7),pos+=3;else if(s==18)n=11+bits(dat,pos,127),pos+=7;while(n--)ldt[i++]=c}}var lt=ldt.subarray(0,hLit),dt=ldt.subarray(hLit);lbt=max(lt);dbt=max(dt);lm=hMap(lt,lbt,1);dm=hMap(dt,dbt,1)}else err(1);if(pos>tbts){if(noSt)err(0);break}}if(noBuf)cbuf(bt+131072);var lms=(1<>>4;pos+=c&15;if(pos>tbts){if(noSt)err(0);break}if(!c)err(2);if(sym<256)buf[bt++]=sym;else if(sym==256){lpos=pos,lm=null;break}else{var add=sym-254;if(sym>264){var i=sym-257,b=fleb[i];add=bits(dat,pos,(1<>>4;if(!d)err(3);pos+=d&15;var dt=fd[dsym];if(dsym>3){var b=fdeb[dsym];dt+=bits16(dat,pos)&(1<tbts){if(noSt)err(0);break}if(noBuf)cbuf(bt+131072);var end=bt+add;for(;bt>>8};var wbits16=function(d,p,v){v<<=p&7;var o=p/8|0;d[o]|=v;d[o+1]|=v>>>8;d[o+2]|=v>>>16};var hTree=function(d,mb){var t=[];for(var i=0;imaxSym)maxSym=t2[i].s}var tr=new u16(maxSym+1);var mbt=ln(t[i1-1],tr,0);if(mbt>mb){var i=0,dt=0;var lft=mbt-mb,cst=1<mb){dt+=cst-(1<>>=lft;while(dt>0){var i2_2=t2[i].s;if(tr[i2_2]=0&&dt;--i){var i2_3=t2[i].s;if(tr[i2_3]==mb){--tr[i2_3];++dt}}mbt=mb}return[new u8(tr),mbt]};var ln=function(n,l,d){return n.s==-1?Math.max(ln(n.l,l,d+1),ln(n.r,l,d+1)):l[n.s]=d};var lc=function(c){var s=c.length;while(s&&!c[--s]);var cl=new u16(++s);var cli=0,cln=c[0],cls=1;var w=function(v){cl[cli++]=v};for(var i=1;i<=s;++i){if(c[i]==cln&&i!=s)++cls;else{if(!cln&&cls>2){for(;cls>138;cls-=138)w(32754);if(cls>2){w(cls>10?cls-11<<5|28690:cls-3<<5|12305);cls=0}}else if(cls>3){w(cln),--cls;for(;cls>6;cls-=6)w(8304);if(cls>2)w(cls-3<<5|8208),cls=0}while(cls--)w(cln);cls=1;cln=c[i]}}return[cl.subarray(0,cli),s]};var clen=function(cf,cl){var l=0;for(var i=0;i>>8;out[o+2]=out[o]^255;out[o+3]=out[o+1]^255;for(var i=0;i4&&!lct[clim[nlcc-1]];--nlcc);var flen=bl+5<<3;var ftlen=clen(lf,flt)+clen(df,fdt)+eb;var dtlen=clen(lf,dlt)+clen(df,ddt)+eb+14+3*nlcc+clen(lcfreq,lct)+(2*lcfreq[16]+3*lcfreq[17]+7*lcfreq[18]);if(flen<=ftlen&&flen<=dtlen)return wfblk(out,p,dat.subarray(bs,bs+bl));var lm,ll,dm,dl;wbits(out,p,1+(dtlen15)wbits(out,p,clct[i]>>>5&127),p+=clct[i]>>>12}}}else{lm=flm,ll=flt,dm=fdm,dl=fdt}for(var i=0;i255){var len=syms[i]>>>18&31;wbits16(out,p,lm[len+257]),p+=ll[len+257];if(len>7)wbits(out,p,syms[i]>>>23&31),p+=fleb[len];var dst=syms[i]&31;wbits16(out,p,dm[dst]),p+=dl[dst];if(dst>3)wbits16(out,p,syms[i]>>>5&8191),p+=fdeb[dst]}else{wbits16(out,p,lm[syms[i]]),p+=ll[syms[i]]}}wbits16(out,p,lm[256]);return p+ll[256]};var deo=new u32([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]);var et=new u8(0);var dflt=function(dat,lvl,plvl,pre,post,lst){var s=dat.length;var o=new u8(pre+s+5*(1+Math.ceil(s/7e3))+post);var w=o.subarray(pre,o.length-post);var pos=0;if(!lvl||s<8){for(var i=0;i<=s;i+=65535){var e=i+65535;if(e>=s){w[pos>>3]=lst}pos=wfblk(w,pos+1,dat.subarray(i,e))}}else{var opt=deo[lvl-1];var n=opt>>>13,c=opt&8191;var msk_1=(1<7e3||li>24576)&&rem>423){pos=wblk(dat,w,0,syms,lf,df,eb,li,bs,i-bs,pos);li=lc_1=eb=0,bs=i;for(var j=0;j<286;++j)lf[j]=0;for(var j=0;j<30;++j)df[j]=0}var l=2,d=0,ch_1=c,dif=imod-pimod&32767;if(rem>2&&hv==hsh(i-dif)){var maxn=Math.min(n,rem)-1;var maxd=Math.min(32767,i);var ml=Math.min(258,rem);while(dif<=maxd&&--ch_1&&imod!=pimod){if(dat[i+l]==dat[i+l-dif]){var nl=0;for(;nll){l=nl,d=dif;if(nl>maxn)break;var mmd=Math.min(dif,nl-2);var md=0;for(var j=0;jmd)md=cd,pimod=ti}}}imod=pimod,pimod=prev[imod];dif+=imod-pimod+32768&32767}}if(d){syms[li++]=268435456|revfl[l]<<18|revfd[d];var lin=revfl[l]&31,din=revfd[d]&31;eb+=fleb[lin]+fdeb[din];++lf[257+lin];++df[din];wi=i+l;++lc_1}else{syms[li++]=dat[i];++lf[dat[i]]}}}pos=wblk(dat,w,lst,syms,lf,df,eb,li,bs,i-bs,pos);if(!lst&&pos&7)pos=wfblk(w,pos+1,et)}return slc(o,0,pre+shft(pos)+post)};var crct=function(){var t=new Int32Array(256);for(var i=0;i<256;++i){var c=i,k=9;while(--k)c=(c&1&&-306674912)^c>>>1;t[i]=c}return t}();var crc=function(){var c=-1;return{p:function(d){var cr=c;for(var i=0;i>>8;c=cr},d:function(){return~c}}};var adler=function(){var a=1,b=0;return{p:function(d){var n=a,m=b;var l=d.length|0;for(var i=0;i!=l;){var e=Math.min(i+2655,l);for(;i>16),m=(m&65535)+15*(m>>16)}a=n,b=m},d:function(){a%=65521,b%=65521;return(a&255)<<24|a>>>8<<16|(b&255)<<8|b>>>8}}};var dopt=function(dat,opt,pre,post,st){return dflt(dat,opt.level==null?6:opt.level,opt.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(dat.length)))*1.5):12+opt.mem,pre,post,!st)};var mrg=function(a,b){var o={};for(var k in a)o[k]=a[k];for(var k in b)o[k]=b[k];return o};var wcln=function(fn,fnStr,td){var dt=fn();var st=fn.toString();var ks=st.slice(st.indexOf("[")+1,st.lastIndexOf("]")).replace(/\s+/g,"").split(",");for(var i=0;i>>0};var b8=function(d,b){return b4(d,b)+b4(d,b+4)*4294967296};var wbytes=function(d,b,v){for(;v;++b)d[b]=v,v>>>=8};var gzh=function(c,o){var fn=o.filename;c[0]=31,c[1]=139,c[2]=8,c[8]=o.level<2?4:o.level==9?2:0,c[9]=3;if(o.mtime!=0)wbytes(c,4,Math.floor(new Date(o.mtime||Date.now())/1e3));if(fn){c[3]=8;for(var i=0;i<=fn.length;++i)c[i+10]=fn.charCodeAt(i)}};var gzs=function(d){if(d[0]!=31||d[1]!=139||d[2]!=8)err(6,"invalid gzip data");var flg=d[3];var st=10;if(flg&4)st+=d[10]|(d[11]<<8)+2;for(var zs=(flg>>3&1)+(flg>>4&1);zs>0;zs-=!d[st++]);return st+(flg&2)};var gzl=function(d){var l=d.length;return(d[l-4]|d[l-3]<<8|d[l-2]<<16|d[l-1]<<24)>>>0};var gzhl=function(o){return 10+(o.filename&&o.filename.length+1||0)};var zlh=function(c,o){var lv=o.level,fl=lv==0?0:lv<6?1:lv==9?3:2;c[0]=120,c[1]=fl<<6|(fl?32-2*fl:1)};var zlv=function(d){if((d[0]&15)!=8||d[0]>>>4>7||(d[0]<<8|d[1])%31)err(6,"invalid zlib data");if(d[1]&32)err(6,"invalid zlib data: preset dictionaries not supported")};function AsyncCmpStrm(opts,cb){if(!cb&&typeof opts=="function")cb=opts,opts={};this.ondata=cb;return opts}var Deflate=function(){function Deflate(opts,cb){if(!cb&&typeof opts=="function")cb=opts,opts={};this.ondata=cb;this.o=opts||{}}Deflate.prototype.p=function(c,f){this.ondata(dopt(c,this.o,0,0,!f),f)};Deflate.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(this.d)err(4);this.d=final;this.p(chunk,final||false)};return Deflate}();exports.Deflate=Deflate;var AsyncDeflate=function(){function AsyncDeflate(opts,cb){astrmify([bDflt,function(){return[astrm,Deflate]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Deflate(ev.data);onmessage=astrm(strm)},6)}return AsyncDeflate}();exports.AsyncDeflate=AsyncDeflate;function deflate(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt],function(ev){return pbf(deflateSync(ev.data[0],ev.data[1]))},0,cb)}exports.deflate=deflate;function deflateSync(data,opts){return dopt(data,opts||{},0,0)}exports.deflateSync=deflateSync;var Inflate=function(){function Inflate(cb){this.s={};this.p=new u8(0);this.ondata=cb}Inflate.prototype.e=function(c){if(!this.ondata)err(5);if(this.d)err(4);var l=this.p.length;var n=new u8(l+c.length);n.set(this.p),n.set(c,l),this.p=n};Inflate.prototype.c=function(final){this.d=this.s.i=final||false;var bts=this.s.b;var dt=inflt(this.p,this.o,this.s);this.ondata(slc(dt,bts,this.s.b),this.d);this.o=slc(dt,this.s.b-32768),this.s.b=this.o.length;this.p=slc(this.p,this.s.p/8|0),this.s.p&=7};Inflate.prototype.push=function(chunk,final){this.e(chunk),this.c(final)};return Inflate}();exports.Inflate=Inflate;var AsyncInflate=function(){function AsyncInflate(cb){this.ondata=cb;astrmify([bInflt,function(){return[astrm,Inflate]}],this,0,function(){var strm=new Inflate;onmessage=astrm(strm)},7)}return AsyncInflate}();exports.AsyncInflate=AsyncInflate;function inflate(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt],function(ev){return pbf(inflateSync(ev.data[0],gu8(ev.data[1])))},1,cb)}exports.inflate=inflate;function inflateSync(data,out){return inflt(data,out)}exports.inflateSync=inflateSync;var Gzip=function(){function Gzip(opts,cb){this.c=crc();this.l=0;this.v=1;Deflate.call(this,opts,cb)}Gzip.prototype.push=function(chunk,final){Deflate.prototype.push.call(this,chunk,final)};Gzip.prototype.p=function(c,f){this.c.p(c);this.l+=c.length;var raw=dopt(c,this.o,this.v&&gzhl(this.o),f&&8,!f);if(this.v)gzh(raw,this.o),this.v=0;if(f)wbytes(raw,raw.length-8,this.c.d()),wbytes(raw,raw.length-4,this.l);this.ondata(raw,f)};return Gzip}();exports.Gzip=Gzip;exports.Compress=Gzip;var AsyncGzip=function(){function AsyncGzip(opts,cb){astrmify([bDflt,gze,function(){return[astrm,Deflate,Gzip]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Gzip(ev.data);onmessage=astrm(strm)},8)}return AsyncGzip}();exports.AsyncGzip=AsyncGzip;exports.AsyncCompress=AsyncGzip;function gzip(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt,gze,function(){return[gzipSync]}],function(ev){return pbf(gzipSync(ev.data[0],ev.data[1]))},2,cb)}exports.gzip=gzip;exports.compress=gzip;function gzipSync(data,opts){if(!opts)opts={};var c=crc(),l=data.length;c.p(data);var d=dopt(data,opts,gzhl(opts),8),s=d.length;return gzh(d,opts),wbytes(d,s-8,c.d()),wbytes(d,s-4,l),d}exports.gzipSync=gzipSync;exports.compressSync=gzipSync;var Gunzip=function(){function Gunzip(cb){this.v=1;Inflate.call(this,cb)}Gunzip.prototype.push=function(chunk,final){Inflate.prototype.e.call(this,chunk);if(this.v){var s=this.p.length>3?gzs(this.p):4;if(s>=this.p.length&&!final)return;this.p=this.p.subarray(s),this.v=0}if(final){if(this.p.length<8)err(6,"invalid gzip data");this.p=this.p.subarray(0,-8)}Inflate.prototype.c.call(this,final)};return Gunzip}();exports.Gunzip=Gunzip;var AsyncGunzip=function(){function AsyncGunzip(cb){this.ondata=cb;astrmify([bInflt,guze,function(){return[astrm,Inflate,Gunzip]}],this,0,function(){var strm=new Gunzip;onmessage=astrm(strm)},9)}return AsyncGunzip}();exports.AsyncGunzip=AsyncGunzip;function gunzip(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt,guze,function(){return[gunzipSync]}],function(ev){return pbf(gunzipSync(ev.data[0]))},3,cb)}exports.gunzip=gunzip;function gunzipSync(data,out){return inflt(data.subarray(gzs(data),-8),out||new u8(gzl(data)))}exports.gunzipSync=gunzipSync;var Zlib=function(){function Zlib(opts,cb){this.c=adler();this.v=1;Deflate.call(this,opts,cb)}Zlib.prototype.push=function(chunk,final){Deflate.prototype.push.call(this,chunk,final)};Zlib.prototype.p=function(c,f){this.c.p(c);var raw=dopt(c,this.o,this.v&&2,f&&4,!f);if(this.v)zlh(raw,this.o),this.v=0;if(f)wbytes(raw,raw.length-4,this.c.d());this.ondata(raw,f)};return Zlib}();exports.Zlib=Zlib;var AsyncZlib=function(){function AsyncZlib(opts,cb){astrmify([bDflt,zle,function(){return[astrm,Deflate,Zlib]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Zlib(ev.data);onmessage=astrm(strm)},10)}return AsyncZlib}();exports.AsyncZlib=AsyncZlib;function zlib(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt,zle,function(){return[zlibSync]}],function(ev){return pbf(zlibSync(ev.data[0],ev.data[1]))},4,cb)}exports.zlib=zlib;function zlibSync(data,opts){if(!opts)opts={};var a=adler();a.p(data);var d=dopt(data,opts,2,4);return zlh(d,opts),wbytes(d,d.length-4,a.d()),d}exports.zlibSync=zlibSync;var Unzlib=function(){function Unzlib(cb){this.v=1;Inflate.call(this,cb)}Unzlib.prototype.push=function(chunk,final){Inflate.prototype.e.call(this,chunk);if(this.v){if(this.p.length<2&&!final)return;this.p=this.p.subarray(2),this.v=0}if(final){if(this.p.length<4)err(6,"invalid zlib data");this.p=this.p.subarray(0,-4)}Inflate.prototype.c.call(this,final)};return Unzlib}();exports.Unzlib=Unzlib;var AsyncUnzlib=function(){function AsyncUnzlib(cb){this.ondata=cb;astrmify([bInflt,zule,function(){return[astrm,Inflate,Unzlib]}],this,0,function(){var strm=new Unzlib;onmessage=astrm(strm)},11)}return AsyncUnzlib}();exports.AsyncUnzlib=AsyncUnzlib;function unzlib(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt,zule,function(){return[unzlibSync]}],function(ev){return pbf(unzlibSync(ev.data[0],gu8(ev.data[1])))},5,cb)}exports.unzlib=unzlib;function unzlibSync(data,out){return inflt((zlv(data),data.subarray(2,-4)),out)}exports.unzlibSync=unzlibSync;var Decompress=function(){function Decompress(cb){this.G=Gunzip;this.I=Inflate;this.Z=Unzlib;this.ondata=cb}Decompress.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(!this.s){if(this.p&&this.p.length){var n=new u8(this.p.length+chunk.length);n.set(this.p),n.set(chunk,this.p.length)}else this.p=chunk;if(this.p.length>2){var _this_1=this;var cb=function(){_this_1.ondata.apply(_this_1,arguments)};this.s=this.p[0]==31&&this.p[1]==139&&this.p[2]==8?new this.G(cb):(this.p[0]&15)!=8||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(cb):new this.Z(cb);this.s.push(this.p,final);this.p=null}}else this.s.push(chunk,final)};return Decompress}();exports.Decompress=Decompress;var AsyncDecompress=function(){function AsyncDecompress(cb){this.G=AsyncGunzip;this.I=AsyncInflate;this.Z=AsyncUnzlib;this.ondata=cb}AsyncDecompress.prototype.push=function(chunk,final){Decompress.prototype.push.call(this,chunk,final)};return AsyncDecompress}();exports.AsyncDecompress=AsyncDecompress;function decompress(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return data[0]==31&&data[1]==139&&data[2]==8?gunzip(data,opts,cb):(data[0]&15)!=8||data[0]>>4>7||(data[0]<<8|data[1])%31?inflate(data,opts,cb):unzlib(data,opts,cb)}exports.decompress=decompress;function decompressSync(data,out){return data[0]==31&&data[1]==139&&data[2]==8?gunzipSync(data,out):(data[0]&15)!=8||data[0]>>4>7||(data[0]<<8|data[1])%31?inflateSync(data,out):unzlibSync(data,out)}exports.decompressSync=decompressSync;var fltn=function(d,p,t,o){for(var k in d){var val=d[k],n=p+k,op=o;if(Array.isArray(val))op=mrg(o,val[1]),val=val[0];if(val instanceof u8)t[n]=[val,op];else{t[n+="/"]=[new u8(0),op];fltn(val,n,t,o)}}};var te=typeof TextEncoder!="undefined"&&new TextEncoder;var td=typeof TextDecoder!="undefined"&&new TextDecoder;var tds=0;try{td.decode(et,{stream:true});tds=1}catch(e){}var dutf8=function(d){for(var r="",i=0;;){var c=d[i++];var eb=(c>127)+(c>223)+(c>239);if(i+eb>d.length)return[r,slc(d,i-1)];if(!eb)r+=String.fromCharCode(c);else if(eb==3){c=((c&15)<<18|(d[i++]&63)<<12|(d[i++]&63)<<6|d[i++]&63)-65536,r+=String.fromCharCode(55296|c>>10,56320|c&1023)}else if(eb&1)r+=String.fromCharCode((c&31)<<6|d[i++]&63);else r+=String.fromCharCode((c&15)<<12|(d[i++]&63)<<6|d[i++]&63)}};var DecodeUTF8=function(){function DecodeUTF8(cb){this.ondata=cb;if(tds)this.t=new TextDecoder;else this.p=et}DecodeUTF8.prototype.push=function(chunk,final){if(!this.ondata)err(5);final=!!final;if(this.t){this.ondata(this.t.decode(chunk,{stream:true}),final);if(final){if(this.t.decode().length)err(8);this.t=null}return}if(!this.p)err(4);var dat=new u8(this.p.length+chunk.length);dat.set(this.p);dat.set(chunk,this.p.length);var _a=dutf8(dat),ch=_a[0],np=_a[1];if(final){if(np.length)err(8);this.p=null}else this.p=np;this.ondata(ch,final)};return DecodeUTF8}();exports.DecodeUTF8=DecodeUTF8;var EncodeUTF8=function(){function EncodeUTF8(cb){this.ondata=cb}EncodeUTF8.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(this.d)err(4);this.ondata(strToU8(chunk),this.d=final||false)};return EncodeUTF8}();exports.EncodeUTF8=EncodeUTF8;function strToU8(str,latin1){if(latin1){var ar_1=new u8(str.length);for(var i=0;i>1));var ai=0;var w=function(v){ar[ai++]=v};for(var i=0;iar.length){var n=new u8(ai+8+(l-i<<1));n.set(ar);ar=n}var c=str.charCodeAt(i);if(c<128||latin1)w(c);else if(c<2048)w(192|c>>6),w(128|c&63);else if(c>55295&&c<57344)c=65536+(c&1023<<10)|str.charCodeAt(++i)&1023,w(240|c>>18),w(128|c>>12&63),w(128|c>>6&63),w(128|c&63);else w(224|c>>12),w(128|c>>6&63),w(128|c&63)}return slc(ar,0,ai)}exports.strToU8=strToU8;function strFromU8(dat,latin1){if(latin1){var r="";for(var i=0;i65535)err(9);le+=l+4}}return le};var wzh=function(d,b,f,fn,u,c,ce,co){var fl=fn.length,ex=f.extra,col=co&&co.length;var exl=exfl(ex);wbytes(d,b,ce!=null?33639248:67324752),b+=4;if(ce!=null)d[b++]=20,d[b++]=f.os;d[b]=20,b+=2;d[b++]=f.flag<<1|(c==null&&8),d[b++]=u&&8;d[b++]=f.compression&255,d[b++]=f.compression>>8;var dt=new Date(f.mtime==null?Date.now():f.mtime),y=dt.getFullYear()-1980;if(y<0||y>119)err(10);wbytes(d,b,y<<25|dt.getMonth()+1<<21|dt.getDate()<<16|dt.getHours()<<11|dt.getMinutes()<<5|dt.getSeconds()>>>1),b+=4;if(c!=null){wbytes(d,b,f.crc);wbytes(d,b+4,c);wbytes(d,b+8,f.size)}wbytes(d,b+12,fl);wbytes(d,b+14,exl),b+=16;if(ce!=null){wbytes(d,b,col);wbytes(d,b+6,f.attrs);wbytes(d,b+10,ce),b+=14}d.set(fn,b);b+=fl;if(exl){for(var k in ex){var exf=ex[k],l=exf.length;wbytes(d,b,+k);wbytes(d,b+2,l);d.set(exf,b+4),b+=4+l}}if(col)d.set(co,b),b+=col;return b};var wzf=function(o,b,c,d,e){wbytes(o,b,101010256);wbytes(o,b+8,c);wbytes(o,b+10,c);wbytes(o,b+12,d);wbytes(o,b+16,e)};var ZipPassThrough=function(){function ZipPassThrough(filename){this.filename=filename;this.c=crc();this.size=0;this.compression=0}ZipPassThrough.prototype.process=function(chunk,final){this.ondata(null,chunk,final)};ZipPassThrough.prototype.push=function(chunk,final){if(!this.ondata)err(5);this.c.p(chunk);this.size+=chunk.length;if(final)this.crc=this.c.d();this.process(chunk,final||false)};return ZipPassThrough}();exports.ZipPassThrough=ZipPassThrough;var ZipDeflate=function(){function ZipDeflate(filename,opts){var _this_1=this;if(!opts)opts={};ZipPassThrough.call(this,filename);this.d=new Deflate(opts,function(dat,final){_this_1.ondata(null,dat,final)});this.compression=8;this.flag=dbf(opts.level)}ZipDeflate.prototype.process=function(chunk,final){try{this.d.push(chunk,final)}catch(e){this.ondata(e,null,final)}};ZipDeflate.prototype.push=function(chunk,final){ZipPassThrough.prototype.push.call(this,chunk,final)};return ZipDeflate}();exports.ZipDeflate=ZipDeflate;var AsyncZipDeflate=function(){function AsyncZipDeflate(filename,opts){var _this_1=this;if(!opts)opts={};ZipPassThrough.call(this,filename);this.d=new AsyncDeflate(opts,function(err,dat,final){_this_1.ondata(err,dat,final)});this.compression=8;this.flag=dbf(opts.level);this.terminate=this.d.terminate}AsyncZipDeflate.prototype.process=function(chunk,final){this.d.push(chunk,final)};AsyncZipDeflate.prototype.push=function(chunk,final){ZipPassThrough.prototype.push.call(this,chunk,final)};return AsyncZipDeflate}();exports.AsyncZipDeflate=AsyncZipDeflate;var Zip=function(){function Zip(cb){this.ondata=cb;this.u=[];this.d=1}Zip.prototype.add=function(file){var _this_1=this;if(!this.ondata)err(5);if(this.d&2)this.ondata(err(4+(this.d&1)*8,0,1),null,false);else{var f=strToU8(file.filename),fl_1=f.length;var com=file.comment,o=com&&strToU8(com);var u=fl_1!=file.filename.length||o&&com.length!=o.length;var hl_1=fl_1+exfl(file.extra)+30;if(fl_1>65535)this.ondata(err(11,0,1),null,false);var header=new u8(hl_1);wzh(header,0,file,f,u);var chks_1=[header];var pAll_1=function(){for(var _i=0,chks_2=chks_1;_i65535)cbl(err(11,0,1),null);if(!compression)cbl(null,file);else if(size<16e4){try{cbl(null,deflateSync(file,p))}catch(e){cbl(e,null)}}else term.push(deflate(file,p,cbl))};for(var i=0;i65535)err(11);var d=compression?deflateSync(file,p):file,l=d.length;var c=crc();c.p(file);files.push(mrg(p,{size:file.length,crc:c.d(),c:d,f:f,m:m,u:s!=fn.length||m&&com.length!=ms,o:o,compression:compression}));o+=30+s+exl+l;tot+=76+2*(s+exl)+(ms||0)+l}var out=new u8(tot+22),oe=o,cdl=tot-o;for(var i=0;i0){var len=Math.min(this.c,chunk.length);var toAdd=chunk.subarray(0,len);this.c-=len;if(this.d)this.d.push(toAdd,!this.c);else this.k[0].push(toAdd);chunk=chunk.subarray(len);if(chunk.length)return this.push(chunk,final)}else{var f=0,i=0,is=void 0,buf=void 0;if(!this.p.length)buf=chunk;else if(!chunk.length)buf=this.p;else{buf=new u8(this.p.length+chunk.length);buf.set(this.p),buf.set(chunk,this.p.length)}var l=buf.length,oc=this.c,add=oc&&this.d;var _loop_2=function(){var _a;var sig=b4(buf,i);if(sig==67324752){f=1,is=i;this_1.d=null;this_1.c=0;var bf=b2(buf,i+6),cmp_1=b2(buf,i+8),u=bf&2048,dd=bf&8,fnl=b2(buf,i+26),es=b2(buf,i+28);if(l>i+30+fnl+es){var chks_3=[];this_1.k.unshift(chks_3);f=2;var sc_1=b4(buf,i+18),su_1=b4(buf,i+22);var fn_1=strFromU8(buf.subarray(i+30,i+=30+fnl),!u);if(sc_1==4294967295){_a=dd?[-2]:z64e(buf,i),sc_1=_a[0],su_1=_a[1]}else if(dd)sc_1=-1;i+=es;this_1.c=sc_1;var d_1;var file_1={name:fn_1,compression:cmp_1,start:function(){if(!file_1.ondata)err(5);if(!sc_1)file_1.ondata(null,et,true);else{var ctr=_this_1.o[cmp_1];if(!ctr)file_1.ondata(err(14,"unknown compression type "+cmp_1,1),null,false);d_1=sc_1<0?new ctr(fn_1):new ctr(fn_1,sc_1,su_1);d_1.ondata=function(err,dat,final){file_1.ondata(err,dat,final)};for(var _i=0,chks_4=chks_3;_i=0)file_1.size=sc_1,file_1.originalSize=su_1;this_1.onfile(file_1)}return"break"}else if(oc){if(sig==134695760){is=i+=12+(oc==-2&&8),f=3,this_1.c=0;return"break"}else if(sig==33639248){is=i-=4,f=3,this_1.c=0;return"break"}}};var this_1=this;for(;i65558){cbd(err(13,0,1),null);return tAll}}var lft=b2(data,e+8);if(lft){var c=lft;var o=b4(data,e+16);var z=o==4294967295;if(z){e=b4(data,e-12);if(b4(data,e)!=101075792){cbd(err(13,0,1),null);return tAll}c=lft=b4(data,e+32);o=b4(data,e+48)}var fltr=opts&&opts.filter;var _loop_3=function(i){var _a=zh(data,o,z),c_1=_a[0],sc=_a[1],su=_a[2],fn=_a[3],no=_a[4],off=_a[5],b=slzh(data,off);o=no;var cbl=function(e,d){if(e){tAll();cbd(e,null)}else{if(d)files[fn]=d;if(!--lft)cbd(null,files)}};if(!fltr||fltr({name:fn,size:sc,originalSize:su,compression:c_1})){if(!c_1)cbl(null,slc(data,b,b+sc));else if(c_1==8){var infl=data.subarray(b,b+sc);if(sc<32e4){try{cbl(null,inflateSync(infl,new u8(su)))}catch(e){cbl(e,null)}}else term.push(inflate(infl,{size:su},cbl))}else cbl(err(14,"unknown compression type "+c_1,1),null)}else cbl(null,null)};for(var i=0;i65558)err(13)}var c=b2(data,e+8);if(!c)return{};var o=b4(data,e+16);var z=o==4294967295;if(z){e=b4(data,e-12);if(b4(data,e)!=101075792)err(13);c=b4(data,e+32);o=b4(data,e+48)}var fltr=opts&&opts.filter;for(var i=0;i>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],6:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||function(esize,ecode,edata,littleEndian){if(esize%16!=0){throw new Error("This does not appear to be a NIFTI extension")}this.esize=esize;this.ecode=ecode;this.edata=edata;this.littleEndian=littleEndian};nifti.NIFTIEXTENSION.prototype.toArrayBuffer=function(){let byteArray=new Uint8Array(this.esize);byteArray.set(this.data.buffer,8);let view=new DataView(byteArray.buffer);view.setInt32(0,this.esize,this.littleEndian);view.setInt32(4,this.ecode,this.littleEndian);return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTIEXTENSION}},{}],7:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.NIFTI1=nifti.NIFTI1||(typeof require!=="undefined"?require("./nifti1.js"):null);nifti.NIFTI2=nifti.NIFTI2||(typeof require!=="undefined"?require("./nifti2.js"):null);nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.Utils=nifti.Utils||(typeof require!=="undefined"?require("./utilities.js"):null);var fflate=fflate||(typeof require!=="undefined"?require("fflate"):null);nifti.isNIFTI1=function(data,isHdrImgPairOK=false){var buf,mag1,mag2,mag3;if(data.byteLength0&&this.sform_code0){for(ctrOut=0;ctrOut<3;ctrOut+=1){for(ctrIn=0;ctrIn<4;ctrIn+=1){index=280+(ctrOut*4+ctrIn)*4;this.affine[ctrOut][ctrIn]=nifti.Utils.getFloatAt(rawData,index,this.littleEndian)}}}this.affine[3][0]=0;this.affine[3][1]=0;this.affine[3][2]=0;this.affine[3][3]=1;this.intent_name=nifti.Utils.getStringAt(rawData,328,344);this.magic=nifti.Utils.getStringAt(rawData,344,348);this.isHDR=this.magic===nifti.NIFTI1.MAGIC_NUMBER2;if(rawData.byteLength>nifti.NIFTI1.MAGIC_COOKIE){this.extensionFlag[0]=nifti.Utils.getByteAt(rawData,348);this.extensionFlag[1]=nifti.Utils.getByteAt(rawData,348+1);this.extensionFlag[2]=nifti.Utils.getByteAt(rawData,348+2);this.extensionFlag[3]=nifti.Utils.getByteAt(rawData,348+3);if(this.extensionFlag[0]){this.extensions=nifti.Utils.getExtensionsAt(rawData,this.getExtensionLocation(),this.littleEndian,this.vox_offset);this.extensionSize=this.extensions[0].esize;this.extensionCode=this.extensions[0].ecode}}};nifti.NIFTI1.prototype.toFormattedString=function(){var fmt=nifti.Utils.formatNumber,string="";string+="Dim Info = "+this.dim_info+"\n";string+="Image Dimensions (1-8): "+this.dims[0]+", "+this.dims[1]+", "+this.dims[2]+", "+this.dims[3]+", "+this.dims[4]+", "+this.dims[5]+", "+this.dims[6]+", "+this.dims[7]+"\n";string+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+"\n";string+="Intent Code = "+this.intent_code+"\n";string+="Datatype = "+this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+")\n";string+="Bits Per Voxel = "+this.numBitsPerVoxel+"\n";string+="Slice Start = "+this.slice_start+"\n";string+="Voxel Dimensions (1-8): "+fmt(this.pixDims[0])+", "+fmt(this.pixDims[1])+", "+fmt(this.pixDims[2])+", "+fmt(this.pixDims[3])+", "+fmt(this.pixDims[4])+", "+fmt(this.pixDims[5])+", "+fmt(this.pixDims[6])+", "+fmt(this.pixDims[7])+"\n";string+="Image Offset = "+this.vox_offset+"\n";string+="Data Scale: Slope = "+fmt(this.scl_slope)+" Intercept = "+fmt(this.scl_inter)+"\n";string+="Slice End = "+this.slice_end+"\n";string+="Slice Code = "+this.slice_code+"\n";string+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(nifti.NIFTI1.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(nifti.NIFTI1.TEMPORAL_UNITS_MASK&this.xyzt_units)+")\n";string+="Display Range: Max = "+fmt(this.cal_max)+" Min = "+fmt(this.cal_min)+"\n";string+="Slice Duration = "+this.slice_duration+"\n";string+="Time Axis Shift = "+this.toffset+"\n";string+='Description: "'+this.description+'"\n';string+='Auxiliary File: "'+this.aux_file+'"\n';string+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+")\n";string+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+")\n";string+="Quaternion Parameters: "+"b = "+fmt(this.quatern_b)+" "+"c = "+fmt(this.quatern_c)+" "+"d = "+fmt(this.quatern_d)+"\n";string+="Quaternion Offsets: "+"x = "+this.qoffset_x+" "+"y = "+this.qoffset_y+" "+"z = "+this.qoffset_z+"\n";string+="S-Form Parameters X: "+fmt(this.affine[0][0])+", "+fmt(this.affine[0][1])+", "+fmt(this.affine[0][2])+", "+fmt(this.affine[0][3])+"\n";string+="S-Form Parameters Y: "+fmt(this.affine[1][0])+", "+fmt(this.affine[1][1])+", "+fmt(this.affine[1][2])+", "+fmt(this.affine[1][3])+"\n";string+="S-Form Parameters Z: "+fmt(this.affine[2][0])+", "+fmt(this.affine[2][1])+", "+fmt(this.affine[2][2])+", "+fmt(this.affine[2][3])+"\n";string+='Intent Name: "'+this.intent_name+'"\n';if(this.extensionFlag[0]){string+="Extension: Size = "+this.extensionSize+" Code = "+this.extensionCode+"\n"}return string};nifti.NIFTI1.prototype.getDatatypeCodeString=function(code){if(code===nifti.NIFTI1.TYPE_UINT8){return"1-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_INT16){return"2-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_INT32){return"4-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_FLOAT32){return"4-Byte Float"}else if(code===nifti.NIFTI1.TYPE_FLOAT64){return"8-Byte Float"}else if(code===nifti.NIFTI1.TYPE_RGB24){return"RGB"}else if(code===nifti.NIFTI1.TYPE_INT8){return"1-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_UINT16){return"2-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_UINT32){return"4-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_INT64){return"8-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_UINT64){return"8-Byte Unsigned Integer"}else{return"Unknown"}};nifti.NIFTI1.prototype.getTransformCodeString=function(code){if(code===nifti.NIFTI1.XFORM_SCANNER_ANAT){return"Scanner"}else if(code===nifti.NIFTI1.XFORM_ALIGNED_ANAT){return"Aligned"}else if(code===nifti.NIFTI1.XFORM_TALAIRACH){return"Talairach"}else if(code===nifti.NIFTI1.XFORM_MNI_152){return"MNI"}else{return"Unknown"}};nifti.NIFTI1.prototype.getUnitsCodeString=function(code){if(code===nifti.NIFTI1.UNITS_METER){return"Meters"}else if(code===nifti.NIFTI1.UNITS_MM){return"Millimeters"}else if(code===nifti.NIFTI1.UNITS_MICRON){return"Microns"}else if(code===nifti.NIFTI1.UNITS_SEC){return"Seconds"}else if(code===nifti.NIFTI1.UNITS_MSEC){return"Milliseconds"}else if(code===nifti.NIFTI1.UNITS_USEC){return"Microseconds"}else if(code===nifti.NIFTI1.UNITS_HZ){return"Hz"}else if(code===nifti.NIFTI1.UNITS_PPM){return"PPM"}else if(code===nifti.NIFTI1.UNITS_RADS){return"Rads"}else{return"Unknown"}};nifti.NIFTI1.prototype.getQformMat=function(){return this.convertNiftiQFormToNiftiSForm(this.quatern_b,this.quatern_c,this.quatern_d,this.qoffset_x,this.qoffset_y,this.qoffset_z,this.pixDims[1],this.pixDims[2],this.pixDims[3],this.pixDims[0])};nifti.NIFTI1.prototype.convertNiftiQFormToNiftiSForm=function(qb,qc,qd,qx,qy,qz,dx,dy,dz,qfac){var R=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],a,b=qb,c=qc,d=qd,xd,yd,zd;R[3][0]=R[3][1]=R[3][2]=0;R[3][3]=1;a=1-(b*b+c*c+d*d);if(a<1e-7){a=1/Math.sqrt(b*b+c*c+d*d);b*=a;c*=a;d*=a;a=0}else{a=Math.sqrt(a)}xd=dx>0?dx:1;yd=dy>0?dy:1;zd=dz>0?dz:1;if(qfac<0){zd=-zd}R[0][0]=(a*a+b*b-c*c-d*d)*xd;R[0][1]=2*(b*c-a*d)*yd;R[0][2]=2*(b*d+a*c)*zd;R[1][0]=2*(b*c+a*d)*xd;R[1][1]=(a*a+c*c-b*b-d*d)*yd;R[1][2]=2*(c*d-a*b)*zd;R[2][0]=2*(b*d-a*c)*xd;R[2][1]=2*(c*d+a*b)*yd;R[2][2]=(a*a+d*d-c*c-b*b)*zd;R[0][3]=qx;R[1][3]=qy;R[2][3]=qz;return R};nifti.NIFTI1.prototype.convertNiftiSFormToNEMA=function(R){var xi,xj,xk,yi,yj,yk,zi,zj,zk,val,detQ,detP,i,j,k,p,q,r,ibest,jbest,kbest,pbest,qbest,rbest,M,vbest,Q,P,iChar,jChar,kChar,iSense,jSense,kSense;k=0;Q=[[0,0,0],[0,0,0],[0,0,0]];P=[[0,0,0],[0,0,0],[0,0,0]];xi=R[0][0];xj=R[0][1];xk=R[0][2];yi=R[1][0];yj=R[1][1];yk=R[1][2];zi=R[2][0];zj=R[2][1];zk=R[2][2];val=Math.sqrt(xi*xi+yi*yi+zi*zi);if(val===0){return null}xi/=val;yi/=val;zi/=val;val=Math.sqrt(xj*xj+yj*yj+zj*zj);if(val===0){return null}xj/=val;yj/=val;zj/=val;val=xi*xj+yi*yj+zi*zj;if(Math.abs(val)>1e-4){xj-=val*xi;yj-=val*yi;zj-=val*zi;val=Math.sqrt(xj*xj+yj*yj+zj*zj);if(val===0){return null}xj/=val;yj/=val;zj/=val}val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){xk=yi*zj-zi*yj;yk=zi*xj-zj*xi;zk=xi*yj-yi*xj}else{xk/=val;yk/=val;zk/=val}val=xi*xk+yi*yk+zi*zk;if(Math.abs(val)>1e-4){xk-=val*xi;yk-=val*yi;zk-=val*zi;val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){return null}xk/=val;yk/=val;zk/=val}val=xj*xk+yj*yk+zj*zk;if(Math.abs(val)>1e-4){xk-=val*xj;yk-=val*yj;zk-=val*zj;val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){return null}xk/=val;yk/=val;zk/=val}Q[0][0]=xi;Q[0][1]=xj;Q[0][2]=xk;Q[1][0]=yi;Q[1][1]=yj;Q[1][2]=yk;Q[2][0]=zi;Q[2][1]=zj;Q[2][2]=zk;detQ=this.nifti_mat33_determ(Q);if(detQ===0){return null}vbest=-666;ibest=pbest=qbest=rbest=1;jbest=2;kbest=3;for(i=1;i<=3;i+=1){for(j=1;j<=3;j+=1){if(i!==j){for(k=1;k<=3;k+=1){if(!(i===k||j===k)){P[0][0]=P[0][1]=P[0][2]=P[1][0]=P[1][1]=P[1][2]=P[2][0]=P[2][1]=P[2][2]=0;for(p=-1;p<=1;p+=2){for(q=-1;q<=1;q+=2){for(r=-1;r<=1;r+=2){P[0][i-1]=p;P[1][j-1]=q;P[2][k-1]=r;detP=this.nifti_mat33_determ(P);if(detP*detQ>0){M=this.nifti_mat33_mul(P,Q);val=M[0][0]+M[1][1]+M[2][2];if(val>vbest){vbest=val;ibest=i;jbest=j;kbest=k;pbest=p;qbest=q;rbest=r}}}}}}}}}}iChar=jChar=kChar=iSense=jSense=kSense=0;switch(ibest*pbest){case 1:iChar="X";iSense="+";break;case-1:iChar="X";iSense="-";break;case 2:iChar="Y";iSense="+";break;case-2:iChar="Y";iSense="-";break;case 3:iChar="Z";iSense="+";break;case-3:iChar="Z";iSense="-";break}switch(jbest*qbest){case 1:jChar="X";jSense="+";break;case-1:jChar="X";jSense="-";break;case 2:jChar="Y";jSense="+";break;case-2:jChar="Y";jSense="-";break;case 3:jChar="Z";jSense="+";break;case-3:jChar="Z";jSense="-";break}switch(kbest*rbest){case 1:kChar="X";kSense="+";break;case-1:kChar="X";kSense="-";break;case 2:kChar="Y";kSense="+";break;case-2:kChar="Y";kSense="-";break;case 3:kChar="Z";kSense="+";break;case-3:kChar="Z";kSense="-";break}return iChar+jChar+kChar+iSense+jSense+kSense};nifti.NIFTI1.prototype.nifti_mat33_mul=function(A,B){var C=[[0,0,0],[0,0,0],[0,0,0]],i,j;for(i=0;i<3;i+=1){for(j=0;j<3;j+=1){C[i][j]=A[i][0]*B[0][j]+A[i][1]*B[1][j]+A[i][2]*B[2][j]}}return C};nifti.NIFTI1.prototype.nifti_mat33_determ=function(R){var r11,r12,r13,r21,r22,r23,r31,r32,r33;r11=R[0][0];r12=R[0][1];r13=R[0][2];r21=R[1][0];r22=R[1][1];r23=R[1][2];r31=R[2][0];r32=R[2][1];r33=R[2][2];return r11*r22*r33-r11*r32*r23-r21*r12*r33+r21*r32*r13+r31*r12*r23-r31*r22*r13};nifti.NIFTI1.prototype.getExtensionLocation=function(){return nifti.NIFTI1.MAGIC_COOKIE+4};nifti.NIFTI1.prototype.getExtensionSize=function(data){return nifti.Utils.getIntAt(data,this.getExtensionLocation(),this.littleEndian)};nifti.NIFTI1.prototype.getExtensionCode=function(data){return nifti.Utils.getIntAt(data,this.getExtensionLocation()+4,this.littleEndian)};nifti.NIFTI1.prototype.addExtension=function(extension,index=-1){if(index==-1){this.extensions.push(extension)}else{this.extensions.splice(index,0,extension)}this.vox_offset+=extension.esize};nifti.NIFTI1.prototype.removeExtension=function(index){let extension=this.extensions[index];if(extension){this.vox_offset-=extension.esize}this.extensions.splice(index,1)};nifti.NIFTI1.prototype.toArrayBuffer=function(includeExtensions=false){const SHORT_SIZE=2;const FLOAT32_SIZE=4;let byteSize=348+4;if(includeExtensions){for(let extension of this.extensions){byteSize+=extension.esize}}let byteArray=new Uint8Array(byteSize);let view=new DataView(byteArray.buffer);view.setInt32(0,348,this.littleEndian);view.setUint8(39,this.dim_info);for(let i=0;i<8;i++){view.setUint16(40+SHORT_SIZE*i,this.dims[i],this.littleEndian)}view.setFloat32(56,this.intent_p1,this.littleEndian);view.setFloat32(60,this.intent_p2,this.littleEndian);view.setFloat32(64,this.intent_p3,this.littleEndian);view.setInt16(68,this.intent_code,this.littleEndian);view.setInt16(70,this.datatypeCode,this.littleEndian);view.setInt16(72,this.numBitsPerVoxel,this.littleEndian);view.setInt16(74,this.slice_start,this.littleEndian);for(let i=0;i<8;i++){view.setFloat32(76+FLOAT32_SIZE*i,this.pixDims[i],this.littleEndian)}view.setFloat32(108,this.vox_offset,this.littleEndian);view.setFloat32(112,this.scl_slope,this.littleEndian);view.setFloat32(116,this.scl_inter,this.littleEndian);view.setInt16(120,this.slice_end,this.littleEndian);view.setUint8(122,this.slice_code);view.setUint8(123,this.xyzt_units);view.setFloat32(124,this.cal_max,this.littleEndian);view.setFloat32(128,this.cal_min,this.littleEndian);view.setFloat32(132,this.slice_duration,this.littleEndian);view.setFloat32(136,this.toffset,this.littleEndian);byteArray.set(Buffer.from(this.description),148);byteArray.set(Buffer.from(this.aux_file),228);view.setInt16(252,this.qform_code,this.littleEndian);view.setInt16(254,this.sform_code,this.littleEndian);view.setFloat32(256,this.quatern_b,this.littleEndian);view.setFloat32(260,this.quatern_c,this.littleEndian);view.setFloat32(264,this.quatern_d,this.littleEndian);view.setFloat32(268,this.qoffset_x,this.littleEndian);view.setFloat32(272,this.qoffset_y,this.littleEndian);view.setFloat32(276,this.qoffset_z,this.littleEndian);const flattened=this.affine.flat();for(let i=0;i<12;i++){view.setFloat32(280+FLOAT32_SIZE*i,flattened[i],this.littleEndian)}byteArray.set(Buffer.from(this.intent_name),328);byteArray.set(Buffer.from(this.magic),344);if(includeExtensions){byteArray.set(Uint8Array.from([1,0,0,0]),348);let extensionByteIndex=this.getExtensionLocation();for(const extension of this.extensions){view.setInt32(extensionByteIndex,extension.esize,extension.littleEndian);view.setInt32(extensionByteIndex+4,extension.ecode,extension.littleEndian);byteArray.set(new Uint8Array(extension.edata),extensionByteIndex+8);extensionByteIndex+=extension.esize}}else{byteArray.set(new Uint8Array(4).fill(0),348)}return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTI1}}).call(this)}).call(this,require("buffer").Buffer)},{"./nifti-extension.js":6,"./utilities.js":10,buffer:2}],9:[function(require,module,exports){(function(Buffer){(function(){"use strict";var nifti=nifti||{};nifti.Utils=nifti.Utils||(typeof require!=="undefined"?require("./utilities.js"):null);nifti.NIFTI1=nifti.NIFTI1||(typeof require!=="undefined"?require("./nifti1.js"):null);nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.NIFTI2=nifti.NIFTI2||function(){this.littleEndian=false;this.dim_info=0;this.dims=[];this.intent_p1=0;this.intent_p2=0;this.intent_p3=0;this.intent_code=0;this.datatypeCode=0;this.numBitsPerVoxel=0;this.slice_start=0;this.slice_end=0;this.slice_code=0;this.pixDims=[];this.vox_offset=0;this.scl_slope=1;this.scl_inter=0;this.xyzt_units=0;this.cal_max=0;this.cal_min=0;this.slice_duration=0;this.toffset=0;this.description="";this.aux_file="";this.intent_name="";this.qform_code=0;this.sform_code=0;this.quatern_b=0;this.quatern_c=0;this.quatern_d=0;this.qoffset_x=0;this.qoffset_y=0;this.qoffset_z=0;this.affine=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];this.magic=0;this.extensionFlag=[0,0,0,0];this.extensions=[]};nifti.NIFTI2.MAGIC_COOKIE=540;nifti.NIFTI2.MAGIC_NUMBER_LOCATION=4;nifti.NIFTI2.MAGIC_NUMBER=[110,43,50,0,13,10,26,10];nifti.NIFTI2.MAGIC_NUMBER2=[110,105,50,0,13,10,26,10];nifti.NIFTI2.prototype.readHeader=function(data){var rawData=new DataView(data),magicCookieVal=nifti.Utils.getIntAt(rawData,0,this.littleEndian),ctr,ctrOut,ctrIn,index,array;if(magicCookieVal!==nifti.NIFTI2.MAGIC_COOKIE){this.littleEndian=true;magicCookieVal=nifti.Utils.getIntAt(rawData,0,this.littleEndian)}if(magicCookieVal!==nifti.NIFTI2.MAGIC_COOKIE){throw new Error("This does not appear to be a NIFTI file!")}this.magic=nifti.Utils.getStringAt(rawData,4,12);this.datatypeCode=nifti.Utils.getShortAt(rawData,12,this.littleEndian);this.numBitsPerVoxel=nifti.Utils.getShortAt(rawData,14,this.littleEndian);for(ctr=0;ctr<8;ctr+=1){index=16+ctr*8;this.dims[ctr]=nifti.Utils.getLongAt(rawData,index,this.littleEndian)}this.intent_p1=nifti.Utils.getDoubleAt(rawData,80,this.littleEndian);this.intent_p2=nifti.Utils.getDoubleAt(rawData,88,this.littleEndian);this.intent_p3=nifti.Utils.getDoubleAt(rawData,96,this.littleEndian);for(ctr=0;ctr<8;ctr+=1){index=104+ctr*8;this.pixDims[ctr]=nifti.Utils.getDoubleAt(rawData,index,this.littleEndian)}this.vox_offset=nifti.Utils.getLongAt(rawData,168,this.littleEndian);this.scl_slope=nifti.Utils.getDoubleAt(rawData,176,this.littleEndian);this.scl_inter=nifti.Utils.getDoubleAt(rawData,184,this.littleEndian);this.cal_max=nifti.Utils.getDoubleAt(rawData,192,this.littleEndian);this.cal_min=nifti.Utils.getDoubleAt(rawData,200,this.littleEndian);this.slice_duration=nifti.Utils.getDoubleAt(rawData,208,this.littleEndian);this.toffset=nifti.Utils.getDoubleAt(rawData,216,this.littleEndian);this.slice_start=nifti.Utils.getLongAt(rawData,224,this.littleEndian);this.slice_end=nifti.Utils.getLongAt(rawData,232,this.littleEndian);this.description=nifti.Utils.getStringAt(rawData,240,240+80);this.aux_file=nifti.Utils.getStringAt(rawData,320,320+24);this.qform_code=nifti.Utils.getIntAt(rawData,344,this.littleEndian);this.sform_code=nifti.Utils.getIntAt(rawData,348,this.littleEndian);this.quatern_b=nifti.Utils.getDoubleAt(rawData,352,this.littleEndian);this.quatern_c=nifti.Utils.getDoubleAt(rawData,360,this.littleEndian);this.quatern_d=nifti.Utils.getDoubleAt(rawData,368,this.littleEndian);this.qoffset_x=nifti.Utils.getDoubleAt(rawData,376,this.littleEndian);this.qoffset_y=nifti.Utils.getDoubleAt(rawData,384,this.littleEndian);this.qoffset_z=nifti.Utils.getDoubleAt(rawData,392,this.littleEndian);for(ctrOut=0;ctrOut<3;ctrOut+=1){for(ctrIn=0;ctrIn<4;ctrIn+=1){index=400+(ctrOut*4+ctrIn)*8;this.affine[ctrOut][ctrIn]=nifti.Utils.getDoubleAt(rawData,index,this.littleEndian)}}this.affine[3][0]=0;this.affine[3][1]=0;this.affine[3][2]=0;this.affine[3][3]=1;this.slice_code=nifti.Utils.getIntAt(rawData,496,this.littleEndian);this.xyzt_units=nifti.Utils.getIntAt(rawData,500,this.littleEndian);this.intent_code=nifti.Utils.getIntAt(rawData,504,this.littleEndian);this.intent_name=nifti.Utils.getStringAt(rawData,508,508+16);this.dim_info=nifti.Utils.getByteAt(rawData,524);if(rawData.byteLength>nifti.NIFTI2.MAGIC_COOKIE){this.extensionFlag[0]=nifti.Utils.getByteAt(rawData,540);this.extensionFlag[1]=nifti.Utils.getByteAt(rawData,540+1);this.extensionFlag[2]=nifti.Utils.getByteAt(rawData,540+2);this.extensionFlag[3]=nifti.Utils.getByteAt(rawData,540+3);if(this.extensionFlag[0]){this.extensions=nifti.Utils.getExtensionsAt(rawData,this.getExtensionLocation(),this.littleEndian,this.vox_offset);this.extensionSize=this.extensions[0].esize;this.extensionCode=this.extensions[0].ecode}}};nifti.NIFTI2.prototype.toFormattedString=function(){var fmt=nifti.Utils.formatNumber,string="";string+="Datatype = "+ +this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+")\n";string+="Bits Per Voxel = "+" = "+this.numBitsPerVoxel+"\n";string+="Image Dimensions"+" (1-8): "+this.dims[0]+", "+this.dims[1]+", "+this.dims[2]+", "+this.dims[3]+", "+this.dims[4]+", "+this.dims[5]+", "+this.dims[6]+", "+this.dims[7]+"\n";string+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+"\n";string+="Voxel Dimensions (1-8): "+fmt(this.pixDims[0])+", "+fmt(this.pixDims[1])+", "+fmt(this.pixDims[2])+", "+fmt(this.pixDims[3])+", "+fmt(this.pixDims[4])+", "+fmt(this.pixDims[5])+", "+fmt(this.pixDims[6])+", "+fmt(this.pixDims[7])+"\n";string+="Image Offset = "+this.vox_offset+"\n";string+="Data Scale: Slope = "+fmt(this.scl_slope)+" Intercept = "+fmt(this.scl_inter)+"\n";string+="Display Range: Max = "+fmt(this.cal_max)+" Min = "+fmt(this.cal_min)+"\n";string+="Slice Duration = "+this.slice_duration+"\n";string+="Time Axis Shift = "+this.toffset+"\n";string+="Slice Start = "+this.slice_start+"\n";string+="Slice End = "+this.slice_end+"\n";string+='Description: "'+this.description+'"\n';string+='Auxiliary File: "'+this.aux_file+'"\n';string+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+")\n";string+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+")\n";string+="Quaternion Parameters: "+"b = "+fmt(this.quatern_b)+" "+"c = "+fmt(this.quatern_c)+" "+"d = "+fmt(this.quatern_d)+"\n";string+="Quaternion Offsets: "+"x = "+this.qoffset_x+" "+"y = "+this.qoffset_y+" "+"z = "+this.qoffset_z+"\n";string+="S-Form Parameters X: "+fmt(this.affine[0][0])+", "+fmt(this.affine[0][1])+", "+fmt(this.affine[0][2])+", "+fmt(this.affine[0][3])+"\n";string+="S-Form Parameters Y: "+fmt(this.affine[1][0])+", "+fmt(this.affine[1][1])+", "+fmt(this.affine[1][2])+", "+fmt(this.affine[1][3])+"\n";string+="S-Form Parameters Z: "+fmt(this.affine[2][0])+", "+fmt(this.affine[2][1])+", "+fmt(this.affine[2][2])+", "+fmt(this.affine[2][3])+"\n";string+="Slice Code = "+this.slice_code+"\n";string+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(nifti.NIFTI1.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(nifti.NIFTI1.TEMPORAL_UNITS_MASK&this.xyzt_units)+")\n";string+="Intent Code = "+this.intent_code+"\n";string+='Intent Name: "'+this.intent_name+'"\n';string+="Dim Info = "+this.dim_info+"\n";return string};nifti.NIFTI2.prototype.getExtensionLocation=function(){return nifti.NIFTI2.MAGIC_COOKIE+4};nifti.NIFTI2.prototype.getExtensionSize=nifti.NIFTI1.prototype.getExtensionSize;nifti.NIFTI2.prototype.getExtensionCode=nifti.NIFTI1.prototype.getExtensionCode;nifti.NIFTI2.prototype.addExtension=nifti.NIFTI1.prototype.addExtension;nifti.NIFTI2.prototype.removeExtension=nifti.NIFTI1.prototype.removeExtension;nifti.NIFTI2.prototype.getDatatypeCodeString=nifti.NIFTI1.prototype.getDatatypeCodeString;nifti.NIFTI2.prototype.getTransformCodeString=nifti.NIFTI1.prototype.getTransformCodeString;nifti.NIFTI2.prototype.getUnitsCodeString=nifti.NIFTI1.prototype.getUnitsCodeString;nifti.NIFTI2.prototype.getQformMat=nifti.NIFTI1.prototype.getQformMat;nifti.NIFTI2.prototype.convertNiftiQFormToNiftiSForm=nifti.NIFTI1.prototype.convertNiftiQFormToNiftiSForm;nifti.NIFTI2.prototype.convertNiftiSFormToNEMA=nifti.NIFTI1.prototype.convertNiftiSFormToNEMA;nifti.NIFTI2.prototype.nifti_mat33_mul=nifti.NIFTI1.prototype.nifti_mat33_mul;nifti.NIFTI2.prototype.nifti_mat33_determ=nifti.NIFTI1.prototype.nifti_mat33_determ;nifti.NIFTI2.prototype.toArrayBuffer=function(includeExtensions=false){const INT64_SIZE=8;const DOUBLE_SIZE=8;let byteSize=540+4;if(includeExtensions){for(let extension of this.extensions){byteSize+=extension.esize}}let byteArray=new Uint8Array(byteSize);let view=new DataView(byteArray.buffer);view.setInt32(0,540,this.littleEndian);byteArray.set(Buffer.from(this.magic),4);view.setInt16(12,this.datatypeCode,this.littleEndian);view.setInt16(14,this.numBitsPerVoxel,this.littleEndian);for(let i=0;i<8;i++){view.setBigInt64(16+INT64_SIZE*i,BigInt(this.dims[i]),this.littleEndian)}view.setFloat64(80,this.intent_p1,this.littleEndian);view.setFloat64(88,this.intent_p2,this.littleEndian);view.setFloat64(96,this.intent_p3,this.littleEndian);for(let i=0;i<8;i++){view.setFloat64(104+DOUBLE_SIZE*i,this.pixDims[i],this.littleEndian)}view.setBigInt64(168,BigInt(this.vox_offset),this.littleEndian);view.setFloat64(176,this.scl_slope,this.littleEndian);view.setFloat64(184,this.scl_inter,this.littleEndian);view.setFloat64(192,this.cal_max,this.littleEndian);view.setFloat64(200,this.cal_min,this.littleEndian);view.setFloat64(208,this.slice_duration,this.littleEndian);view.setFloat64(216,this.toffset,this.littleEndian);view.setBigInt64(224,BigInt(this.slice_start),this.littleEndian);view.setBigInt64(232,BigInt(this.slice_end),this.littleEndian);byteArray.set(Buffer.from(this.description),240);byteArray.set(Buffer.from(this.aux_file),320);view.setInt32(344,this.qform_code,this.littleEndian);view.setInt32(348,this.sform_code,this.littleEndian);view.setFloat64(352,this.quatern_b,this.littleEndian);view.setFloat64(360,this.quatern_c,this.littleEndian);view.setFloat64(368,this.quatern_d,this.littleEndian);view.setFloat64(376,this.qoffset_x,this.littleEndian);view.setFloat64(384,this.qoffset_y,this.littleEndian);view.setFloat64(392,this.qoffset_z,this.littleEndian);const flattened=this.affine.flat();for(let i=0;i<12;i++){view.setFloat64(400+DOUBLE_SIZE*i,flattened[i],this.littleEndian)}view.setInt32(496,this.slice_code,this.littleEndian);view.setInt32(500,this.xyzt_units,this.littleEndian);view.setInt32(504,this.intent_code,this.littleEndian);byteArray.set(Buffer.from(this.intent_name),508);view.setUint8(524,this.dim_info);if(includeExtensions){byteArray.set(Uint8Array.from([1,0,0,0]),540);let extensionByteIndex=this.getExtensionLocation();for(const extension of this.extensions){view.setInt32(extensionByteIndex,extension.esize,extension.littleEndian);view.setInt32(extensionByteIndex+4,extension.ecode,extension.littleEndian);byteArray.set(new Uint8Array(extension.edata),extensionByteIndex+8);extensionByteIndex+=extension.esize}}else{byteArray.set(new Uint8Array(4).fill(0),540)}return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTI2}}).call(this)}).call(this,require("buffer").Buffer)},{"./nifti-extension.js":6,"./nifti1.js":8,"./utilities.js":10,buffer:2}],10:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.Utils=nifti.Utils||{};nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.Utils.crcTable=null;nifti.Utils.GUNZIP_MAGIC_COOKIE1=31;nifti.Utils.GUNZIP_MAGIC_COOKIE2=139;nifti.Utils.getStringAt=function(data,start,end){var str="",ctr,ch;for(ctr=start;ctr=0;ctr--){value=value*256+array[ctr]}return value};nifti.Utils.getExtensionsAt=function(data,start,littleEndian,voxOffset){let extensions=[];let extensionByteIndex=start;while(extensionByteIndexvoxOffset){extensionLittleEndian=!extensionLittleEndian;esize=nifti.Utils.getIntAt(data,extensionByteIndex,extensionLittleEndian);if(esize+extensionByteIndex>voxOffset){throw new Error("This does not appear to be a valid NIFTI extension")}}if(esize%16!=0){throw new Error("This does not appear to be a NIFTI extension")}let ecode=nifti.Utils.getIntAt(data,extensionByteIndex+4,extensionLittleEndian);let edata=data.buffer.slice(extensionByteIndex+8,extensionByteIndex+esize);console.log("extensionByteIndex: "+(extensionByteIndex+8)+" esize: "+esize);console.log(edata);let extension=new nifti.NIFTIEXTENSION(esize,ecode,edata,extensionLittleEndian);extensions.push(extension);extensionByteIndex+=esize}return extensions};nifti.Utils.toArrayBuffer=function(buffer){var ab,view,i;ab=new ArrayBuffer(buffer.length);view=new Uint8Array(ab);for(i=0;i>>1:c>>>1}crcTable[n]=c}return crcTable};nifti.Utils.crc32=function(dataView){var crcTable=nifti.Utils.crcTable||(nifti.Utils.crcTable=nifti.Utils.makeCRCTable());var crc=0^-1;for(var i=0;i>>8^crcTable[(crc^dataView.getUint8(i))&255]}return(crc^-1)>>>0};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.Utils}},{"./nifti-extension.js":6}]},{},[7])(7)}); \ No newline at end of file +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.nifti=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;var i;for(i=0;i>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;ilen2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],2:[function(require,module,exports){(function(Buffer){(function(){"use strict";var base64=require("base64-js");var ieee754=require("ieee754");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;var K_MAX_LENGTH=2147483647;exports.kMaxLength=K_MAX_LENGTH;Buffer.TYPED_ARRAY_SUPPORT=typedArraySupport();if(!Buffer.TYPED_ARRAY_SUPPORT&&typeof console!=="undefined"&&typeof console.error==="function"){console.error("This browser lacks typed array (Uint8Array) support which is required by "+"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.")}function typedArraySupport(){try{var arr=new Uint8Array(1);arr.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}};return arr.foo()===42}catch(e){return false}}Object.defineProperty(Buffer.prototype,"parent",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.buffer}});Object.defineProperty(Buffer.prototype,"offset",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.byteOffset}});function createBuffer(length){if(length>K_MAX_LENGTH){throw new RangeError('The value "'+length+'" is invalid for option "size"')}var buf=new Uint8Array(length);buf.__proto__=Buffer.prototype;return buf}function Buffer(arg,encodingOrOffset,length){if(typeof arg==="number"){if(typeof encodingOrOffset==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return allocUnsafe(arg)}return from(arg,encodingOrOffset,length)}if(typeof Symbol!=="undefined"&&Symbol.species!=null&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true,enumerable:false,writable:false})}Buffer.poolSize=8192;function from(value,encodingOrOffset,length){if(typeof value==="string"){return fromString(value,encodingOrOffset)}if(ArrayBuffer.isView(value)){return fromArrayLike(value)}if(value==null){throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}if(isInstance(value,ArrayBuffer)||value&&isInstance(value.buffer,ArrayBuffer)){return fromArrayBuffer(value,encodingOrOffset,length)}if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var valueOf=value.valueOf&&value.valueOf();if(valueOf!=null&&valueOf!==value){return Buffer.from(valueOf,encodingOrOffset,length)}var b=fromObject(value);if(b)return b;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof value[Symbol.toPrimitive]==="function"){return Buffer.from(value[Symbol.toPrimitive]("string"),encodingOrOffset,length)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}Buffer.from=function(value,encodingOrOffset,length){return from(value,encodingOrOffset,length)};Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;function assertSize(size){if(typeof size!=="number"){throw new TypeError('"size" argument must be of type number')}else if(size<0){throw new RangeError('The value "'+size+'" is invalid for option "size"')}}function alloc(size,fill,encoding){assertSize(size);if(size<=0){return createBuffer(size)}if(fill!==undefined){return typeof encoding==="string"?createBuffer(size).fill(fill,encoding):createBuffer(size).fill(fill)}return createBuffer(size)}Buffer.alloc=function(size,fill,encoding){return alloc(size,fill,encoding)};function allocUnsafe(size){assertSize(size);return createBuffer(size<0?0:checked(size)|0)}Buffer.allocUnsafe=function(size){return allocUnsafe(size)};Buffer.allocUnsafeSlow=function(size){return allocUnsafe(size)};function fromString(string,encoding){if(typeof encoding!=="string"||encoding===""){encoding="utf8"}if(!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}var length=byteLength(string,encoding)|0;var buf=createBuffer(length);var actual=buf.write(string,encoding);if(actual!==length){buf=buf.slice(0,actual)}return buf}function fromArrayLike(array){var length=array.length<0?0:checked(array.length)|0;var buf=createBuffer(length);for(var i=0;i=K_MAX_LENGTH){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+K_MAX_LENGTH.toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return b!=null&&b._isBuffer===true&&b!==Buffer.prototype};Buffer.compare=function compare(a,b){if(isInstance(a,Uint8Array))a=Buffer.from(a,a.offset,a.byteLength);if(isInstance(b,Uint8Array))b=Buffer.from(b,b.offset,b.byteLength);if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i2&&arguments[2]===true;if(!mustMatch&&len===0)return 0;var loweredCase=false;for(;;){switch(encoding){case"ascii":case"latin1":case"binary":return len;case"utf8":case"utf-8":return utf8ToBytes(string).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return len*2;case"hex":return len>>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase){return mustMatch?-1:utf8ToBytes(string).length}encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"latin1":case"binary":return latin1Slice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;imax)str+=" ... ";return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(isInstance(target,Uint8Array)){target=Buffer.from(target,target.offset,target.byteLength)}if(!Buffer.isBuffer(target)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof target)}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset=+byteOffset;if(numberIsNaN(byteOffset)){byteOffset=dir?0:buffer.length-1}if(byteOffset<0)byteOffset=buffer.length+byteOffset;if(byteOffset>=buffer.length){if(dir)return-1;else byteOffset=buffer.length-1}else if(byteOffset<0){if(dir)byteOffset=0;else return-1}if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(buffer,val,byteOffset,encoding,dir)}else if(typeof val==="number"){val=val&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(dir){return Uint8Array.prototype.indexOf.call(buffer,val,byteOffset)}else{return Uint8Array.prototype.lastIndexOf.call(buffer,val,byteOffset)}}return arrayIndexOf(buffer,[val],byteOffset,encoding,dir)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(arr,val,byteOffset,encoding,dir){var indexSize=1;var arrLength=arr.length;var valLength=val.length;if(encoding!==undefined){encoding=String(encoding).toLowerCase();if(encoding==="ucs2"||encoding==="ucs-2"||encoding==="utf16le"||encoding==="utf-16le"){if(arr.length<2||val.length<2){return-1}indexSize=2;arrLength/=2;valLength/=2;byteOffset/=2}}function read(buf,i){if(indexSize===1){return buf[i]}else{return buf.readUInt16BE(i*indexSize)}}var i;if(dir){var foundIndex=-1;for(i=byteOffset;iarrLength)byteOffset=arrLength-valLength;for(i=byteOffset;i>=0;i--){var found=true;for(var j=0;jremaining){length=remaining}}var strLen=string.length;if(length>strLen/2){length=strLen/2}for(var i=0;i>>0;if(isFinite(length)){length=length>>>0;if(encoding===undefined)encoding="utf8"}else{encoding=length;length=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var remaining=this.length-offset;if(length===undefined||length>remaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"latin1":case"binary":return latin1Write(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){checkOffset(offset,byteLength,this.length)}var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);this[offset]=value&255;return offset+1};Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255;return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24;return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,4,34028234663852886e22,-34028234663852886e22)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,8,17976931348623157e292,-17976931348623157e292)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!Buffer.isBuffer(target))throw new TypeError("argument should be a Buffer");if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("Index out of range");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;--i){target[i+targetStart]=this[i+start]}}else{Uint8Array.prototype.set.call(target,this.subarray(start,end),targetStart)}return len};Buffer.prototype.fill=function fill(val,start,end,encoding){if(typeof val==="string"){if(typeof start==="string"){encoding=start;start=0;end=this.length}else if(typeof end==="string"){encoding=end;end=this.length}if(encoding!==undefined&&typeof encoding!=="string"){throw new TypeError("encoding must be a string")}if(typeof encoding==="string"&&!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}if(val.length===1){var code=val.charCodeAt(0);if(encoding==="utf8"&&code<128||encoding==="latin1"){val=code}}}else if(typeof val==="number"){val=val&255}if(start<0||this.length>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){for(var i=0;i=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isInstance(obj,type){return obj instanceof type||obj!=null&&obj.constructor!=null&&obj.constructor.name!=null&&obj.constructor.name===type.name}function numberIsNaN(obj){return obj!==obj}}).call(this)}).call(this,require("buffer").Buffer)},{"base64-js":1,buffer:2,ieee754:5}],3:[function(require,module,exports){"use strict";var node_worker_1=require("./node-worker.cjs");var u8=Uint8Array,u16=Uint16Array,u32=Uint32Array;var fleb=new u8([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]);var fdeb=new u8([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]);var clim=new u8([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);var freb=function(eb,start){var b=new u16(31);for(var i=0;i<31;++i){b[i]=start+=1<>>1|(i&21845)<<1;x=(x&52428)>>>2|(x&13107)<<2;x=(x&61680)>>>4|(x&3855)<<4;rev[i]=((x&65280)>>>8|(x&255)<<8)>>>1}var hMap=function(cd,mb,r){var s=cd.length;var i=0;var l=new u16(mb);for(;i>>rvb]=sv}}}}else{co=new u16(s);for(i=0;i>>15-cd[i]}}}return co};var flt=new u8(288);for(var i=0;i<144;++i)flt[i]=8;for(var i=144;i<256;++i)flt[i]=9;for(var i=256;i<280;++i)flt[i]=7;for(var i=280;i<288;++i)flt[i]=8;var fdt=new u8(32);for(var i=0;i<32;++i)fdt[i]=5;var flm=hMap(flt,9,0),flrm=hMap(flt,9,1);var fdm=hMap(fdt,5,0),fdrm=hMap(fdt,5,1);var max=function(a){var m=a[0];for(var i=1;im)m=a[i]}return m};var bits=function(d,p,m){var o=p/8|0;return(d[o]|d[o+1]<<8)>>(p&7)&m};var bits16=function(d,p){var o=p/8|0;return(d[o]|d[o+1]<<8|d[o+2]<<16)>>(p&7)};var shft=function(p){return(p+7)/8|0};var slc=function(v,s,e){if(s==null||s<0)s=0;if(e==null||e>v.length)e=v.length;var n=new(v.BYTES_PER_ELEMENT==2?u16:v.BYTES_PER_ELEMENT==4?u32:u8)(e-s);n.set(v.subarray(s,e));return n};exports.FlateErrorCode={UnexpectedEOF:0,InvalidBlockType:1,InvalidLengthLiteral:2,InvalidDistance:3,StreamFinished:4,NoStreamHandler:5,InvalidHeader:6,NoCallback:7,InvalidUTF8:8,ExtraFieldTooLong:9,InvalidDate:10,FilenameTooLong:11,StreamFinishing:12,InvalidZipData:13,UnknownCompressionMethod:14};var ec=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"];var err=function(ind,msg,nt){var e=new Error(msg||ec[ind]);e.code=ind;if(Error.captureStackTrace)Error.captureStackTrace(e,err);if(!nt)throw e;return e};var inflt=function(dat,buf,st){var sl=dat.length;if(!sl||st&&st.f&&!st.l)return buf||new u8(0);var noBuf=!buf||st;var noSt=!st||st.i;if(!st)st={};if(!buf)buf=new u8(sl*3);var cbuf=function(l){var bl=buf.length;if(l>bl){var nbuf=new u8(Math.max(bl*2,l));nbuf.set(buf);buf=nbuf}};var final=st.f||0,pos=st.p||0,bt=st.b||0,lm=st.l,dm=st.d,lbt=st.m,dbt=st.n;var tbts=sl*8;do{if(!lm){final=bits(dat,pos,1);var type=bits(dat,pos+1,3);pos+=3;if(!type){var s=shft(pos)+4,l=dat[s-4]|dat[s-3]<<8,t=s+l;if(t>sl){if(noSt)err(0);break}if(noBuf)cbuf(bt+l);buf.set(dat.subarray(s,t),bt);st.b=bt+=l,st.p=pos=t*8,st.f=final;continue}else if(type==1)lm=flrm,dm=fdrm,lbt=9,dbt=5;else if(type==2){var hLit=bits(dat,pos,31)+257,hcLen=bits(dat,pos+10,15)+4;var tl=hLit+bits(dat,pos+5,31)+1;pos+=14;var ldt=new u8(tl);var clt=new u8(19);for(var i=0;i>>4;if(s<16){ldt[i++]=s}else{var c=0,n=0;if(s==16)n=3+bits(dat,pos,3),pos+=2,c=ldt[i-1];else if(s==17)n=3+bits(dat,pos,7),pos+=3;else if(s==18)n=11+bits(dat,pos,127),pos+=7;while(n--)ldt[i++]=c}}var lt=ldt.subarray(0,hLit),dt=ldt.subarray(hLit);lbt=max(lt);dbt=max(dt);lm=hMap(lt,lbt,1);dm=hMap(dt,dbt,1)}else err(1);if(pos>tbts){if(noSt)err(0);break}}if(noBuf)cbuf(bt+131072);var lms=(1<>>4;pos+=c&15;if(pos>tbts){if(noSt)err(0);break}if(!c)err(2);if(sym<256)buf[bt++]=sym;else if(sym==256){lpos=pos,lm=null;break}else{var add=sym-254;if(sym>264){var i=sym-257,b=fleb[i];add=bits(dat,pos,(1<>>4;if(!d)err(3);pos+=d&15;var dt=fd[dsym];if(dsym>3){var b=fdeb[dsym];dt+=bits16(dat,pos)&(1<tbts){if(noSt)err(0);break}if(noBuf)cbuf(bt+131072);var end=bt+add;for(;bt>>8};var wbits16=function(d,p,v){v<<=p&7;var o=p/8|0;d[o]|=v;d[o+1]|=v>>>8;d[o+2]|=v>>>16};var hTree=function(d,mb){var t=[];for(var i=0;imaxSym)maxSym=t2[i].s}var tr=new u16(maxSym+1);var mbt=ln(t[i1-1],tr,0);if(mbt>mb){var i=0,dt=0;var lft=mbt-mb,cst=1<mb){dt+=cst-(1<>>=lft;while(dt>0){var i2_2=t2[i].s;if(tr[i2_2]=0&&dt;--i){var i2_3=t2[i].s;if(tr[i2_3]==mb){--tr[i2_3];++dt}}mbt=mb}return[new u8(tr),mbt]};var ln=function(n,l,d){return n.s==-1?Math.max(ln(n.l,l,d+1),ln(n.r,l,d+1)):l[n.s]=d};var lc=function(c){var s=c.length;while(s&&!c[--s]);var cl=new u16(++s);var cli=0,cln=c[0],cls=1;var w=function(v){cl[cli++]=v};for(var i=1;i<=s;++i){if(c[i]==cln&&i!=s)++cls;else{if(!cln&&cls>2){for(;cls>138;cls-=138)w(32754);if(cls>2){w(cls>10?cls-11<<5|28690:cls-3<<5|12305);cls=0}}else if(cls>3){w(cln),--cls;for(;cls>6;cls-=6)w(8304);if(cls>2)w(cls-3<<5|8208),cls=0}while(cls--)w(cln);cls=1;cln=c[i]}}return[cl.subarray(0,cli),s]};var clen=function(cf,cl){var l=0;for(var i=0;i>>8;out[o+2]=out[o]^255;out[o+3]=out[o+1]^255;for(var i=0;i4&&!lct[clim[nlcc-1]];--nlcc);var flen=bl+5<<3;var ftlen=clen(lf,flt)+clen(df,fdt)+eb;var dtlen=clen(lf,dlt)+clen(df,ddt)+eb+14+3*nlcc+clen(lcfreq,lct)+(2*lcfreq[16]+3*lcfreq[17]+7*lcfreq[18]);if(flen<=ftlen&&flen<=dtlen)return wfblk(out,p,dat.subarray(bs,bs+bl));var lm,ll,dm,dl;wbits(out,p,1+(dtlen15)wbits(out,p,clct[i]>>>5&127),p+=clct[i]>>>12}}}else{lm=flm,ll=flt,dm=fdm,dl=fdt}for(var i=0;i255){var len=syms[i]>>>18&31;wbits16(out,p,lm[len+257]),p+=ll[len+257];if(len>7)wbits(out,p,syms[i]>>>23&31),p+=fleb[len];var dst=syms[i]&31;wbits16(out,p,dm[dst]),p+=dl[dst];if(dst>3)wbits16(out,p,syms[i]>>>5&8191),p+=fdeb[dst]}else{wbits16(out,p,lm[syms[i]]),p+=ll[syms[i]]}}wbits16(out,p,lm[256]);return p+ll[256]};var deo=new u32([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]);var et=new u8(0);var dflt=function(dat,lvl,plvl,pre,post,lst){var s=dat.length;var o=new u8(pre+s+5*(1+Math.ceil(s/7e3))+post);var w=o.subarray(pre,o.length-post);var pos=0;if(!lvl||s<8){for(var i=0;i<=s;i+=65535){var e=i+65535;if(e>=s){w[pos>>3]=lst}pos=wfblk(w,pos+1,dat.subarray(i,e))}}else{var opt=deo[lvl-1];var n=opt>>>13,c=opt&8191;var msk_1=(1<7e3||li>24576)&&rem>423){pos=wblk(dat,w,0,syms,lf,df,eb,li,bs,i-bs,pos);li=lc_1=eb=0,bs=i;for(var j=0;j<286;++j)lf[j]=0;for(var j=0;j<30;++j)df[j]=0}var l=2,d=0,ch_1=c,dif=imod-pimod&32767;if(rem>2&&hv==hsh(i-dif)){var maxn=Math.min(n,rem)-1;var maxd=Math.min(32767,i);var ml=Math.min(258,rem);while(dif<=maxd&&--ch_1&&imod!=pimod){if(dat[i+l]==dat[i+l-dif]){var nl=0;for(;nll){l=nl,d=dif;if(nl>maxn)break;var mmd=Math.min(dif,nl-2);var md=0;for(var j=0;jmd)md=cd,pimod=ti}}}imod=pimod,pimod=prev[imod];dif+=imod-pimod+32768&32767}}if(d){syms[li++]=268435456|revfl[l]<<18|revfd[d];var lin=revfl[l]&31,din=revfd[d]&31;eb+=fleb[lin]+fdeb[din];++lf[257+lin];++df[din];wi=i+l;++lc_1}else{syms[li++]=dat[i];++lf[dat[i]]}}}pos=wblk(dat,w,lst,syms,lf,df,eb,li,bs,i-bs,pos);if(!lst&&pos&7)pos=wfblk(w,pos+1,et)}return slc(o,0,pre+shft(pos)+post)};var crct=function(){var t=new Int32Array(256);for(var i=0;i<256;++i){var c=i,k=9;while(--k)c=(c&1&&-306674912)^c>>>1;t[i]=c}return t}();var crc=function(){var c=-1;return{p:function(d){var cr=c;for(var i=0;i>>8;c=cr},d:function(){return~c}}};var adler=function(){var a=1,b=0;return{p:function(d){var n=a,m=b;var l=d.length|0;for(var i=0;i!=l;){var e=Math.min(i+2655,l);for(;i>16),m=(m&65535)+15*(m>>16)}a=n,b=m},d:function(){a%=65521,b%=65521;return(a&255)<<24|a>>>8<<16|(b&255)<<8|b>>>8}}};var dopt=function(dat,opt,pre,post,st){return dflt(dat,opt.level==null?6:opt.level,opt.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(dat.length)))*1.5):12+opt.mem,pre,post,!st)};var mrg=function(a,b){var o={};for(var k in a)o[k]=a[k];for(var k in b)o[k]=b[k];return o};var wcln=function(fn,fnStr,td){var dt=fn();var st=fn.toString();var ks=st.slice(st.indexOf("[")+1,st.lastIndexOf("]")).replace(/\s+/g,"").split(",");for(var i=0;i>>0};var b8=function(d,b){return b4(d,b)+b4(d,b+4)*4294967296};var wbytes=function(d,b,v){for(;v;++b)d[b]=v,v>>>=8};var gzh=function(c,o){var fn=o.filename;c[0]=31,c[1]=139,c[2]=8,c[8]=o.level<2?4:o.level==9?2:0,c[9]=3;if(o.mtime!=0)wbytes(c,4,Math.floor(new Date(o.mtime||Date.now())/1e3));if(fn){c[3]=8;for(var i=0;i<=fn.length;++i)c[i+10]=fn.charCodeAt(i)}};var gzs=function(d){if(d[0]!=31||d[1]!=139||d[2]!=8)err(6,"invalid gzip data");var flg=d[3];var st=10;if(flg&4)st+=d[10]|(d[11]<<8)+2;for(var zs=(flg>>3&1)+(flg>>4&1);zs>0;zs-=!d[st++]);return st+(flg&2)};var gzl=function(d){var l=d.length;return(d[l-4]|d[l-3]<<8|d[l-2]<<16|d[l-1]<<24)>>>0};var gzhl=function(o){return 10+(o.filename&&o.filename.length+1||0)};var zlh=function(c,o){var lv=o.level,fl=lv==0?0:lv<6?1:lv==9?3:2;c[0]=120,c[1]=fl<<6|(fl?32-2*fl:1)};var zlv=function(d){if((d[0]&15)!=8||d[0]>>>4>7||(d[0]<<8|d[1])%31)err(6,"invalid zlib data");if(d[1]&32)err(6,"invalid zlib data: preset dictionaries not supported")};function AsyncCmpStrm(opts,cb){if(!cb&&typeof opts=="function")cb=opts,opts={};this.ondata=cb;return opts}var Deflate=function(){function Deflate(opts,cb){if(!cb&&typeof opts=="function")cb=opts,opts={};this.ondata=cb;this.o=opts||{}}Deflate.prototype.p=function(c,f){this.ondata(dopt(c,this.o,0,0,!f),f)};Deflate.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(this.d)err(4);this.d=final;this.p(chunk,final||false)};return Deflate}();exports.Deflate=Deflate;var AsyncDeflate=function(){function AsyncDeflate(opts,cb){astrmify([bDflt,function(){return[astrm,Deflate]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Deflate(ev.data);onmessage=astrm(strm)},6)}return AsyncDeflate}();exports.AsyncDeflate=AsyncDeflate;function deflate(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt],function(ev){return pbf(deflateSync(ev.data[0],ev.data[1]))},0,cb)}exports.deflate=deflate;function deflateSync(data,opts){return dopt(data,opts||{},0,0)}exports.deflateSync=deflateSync;var Inflate=function(){function Inflate(cb){this.s={};this.p=new u8(0);this.ondata=cb}Inflate.prototype.e=function(c){if(!this.ondata)err(5);if(this.d)err(4);var l=this.p.length;var n=new u8(l+c.length);n.set(this.p),n.set(c,l),this.p=n};Inflate.prototype.c=function(final){this.d=this.s.i=final||false;var bts=this.s.b;var dt=inflt(this.p,this.o,this.s);this.ondata(slc(dt,bts,this.s.b),this.d);this.o=slc(dt,this.s.b-32768),this.s.b=this.o.length;this.p=slc(this.p,this.s.p/8|0),this.s.p&=7};Inflate.prototype.push=function(chunk,final){this.e(chunk),this.c(final)};return Inflate}();exports.Inflate=Inflate;var AsyncInflate=function(){function AsyncInflate(cb){this.ondata=cb;astrmify([bInflt,function(){return[astrm,Inflate]}],this,0,function(){var strm=new Inflate;onmessage=astrm(strm)},7)}return AsyncInflate}();exports.AsyncInflate=AsyncInflate;function inflate(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt],function(ev){return pbf(inflateSync(ev.data[0],gu8(ev.data[1])))},1,cb)}exports.inflate=inflate;function inflateSync(data,out){return inflt(data,out)}exports.inflateSync=inflateSync;var Gzip=function(){function Gzip(opts,cb){this.c=crc();this.l=0;this.v=1;Deflate.call(this,opts,cb)}Gzip.prototype.push=function(chunk,final){Deflate.prototype.push.call(this,chunk,final)};Gzip.prototype.p=function(c,f){this.c.p(c);this.l+=c.length;var raw=dopt(c,this.o,this.v&&gzhl(this.o),f&&8,!f);if(this.v)gzh(raw,this.o),this.v=0;if(f)wbytes(raw,raw.length-8,this.c.d()),wbytes(raw,raw.length-4,this.l);this.ondata(raw,f)};return Gzip}();exports.Gzip=Gzip;exports.Compress=Gzip;var AsyncGzip=function(){function AsyncGzip(opts,cb){astrmify([bDflt,gze,function(){return[astrm,Deflate,Gzip]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Gzip(ev.data);onmessage=astrm(strm)},8)}return AsyncGzip}();exports.AsyncGzip=AsyncGzip;exports.AsyncCompress=AsyncGzip;function gzip(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt,gze,function(){return[gzipSync]}],function(ev){return pbf(gzipSync(ev.data[0],ev.data[1]))},2,cb)}exports.gzip=gzip;exports.compress=gzip;function gzipSync(data,opts){if(!opts)opts={};var c=crc(),l=data.length;c.p(data);var d=dopt(data,opts,gzhl(opts),8),s=d.length;return gzh(d,opts),wbytes(d,s-8,c.d()),wbytes(d,s-4,l),d}exports.gzipSync=gzipSync;exports.compressSync=gzipSync;var Gunzip=function(){function Gunzip(cb){this.v=1;Inflate.call(this,cb)}Gunzip.prototype.push=function(chunk,final){Inflate.prototype.e.call(this,chunk);if(this.v){var s=this.p.length>3?gzs(this.p):4;if(s>=this.p.length&&!final)return;this.p=this.p.subarray(s),this.v=0}if(final){if(this.p.length<8)err(6,"invalid gzip data");this.p=this.p.subarray(0,-8)}Inflate.prototype.c.call(this,final)};return Gunzip}();exports.Gunzip=Gunzip;var AsyncGunzip=function(){function AsyncGunzip(cb){this.ondata=cb;astrmify([bInflt,guze,function(){return[astrm,Inflate,Gunzip]}],this,0,function(){var strm=new Gunzip;onmessage=astrm(strm)},9)}return AsyncGunzip}();exports.AsyncGunzip=AsyncGunzip;function gunzip(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt,guze,function(){return[gunzipSync]}],function(ev){return pbf(gunzipSync(ev.data[0]))},3,cb)}exports.gunzip=gunzip;function gunzipSync(data,out){return inflt(data.subarray(gzs(data),-8),out||new u8(gzl(data)))}exports.gunzipSync=gunzipSync;var Zlib=function(){function Zlib(opts,cb){this.c=adler();this.v=1;Deflate.call(this,opts,cb)}Zlib.prototype.push=function(chunk,final){Deflate.prototype.push.call(this,chunk,final)};Zlib.prototype.p=function(c,f){this.c.p(c);var raw=dopt(c,this.o,this.v&&2,f&&4,!f);if(this.v)zlh(raw,this.o),this.v=0;if(f)wbytes(raw,raw.length-4,this.c.d());this.ondata(raw,f)};return Zlib}();exports.Zlib=Zlib;var AsyncZlib=function(){function AsyncZlib(opts,cb){astrmify([bDflt,zle,function(){return[astrm,Deflate,Zlib]}],this,AsyncCmpStrm.call(this,opts,cb),function(ev){var strm=new Zlib(ev.data);onmessage=astrm(strm)},10)}return AsyncZlib}();exports.AsyncZlib=AsyncZlib;function zlib(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bDflt,zle,function(){return[zlibSync]}],function(ev){return pbf(zlibSync(ev.data[0],ev.data[1]))},4,cb)}exports.zlib=zlib;function zlibSync(data,opts){if(!opts)opts={};var a=adler();a.p(data);var d=dopt(data,opts,2,4);return zlh(d,opts),wbytes(d,d.length-4,a.d()),d}exports.zlibSync=zlibSync;var Unzlib=function(){function Unzlib(cb){this.v=1;Inflate.call(this,cb)}Unzlib.prototype.push=function(chunk,final){Inflate.prototype.e.call(this,chunk);if(this.v){if(this.p.length<2&&!final)return;this.p=this.p.subarray(2),this.v=0}if(final){if(this.p.length<4)err(6,"invalid zlib data");this.p=this.p.subarray(0,-4)}Inflate.prototype.c.call(this,final)};return Unzlib}();exports.Unzlib=Unzlib;var AsyncUnzlib=function(){function AsyncUnzlib(cb){this.ondata=cb;astrmify([bInflt,zule,function(){return[astrm,Inflate,Unzlib]}],this,0,function(){var strm=new Unzlib;onmessage=astrm(strm)},11)}return AsyncUnzlib}();exports.AsyncUnzlib=AsyncUnzlib;function unzlib(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return cbify(data,opts,[bInflt,zule,function(){return[unzlibSync]}],function(ev){return pbf(unzlibSync(ev.data[0],gu8(ev.data[1])))},5,cb)}exports.unzlib=unzlib;function unzlibSync(data,out){return inflt((zlv(data),data.subarray(2,-4)),out)}exports.unzlibSync=unzlibSync;var Decompress=function(){function Decompress(cb){this.G=Gunzip;this.I=Inflate;this.Z=Unzlib;this.ondata=cb}Decompress.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(!this.s){if(this.p&&this.p.length){var n=new u8(this.p.length+chunk.length);n.set(this.p),n.set(chunk,this.p.length)}else this.p=chunk;if(this.p.length>2){var _this_1=this;var cb=function(){_this_1.ondata.apply(_this_1,arguments)};this.s=this.p[0]==31&&this.p[1]==139&&this.p[2]==8?new this.G(cb):(this.p[0]&15)!=8||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(cb):new this.Z(cb);this.s.push(this.p,final);this.p=null}}else this.s.push(chunk,final)};return Decompress}();exports.Decompress=Decompress;var AsyncDecompress=function(){function AsyncDecompress(cb){this.G=AsyncGunzip;this.I=AsyncInflate;this.Z=AsyncUnzlib;this.ondata=cb}AsyncDecompress.prototype.push=function(chunk,final){Decompress.prototype.push.call(this,chunk,final)};return AsyncDecompress}();exports.AsyncDecompress=AsyncDecompress;function decompress(data,opts,cb){if(!cb)cb=opts,opts={};if(typeof cb!="function")err(7);return data[0]==31&&data[1]==139&&data[2]==8?gunzip(data,opts,cb):(data[0]&15)!=8||data[0]>>4>7||(data[0]<<8|data[1])%31?inflate(data,opts,cb):unzlib(data,opts,cb)}exports.decompress=decompress;function decompressSync(data,out){return data[0]==31&&data[1]==139&&data[2]==8?gunzipSync(data,out):(data[0]&15)!=8||data[0]>>4>7||(data[0]<<8|data[1])%31?inflateSync(data,out):unzlibSync(data,out)}exports.decompressSync=decompressSync;var fltn=function(d,p,t,o){for(var k in d){var val=d[k],n=p+k,op=o;if(Array.isArray(val))op=mrg(o,val[1]),val=val[0];if(val instanceof u8)t[n]=[val,op];else{t[n+="/"]=[new u8(0),op];fltn(val,n,t,o)}}};var te=typeof TextEncoder!="undefined"&&new TextEncoder;var td=typeof TextDecoder!="undefined"&&new TextDecoder;var tds=0;try{td.decode(et,{stream:true});tds=1}catch(e){}var dutf8=function(d){for(var r="",i=0;;){var c=d[i++];var eb=(c>127)+(c>223)+(c>239);if(i+eb>d.length)return[r,slc(d,i-1)];if(!eb)r+=String.fromCharCode(c);else if(eb==3){c=((c&15)<<18|(d[i++]&63)<<12|(d[i++]&63)<<6|d[i++]&63)-65536,r+=String.fromCharCode(55296|c>>10,56320|c&1023)}else if(eb&1)r+=String.fromCharCode((c&31)<<6|d[i++]&63);else r+=String.fromCharCode((c&15)<<12|(d[i++]&63)<<6|d[i++]&63)}};var DecodeUTF8=function(){function DecodeUTF8(cb){this.ondata=cb;if(tds)this.t=new TextDecoder;else this.p=et}DecodeUTF8.prototype.push=function(chunk,final){if(!this.ondata)err(5);final=!!final;if(this.t){this.ondata(this.t.decode(chunk,{stream:true}),final);if(final){if(this.t.decode().length)err(8);this.t=null}return}if(!this.p)err(4);var dat=new u8(this.p.length+chunk.length);dat.set(this.p);dat.set(chunk,this.p.length);var _a=dutf8(dat),ch=_a[0],np=_a[1];if(final){if(np.length)err(8);this.p=null}else this.p=np;this.ondata(ch,final)};return DecodeUTF8}();exports.DecodeUTF8=DecodeUTF8;var EncodeUTF8=function(){function EncodeUTF8(cb){this.ondata=cb}EncodeUTF8.prototype.push=function(chunk,final){if(!this.ondata)err(5);if(this.d)err(4);this.ondata(strToU8(chunk),this.d=final||false)};return EncodeUTF8}();exports.EncodeUTF8=EncodeUTF8;function strToU8(str,latin1){if(latin1){var ar_1=new u8(str.length);for(var i=0;i>1));var ai=0;var w=function(v){ar[ai++]=v};for(var i=0;iar.length){var n=new u8(ai+8+(l-i<<1));n.set(ar);ar=n}var c=str.charCodeAt(i);if(c<128||latin1)w(c);else if(c<2048)w(192|c>>6),w(128|c&63);else if(c>55295&&c<57344)c=65536+(c&1023<<10)|str.charCodeAt(++i)&1023,w(240|c>>18),w(128|c>>12&63),w(128|c>>6&63),w(128|c&63);else w(224|c>>12),w(128|c>>6&63),w(128|c&63)}return slc(ar,0,ai)}exports.strToU8=strToU8;function strFromU8(dat,latin1){if(latin1){var r="";for(var i=0;i65535)err(9);le+=l+4}}return le};var wzh=function(d,b,f,fn,u,c,ce,co){var fl=fn.length,ex=f.extra,col=co&&co.length;var exl=exfl(ex);wbytes(d,b,ce!=null?33639248:67324752),b+=4;if(ce!=null)d[b++]=20,d[b++]=f.os;d[b]=20,b+=2;d[b++]=f.flag<<1|(c==null&&8),d[b++]=u&&8;d[b++]=f.compression&255,d[b++]=f.compression>>8;var dt=new Date(f.mtime==null?Date.now():f.mtime),y=dt.getFullYear()-1980;if(y<0||y>119)err(10);wbytes(d,b,y<<25|dt.getMonth()+1<<21|dt.getDate()<<16|dt.getHours()<<11|dt.getMinutes()<<5|dt.getSeconds()>>>1),b+=4;if(c!=null){wbytes(d,b,f.crc);wbytes(d,b+4,c);wbytes(d,b+8,f.size)}wbytes(d,b+12,fl);wbytes(d,b+14,exl),b+=16;if(ce!=null){wbytes(d,b,col);wbytes(d,b+6,f.attrs);wbytes(d,b+10,ce),b+=14}d.set(fn,b);b+=fl;if(exl){for(var k in ex){var exf=ex[k],l=exf.length;wbytes(d,b,+k);wbytes(d,b+2,l);d.set(exf,b+4),b+=4+l}}if(col)d.set(co,b),b+=col;return b};var wzf=function(o,b,c,d,e){wbytes(o,b,101010256);wbytes(o,b+8,c);wbytes(o,b+10,c);wbytes(o,b+12,d);wbytes(o,b+16,e)};var ZipPassThrough=function(){function ZipPassThrough(filename){this.filename=filename;this.c=crc();this.size=0;this.compression=0}ZipPassThrough.prototype.process=function(chunk,final){this.ondata(null,chunk,final)};ZipPassThrough.prototype.push=function(chunk,final){if(!this.ondata)err(5);this.c.p(chunk);this.size+=chunk.length;if(final)this.crc=this.c.d();this.process(chunk,final||false)};return ZipPassThrough}();exports.ZipPassThrough=ZipPassThrough;var ZipDeflate=function(){function ZipDeflate(filename,opts){var _this_1=this;if(!opts)opts={};ZipPassThrough.call(this,filename);this.d=new Deflate(opts,function(dat,final){_this_1.ondata(null,dat,final)});this.compression=8;this.flag=dbf(opts.level)}ZipDeflate.prototype.process=function(chunk,final){try{this.d.push(chunk,final)}catch(e){this.ondata(e,null,final)}};ZipDeflate.prototype.push=function(chunk,final){ZipPassThrough.prototype.push.call(this,chunk,final)};return ZipDeflate}();exports.ZipDeflate=ZipDeflate;var AsyncZipDeflate=function(){function AsyncZipDeflate(filename,opts){var _this_1=this;if(!opts)opts={};ZipPassThrough.call(this,filename);this.d=new AsyncDeflate(opts,function(err,dat,final){_this_1.ondata(err,dat,final)});this.compression=8;this.flag=dbf(opts.level);this.terminate=this.d.terminate}AsyncZipDeflate.prototype.process=function(chunk,final){this.d.push(chunk,final)};AsyncZipDeflate.prototype.push=function(chunk,final){ZipPassThrough.prototype.push.call(this,chunk,final)};return AsyncZipDeflate}();exports.AsyncZipDeflate=AsyncZipDeflate;var Zip=function(){function Zip(cb){this.ondata=cb;this.u=[];this.d=1}Zip.prototype.add=function(file){var _this_1=this;if(!this.ondata)err(5);if(this.d&2)this.ondata(err(4+(this.d&1)*8,0,1),null,false);else{var f=strToU8(file.filename),fl_1=f.length;var com=file.comment,o=com&&strToU8(com);var u=fl_1!=file.filename.length||o&&com.length!=o.length;var hl_1=fl_1+exfl(file.extra)+30;if(fl_1>65535)this.ondata(err(11,0,1),null,false);var header=new u8(hl_1);wzh(header,0,file,f,u);var chks_1=[header];var pAll_1=function(){for(var _i=0,chks_2=chks_1;_i65535)cbl(err(11,0,1),null);if(!compression)cbl(null,file);else if(size<16e4){try{cbl(null,deflateSync(file,p))}catch(e){cbl(e,null)}}else term.push(deflate(file,p,cbl))};for(var i=0;i65535)err(11);var d=compression?deflateSync(file,p):file,l=d.length;var c=crc();c.p(file);files.push(mrg(p,{size:file.length,crc:c.d(),c:d,f:f,m:m,u:s!=fn.length||m&&com.length!=ms,o:o,compression:compression}));o+=30+s+exl+l;tot+=76+2*(s+exl)+(ms||0)+l}var out=new u8(tot+22),oe=o,cdl=tot-o;for(var i=0;i0){var len=Math.min(this.c,chunk.length);var toAdd=chunk.subarray(0,len);this.c-=len;if(this.d)this.d.push(toAdd,!this.c);else this.k[0].push(toAdd);chunk=chunk.subarray(len);if(chunk.length)return this.push(chunk,final)}else{var f=0,i=0,is=void 0,buf=void 0;if(!this.p.length)buf=chunk;else if(!chunk.length)buf=this.p;else{buf=new u8(this.p.length+chunk.length);buf.set(this.p),buf.set(chunk,this.p.length)}var l=buf.length,oc=this.c,add=oc&&this.d;var _loop_2=function(){var _a;var sig=b4(buf,i);if(sig==67324752){f=1,is=i;this_1.d=null;this_1.c=0;var bf=b2(buf,i+6),cmp_1=b2(buf,i+8),u=bf&2048,dd=bf&8,fnl=b2(buf,i+26),es=b2(buf,i+28);if(l>i+30+fnl+es){var chks_3=[];this_1.k.unshift(chks_3);f=2;var sc_1=b4(buf,i+18),su_1=b4(buf,i+22);var fn_1=strFromU8(buf.subarray(i+30,i+=30+fnl),!u);if(sc_1==4294967295){_a=dd?[-2]:z64e(buf,i),sc_1=_a[0],su_1=_a[1]}else if(dd)sc_1=-1;i+=es;this_1.c=sc_1;var d_1;var file_1={name:fn_1,compression:cmp_1,start:function(){if(!file_1.ondata)err(5);if(!sc_1)file_1.ondata(null,et,true);else{var ctr=_this_1.o[cmp_1];if(!ctr)file_1.ondata(err(14,"unknown compression type "+cmp_1,1),null,false);d_1=sc_1<0?new ctr(fn_1):new ctr(fn_1,sc_1,su_1);d_1.ondata=function(err,dat,final){file_1.ondata(err,dat,final)};for(var _i=0,chks_4=chks_3;_i=0)file_1.size=sc_1,file_1.originalSize=su_1;this_1.onfile(file_1)}return"break"}else if(oc){if(sig==134695760){is=i+=12+(oc==-2&&8),f=3,this_1.c=0;return"break"}else if(sig==33639248){is=i-=4,f=3,this_1.c=0;return"break"}}};var this_1=this;for(;i65558){cbd(err(13,0,1),null);return tAll}}var lft=b2(data,e+8);if(lft){var c=lft;var o=b4(data,e+16);var z=o==4294967295;if(z){e=b4(data,e-12);if(b4(data,e)!=101075792){cbd(err(13,0,1),null);return tAll}c=lft=b4(data,e+32);o=b4(data,e+48)}var fltr=opts&&opts.filter;var _loop_3=function(i){var _a=zh(data,o,z),c_1=_a[0],sc=_a[1],su=_a[2],fn=_a[3],no=_a[4],off=_a[5],b=slzh(data,off);o=no;var cbl=function(e,d){if(e){tAll();cbd(e,null)}else{if(d)files[fn]=d;if(!--lft)cbd(null,files)}};if(!fltr||fltr({name:fn,size:sc,originalSize:su,compression:c_1})){if(!c_1)cbl(null,slc(data,b,b+sc));else if(c_1==8){var infl=data.subarray(b,b+sc);if(sc<32e4){try{cbl(null,inflateSync(infl,new u8(su)))}catch(e){cbl(e,null)}}else term.push(inflate(infl,{size:su},cbl))}else cbl(err(14,"unknown compression type "+c_1,1),null)}else cbl(null,null)};for(var i=0;i65558)err(13)}var c=b2(data,e+8);if(!c)return{};var o=b4(data,e+16);var z=o==4294967295;if(z){e=b4(data,e-12);if(b4(data,e)!=101075792)err(13);c=b4(data,e+32);o=b4(data,e+48)}var fltr=opts&&opts.filter;for(var i=0;i>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],6:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||function(esize,ecode,edata,littleEndian){if(esize%16!=0){throw new Error("This does not appear to be a NIFTI extension")}this.esize=esize;this.ecode=ecode;this.edata=edata;this.littleEndian=littleEndian};nifti.NIFTIEXTENSION.prototype.toArrayBuffer=function(){let byteArray=new Uint8Array(this.esize);byteArray.set(this.data.buffer,8);let view=new DataView(byteArray.buffer);view.setInt32(0,this.esize,this.littleEndian);view.setInt32(4,this.ecode,this.littleEndian);return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTIEXTENSION}},{}],7:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.NIFTI1=nifti.NIFTI1||(typeof require!=="undefined"?require("./nifti1.js"):null);nifti.NIFTI2=nifti.NIFTI2||(typeof require!=="undefined"?require("./nifti2.js"):null);nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.Utils=nifti.Utils||(typeof require!=="undefined"?require("./utilities.js"):null);var fflate=fflate||(typeof require!=="undefined"?require("fflate"):null);nifti.isNIFTI1=function(data,isHdrImgPairOK=false){var buf,mag1,mag2,mag3;if(data.byteLength0&&this.sform_code0){for(ctrOut=0;ctrOut<3;ctrOut+=1){for(ctrIn=0;ctrIn<4;ctrIn+=1){index=280+(ctrOut*4+ctrIn)*4;this.affine[ctrOut][ctrIn]=nifti.Utils.getFloatAt(rawData,index,this.littleEndian)}}}this.affine[3][0]=0;this.affine[3][1]=0;this.affine[3][2]=0;this.affine[3][3]=1;this.intent_name=nifti.Utils.getStringAt(rawData,328,344);this.magic=nifti.Utils.getStringAt(rawData,344,348);this.isHDR=this.magic===nifti.NIFTI1.MAGIC_NUMBER2;if(rawData.byteLength>nifti.NIFTI1.MAGIC_COOKIE){this.extensionFlag[0]=nifti.Utils.getByteAt(rawData,348);this.extensionFlag[1]=nifti.Utils.getByteAt(rawData,348+1);this.extensionFlag[2]=nifti.Utils.getByteAt(rawData,348+2);this.extensionFlag[3]=nifti.Utils.getByteAt(rawData,348+3);if(this.extensionFlag[0]){this.extensions=nifti.Utils.getExtensionsAt(rawData,this.getExtensionLocation(),this.littleEndian,this.vox_offset);this.extensionSize=this.extensions[0].esize;this.extensionCode=this.extensions[0].ecode}}};nifti.NIFTI1.prototype.toFormattedString=function(){var fmt=nifti.Utils.formatNumber,string="";string+="Dim Info = "+this.dim_info+"\n";string+="Image Dimensions (1-8): "+this.dims[0]+", "+this.dims[1]+", "+this.dims[2]+", "+this.dims[3]+", "+this.dims[4]+", "+this.dims[5]+", "+this.dims[6]+", "+this.dims[7]+"\n";string+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+"\n";string+="Intent Code = "+this.intent_code+"\n";string+="Datatype = "+this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+")\n";string+="Bits Per Voxel = "+this.numBitsPerVoxel+"\n";string+="Slice Start = "+this.slice_start+"\n";string+="Voxel Dimensions (1-8): "+fmt(this.pixDims[0])+", "+fmt(this.pixDims[1])+", "+fmt(this.pixDims[2])+", "+fmt(this.pixDims[3])+", "+fmt(this.pixDims[4])+", "+fmt(this.pixDims[5])+", "+fmt(this.pixDims[6])+", "+fmt(this.pixDims[7])+"\n";string+="Image Offset = "+this.vox_offset+"\n";string+="Data Scale: Slope = "+fmt(this.scl_slope)+" Intercept = "+fmt(this.scl_inter)+"\n";string+="Slice End = "+this.slice_end+"\n";string+="Slice Code = "+this.slice_code+"\n";string+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(nifti.NIFTI1.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(nifti.NIFTI1.TEMPORAL_UNITS_MASK&this.xyzt_units)+")\n";string+="Display Range: Max = "+fmt(this.cal_max)+" Min = "+fmt(this.cal_min)+"\n";string+="Slice Duration = "+this.slice_duration+"\n";string+="Time Axis Shift = "+this.toffset+"\n";string+='Description: "'+this.description+'"\n';string+='Auxiliary File: "'+this.aux_file+'"\n';string+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+")\n";string+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+")\n";string+="Quaternion Parameters: "+"b = "+fmt(this.quatern_b)+" "+"c = "+fmt(this.quatern_c)+" "+"d = "+fmt(this.quatern_d)+"\n";string+="Quaternion Offsets: "+"x = "+this.qoffset_x+" "+"y = "+this.qoffset_y+" "+"z = "+this.qoffset_z+"\n";string+="S-Form Parameters X: "+fmt(this.affine[0][0])+", "+fmt(this.affine[0][1])+", "+fmt(this.affine[0][2])+", "+fmt(this.affine[0][3])+"\n";string+="S-Form Parameters Y: "+fmt(this.affine[1][0])+", "+fmt(this.affine[1][1])+", "+fmt(this.affine[1][2])+", "+fmt(this.affine[1][3])+"\n";string+="S-Form Parameters Z: "+fmt(this.affine[2][0])+", "+fmt(this.affine[2][1])+", "+fmt(this.affine[2][2])+", "+fmt(this.affine[2][3])+"\n";string+='Intent Name: "'+this.intent_name+'"\n';if(this.extensionFlag[0]){string+="Extension: Size = "+this.extensionSize+" Code = "+this.extensionCode+"\n"}return string};nifti.NIFTI1.prototype.getDatatypeCodeString=function(code){if(code===nifti.NIFTI1.TYPE_UINT8){return"1-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_INT16){return"2-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_INT32){return"4-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_FLOAT32){return"4-Byte Float"}else if(code===nifti.NIFTI1.TYPE_FLOAT64){return"8-Byte Float"}else if(code===nifti.NIFTI1.TYPE_RGB24){return"RGB"}else if(code===nifti.NIFTI1.TYPE_INT8){return"1-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_UINT16){return"2-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_UINT32){return"4-Byte Unsigned Integer"}else if(code===nifti.NIFTI1.TYPE_INT64){return"8-Byte Signed Integer"}else if(code===nifti.NIFTI1.TYPE_UINT64){return"8-Byte Unsigned Integer"}else{return"Unknown"}};nifti.NIFTI1.prototype.getTransformCodeString=function(code){if(code===nifti.NIFTI1.XFORM_SCANNER_ANAT){return"Scanner"}else if(code===nifti.NIFTI1.XFORM_ALIGNED_ANAT){return"Aligned"}else if(code===nifti.NIFTI1.XFORM_TALAIRACH){return"Talairach"}else if(code===nifti.NIFTI1.XFORM_MNI_152){return"MNI"}else{return"Unknown"}};nifti.NIFTI1.prototype.getUnitsCodeString=function(code){if(code===nifti.NIFTI1.UNITS_METER){return"Meters"}else if(code===nifti.NIFTI1.UNITS_MM){return"Millimeters"}else if(code===nifti.NIFTI1.UNITS_MICRON){return"Microns"}else if(code===nifti.NIFTI1.UNITS_SEC){return"Seconds"}else if(code===nifti.NIFTI1.UNITS_MSEC){return"Milliseconds"}else if(code===nifti.NIFTI1.UNITS_USEC){return"Microseconds"}else if(code===nifti.NIFTI1.UNITS_HZ){return"Hz"}else if(code===nifti.NIFTI1.UNITS_PPM){return"PPM"}else if(code===nifti.NIFTI1.UNITS_RADS){return"Rads"}else{return"Unknown"}};nifti.NIFTI1.prototype.getQformMat=function(){return this.convertNiftiQFormToNiftiSForm(this.quatern_b,this.quatern_c,this.quatern_d,this.qoffset_x,this.qoffset_y,this.qoffset_z,this.pixDims[1],this.pixDims[2],this.pixDims[3],this.pixDims[0])};nifti.NIFTI1.prototype.convertNiftiQFormToNiftiSForm=function(qb,qc,qd,qx,qy,qz,dx,dy,dz,qfac){var R=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],a,b=qb,c=qc,d=qd,xd,yd,zd;R[3][0]=R[3][1]=R[3][2]=0;R[3][3]=1;a=1-(b*b+c*c+d*d);if(a<1e-7){a=1/Math.sqrt(b*b+c*c+d*d);b*=a;c*=a;d*=a;a=0}else{a=Math.sqrt(a)}xd=dx>0?dx:1;yd=dy>0?dy:1;zd=dz>0?dz:1;if(qfac<0){zd=-zd}R[0][0]=(a*a+b*b-c*c-d*d)*xd;R[0][1]=2*(b*c-a*d)*yd;R[0][2]=2*(b*d+a*c)*zd;R[1][0]=2*(b*c+a*d)*xd;R[1][1]=(a*a+c*c-b*b-d*d)*yd;R[1][2]=2*(c*d-a*b)*zd;R[2][0]=2*(b*d-a*c)*xd;R[2][1]=2*(c*d+a*b)*yd;R[2][2]=(a*a+d*d-c*c-b*b)*zd;R[0][3]=qx;R[1][3]=qy;R[2][3]=qz;return R};nifti.NIFTI1.prototype.convertNiftiSFormToNEMA=function(R){var xi,xj,xk,yi,yj,yk,zi,zj,zk,val,detQ,detP,i,j,k,p,q,r,ibest,jbest,kbest,pbest,qbest,rbest,M,vbest,Q,P,iChar,jChar,kChar,iSense,jSense,kSense;k=0;Q=[[0,0,0],[0,0,0],[0,0,0]];P=[[0,0,0],[0,0,0],[0,0,0]];xi=R[0][0];xj=R[0][1];xk=R[0][2];yi=R[1][0];yj=R[1][1];yk=R[1][2];zi=R[2][0];zj=R[2][1];zk=R[2][2];val=Math.sqrt(xi*xi+yi*yi+zi*zi);if(val===0){return null}xi/=val;yi/=val;zi/=val;val=Math.sqrt(xj*xj+yj*yj+zj*zj);if(val===0){return null}xj/=val;yj/=val;zj/=val;val=xi*xj+yi*yj+zi*zj;if(Math.abs(val)>1e-4){xj-=val*xi;yj-=val*yi;zj-=val*zi;val=Math.sqrt(xj*xj+yj*yj+zj*zj);if(val===0){return null}xj/=val;yj/=val;zj/=val}val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){xk=yi*zj-zi*yj;yk=zi*xj-zj*xi;zk=xi*yj-yi*xj}else{xk/=val;yk/=val;zk/=val}val=xi*xk+yi*yk+zi*zk;if(Math.abs(val)>1e-4){xk-=val*xi;yk-=val*yi;zk-=val*zi;val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){return null}xk/=val;yk/=val;zk/=val}val=xj*xk+yj*yk+zj*zk;if(Math.abs(val)>1e-4){xk-=val*xj;yk-=val*yj;zk-=val*zj;val=Math.sqrt(xk*xk+yk*yk+zk*zk);if(val===0){return null}xk/=val;yk/=val;zk/=val}Q[0][0]=xi;Q[0][1]=xj;Q[0][2]=xk;Q[1][0]=yi;Q[1][1]=yj;Q[1][2]=yk;Q[2][0]=zi;Q[2][1]=zj;Q[2][2]=zk;detQ=this.nifti_mat33_determ(Q);if(detQ===0){return null}vbest=-666;ibest=pbest=qbest=rbest=1;jbest=2;kbest=3;for(i=1;i<=3;i+=1){for(j=1;j<=3;j+=1){if(i!==j){for(k=1;k<=3;k+=1){if(!(i===k||j===k)){P[0][0]=P[0][1]=P[0][2]=P[1][0]=P[1][1]=P[1][2]=P[2][0]=P[2][1]=P[2][2]=0;for(p=-1;p<=1;p+=2){for(q=-1;q<=1;q+=2){for(r=-1;r<=1;r+=2){P[0][i-1]=p;P[1][j-1]=q;P[2][k-1]=r;detP=this.nifti_mat33_determ(P);if(detP*detQ>0){M=this.nifti_mat33_mul(P,Q);val=M[0][0]+M[1][1]+M[2][2];if(val>vbest){vbest=val;ibest=i;jbest=j;kbest=k;pbest=p;qbest=q;rbest=r}}}}}}}}}}iChar=jChar=kChar=iSense=jSense=kSense=0;switch(ibest*pbest){case 1:iChar="X";iSense="+";break;case-1:iChar="X";iSense="-";break;case 2:iChar="Y";iSense="+";break;case-2:iChar="Y";iSense="-";break;case 3:iChar="Z";iSense="+";break;case-3:iChar="Z";iSense="-";break}switch(jbest*qbest){case 1:jChar="X";jSense="+";break;case-1:jChar="X";jSense="-";break;case 2:jChar="Y";jSense="+";break;case-2:jChar="Y";jSense="-";break;case 3:jChar="Z";jSense="+";break;case-3:jChar="Z";jSense="-";break}switch(kbest*rbest){case 1:kChar="X";kSense="+";break;case-1:kChar="X";kSense="-";break;case 2:kChar="Y";kSense="+";break;case-2:kChar="Y";kSense="-";break;case 3:kChar="Z";kSense="+";break;case-3:kChar="Z";kSense="-";break}return iChar+jChar+kChar+iSense+jSense+kSense};nifti.NIFTI1.prototype.nifti_mat33_mul=function(A,B){var C=[[0,0,0],[0,0,0],[0,0,0]],i,j;for(i=0;i<3;i+=1){for(j=0;j<3;j+=1){C[i][j]=A[i][0]*B[0][j]+A[i][1]*B[1][j]+A[i][2]*B[2][j]}}return C};nifti.NIFTI1.prototype.nifti_mat33_determ=function(R){var r11,r12,r13,r21,r22,r23,r31,r32,r33;r11=R[0][0];r12=R[0][1];r13=R[0][2];r21=R[1][0];r22=R[1][1];r23=R[1][2];r31=R[2][0];r32=R[2][1];r33=R[2][2];return r11*r22*r33-r11*r32*r23-r21*r12*r33+r21*r32*r13+r31*r12*r23-r31*r22*r13};nifti.NIFTI1.prototype.getExtensionLocation=function(){return nifti.NIFTI1.MAGIC_COOKIE+4};nifti.NIFTI1.prototype.getExtensionSize=function(data){return nifti.Utils.getIntAt(data,this.getExtensionLocation(),this.littleEndian)};nifti.NIFTI1.prototype.getExtensionCode=function(data){return nifti.Utils.getIntAt(data,this.getExtensionLocation()+4,this.littleEndian)};nifti.NIFTI1.prototype.addExtension=function(extension,index=-1){if(index==-1){this.extensions.push(extension)}else{this.extensions.splice(index,0,extension)}this.vox_offset+=extension.esize};nifti.NIFTI1.prototype.removeExtension=function(index){let extension=this.extensions[index];if(extension){this.vox_offset-=extension.esize}this.extensions.splice(index,1)};nifti.NIFTI1.prototype.toArrayBuffer=function(includeExtensions=false){const SHORT_SIZE=2;const FLOAT32_SIZE=4;let byteSize=348+4;if(includeExtensions){for(let extension of this.extensions){byteSize+=extension.esize}}let byteArray=new Uint8Array(byteSize);let view=new DataView(byteArray.buffer);view.setInt32(0,348,this.littleEndian);view.setUint8(39,this.dim_info);for(let i=0;i<8;i++){view.setUint16(40+SHORT_SIZE*i,this.dims[i],this.littleEndian)}view.setFloat32(56,this.intent_p1,this.littleEndian);view.setFloat32(60,this.intent_p2,this.littleEndian);view.setFloat32(64,this.intent_p3,this.littleEndian);view.setInt16(68,this.intent_code,this.littleEndian);view.setInt16(70,this.datatypeCode,this.littleEndian);view.setInt16(72,this.numBitsPerVoxel,this.littleEndian);view.setInt16(74,this.slice_start,this.littleEndian);for(let i=0;i<8;i++){view.setFloat32(76+FLOAT32_SIZE*i,this.pixDims[i],this.littleEndian)}view.setFloat32(108,this.vox_offset,this.littleEndian);view.setFloat32(112,this.scl_slope,this.littleEndian);view.setFloat32(116,this.scl_inter,this.littleEndian);view.setInt16(120,this.slice_end,this.littleEndian);view.setUint8(122,this.slice_code);view.setUint8(123,this.xyzt_units);view.setFloat32(124,this.cal_max,this.littleEndian);view.setFloat32(128,this.cal_min,this.littleEndian);view.setFloat32(132,this.slice_duration,this.littleEndian);view.setFloat32(136,this.toffset,this.littleEndian);byteArray.set(Buffer.from(this.description),148);byteArray.set(Buffer.from(this.aux_file),228);view.setInt16(252,this.qform_code,this.littleEndian);view.setInt16(254,this.sform_code,this.littleEndian);view.setFloat32(256,this.quatern_b,this.littleEndian);view.setFloat32(260,this.quatern_c,this.littleEndian);view.setFloat32(264,this.quatern_d,this.littleEndian);view.setFloat32(268,this.qoffset_x,this.littleEndian);view.setFloat32(272,this.qoffset_y,this.littleEndian);view.setFloat32(276,this.qoffset_z,this.littleEndian);const flattened=this.affine.flat();for(let i=0;i<12;i++){view.setFloat32(280+FLOAT32_SIZE*i,flattened[i],this.littleEndian)}byteArray.set(Buffer.from(this.intent_name),328);byteArray.set(Buffer.from(this.magic),344);if(includeExtensions){byteArray.set(Uint8Array.from([1,0,0,0]),348);let extensionByteIndex=this.getExtensionLocation();for(const extension of this.extensions){view.setInt32(extensionByteIndex,extension.esize,extension.littleEndian);view.setInt32(extensionByteIndex+4,extension.ecode,extension.littleEndian);byteArray.set(new Uint8Array(extension.edata),extensionByteIndex+8);extensionByteIndex+=extension.esize}}else{byteArray.set(new Uint8Array(4).fill(0),348)}return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTI1}}).call(this)}).call(this,require("buffer").Buffer)},{"./nifti-extension.js":6,"./utilities.js":10,buffer:2}],9:[function(require,module,exports){(function(Buffer){(function(){"use strict";var nifti=nifti||{};nifti.Utils=nifti.Utils||(typeof require!=="undefined"?require("./utilities.js"):null);nifti.NIFTI1=nifti.NIFTI1||(typeof require!=="undefined"?require("./nifti1.js"):null);nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.NIFTI2=nifti.NIFTI2||function(){this.littleEndian=false;this.dim_info=0;this.dims=[];this.intent_p1=0;this.intent_p2=0;this.intent_p3=0;this.intent_code=0;this.datatypeCode=0;this.numBitsPerVoxel=0;this.slice_start=0;this.slice_end=0;this.slice_code=0;this.pixDims=[];this.vox_offset=0;this.scl_slope=1;this.scl_inter=0;this.xyzt_units=0;this.cal_max=0;this.cal_min=0;this.slice_duration=0;this.toffset=0;this.description="";this.aux_file="";this.intent_name="";this.qform_code=0;this.sform_code=0;this.quatern_b=0;this.quatern_c=0;this.quatern_d=0;this.qoffset_x=0;this.qoffset_y=0;this.qoffset_z=0;this.affine=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];this.magic=0;this.extensionFlag=[0,0,0,0];this.extensions=[]};nifti.NIFTI2.MAGIC_COOKIE=540;nifti.NIFTI2.MAGIC_NUMBER_LOCATION=4;nifti.NIFTI2.MAGIC_NUMBER=[110,43,50,0,13,10,26,10];nifti.NIFTI2.MAGIC_NUMBER2=[110,105,50,0,13,10,26,10];nifti.NIFTI2.prototype.readHeader=function(data){var rawData=new DataView(data),magicCookieVal=nifti.Utils.getIntAt(rawData,0,this.littleEndian),ctr,ctrOut,ctrIn,index,array;if(magicCookieVal!==nifti.NIFTI2.MAGIC_COOKIE){this.littleEndian=true;magicCookieVal=nifti.Utils.getIntAt(rawData,0,this.littleEndian)}if(magicCookieVal!==nifti.NIFTI2.MAGIC_COOKIE){throw new Error("This does not appear to be a NIFTI file!")}this.magic=nifti.Utils.getStringAt(rawData,4,12);this.datatypeCode=nifti.Utils.getShortAt(rawData,12,this.littleEndian);this.numBitsPerVoxel=nifti.Utils.getShortAt(rawData,14,this.littleEndian);for(ctr=0;ctr<8;ctr+=1){index=16+ctr*8;this.dims[ctr]=nifti.Utils.getLongAt(rawData,index,this.littleEndian)}this.intent_p1=nifti.Utils.getDoubleAt(rawData,80,this.littleEndian);this.intent_p2=nifti.Utils.getDoubleAt(rawData,88,this.littleEndian);this.intent_p3=nifti.Utils.getDoubleAt(rawData,96,this.littleEndian);for(ctr=0;ctr<8;ctr+=1){index=104+ctr*8;this.pixDims[ctr]=nifti.Utils.getDoubleAt(rawData,index,this.littleEndian)}this.vox_offset=nifti.Utils.getLongAt(rawData,168,this.littleEndian);this.scl_slope=nifti.Utils.getDoubleAt(rawData,176,this.littleEndian);this.scl_inter=nifti.Utils.getDoubleAt(rawData,184,this.littleEndian);this.cal_max=nifti.Utils.getDoubleAt(rawData,192,this.littleEndian);this.cal_min=nifti.Utils.getDoubleAt(rawData,200,this.littleEndian);this.slice_duration=nifti.Utils.getDoubleAt(rawData,208,this.littleEndian);this.toffset=nifti.Utils.getDoubleAt(rawData,216,this.littleEndian);this.slice_start=nifti.Utils.getLongAt(rawData,224,this.littleEndian);this.slice_end=nifti.Utils.getLongAt(rawData,232,this.littleEndian);this.description=nifti.Utils.getStringAt(rawData,240,240+80);this.aux_file=nifti.Utils.getStringAt(rawData,320,320+24);this.qform_code=nifti.Utils.getIntAt(rawData,344,this.littleEndian);this.sform_code=nifti.Utils.getIntAt(rawData,348,this.littleEndian);this.quatern_b=nifti.Utils.getDoubleAt(rawData,352,this.littleEndian);this.quatern_c=nifti.Utils.getDoubleAt(rawData,360,this.littleEndian);this.quatern_d=nifti.Utils.getDoubleAt(rawData,368,this.littleEndian);this.qoffset_x=nifti.Utils.getDoubleAt(rawData,376,this.littleEndian);this.qoffset_y=nifti.Utils.getDoubleAt(rawData,384,this.littleEndian);this.qoffset_z=nifti.Utils.getDoubleAt(rawData,392,this.littleEndian);for(ctrOut=0;ctrOut<3;ctrOut+=1){for(ctrIn=0;ctrIn<4;ctrIn+=1){index=400+(ctrOut*4+ctrIn)*8;this.affine[ctrOut][ctrIn]=nifti.Utils.getDoubleAt(rawData,index,this.littleEndian)}}this.affine[3][0]=0;this.affine[3][1]=0;this.affine[3][2]=0;this.affine[3][3]=1;this.slice_code=nifti.Utils.getIntAt(rawData,496,this.littleEndian);this.xyzt_units=nifti.Utils.getIntAt(rawData,500,this.littleEndian);this.intent_code=nifti.Utils.getIntAt(rawData,504,this.littleEndian);this.intent_name=nifti.Utils.getStringAt(rawData,508,508+16);this.dim_info=nifti.Utils.getByteAt(rawData,524);if(rawData.byteLength>nifti.NIFTI2.MAGIC_COOKIE){this.extensionFlag[0]=nifti.Utils.getByteAt(rawData,540);this.extensionFlag[1]=nifti.Utils.getByteAt(rawData,540+1);this.extensionFlag[2]=nifti.Utils.getByteAt(rawData,540+2);this.extensionFlag[3]=nifti.Utils.getByteAt(rawData,540+3);if(this.extensionFlag[0]){this.extensions=nifti.Utils.getExtensionsAt(rawData,this.getExtensionLocation(),this.littleEndian,this.vox_offset);this.extensionSize=this.extensions[0].esize;this.extensionCode=this.extensions[0].ecode}}};nifti.NIFTI2.prototype.toFormattedString=function(){var fmt=nifti.Utils.formatNumber,string="";string+="Datatype = "+ +this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+")\n";string+="Bits Per Voxel = "+" = "+this.numBitsPerVoxel+"\n";string+="Image Dimensions"+" (1-8): "+this.dims[0]+", "+this.dims[1]+", "+this.dims[2]+", "+this.dims[3]+", "+this.dims[4]+", "+this.dims[5]+", "+this.dims[6]+", "+this.dims[7]+"\n";string+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+"\n";string+="Voxel Dimensions (1-8): "+fmt(this.pixDims[0])+", "+fmt(this.pixDims[1])+", "+fmt(this.pixDims[2])+", "+fmt(this.pixDims[3])+", "+fmt(this.pixDims[4])+", "+fmt(this.pixDims[5])+", "+fmt(this.pixDims[6])+", "+fmt(this.pixDims[7])+"\n";string+="Image Offset = "+this.vox_offset+"\n";string+="Data Scale: Slope = "+fmt(this.scl_slope)+" Intercept = "+fmt(this.scl_inter)+"\n";string+="Display Range: Max = "+fmt(this.cal_max)+" Min = "+fmt(this.cal_min)+"\n";string+="Slice Duration = "+this.slice_duration+"\n";string+="Time Axis Shift = "+this.toffset+"\n";string+="Slice Start = "+this.slice_start+"\n";string+="Slice End = "+this.slice_end+"\n";string+='Description: "'+this.description+'"\n';string+='Auxiliary File: "'+this.aux_file+'"\n';string+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+")\n";string+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+")\n";string+="Quaternion Parameters: "+"b = "+fmt(this.quatern_b)+" "+"c = "+fmt(this.quatern_c)+" "+"d = "+fmt(this.quatern_d)+"\n";string+="Quaternion Offsets: "+"x = "+this.qoffset_x+" "+"y = "+this.qoffset_y+" "+"z = "+this.qoffset_z+"\n";string+="S-Form Parameters X: "+fmt(this.affine[0][0])+", "+fmt(this.affine[0][1])+", "+fmt(this.affine[0][2])+", "+fmt(this.affine[0][3])+"\n";string+="S-Form Parameters Y: "+fmt(this.affine[1][0])+", "+fmt(this.affine[1][1])+", "+fmt(this.affine[1][2])+", "+fmt(this.affine[1][3])+"\n";string+="S-Form Parameters Z: "+fmt(this.affine[2][0])+", "+fmt(this.affine[2][1])+", "+fmt(this.affine[2][2])+", "+fmt(this.affine[2][3])+"\n";string+="Slice Code = "+this.slice_code+"\n";string+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(nifti.NIFTI1.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(nifti.NIFTI1.TEMPORAL_UNITS_MASK&this.xyzt_units)+")\n";string+="Intent Code = "+this.intent_code+"\n";string+='Intent Name: "'+this.intent_name+'"\n';string+="Dim Info = "+this.dim_info+"\n";return string};nifti.NIFTI2.prototype.getExtensionLocation=function(){return nifti.NIFTI2.MAGIC_COOKIE+4};nifti.NIFTI2.prototype.getExtensionSize=nifti.NIFTI1.prototype.getExtensionSize;nifti.NIFTI2.prototype.getExtensionCode=nifti.NIFTI1.prototype.getExtensionCode;nifti.NIFTI2.prototype.addExtension=nifti.NIFTI1.prototype.addExtension;nifti.NIFTI2.prototype.removeExtension=nifti.NIFTI1.prototype.removeExtension;nifti.NIFTI2.prototype.getDatatypeCodeString=nifti.NIFTI1.prototype.getDatatypeCodeString;nifti.NIFTI2.prototype.getTransformCodeString=nifti.NIFTI1.prototype.getTransformCodeString;nifti.NIFTI2.prototype.getUnitsCodeString=nifti.NIFTI1.prototype.getUnitsCodeString;nifti.NIFTI2.prototype.getQformMat=nifti.NIFTI1.prototype.getQformMat;nifti.NIFTI2.prototype.convertNiftiQFormToNiftiSForm=nifti.NIFTI1.prototype.convertNiftiQFormToNiftiSForm;nifti.NIFTI2.prototype.convertNiftiSFormToNEMA=nifti.NIFTI1.prototype.convertNiftiSFormToNEMA;nifti.NIFTI2.prototype.nifti_mat33_mul=nifti.NIFTI1.prototype.nifti_mat33_mul;nifti.NIFTI2.prototype.nifti_mat33_determ=nifti.NIFTI1.prototype.nifti_mat33_determ;nifti.NIFTI2.prototype.toArrayBuffer=function(includeExtensions=false){const INT64_SIZE=8;const DOUBLE_SIZE=8;let byteSize=540+4;if(includeExtensions){for(let extension of this.extensions){byteSize+=extension.esize}}let byteArray=new Uint8Array(byteSize);let view=new DataView(byteArray.buffer);view.setInt32(0,540,this.littleEndian);byteArray.set(Buffer.from(this.magic),4);view.setInt16(12,this.datatypeCode,this.littleEndian);view.setInt16(14,this.numBitsPerVoxel,this.littleEndian);for(let i=0;i<8;i++){view.setBigInt64(16+INT64_SIZE*i,BigInt(this.dims[i]),this.littleEndian)}view.setFloat64(80,this.intent_p1,this.littleEndian);view.setFloat64(88,this.intent_p2,this.littleEndian);view.setFloat64(96,this.intent_p3,this.littleEndian);for(let i=0;i<8;i++){view.setFloat64(104+DOUBLE_SIZE*i,this.pixDims[i],this.littleEndian)}view.setBigInt64(168,BigInt(this.vox_offset),this.littleEndian);view.setFloat64(176,this.scl_slope,this.littleEndian);view.setFloat64(184,this.scl_inter,this.littleEndian);view.setFloat64(192,this.cal_max,this.littleEndian);view.setFloat64(200,this.cal_min,this.littleEndian);view.setFloat64(208,this.slice_duration,this.littleEndian);view.setFloat64(216,this.toffset,this.littleEndian);view.setBigInt64(224,BigInt(this.slice_start),this.littleEndian);view.setBigInt64(232,BigInt(this.slice_end),this.littleEndian);byteArray.set(Buffer.from(this.description),240);byteArray.set(Buffer.from(this.aux_file),320);view.setInt32(344,this.qform_code,this.littleEndian);view.setInt32(348,this.sform_code,this.littleEndian);view.setFloat64(352,this.quatern_b,this.littleEndian);view.setFloat64(360,this.quatern_c,this.littleEndian);view.setFloat64(368,this.quatern_d,this.littleEndian);view.setFloat64(376,this.qoffset_x,this.littleEndian);view.setFloat64(384,this.qoffset_y,this.littleEndian);view.setFloat64(392,this.qoffset_z,this.littleEndian);const flattened=this.affine.flat();for(let i=0;i<12;i++){view.setFloat64(400+DOUBLE_SIZE*i,flattened[i],this.littleEndian)}view.setInt32(496,this.slice_code,this.littleEndian);view.setInt32(500,this.xyzt_units,this.littleEndian);view.setInt32(504,this.intent_code,this.littleEndian);byteArray.set(Buffer.from(this.intent_name),508);view.setUint8(524,this.dim_info);if(includeExtensions){byteArray.set(Uint8Array.from([1,0,0,0]),540);let extensionByteIndex=this.getExtensionLocation();for(const extension of this.extensions){view.setInt32(extensionByteIndex,extension.esize,extension.littleEndian);view.setInt32(extensionByteIndex+4,extension.ecode,extension.littleEndian);byteArray.set(new Uint8Array(extension.edata),extensionByteIndex+8);extensionByteIndex+=extension.esize}}else{byteArray.set(new Uint8Array(4).fill(0),540)}return byteArray.buffer};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.NIFTI2}}).call(this)}).call(this,require("buffer").Buffer)},{"./nifti-extension.js":6,"./nifti1.js":8,"./utilities.js":10,buffer:2}],10:[function(require,module,exports){"use strict";var nifti=nifti||{};nifti.Utils=nifti.Utils||{};nifti.NIFTIEXTENSION=nifti.NIFTIEXTENSION||(typeof require!=="undefined"?require("./nifti-extension.js"):null);nifti.Utils.crcTable=null;nifti.Utils.GUNZIP_MAGIC_COOKIE1=31;nifti.Utils.GUNZIP_MAGIC_COOKIE2=139;nifti.Utils.getStringAt=function(data,start,end){var str="",ctr,ch;for(ctr=start;ctr=0;ctr--){value=value*256+array[ctr]}return value};nifti.Utils.getExtensionsAt=function(data,start,littleEndian,voxOffset){let extensions=[];let extensionByteIndex=start;while(extensionByteIndexvoxOffset){extensionLittleEndian=!extensionLittleEndian;esize=nifti.Utils.getIntAt(data,extensionByteIndex,extensionLittleEndian);if(esize+extensionByteIndex>voxOffset){throw new Error("This does not appear to be a valid NIFTI extension")}}if(esize%16!=0){throw new Error("This does not appear to be a NIFTI extension")}let ecode=nifti.Utils.getIntAt(data,extensionByteIndex+4,extensionLittleEndian);let edata=data.buffer.slice(extensionByteIndex+8,extensionByteIndex+esize);console.log("extensionByteIndex: "+(extensionByteIndex+8)+" esize: "+esize);console.log(edata);let extension=new nifti.NIFTIEXTENSION(esize,ecode,edata,extensionLittleEndian);extensions.push(extension);extensionByteIndex+=esize}return extensions};nifti.Utils.toArrayBuffer=function(buffer){var ab,view,i;ab=new ArrayBuffer(buffer.length);view=new Uint8Array(ab);for(i=0;i>>1:c>>>1}crcTable[n]=c}return crcTable};nifti.Utils.crc32=function(dataView){var crcTable=nifti.Utils.crcTable||(nifti.Utils.crcTable=nifti.Utils.makeCRCTable());var crc=0^-1;for(var i=0;i>>8^crcTable[(crc^dataView.getUint8(i))&255]}return(crc^-1)>>>0};var moduleType=typeof module;if(moduleType!=="undefined"&&module.exports){module.exports=nifti.Utils}},{"./nifti-extension.js":6}]},{},[7])(7)}); \ No newline at end of file diff --git a/release/current/nifti-reader.js b/release/current/nifti-reader.js index fde31ae..d802e51 100644 --- a/release/current/nifti-reader.js +++ b/release/current/nifti-reader.js @@ -5118,6 +5118,12 @@ nifti.NIFTI1.prototype.readHeader = function (data) { // Added by znshje on 27/11/2021 // /* See: https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h */ + if ((this.qform_code < 1) && (this.sform_code < 1)) { + // METHOD 0 (used when both SFORM and QFORM are unknown) + this.affine[0][0] = this.pixDims[1]; + this.affine[1][1] = this.pixDims[2]; + this.affine[2][2] = this.pixDims[3]; + } if ((this.qform_code > 0) && (this.sform_code < this.qform_code)) { // METHOD 2 (used when qform_code > 0, which should be the "normal" case): // --------------------------------------------------------------------- diff --git a/src/nifti1.js b/src/nifti1.js index 66de6dc..abd93e6 100644 --- a/src/nifti1.js +++ b/src/nifti1.js @@ -238,6 +238,12 @@ nifti.NIFTI1.prototype.readHeader = function (data) { // Added by znshje on 27/11/2021 // /* See: https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h */ + if ((this.qform_code < 1) && (this.sform_code < 1)) { + // METHOD 0 (used when both SFORM and QFORM are unknown) + this.affine[0][0] = this.pixDims[1]; + this.affine[1][1] = this.pixDims[2]; + this.affine[2][2] = this.pixDims[3]; + } if ((this.qform_code > 0) && (this.sform_code < this.qform_code)) { // METHOD 2 (used when qform_code > 0, which should be the "normal" case): // ---------------------------------------------------------------------