brocha
Version:
Universal Brotli decompressor written in 100% TypeScript with zero dependencies. Blazing fast, lightweight, and compatible with any ES2015+ environment.
15 lines • 192 kB
JavaScript
// deno-fmt-ignore-file
// deno-lint-ignore-file
/*!
* brocha v0.1.0 · fast universal compression killer in pure JS
* ----------------------------------------------------------------------
* Copyright (c) 2024 Nicholas Berlette. All rights reserved. MIT.
* Copyright (c) 2017 Google Inc. All rights reserved. MIT License.
* @license https://nick.mit-license.org
* @see https://jsr.io/@nick/brocha/doc for the latest API reference
* @see https://github.com/nberlette/brocha for the brocha source code
* @see https://github.com/google/brotli for the original C source code
* ----------------------------------------------------------------------
* @generated 2025-01-01T01:15:00.679Z
*/
var brocha=(()=>{var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __typeError=msg=>{throw TypeError(msg)};var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value),__accessCheck=(obj,member,msg)=>member.has(obj)||__typeError("Cannot "+msg);var __privateGet=(obj,member,getter)=>(__accessCheck(obj,member,"read from private field"),getter?getter.call(obj):member.get(obj)),__privateAdd=(obj,member,value)=>member.has(obj)?__typeError("Cannot add the same private member more than once"):member instanceof WeakSet?member.add(obj):member.set(obj,value),__privateSet=(obj,member,value,setter)=>(__accessCheck(obj,member,"write to private field"),setter?setter.call(obj,value):member.set(obj,value),value);var mod_exports={};__export(mod_exports,{BrotliDecoderAllocBlockTypeTreesError:()=>BrotliDecoderAllocBlockTypeTreesError,BrotliDecoderAllocContextMapError:()=>BrotliDecoderAllocContextMapError,BrotliDecoderAllocContextModesError:()=>BrotliDecoderAllocContextModesError,BrotliDecoderAllocRingBuffer1Error:()=>BrotliDecoderAllocRingBuffer1Error,BrotliDecoderAllocRingBuffer2Error:()=>BrotliDecoderAllocRingBuffer2Error,BrotliDecoderAllocTreeGroupsError:()=>BrotliDecoderAllocTreeGroupsError,BrotliDecoderBlockLength1Error:()=>BrotliDecoderBlockLength1Error,BrotliDecoderBlockLength2Error:()=>BrotliDecoderBlockLength2Error,BrotliDecoderClSpaceError:()=>BrotliDecoderClSpaceError,BrotliDecoderContextMapRepeatError:()=>BrotliDecoderContextMapRepeatError,BrotliDecoderDictionaryError:()=>BrotliDecoderDictionaryError,BrotliDecoderDictionaryNotSetError:()=>BrotliDecoderDictionaryNotSetError,BrotliDecoderDistanceError:()=>BrotliDecoderDistanceError,BrotliDecoderError:()=>BrotliDecoderError,BrotliDecoderErrorResult:()=>BrotliDecoderErrorResult,BrotliDecoderExuberantMetaNibbleError:()=>BrotliDecoderExuberantMetaNibbleError,BrotliDecoderExuberantNibbleError:()=>BrotliDecoderExuberantNibbleError,BrotliDecoderHuffmanSpaceError:()=>BrotliDecoderHuffmanSpaceError,BrotliDecoderInvalidArgumentsError:()=>BrotliDecoderInvalidArgumentsError,BrotliDecoderNeedsMoreInputResult:()=>BrotliDecoderNeedsMoreInputResult,BrotliDecoderNeedsMoreOutputResult:()=>BrotliDecoderNeedsMoreOutputResult,BrotliDecoderNoError:()=>BrotliDecoderNoError,BrotliDecoderPadding1Error:()=>BrotliDecoderPadding1Error,BrotliDecoderPadding2Error:()=>BrotliDecoderPadding2Error,BrotliDecoderReservedError:()=>BrotliDecoderReservedError,BrotliDecoderResult:()=>BrotliDecoderResult,BrotliDecoderSimpleHuffmanAlphabetError:()=>BrotliDecoderSimpleHuffmanAlphabetError,BrotliDecoderSimpleHuffmanSameError:()=>BrotliDecoderSimpleHuffmanSameError,BrotliDecoderSuccessResult:()=>BrotliDecoderSuccessResult,BrotliDecoderTransformError:()=>BrotliDecoderTransformError,BrotliDecoderUnknownError:()=>BrotliDecoderUnknownError,BrotliDecoderUnreachableError:()=>BrotliDecoderUnreachableError,BrotliDecoderWindowBitsError:()=>BrotliDecoderWindowBitsError,State:()=>State,decompress:()=>decompress,default:()=>decompress_default});var $global=(()=>{if(typeof globalThis=="object"&&globalThis)return globalThis;try{return(0,eval)("this")}catch{if(typeof global=="object"&&global)return global;if(typeof window=="object"&&window)return window;if(typeof root=="object"&&root)return root;if(typeof self=="object"&&self)return self;throw{message:"Unable to locate global `this`",toString(){return this.message}}}})(),Object2=$global.Object,ObjectGetPrototypeOf=Object2.getPrototypeOf,ObjectDefineProperty=Object2.defineProperty,ObjectGetOwnPropertyDescriptor=Object2.getOwnPropertyDescriptor,ObjectFreeze=Object2.freeze,{bind,call}=$global.Function.prototype,uncurryThis=fn=>{let bound=bind.call(call,fn);return ObjectDefineProperty(bound,"name",{value:fn.name}),bound};function lookupGetter(o,p,_allowUndefined){return ObjectGetOwnPropertyDescriptor(o,p)?.get??(()=>{})}var toString=uncurryThis(Object2.prototype.toString),Error2=$global.Error,TypeError2=$global.TypeError,RangeError=$global.RangeError,ReferenceError2=$global.ReferenceError,Array=$global.Array,Symbol2=$global.Symbol,String=$global.String,StringFromCharCode=String.fromCharCode,StringPrototype=String.prototype,StringPrototypeCharCodeAt=uncurryThis(StringPrototype.charCodeAt),StringPrototypeReplace=uncurryThis(StringPrototype.replace),StringPrototypeSlice=uncurryThis(StringPrototype.slice),StringPrototypeCodePointAt=uncurryThis(StringPrototype.codePointAt),StringPrototypeToLowerCase=uncurryThis(StringPrototype.toLowerCase),ArrayBuffer=$global.ArrayBuffer,ArrayBufferIsView=ArrayBuffer.isView,ArrayBufferPrototype=ArrayBuffer.prototype,ArrayBufferPrototypeGetByteLength=uncurryThis(lookupGetter(ArrayBuffer.prototype,"byteLength")),SharedArrayBuffer=$global.SharedArrayBuffer,SharedArrayBufferPrototype=SharedArrayBuffer.prototype,SharedArrayBufferPrototypeGetByteLength=uncurryThis(lookupGetter(SharedArrayBuffer.prototype,"byteLength")),Uint8Array2=$global.Uint8Array,Uint8ArrayPrototypeSlice=uncurryThis(Uint8Array2.prototype.slice),Uint8ArrayPrototypeSubarray=uncurryThis(Uint8Array2.prototype.subarray),DataView=$global.DataView,Int16Array2=$global.Int16Array,Int16ArrayOf=Int16Array2?.of.bind(Int16Array2),Int32Array=$global.Int32Array,Int32ArrayOf=Int32Array?.of.bind(Int32Array),Int8Array=$global.Int8Array,TypedArray=ObjectGetPrototypeOf(Uint8Array2),TypedArrayPrototype=TypedArray?.prototype,TypedArrayPrototypeGetToStringTag=lookupGetter(TypedArrayPrototype,Symbol2.toStringTag),TypedArrayPrototypeSubarray=uncurryThis(TypedArrayPrototype.subarray);var MAX_HUFFMAN_TABLE_SIZE=Int32ArrayOf(256,402,436,468,500,534,566,598,630,662,694,726,758,790,822,854,886,920,952,984,1016,1048,1080),CODE_LENGTH_CODE_ORDER=Int32ArrayOf(1,2,3,4,0,5,17,6,16,7,8,9,10,11,12,13,14,15),DSC_INDEX_OFFSET=Int32ArrayOf(0,3,2,1,0,0,0,0,0,0,3,3,3,3,3,3),DSC_VALUE_OFFSET=Int32ArrayOf(0,0,0,0,-1,1,-2,2,-3,3,-1,1,-2,2,-3,3),FIXED_TABLE=Int32ArrayOf(131072,131076,131075,196610,131072,131076,131075,262145,131072,131076,131075,196610,131072,131076,131075,262149),BLOCK_LENGTH_OFFSET=Int32ArrayOf(1,5,9,13,17,25,33,41,49,65,81,97,113,145,177,209,241,305,369,497,753,1265,2289,4337,8433,16625),BLOCK_LENGTH_N_BITS=Int32ArrayOf(2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,7,8,9,10,11,12,13,24),INSERT_LENGTH_N_BITS=Int16ArrayOf(0,0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,12,14,24),COPY_LENGTH_N_BITS=Int16ArrayOf(0,0,0,0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,24),LOOKUP=unpackLookupTable(new Int32Array(2048)),COMMAND_LOOKUP_TABLE=unpackCommandLookupTable(new Int16Array(2816));function unpackCommandLookupTable(cmdLookup){let insertLengthOffsets=new Int32Array(24),copyLengthOffsets=new Int32Array(24);copyLengthOffsets[0]=2;for(let i=0;i<23;++i)insertLengthOffsets[i+1]=insertLengthOffsets[i]+(1<<INSERT_LENGTH_N_BITS[i]),copyLengthOffsets[i+1]=copyLengthOffsets[i]+(1<<COPY_LENGTH_N_BITS[i]);for(let cmdCode=0;cmdCode<704;++cmdCode){let rangeIdx=cmdCode>>>6,distanceContextOffset=-4;rangeIdx>=2&&(rangeIdx-=2,distanceContextOffset=0);let insertCode=(170064>>>rangeIdx*2&3)<<3|cmdCode>>>3&7,copyCode=(156228>>>rangeIdx*2&3)<<3|cmdCode&7,copyLengthOffset=copyLengthOffsets[copyCode],distanceContext=distanceContextOffset+(copyLengthOffset>4?3:copyLengthOffset-2),index=cmdCode*4;cmdLookup[index]=INSERT_LENGTH_N_BITS[insertCode]|COPY_LENGTH_N_BITS[copyCode]<<8,cmdLookup[index+1]=insertLengthOffsets[insertCode],cmdLookup[index+2]=copyLengthOffsets[copyCode],cmdLookup[index+3]=distanceContext}return cmdLookup}function unpackLookupTable(lookup){let map=` !! ! "#$##%#$&'##(#)#++++++++++((&*'##,---,---,-----,-----,-----&#'###.///.///./////./////./////&#'# `,rle="A/* ': & : $ \x81 @";for(let i=0;i<256;++i)lookup[i]=i&63,lookup[512+i]=i>>2,lookup[1792+i]=2+(i>>6);for(let i=0;i<128;++i)lookup[1024+i]=4*(StringPrototypeCharCodeAt(map,i)-32);for(let i=0;i<64;++i)lookup[1152+i]=i&1,lookup[1216+i]=2+(i&1);let offset=1280;for(let k=0;k<19;++k){let value=k&3,rep=rle.charCodeAt(k)-32;for(let i=0;i<rep;++i)lookup[offset++]=value}for(let i=0;i<16;++i)lookup[1792+i]=1,lookup[2032+i]=6;lookup[1792]=0,lookup[2047]=7;for(let i=0;i<256;++i)lookup[1536+i]=lookup[1792+i]<<3;return lookup}function getNextKey(key,len){let step=1<<len-1;for(;key&step;)step=step>>1;return(key&step-1)+step}function replicateValue(table,offset,step,end,item){let pos=end;do pos-=step,table[offset+pos]=item;while(pos>0)}function nextTableBitSize(count,len,rootBits){let bits=len,left=1<<bits-rootBits;for(;bits<15&&(left-=count[bits],!(left<=0));)bits++,left<<=1;return bits-rootBits}function buildHuffmanTable(tableGroup,tableIdx,rootBits,codeLengths,codeLengthsSize){let tableOffset=tableGroup[tableIdx],sorted=new Int32Array(codeLengthsSize),count=new Int32Array(16),offset=new Int32Array(16);for(let sym=0;sym<codeLengthsSize;++sym)count[codeLengths[sym]]++;offset[1]=0;for(let len=1;len<15;++len)offset[len+1]=offset[len]+count[len];for(let sym=0;sym<codeLengthsSize;++sym)codeLengths[sym]!==0&&(sorted[offset[codeLengths[sym]]++]=sym);let tableBits=rootBits,tableSize=1<<tableBits,totalSize=tableSize;if(offset[15]===1){for(let k=0;k<totalSize;++k)tableGroup[tableOffset+k]=sorted[0];return totalSize}let key=0,symbol=0,step=1;for(let len=1;len<=rootBits;++len)for(step<<=1;count[len]>0;)replicateValue(tableGroup,tableOffset+key,step,tableSize,len<<16|sorted[symbol++]),key=getNextKey(key,len),count[len]--;let mask=totalSize-1,low=-1,currentOffset=tableOffset;step=1;for(let len=rootBits+1;len<=15;++len)for(step<<=1;count[len]>0;)(key&mask)!==low&&(currentOffset+=tableSize,tableBits=nextTableBitSize(count,len,rootBits),tableSize=1<<tableBits,totalSize+=tableSize,low=key&mask,tableGroup[tableOffset+low]=tableBits+rootBits<<16|currentOffset-tableOffset-low),replicateValue(tableGroup,currentOffset+(key>>rootBits),step,tableSize,len-rootBits<<16|sorted[symbol++]),key=getNextKey(key,len),count[len]--;return totalSize}function log2floor(i){let result=-1,step=16,v=i;for(;step>0;){let next=v>>>step;next!==0&&(result+=step,v=next),step=step>>1}return result+v}function isTypedArray(it,type){try{let tag=TypedArrayPrototypeGetToStringTag?.call(it);return typeof tag<"u"&&(type==null||tag===type)}catch{return!1}}function toUsAsciiBytes(src){let n=src.length,result=new Int8Array(n);for(let i=0;i<n;++i)result[i]=StringPrototypeCharCodeAt(src,i);return result}function toInt8Array(bs){if(typeof bs=="string")return toUsAsciiBytes(bs);if(isTypedArray(bs,"Int8Array"))return bs;if(ArrayBufferIsView(bs)){let{buffer,byteOffset,byteLength}=bs;return new Int8Array(buffer,byteOffset,byteLength)}return new Int8Array(bs)}var InputStream=class{constructor(data,offset=0){this.offset=offset;__publicField(this,"data",new Int8Array(0));data&&(this.data=toInt8Array(data))}};var _BrotliDecoderError=class _BrotliDecoderError extends Error2{constructor(message,options){if(new.target===_BrotliDecoderError)throw new TypeError2("Abstract class BrotliDecoderError cannot be instantiated directly.");let{cause,message:msg}=options??(options={});super(message??msg??cause+"",{cause});__publicField(this,"message");__publicField(this,"options",{});this.options=options,this.message=options.message??(options.message=this.message??cause+""),this.code=options.code??(options.code=this.code??0),this.kind=options.kind??(options.kind=this.kind??"UNKNOWN")}get name(){return`${_BrotliDecoderError.prefix}_${this.kind}`}get cause(){return super.cause??this.options.cause}toJSON(){let{code,name,kind,message,cause,stack}=this;return{code,kind,name,message,cause,stack}}};__publicField(_BrotliDecoderError,"prefix","BROTLI_DECODER_ERROR");var BrotliDecoderError=_BrotliDecoderError,BrotliDecoderUnknownError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",0);__publicField(this,"kind","UNKNOWN");__publicField(this,"message","Unknown error occurred.")}},BrotliDecoderUnreachableError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-31);__publicField(this,"kind","UNREACHABLE");__publicField(this,"message","Unreachable code reached.")}},BrotliDecoderAllocBlockTypeTreesError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-30);__publicField(this,"kind","ALLOC_BLOCK_TYPE_TREES");__publicField(this,"message","Failed to allocate block kind trees.")}},BrotliDecoderAllocRingBuffer2Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-27);__publicField(this,"kind","ALLOC_RING_BUFFER_2");__publicField(this,"message","Failed to allocate ring buffer 2.")}},BrotliDecoderAllocRingBuffer1Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-26);__publicField(this,"kind","ALLOC_RING_BUFFER_1");__publicField(this,"message","Failed to allocate ring buffer 1.")}},BrotliDecoderAllocContextMapError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-25);__publicField(this,"kind","ALLOC_CONTEXT_MAP");__publicField(this,"message","Failed to allocate context map.")}},BrotliDecoderAllocTreeGroupsError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-22);__publicField(this,"kind","ALLOC_TREE_GROUPS");__publicField(this,"message","Failed to allocate tree groups.")}},BrotliDecoderAllocContextModesError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-21);__publicField(this,"kind","ALLOC_CONTEXT_MODES");__publicField(this,"message","Failed to allocate context modes.")}},BrotliDecoderInvalidArgumentsError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-20);__publicField(this,"kind","INVALID_ARGUMENTS");__publicField(this,"message","Invalid arguments.")}},BrotliDecoderDictionaryNotSetError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-19);__publicField(this,"kind","DICTIONARY_NOT_SET");__publicField(this,"message","Dictionary not set.")}},BrotliDecoderDistanceError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-16);__publicField(this,"kind","FORMAT_DISTANCE");__publicField(this,"message","Invalid distance found.")}},BrotliDecoderPadding2Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-15);__publicField(this,"kind","FORMAT_PADDING_2");__publicField(this,"message","Invalid padding bits found in the last metablock.")}},BrotliDecoderPadding1Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-14);__publicField(this,"kind","FORMAT_PADDING_1");__publicField(this,"message","Invalid padding bits found.")}},BrotliDecoderWindowBitsError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-13);__publicField(this,"kind","FORMAT_WINDOW_BITS");__publicField(this,"message","Invalid window size found.")}},BrotliDecoderDictionaryError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-12);__publicField(this,"kind","FORMAT_DICTIONARY");__publicField(this,"message","Invalid dictionary size or distance found.")}},BrotliDecoderTransformError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-11);__publicField(this,"kind","FORMAT_TRANSFORM");__publicField(this,"message","Reserved transform found.")}},BrotliDecoderBlockLength2Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-10);__publicField(this,"kind","FORMAT_BLOCK_LENGTH_2");__publicField(this,"message","Block length is too long.")}},BrotliDecoderBlockLength1Error=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-9);__publicField(this,"kind","FORMAT_BLOCK_LENGTH_1");__publicField(this,"message","Block length is too short.")}},BrotliDecoderContextMapRepeatError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-8);__publicField(this,"kind","FORMAT_CONTEXT_MAP_REPEAT");__publicField(this,"message","Context map repeat is too long.")}},BrotliDecoderHuffmanSpaceError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-7);__publicField(this,"kind","FORMAT_HUFFMAN_SPACE");__publicField(this,"message","Distance code is too far back for the huffman code.")}},BrotliDecoderClSpaceError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-6);__publicField(this,"kind","FORMAT_CL_SPACE");__publicField(this,"message","Distance code is too far back.")}},BrotliDecoderSimpleHuffmanSameError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-5);__publicField(this,"kind","FORMAT_SIMPLE_HUFFMAN_SAME");__publicField(this,"message","Duplicate simple Huffman symbols.")}},BrotliDecoderSimpleHuffmanAlphabetError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-4);__publicField(this,"kind","FORMAT_SIMPLE_HUFFMAN_ALPHABET");__publicField(this,"message","Simple Huffman code alphabet error.")}},BrotliDecoderExuberantMetaNibbleError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-3);__publicField(this,"kind","FORMAT_EXUBERANT_META_NIBBLE");__publicField(this,"message","Invalid meta-block nibble.")}},BrotliDecoderReservedError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-2);__publicField(this,"kind","FORMAT_RESERVED");__publicField(this,"message","Reserved format error.")}},BrotliDecoderExuberantNibbleError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",-1);__publicField(this,"kind","FORMAT_EXUBERANT_NIBBLE");__publicField(this,"message","Invalid nibble.")}},BrotliDecoderNoError=class extends BrotliDecoderError{constructor(){super(...arguments);__publicField(this,"code",0);__publicField(this,"kind","NO_ERROR");__publicField(this,"message","No error occurred.")}},BrotliDecoderResult=class _BrotliDecoderResult extends Error2{constructor(message){if(new.target===_BrotliDecoderResult)throw new TypeError2("Abstract class BrotliDecoderResult cannot be instantiated directly.");super(message||"");__publicField(this,"message","");this.message=message||this.message||""}toJSON(){let{code,kind,message}=this;return{type:"BrotliDecoderResult",code,kind,message}}},BrotliDecoderErrorResult=class extends BrotliDecoderResult{constructor(error){super(`Decompression failed: ${error.message}`);this.error=error;__publicField(this,"code",0);__publicField(this,"kind","BROTLI_DECODER_RESULT_ERROR")}},BrotliDecoderSuccessResult=class extends BrotliDecoderResult{constructor(){super(...arguments);__publicField(this,"code",1);__publicField(this,"kind","BROTLI_DECODER_RESULT_SUCCESS");__publicField(this,"message","Decompression successful.")}},BrotliDecoderNeedsMoreInputResult=class extends BrotliDecoderResult{constructor(){super(...arguments);__publicField(this,"code",2);__publicField(this,"kind","BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT");__publicField(this,"message","Decoder needs more input data to continue.")}},BrotliDecoderNeedsMoreOutputResult=class extends BrotliDecoderResult{constructor(){super(...arguments);__publicField(this,"code",3);__publicField(this,"kind","BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT");__publicField(this,"message","Decoder needs more output space to continue.")}};var Transforms=class{constructor(numTransforms,prefixSuffixLen,prefixSuffixCount){this.numTransforms=numTransforms;this.prefixSuffixLen=prefixSuffixLen;this.prefixSuffixCount=prefixSuffixCount;__publicField(this,"triplets",new Int32Array(0));__publicField(this,"prefixSuffixStorage",new Int8Array(0));__publicField(this,"prefixSuffixHeads",new Int32Array(0));__publicField(this,"params",new Int16Array2(0));this.numTransforms=numTransforms,this.triplets=new Int32Array(numTransforms*3),this.params=new Int16Array2(numTransforms),this.prefixSuffixStorage=new Int8Array(prefixSuffixLen),this.prefixSuffixHeads=new Int32Array(prefixSuffixCount+1)}unpack(prefixSuffixSrc,transformsSrc){let expectedLen=this.prefixSuffixLen+this.prefixSuffixCount,n=prefixSuffixSrc.length;if(n!==expectedLen)throw new BrotliDecoderTransformError(`PrefixSuffix length mismatch: ${n} != ${expectedLen} expected`);let index=1,j=0;for(let i=0;i<n;++i){let c=prefixSuffixSrc.charCodeAt(i);c===35?this.prefixSuffixHeads[index++]=j:this.prefixSuffixStorage[j++]=c}if(transformsSrc.length!==this.triplets.length)throw new BrotliDecoderTransformError(`transformsSrc length mismatch: ${transformsSrc.length} != ${this.triplets.length} expected`);for(let i=0;i<this.triplets.length;++i)this.triplets[i]=transformsSrc.charCodeAt(i)-32;return this}transformDictionaryWord(dst,dstOffset,src,srcOffset,wordLen,transformIndex){let offset=dstOffset,transformOffset=3*transformIndex,prefixIdx=this.triplets[transformOffset],transform=this.triplets[transformOffset+1],suffixIdx=this.triplets[transformOffset+2],prefixEnd=this.prefixSuffixHeads[prefixIdx+1],suffixEnd=this.prefixSuffixHeads[suffixIdx+1],prefix=this.prefixSuffixHeads[prefixIdx],suffix=this.prefixSuffixHeads[suffixIdx],omitFirst=transform-11,omitLast=transform;for((omitFirst<1||omitFirst>9)&&(omitFirst=0),(omitLast<1||omitLast>9)&&(omitLast=0);prefix!==prefixEnd;)dst[offset++]=this.prefixSuffixStorage[prefix++];let len=wordLen;omitFirst>len&&(omitFirst=len);let dictOffset=srcOffset+omitFirst;for(let i=len-=omitFirst+omitLast;i>0;i--)dst[offset++]=src[dictOffset++];if(transform===10||transform===11){let upperOffset=offset-len;for(transform===10&&(len=1);len>0;){let c0=dst[upperOffset]&255;c0<192?(c0>=97&&c0<=122&&(dst[upperOffset]=dst[upperOffset]^32),upperOffset+=1,len-=1):c0<224?(dst[upperOffset+1]=dst[upperOffset+1]^32,upperOffset+=2,len-=2):(dst[upperOffset+2]=dst[upperOffset+2]^5,upperOffset+=3,len-=3)}}else if(transform===21||transform===22){let shift=offset-len,param=this.params[transformIndex],scalar=(param&32767)+(16777216-(param&32768));for(;len>0;){let step=1,c0=dst[shift]&255;if(c0<128)scalar+=c0,dst[shift]=scalar&127;else if(!(c0<192)){if(c0<224)if(len>=2){let c1=dst[shift+1];scalar+=c1&63|(c0&31)<<6,dst[shift]=192|scalar>>6&31,dst[shift+1]=c1&192|scalar&63,step=2}else step=len;else if(c0<240)if(len>=3){let c1=dst[shift+1],c2=dst[shift+2];scalar+=c2&63|(c1&63)<<6|(c0&15)<<12,dst[shift]=224|scalar>>12&15,dst[shift+1]=c1&192|scalar>>6&63,dst[shift+2]=c2&192|scalar&63,step=3}else step=len;else if(c0<248)if(len>=4){let c1=dst[shift+1],c2=dst[shift+2],c3=dst[shift+3];scalar+=c3&63|(c2&63)<<6|(c1&63)<<12|(c0&7)<<18,dst[shift]=240|scalar>>18&7,dst[shift+1]=c1&192|scalar>>12&63,dst[shift+2]=c2&192|scalar>>6&63,dst[shift+3]=c3&192|scalar&63,step=4}else step=len}shift+=step,len-=step,transform===21&&(len=0)}}for(;suffix!==suffixEnd;)dst[offset++]=this.prefixSuffixStorage[suffix++];return offset-dstOffset}};var _initialized,_dictionaryData,_transforms,_offsets,_sizeBits,_State=class _State{constructor(bytes,dict){__publicField(this,"input",new InputStream(new Int8Array(0)));__publicField(this,"totalOutput",0);__publicField(this,"outputUsed",0);__publicField(this,"outputOffset",0);__publicField(this,"outputLength",0);__publicField(this,"expectedTotalSize",0);__publicField(this,"runningState",0);__publicField(this,"nextRunningState",0);__publicField(this,"chunks",[]);__publicField(this,"byteBuffer",new Int8Array(0));__publicField(this,"output",new Int8Array(0));__publicField(this,"ringBuffer",new Int8Array(0));__publicField(this,"contextModes",new Int8Array(0));__publicField(this,"contextMap",new Int8Array(0));__publicField(this,"distContextMap",new Int8Array(0));__publicField(this,"distExtraBits",new Int8Array(0));__publicField(this,"shortBuffer",new Int16Array2(0));__publicField(this,"rings",new Int32Array(0));__publicField(this,"blockTrees",new Int32Array(0));__publicField(this,"commandTreeGroup",new Int32Array(0));__publicField(this,"distanceTreeGroup",new Int32Array(0));__publicField(this,"literalTreeGroup",new Int32Array(0));__publicField(this,"distOffset",new Int32Array(0));__publicField(this,"bitOffset",0);__publicField(this,"halfOffset",0);__publicField(this,"accumulator32",0);__publicField(this,"tailBytes",0);__publicField(this,"endOfStreamReached",0);__publicField(this,"inputEnd",0);__publicField(this,"isUncompressed",0);__publicField(this,"isMetadata",0);__publicField(this,"isEager",0);__publicField(this,"isLargeWindow",0);__publicField(this,"numLiteralBlockTypes",0);__publicField(this,"numCommandBlockTypes",0);__publicField(this,"numDistanceBlockTypes",0);__publicField(this,"trivialLiteralContext",0);__publicField(this,"literalTreeIdx",0);__publicField(this,"commandTreeIdx",0);__publicField(this,"pos",0);__publicField(this,"j",0);__publicField(this,"contextMapSlice",0);__publicField(this,"contextLookupOffset1",0);__publicField(this,"contextLookupOffset2",0);__publicField(this,"numDirectDistanceCodes",0);__publicField(this,"insertLength",0);__publicField(this,"copyLength",0);__publicField(this,"metaBlockLength",0);__publicField(this,"commandBlockLength",0);__publicField(this,"literalBlockLength",0);__publicField(this,"distanceBlockLength",0);__publicField(this,"distContextMapSlice",0);__publicField(this,"distanceCode",0);__publicField(this,"distancePostfixBits",0);__publicField(this,"distance",0);__publicField(this,"distRbIdx",0);__publicField(this,"maxDistance",0);__publicField(this,"maxBackwardDistance",0);__publicField(this,"maxRingBufferSize",0);__publicField(this,"ringBufferSize",0);__publicField(this,"ringBufferBytesWritten",0);__publicField(this,"ringBufferBytesReady",0);__publicField(this,"cdNumChunks",0);__publicField(this,"cdTotalSize",0);__publicField(this,"cdBrIndex",0);__publicField(this,"cdBrOffset",0);__publicField(this,"cdBrLength",0);__publicField(this,"cdBrCopied",0);__publicField(this,"cdChunks",[]);__publicField(this,"cdChunkOffsets",new Int32Array(0));__publicField(this,"cdBlockBits",0);__publicField(this,"cdBlockMap",new Int8Array(0));!dict&&!_State.initialized&&(_State.initializeDefaultDictionary(),__privateSet(_State,_initialized,!0)),this.ringBuffer=new Int8Array(0),this.rings=new Int32Array(10),this.rings[0]=16,this.rings[1]=15,this.rings[2]=11,this.rings[3]=4,bytes&&(this.input=new InputStream(bytes)),this.init(),dict&&this.attachDictionaryChunk(dict)}decompress(){for(this.totalOutput=0,this.chunks.length=0;;){let chunk=new Int8Array(16384);if(this.chunks.push(chunk),this.output=chunk,this.outputOffset=0,this.outputLength=16384,this.outputUsed=0,this.decompressChunk(),this.totalOutput+=this.outputUsed,this.outputUsed<16384)break}this.close();let result=new Int8Array(this.totalOutput);for(let offset=0,i=0;i<this.chunks.length;++i){let chunk=this.chunks[i],end=offset+16384;end>this.totalOutput&&(end=this.totalOutput);let len=end-offset;len<16384?result.set(chunk.subarray(0,len),offset):result.set(chunk,offset),offset+=len}this.chunks.length=0;let{buffer,byteOffset,byteLength}=result;return new Uint8Array2(buffer,byteOffset,byteLength)}readInput(data,offset,length){if(this.input==null)return-1;let src=this.input,end=src.offset+length;end>src.data.length&&(end=src.data.length);let bytesRead=end-src.offset;return data.set(src.data.subarray(src.offset,end),offset),src.offset+=bytesRead,bytesRead}init(){if(this.runningState!==0)throw new BrotliDecoderUnreachableError("State must be uninitialized");this.blockTrees=new Int32Array(3091),this.blockTrees[0]=7,this.distRbIdx=3;let maxDistanceAlphabetLimit=this.calculateDistanceAlphabetLimit(2147483644,3,120);return this.distExtraBits=new Int8Array(maxDistanceAlphabetLimit),this.distOffset=new Int32Array(maxDistanceAlphabetLimit),this.initBitReader(),this.runningState=1,this}initBitReader(){return this.byteBuffer=new Int8Array(4160),this.accumulator32=0,this.shortBuffer=new Int16Array2(2080),this.bitOffset=32,this.halfOffset=2048,this.endOfStreamReached=0,this.prepare()}close(){if(this.runningState===0)throw new BrotliDecoderUnreachableError("State must be initialized");this.runningState!==11&&(this.runningState=11,this.input.data=new Int8Array(0),this.input.offset=0)}prepare(){return this.halfOffset>2030&&this.doReadMoreInput(),this.checkHealth(0),this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16,this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16,this}reload(){return this.bitOffset===32&&this.prepare(),this}attachDictionaryChunk(buf){if(this.runningState!==1)throw new BrotliDecoderUnreachableError("State must be freshly initialized");if(this.cdNumChunks===0&&(this.cdChunks=new Array(16),this.cdChunkOffsets=new Int32Array(16),this.cdBlockBits=-1),this.cdNumChunks===15)throw new BrotliDecoderDictionaryError("Too many dictionary chunks");let data;if(typeof buf=="string")data=toUsAsciiBytes(buf);else if(isTypedArray(buf,"Int8Array"))data=buf;else if(ArrayBufferIsView(buf)){let{buffer,byteOffset,byteLength}=buf;data=new Int8Array(buffer,byteOffset,byteLength)}else try{ArrayBufferPrototypeGetByteLength(buf),data=new Int8Array(buf)}catch{try{SharedArrayBufferPrototypeGetByteLength(buf),data=new Int8Array(buf)}catch{throw new BrotliDecoderInvalidArgumentsError("Invalid dictionary buffer type")}}this.cdChunks[this.cdNumChunks]=data,this.cdNumChunks++,this.cdTotalSize+=data.length,this.cdChunkOffsets[this.cdNumChunks]=this.cdTotalSize}initializeCompoundDictionary(){this.cdBlockMap=new Int8Array(256);let blockBits=8;for(;this.cdTotalSize-1>>>blockBits;)blockBits++;blockBits-=8,this.cdBlockBits=blockBits;let cursor=0,index=0;for(;cursor<this.cdTotalSize;){for(;this.cdChunkOffsets[index+1]<cursor;)index++;this.cdBlockMap[cursor>>>blockBits]=index,cursor+=1<<blockBits}}initializeCompoundDictionaryCopy(address,length){this.cdBlockBits===-1&&this.initializeCompoundDictionary();let index=this.cdBlockMap[address>>>this.cdBlockBits];for(;address>=this.cdChunkOffsets[index+1];)index++;if(this.cdTotalSize>address+length)throw new BrotliDecoderDictionaryError("Compound dictionary copy out of bounds");this.distRbIdx=this.distRbIdx+1&3,this.rings[this.distRbIdx]=this.distance,this.metaBlockLength-=length,this.cdBrIndex=index,this.cdBrOffset=address-this.cdChunkOffsets[index],this.cdBrLength=length,this.cdBrCopied=0}copyFromCompoundDictionary(fence){let pos=this.pos,origPos=pos;for(;this.cdBrLength!==this.cdBrCopied;){let space=fence-pos,remChunkLength=this.cdChunkOffsets[this.cdBrIndex+1]-this.cdChunkOffsets[this.cdBrIndex]-this.cdBrOffset,length=this.cdBrLength-this.cdBrCopied;if(length>remChunkLength&&(length=remChunkLength),length>space&&(length=space),this.ringBuffer.set(this.cdChunks[this.cdBrIndex].slice(this.cdBrOffset,this.cdBrOffset+length),pos),pos+=length,this.cdBrOffset+=length,this.cdBrCopied+=length,length===remChunkLength&&(this.cdBrIndex++,this.cdBrOffset=0),pos>=fence)break}return pos-origPos}copyRawBytes(data,offset,length){let pos=offset,len=length;if(this.bitOffset&7)throw new BrotliDecoderAllocRingBuffer1Error("Unaligned copy offset");for(;this.bitOffset!==32&&len!==0;)data[pos++]=this.accumulator32>>>this.bitOffset,this.bitOffset+=8,len--;if(len===0)return;let copyNibbles=this.halfAvailable();if(copyNibbles>len>>1&&(copyNibbles=len>>1),copyNibbles>0){let readOffset=this.halfOffset<<1,delta=copyNibbles<<1,chunk=this.byteBuffer.subarray(readOffset,readOffset+delta);data.set(chunk,pos),pos+=delta,len-=delta,this.halfOffset+=copyNibbles}if(len!==0){if(this.halfAvailable()>0){for(this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);len!==0;)data[pos++]=this.accumulator32>>>this.bitOffset,this.bitOffset+=8,len--;this.checkHealth(0);return}for(;len>0;){let chunkLen=this.readInput(data,pos,len);if(chunkLen===-1)throw new BrotliDecoderBlockLength2Error("Unexpected end of input");pos+=chunkLen,len-=chunkLen}}}copyUncompressedData(){let ringBuffer=this.ringBuffer;if(this.metaBlockLength<=0){this.reload(),this.runningState=2;return}let chunkLength=this.ringBufferSize-this.pos;if(chunkLength>this.metaBlockLength&&(chunkLength=this.metaBlockLength),this.copyRawBytes(ringBuffer,this.pos,chunkLength),this.metaBlockLength-=chunkLength,this.pos+=chunkLength,this.pos===this.ringBufferSize){this.nextRunningState=6,this.runningState=12;return}this.reload(),this.runningState=2}bytesToNibbles(byteLen){let byteBuffer=this.byteBuffer,shortBuffer=this.shortBuffer;for(let i=0;i<byteLen>>1;++i)shortBuffer[i]=byteBuffer[i*2]&255|(byteBuffer[i*2+1]&255)<<8}calculateDistanceLut(alphabetSizeLimit){let distExtraBits=this.distExtraBits,distOffset=this.distOffset,npostfix=this.distancePostfixBits,ndirect=this.numDirectDistanceCodes,postfix=1<<npostfix,bits=1,half=0,i=16;for(let j=0;j<ndirect;++j)distExtraBits[i]=0,distOffset[i]=j+1,++i;for(;i<alphabetSizeLimit;){let base=ndirect+((2+half<<bits)-4<<npostfix)+1;for(let j=0;j<postfix;++j)distExtraBits[i]=bits,distOffset[i]=base+j,++i;bits=bits+half,half=half^1}}calculateFence(){let result=this.ringBufferSize;if(this.isEager!==0){let offset=this.outputLength-this.outputUsed,next=this.ringBufferBytesWritten+offset;next<result&&(result=next)}return result}decompressChunk(){if(!_State.initialized||this.runningState===0)throw new BrotliDecoderDictionaryNotSetError("Dictionary not initialized");if(this.runningState===11)throw new BrotliDecoderUnreachableError("Cannot decompress after close");if(this.runningState===1){let windowBits=this.decodeWindowBits();if(windowBits===-1)throw new BrotliDecoderWindowBitsError("Invalid 'windowBits' code");this.maxRingBufferSize=1<<windowBits,this.maxBackwardDistance=this.maxRingBufferSize-16,this.runningState=2}let fence=this.ringBufferSize;if(this.isEager!==0){let offset=this.outputLength-this.outputUsed,next=this.ringBufferBytesWritten+offset;next<fence&&(fence=next)}let ringBufferMask=this.ringBufferSize-1,ringBuffer=this.ringBuffer;for(;this.runningState!==10;)switch(this.runningState){case 2:if(this.metaBlockLength<0)throw new BrotliDecoderBlockLength1Error("Invalid block length");if(this.readNextMetablockHeader(),fence=this.ringBufferSize,this.isEager!==0){let offset=this.outputLength-this.outputUsed,next=this.ringBufferBytesWritten+offset;next<fence&&(fence=next)}ringBufferMask=this.ringBufferSize-1,ringBuffer=this.ringBuffer;continue;case 3:this.readMetablockHuffmanCodesAndContextMaps(),this.runningState=4;case 4:{if(this.metaBlockLength<=0){this.runningState=2;continue}this.halfOffset>2030&&this.doReadMoreInput(),this.commandBlockLength===0&&(this.commandBlockLength=this.decodeBlockTypeAndLength(1,this.numCommandBlockTypes),this.commandTreeIdx=this.rings[7]),this.commandBlockLength--,this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let cmdCode=this.readSymbol(this.commandTreeGroup,this.commandTreeIdx)<<2,insertAndCopyExtraBits=COMMAND_LOOKUP_TABLE[cmdCode],insertLengthOffset=COMMAND_LOOKUP_TABLE[cmdCode+1],copyLengthOffset=COMMAND_LOOKUP_TABLE[cmdCode+2];this.distanceCode=COMMAND_LOOKUP_TABLE[cmdCode+3],this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let insertLengthExtraBits=insertAndCopyExtraBits&255;this.insertLength=insertLengthOffset+(insertLengthExtraBits<=16?this.readFewBits(insertLengthExtraBits):this.readManyBits(insertLengthExtraBits)),this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let copyLengthExtraBits=insertAndCopyExtraBits>>8;this.copyLength=copyLengthOffset+(copyLengthExtraBits<=16?this.readFewBits(copyLengthExtraBits):this.readManyBits(copyLengthExtraBits)),this.j=0,this.runningState=7}case 7:if(this.trivialLiteralContext!==0){for(;this.j<this.insertLength;)if(this.halfOffset>2030&&this.doReadMoreInput(),this.literalBlockLength||this.decodeLiteralBlockSwitch(),this.literalBlockLength--,this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),ringBuffer[this.pos]=this.readSymbol(this.literalTreeGroup,this.literalTreeIdx),this.pos++,this.j++,this.pos>=fence){this.nextRunningState=7,this.runningState=12;break}}else{let prev1=ringBuffer[this.pos-1&ringBufferMask]&255,prev2=ringBuffer[this.pos-2&ringBufferMask]&255;for(;this.j<this.insertLength;){this.halfOffset>2030&&this.doReadMoreInput(),this.literalBlockLength||this.decodeLiteralBlockSwitch();let literalContext=LOOKUP[this.contextLookupOffset1+prev1]|LOOKUP[this.contextLookupOffset2+prev2],literalTreeIdx=this.contextMap[this.contextMapSlice+literalContext]&255;if(this.literalBlockLength--,prev2=prev1,this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),prev1=this.readSymbol(this.literalTreeGroup,literalTreeIdx),ringBuffer[this.pos++]=prev1,this.j++,this.pos>=fence){this.nextRunningState=7,this.runningState=12;break}}}if(this.runningState!==7)continue;if(this.metaBlockLength-=this.insertLength,this.metaBlockLength<=0){this.runningState=4;continue}let dsc=this.distanceCode;if(dsc<0)this.distance=this.rings[this.distRbIdx];else{this.halfOffset>2030&&this.doReadMoreInput(),this.distanceBlockLength===0&&(this.distanceBlockLength=this.decodeBlockTypeAndLength(2,this.numDistanceBlockTypes),this.distContextMapSlice=this.rings[9]<<2),this.distanceBlockLength--,this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let slice=this.distContextMapSlice+dsc,distTreeIdx=this.distContextMap[slice]&255;if(dsc=this.readSymbol(this.distanceTreeGroup,distTreeIdx),dsc<16){let index=this.distRbIdx+DSC_INDEX_OFFSET[dsc]&3;if(this.distance=this.rings[index]+DSC_VALUE_OFFSET[dsc],this.distance<0)throw new BrotliDecoderDistanceError("Negative distance")}else{let extraBits=this.distExtraBits[dsc],bits;this.bitOffset+extraBits<=32?bits=this.readFewBits(extraBits):(this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),bits=extraBits<=16?this.readFewBits(extraBits):this.readManyBits(extraBits)),this.distance=this.distOffset[dsc]+(bits<<this.distancePostfixBits)}}if(this.maxDistance=this.maxDistance!==this.maxBackwardDistance&&this.pos<this.maxBackwardDistance?this.pos:this.maxBackwardDistance,this.distance>this.maxDistance){this.runningState=9;continue}if(dsc>0&&(this.distRbIdx+=1,this.rings[this.distRbIdx&=3]=this.distance),this.copyLength>this.metaBlockLength)throw new BrotliDecoderBlockLength2Error("Invalid copy length");this.j=0,this.runningState=8;case 8:let dst=this.pos,src=dst-this.distance&ringBufferMask,copyLength=this.copyLength-this.j,srcEnd=src+copyLength,dstEnd=dst+copyLength;if(srcEnd<ringBufferMask&&dstEnd<ringBufferMask){if(copyLength<12||srcEnd>dst&&dstEnd>src){let numQuads=copyLength+3>>2;for(let k=0;k<numQuads;++k)ringBuffer[dst++]=ringBuffer[src++],ringBuffer[dst++]=ringBuffer[src++],ringBuffer[dst++]=ringBuffer[src++],ringBuffer[dst++]=ringBuffer[src++]}else ringBuffer.copyWithin(dst,src,srcEnd);this.j+=copyLength,this.metaBlockLength-=copyLength,this.pos+=copyLength}else for(;this.j<this.copyLength;)if(ringBuffer[this.pos]=ringBuffer[this.pos-this.distance&ringBufferMask],this.metaBlockLength--,this.pos++,this.j++,this.pos>=fence){this.nextRunningState=8,this.runningState=12;break}this.runningState===8&&(this.runningState=4);continue;case 9:{if(this.distance>2147483644)throw new BrotliDecoderDistanceError("Invalid backward reference");let address=this.distance-this.maxDistance-1-this.cdTotalSize;if(address<0)this.initializeCompoundDictionaryCopy(-address-1,this.copyLength),this.runningState=14;else{let wordLength=this.copyLength;if(wordLength>31)throw new BrotliDecoderAllocRingBuffer1Error("Invalid backward reference");let shift=_State.sizeBits[wordLength];if(shift===0)throw new BrotliDecoderAllocRingBuffer1Error("Invalid backward reference");let offset=_State.offsets[wordLength],mask=(1<<shift)-1,wordIdx=address&mask,transformIdx=address>>>shift;offset+=wordIdx*wordLength;let transforms=__privateGet(_State,_transforms);if(!transforms)throw new BrotliDecoderDictionaryNotSetError("Dictionary not initialized");if(transformIdx>=transforms.numTransforms)throw new BrotliDecoderTransformError("Invalid backward reference");let len=transforms.transformDictionaryWord(this.ringBuffer,this.pos,_State.dictionaryData,offset,wordLength,transformIdx);if(this.pos+=len,this.metaBlockLength-=len,this.pos>=fence){this.nextRunningState=4,this.runningState=12;return}this.runningState=4}}continue;case 14:if(this.pos+=this.copyFromCompoundDictionary(fence),this.pos>=fence){this.nextRunningState=14,this.runningState=12;return}this.runningState=4;continue;case 5:for(;this.metaBlockLength>0;)this.halfOffset>2030&&this.doReadMoreInput(),this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),this.readFewBits(8),this.metaBlockLength--;this.runningState=2;continue;case 6:this.copyUncompressedData();continue;case 12:this.ringBufferBytesReady=this.ringBufferSize>this.pos?this.pos:this.ringBufferSize,this.runningState=13;case 13:if(this.writeRingBuffer()===0)return;this.pos>=this.maxBackwardDistance&&(this.maxDistance=this.maxBackwardDistance),this.pos>=this.ringBufferSize&&(this.pos>this.ringBufferSize&&ringBuffer.copyWithin(0,this.ringBufferSize,this.pos),this.pos=this.pos&ringBufferMask,this.ringBufferBytesWritten=0),this.runningState=this.nextRunningState;continue;default:throw new BrotliDecoderUnreachableError(`Unexpected state: ${this.runningState}`)}if(this.runningState===10){if(this.metaBlockLength<0)throw new BrotliDecoderBlockLength1Error("Invalid metablock length");this.jumpToByteBoundary(),this.checkHealth(1)}}doReadMoreInput(){if(this.endOfStreamReached!==0&&this.halfAvailable()<-2)throw new BrotliDecoderNeedsMoreInputResult;let readOffset=this.halfOffset<<1,bytesInBuffer=4096-readOffset;for(this.byteBuffer.copyWithin(0,readOffset,4096),this.halfOffset=0;bytesInBuffer<4096;){let spaceLeft=4096-bytesInBuffer,len=this.readInput(this.byteBuffer,bytesInBuffer,spaceLeft);if(len<=0){this.endOfStreamReached=1,this.tailBytes=bytesInBuffer,bytesInBuffer+=1;break}bytesInBuffer+=len}this.bytesToNibbles(bytesInBuffer)}checkHealth(endOfStream){if(this.endOfStreamReached!==0){let byteOffset=(this.halfOffset<<1)+(this.bitOffset+7>>3)-4;if(byteOffset>this.tailBytes)throw new BrotliDecoderNeedsMoreInputResult;if(endOfStream!==0&&byteOffset!==this.tailBytes)throw new BrotliDecoderNeedsMoreOutputResult}}readFewBits(n){let v=this.accumulator32>>>this.bitOffset&(1<<n)-1;return this.bitOffset+=n,v}readManyBits(n){let low=this.readFewBits(16);return this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16,low|this.readFewBits(n-16)<<16}jumpToByteBoundary(){let padding=32-this.bitOffset&7;if(padding!==0&&this.readFewBits(padding)!==0)throw new BrotliDecoderPadding1Error}halfAvailable(){let limit=2048;return this.endOfStreamReached!==0&&(limit=this.tailBytes+1>>1),limit-this.halfOffset}decodeWindowBits(){let isLargeWindow=this.isLargeWindow;if(this.isLargeWindow=0,this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),this.readFewBits(1)===0)return 16;let n=this.readFewBits(3);return n!==0?17+n:(n=this.readFewBits(3),n!==0?n===1?isLargeWindow===0||(this.isLargeWindow=1,this.readFewBits(1)===1)||(n=this.readFewBits(6),n<10||n>30)?-1:n:8+n:17)}decodeVarLenUnsignedByte(){if(this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),this.readFewBits(1)!==0){let n=this.readFewBits(3);return n===0?1:this.readFewBits(n)+(1<<n)}return 0}decodeLiteralBlockSwitch(){this.literalBlockLength=this.decodeBlockTypeAndLength(0,this.numLiteralBlockTypes);let literalBlockType=this.rings[5];this.contextMapSlice=literalBlockType<<6,this.literalTreeIdx=this.contextMap[this.contextMapSlice]&255;let contextMode=this.contextModes[literalBlockType];this.contextLookupOffset1=contextMode<<9,this.contextLookupOffset2=this.contextLookupOffset1+256}decodeContextMap(contextMapSize,contextMap){this.halfOffset>2030&&this.doReadMoreInput();let numTrees=this.decodeVarLenUnsignedByte()+1;if(numTrees===1)return contextMap.fill(0,0,contextMapSize),numTrees;this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let useRleForZeros=this.readFewBits(1),maxRunLengthPrefix=0;useRleForZeros!==0&&(maxRunLengthPrefix=this.readFewBits(4)+1);let alphabetSize=numTrees+maxRunLengthPrefix,tableSize=MAX_HUFFMAN_TABLE_SIZE[alphabetSize+31>>5],table=new Int32Array(tableSize+1),tableIdx=table.length-1;this.readHuffmanCode(alphabetSize,alphabetSize,table,tableIdx);let i=0;for(;i<contextMapSize;){this.halfOffset>2030&&this.doReadMoreInput(),this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let code=this.readSymbol(table,tableIdx);if(code===0)contextMap[i]=0,i++;else if(code<=maxRunLengthPrefix){this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let reps=(1<<code)+this.readFewBits(code);for(;reps!==0;){if(i>=contextMapSize)throw new BrotliDecoderContextMapRepeatError("Invalid context map");contextMap[i]=0,i++,reps--}}else contextMap[i]=code-maxRunLengthPrefix,i++}return this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),this.readFewBits(1)===1&&this.inverseMoveToFrontTransform(contextMap,contextMapSize),numTrees}decodeBlockTypeAndLength(treeType,numBlockTypes){let ringBuffers=this.rings,offset=4+treeType*2;this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16);let blockType=this.readSymbol(this.blockTrees,2*treeType),result=this.readBlockLength(this.blockTrees,2*treeType+1);return blockType===1?blockType=ringBuffers[offset+1]+1:blockType===0?blockType=ringBuffers[offset]:blockType-=2,blockType>=numBlockTypes&&(blockType-=numBlockTypes),ringBuffers[offset]=ringBuffers[offset+1],ringBuffers[offset+1]=blockType,result}decodeHuffmanTreeGroup(alphabetSizeMax,alphabetSizeLimit,n){let maxTableSize=MAX_HUFFMAN_TABLE_SIZE[alphabetSizeLimit+31>>5],group=new Int32Array(n+n*maxTableSize),next=n;for(let i=0;i<n;++i)group[i]=next,next+=this.readHuffmanCode(alphabetSizeMax,alphabetSizeLimit,group,i);return group}moveToFront(v,index){let i=index,value=v[i];for(;i>0;)v[i]=v[i-1],i--;v[0]=value}inverseMoveToFrontTransform(v,vLen){let mtf=new Int32Array(256);for(let i=0;i<256;++i)mtf[i]=i;for(let i=0;i<vLen;++i){let index=v[i]&255;v[i]=mtf[index],index!==0&&this.moveToFront(mtf,index)}}maybeReallocateRingBuffer(){let newSize=this.maxRingBufferSize;if(newSize>this.expectedTotalSize){let minimalNewSize=this.expectedTotalSize;for(;newSize>>1>minimalNewSize;)newSize>>=1;this.inputEnd===0&&newSize<16384&&this.maxRingBufferSize>=16384&&(newSize=16384)}if(newSize>this.ringBufferSize){let newBuffer=new Int8Array(newSize+37);this.ringBuffer.length!==0&&newBuffer.set(this.ringBuffer.subarray(0,this.ringBufferSize),0),this.ringBuffer=newBuffer,this.ringBufferSize=newSize}}readHuffmanCodeLengths(codeLengthCodeLengths,numSymbols,codeLengths){let symbol=0,prevLen=8,repeat=0,repeatLen=0,space=32768,table=new Int32Array(33),tableIdx=table.length-1;for(buildHuffmanTable(table,tableIdx,5,codeLengthCodeLengths,18);symbol<numSymbols&&space>0;){if(this.halfOffset>2030&&this.doReadMoreInput(),this.bitOffset>=16){let acc=this.shortBuffer[this.halfOffset++]<<16;this.accumulator32=acc|this.accumulator32>>>16,this.bitOffset-=16}let p=this.accumulator32>>>this.bitOffset&31;this.bitOffset+=table[p]>>16;let codeLen=table[p]&65535;if(codeLen<16)repeat=0,codeLengths[symbol++]=codeLen,codeLen!==0&&(prevLen=codeLen,space-=32768>>codeLen);else{let extraBits=codeLen-14,newLen=0;codeLen===16&&(newLen=prevLen),repeatLen!==newLen&&([repeat,repeatLen]=[0,newLen]);let oldRepeat=repeat;repeat>0&&(repeat=(repeat-=2)<<extraBits),this.bitOffset>=16&&(this.accumulator32=this.shortBuffer[this.halfOffset++]<<16|this.accumulator32>>>16,this.bitOffset-=16),repeat+=this.readFewBits(extraBit