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