define(["./RuntimeError-608565a6","./when-229515d6","./createTaskProcessorWorker"],(function(e,t,n){"use strict";function i(t,n){if(i.passThroughDataForTesting)return n;const r=t.byteLength;if(0===r||r%4!=0)throw new e.RuntimeError("The length of key must be greater than 0 and a multiple of 4.");const a=new DataView(n),o=a.getUint32(0,!0);if(1953029805===o||2917034100===o)return n;const s=new DataView(t);let f=0;const l=n.byteLength,d=l-l%8,h=r;let c,u=8;for(;f=h&&(u=(u+8)%24,c=u);f>>16&65535|0,o=0;0!==n;){n-=o=n>2e3?2e3:n;do{a=a+(r=r+t[i++]|0)|0}while(--o);r%=65521,a%=65521}return r|a<<16|0};var l=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var i=0;i<8;i++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();var d=function(e,t,n,i){var r=l,a=i+n;e^=-1;for(var o=i;o>>8^r[255&(e^t[o])];return-1^e},h=function(e,t){var n,i,r,a,o,s,f,l,d,h,c,u,w,b,m,g,k,v,p,y,_,x,B,E,A;n=e.state,i=e.next_in,E=e.input,r=i+(e.avail_in-5),a=e.next_out,A=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),f=n.dmax,l=n.wsize,d=n.whave,h=n.wnext,c=n.window,u=n.hold,w=n.bits,b=n.lencode,m=n.distcode,g=(1<>>=p=v>>>24,w-=p,0===(p=v>>>16&255))A[a++]=65535&v;else{if(!(16&p)){if(0==(64&p)){v=b[(65535&v)+(u&(1<>>=p,w-=p),w<15&&(u+=E[i++]<>>=p=v>>>24,w-=p,!(16&(p=v>>>16&255))){if(0==(64&p)){v=m[(65535&v)+(u&(1<f){e.msg="invalid distance too far back",n.mode=30;break e}if(u>>>=p,w-=p,_>(p=a-o)){if((p=_-p)>d&&n.sane){e.msg="invalid distance too far back",n.mode=30;break e}if(x=0,B=c,0===h){if(x+=l-p,p2;)A[a++]=B[x++],A[a++]=B[x++],A[a++]=B[x++],y-=3;y&&(A[a++]=B[x++],y>1&&(A[a++]=B[x++]))}else{x=a-_;do{A[a++]=A[x++],A[a++]=A[x++],A[a++]=A[x++],y-=3}while(y>2);y&&(A[a++]=A[x++],y>1&&(A[a++]=A[x++]))}break}}break}}while(i>3,u&=(1<<(w-=y<<3))-1,e.next_in=i,e.next_out=a,e.avail_in=i=1&&0===P[T];T--);if(U>T&&(U=T),0===T)return r[a++]=20971520,r[a++]=20971520,f.bits=1,0;for(A=1;A0&&(0===e||1!==T))return-1;for(O[1]=0,B=1;B852||2===e&&I>592)return 1;for(;;){p=B-R,o[E]v?(y=M[j+o[E]],_=D[V+o[E]]):(y=96,_=0),l=1<>R)+(d-=l)]=p<<24|y<<16|_|0}while(0!==d);for(l=1<>=1;if(0!==l?(z&=l-1,z+=l):z=0,E++,0==--P[B]){if(B===T)break;B=t[n+o[E]]}if(B>U&&(z&g)!==h){for(0===R&&(R=U),k+=A,C=1<<(S=B-R);S+R852||2===e&&I>592)return 1;r[h=z&g]=U<<24|S<<16|k-a|0}}return 0!==z&&(r[k+z]=B-R<<24|64<<16|0),f.bits=U,0},k=-2,v=12,p=30;function y(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function _(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function x(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new s.Buf32(852),t.distcode=t.distdyn=new s.Buf32(592),t.sane=1,t.back=-1,0):k}function B(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,x(e)):k}function E(e,t){var n,i;return e&&e.state?(i=e.state,t<0?(n=0,t=-t):(n=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?k:(null!==i.window&&i.wbits!==t&&(i.window=null),i.wrap=n,i.wbits=t,B(e))):k}function A(e,t){var n,i;return e?(i=new _,e.state=i,i.window=null,0!==(n=E(e,t))&&(e.state=null),n):k}var T,U,S=!0;function R(e){if(S){var t;for(T=new s.Buf32(512),U=new s.Buf32(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(g(1,e.lens,0,288,T,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;g(2,e.lens,0,32,U,0,e.work,{bits:5}),S=!1}e.lencode=T,e.lenbits=9,e.distcode=U,e.distbits=5}function C(e,t,n,i){var r,a=e.state;return null===a.window&&(a.wsize=1<=a.wsize?(s.arraySet(a.window,t,n-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):((r=a.wsize-a.wnext)>i&&(r=i),s.arraySet(a.window,t,n-i,r,a.wnext),(i-=r)?(s.arraySet(a.window,t,n-i,i,0),a.wnext=i,a.whave=a.wsize):(a.wnext+=r,a.wnext===a.wsize&&(a.wnext=0),a.whave>>8&255,n.check=d(n.check,M,2,0),u=0,w=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",n.mode=p;break}if(8!=(15&u)){e.msg="unknown compression method",n.mode=p;break}if(w-=4,z=8+(15&(u>>>=4)),0===n.wbits)n.wbits=z;else if(z>n.wbits){e.msg="invalid window size",n.mode=p;break}n.dmax=1<>8&1),512&n.flags&&(M[0]=255&u,M[1]=u>>>8&255,n.check=d(n.check,M,2,0)),u=0,w=0,n.mode=3;case 3:for(;w<32;){if(0===l)break e;l--,u+=i[a++]<>>8&255,M[2]=u>>>16&255,M[3]=u>>>24&255,n.check=d(n.check,M,4,0)),u=0,w=0,n.mode=4;case 4:for(;w<16;){if(0===l)break e;l--,u+=i[a++]<>8),512&n.flags&&(M[0]=255&u,M[1]=u>>>8&255,n.check=d(n.check,M,2,0)),u=0,w=0,n.mode=5;case 5:if(1024&n.flags){for(;w<16;){if(0===l)break e;l--,u+=i[a++]<>>8&255,n.check=d(n.check,M,2,0)),u=0,w=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&((_=n.length)>l&&(_=l),_&&(n.head&&(z=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Array(n.head.extra_len)),s.arraySet(n.head.extra,i,a,_,z)),512&n.flags&&(n.check=d(n.check,i,_,a)),l-=_,a+=_,n.length-=_),n.length))break e;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(0===l)break e;_=0;do{z=i[a+_++],n.head&&z&&n.length<65536&&(n.head.name+=String.fromCharCode(z))}while(z&&_>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=v;break;case 10:for(;w<32;){if(0===l)break e;l--,u+=i[a++]<>>=7&w,w-=7&w,n.mode=27;break}for(;w<3;){if(0===l)break e;l--,u+=i[a++]<>>=1)){case 0:n.mode=14;break;case 1:if(R(n),n.mode=20,6===t){u>>>=2,w-=2;break e}break;case 2:n.mode=17;break;case 3:e.msg="invalid block type",n.mode=p}u>>>=2,w-=2;break;case 14:for(u>>>=7&w,w-=7&w;w<32;){if(0===l)break e;l--,u+=i[a++]<>>16^65535)){e.msg="invalid stored block lengths",n.mode=p;break}if(n.length=65535&u,u=0,w=0,n.mode=15,6===t)break e;case 15:n.mode=16;case 16:if(_=n.length){if(_>l&&(_=l),_>c&&(_=c),0===_)break e;s.arraySet(r,i,a,_,o),l-=_,a+=_,c-=_,o+=_,n.length-=_;break}n.mode=v;break;case 17:for(;w<14;){if(0===l)break e;l--,u+=i[a++]<>>=5,w-=5,n.ndist=1+(31&u),u>>>=5,w-=5,n.ncode=4+(15&u),u>>>=4,w-=4,n.nlen>286||n.ndist>30){e.msg="too many length or distance symbols",n.mode=p;break}n.have=0,n.mode=18;case 18:for(;n.have>>=3,w-=3}for(;n.have<19;)n.lens[j[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,V={bits:n.lenbits},D=g(0,n.lens,0,19,n.lencode,0,n.work,V),n.lenbits=V.bits,D){e.msg="invalid code lengths set",n.mode=p;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=i[a++]<>>=E,w-=E,n.lens[n.have++]=T;else{if(16===T){for(P=E+2;w>>=E,w-=E,0===n.have){e.msg="invalid bit length repeat",n.mode=p;break}z=n.lens[n.have-1],_=3+(3&u),u>>>=2,w-=2}else if(17===T){for(P=E+3;w>>=E)),u>>>=3,w-=3}else{for(P=E+7;w>>=E)),u>>>=7,w-=7}if(n.have+_>n.nlen+n.ndist){e.msg="invalid bit length repeat",n.mode=p;break}for(;_--;)n.lens[n.have++]=z}}if(n.mode===p)break;if(0===n.lens[256]){e.msg="invalid code -- missing end-of-block",n.mode=p;break}if(n.lenbits=9,V={bits:n.lenbits},D=g(1,n.lens,0,n.nlen,n.lencode,0,n.work,V),n.lenbits=V.bits,D){e.msg="invalid literal/lengths set",n.mode=p;break}if(n.distbits=6,n.distcode=n.distdyn,V={bits:n.distbits},D=g(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,V),n.distbits=V.bits,D){e.msg="invalid distances set",n.mode=p;break}if(n.mode=20,6===t)break e;case 20:n.mode=21;case 21:if(l>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=l,n.hold=u,n.bits=w,h(e,m),o=e.next_out,r=e.output,c=e.avail_out,a=e.next_in,i=e.input,l=e.avail_in,u=n.hold,w=n.bits,n.mode===v&&(n.back=-1);break}for(n.back=0;A=(O=n.lencode[u&(1<>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=i[a++]<>U)])>>>16&255,T=65535&O,!(U+(E=O>>>24)<=w);){if(0===l)break e;l--,u+=i[a++]<>>=U,w-=U,n.back+=U}if(u>>>=E,w-=E,n.back+=E,n.length=T,0===A){n.mode=26;break}if(32&A){n.back=-1,n.mode=v;break}if(64&A){e.msg="invalid literal/length code",n.mode=p;break}n.extra=15&A,n.mode=22;case 22:if(n.extra){for(P=n.extra;w>>=n.extra,w-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;A=(O=n.distcode[u&(1<>>16&255,T=65535&O,!((E=O>>>24)<=w);){if(0===l)break e;l--,u+=i[a++]<>U)])>>>16&255,T=65535&O,!(U+(E=O>>>24)<=w);){if(0===l)break e;l--,u+=i[a++]<>>=U,w-=U,n.back+=U}if(u>>>=E,w-=E,n.back+=E,64&A){e.msg="invalid distance code",n.mode=p;break}n.offset=T,n.extra=15&A,n.mode=24;case 24:if(n.extra){for(P=n.extra;w>>=n.extra,w-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg="invalid distance too far back",n.mode=p;break}n.mode=25;case 25:if(0===c)break e;if(_=m-c,n.offset>_){if((_=n.offset-_)>n.whave&&n.sane){e.msg="invalid distance too far back",n.mode=p;break}_>n.wnext?(_-=n.wnext,x=n.wsize-_):x=n.wnext-_,_>n.length&&(_=n.length),B=n.window}else B=r,x=o-n.offset,_=n.length;_>c&&(_=c),c-=_,n.length-=_;do{r[o++]=B[x++]}while(--_);0===n.length&&(n.mode=21);break;case 26:if(0===c)break e;r[o++]=n.length,c--,n.mode=21;break;case 27:if(n.wrap){for(;w<32;){if(0===l)break e;l--,u|=i[a++]<=252?6:P>=248?5:P>=240?4:P>=224?3:P>=192?2:1;V[254]=V[254]=1;function O(e,t){if(t<65534&&(e.subarray&&D||!e.subarray&&z))return String.fromCharCode.apply(null,s.shrinkBuf(e,t));for(var n="",i=0;i>>6,t[a++]=128|63&n):n<65536?(t[a++]=224|n>>>12,t[a++]=128|n>>>6&63,t[a++]=128|63&n):(t[a++]=240|n>>>18,t[a++]=128|n>>>12&63,t[a++]=128|n>>>6&63,t[a++]=128|63&n);return t},j=function(e){for(var t=new s.Buf8(e.length),n=0,i=t.length;n4)s[i++]=65533,n+=a-1;else{for(r&=2===a?31:3===a?15:7;a>1&&n1?s[i++]=65533:r<65536?s[i++]=r:(r-=65536,s[i++]=55296|r>>10&1023,s[i++]=56320|1023&r)}return O(s,i)},N=function(e,t){var n;for((t=t||e.length)>e.length&&(t=e.length),n=t-1;n>=0&&128==(192&e[n]);)n--;return n<0||0===n?t:n+V[e[n]]>t?n:t},L=0,Y=2,F=4,G=0,K=1,Q=2,q=-5,W={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var J=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};var X=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1},Z=Object.prototype.toString;function $(e){if(!(this instanceof $))return new $(e);this.options=s.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new J,this.strm.avail_out=0;var n=I.inflateInit2(this.strm,t.windowBits);if(n!==G)throw new Error(W[n]);if(this.header=new X,I.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=M(t.dictionary):"[object ArrayBuffer]"===Z.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(n=I.inflateSetDictionary(this.strm,t.dictionary))!==G))throw new Error(W[n])}function ee(e,t){var n=new $(t);if(n.push(e,!0),n.err)throw n.msg||W[n.err];return n.result}$.prototype.push=function(e,t){var n,i,r,a,o,f=this.strm,l=this.options.chunkSize,d=this.options.dictionary,h=!1;if(this.ended)return!1;i=t===~~t?t:!0===t?F:L,"string"==typeof e?f.input=j(e):"[object ArrayBuffer]"===Z.call(e)?f.input=new Uint8Array(e):f.input=e,f.next_in=0,f.avail_in=f.input.length;do{if(0===f.avail_out&&(f.output=new s.Buf8(l),f.next_out=0,f.avail_out=l),(n=I.inflate(f,L))===Q&&d&&(n=I.inflateSetDictionary(this.strm,d)),n===q&&!0===h&&(n=G,h=!1),n!==K&&n!==G)return this.onEnd(n),this.ended=!0,!1;f.next_out&&(0!==f.avail_out&&n!==K&&(0!==f.avail_in||i!==F&&i!==Y)||("string"===this.options.to?(r=N(f.output,f.next_out),a=f.next_out-r,o=H(f.output,r),f.next_out=a,f.avail_out=l-a,a&&s.arraySet(f.output,f.output,r,a,0),this.onData(o)):this.onData(s.shrinkBuf(f.output,f.next_out)))),0===f.avail_in&&0===f.avail_out&&(h=!0)}while((f.avail_in>0||0===f.avail_out)&&n!==K);return n===K&&(i=F),i===F?(n=I.inflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===G):i!==Y||(this.onEnd(G),f.avail_out=0,!0)},$.prototype.onData=function(e){this.chunks.push(e)},$.prototype.onEnd=function(e){e===G&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=s.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var te={Inflate:$,inflate:ee,inflateRaw:function(e,t){return(t=t||{}).raw=!0,ee(e,t)},ungzip:ee};const ne=Uint16Array.BYTES_PER_ELEMENT,ie=Int32Array.BYTES_PER_ELEMENT,re=Uint32Array.BYTES_PER_ELEMENT,ae={METADATA:0,TERRAIN:1,DBROOT:2};ae.fromString=function(e){return"Metadata"===e?ae.METADATA:"Terrain"===e?ae.TERRAIN:"DbRoot"===e?ae.DBROOT:void 0};const oe=1953029805,se=2917034100;return n((function(t,n){const r=ae.fromString(t.type);let a=t.buffer;i(t.key,a);const s=function(t){const n=new DataView(t);let i=0;const r=n.getUint32(i,!0);if(i+=re,r!==oe&&r!==se)throw new e.RuntimeError("Invalid magic");const a=n.getUint32(i,r===oe);i+=re;const o=new Uint8Array(t,i),s=te.inflate(o);if(s.length!==a)throw new e.RuntimeError("Size of packet doesn't match header");return s}(a);a=s.buffer;const f=s.length;switch(r){case ae.METADATA:return function(t,n,i){const r=new DataView(t);let a=0;const s=r.getUint32(a,!0);if(a+=re,32301!==s)throw new e.RuntimeError("Invalid magic");const f=r.getUint32(a,!0);if(a+=re,1!==f)throw new e.RuntimeError("Invalid data type. Must be 1 for QuadTreePacket");const l=r.getUint32(a,!0);if(a+=re,2!==l)throw new e.RuntimeError("Invalid QuadTreePacket version. Only version 2 is supported.");const d=r.getInt32(a,!0);a+=ie;const h=r.getInt32(a,!0);if(a+=ie,32!==h)throw new e.RuntimeError("Invalid instance size.");const c=r.getInt32(a,!0);a+=ie;const u=r.getInt32(a,!0);a+=ie;const w=r.getInt32(a,!0);if(a+=ie,c!==d*h+a)throw new e.RuntimeError("Invalid dataBufferOffset");if(c+u+w!==n)throw new e.RuntimeError("Invalid packet offsets");const b=[];for(let e=0;en)throw new e.RuntimeError("Malformed terrain packet found.")}return t};let o=0;const s=[];for(;s.length<5;){const e=o;o=a(o);const n=t.slice(e,o);i.push(n),s.push(n)}return s}(a,f,n);case ae.DBROOT:return n.push(a),{buffer:a}}}))}));