var Oh=Object.defineProperty;var Rh=(t,e,n)=>e in t?Oh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var b=(t,e,n)=>(Rh(t,typeof e!="symbol"?e+"":e,n),n);var Dh=typeof global=="object"&&global&&global.Object===Object&&global,kh=typeof self=="object"&&self&&self.Object===Object&&self,ec=Dh||kh||Function("return this")(),Pi=ec.Symbol,tc=Object.prototype,Uh=tc.hasOwnProperty,Lh=tc.toString,Sn=Pi?Pi.toStringTag:void 0;function zh(t){var e=Uh.call(t,Sn),n=t[Sn];try{t[Sn]=void 0;var i=!0}catch{}var s=Lh.call(t);return i&&(e?t[Sn]=n:delete t[Sn]),s}var $h=Object.prototype,Fh=$h.toString;function Bh(t){return Fh.call(t)}var Vh="[object Null]",Gh="[object Undefined]",go=Pi?Pi.toStringTag:void 0;function jh(t){return t==null?t===void 0?Gh:Vh:go&&go in Object(t)?zh(t):Bh(t)}function qh(t){return t!=null&&typeof t=="object"}var Yh="[object Symbol]";function Hh(t){return typeof t=="symbol"||qh(t)&&jh(t)==Yh}var Kh=/\s/;function Jh(t){for(var e=t.length;e--&&Kh.test(t.charAt(e)););return e}var Wh=/^\s+/;function Zh(t){return t&&t.slice(0,Jh(t)+1).replace(Wh,"")}function Ai(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var mo=NaN,Qh=/^[-+]0x[0-9a-f]+$/i,Xh=/^0b[01]+$/i,eu=/^0o[0-7]+$/i,tu=parseInt;function yo(t){if(typeof t=="number")return t;if(Hh(t))return mo;if(Ai(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=Ai(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Zh(t);var n=Xh.test(t);return n||eu.test(t)?tu(t.slice(2),n?2:8):Qh.test(t)?mo:+t}var ps=function(){return ec.Date.now()},nu="Expected a function",iu=Math.max,su=Math.min;function ur(t,e,n){var i,s,r,o,a,c,l=0,u=!1,h=!1,d=!0;if(typeof t!="function")throw new TypeError(nu);e=yo(e)||0,Ai(n)&&(u=!!n.leading,h="maxWait"in n,r=h?iu(yo(n.maxWait)||0,e):r,d="trailing"in n?!!n.trailing:d);function p(m){var E=i,y=s;return i=s=void 0,l=m,o=t.apply(y,E),o}function g(m){return l=m,a=setTimeout(S,e),u?p(m):o}function f(m){var E=m-c,y=m-l,_=e-E;return h?su(_,r-y):_}function v(m){var E=m-c,y=m-l;return c===void 0||E>=e||E<0||h&&y>=r}function S(){var m=ps();if(v(m))return I(m);a=setTimeout(S,f(m))}function I(m){return a=void 0,d&&i?p(m):(i=s=void 0,o)}function C(){a!==void 0&&clearTimeout(a),l=0,i=c=s=a=void 0}function w(){return a===void 0?o:I(ps())}function M(){var m=ps(),E=v(m);if(i=arguments,s=this,c=m,E){if(a===void 0)return g(c);if(h)return clearTimeout(a),a=setTimeout(S,e),p(c)}return a===void 0&&(a=setTimeout(S,e)),o}return M.cancel=C,M.flush=w,M}var ru="Expected a function";function vo(t,e,n){var i=!0,s=!0;if(typeof t!="function")throw new TypeError(ru);return Ai(n)&&(i="leading"in n?!!n.leading:i,s="trailing"in n?!!n.trailing:s),ur(t,e,{leading:i,maxWait:e,trailing:s})}function ou(t){typeof t=="object"?t.dispose():t()}function nc(t){for(let e=t.length;e>0;--e)ou(t[e-1])}function au(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}class wt{constructor(){this.refCount=1}addRef(){return++this.refCount,this}dispose(){--this.refCount===0&&this.refCountReachedZero()}refCountReachedZero(){this.disposed();const{disposers:e}=this;e!==void 0&&(nc(e),this.disposers=void 0),this.wasDisposed=!0}disposed(){}registerDisposer(e){const{disposers:n}=this;return n==null?this.disposers=[e]:n.push(e),e}unregisterDisposer(e){const{disposers:n}=this;if(n!=null){const i=n.indexOf(e);i!==-1&&n.splice(i,1)}return e}registerEventListener(e,n,i,s){this.registerDisposer(au(e,n,i,s))}registerCancellable(e){return this.registerDisposer(()=>{e.cancel()}),e}}class cu extends wt{constructor(e){super(),this.value=e}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class Hi{constructor(){this.handlers=new Set,this.count=0;const e=this;this.dispatch=function(){++e.count,e.handlers.forEach(n=>{n.apply(this,arguments)})}}add(e){return this.handlers.add(e),()=>this.remove(e)}remove(e){return this.handlers.delete(e)}dispose(){this.handlers=void 0}}class Ht extends Hi{}class xi{constructor(e){this.value_=e,this.changed=new Ht}get value(){return this.value_}set value(e){e!==this.value_&&(this.value_=e,this.changed.dispatch())}}function lu(t,...e){const n=e.map(c=>c.value),i=e.length;let s=new wt,r=t(s,...n);const o=ur(()=>{let c=!1;for(let l=0;l<i;++l){const h=e[l].value;n[l]!==h&&(n[l]=h,c=!0)}c&&(s.dispose(),s=new wt,r=t(s,...n))},0),a=e.map(c=>c.changed.add(o));return{flush(){o.flush()},dispose(){o.cancel(),nc(a),s.dispose()},get value(){return o.flush(),r}}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class hu extends Error{constructor(){super(...arguments),this.name="CancellationError",this.message="CANCELED"}toString(){return"CANCELED"}}const St=new hu;function uu(t){if(t.isCanceled===!0)throw St}const Ms=()=>{},pe={isCanceled:!1,add:()=>Ms,remove:Ms};class Ki{cancel(){const{handlers:e}=this;if(e!==null&&(this.handlers=null,e!==void 0))for(const n of e)n()}get isCanceled(){return this.handlers===null}add(e){let{handlers:n}=this;return n===null?(e(),Ms):(n===void 0&&(n=this.handlers=new Set),n.add(e),()=>{this.remove(e)})}remove(e){const{handlers:n}=this;n!=null&&n.delete(e)}}class ic extends Ki{constructor(){super(...arguments),this.consumers=new Set}addConsumer(e=pe){const{consumers:n}=this;n.has(e)||e.isCanceled||(n.add(e),e.add(()=>{n.delete(e),n.size===0&&this.cancel()}))}}function sc(t,e){return new Promise((n,i)=>{if(t===pe){e(n,i,pe);return}const s=new Ki,r=t.add(()=>{s.cancel()});e(o=>{r(),n(o)},o=>{r(),i(o)},s)})}const rc=!(typeof Window<"u"&&self instanceof Window),Ts="rpc.promise.response",oc="rpc.promise.cancel",ac=new Map;function K(t,e){ac.set(t,e)}class du extends Error{constructor(e,n){super(n),this.name=e,this.message=n}}function Ji(t,e){K(t,function(n){const i=n.id,s=new Ki,r=e.call(this,n,s);this.set(i,{promise:r,cancellationToken:s}),r.then(({value:o,transfers:a})=>{this.delete(i),this.invoke(Ts,{id:i,value:o},a)},o=>{this.delete(i),this.invoke(Ts,{id:i,error:o.message,errorName:o.name})})})}K(oc,function(t){const e=t.id,n=this.get(e);if(n!==void 0){const{cancellationToken:i}=n;i.cancel()}});K(Ts,function(t){const e=t.id,{resolve:n,reject:i}=this.get(e);this.delete(e),Object.prototype.hasOwnProperty.call(t,"value")?n(t.value):t.errorName===St.name?i(St):i(new du(t.errorName,t.error))});const fu=rc?-1:0;class pu{constructor(e){this.target=e,this.objects=new Map,this.nextId=fu,e.onmessage=n=>{const i=n.data;ac.get(i.functionName).call(this,i)}}get numObjects(){return this.objects.size}set(e,n){this.objects.set(e,n)}delete(e){this.objects.delete(e)}get(e){return this.objects.get(e)}getRef(e){const n=e.id,i=this.get(n);return i.referencedGeneration=e.gen,i.addRef(),i}getOptionalRef(e){if(e===void 0)return;const n=e.id,i=this.get(n);return i.referencedGeneration=e.gen,i.addRef(),i}invoke(e,n,i){n.functionName=e,this.target.postMessage(n,i)}promiseInvoke(e,n,i=pe,s){return sc(i,(r,o,a)=>{const c=n.id=this.newId();this.set(c,{resolve:r,reject:o}),this.invoke(e,n,s),a.add(()=>{this.invoke(oc,{id:c})})})}newId(){return rc?this.nextId--:this.nextId++}}class dr extends wt{constructor(){super(...arguments),this.rpc=null,this.rpcId=null}initializeSharedObject(e,n=e.newId()){this.rpc=e,this.rpcId=n,this.isOwner=!1,e.set(n,this)}initializeCounterpart(e,n={}){this.initializeSharedObject(e),this.unreferencedGeneration=0,this.referencedGeneration=0,this.isOwner=!0,n.id=this.rpcId,n.type=this.RPC_TYPE_ID,e.invoke("SharedObject.new",n)}dispose(){super.dispose()}addCounterpartRef(){return{id:this.rpcId,gen:++this.referencedGeneration}}refCountReachedZero(){this.isOwner===!0?this.referencedGeneration===this.unreferencedGeneration&&this.ownerDispose():this.isOwner===!1?this.rpc.invoke("SharedObject.refCountReachedZero",{id:this.rpcId,gen:this.referencedGeneration}):super.refCountReachedZero()}ownerDispose(){const{rpc:e,rpcId:n}=this;super.refCountReachedZero(),e.delete(n),e.invoke("SharedObject.dispose",{id:n})}counterpartRefCountReachedZero(e){this.unreferencedGeneration=e,this.refCount===0&&e===this.referencedGeneration&&this.ownerDispose()}}function cc(t,e,n={}){e!=null&&t.initializeSharedObject(e,n.id)}class xe extends dr{constructor(e,n={}){super(),cc(this,e,n)}}K("SharedObject.dispose",function(t){const e=this.get(t.id);if(e.refCount!==0)throw new Error("Attempted to dispose object with non-zero reference count.");e.disposed(),this.delete(e.rpcId),e.rpcId=null,e.rpc=null});K("SharedObject.refCountReachedZero",function(t){const e=this.get(t.id),n=t.gen;e.counterpartRefCountReachedZero(n)});const lc=new Map;function gu(t){return e=>{e.prototype.RPC_TYPE_ID=t}}function L(t){return e=>{if(t!==void 0)e.prototype.RPC_TYPE_ID=t;else if(t=e.prototype.RPC_TYPE_ID,t===void 0)throw new Error("RPC_TYPE_ID should have already been defined");lc.set(t,e)}}K("SharedObject.new",function(t){const e=this,n=t.type,i=lc.get(n),s=new i(e,t);--s.refCount});var mu=Object.defineProperty,yu=Object.getOwnPropertyDescriptor,vu=(t,e,n,i)=>{for(var s=i>1?void 0:i?yu(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&mu(e,n,s),s};const hc="SharedWatchableValue.changed";let Ni=class extends xe{constructor(t,e={}){super(t,e),this.updatingValue_=!1,t!==void 0&&(this.base=new xi(e.value),this.setupChangedHandler())}initializeCounterpart(t,e={}){e.value=this.value,super.initializeCounterpart(t,e)}setupChangedHandler(){this.registerDisposer(this.base.changed.add(()=>{if(this.updatingValue_)this.updatingValue_=!1;else{const{rpc:t}=this;t!==null&&t.invoke(hc,{id:this.rpcId,value:this.value})}}))}static makeFromExisting(t,e){const n=new Ni;return n.base=e,n.setupChangedHandler(),n.initializeCounterpart(t),n}static make(t,e){return Ni.makeFromExisting(t,new xi(e))}get value(){return this.base.value}set value(t){this.base.value=t}get changed(){return this.base.changed}};Ni=vu([L("SharedWatchableValue")],Ni);K(hc,function(t){const e=this.get(t.id);e.updatingValue_=!0,e.base.value=t.value,e.updatingValue_=!1});/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var N=(t=>(t[t.GPU_MEMORY=0]="GPU_MEMORY",t[t.SYSTEM_MEMORY=1]="SYSTEM_MEMORY",t[t.SYSTEM_MEMORY_WORKER=2]="SYSTEM_MEMORY_WORKER",t[t.DOWNLOADING=3]="DOWNLOADING",t[t.QUEUED=4]="QUEUED",t[t.NEW=5]="NEW",t[t.FAILED=6]="FAILED",t[t.EXPIRED=7]="EXPIRED",t))(N||{});const uc=8;var q=(t=>(t[t.FIRST_TIER=0]="FIRST_TIER",t[t.FIRST_ORDERED_TIER=0]="FIRST_ORDERED_TIER",t[t.VISIBLE=0]="VISIBLE",t[t.PREFETCH=1]="PREFETCH",t[t.LAST_ORDERED_TIER=1]="LAST_ORDERED_TIER",t[t.RECENT=2]="RECENT",t[t.LAST_TIER=2]="LAST_TIER",t))(q||{});const fr=3;var Ps=(t=>(t[t.totalTime=0]="totalTime",t[t.totalChunks=1]="totalChunks",t))(Ps||{}),yi=(t=>(t[t.numChunks=0]="numChunks",t[t.systemMemoryBytes=1]="systemMemoryBytes",t[t.gpuMemoryBytes=2]="gpuMemoryBytes",t))(yi||{});const Mn=3,wu=2,Su=uc*fr*Mn+wu;function Iu(t,e){return t*fr+e}function wo(t){return uc*fr*Mn+t}const Eu=1e13,Cu="ChunkQueueManager",_u="ChunkManager",bu="ChunkSource.invalidate",Mu="ChunkQueueManager.requestChunkStatistics",Tu="ChunkManager.chunkLayerStatistics";/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class Pu{static insertAfter(e,n){const i=e.next0;n.next0=i,n.prev0=e,e.next0=n,i.prev0=n}static insertBefore(e,n){const i=e.prev0;n.prev0=i,n.next0=e,e.prev0=n,i.next0=n}static front(e){const n=e.next0;return n===e?null:n}static back(e){const n=e.prev0;return n===e?null:n}static pop(e){const n=e.next0,i=e.prev0;return n.prev0=i,i.next0=n,e.next0=null,e.prev0=null,e}static*iterator(e){for(let n=e.next0;n!==e;n=n.next0)yield n}static*reverseIterator(e){for(let n=e.prev0;n!==e;n=n.prev0)yield n}static initializeHead(e){e.next0=e.prev0=e}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class Au{static insertAfter(e,n){const i=e.next1;n.next1=i,n.prev1=e,e.next1=n,i.prev1=n}static insertBefore(e,n){const i=e.prev1;n.prev1=i,n.next1=e,e.prev1=n,i.next1=n}static front(e){const n=e.next1;return n===e?null:n}static back(e){const n=e.prev1;return n===e?null:n}static pop(e){const n=e.next1,i=e.prev1;return n.prev1=i,i.next1=n,e.next1=null,e.prev1=null,e}static*iterator(e){for(let n=e.next1;n!==e;n=n.next1)yield n}static*reverseIterator(e){for(let n=e.prev1;n!==e;n=n.prev1)yield n}static initializeHead(e){e.next1=e.prev1=e}}var vi=1e-6,Se=typeof Float32Array<"u"?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});function pr(){var t=new Se(9);return Se!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function dc(t){var e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],o=t[5],a=t[6],c=t[7],l=t[8];return e*(l*r-o*c)+n*(-l*s+o*a)+i*(c*s-r*a)}function _t(){var t=new Se(16);return Se!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function xu(t){var e=new Se(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function So(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Nu(t,e,n,i,s,r,o,a,c,l,u,h,d,p,g,f){var v=new Se(16);return v[0]=t,v[1]=e,v[2]=n,v[3]=i,v[4]=s,v[5]=r,v[6]=o,v[7]=a,v[8]=c,v[9]=l,v[10]=u,v[11]=h,v[12]=d,v[13]=p,v[14]=g,v[15]=f,v}function fc(t,e){var n=e[0],i=e[1],s=e[2],r=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],p=e[11],g=e[12],f=e[13],v=e[14],S=e[15],I=n*a-i*o,C=n*c-s*o,w=n*l-r*o,M=i*c-s*a,m=i*l-r*a,E=s*l-r*c,y=u*f-h*g,_=u*v-d*g,T=u*S-p*g,P=h*v-d*f,A=h*S-p*f,D=d*S-p*v,x=I*D-C*A+w*P+M*T-m*_+E*y;return x?(x=1/x,t[0]=(a*D-c*A+l*P)*x,t[1]=(s*A-i*D-r*P)*x,t[2]=(f*E-v*m+S*M)*x,t[3]=(d*m-h*E-p*M)*x,t[4]=(c*T-o*D-l*_)*x,t[5]=(n*D-s*T+r*_)*x,t[6]=(v*w-g*E-S*C)*x,t[7]=(u*E-d*w+p*C)*x,t[8]=(o*A-a*T+l*y)*x,t[9]=(i*T-n*A-r*y)*x,t[10]=(g*m-f*w+S*I)*x,t[11]=(h*w-u*m-p*I)*x,t[12]=(a*_-o*P-c*y)*x,t[13]=(n*P-i*_+s*y)*x,t[14]=(f*C-g*M-v*I)*x,t[15]=(u*M-h*C+d*I)*x,t):null}function gr(t,e,n){var i=e[0],s=e[1],r=e[2],o=e[3],a=e[4],c=e[5],l=e[6],u=e[7],h=e[8],d=e[9],p=e[10],g=e[11],f=e[12],v=e[13],S=e[14],I=e[15],C=n[0],w=n[1],M=n[2],m=n[3];return t[0]=C*i+w*a+M*h+m*f,t[1]=C*s+w*c+M*d+m*v,t[2]=C*r+w*l+M*p+m*S,t[3]=C*o+w*u+M*g+m*I,C=n[4],w=n[5],M=n[6],m=n[7],t[4]=C*i+w*a+M*h+m*f,t[5]=C*s+w*c+M*d+m*v,t[6]=C*r+w*l+M*p+m*S,t[7]=C*o+w*u+M*g+m*I,C=n[8],w=n[9],M=n[10],m=n[11],t[8]=C*i+w*a+M*h+m*f,t[9]=C*s+w*c+M*d+m*v,t[10]=C*r+w*l+M*p+m*S,t[11]=C*o+w*u+M*g+m*I,C=n[12],w=n[13],M=n[14],m=n[15],t[12]=C*i+w*a+M*h+m*f,t[13]=C*s+w*c+M*d+m*v,t[14]=C*r+w*l+M*p+m*S,t[15]=C*o+w*u+M*g+m*I,t}function Ou(t,e,n,i){var s=e[0],r=e[1],o=e[2],a=e[3],c=s+s,l=r+r,u=o+o,h=s*c,d=s*l,p=s*u,g=r*l,f=r*u,v=o*u,S=a*c,I=a*l,C=a*u,w=i[0],M=i[1],m=i[2];return t[0]=(1-(g+v))*w,t[1]=(d+C)*w,t[2]=(p-I)*w,t[3]=0,t[4]=(d-C)*M,t[5]=(1-(h+v))*M,t[6]=(f+S)*M,t[7]=0,t[8]=(p+I)*m,t[9]=(f-S)*m,t[10]=(1-(h+g))*m,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function Q(){var t=new Se(3);return Se!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function As(t){var e=new Se(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Ru(t){var e=t[0],n=t[1],i=t[2];return Math.hypot(e,n,i)}function ve(t,e,n){var i=new Se(3);return i[0]=t,i[1]=e,i[2]=n,i}function Wi(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function Bt(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function gs(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function It(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function pc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function mr(t,e){var n=e[0]-t[0],i=e[1]-t[1],s=e[2]-t[2];return Math.hypot(n,i,s)}function xs(t,e){var n=e[0],i=e[1],s=e[2],r=n*n+i*i+s*s;return r>0&&(r=1/Math.sqrt(r)),t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function Du(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function wi(t,e,n){var i=e[0],s=e[1],r=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-r*a,t[1]=r*o-i*c,t[2]=i*a-s*o,t}function ku(t,e,n){var i=e[0],s=e[1],r=e[2],o=n[3]*i+n[7]*s+n[11]*r+n[15];return o=o||1,t[0]=(n[0]*i+n[4]*s+n[8]*r+n[12])/o,t[1]=(n[1]*i+n[5]*s+n[9]*r+n[13])/o,t[2]=(n[2]*i+n[6]*s+n[10]*r+n[14])/o,t}function Uu(t,e){var n=t[0],i=t[1],s=t[2],r=e[0],o=e[1],a=e[2];return Math.abs(n-r)<=vi*Math.max(1,Math.abs(n),Math.abs(r))&&Math.abs(i-o)<=vi*Math.max(1,Math.abs(i),Math.abs(o))&&Math.abs(s-a)<=vi*Math.max(1,Math.abs(s),Math.abs(a))}var Lu=Ru;(function(){var t=Q();return function(e,n,i,s,r,o){var a,c;for(n||(n=3),i||(i=0),s?c=Math.min(s*n+i,e.length):c=e.length,a=i;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],r(t,t,o),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();function zu(){var t=new Se(4);return Se!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function Zi(t,e,n,i){var s=new Se(4);return s[0]=t,s[1]=e,s[2]=n,s[3]=i,s}function $u(t,e){var n=e[0],i=e[1],s=e[2],r=e[3],o=n*n+i*i+s*s+r*r;return o>0&&(o=1/Math.sqrt(o)),t[0]=n*o,t[1]=i*o,t[2]=s*o,t[3]=r*o,t}(function(){var t=zu();return function(e,n,i,s,r,o){var a,c;for(n||(n=4),i||(i=0),s?c=Math.min(s*n+i,e.length):c=e.length,a=i;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],r(t,t,o),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}})();function Oi(){var t=new Se(4);return Se!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Fu(t,e,n){n=n*.5;var i=Math.sin(n);return t[0]=i*e[0],t[1]=i*e[1],t[2]=i*e[2],t[3]=Math.cos(n),t}function ms(t,e,n,i){var s=e[0],r=e[1],o=e[2],a=e[3],c=n[0],l=n[1],u=n[2],h=n[3],d,p,g,f,v;return p=s*c+r*l+o*u+a*h,p<0&&(p=-p,c=-c,l=-l,u=-u,h=-h),1-p>vi?(d=Math.acos(p),g=Math.sin(d),f=Math.sin((1-i)*d)/g,v=Math.sin(i*d)/g):(f=1-i,v=i),t[0]=f*s+v*c,t[1]=f*r+v*l,t[2]=f*o+v*u,t[3]=f*a+v*h,t}function Bu(t,e){var n=e[0]+e[4]+e[8],i;if(n>0)i=Math.sqrt(n+1),t[3]=.5*i,i=.5/i,t[0]=(e[5]-e[7])*i,t[1]=(e[6]-e[2])*i,t[2]=(e[1]-e[3])*i;else{var s=0;e[4]>e[0]&&(s=1),e[8]>e[s*3+s]&&(s=2);var r=(s+1)%3,o=(s+2)%3;i=Math.sqrt(e[s*3+s]-e[r*3+r]-e[o*3+o]+1),t[s]=.5*i,i=.5/i,t[3]=(e[r*3+o]-e[o*3+r])*i,t[r]=(e[r*3+s]+e[s*3+r])*i,t[o]=(e[o*3+s]+e[s*3+o])*i}return t}var Vu=Zi,gc=$u;(function(){var t=Q(),e=ve(1,0,0),n=ve(0,1,0);return function(i,s,r){var o=Du(s,r);return o<-.999999?(wi(t,e,s),Lu(t)<1e-6&&wi(t,n,s),xs(t,t),Fu(i,t,Math.PI),i):o>.999999?(i[0]=0,i[1]=0,i[2]=0,i[3]=1,i):(wi(t,s,r),i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=1+o,gc(i,i))}})();(function(){var t=Oi(),e=Oi();return function(n,i,s,r,o,a){return ms(t,i,o,a),ms(e,s,r,a),ms(n,t,e,2*a*(1-a)),n}})();(function(){var t=pr();return function(e,n,i,s){return t[0]=i[0],t[3]=i[1],t[6]=i[2],t[1]=s[0],t[4]=s[1],t[7]=s[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],gc(e,Bu(e,t))}})();function Gu(t,e,n){const i=new t.constructor(t.length);for(let s=0;s<e*n;s+=n)for(let r=0;r<n;r++){const o=s/n;i[r*e+o]=t[s+r]}return i}function mt(t,e){const n=t.length;if(e.length!==n)return!1;for(let i=0;i<n;++i)if(t[i]!==e[i])return!1;return!0}_t();ve(1,0,0),ve(0,1,0),ve(0,0,1);const Si=ve(0,0,0);Zi(0,0,0,0);const ju=ve(1,1,1),qu=ve(1/0,1/0,1/0);Oi();function Ns(t){return t[0]*t[1]*t[2]}function Vt(t){return`${t[0]},${t[1]},${t[2]}`}function Yu(t,e,n){const i=e[0],s=e[1],r=e[2];return t[0]=n[0]*i+n[4]*s+n[8]*r,t[1]=n[1]*i+n[5]*s+n[9]*r,t[2]=n[2]*i+n[6]*s+n[10]*r,t}function Hu(t,e,n){const i=e[0],s=e[1],r=e[2];return t[0]=n[0]*i+n[1]*s+n[2]*r,t[1]=n[4]*i+n[5]*s+n[6]*r,t[2]=n[8]*i+n[9]*s+n[10]*r,t}function Ku(t,e,n,i,s){const r=t;return t[0]=i[0],t[1]=i[1],t[2]=i[2]*s,Ou(t,n,e,r)}function mc(t,e){const n=e[0],i=e[1],s=e[2],r=e[4],o=e[5],a=e[6],c=e[8],l=e[9],u=e[10];return t[0]=n,t[1]=i,t[2]=s,t[3]=r,t[4]=o,t[5]=a,t[6]=c,t[7]=l,t[8]=u,t}function yc(t,e){const n=e[0],i=e[1],s=e[2],r=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],p=e[11],g=e[12],f=e[13],v=e[14],S=e[15];t[0]=r+n,t[1]=l+o,t[2]=p+u,t[3]=S+g,t[4]=r-n,t[5]=l-o,t[6]=p-u,t[7]=S-g,t[8]=r+i,t[9]=l+a,t[10]=p+h,t[11]=S+f,t[12]=r-i,t[13]=l-a,t[14]=p-h,t[15]=S-f;const I=r+s,C=l+c,w=p+d,M=S+v,m=r-s,E=l-c,y=p-d,_=S-v,T=Math.sqrt(I**2+C**2+w**2);t[16]=I/T,t[17]=C/T,t[18]=w/T,t[19]=M/T;const P=Math.sqrt(m**2+E**2+y**2);return t[20]=m/P,t[21]=E/P,t[22]=y/P,t[23]=_/P,t}function vc(t,e,n,i,s,r,o){for(let a=0;a<6;++a){const c=o[a*4],l=o[a*4+1],u=o[a*4+2],h=o[a*4+3];if(Math.max(c*t,c*i)+Math.max(l*e,l*s)+Math.max(u*n,u*r)+h<0)return!1}return!0}function Ju(t,e,n,i,s,r,o){for(let a=0;a<4;++a){const c=o[a*4],l=o[a*4+1],u=o[a*4+2],h=o[a*4+3];if(Math.max(c*t,c*i)+Math.max(l*e,l*s)+Math.max(u*n,u*r)+h<0)return!1}{const c=o[20],l=o[5*4+1],u=o[5*4+2],h=o[5*4+3],d=Math.max(c*t,c*i)+Math.max(l*e,l*s)+Math.max(u*n,u*r),p=Math.min(c*t,c*i)+Math.min(l*e,l*s)+Math.min(u*n,u*r),g=Math.abs(h)*1e-6;if(p>-h+g||d<-h-g)return!1}return!0}function Wu(t){if(t[15]===1){const o=2/Math.abs(t[10]),a=2/Math.abs(t[0]),c=2/Math.abs(t[5]);return a*c*o}const e=t[10],i=2*t[14]/(2*e-2),s=(e-1)*i/(e+1);return 4/(t[0]*t[5])/3*(Math.abs(s)**3-Math.abs(i)**3)}function wc(t){if(t[15]===1)return 2/Math.abs(t[10]);const e=t[10],i=2*t[14]/(2*e-2),s=(e-1)*i/(e+1);return Math.abs(s-i)}Q();function yr(t){const e=typeof t;if(e==="number"||e==="string"){const n=parseFloat(""+t);if(!Number.isNaN(n))return n}throw new Error(`Expected floating-point number, but received: ${JSON.stringify(t)}.`)}function Rt(t){const e=yr(t);if(Number.isFinite(e))return e;throw new Error(`Expected finite floating-point number, but received: ${e}.`)}function Zu(t){const e=yr(t);if(Number.isFinite(e)&&e>=0)return e;throw new Error(`Expected finite non-negative floating-point number, but received: ${e}.`)}function Be(t){if(typeof t=="object"){if(t===null)return"null";if(Array.isArray(t)){let r="[";const o=t.length;let a=0;if(a<o)for(r+=Be(t[a]);++a<o;)r+=",",r+=Be(t[a]);return r+="]",r}let e="{";const n=Object.keys(t).sort();let i=0;const s=n.length;if(i<s){let r=n[i];for(e+=JSON.stringify(r),e+=":",e+=Be(t[r]);++i<s;)e+=",",r=n[i],e+=JSON.stringify(r),e+=":",e+=Be(t[r])}return e+="}",e}return JSON.stringify(t)}const Qu=/('(?:[^'\\]|(?:\\.))*')/,Xu=/("(?:[^"\\]|(?:\\.))*")/,ed=new RegExp(`${Qu.source}|${Xu.source}`),td=/^((?:[^"'\\]|(?:\\[^']))*)("|\\')/;function nd(t,e,n,i){if(t.length>=2&&t.charAt(0)===e&&t.charAt(t.length-1)===e){let s=t.substr(1,t.length-2),r=n;for(;s.length>0;){const o=s.match(i);if(o===null){r+=s;break}r+=o[1],o[2]===n?(r+="\\",r+=n):r+=e,s=s.substr(o.index+o[0].length)}return r+=n,r}return t}function id(t){return nd(t,"'",'"',td)}function sd(t){let e="";for(;t.length>0;){const n=t.match(ed);let i,s;if(n===null)i=t,t="",s="";else{i=t.substr(0,n.index),t=t.substr(n.index+n[0].length);const r=n[1];r!==void 0?s=id(r):s=n[2]}e+=i.replace(/\(/g,"[").replace(/\)/g,"]").replace("True","true").replace("False","false").replace(/,\s*([}\]])/g,"$1"),e+=s}return e}function rd(t){return JSON.parse(sd(t))}function Ri(t,e){if(!Array.isArray(t))throw new Error(`Expected array, but received: ${JSON.stringify(t)}.`);return t.map(e)}function We(t,e,n){const i=t.length;if(!Array.isArray(e)||e.length!==i)throw new Error(`Expected length ${i} array, but received: ${JSON.stringify(e)}.`);for(let s=0;s<i;++s)t[s]=n(e[s],s);return t}function Ge(t){if(typeof t!="object"||t==null||Array.isArray(t))throw new Error(`Expected JSON object, but received: ${JSON.stringify(t)}.`);return t}function Dt(t){const e=parseInt(t,10);if(!Number.isInteger(e))throw new Error(`Expected integer, but received: ${JSON.stringify(t)}.`);return e}function Ft(t){if(typeof t!="string")throw new Error(`Expected string, but received: ${JSON.stringify(t)}.`);return t}function od(t){if(t!==void 0)return Ft(t)}function X(t,e,n){const i=Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;try{return n(i)}catch(s){throw new Error(`Error parsing ${JSON.stringify(e)} property: ${s.message}`)}}function ad(t,e,n,i){return X(t,e,s=>s===void 0?i:n(s))}function cd(t,e,n=/^[a-zA-Z]/){if(typeof t=="string"&&t.match(n)!==null){const i=t.toUpperCase();if(Object.prototype.hasOwnProperty.call(e,i))return e[i]}throw new Error(`Invalid enum value: ${JSON.stringify(t)}.`)}function Kt(t){if(!Array.isArray(t))throw new Error(`Expected array, received: ${JSON.stringify(t)}.`);for(const e of t)if(typeof e!="string")throw new Error(`Expected string, received: ${JSON.stringify(e)}.`);return t}class ld{constructor(){this.map=new Map}get(e,n){const{map:i}=this;let s=i.get(e);return s===void 0?(s=n(),s.registerDisposer(()=>{i.delete(e)}),i.set(e,s)):s.addRef(),s}}class hd extends ld{get(e,n){return typeof e!="string"&&(e=Be(e)),super.get(e,n)}getUncounted(e,n){return this.get(e,()=>new cu(n())).value}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */let ud=class{constructor(e){this.compare=e}meld(e,n){if(n===null)return e;if(e===null)return n;const{compare:i}=this;if(i(n,e)){const r=e;e=n,n=r}const s=e.child0;return n.next0=s,n.prev0=e,s!==null&&(s.prev0=n),e.child0=n,e}combineChildren(e){let n=e.child0;if(n===null)return null;let i=null;for(;;){const r=n.next0;let o,a;if(r===null?(o=null,a=n):(o=r.next0,a=this.meld(n,r)),a.next0=i,i=a,o===null)break;n=o}let s=i;for(i=i.next0;i!==null;){const r=i.next0;s=this.meld(s,i),i=r}return s.prev0=null,s.next0=null,s}removeMin(e){const n=this.combineChildren(e);return e.next0=null,e.prev0=null,e.child0=null,n}remove(e,n){if(e===n)return this.removeMin(e);const i=n.prev0,s=n.next0;i.child0===n?i.child0=s:i.next0=s,s!==null&&(s.prev0=i);const r=this.meld(e,this.combineChildren(n));return n.next0=null,n.prev0=null,n.child0=null,r}*entries(e){if(e!==null){let n=e.child0;for(yield e;n!==null;){const i=n.next0;yield*this.entries(n),n=i}}}*removedEntries(e){if(e!==null){let n=e.child0;for(e.child0=null,e.next0=null,e.prev0=null,yield e;n!==null;){const i=n.next0;n.child0=null,n.next0=null,n.prev0=null,yield*this.entries(n),n=i}}}};/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class dd{constructor(e){this.compare=e}meld(e,n){if(n===null)return e;if(e===null)return n;const{compare:i}=this;if(i(n,e)){const r=e;e=n,n=r}const s=e.child1;return n.next1=s,n.prev1=e,s!==null&&(s.prev1=n),e.child1=n,e}combineChildren(e){let n=e.child1;if(n===null)return null;let i=null;for(;;){const r=n.next1;let o,a;if(r===null?(o=null,a=n):(o=r.next1,a=this.meld(n,r)),a.next1=i,i=a,o===null)break;n=o}let s=i;for(i=i.next1;i!==null;){const r=i.next1;s=this.meld(s,i),i=r}return s.prev1=null,s.next1=null,s}removeMin(e){const n=this.combineChildren(e);return e.next1=null,e.prev1=null,e.child1=null,n}remove(e,n){if(e===n)return this.removeMin(e);const i=n.prev1,s=n.next1;i.child1===n?i.child1=s:i.next1=s,s!==null&&(s.prev1=i);const r=this.meld(e,this.combineChildren(n));return n.next1=null,n.prev1=null,n.child1=null,r}*entries(e){if(e!==null){let n=e.child1;for(yield e;n!==null;){const i=n.next1;yield*this.entries(n),n=i}}}*removedEntries(e){if(e!==null){let n=e.child1;for(e.child1=null,e.next1=null,e.prev1=null,yield e;n!==null;){const i=n.next1;n.child1=null,n.next1=null,n.prev1=null,yield*this.entries(n),n=i}}}}var fd=Object.defineProperty,pd=Object.getOwnPropertyDescriptor,vr=(t,e,n,i)=>{for(var s=i>1?void 0:i?pd(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&fd(e,n,s),s};let gd=0;function md(){return++gd}class ne{constructor(){this.child0=null,this.next0=null,this.prev0=null,this.child1=null,this.next1=null,this.prev1=null,this.source=null,this.key=null,this.state_=N.NEW,this.error=null,this.markGeneration=-1,this.priority=0,this.newPriority=0,this.priorityTier=q.RECENT,this.newPriorityTier=q.RECENT,this.systemMemoryBytes_=0,this.gpuMemoryBytes_=0,this.downloadSlots_=1,this.isComputational=!1,this.requestedState=N.NEW,this.newRequestedState=N.NEW,this.downloadCancellationToken=void 0}initialize(e){this.key=e,this.priority=Number.NEGATIVE_INFINITY,this.priorityTier=q.RECENT,this.newPriority=Number.NEGATIVE_INFINITY,this.newPriorityTier=q.RECENT,this.error=null,this.state=N.NEW,this.requestedState=N.NEW,this.newRequestedState=N.NEW}updatePriorityProperties(){this.priorityTier=this.newPriorityTier,this.priority=this.newPriority,this.newPriorityTier=q.RECENT,this.newPriority=Number.NEGATIVE_INFINITY,this.requestedState=this.newRequestedState,this.newRequestedState=N.NEW}dispose(){this.source=null,this.error=null}get chunkManager(){return this.source.chunkManager}get queueManager(){return this.source.chunkManager.queueManager}downloadFailed(e){this.error=e,this.queueManager.updateChunkState(this,N.FAILED)}downloadSucceeded(){this.requestedState===N.SYSTEM_MEMORY?(this.queueManager.moveChunkToFrontend(this),this.queueManager.updateChunkState(this,N.SYSTEM_MEMORY)):this.queueManager.updateChunkState(this,N.SYSTEM_MEMORY_WORKER)}freeSystemMemory(){}serialize(e,n){e.id=this.key,e.source=this.source.rpcId,e.new=!0}toString(){return this.key}set state(e){if(e===this.state_)return;const n=this.state_;this.state_=e,this.source.chunkStateChanged(this,n)}get state(){return this.state_}set systemMemoryBytes(e){Xe(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.systemMemoryBytes_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),Xe(this,1),this.chunkManager.queueManager.scheduleUpdate()}get systemMemoryBytes(){return this.systemMemoryBytes_}set gpuMemoryBytes(e){Xe(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.gpuMemoryBytes_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),Xe(this,1),this.chunkManager.queueManager.scheduleUpdate()}get gpuMemoryBytes(){return this.gpuMemoryBytes_}get downloadSlots(){return this.downloadSlots_}set downloadSlots(e){e!==this.downloadSlots_&&(Xe(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.downloadSlots_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),Xe(this,1),this.chunkManager.queueManager.scheduleUpdate())}registerListener(e){return this.source?this.source.registerChunkListener(this.key,e):!1}unregisterListener(e){return this.source?this.source.unregisterChunkListener(this.key,e):!1}static priorityLess(e,n){return e.priority<n.priority}static priorityGreater(e,n){return e.priority>n.priority}}const yd=2;class wr extends dr{constructor(e){super(),this.chunkManager=e,this.listeners_=new Map,this.chunks=new Map,this.freeChunks=new Array,this.statistics=new Float64Array(Su),this.sourceQueueLevel=0,e.queueManager.sources.add(this)}disposed(){this.chunkManager.queueManager.sources.delete(this),super.disposed()}getNewChunk_(e){const n=this.freeChunks,i=n.length;if(i>0){const r=n[i-1];return n.length=i-1,r.source=this,r}const s=new e;return s.source=this,s}addChunk(e){const{chunks:n}=this;n.size===0&&this.addRef(),n.set(e.key,e),Xe(e,1)}removeChunk(e){const{chunks:n,freeChunks:i}=this;n.delete(e.key),e.dispose(),i[i.length]=e,n.size===0&&this.dispose()}registerChunkListener(e,n){return this.listeners_.has(e)?this.listeners_.get(e).push(n):this.listeners_.set(e,[n]),!0}unregisterChunkListener(e,n){if(!this.listeners_.has(e))return!1;const i=this.listeners_.get(e),s=i.indexOf(n);return s<0?!1:(i.splice(s,1),i.length===0&&this.listeners_.delete(e),!0)}chunkStateChanged(e,n){const{key:i}=e;if(i===null)return;const s=this.listeners_.get(i);if(s!==void 0)for(const r of s.slice())r(e,n)}}function Xe(t,e){const{statistics:n}=t.source,{systemMemoryBytes:i,gpuMemoryBytes:s}=t,r=Iu(t.state,t.priorityTier);n[r*Mn+yi.numChunks]+=e,n[r*Mn+yi.systemMemoryBytes]+=e*i,n[r*Mn+yi.gpuMemoryBytes]+=e*s}class Le extends wr{constructor(e,n){const i=e.get(n.chunkManager);super(i),cc(this,e,n)}}function vd(t){const e=t.downloadCancellationToken=new Ki,n=Date.now();t.source.download(t,e).then(()=>{if(t.downloadCancellationToken===e){t.downloadCancellationToken=void 0;const i=Date.now(),{statistics:s}=t.source;s[wo(Ps.totalTime)]+=i-n,++s[wo(Ps.totalChunks)],t.downloadSucceeded()}},i=>{t.downloadCancellationToken===e&&(t.downloadCancellationToken=void 0,t.downloadFailed(i),console.log(`Error retrieving chunk ${t}: ${i}`))})}function Io(t){const e=t.downloadCancellationToken;t.downloadCancellationToken=void 0,e.cancel()}class Sc{constructor(e,n){this.heapOperations=e,this.linkedListOperations=n,this.heapRoots=[null,null],this.recentHead=new ne,n.initializeHead(this.recentHead)}add(e){const n=e.priorityTier;if(n===q.RECENT)this.linkedListOperations.insertAfter(this.recentHead,e);else{const{heapRoots:i}=this;i[n]=this.heapOperations.meld(i[n],e)}}*candidates(){if(this.heapOperations.compare===ne.priorityLess){const{linkedListOperations:e,recentHead:n}=this;for(;;){const s=e.back(n);if(s==null)break;yield s}const{heapRoots:i}=this;for(let s=q.LAST_ORDERED_TIER;s>=q.FIRST_ORDERED_TIER;--s)for(;;){const r=i[s];if(r==null)break;yield r}}else{const e=this.heapRoots;for(let s=q.FIRST_ORDERED_TIER;s<=q.LAST_ORDERED_TIER;++s)for(;;){const r=e[s];if(r==null)break;yield r}const{linkedListOperations:n,recentHead:i}=this;for(;;){const s=n.front(i);if(s==null)break;yield s}}}delete(e){const n=e.priorityTier;if(n===q.RECENT)this.linkedListOperations.pop(e);else{const i=this.heapRoots;i[n]=this.heapOperations.remove(i[n],e)}}}function wd(t){return new Sc(new ud(t),Pu)}function ot(t){return new Sc(new dd(t),Au)}function ys(t,e,n,i,s,r){for(;e.availableItems<1||e.availableSize<t;){const o=s.next().value;if(o===void 0)return!1;const a=o.priorityTier;if(a<n||a===n&&o.priority>=i)return!1;r(o)}return!0}class Sd extends wt{constructor(e,n){super(),this.itemLimit=e,this.sizeLimit=n,this.currentSize=0,this.currentItems=0,this.capacityChanged=new Ht,this.registerDisposer(e.changed.add(this.capacityChanged.dispatch)),this.registerDisposer(n.changed.add(this.capacityChanged.dispatch))}adjust(e,n){this.currentItems-=e,this.currentSize-=n}get availableSize(){return this.sizeLimit.value-this.currentSize}get availableItems(){return this.itemLimit.value-this.currentItems}toString(){return`bytes=${this.currentSize}/${this.sizeLimit.value},items=${this.currentItems}/${this.itemLimit.value}`}}let Eo=class extends xe{constructor(t,e){super(t,e),this.sources=new Set,this.queuedDownloadPromotionQueue=[ot(ne.priorityGreater),ot(ne.priorityGreater)],this.queuedComputePromotionQueue=ot(ne.priorityGreater),this.downloadEvictionQueue=[ot(ne.priorityLess),ot(ne.priorityLess)],this.computeEvictionQueue=ot(ne.priorityLess),this.systemMemoryEvictionQueue=wd(ne.priorityLess),this.gpuMemoryPromotionQueue=ot(ne.priorityGreater),this.gpuMemoryEvictionQueue=ot(ne.priorityLess),this.updatePending=null,this.gpuMemoryChanged=new Ht,this.numQueued=0,this.numFailed=0,this.gpuMemoryGeneration=0;const n=i=>{const s=this.registerDisposer(new Sd(t.get(i.itemLimit),t.get(i.sizeLimit)));return s.capacityChanged.add(()=>this.scheduleUpdate()),s};this.gpuMemoryCapacity=n(e.gpuMemoryCapacity),this.systemMemoryCapacity=n(e.systemMemoryCapacity),this.enablePrefetch=t.get(e.enablePrefetch),this.downloadCapacity=[n(e.downloadCapacity),n(e.downloadCapacity)],this.computeCapacity=n(e.computeCapacity)}scheduleUpdate(){this.updatePending===null&&(this.updatePending=setTimeout(this.process.bind(this),0))}*chunkQueuesForChunk(t){switch(t.state){case N.QUEUED:t.isComputational?yield this.queuedComputePromotionQueue:yield this.queuedDownloadPromotionQueue[t.source.sourceQueueLevel];break;case N.DOWNLOADING:t.isComputational?yield this.computeEvictionQueue:(yield this.downloadEvictionQueue[t.source.sourceQueueLevel],yield this.systemMemoryEvictionQueue);break;case N.SYSTEM_MEMORY_WORKER:case N.SYSTEM_MEMORY:yield this.systemMemoryEvictionQueue,t.requestedState===N.GPU_MEMORY&&(yield this.gpuMemoryPromotionQueue);break;case N.GPU_MEMORY:yield this.systemMemoryEvictionQueue,yield this.gpuMemoryEvictionQueue;break}}adjustCapacitiesForChunk(t,e){const n=e?-1:1;switch(t.state){case N.FAILED:this.numFailed-=n;break;case N.QUEUED:this.numQueued-=n;break;case N.DOWNLOADING:(t.isComputational?this.computeCapacity:this.downloadCapacity[t.source.sourceQueueLevel]).adjust(n*t.downloadSlots,n*t.systemMemoryBytes),this.systemMemoryCapacity.adjust(n,n*t.systemMemoryBytes);break;case N.SYSTEM_MEMORY:case N.SYSTEM_MEMORY_WORKER:this.systemMemoryCapacity.adjust(n,n*t.systemMemoryBytes);break;case N.GPU_MEMORY:this.systemMemoryCapacity.adjust(n,n*t.systemMemoryBytes),this.gpuMemoryCapacity.adjust(n,n*t.gpuMemoryBytes);break}}removeChunkFromQueues_(t){Xe(t,-1);for(const e of this.chunkQueuesForChunk(t))e.delete(t)}addChunkToQueues_(t){if(t.state===N.QUEUED&&t.priorityTier===q.RECENT){const{source:e}=t;return e.removeChunk(t),this.adjustCapacitiesForChunk(t,!1),!1}Xe(t,1);for(const e of this.chunkQueuesForChunk(t))e.add(t);return!0}performChunkPriorityUpdate(t){if(t.priorityTier===t.newPriorityTier&&t.priority===t.newPriority){t.newPriorityTier=q.RECENT,t.newPriority=Number.NEGATIVE_INFINITY;return}this.removeChunkFromQueues_(t),t.updatePriorityProperties(),t.state===N.NEW&&(t.state=N.QUEUED,this.adjustCapacitiesForChunk(t,!0)),this.addChunkToQueues_(t)}updateChunkState(t,e){e!==t.state&&(this.adjustCapacitiesForChunk(t,!1),this.removeChunkFromQueues_(t),t.state=e,this.adjustCapacitiesForChunk(t,!0),this.addChunkToQueues_(t),this.scheduleUpdate())}processGPUPromotions_(){const t=this;function e(r){t.freeChunkGPUMemory(r),r.source.chunkManager.queueManager.updateChunkState(r,N.SYSTEM_MEMORY)}const n=this.gpuMemoryPromotionQueue.candidates(),i=this.gpuMemoryEvictionQueue.candidates(),s=this.gpuMemoryCapacity;for(;;){const r=n.next().value;if(r===void 0)break;const o=r.priorityTier,a=r.priority;if(!ys(r.gpuMemoryBytes,s,o,a,i,e))break;this.copyChunkToGPU(r),this.updateChunkState(r,N.GPU_MEMORY)}}freeChunkGPUMemory(t){++this.gpuMemoryGeneration,this.rpc.invoke("Chunk.update",{id:t.key,state:N.SYSTEM_MEMORY,source:t.source.rpcId})}freeChunkSystemMemory(t){t.state===N.SYSTEM_MEMORY_WORKER?t.freeSystemMemory():this.rpc.invoke("Chunk.update",{id:t.key,state:N.EXPIRED,source:t.source.rpcId})}retrieveChunkData(t){return this.rpc.promiseInvoke("Chunk.retrieve",{key:t.key,source:t.source.rpcId})}copyChunkToGPU(t){++this.gpuMemoryGeneration;const e=this.rpc;if(t.state===N.SYSTEM_MEMORY)e.invoke("Chunk.update",{id:t.key,source:t.source.rpcId,state:N.GPU_MEMORY});else{const n={},i=[];t.serialize(n,i),n.state=N.GPU_MEMORY,e.invoke("Chunk.update",n,i)}}moveChunkToFrontend(t){const e=this.rpc,n={},i=[];t.serialize(n,i),n.state=N.SYSTEM_MEMORY,e.invoke("Chunk.update",n,i)}processQueuePromotions_(){const t=n=>{switch(n.state){case N.DOWNLOADING:Io(n);break;case N.GPU_MEMORY:this.freeChunkGPUMemory(n);case N.SYSTEM_MEMORY_WORKER:case N.SYSTEM_MEMORY:this.freeChunkSystemMemory(n);break}this.updateChunkState(n,N.QUEUED)},e=(n,i,s)=>{const r=this.systemMemoryEvictionQueue.candidates(),o=this.systemMemoryCapacity;for(;;){const a=n.next();if(a.done)return;const c=a.value,l=0,u=c.priorityTier,h=c.priority;if(!ys(l,s,u,h,i,t)||!ys(l,o,u,h,r,t))return;this.updateChunkState(c,N.DOWNLOADING),vd(c)}};for(let n=0;n<yd;++n)e(this.queuedDownloadPromotionQueue[n].candidates(),this.downloadEvictionQueue[n].candidates(),this.downloadCapacity[n]);e(this.queuedComputePromotionQueue.candidates(),this.computeEvictionQueue.candidates(),this.computeCapacity)}process(){if(!this.updatePending)return;this.updatePending=null;const t=this.gpuMemoryGeneration;this.processGPUPromotions_(),this.processQueuePromotions_(),this.logStatistics(),this.gpuMemoryGeneration!==t&&this.gpuMemoryChanged.dispatch()}logStatistics(){}invalidateSourceCache(t){for(const e of t.chunks.values()){switch(e.state){case N.DOWNLOADING:Io(e);break;case N.SYSTEM_MEMORY_WORKER:e.freeSystemMemory();break}this.updateChunkState(e,N.QUEUED)}this.rpc.invoke("Chunk.update",{source:t.rpcId}),this.scheduleUpdate()}};Eo=vr([L(Cu)],Eo);class Sr extends xe{constructor(){super(...arguments),this.chunkManagerGeneration=-1,this.numVisibleChunksNeeded=0,this.numVisibleChunksAvailable=0,this.numPrefetchChunksNeeded=0,this.numPrefetchChunksAvailable=0}}const Co=200;let _o=class extends xe{constructor(t,e){super(t,e),this.existingTierChunks=[],this.newTierChunks=[],this.updatePending=null,this.recomputeChunkPriorities=new Ht,this.recomputeChunkPrioritiesLate=new Ht,this.memoize=new hd,this.layers=[],this.sendLayerChunkStatistics=this.registerCancellable(vo(()=>{this.rpc.invoke(Tu,{id:this.rpcId,layers:this.layers.map(n=>({id:n.rpcId,numVisibleChunksAvailable:n.numVisibleChunksAvailable,numVisibleChunksNeeded:n.numVisibleChunksNeeded,numPrefetchChunksAvailable:n.numPrefetchChunksAvailable,numPrefetchChunksNeeded:n.numPrefetchChunksNeeded}))})},Co)),this.queueManager=t.get(e.chunkQueueManager).addRef(),this.registerDisposer(this.queueManager.gpuMemoryChanged.add(this.registerCancellable(vo(()=>this.scheduleUpdateChunkPriorities(),Co,{leading:!1,trailing:!0}))));for(let n=q.FIRST_TIER;n<=q.LAST_TIER;++n)n!==q.RECENT&&(this.existingTierChunks[n]=[])}scheduleUpdateChunkPriorities(){this.updatePending===null&&(this.updatePending=setTimeout(this.recomputeChunkPriorities_.bind(this),0))}registerLayer(t){const e=this.recomputeChunkPriorities.count;t.chunkManagerGeneration!==e&&(t.chunkManagerGeneration=e,this.layers.push(t),t.numVisibleChunksAvailable=0,t.numVisibleChunksNeeded=0,t.numPrefetchChunksAvailable=0,t.numPrefetchChunksNeeded=0)}recomputeChunkPriorities_(){this.updatePending=null,this.layers.length=0,this.recomputeChunkPriorities.dispatch(),this.recomputeChunkPrioritiesLate.dispatch(),this.updateQueueState([q.VISIBLE,q.PREFETCH]),this.sendLayerChunkStatistics()}requestChunk(t,e,n,i=N.GPU_MEMORY){if(Number.isNaN(n))return;if(e===q.RECENT)throw new Error("Not going to request a chunk with the RECENT tier");t.newRequestedState=Math.min(t.newRequestedState,i),t.newPriorityTier===q.RECENT&&this.newTierChunks.push(t);const s=t.newPriorityTier;(e<s||e===s&&n>t.newPriority)&&(t.newPriorityTier=e,t.newPriority=n)}updateQueueState(t){const e=this.existingTierChunks,n=this.queueManager;for(const s of t){const r=e[s];for(const o of r)o.newPriorityTier===q.RECENT&&n.performChunkPriorityUpdate(o);r.length=0}const i=this.newTierChunks;for(const s of i)n.performChunkPriorityUpdate(s),e[s.priorityTier].push(s);i.length=0,this.queueManager.scheduleUpdate()}};_o=vr([L(_u)],_o);function re(t,e){let n=class extends t{constructor(...i){super(...i);const s=i[1];this.parameters=s.parameters}};return n=vr([gu(e.RPC_ID)],n),n}function st(t){return class extends t{constructor(...e){super(...e);const n=e[0],i=e[1];this.chunkManager=n.get(i.chunkManager)}}}K(bu,function(t){const e=this.get(t.id);e.chunkManager.queueManager.invalidateSourceCache(e)});Ji(Mu,function(t){const e=this.get(t.queue),n=new Map;for(const i of e.sources)n.set(i.rpcId,i.statistics);return Promise.resolve({value:n})});/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const Id="rendered_view.addLayer",Ed="rendered_view.removeLayer",Cd="SharedProjectionParameters",_d="SharedProjectionParameters.changed";var bd=Object.defineProperty,Md=Object.getOwnPropertyDescriptor,Td=(t,e,n,i)=>{for(var s=i>1?void 0:i?Md(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&bd(e,n,s),s};class Pd extends wt{constructor(e){super(),this.view=e,this.state=void 0}}class Qi extends Sr{constructor(){super(...arguments),this.attachments=new Map}attach(e){}}K(Id,function(t){const e=this.get(t.view),n=this.get(t.layer),i=new Pd(e);n.attachments.set(e,i),n.attach(i)});K(Ed,function(t){const e=this.get(t.view),n=this.get(t.layer),i=n.attachments.get(e);n.attachments.delete(e),i.dispose()});let bo=class extends xe{constructor(t,e){super(t,e),this.changed=new Hi,this.value=e.value,this.oldValue=Object.assign({},this.value)}};bo=Td([L(Cd)],bo);K(_d,function(t){const e=this.get(t.id),{value:n,oldValue:i}=e;Object.assign(i,n),Object.assign(n,t.value),e.changed.dispatch(i,n)});function Ad(t,e,n){const i=t.length;for(let s=0;s<i;++s)t[s]=e[s]+n[s];return t}function xd(t,e,n){const i=t.length;for(let s=0;s<i;++s)t[s]=e[s]*n[s];return t}function Nd(t){let e=1;for(let n=0,i=t.length;n<i;++n)e*=t[n];return e}function Od(t,e,n){const i=t.length;for(let s=0;s<i;++s)t[s]=Math.min(e[s],n[s]);return t}function Rd(t,e,n){const i=t.length;for(let s=0;s<i;++s)t[s]=Math.max(e[s],n[s]);return t}const Ic=new Float64Array(0);function Dd(t,e,n){for(let i=0;i<n;++i){const s=e*i;t.fill(0,s,s+n),t[s+i]=1}return t}function kd(t,e,n=e){return Dd(new t(e*n),e,Math.min(e,n))}function Ud(t,e,n,i,s,r){for(let o=0;o<r;++o){const a=o*i,c=o*e;for(let l=0;l<s;++l)t[c+l]=n[a+l]}return t}let Ne;function Ld(t,e,n){let i=1;(Ne===void 0||Ne.length<n)&&(Ne=new Uint32Array(n));for(let s=0;s<n;++s)Ne[s]=s;for(let s=0;s<n;++s){const r=e*s;let o=s;{let l=Math.abs(t[r+s]);for(let u=s+1;u<n;++u){const h=Math.abs(t[r+u]);h>l&&(l=h,o=u)}}if(s!==o){i*=-1;for(let l=0;l<n;++l){const u=e*l,h=t[u+s];t[u+s]=t[u+o],t[u+o]=h}{const l=Ne[s];Ne[s]=Ne[o],Ne[o]=l}}const a=t[r+s],c=1/a;i*=a;for(let l=0;l<n;++l)t[e*l+s]*=c;t[r+s]=c;for(let l=0;l<n;++l){if(l===s)continue;const u=-t[e*s+l];for(let h=0;h<n;++h){const d=e*h;t[d+l]+=u*t[d+s]}t[e*s+l]=u*c}}for(let s=0;s<n;++s){let r=Ne[s];for(;r!==s;){const o=e*s,a=e*r;for(let l=0;l<n;++l){const u=o+l,h=a+l,d=t[u];t[u]=t[h],t[h]=d}const c=Ne[s]=Ne[r];Ne[r]=r,r=c}}return i}function zd(t,e,n,i,s){return Ud(t,e,n,i,s,s),Ld(t,e,s)}const $d=[{prefix:"Y",exponent:24,longPrefix:"yotta"},{prefix:"Z",exponent:21,longPrefix:"zetta"},{prefix:"E",exponent:18,longPrefix:"exa"},{prefix:"P",exponent:15,longPrefix:"peta"},{prefix:"T",exponent:12,longPrefix:"tera"},{prefix:"G",exponent:9,longPrefix:"giga"},{prefix:"M",exponent:6,longPrefix:"mega"},{prefix:"k",exponent:3,longPrefix:"kilo"},{prefix:"",exponent:0,longPrefix:""},{prefix:"m",exponent:-3,longPrefix:"milli"},{prefix:"µ",exponent:-6,longPrefix:"micro"},{prefix:"n",exponent:-9,longPrefix:"nano"},{prefix:"p",exponent:-12,longPrefix:"pico"},{prefix:"f",exponent:-15,longPrefix:"femto"},{prefix:"a",exponent:-18,longPrefix:"atto"},{prefix:"z",exponent:-21,longPrefix:"zepto"},{prefix:"y",exponent:-24,longPrefix:"yocto"}],Ec=[...$d,{prefix:"h",exponent:2,longPrefix:"hecto"},{prefix:"da",exponent:1,longPrefix:"deca"},{prefix:"d",exponent:-1,longPrefix:"deci"},{prefix:"c",exponent:-2,longPrefix:"centi"}],Fd=[{prefix:"u",exponent:-6},...Ec],Cc=new Map;Cc.set("",{unit:"",exponent:0});const Bd=new Map;for(const{prefix:t,exponent:e}of Fd){Bd.set(e,t);for(const n of["m","s","Hz","rad/s"])Cc.set(`${t}${n}`,{unit:n,exponent:e})}function _c(t){const{names:e,units:n,scales:i}=t,{valid:s=!0,rank:r=e.length,timestamps:o=e.map(()=>Number.NEGATIVE_INFINITY),ids:a=e.map((h,d)=>-d),boundingBoxes:c=[]}=t,{coordinateArrays:l=new Array(r)}=t,{bounds:u=Gd(c,r)}=t;return{valid:s,rank:r,names:e,timestamps:o,ids:a,units:n,scales:i,boundingBoxes:c,bounds:u,coordinateArrays:l}}_c({valid:!1,names:[],units:[],scales:Ic,boundingBoxes:[]});_c({valid:!0,names:[],units:[],scales:Ic,boundingBoxes:[]});function Vd(t,e,n){const{box:{lowerBounds:i,upperBounds:s},transform:r}=t,o=i.length,a=n,c=r[a*o+e];let l=c,u=c,h=!1;for(let d=0;d<o;++d){const p=r[a*d+e];if(p===0)continue;const g=p*i[d],f=p*s[d];l+=Math.min(g,f),u+=Math.max(g,f),h=!0}if(h)return{lower:l,upper:u}}function Gd(t,e){const n=new Float64Array(e),i=new Float64Array(e);n.fill(Number.NEGATIVE_INFINITY),i.fill(Number.POSITIVE_INFINITY);const s=new Array(e);s.fill(0);const r=new Array(e);r.fill(0);for(const a of t)for(let c=0;c<e;++c){const l=Vd(a,c,e);if(l===void 0)continue;const{lower:u,upper:h}=l;if(Number.isFinite(u)&&Number.isFinite(h)){const d=Math.floor(u),p=Math.floor(h);d===u&&p===h?++r[c]:u-d===.5&&h-p===.5&&++s[c]}n[c]=n[c]===Number.NEGATIVE_INFINITY?u:Math.min(n[c],u),i[c]=i[c]===Number.POSITIVE_INFINITY?h:Math.max(i[c],h)}const o=r.map((a,c)=>s[c]>0&&a===0);return{lowerBounds:n,upperBounds:i,voxelCenterAtIntegerCoordinates:o}}function jd(t,e,n,i,s){const r=e.length,o=n.length,a=t.length;let c=!0;for(let l=0;l<i;++l){let u=l,h=0;for(let d=0;d<r;++d)h+=s[u+d*i]*e[d];u+=r*i;for(let d=0;d<o;++d)h+=s[u+d*i]*n[d];h+=s[u+o*i],l<a?t[l]=h:(h<0||h>=1)&&(c=!1)}return c}function qd(t,e,n){t.fill(0),t[15]=1;let i=!0;const{displayDimensionIndices:s}=e,{globalToRenderLayerDimensions:r,modelToRenderLayerTransform:o}=n,a=n.rank;for(let c=0;c<3;++c){const l=s[c];if(l===-1){i=!1;continue}const u=r[l];if(u===-1){i=!1;continue}t[c+12]=o[u+a*(a+1)];for(let h=0;h<3;++h)t[c+4*h]=o[u+(a+1)*h]}if(!i){const{globalDimensionNames:c}=e,l=Array.from(s.filter(u=>u!==-1),u=>c[u]).join(", ");throw new Error(`Transform from model dimensions (${n.modelDimensionNames.join(", ")}) to display dimensions (${l}) does not have full rank`)}}class Xi{constructor(e,n,i){this.size=As(e),this.transform=xu(n),this.finiteRank=i;const s=_t(),r=zd(s,4,n,4,4);if(r===0)throw new Error("Transform is singular");this.invTransform=s,this.detTransform=r}toObject(){return{size:this.size,transform:this.transform,finiteRank:this.finiteRank}}static fromObject(e){return new Xi(e.size,e.transform,e.finiteRank)}globalToLocalSpatial(e,n){return ku(e,n,this.invTransform)}localSpatialVectorToGlobal(e,n){return Yu(e,n,this.transform)}globalToLocalNormal(e,n){return Hu(e,n,this.transform)}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var V=(t=>(t[t.UINT8=0]="UINT8",t[t.INT8=1]="INT8",t[t.UINT16=2]="UINT16",t[t.INT16=3]="INT16",t[t.UINT32=4]="UINT32",t[t.INT32=5]="INT32",t[t.UINT64=6]="UINT64",t[t.FLOAT32=7]="FLOAT32",t))(V||{});const Qt={0:1,1:1,2:2,3:2,4:4,5:4,6:8,7:4},bc={0:Uint8Array,1:Int8Array,2:Uint16Array,3:Int16Array,4:Uint32Array,5:Int32Array,6:Uint32Array,7:Float32Array},Mc={0:1,1:1,2:1,3:1,4:1,5:1,6:2,7:1};function Tc(t,e,n=0,i=e.byteLength){const s=Qt[t],r=Mc[t];return new bc[t](e,n,i/s*r)}const Yd=_t();function Hd(t,e){let n=0,i=Math.abs(t.detTransform);const{transform:s,size:r}=t;for(let o=0;o<3;++o){let a=0;for(let l=0;l<3;++l)a+=e[l*4+2]*s[4*o+l];const c=r[o];n+=Math.abs(a)*c,i*=c}return i/n}function Pc(t,e,n){const{curPositionInChunks:i,fixedPositionWithinChunk:s}=t,{nonDisplayLowerClipBound:r,nonDisplayUpperClipBound:o}=t,{rank:a,chunkDataSize:c}=t.source.spec;if(!jd(i,e,n,t.layerRank,t.fixedLayerToChunkTransform))return!1;for(let l=0;l<a;++l){const u=i[l];if(u<r[l]||u>=o[l])return!1;const h=c[l],d=i[l]=Math.floor(u/h);s[l]=u-d*h}return!0}function Kd(t,e){const n=e.length;let i=0;if(n>1){let s=0;for(let r=0;r<n;++r){const o=e[r],{chunkLayout:a}=o,c=Hd(a,t);c>s&&(s=c,i=r)}}return i}const kt=new Xi(Q(),_t(),0);function Jd(t,e){if(t.displayDimensionRenderInfo!==e.displayDimensionRenderInfo||t.pixelSize!==e.pixelSize)return!0;const{viewMatrix:n}=t,{viewMatrix:i}=e;for(let s=0;s<12;++s)if(n[s]!==i[s])return!0;return!1}class Wd extends dr{constructor(e){super(),this.projectionParameters=e,this.visibleLayers=new Map,this.visibleSourcesStale=!0,this.registerDisposer(e.changed.add((n,i)=>{Jd(n,i)&&this.invalidateVisibleSources(),this.invalidateVisibleChunks()}))}invalidateVisibleSources(){this.visibleSourcesStale=!0}invalidateVisibleChunks(){}updateVisibleSources(){if(!this.visibleSourcesStale)return;this.visibleSourcesStale=!1;const e=this.projectionParameters.value.displayDimensionRenderInfo,{visibleLayers:n}=this;for(const[i,{allSources:s,visibleSources:r,displayDimensionRenderInfo:o}]of n){if(r.length=0,o!==e||s.length===0)continue;const a=Kd(this.projectionParameters.value.viewMatrix,s.map(l=>l[0])),c=s[a];for(const l of i.filterVisibleSources(this,c))r.push(l);r.reverse()}}}function*Zd(t,e,n){const i=t.projectionParameters.value.pixelSize*1.1,s=n[0].effectiveVoxelSize,r=e.renderScaleTarget.value,o=u=>{const h=i*r;for(let d=0;d<3;++d){const p=u[d];if(p>h&&p>1.01*s[d])return!0}return!1},a=(u,h)=>{const d=i*r;for(let p=0;p<3;++p){const g=u[p],f=h[p];if(Math.abs(d-g)<Math.abs(d-f)&&g<1.01*f)return!0}return!1};let c=n.length-1,l;for(;;){const u=n[c];if(l!==void 0&&!a(u.effectiveVoxelSize,l)||(yield u,c===0||!o(u.effectiveVoxelSize)))break;l=u.effectiveVoxelSize,--c}}const Qd="SliceView",Xd="sliceview/RenderLayer",ef="SliceView.addVisibleLayer",tf="SliceView.removeVisibleLayer",nf="ChunkManager.requestChunk",Ir=new Float32Array(3),Er=new Float32Array(3),Ac=_t(),xc=new Float32Array(24);function Nc(t,e,n,i){const s=Ir,r=Er,{lowerChunkDisplayBound:o,upperChunkDisplayBound:a}=e;for(let h=0;h<3;++h)s[h]=Math.max(s[h],o[h]),r[h]=Math.min(r[h],a[h]);const{curPositionInChunks:c,chunkDisplayDimensionIndices:l}=e;function u(){if(!i(s[0],s[1],s[2],r[0],r[1],r[2],t))return;let h=0,d=Math.max(0,r[0]-s[0]),p=d;for(let S=1;S<3;++S){const I=Math.max(0,r[S]-s[S]);p*=I,I>d&&(d=I,h=S)}if(p===0)return;if(p===1){c[l[0]]=s[0],c[l[1]]=s[1],c[l[2]]=s[2],n(s,t);return}const g=s[h],f=r[h],v=Math.floor(.5*(g+f));r[h]=v,u(),r[h]=f,s[h]=v,u(),s[h]=g}u()}function Oc(t,e,n,i){if(!Pc(n,t.globalPosition,e))return;const{size:s}=n.chunkLayout,r=gr(Ac,t.viewProjectionMat,n.chunkLayout.transform);for(let l=0;l<3;++l){const u=s[l];for(let h=0;h<4;++h)r[4*l+h]*=u}const o=xc;yc(o,r);const a=Ir,c=Er;a.fill(Number.NEGATIVE_INFINITY),c.fill(Number.POSITIVE_INFINITY),Nc(o,n,i,vc)}function Rc(t,e,n,i,s){if(!Pc(n,t.globalPosition,e))return;const{size:r}=i,o=gr(Ac,t.viewProjectionMat,i.transform);for(let d=0;d<3;++d){const p=r[d];for(let g=0;g<4;++g)o[4*d+g]*=p}const a=Yd;fc(a,o);const c=Ir,l=Er,u=.001;for(let d=0;d<3;++d){const p=a[12+d]+u/r[d],g=Math.abs(a[d]),f=Math.abs(a[4+d]);c[d]=Math.floor(p-g-f),l[d]=Math.floor(p+g+f+1)}const h=xc;for(let d=0;d<3;++d){const p=o[4*d],g=o[4*d+1],f=o[4*d+2];h[d]=p,h[4+d]=-p,h[8+d]=+g,h[12+d]=-g,h[16+d]=+f,h[20+d]=-f}{const p=o[12],g=o[4*3+1],f=o[4*3+2];h[3]=1+p,h[7]=1-p,h[11]=1+g,h[15]=1-g,h[19]=f,h[23]=-f}Nc(h,n,s,Ju)}function Dc(t,e){const{finiteRank:n}=e;if(n===3)return e;kt.finiteRank=n,Wi(kt.size,e.size);const i=So(kt.transform,e.transform),s=So(kt.invTransform,e.invTransform);kt.detTransform=e.detTransform;const{invViewMatrix:r,width:o,height:a}=t,c=wc(t.projectionMat);for(let l=n;l<3;++l){const u=r[12+l];let h=u,d=u;const p=Math.abs(r[l]*o);h-=p,d+=p;const g=Math.abs(r[l+4]*a);h-=g,d+=g;const f=Math.abs(r[l+8]*c);h-=f,d+=f;const v=Math.max(1,d-h);i[12+l]=h,i[5*l]=v}return fc(s,i),kt}/**
 * @license
 * Copyright 2020 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function sf(t){const e=.254829592,n=-.284496736,i=1.421413741,s=-1.453152027,r=1.061405429,a=1/(1+.3275911*Math.abs(t)),c=1-((((r*a+s)*a+i)*a+n)*a+e)*a*Math.exp(-t*t);return Math.sign(t)*c}/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const rf=50,of=1e3;class af{constructor(e=rf,n=of){this.velocityHalfLifeMilliseconds=e,this.modelHalfLifeMilliseconds=n,this.lastTime=Number.NEGATIVE_INFINITY,this.rank=0,this.numSamples=0,this.prevPosition=new Float32Array,this.velocity=new Float32Array,this.mean=new Float32Array,this.variance=new Float32Array}reset(e){this.lastTime=Number.NEGATIVE_INFINITY,this.rank=e,this.numSamples=0,this.velocity=new Float32Array(e),this.prevPosition=new Float32Array(e),this.mean=new Float32Array(e),this.variance=new Float32Array(e)}addSample(e,n=Date.now()){const i=e.length;i!==this.rank&&this.reset(i);const s=this.numSamples;if(++this.numSamples,this.numSamples===0){this.prevPosition.set(e),this.lastTime=n;return}const r=n-this.lastTime;this.lastTime=n;const o=1-2**-(r/this.velocityHalfLifeMilliseconds),a=1-2**-(r/this.modelHalfLifeMilliseconds),{velocity:c,prevPosition:l,mean:u,variance:h}=this;for(let d=0;d<i;++d){const p=(e[d]-l[d])/Math.max(r,1);l[d]=e[d];const g=c[d],f=c[d]=g+o*(p-g);if(s===1)u[d]=f;else{const v=u[d],S=h[d],I=f-v;u[d]=v+a*I,h[d]=(1-a)*(S+a*I*I)}}}}function bt(t){return class extends t{constructor(...e){super(...e);const n=e[0],i=e[1];this.visibility=n.get(i.visibility),this.registerDisposer(this.visibility.changed.add(()=>this.chunkManager.scheduleUpdateChunkPriorities()))}}}function je(t){return t===Number.POSITIVE_INFINITY?q.VISIBLE:q.PREFETCH}function qe(t){return t===Number.POSITIVE_INFINITY?0:t*Eu}var cf=Object.defineProperty,lf=Object.getOwnPropertyDescriptor,kc=(t,e,n,i)=>{for(var s=i>1?void 0:i?lf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&cf(e,n,s),s};const Uc=-1e12,Cr=1e9,Mo=Q(),hf=Q(),uf=Q();class df extends Wd{constructor(e,n){super(e.get(n.projectionParameters)),this.initializeSharedObject(e,n.id)}}function To(t){for(const e of t)for(const n of e)n.source.dispose()}const ff=bt(st(df));let Po=class extends ff{constructor(t,e){super(t,e),this.velocityEstimator=new af,this.handleLayerChanged=()=>{this.chunkManager.scheduleUpdateChunkPriorities()},this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateVisibleChunks()})),this.registerDisposer(this.projectionParameters.changed.add(()=>{this.velocityEstimator.addSample(this.projectionParameters.value.globalPosition)}))}invalidateVisibleChunks(){super.invalidateVisibleChunks(),this.chunkManager.scheduleUpdateChunkPriorities()}updateVisibleChunks(){const t=this.projectionParameters.value,e=this.chunkManager,n=this.visibility.value;if(n===Number.NEGATIVE_INFINITY)return;this.updateVisibleSources();const{centerDataPosition:i}=t,s=je(n);let r=qe(n);r+=Uc;const o=hf,a=uf,c=[];this.velocityEstimator.addSample(this.projectionParameters.value.globalPosition);for(const[l,u]of this.visibleLayers){e.registerLayer(l);const{visibleSources:h}=u;for(let d=0,p=h.length;d<p;++d){const g=h[d],f=e.queueManager.enablePrefetch.value?gf(this.velocityEstimator,g):[],{chunkLayout:v}=g;v.globalToLocalSpatial(o,i);const{size:S,finiteRank:I}=v;Wi(a,S);for(let m=I;m<3;++m)a[m]=0,o[m]=0;const w=r+Cr*d;c.length=0;const M=md();if(Rc(t,g.renderLayer.localPosition.value,g,Dc(t,g.chunkLayout),m=>{It(Mo,m,a);const E=-mr(o,Mo),{curPositionInChunks:y}=g,_=g.source.getChunk(y);e.requestChunk(_,s,w+E),++l.numVisibleChunksNeeded,_.state===N.GPU_MEMORY&&++l.numVisibleChunksAvailable,c.push(_),_.markGeneration=M}),f.length!==0){const{curPositionInChunks:m}=g;for(const E of c){m.set(E.chunkGridPosition);for(let y=0,_=f.length;y<_;){const T=f[y],P=f[y+2],A=f[y+3],D=f[y+4],x=f[y+5],F=m[T],z=F+f[y+1];if(z<P||z>A){y=x;continue}m[T]=z;const U=g.source.getChunk(m);if(m[T]=F,U.markGeneration===M){y=x;continue}e.requestChunk(U,q.PREFETCH,w+D),++l.numPrefetchChunksNeeded,U.state===N.GPU_MEMORY&&++l.numPrefetchChunksAvailable,y+=_n}}}}}}removeVisibleLayer(t){const{visibleLayers:e}=this,n=e.get(t);e.delete(t),To(n.allSources),t.renderScaleTarget.changed.remove(this.invalidateVisibleSources),t.localPosition.changed.remove(this.handleLayerChanged),this.invalidateVisibleSources()}addVisibleLayer(t,e){const{displayDimensionRenderInfo:n}=this.projectionParameters.value;let i=this.visibleLayers.get(t);i===void 0?(i={allSources:e,visibleSources:[],displayDimensionRenderInfo:n},this.visibleLayers.set(t,i),t.renderScaleTarget.changed.add(()=>this.invalidateVisibleSources()),t.localPosition.changed.add(this.handleLayerChanged)):(To(i.allSources),i.allSources=e,i.visibleSources.length=0,i.displayDimensionRenderInfo=n),this.invalidateVisibleSources()}disposed(){for(const t of this.visibleLayers.keys())this.removeVisibleLayer(t);super.disposed()}invalidateVisibleSources(){super.invalidateVisibleSources(),this.chunkManager.scheduleUpdateChunkPriorities()}};Po=kc([L(Qd)],Po);function es(t,e,n){return e.map(s=>s.map(r=>{const o=t.getRef(r.source),a=r.chunkLayout,{rank:c}=o.spec;return{renderLayer:n,source:o,chunkLayout:Xi.fromObject(a),layerRank:r.layerRank,nonDisplayLowerClipBound:r.nonDisplayLowerClipBound,nonDisplayUpperClipBound:r.nonDisplayUpperClipBound,lowerClipBound:r.lowerClipBound,upperClipBound:r.upperClipBound,lowerClipDisplayBound:r.lowerClipDisplayBound,upperClipDisplayBound:r.upperClipDisplayBound,lowerChunkDisplayBound:r.lowerChunkDisplayBound,upperChunkDisplayBound:r.upperChunkDisplayBound,effectiveVoxelSize:r.effectiveVoxelSize,chunkDisplayDimensionIndices:r.chunkDisplayDimensionIndices,fixedLayerToChunkTransform:r.fixedLayerToChunkTransform,combinedGlobalLocalToChunkTransform:r.combinedGlobalLocalToChunkTransform,curPositionInChunks:new Float32Array(c),fixedPositionWithinChunk:new Uint32Array(c)}}))}K(ef,function(t){const e=this.get(t.id),n=this.get(t.layerId),i=es(this,t.sources,n);e.addVisibleLayer(n,i)});K(tf,function(t){const e=this.get(t.id),n=this.get(t.layerId);e.removeVisibleLayer(n)});class Lc extends ne{constructor(){super(...arguments),this.source=null}initializeVolumeChunk(e,n){super.initialize(e),this.chunkGridPosition=Float32Array.from(n)}serialize(e,n){super.serialize(e,n),e.chunkGridPosition=this.chunkGridPosition}downloadSucceeded(){super.downloadSucceeded()}freeSystemMemory(){}toString(){return this.source.toString()+":"+Vt(this.chunkGridPosition)}}class zc extends Le{constructor(e,n){super(e,n),this.spec=n.spec}getChunk(e){const n=e.join();let i=this.chunks.get(n);return i===void 0&&(i=this.getNewChunk_(this.chunkConstructor),i.initializeVolumeChunk(n,e),this.addChunk(i)),i}}let Ao=class extends xe{constructor(t,e){super(t,e),this.renderScaleTarget=t.get(e.renderScaleTarget),this.localPosition=t.get(e.localPosition),this.numVisibleChunksNeeded=0,this.numVisibleChunksAvailable=0,this.numPrefetchChunksAvailable=0,this.numPrefetchChunksNeeded=0,this.chunkManagerGeneration=-1}filterVisibleSources(t,e){return Zd(t,this,e)}};Ao=kc([L(Xd)],Ao);const xo=2e3,pf=.1,No=32,Oo=.05,_n=6;function gf(t,e){const n=[],i=t.rank,{combinedGlobalLocalToChunkTransform:s,layerRank:r}=e,{rank:o,chunkDataSize:a}=e.source.spec,{mean:c,variance:l}=t;for(let u=0;u<o;++u){const h=e.chunkDisplayDimensionIndices.includes(u);let d=0,p=0;for(let y=0;y<i;++y){const _=c[y],T=l[y],P=s[y*r+u];d+=P*_,p+=P*P*T}if(d>pf)continue;const g=a[u],f=h?0:e.fixedPositionWithinChunk[u]/g,v=d/g*xo;let S=Math.sqrt(2*p)/g*xo;if(Math.abs(v)<.001&&S<.001)continue;S=Math.max(1e-6,S);const I=y=>.5*(1+sf((y-v)/S)),C=e.curPositionInChunks[u],w=Math.floor(e.lowerClipBound[u]/g),M=Math.ceil(e.upperClipBound[u]/g)-1;let m=n.length;for(let y=1;y<=No&&!(!h&&C+y>M);++y){const _=1-I(y-f);if(_<Oo)break;n.push(u,y,w,M,_,0)}let E=n.length;for(let y=m,_=n.length;y<_;y+=_n)n[y+_n-1]=E;m=E;for(let y=1;y<=No&&!(!h&&C-y<w);++y){const _=I(-y+1-f);if(_<Oo)break;n.push(u,-y,w,M,_,0)}E=n.length;for(let y=m,_=n.length;y<_;y+=_n)n[y+_n-1]=E}return n}Ji(nf,async function(t,e){const n=this.get(t.source),{chunkManager:i}=n,s=n.getChunk(t.chunkGridPosition),r=s.key;if(s.state<=N.SYSTEM_MEMORY)return{value:void 0};const o=i.recomputeChunkPriorities.add(()=>{i.requestChunk(s,q.VISIBLE,Number.POSITIVE_INFINITY,N.SYSTEM_MEMORY)});i.scheduleUpdateChunkPriorities();let a;const c=new Promise((u,h)=>{a=d=>{if(d.state===N.FAILED){h(d.error);return}d.state<=N.SYSTEM_MEMORY&&u()}});n.registerChunkListener(r,a);const l=new Promise((u,h)=>{e.add(()=>{h(St)})});try{return await Promise.race([c,l]),{value:void 0}}finally{n.unregisterChunkListener(r,a),o(),i.scheduleUpdateChunkPriorities()}});/**
 * @license
 * Copyright 2018 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const mf="perspective_view/PerspectiveView";var yf=Object.defineProperty,vf=Object.getOwnPropertyDescriptor,wf=(t,e,n,i)=>{for(var s=i>1?void 0:i?vf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&yf(e,n,s),s};let Ro=class extends xe{constructor(...t){super(...t);const e=t[0],n=t[1];this.visibility=e.get(n.visibility),this.projectionParameters=e.get(n.projectionParameters)}};Ro=wf([L(mf)],Ro);class $c extends Qi{}const Sf="volume_rendering/VolumeRenderingRenderLayer",If="volume_rendering/VolumeRenderingRenderLayer/update",Ef=pr();function Cf(t,e,n,i,s,r){if(i.length===0)return;const{viewMatrix:o,projectionMat:a,displayDimensionRenderInfo:c}=t,{voxelPhysicalScales:l}=c,u=Ns(l),h=wc(a),p=(h/n)**3,g=dc(mc(Ef,o)),f={spatialScales:new Map,activeIndex:-1},v=E=>{const y=i[E];return Math.abs(y.chunkLayout.detTransform*g)};let S=i.length-1,I=v(S);for(let E=S;E>=0;--E){const y=v(E),_=Math.cbrt(y*u/g),T=h/Math.cbrt(y);f.spatialScales.set(_,T),y-p>=0&&(I=y,S=E),f.activeIndex=S}const C=Math.cbrt(I*u/g),w=h/Math.cbrt(I);let M=!0;const m=i[S];Oc(t,e,m,(E,y)=>{M&&(s(m,S,C,w,y,f),M=!1),r(m,S,E)})}var _f=Object.defineProperty,bf=Object.getOwnPropertyDescriptor,Mf=(t,e,n,i)=>{for(var s=i>1?void 0:i?bf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&_f(e,n,s),s};const Do=Q(),Tf=Q(),Pf=Q(),Af=Q();let ko=class extends st(Qi){constructor(t,e){super(t,e),this.renderScaleTarget=t.get(e.renderScaleTarget),this.localPosition=t.get(e.localPosition);const n=()=>this.chunkManager.scheduleUpdateChunkPriorities();this.registerDisposer(this.localPosition.changed.add(n)),this.registerDisposer(this.renderScaleTarget.changed.add(n)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>this.recomputeChunkPriorities()))}attach(t){const e=()=>this.chunkManager.scheduleUpdateChunkPriorities(),{view:n}=t;t.registerDisposer(e),t.registerDisposer(n.projectionParameters.changed.add(e)),t.registerDisposer(n.visibility.changed.add(e)),t.state={displayDimensionRenderInfo:n.projectionParameters.value.displayDimensionRenderInfo,transformedSources:[]}}recomputeChunkPriorities(){for(const t of this.attachments.values()){const{view:e}=t,n=e.visibility.value;if(n===Number.NEGATIVE_INFINITY)continue;const{transformedSources:i,displayDimensionRenderInfo:s}=t.state;if(i.length===0||s!==e.projectionParameters.value.displayDimensionRenderInfo)continue;const r=e.projectionParameters.value,o=je(n);let a=qe(n);a+=Uc;const c=Tf,l=Pf,u=Af,{globalPosition:h,displayDimensionRenderInfo:{displayDimensionIndices:d}}=r;for(let f=0;f<3;++f){const v=d[f];u[f]=v===-1?0:h[v]}let p;const{chunkManager:g}=this;g.registerLayer(this),Cf(r,this.localPosition.value,this.renderScaleTarget.value,i[0],(f,v)=>{const{chunkLayout:S}=f;S.globalToLocalSpatial(c,u);const{size:I,finiteRank:C}=S;Wi(l,I);for(let M=C;M<3;++M)l[M]=0,c[M]=0;const w=i[0].length-1-v;p=a+Cr*w},(f,v,S)=>{It(Do,S,l);const I=-mr(c,Do),C=f.source.getChunk(f.curPositionInChunks);++this.numVisibleChunksNeeded,g.requestChunk(C,o,p+I),C.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable})}}};ko=Mf([L(Sf)],ko);K(If,function(t){const e=this.get(t.view),n=this.get(t.layer),i=n.attachments.get(e);i.state.transformedSources=es(this,t.sources,n),i.state.displayDimensionRenderInfo=i.view.projectionParameters.value.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()});const xf="annotation.MetadataChunkSource",Nf="annotation.SubsetGeometryChunkSource",Of="annotation.reference.add",Rf="annotation.reference.delete",Df="annotation.commit",Uo="annotation.commit",kf="annotation/SpatiallyIndexedRenderLayer",Uf="annotation/PerspectiveRenderLayer:updateSources",Lf="annotation/RenderLayer",zf="annotation/RenderLayer.updateSegmentation",$f=pr();function Ff(t,e,n,i,s,r){const{displayDimensionRenderInfo:o,viewMatrix:a,projectionMat:c,width:l,height:u}=t,{voxelPhysicalScales:h}=o,d=Math.abs(dc(mc($f,a))),p=Ns(h),g=Wu(c)/d*p;if(i.length===0)return;const f=i[0];let v=Math.abs(f.chunkLayout.detTransform)*p;const{lowerClipDisplayBound:S,upperClipDisplayBound:I}=f;for(let y=0;y<3;++y)v*=I[y]-S[y];const C=Math.min(v,g),w=l*u,m=w/n**2/C;let E=0;for(let y=i.length-1;y>=0&&E<m;--y){const _=i[y],T=_.source.spec,{chunkLayout:P}=_,A=Ns(P.size)*Math.abs(P.detTransform)*p,{limit:D,rank:x}=T,{nonDisplayLowerClipBound:F,nonDisplayUpperClipBound:z}=_;let U=1;for(let W=0;W<x;++W){const de=z[W]-F[W];Number.isFinite(de)&&(U/=de)}const Y=D*U/A;let H=!0;const be=E+Y,ae=(1/be)**(1/3),Me=Math.sqrt(w/(be*C)),ce=(m-E)*A/U,le=Math.min(1,ce/T.limit);Oc(t,e,_,()=>{H&&(s(_,y),H=!1),r(_,y,le,ae,Me)}),E=be}}/**
 * @license
 * Copyright 2018 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const fi=new Float32Array(1);function Bf(t){fi[0]=t,t=fi[0];for(let e=1;e<21;++e){const n=t.toPrecision(e);if(fi[0]=parseFloat(n),fi[0]===t)return n}return t.toString()}/**
 * @license
 * Copyright 2017 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function Vf(t){return("0"+t.toString(16)).slice(-2)}function Gf(t){const e=/^rgba\(([0-9]+), ([0-9]+), ([0-9]+), (0(?:\.[0-9]+)?)\)$/;{const i=t.match(e);if(i!==null)return[parseInt(i[1],10),parseInt(i[2],10),parseInt(i[3],10),parseFloat(i[4])]}const n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;{const i=t.match(n);if(i!==null)return[parseInt(i[1],16),parseInt(i[2],16),parseInt(i[3],16),1]}throw new Error(`Invalid serialized color: ${JSON.stringify(t)}.`)}function Fc(t){try{if(typeof t!="string")throw new Error(`Expected string, but received ${JSON.stringify(t)}.`);const e=document.createElement("canvas").getContext("2d");e.fillStyle=t;const n=Gf(e.fillStyle);return Zi(n[0]/255,n[1]/255,n[2]/255,n[3])}catch(e){throw new Error(`Failed to parse color specification: ${e.message}`)}}function jf(t){return Fc(t).subarray(0,3)}function Lo(t){const e=t[3]===void 0?3:4;let n=0;for(let i=0;i<e;i++)n=(n<<8>>>0)+Math.min(255,Math.max(0,Math.round(t[e-1-i]*255)));return n}function qf(t){return ve((t>>>0&255)/255,(t>>>8&255)/255,(t>>>16&255)/255)}function Yf(t){return Zi((t>>>0&255)/255,(t>>>8&255)/255,(t>>>16&255)/255,(t>>>24&255)/255)}function zo(t){if(t[3]===void 0||t[3]===1){let n="#";for(let i=0;i<3;++i)n+=Vf(Math.min(255,Math.max(0,Math.round(t[i]*255))));return n}let e="rgba(";for(let n=0;n<3;++n)n!==0&&(e+=", "),e+=Math.min(255,Math.max(0,Math.round(t[n]*255)));return e+=`, ${Bf(t[3])})`,e}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var te=(t=>(t[t.LITTLE=0]="LITTLE",t[t.BIG=1]="BIG",t))(te||{});function Hf(){const t=Uint16Array.of(4386);return new Uint8Array(t.buffer)[0]===17?1:0}const ti=Hf();function Bc(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,i=e.length;n<i;n+=2){const s=e[n];e[n]=e[n+1],e[n+1]=s}}function Vc(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,i=e.length;n<i;n+=4){let s=e[n];e[n]=e[n+3],e[n+3]=s,s=e[n+1],e[n+1]=e[n+2],e[n+2]=s}}function Kf(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,i=e.length;n<i;n+=8){let s=e[n];e[n]=e[n+7],e[n+7]=s,s=e[n+1],e[n+1]=e[n+6],e[n+6]=s,s=e[n+2],e[n+2]=e[n+5],e[n+5]=s,s=e[n+3],e[n+3]=e[n+4],e[n+4]=s}}function Jf(t,e,n=ti){e!==n&&Bc(t)}function Ve(t,e,n=ti){e!==n&&Vc(t)}function _r(t,e,n,i=ti){if(!(e===i||n===1))switch(n){case 2:Bc(t);break;case 4:Vc(t);break;case 8:Kf(t);break}}const Wf=new Float64Array(1);new Uint32Array(Wf.buffer);/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const vs=new Uint32Array(2),In=4294967296,Os=[];for(let t=2;t<=36;++t){const e=Math.floor(32/Math.log2(t)),n=t**e;let i=`^[0-${String.fromCharCode(48+Math.min(9,t-1))}`;t>10&&(i+=`a-${String.fromCharCode(97+t-11)}`,i+=`A-${String.fromCharCode(65+t-11)}`);const s=Math.ceil(64/Math.log2(t));i+=`]{1,${s}}$`;const r=new RegExp(i);Os[t]={lowDigits:e,lowBase:n,pattern:r}}function $o(t,e){t>>>=0,e>>>=0;const n=t&65535,i=t>>>16,s=e&65535,r=e>>>16;let a=(n*s>>>16)+i*s,c=a>>>16;a=(a&65535)+n*r,c+=a>>>16;let l=c>>>16;return c=(c&65535)+i*r,l+=c>>>16,((l&65535)<<16|c&65535)>>>0}const me=class me{constructor(e=0,n=0){this.low=e,this.high=n}clone(){return new me(this.low,this.high)}assign(e){this.low=e.low,this.high=e.high}toString(e=10){let n=this.low,i=this.high;if(i===0)return n.toString(e);i*=In;const{lowBase:s,lowDigits:r}=Os[e],o=i%s;i=Math.floor(i/s),n+=o,i+=Math.floor(n/s),n=n%s;const a=n.toString(e);return i.toString(e)+"0".repeat(r-a.length)+a}static less(e,n){return e.high<n.high||e.high===n.high&&e.low<n.low}static compare(e,n){return e.high-n.high||e.low-n.low}static equal(e,n){return e.low===n.low&&e.high===n.high}static min(e,n){return me.less(e,n)?e:n}static max(e,n){return me.less(e,n)?n:e}static random(){return crypto.getRandomValues(vs),new me(vs[0],vs[1])}tryParseString(e,n=10){const{lowDigits:i,lowBase:s,pattern:r}=Os[n];if(!r.test(e))return!1;if(e.length<=i)return this.low=parseInt(e,n),this.high=0,!0;const o=e.length-i,a=parseInt(e.substr(o),n),c=parseInt(e.substr(0,o),n);let l,u;if(s===In)l=c,u=a;else{const h=Math.imul(c,s)>>>0;l=$o(c,s)+(Math.imul(Math.floor(c/In),s)>>>0),u=a+h,u>=In&&(++l,u-=In)}return u>>>0!==u||l>>>0!==l?!1:(this.low=u,this.high=l,!0)}parseString(e,n=10){if(!this.tryParseString(e,n))throw new Error(`Failed to parse string as uint64 value: ${JSON.stringify(e)}.`);return this}static parseString(e,n=10){return new me().parseString(e,n)}valid(){const{low:e,high:n}=this;return e>>>0===e&&n>>>0===n}toJSON(){return this.toString()}static lshift(e,n,i){const{low:s,high:r}=n;return i===0?(e.low=s,e.high=r):i<32?(e.low=s<<i,e.high=r<<i|s>>>32-i):(e.low=0,e.high=s<<i-32),e}static rshift(e,n,i){const{low:s,high:r}=n;return i===0?(e.low=s,e.high=r):i<32?(e.low=s>>>i|r<<32-i,e.high=r>>>i):(e.low=r>>>i-32,e.high=0),e}static or(e,n,i){return e.low=n.low|i.low,e.high=n.high|i.high,e}static xor(e,n,i){return e.low=n.low^i.low,e.high=n.high^i.high,e}static and(e,n,i){return e.low=n.low&i.low,e.high=n.high&i.high,e}static add(e,n,i){const s=n.low+i.low;let r=n.high+i.high;const o=s>>>0;return o!==s&&(r+=1),e.low=o,e.high=r>>>0,e}static addUint32(e,n,i){const s=n.low+i;let r=n.high;const o=s>>>0;return o!==s&&(r+=1),e.low=o,e.high=r>>>0,e}static decrement(e,n){let{low:i,high:s}=n;return i===0&&(s-=1),e.low=i-1>>>0,e.high=s>>>0,e}static increment(e,n){let{low:i,high:s}=n;return i===4294967295&&(s+=1),e.low=i+1>>>0,e.high=s>>>0,e}static subtract(e,n,i){const s=n.low-i.low;let r=n.high-i.high;const o=s>>>0;return o!==s&&(r-=1),e.low=o,e.high=r>>>0,e}static absDifference(e,n,i){return me.less(n,i)?me.subtract(e,i,n):me.subtract(e,n,i)}static multiplyUint32(e,n,i){const{low:s,high:r}=n;return e.low=Math.imul(s,i)>>>0,e.high=Math.imul(r,i)+$o(s,i)>>>0,e}static lowMask(e,n){return n===0?e.high=e.low=0:n<=32?(e.high=0,e.low=4294967295>>>32-n):(e.high=4294967295>>>n-32,e.low=4294967295),e}toNumber(){return this.low+this.high*4294967296}setFromNumber(e){e=Math.round(e),e<0?this.low=this.high=0:e>=18446744073709552e3?this.low=this.high=4294967295:(this.low=e%4294967296,this.high=Math.floor(e/4294967296))}static fromNumber(e){const n=new me;return n.setFromNumber(e),n}};me.ZERO=new me(0,0),me.ONE=new me(1,0);let R=me;V.UINT8+"",V.INT8+"",V.UINT16+"",V.INT16+"",V.UINT32+"",V.INT32+"",V.UINT64+"",R.ZERO,new R(4294967295,4294967295),V.FLOAT32+"";/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function Fo(t=128){const e=Math.ceil(t/32),n=new Uint32Array(e);crypto.getRandomValues(n);let i="";for(let s=0;s<e;++s)i+=("00000000"+n[s].toString(16)).slice(-8);return i}function Zf(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=65536;for(let i=0,s=e.length;i<s;i+=n)crypto.getRandomValues(e.subarray(i,Math.min(s,i+n)));return t}var nt=(t=>(t[t.POINT=0]="POINT",t[t.LINE=1]="LINE",t[t.AXIS_ALIGNED_BOUNDING_BOX=2]="AXIS_ALIGNED_BOUNDING_BOX",t[t.ELLIPSOID=3]="ELLIPSOID",t))(nt||{});const Gt=[0,1,2,3];V.FLOAT32,V.UINT32,V.INT32,V.UINT16,V.INT16,V.UINT8,V.INT8;const Rs={rgb:{serializedBytes(){return 3},alignment(){return 1},serializeCode(t,e){return`dv.setUint16(${e}, ${t}, true);dv.setUint8(${e} + 2, ${t} >>> 16);`},deserializeCode(t,e){return`${t} = dv.getUint16(${e}, true) | (dv.getUint8(${e} + 2) << 16);`},deserializeJson(t){return Lo(jf(t))},serializeJson(t){return zo(qf(t))}},rgba:{serializedBytes(){return 4},alignment(){return 1},serializeCode(t,e){return`dv.setUint32(${e}, ${t}, true);`},deserializeCode(t,e){return`${t} = dv.getUint32(${e}, true);`},deserializeJson(t){return Lo(Fc(t))},serializeJson(t){return zo(Yf(t))}},float32:{serializedBytes(){return 4},alignment(){return 4},serializeCode(t,e){return`dv.setFloat32(${e}, ${t}, isLittleEndian);`},deserializeCode(t,e){return`${t} = dv.getFloat32(${e}, isLittleEndian);`},deserializeJson(t){return yr(t)},serializeJson(t){return t}},uint32:{serializedBytes(){return 4},alignment(){return 4},serializeCode(t,e){return`dv.setUint32(${e}, ${t}, isLittleEndian);`},deserializeCode(t,e){return`${t} = dv.getUint32(${e}, isLittleEndian);`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}},int32:{serializedBytes(){return 4},alignment(){return 4},serializeCode(t,e){return`dv.setInt32(${e}, ${t}, isLittleEndian);`},deserializeCode(t,e){return`${t} = dv.getInt32(${e}, isLittleEndian);`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}},uint16:{serializedBytes(){return 2},alignment(){return 2},serializeCode(t,e){return`dv.setUint16(${e}, ${t}, isLittleEndian);`},deserializeCode(t,e){return`${t} = dv.getUint16(${e}, isLittleEndian);`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}},int16:{serializedBytes(){return 2},alignment(){return 2},serializeCode(t,e){return`dv.setInt16(${e}, ${t}, isLittleEndian);`},deserializeCode(t,e){return`${t} = dv.getInt16(${e}, isLittleEndian);`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}},uint8:{serializedBytes(){return 1},alignment(){return 1},serializeCode(t,e){return`dv.setUint8(${e}, ${t});`},deserializeCode(t,e){return`${t} = dv.getUint8(${e});`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}},int8:{serializedBytes(){return 2},alignment(){return 1},serializeCode(t,e){return`dv.setInt8(${e}, ${t});`},deserializeCode(t,e){return`${t} = dv.getInt8(${e});`},deserializeJson(t){return Dt(t)},serializeJson(t){return t}}},Qf=255;function Xf(t,e,n){let i=0;const s=n.length,r=new Array(s),o=[];for(let d=0;d<s;++d)r[d]=d;const a=d=>Rs[n[d].type].alignment(t);r.sort((d,p)=>a(p)-a(d));let c=0;const l=new Array(s);let u=e;const h=()=>{u+=(4-u%4)%4,i+=u,o[c]=u,u=0,++c};for(let d=0;d<s;++d){const p=r[d],g=n[p],f=Rs[g.type],v=f.serializedBytes(t),S=f.alignment(t),I=(S-u%S)%S,w=u+I+v;w+(4-w%4)%4<=Qf?u+=I:h(),l[p]={offset:u,group:c},u+=v}return h(),{serializedBytes:i,offsets:l,propertyGroupBytes:o}}class Gc{constructor(e,n,i){if(this.rank=e,this.firstGroupInitialOffset=n,this.propertySpecs=i,i.length===0){this.serializedBytes=n,this.serialize=this.deserialize=()=>{},this.propertyGroupBytes=[n];return}const{serializedBytes:s,offsets:r,propertyGroupBytes:o}=Xf(e,n,i);this.propertyGroupBytes=o;let a="let groupOffset0 = offset;";for(let h=1;h<o.length;++h)a+=`let groupOffset${h} = groupOffset${h-1} + ${o[h-1]}*annotationCount;`;for(let h=0;h<o.length;++h)a+=`groupOffset${h} += ${o[h]}*annotationIndex;`;let c=a,l=a;const u=i.length;for(let h=0;h<u;++h){const{group:d,offset:p}=r[h],g=i[h],f=Rs[g.type],v=`properties[${h}]`,S=`groupOffset${d} + ${p}`;c+=f.serializeCode(v,S,e),l+=f.deserializeCode(v,S,e)}this.serializedBytes=s,this.serialize=new Function("dv","offset","annotationIndex","annotationCount","isLittleEndian","properties",c),this.deserialize=new Function("dv","offset","annotationIndex","annotationCount","isLittleEndian","properties",l)}}function ep(t,e){const n=[];for(const i of Gt){const s=ts[i];n[i]=new Gc(t,s.serializedBytes(t),e)}return n}function Ds(t,e,n,i,s){for(let r=0;r<i;++r)t.setFloat32(e,s[r],n),e+=4;return e}function ws(t,e,n,i,s,r){return e=Ds(t,e,n,i,s),e=Ds(t,e,n,i,r),e}function ks(t,e,n,i,s){for(let r=0;r<i;++r)s[r]=t.getFloat32(e,n),e+=4;return e}function Ss(t,e,n,i,s,r){return e=ks(t,e,n,i,s),e=ks(t,e,n,i,r),e}const ts={1:{icon:"ꕹ",description:"Line",toJSON(t){return{pointA:Array.from(t.pointA),pointB:Array.from(t.pointB)}},restoreState(t,e,n){t.pointA=X(e,"pointA",i=>We(new Float32Array(n),i,Rt)),t.pointB=X(e,"pointB",i=>We(new Float32Array(n),i,Rt))},serializedBytes(t){return 2*4*t},serialize(t,e,n,i,s){ws(t,e,n,i,s.pointA,s.pointB)},deserialize:(t,e,n,i,s)=>{const r=new Float32Array(i),o=new Float32Array(i);return Ss(t,e,n,i,r,o),{type:1,pointA:r,pointB:o,id:s,properties:[]}},visitGeometry(t,e){e(t.pointA,!1),e(t.pointB,!1)}},0:{icon:"⚬",description:"Point",toJSON:t=>({point:Array.from(t.point)}),restoreState:(t,e,n)=>{t.point=X(e,"point",i=>We(new Float32Array(n),i,Rt))},serializedBytes:t=>t*4,serialize:(t,e,n,i,s)=>{Ds(t,e,n,i,s.point)},deserialize:(t,e,n,i,s)=>{const r=new Float32Array(i);return ks(t,e,n,i,r),{type:0,point:r,id:s,properties:[]}},visitGeometry(t,e){e(t.point,!1)}},2:{icon:"❑",description:"Bounding Box",toJSON:t=>({pointA:Array.from(t.pointA),pointB:Array.from(t.pointB)}),restoreState:(t,e,n)=>{t.pointA=X(e,"pointA",i=>We(new Float32Array(n),i,Rt)),t.pointB=X(e,"pointB",i=>We(new Float32Array(n),i,Rt))},serializedBytes:t=>2*4*t,serialize(t,e,n,i,s){ws(t,e,n,i,s.pointA,s.pointB)},deserialize:(t,e,n,i,s)=>{const r=new Float32Array(i),o=new Float32Array(i);return Ss(t,e,n,i,r,o),{type:2,pointA:r,pointB:o,id:s,properties:[]}},visitGeometry(t,e){e(t.pointA,!1),e(t.pointB,!1)}},3:{icon:"◎",description:"Ellipsoid",toJSON:t=>({center:Array.from(t.center),radii:Array.from(t.radii)}),restoreState:(t,e,n)=>{t.center=X(e,"center",i=>We(new Float32Array(n),i,Rt)),t.radii=X(e,"radii",i=>We(new Float32Array(n),i,Zu))},serializedBytes:t=>2*4*t,serialize(t,e,n,i,s){ws(t,e,n,i,s.center,s.radii)},deserialize:(t,e,n,i,s)=>{const r=new Float32Array(i),o=new Float32Array(i);return Ss(t,e,n,i,r,o),{type:3,center:r,radii:o,id:s,properties:[]}},visitGeometry(t,e){e(t.center,!1),e(t.radii,!0)}}};function tp(t,e){let n=0;const i=[];for(const l of Gt){const h=e[l].serializedBytes;i[l]=n;const p=t[l].length;n+=h*p}const s=[],r=[],o=new ArrayBuffer(n),a=new DataView(o),c=ti===te.LITTLE;for(const l of Gt){const u=e[l],{rank:h}=u,d=u.serialize,p=t[l];s[l]=p.map(I=>I.id),r[l]=new Map(p.map((I,C)=>[I.id,C]));const f=ts[l].serialize,v=i[l],S=u.propertyGroupBytes[0];for(let I=0,C=p.length;I<C;++I){const w=p[I];f(a,v+I*S,c,h,w),d(a,v,I,C,c,w.properties)}}return{data:new Uint8Array(o),typeToIds:s,typeToOffset:i,typeToIdMaps:r}}class np{constructor(e){this.propertySerializers=e,this.annotations=[[],[],[],[]]}add(e){this.annotations[e.type].push(e)}serialize(){return tp(this.annotations,this.propertySerializers)}}function ip(t){if(t==null)return t;const{relatedSegments:e}=t;if(e!==void 0)for(let n=0,i=e.length;n<i;++n){const s=e[n];s!==void 0&&(e[n]=s.map(r=>new R(r.low,r.high)))}return t}Q();Oi();function sp(t,e){return mt(t.globalDimensionNames,e.globalDimensionNames)&&mt(t.displayDimensionIndices,e.displayDimensionIndices)&&mt(t.canonicalVoxelFactors,e.canonicalVoxelFactors)&&mt(t.voxelPhysicalScales,e.voxelPhysicalScales)&&t.canonicalVoxelPhysicalSize===e.canonicalVoxelPhysicalSize&&mt(t.displayDimensionUnits,e.displayDimensionUnits)&&mt(t.displayDimensionScales,e.displayDimensionScales)}var jt=(t=>(t[t.MIN_REPRESENTATIVE=0]="MIN_REPRESENTATIVE",t[t.MAX_REPRESENTATIVE=1]="MAX_REPRESENTATIVE",t[t.REPRESENTATIVE_EXCLUDED=2]="REPRESENTATIVE_EXCLUDED",t[t.NONREPRESENTATIVE_EXCLUDED=4]="NONREPRESENTATIVE_EXCLUDED",t))(jt||{});const Ii=Symbol("disjoint_sets:rank"),tt=Symbol("disjoint_sets:parent"),Di=Symbol("disjoint_sets:next"),bn=Symbol("disjoint_sets:prev");function Is(t){let e=t,n=t[tt];for(;n!==t;)t=n,n=t[tt];for(t=e[tt];n!==t;)e[tt]=n,e=t,t=e[tt];return n}function rp(t,e){const n=t[Ii],i=e[Ii];return n>i?(e[tt]=t,t):(t[tt]=e,n===i&&(e[Ii]=i+1),e)}function op(t,e){const n=t[bn],i=e[bn];e[bn]=n,n[Di]=e,t[bn]=i,i[Di]=t}function*Bo(t){let e=t;do yield e,e=e[Di];while(e!==t)}function ap(t){t[tt]=t,t[Ii]=0,t[Di]=t[bn]=t}const Ut=Symbol("disjoint_sets:min");function Vo(t){return t[tt]===t}class cp{constructor(){this.map=new Map,this.visibleSegmentEquivalencePolicy=new xi(jt.MIN_REPRESENTATIVE),this.generation=0}has(e){const n=e.toString();return this.map.get(n)!==void 0}get(e){const n=e.toString(),i=this.map.get(n);return i===void 0?e:Is(i)[Ut]}isMinElement(e){const n=this.get(e);return n===e||R.equal(n,e)}makeSet(e){const n=e.toString(),{map:i}=this;let s=i.get(n);return s===void 0?(s=e.clone(),ap(s),s[Ut]=s,i.set(n,s),s):Is(s)}link(e,n){if(e=this.makeSet(e),n=this.makeSet(n),e===n)return!1;this.generation++;const i=rp(e,n);op(e,n);const s=e[Ut],r=n[Ut],o=(this.visibleSegmentEquivalencePolicy.value&jt.MAX_REPRESENTATIVE)!==0;return i[Ut]=R.less(s,r)===o?r:s,!0}linkAll(e){for(let n=1,i=e.length;n<i;++n)this.link(e[0],e[n])}deleteSet(e){const{map:n}=this;let i=!1;for(const s of this.setElements(e))n.delete(s.toString()),i=!0;return i&&++this.generation,i}*setElements(e){const n=e.toString(),i=this.map.get(n);i===void 0?yield e:yield*Bo(i)}clear(){const{map:e}=this;return e.size===0?!1:(++this.generation,e.clear(),!0)}get size(){return this.map.size}*mappings(e=new Array(2)){for(const n of this.map.values())e[0]=n,e[1]=Is(n)[Ut],yield e}*roots(){for(const e of this.map.values())Vo(e)&&(yield e)}[Symbol.iterator](){return this.mappings()}toJSON(){const e=new Array;for(const n of this.map.values())if(Vo(n)){const i=new Array;for(const s of Bo(n))i.push(s);i.sort(R.compare),e.push(i)}return e.sort((n,i)=>R.compare(n[0],i[0])),e.map(n=>n.map(i=>i.toString()))}}var lp=Object.defineProperty,hp=Object.getOwnPropertyDescriptor,up=(t,e,n,i)=>{for(var s=i>1?void 0:i?hp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&lp(e,n,s),s};const dp="DisjointUint64Sets",jc="DisjointUint64Sets.add",qc="DisjointUint64Sets.clear",Yc="DisjointUint64Sets.highBitRepresentativeChanged",Hc="DisjointUint64Sets.deleteSet";let ki=class extends xe{constructor(){super(...arguments),this.disjointSets=new cp,this.changed=new Ht}get value(){return this}static makeWithCounterpart(t,e){const n=new ki;return n.disjointSets.visibleSegmentEquivalencePolicy=e,n.registerDisposer(e.changed.add(()=>{Go(n)})),n.initializeCounterpart(t),e.value&&Go(n),n}disposed(){this.disjointSets=void 0,this.changed=void 0,super.disposed()}link(t,e){if(this.disjointSets.link(t,e)){const{rpc:n}=this;return n&&n.invoke(jc,{id:this.rpcId,al:t.low,ah:t.high,bl:e.low,bh:e.high}),this.changed.dispatch(),!0}return!1}linkAll(t){for(let e=1,n=t.length;e<n;++e)this.link(t[0],t[e])}has(t){return this.disjointSets.has(t)}get(t){return this.disjointSets.get(t)}clear(){if(this.disjointSets.clear()){const{rpc:t}=this;t&&t.invoke(qc,{id:this.rpcId}),this.changed.dispatch()}}setElements(t){return this.disjointSets.setElements(t)}deleteSet(t){if(this.disjointSets.deleteSet(t)){const{rpc:e}=this;e&&e.invoke(Hc,{id:this.rpcId,l:t.low,h:t.high}),this.changed.dispatch()}}get size(){return this.disjointSets.size}toJSON(){return this.disjointSets.toJSON()}restoreState(t){if(t!==void 0){const e=[new R,new R];Ri(t,n=>{Ri(n,(i,s)=>{e[s%2].parseString(String(i),10),s!==0&&this.link(e[0],e[1])})})}}assignFrom(t){this.clear(),t instanceof ki&&(t=t.disjointSets);for(const[e,n]of t)this.link(e,n)}};ki=up([L(dp)],ki);const qt=new R,Es=new R;K(jc,function(t){const e=this.get(t.id);qt.low=t.al,qt.high=t.ah,Es.low=t.bl,Es.high=t.bh,e.disjointSets.link(qt,Es)&&e.changed.dispatch()});K(qc,function(t){const e=this.get(t.id);e.disjointSets.clear()&&e.changed.dispatch()});function Go(t){t.rpc.invoke(Yc,{id:t.rpcId,value:t.disjointSets.visibleSegmentEquivalencePolicy.value})}K(Yc,function(t){const e=this.get(t.id);e.disjointSets.visibleSegmentEquivalencePolicy.value=t.value});K(Hc,function(t){const e=this.get(t.id);qt.low=t.l,qt.high=t.h,e.disjointSets.deleteSet(qt)&&e.changed.dispatch()});/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const fp=3432918353,pp=461845907;function jo(t,e){return e>>>=0,t>>>=0,e=Math.imul(e,fp)>>>0,e=(e<<15|e>>>17)>>>0,e=Math.imul(e,pp)>>>0,t=(t^e)>>>0,t=(t<<13|t>>>19)>>>0,t=t*5+3864292196>>>0,t}const qo=3,gp=.8;let Ze=0,Qe=0,Yo=0,Ho=0;class Pn{constructor(e=Pn.generateHashSeeds(qo)){this.hashSeeds=e,this.loadFactor=gp,this.size=0,this.emptyLow=4294967295,this.emptyHigh=4294967295,this.maxRehashAttempts=5,this.maxAttempts=5,this.generation=0,this.mungedEmptyKey=-1;let n=8;for(;n<2*e.length;)n*=2;this.allocate(n)}updateHashFunctions(e){this.hashSeeds=Pn.generateHashSeeds(e),this.mungedEmptyKey=-1}tableWithMungedEmptyKey(e){const n=this.hashSeeds.length,i=new Array(n);for(let c=0;c<n;++c)i[c]=this.getHash(c,this.emptyLow,this.emptyHigh);let{mungedEmptyKey:s}=this;if(s===-1)e:for(;;){s=Math.random()*16777216>>>0;for(let c=0;c<n;++c){const l=this.getHash(c,s,s);for(let u=0;u<n;++u)if(i[u]===l)continue e}this.mungedEmptyKey=s;break}const{table:r,emptyLow:o,emptyHigh:a}=this;for(let c=0;c<n;++c){const l=i[c];r[l]===o&&r[l+1]===a&&(r[l]=s,r[l+1]=s)}try{e(r)}finally{for(let c=0;c<n;++c){const l=i[c];r[l]===s&&r[l+1]===s&&(r[l]=o,r[l+1]=a)}}}static generateHashSeeds(e=qo){return Zf(new Uint32Array(e))}getHash(e,n,i){let s=this.hashSeeds[e];return s=jo(s,n),s=jo(s,i),this.entryStride*(s&this.tableSize-1)}*keys(){const{emptyLow:e,emptyHigh:n,entryStride:i}=this,{table:s}=this;for(let r=0,o=s.length;r<o;r+=i){const a=s[r],c=s[r+1];(a!==e||c!==n)&&(yield new R(a,c))}}*unsafeKeys(e=new R){const{emptyLow:n,emptyHigh:i,entryStride:s}=this,{table:r}=this;for(let o=0,a=r.length;o<a;o+=s){const c=r[o],l=r[o+1];(c!==n||l!==i)&&(e.low=c,e.high=l,yield e)}}indexOfPair(e,n){const{table:i,emptyLow:s,emptyHigh:r}=this;if(e===s&&n===r)return-1;for(let o=0,a=this.hashSeeds.length;o<a;++o){const c=this.getHash(o,e,n);if(i[c]===e&&i[c+1]===n)return c}return-1}indexOf(e){return this.indexOfPair(e.low,e.high)}chooseAnotherEmptyKey(){const{emptyLow:e,emptyHigh:n,table:i,entryStride:s}=this;let r,o;for(;r=Math.random()*4294967296>>>0,o=Math.random()*4294967296>>>0,!(!(r===e&&o===n)&&!this.hasPair(r,o)););this.emptyLow=r,this.emptyHigh=o;for(let a=0,c=i.length;a<c;a+=s)i[a]===e&&i[a+1]===n&&(i[a]=r,i[a+1]=o)}has(e){return this.indexOf(e)!==-1}hasPair(e,n){return this.indexOfPair(e,n)!==-1}delete(e){const n=this.indexOf(e);if(n!==-1){const{table:i}=this;return i[n]=this.emptyLow,i[n+1]=this.emptyHigh,++this.generation,this.size--,!0}return!1}clearTable(){const{table:e,entryStride:n,emptyLow:i,emptyHigh:s}=this,r=e.length;for(let o=0;o<r;o+=n)e[o]=i,e[o+1]=s}clear(){return this.size===0?!1:(this.size=0,++this.generation,this.clearTable(),!0)}reserve(e){return e>this.capacity?(this.backupPending(),this.grow(e),this.restorePending(),!0):!1}swapPending(e,n){const i=Ze,s=Qe;this.storePending(e,n),e[n]=i,e[n+1]=s}storePending(e,n){Ze=e[n],Qe=e[n+1]}backupPending(){Yo=Ze,Ho=Qe}restorePending(){Ze=Yo,Qe=Ho}tryToInsert(){let e=0;const{emptyLow:n,emptyHigh:i,maxAttempts:s,table:r}=this,o=this.hashSeeds.length;let a=Math.floor(Math.random()*o);for(;;){const c=this.getHash(a,Ze,Qe);if(this.swapPending(r,c),Ze===n&&Qe===i)return!0;if(++e===s)break;a=(a+Math.floor(Math.random()*(o-1))+1)%o}return!1}allocate(e){this.tableSize=e;const{entryStride:n}=this;this.table=new Uint32Array(e*n),this.maxAttempts=e,this.clearTable(),this.capacity=e*this.loadFactor,this.mungedEmptyKey=-1}rehash(e,n){this.allocate(n),this.updateHashFunctions(this.hashSeeds.length);const{emptyLow:i,emptyHigh:s,entryStride:r}=this;for(let o=0,a=e.length;o<a;o+=r){const c=e[o],l=e[o+1];if((c!==i||l!==s)&&(this.storePending(e,o),!this.tryToInsert()))return!1}return!0}grow(e){const n=this.table;let{tableSize:i}=this;for(;i<e;)i*=2;for(;;){for(let s=0;s<this.maxRehashAttempts;++s)if(this.rehash(n,i))return;i*=2}}insertInternal(){for(++this.generation,Ze===this.emptyLow&&Qe===this.emptyHigh&&this.chooseAnotherEmptyKey(),++this.size>this.capacity&&(this.backupPending(),this.grow(this.tableSize*2),this.restorePending());!this.tryToInsert();)this.backupPending(),this.grow(this.tableSize),this.restorePending()}}class Kc extends Pn{add(e){const{low:n,high:i}=e;return this.hasPair(n,i)?!1:(Ze=n,Qe=i,this.insertInternal(),!0)}[Symbol.iterator](){return this.unsafeKeys()}}Kc.prototype.entryStride=2;let En=0,Cn=0,Ko=0,Jo=0;class Jc extends Pn{set(e,n){const{low:i,high:s}=e;return this.hasPair(i,s)?!1:(Ze=i,Qe=s,En=n.low,Cn=n.high,this.insertInternal(),!0)}get(e,n){const i=this.indexOf(e);if(i===-1)return!1;const{table:s}=this;return n.low=s[i+2],n.high=s[i+3],!0}swapPending(e,n){const i=En,s=Cn;super.swapPending(e,n),e[n+2]=i,e[n+3]=s}storePending(e,n){super.storePending(e,n),En=e[n+2],Cn=e[n+3]}backupPending(){super.backupPending(),Ko=En,Jo=Cn}restorePending(){super.restorePending(),En=Ko,Cn=Jo}[Symbol.iterator](){return this.unsafeEntries()}*entries(){const{emptyLow:e,emptyHigh:n,entryStride:i}=this,{table:s}=this;for(let r=0,o=s.length;r<o;r+=i){const a=s[r],c=s[r+1];if(a!==e||c!==n){const l=new R(a,c),u=new R(s[r+2],s[r+3]);yield[l,u]}}}*unsafeEntries(e=[new R,new R]){const{emptyLow:n,emptyHigh:i,entryStride:s}=this,{table:r}=this,[o,a]=e;for(let c=0,l=r.length;c<l;c+=s){const u=r[c],h=r[c+1];(u!==n||h!==i)&&(o.low=u,o.high=h,a.low=r[c+2],a.high=r[c+3],yield e)}}}Jc.prototype.entryStride=4;var mp=Object.defineProperty,yp=Object.getOwnPropertyDescriptor,vp=(t,e,n,i)=>{for(var s=i>1?void 0:i?yp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&mp(e,n,s),s};let Us=class extends xe{constructor(){super(...arguments),this.hashTable=new Jc,this.changed=new Hi}get value(){return this}static makeWithCounterpart(t){const e=new Us;return e.initializeCounterpart(t),e}set_(t,e){return this.hashTable.set(t,e)}set(t,e){if(this.set_(t,e)){const{rpc:n}=this;n&&n.invoke("Uint64Map.set",{id:this.rpcId,key:t,value:e}),this.changed.dispatch(t,!0)}}has(t){return this.hashTable.has(t)}get(t,e){return this.hashTable.get(t,e)}[Symbol.iterator](){return this.hashTable.entries()}unsafeEntries(){return this.hashTable.unsafeEntries()}delete_(t){return this.hashTable.delete(t)}delete(t){if(this.delete_(t)){const{rpc:e}=this;e&&e.invoke("Uint64Map.delete",{id:this.rpcId,key:t}),this.changed.dispatch(t,!1)}}get size(){return this.hashTable.size}assignFrom(t){this.clear();for(const[e,n]of t.unsafeEntries())this.set(e,n)}clear(){if(this.hashTable.clear()){const{rpc:t}=this;t&&t.invoke("Uint64Map.clear",{id:this.rpcId}),this.changed.dispatch(null,!1)}}toJSON(){const t={};for(const[e,n]of this.hashTable.unsafeEntries())t[e.toString()]=n.toString();return t}};Us=vp([L("Uint64Map")],Us);K("Uint64Map.set",function(t){const e=this.get(t.id);e.set_(t.key,t.value)&&e.changed.dispatch()});K("Uint64Map.delete",function(t){const e=this.get(t.id);e.delete_(t.key)&&e.changed.dispatch()});K("Uint64Map.clear",function(t){const e=this.get(t.id);e.hashTable.clear()&&e.changed.dispatch()});var wp=Object.defineProperty,Sp=Object.getOwnPropertyDescriptor,Ip=(t,e,n,i)=>{for(var s=i>1?void 0:i?Sp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&wp(e,n,s),s};let An=class extends xe{constructor(){super(...arguments),this.hashTable=new Kc,this.changed=new Hi}get value(){return this}static makeWithCounterpart(t){const e=new An;return e.initializeCounterpart(t),e}set(t,e){e?this.add(t):this.delete(t)}reserve_(t){return this.hashTable.reserve(t)}reserve(t){if(this.reserve_(t)){const{rpc:e}=this;e&&e.invoke("Uint64Set.reserve",{id:this.rpcId,value:t})}}add_(t){let e=!1;for(const n of t)e=this.hashTable.add(n)||e;return e}add(t){const e=Array().concat(t);if(this.add_(e)){const{rpc:n}=this;n&&n.invoke("Uint64Set.add",{id:this.rpcId,value:e}),this.changed.dispatch(t,!0)}}has(t){return this.hashTable.has(t)}[Symbol.iterator](){return this.hashTable.keys()}unsafeKeys(){return this.hashTable.unsafeKeys()}delete_(t){let e=!1;for(const n of t)e=this.hashTable.delete(n)||e;return e}delete(t){const e=Array().concat(t);if(this.delete_(Array().concat(t))){const{rpc:n}=this;n&&n.invoke("Uint64Set.delete",{id:this.rpcId,value:e}),this.changed.dispatch(t,!1)}}get size(){return this.hashTable.size}clear(){if(this.hashTable.clear()){const{rpc:t}=this;t&&t.invoke("Uint64Set.clear",{id:this.rpcId}),this.changed.dispatch(null,!1)}}toJSON(){const t=new Array;for(const e of this.unsafeKeys())t.push(e.toString());return t.sort(),t}assignFrom(t){this.clear();for(const e of t.unsafeKeys())this.add(e)}};An=Ip([L("Uint64Set")],An);K("Uint64Set.reserve",function(t){const e=this.get(t.id);e.reserve_(t.value)&&e.changed.dispatch()});K("Uint64Set.add",function(t){const e=this.get(t.id);e.add_(t.value)&&e.changed.dispatch()});K("Uint64Set.delete",function(t){const e=this.get(t.id);e.delete_(t.value)&&e.changed.dispatch()});K("Uint64Set.clear",function(t){const e=this.get(t.id);e.hashTable.clear()&&e.changed.dispatch()});const Ep=["visibleSegments","segmentEquivalences","temporaryVisibleSegments","temporarySegmentEquivalences","useTemporaryVisibleSegments","useTemporarySegmentEquivalences"];function Wc(t,e,n){t.registerDisposer(e.visibleSegments.changed.add(n)),t.registerDisposer(e.segmentEquivalences.changed.add(n))}function Zc(t,e,n){t.registerDisposer(e.temporaryVisibleSegments.changed.add(n)),t.registerDisposer(e.temporarySegmentEquivalences.changed.add(n)),t.registerDisposer(e.useTemporaryVisibleSegments.changed.add(n)),t.registerDisposer(e.useTemporarySegmentEquivalences.changed.add(n))}function ns(t){return`${t.low},${t.high}`}function Cp(t){return!!(t.high>>>31)}function _p(t){return t.useTemporaryVisibleSegments.value?t.temporaryVisibleSegments:t.visibleSegments}function bp(t){return t.useTemporarySegmentEquivalences.value?t.temporarySegmentEquivalences:t.segmentEquivalences}function ni(t,e){const n=_p(t),i=bp(t),s=i.disjointSets.visibleSegmentEquivalencePolicy.value;for(const r of n.unsafeKeys())if(s&jt.NONREPRESENTATIVE_EXCLUDED){const o=i.get(r);e(r,o)}else{if(!i.disjointSets.isMinElement(r))continue;for(const o of i.setElements(r))s&jt.REPRESENTATIVE_EXCLUDED&&s&jt.MAX_REPRESENTATIVE&&Cp(o)||e(o,r)}}function Qc(t,e,n={}){for(const i of Ep)n[i]=t.get(e[i]);return n}const is=t=>class extends t{constructor(...n){const[i,s]=n;super(i,s),Qc(i,s,this),this.transform=i.get(s.transform),this.renderScaleTarget=i.get(s.renderScaleTarget);const r=()=>{this.chunkManager.scheduleUpdateChunkPriorities()};Zc(this,this,r),Wc(this,this,r),this.registerDisposer(this.transform.changed.add(r)),this.registerDisposer(this.renderScaleTarget.changed.add(r))}};class Mp extends Le{constructor(e,n){super(e,n),this.properties=n.properties}}var Tp=Object.defineProperty,Pp=Object.getOwnPropertyDescriptor,ss=(t,e,n,i)=>{for(var s=i>1?void 0:i?Pp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Tp(e,n,s),s};const Ap=200,xp=60;class Np extends ne{freeSystemMemory(){this.annotation=void 0}serialize(e,n){super.serialize(e,n),e.annotation=this.annotation}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=0,super.downloadSucceeded()}}class Xc{serialize(e,n){e.data=this.data,e.typeToOffset=this.typeToOffset,e.typeToIds=this.typeToIds,e.typeToIdMaps=this.typeToIdMaps,n.push(this.data.buffer)}get numBytes(){return this.data.byteLength}}function el(t){class e extends t{serialize(i,s){super.serialize(i,s);const{data:r}=this;r!==void 0&&(r.serialize(i,s),this.data=void 0)}downloadSucceeded(){const{data:i}=this;this.systemMemoryBytes=this.gpuMemoryBytes=i===void 0?0:i.numBytes,super.downloadSucceeded()}freeSystemMemory(){this.data=void 0}}return e}class Op extends el(Lc){}class Rp extends el(ne){}let Wo=class extends Le{constructor(){super(...arguments),this.parent=void 0}getChunk(t){const{chunks:e}=this;let n=e.get(t);return n===void 0&&(n=this.getNewChunk_(Np),n.initialize(t),this.addChunk(n)),n}download(t,e){return this.parent.downloadMetadata(t,e)}};Wo=ss([L(xf)],Wo);class br extends zc{constructor(e,n){super(e,n),this.parent=e.get(n.parent)}}br.prototype.chunkConstructor=Op;let Zo=class extends Le{constructor(){super(...arguments),this.parent=void 0}getChunk(t){const e=ns(t),{chunks:n}=this;let i=n.get(e);return i===void 0&&(i=this.getNewChunk_(Rp),i.initialize(e),i.objectId=t.clone(),this.addChunk(i)),i}download(t,e){return this.parent.downloadSegmentFilteredGeometry(t,this.relationshipIndex,e)}};Zo=ss([L(Nf)],Zo);class tl extends xe{constructor(e,n){super(e,n),this.references=new Set;const i=this.chunkManager=e.get(n.chunkManager),s=this.metadataChunkSource=this.registerDisposer(e.getRef(n.metadataChunkSource));this.segmentFilteredSources=n.segmentFilteredSource.map((r,o)=>{const a=this.registerDisposer(e.getRef(r));return a.parent=this,a.relationshipIndex=o,a}),s.parent=this,this.registerDisposer(i.recomputeChunkPriorities.add(()=>this.recomputeChunkPriorities()))}recomputeChunkPriorities(){const{chunkManager:e,metadataChunkSource:n}=this;for(const i of this.references)e.requestChunk(n.getChunk(i),q.VISIBLE,Ap)}add(e){throw new Error("Not implemented")}delete(e){throw new Error("Not implemented")}update(e,n){throw new Error("Not implemented")}}K(Of,function(t){const e=this.get(t.id);e.references.add(t.annotation),e.chunkManager.scheduleUpdateChunkPriorities()});K(Rf,function(t){const e=this.get(t.id);e.references.delete(t.annotation),e.chunkManager.scheduleUpdateChunkPriorities()});K(Df,function(t){const e=this.get(t.id),n=t.annotationId,i=ip(t.newAnnotation);let s;n===void 0?s=e.add(i).then(r=>({...i,id:r})):i===null?s=e.delete(n).then(()=>null):s=e.update(n,i).then(()=>i),s.then(r=>{e.wasDisposed||this.invoke(Uo,{id:e.rpcId,annotationId:n||i.id,newAnnotation:r})},r=>{e.wasDisposed||this.invoke(Uo,{id:e.rpcId,annotationId:n||(i==null?void 0:i.id),error:r.message})})});let Qo=class extends st(Qi){constructor(t,e){super(t,e),this.renderScaleTarget=t.get(e.renderScaleTarget),this.localPosition=t.get(e.localPosition);const n=()=>this.chunkManager.scheduleUpdateChunkPriorities();this.registerDisposer(this.localPosition.changed.add(n)),this.registerDisposer(this.renderScaleTarget.changed.add(n)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>this.recomputeChunkPriorities()))}attach(t){const e=()=>this.chunkManager.scheduleUpdateChunkPriorities(),{view:n}=t;t.registerDisposer(e),t.registerDisposer(n.projectionParameters.changed.add(e)),t.registerDisposer(n.visibility.changed.add(e)),t.state={displayDimensionRenderInfo:n.projectionParameters.value.displayDimensionRenderInfo,transformedSources:[]}}recomputeChunkPriorities(){this.chunkManager.registerLayer(this);for(const t of this.attachments.values()){const{view:e}=t,n=e.visibility.value;if(n===Number.NEGATIVE_INFINITY)continue;const i=t.state,{transformedSources:s,displayDimensionRenderInfo:r}=i;if(s.length===0)continue;const o=e.projectionParameters.value.displayDimensionRenderInfo;if(r!==o){if(!sp(r,o))continue;i.displayDimensionRenderInfo=o}const a=je(n),c=qe(n),l=e.projectionParameters.value,{chunkManager:u}=this;Ff(l,this.localPosition.value,this.renderScaleTarget.value,s[0],()=>{},(h,d)=>{const p=h.source.getChunk(h.curPositionInChunks);++this.numVisibleChunksNeeded,p.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable,u.requestChunk(p,a,c+0+Cr*d)})}}};Qo=ss([L(kf)],Qo);K(Uf,function(t){const e=this.get(t.view),n=this.get(t.layer),i=n.attachments.get(e);i.state.transformedSources=es(this,t.sources,n),i.state.displayDimensionRenderInfo=t.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()});let Xo=class extends bt(st(Sr)){constructor(t,e){super(t,e),this.source=t.get(e.source),this.segmentationStates=new xi(this.getSegmentationState(e.segmentationStates));const n=()=>this.chunkManager.scheduleUpdateChunkPriorities();this.registerDisposer(lu((i,s)=>{if(s!==void 0){for(const r of s)r!=null&&(Wc(i,r,n),Zc(i,r,n));n()}},this.segmentationStates)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>this.recomputeChunkPriorities()))}recomputeChunkPriorities(){const t=this.visibility.value;if(t===Number.NEGATIVE_INFINITY)return;const{segmentationStates:{value:e},source:{segmentFilteredSources:n}}=this;if(e===void 0)return;const{chunkManager:i}=this;i.registerLayer(this);const s=e.length;for(let r=0;r<s;++r){const o=e[r];if(o==null)continue;const a=je(t),c=qe(t),l=n[r];ni(o,u=>{const h=l.getChunk(u);++this.numVisibleChunksNeeded,h.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable,i.requestChunk(h,a,c+xp)})}}getSegmentationState(t){if(t!==void 0)return t.map(e=>e==null?e:Qc(this.rpc,e))}};Xo=ss([L(Lf)],Xo);K(zf,function(t){const e=this.get(t.id);e.segmentationStates.value=e.getSegmentationState(t.segmentationStates)});function Dp(t){let e,n,i;return(s,r)=>n!==void 0&&(e===void 0||s===void 0||e.generation!==s.generation)?(e===void 0&&i.addConsumer(r),n):(e=void 0,i=new ic,n=t(s,i).then(o=>(e=o,i=void 0,o),o=>{throw i.isCanceled&&(i=void 0,n=void 0),o}),n)}/**
 * @license
 * Copyright 2017 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const kp="CredentialsProvider",Up="CredentialsProvider.get";var Lp=Object.defineProperty,zp=Object.getOwnPropertyDescriptor,$p=(t,e,n,i)=>{for(var s=i>1?void 0:i?zp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Lp(e,n,s),s};let ea=class extends xe{constructor(){super(...arguments),this.get=Dp((t,e)=>this.rpc.promiseInvoke(Up,{providerId:this.rpcId,invalidCredentials:t},e))}};ea=$p([L(kp)],ea);function ue(){return t=>class extends t{constructor(...e){super(...e);const n=e[1];this.credentialsProvider=this.rpc.getOptionalRef(n.credentialsProvider)}}}class ut extends Error{constructor(e,n,i,s){let r=`Fetching ${JSON.stringify(e)} resulted in HTTP error ${n}`;i&&(r+=`: ${i}`),r+=".",super(r),this.name="HttpError",this.message=r,this.url=e,this.status=n,this.statusText=i,s&&(this.response=s)}static fromResponse(e){return new ut(e.url,e.status,e.statusText,e)}static fromRequestError(e,n){if(n instanceof TypeError){let i;return typeof e=="string"?i=e:i=e.url,new ut(i,0,"Network or CORS error")}return n}}const Fp=32,Bp=500,Vp=1e4;function nl(t){return Math.min(2**t*Bp,Vp/2)*(1+Math.random())}async function ta(t,e){var n;for(let i=0;;){if((n=e==null?void 0:e.signal)!=null&&n.aborted)throw St;let s;try{s=await fetch(t,e)}catch(r){throw ut.fromRequestError(t,r)}if(!s.ok){const{status:r}=s;if((r===429||r===503||r===504)&&++i!==Fp){await new Promise(o=>setTimeout(o,nl(i-1)));continue}throw ut.fromResponse(s)}return s}}function oe(t){return t.arrayBuffer()}function rs(t){return t.json()}async function Ye(t,e,n,i=pe){if(i===pe){const o=await ta(t,e);return await n(o)}const s=new AbortController,r=i.add(()=>s.abort());try{const o=await ta(t,{...e,signal:s.signal});return await n(o)}finally{r()}}const na=new R;function Gp(t,e){let n;return typeof e=="number"?n=`${e-1}`:(R.decrement(na,e),n=na.toString()),{Range:`bytes=${t}-${n}`}}function jp(t){const e=/^([^:/]+):\/\/([^/]+)((?:\/.*)?)$/,n=t.match(e);if(n===null)throw new Error(`Invalid URL: ${JSON.stringify(t)}`);return{protocol:n[1],host:n[2],path:n[3]}}function Mt(t){return t instanceof ut?t.status===0||t.status===403||t.status===404:!1}const qp=3;async function Mr(t,e,n,i,s,r,o=pe){let a;for(let c=0;;){uu(o),c>1&&await new Promise(l=>setTimeout(l,nl(c-2))),a=await t.get(a,o);try{return await Ye(typeof e=="function"?e(a.credentials):e,s(a.credentials,n),i,o)}catch(l){if(l instanceof ut&&r(l,a.credentials)==="refresh"){if(++c===qp)throw l;continue}throw l}}}function Yp(t,e,n,i,s=pe){return Ye(e,n,i,s).catch(r=>{if(r.status!==500&&r.status!==401&&r.status!==403&&r.status!==504)throw r;return Mr(t,e,n,i,o=>{const a=new Headers(n.headers);return a.set("Authorization",`Bearer ${o}`),{...n,headers:a}},o=>{const{status:a}=o;if(a===403||a===401)return"refresh";throw o},s)})}/**
 * @license
 * Copyright 2017 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class Hp{}var Ln;let Kp=(Ln=class extends Hp{static stringify(e){return`boss:volume:${e.baseUrl}/${e.collection}/${e.experiment}/${e.channel}/${e.resolution}/${e.encoding}`}},Ln.RPC_ID="boss/VolumeChunkSource",Ln);var zn;let Jp=(zn=class{static stringify(e){return`boss:mesh:${e.baseUrl}`}},zn.RPC_ID="boss/MeshChunkSource",zn);/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const Wp="mesh/MeshLayer",Zp="mesh/MultiscaleMeshLayer",Qp="mesh/FragmentSource",Xp="mesh/MultiscaleFragmentSource";var xn=(t=>(t[t.float32=0]="float32",t[t.uint10=1]="uint10",t[t.uint16=2]="uint16",t))(xn||{});/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function eg(t,e,n){return t&1|e<<1&2|n<<2&4}function tg(t,e,n,i){const s=Math.max(e,n,i);let r=0,o=t.low,a=0,c=0,l=0;for(let u=0;u<s;++u){if(u<e){const h=o>>>r&1;a|=h<<u,r===31?(r=0,o=t.high):++r}if(u<n){const h=o>>>r&1;c|=h<<u,r===31?(r=0,o=t.high):++r}if(u<i){const h=o>>>r&1;l|=h<<u,r===31?(r=0,o=t.high):++r}}return Uint32Array.of(a,c,l)}function il(t,e,n,i,s,r,o){const a=Math.max(e,n,i);let c=0,l=0,u=!1;function h(d){l|=(d&1)<<c,++c===32&&(t.low=l>>>0,l=0,c=0,u=!0)}for(let d=0;d<a;++d)d<e&&h(s>>d&1),d<n&&h(r>>d&1),d<i&&h(o>>d&1);return u?t.high=l>>>0:(t.high=0,t.low=l>>>0),t}function ng(t,e,n){let i=0;const s=e.length;let r=0,o=!1;function a(c){r|=(c&1)<<i,++i===32&&(t.low=r>>>0,r=0,i=0,o=!0)}for(let c=0;c<32;++c)for(let l=0;l<s;++l)n[l]-1>>>c&&a(e[l]>>>c);return o?t.high=r>>>0:(t.high=0,t.low=r>>>0),t}function ia(t,e){return t<e&&t<(t^e)}function sl(t,e,n,i,s,r){let o=n,a=r;return ia(o^a,e^s)&&(o=e,a=s),ia(o^a,t^i)&&(o=t,a=i),o<a}function ig(t,e,n,i,s,r,o){const{octree:a,lodScales:c,chunkGridSpatialOrigin:l,chunkShape:u}=t,h=c.length-1,d=e[0],p=e[4],g=e[8],f=e[1],v=e[5],S=e[9],I=e[3],C=e[7],w=e[11],M=e[15],m=I>0?0:1,E=C>0?0:1,y=w>0?0:1,_=n[4*4],T=n[4*4+1],P=n[4*4+2],A=n[4*4+3];function D(he,Ie,Te){return I*he+C*Ie+w*Te+M}function x(he,Ie,Te,Pe,Ae,Je){return D(he+m*(Pe-he),Ie+E*(Ae-Ie),Te+y*(Je-Te))}const F=D(-A*_,-A*T,-A*P),z=t.clipLowerBound[0],U=t.clipLowerBound[1],Y=t.clipLowerBound[2],H=t.clipUpperBound[0],be=t.clipUpperBound[1],ae=t.clipUpperBound[2],Me=Math.sqrt((d*s)**2+(f*r)**2),ce=Math.sqrt((p*s)**2+(v*r)**2),le=Math.sqrt((g*s)**2+(S*r)**2),W=Math.max(Me,ce,le);function de(he,Ie,Te){const Pe=1<<he,Ae=Ie*5,Je=a[Ae],rt=a[Ae+1],mn=a[Ae+2],Ah=a[Ae+3],po=a[Ae+4];let yn=Je*Pe*u[0]+l[0],vn=rt*Pe*u[1]+l[1],wn=mn*Pe*u[2]+l[2],hi=yn+Pe*u[0],ui=vn+Pe*u[1],di=wn+Pe*u[2];if(yn=Math.max(yn,z),vn=Math.max(vn,U),wn=Math.max(wn,Y),hi=Math.min(hi,H),ui=Math.min(ui,be),di=Math.min(di,ae),vc(yn,vn,wn,hi,ui,di,n)){const ds=Math.max(F,x(yn,vn,wn,hi,ui,di))/W;if(Te===0||ds*i<Te){const Ot=c[he];if(Ot!==0&&o(he,Ie,Ot/ds,po>>>31),he>0&&(Ot===0||ds*i<Ot)){const xh=Ot===0?Te:Ot,Nh=(po&2147483647)>>>0;for(let fs=Ah;fs<Nh;++fs)de(he-1,fs,xh)}}}}de(h,a.length/5-1,0)}var sg=Object.defineProperty,rg=Object.getOwnPropertyDescriptor,os=(t,e,n,i)=>{for(var s=i>1?void 0:i?rg(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&sg(e,n,s),s};const rl=100,ol=50;class og extends ne{constructor(){super(...arguments),this.objectId=new R}initializeManifestChunk(e,n){super.initialize(e),this.objectId.assign(n)}freeSystemMemory(){this.fragmentIds=null}serialize(e,n){super.serialize(e,n),e.fragmentIds=this.fragmentIds}downloadSucceeded(){this.systemMemoryBytes=100,this.gpuMemoryBytes=0,super.downloadSucceeded(),this.priorityTier<q.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities()}toString(){return this.objectId.toString()}}function al(t,e,n){const{vertexPositions:i,indices:s,vertexNormals:r,strips:o}=t;e.vertexPositions=i,e.indices=s,e.strips=o,e.vertexNormals=r;const a=i.buffer;n.push(a);const c=s.buffer;c!==a&&n.push(c),n.push(r.buffer)}function cl(t){const{vertexPositions:e,indices:n,vertexNormals:i}=t;return e.byteLength+n.byteLength+i.byteLength}class ag extends ne{constructor(){super(...arguments),this.manifestChunk=null,this.fragmentId=null,this.meshData=null}initializeFragmentChunk(e,n,i){super.initialize(e),this.manifestChunk=n,this.fragmentId=i}freeSystemMemory(){this.manifestChunk=null,this.meshData=null,this.fragmentId=null}serialize(e,n){super.serialize(e,n),al(this.meshData,e,n),this.meshData=null}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=cl(this.meshData),super.downloadSucceeded()}}function ll(t,e,n){Ge(e),t.fragmentIds=X(e,n,Kt)}function hl(t,e){const n=Q(),i=Q(),s=Q(),r=new Float32Array(t.length),o=e.length;for(let c=0;c<o;c+=3){const l=e[c]*3,u=e[c+1]*3,h=e[c+2]*3;for(let d=0;d<3;++d)i[d]=t[u+d]-t[l+d],s[d]=t[h+d]-t[u+d];wi(n,i,s),xs(n,n);for(let d=0;d<3;++d){const g=e[c+d]*3;for(let f=0;f<3;++f)r[g+f]+=n[f]}}const a=r.length;for(let c=0;c<a;c+=3){const l=r.subarray(c,c+3);xs(l,l)}return r}function pi(t){return Math.min(Math.max(-127,t*127+.5),127)>>>0}function sa(t){return t<0?-1:1}function cg(t,e){const n=e.length;let i=0;for(let s=0;s<n;s+=3){const r=e[s],o=e[s+1],a=e[s+2],c=1/(Math.abs(r)+Math.abs(o)+Math.abs(a));a<0?(t[i]=pi((1-Math.abs(o*c))*sa(r)),t[i+1]=pi((1-Math.abs(r*c))*sa(o))):(t[i]=pi(r*c),t[i+1]=pi(o*c)),i+=2}}function ul(t,e,n,i,s,r,o){const a=new Float32Array(e,i,s*3);Ve(a,n),r===void 0&&(r=i+12*s);let c;o!==void 0&&(c=o*t);const l=c===void 0?new Uint32Array(e,r):new Uint32Array(e,r,c);if(l.length%t!==0)throw new Error(`Number of indices is not a multiple of ${t}: ${l.length}.`);return Ve(l,n),{vertexPositions:a,indices:l}}function as(t,e,n,i,s,r){return ul(3,t,e,n,i,s,r)}class Xt extends Le{constructor(e,n){super(e,n);const i=this.fragmentSource=this.registerDisposer(e.getRef(n.fragmentSource));i.meshSource=this}getChunk(e){const n=ns(e);let i=this.chunks.get(n);return i===void 0&&(i=this.getNewChunk_(og),i.initializeManifestChunk(n,e),this.addChunk(i)),i}getFragmentKey(e,n){return{key:`${e}/${n}`,fragmentId:n}}getFragmentChunk(e,n){const i=this.fragmentSource,{key:s,fragmentId:r}=this.getFragmentKey(e.key,n);let o=i.chunks.get(s);return o===void 0&&(o=i.getNewChunk_(ag),o.initializeFragmentChunk(s,e,r),i.addChunk(o)),o}}let ra=class extends Le{constructor(){super(...arguments),this.meshSource=null}download(t,e){return this.meshSource.downloadFragment(t,e)}};ra=os([L(Qp)],ra);let oa=class extends is(bt(st($c))){constructor(t,e){super(t,e),this.source=this.registerDisposer(t.getRef(e.source)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateChunkPriorities()}))}attach(t){const e=()=>{this.chunkManager.scheduleUpdateChunkPriorities()},{view:n}=t;t.registerDisposer(n.visibility.changed.add(e)),t.registerDisposer(e),e()}updateChunkPriorities(){const t=this.visibility.value;if(t===Number.NEGATIVE_INFINITY)return;this.chunkManager.registerLayer(this);const e=je(t),n=qe(t),{source:i,chunkManager:s}=this;ni(this,r=>{const o=i.getChunk(r);++this.numVisibleChunksNeeded,s.requestChunk(o,e,n+rl);const a=o.state;if(a===N.SYSTEM_MEMORY_WORKER||a===N.SYSTEM_MEMORY||a===N.GPU_MEMORY){++this.numVisibleChunksAvailable;for(const c of o.fragmentIds){const l=i.getFragmentChunk(o,c);++this.numVisibleChunksNeeded,s.requestChunk(l,e,n+ol),l.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable}}})}};oa=os([L(Wp)],oa);class lg extends ne{constructor(){super(...arguments),this.objectId=new R}initializeManifestChunk(e,n){super.initialize(e),this.objectId.assign(n)}freeSystemMemory(){this.manifest=void 0}serialize(e,n){super.serialize(e,n),e.manifest=this.manifest}downloadSucceeded(){this.systemMemoryBytes=this.manifest.octree.byteLength,this.gpuMemoryBytes=0,super.downloadSucceeded(),this.priorityTier<q.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities()}toString(){return this.objectId.toString()}}class hg extends ne{constructor(){super(...arguments),this.subChunkOffsets=null,this.meshData=null,this.lod=0,this.chunkIndex=0,this.manifestChunk=null}freeSystemMemory(){this.meshData=this.subChunkOffsets=null}serialize(e,n){super.serialize(e,n),al(this.meshData,e,n);const{subChunkOffsets:i}=this;e.subChunkOffsets=i,n.push(i.buffer),this.meshData=this.subChunkOffsets=null}downloadSucceeded(){const{subChunkOffsets:e}=this;this.systemMemoryBytes=this.gpuMemoryBytes=cl(this.meshData),this.systemMemoryBytes+=e.byteLength,super.downloadSucceeded()}}class dl extends Le{constructor(e,n){super(e,n);const i=this.fragmentSource=this.registerDisposer(e.getRef(n.fragmentSource));this.format=n.format,i.meshSource=this}getChunk(e){const n=ns(e);let i=this.chunks.get(n);return i===void 0&&(i=this.getNewChunk_(lg),i.initializeManifestChunk(n,e),this.addChunk(i)),i}getFragmentChunk(e,n,i){const s=`${e.key}/${n}:${i}`,r=this.fragmentSource;let o=r.chunks.get(s);return o===void 0&&(o=r.getNewChunk_(hg),o.initialize(s),o.lod=n,o.chunkIndex=i,o.manifestChunk=e,r.addChunk(o)),o}}let aa=class extends Le{constructor(){super(...arguments),this.meshSource=null}download(t,e){return this.meshSource.downloadFragment(t,e)}};aa=os([L(Xp)],aa);const ug=_t();let ca=class extends is(bt(st($c))){constructor(t,e){super(t,e),this.source=this.registerDisposer(t.getRef(e.source)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateChunkPriorities()}))}attach(t){const e=()=>this.chunkManager.scheduleUpdateChunkPriorities(),{view:n}=t;t.registerDisposer(n.projectionParameters.changed.add(e)),t.registerDisposer(n.visibility.changed.add(e)),t.registerDisposer(e),e()}updateChunkPriorities(){const t=this.visibility.value;if(t===Number.NEGATIVE_INFINITY)return;const{transform:{value:e}}=this;if(e.error!==void 0)return;const n=new Array;this.chunkManager.registerLayer(this);{const r=je(t),o=qe(t),{source:a,chunkManager:c}=this;ni(this,l=>{const u=a.getChunk(l);++this.numVisibleChunksNeeded,c.requestChunk(u,r,o+rl);const h=u.state;(h===N.SYSTEM_MEMORY_WORKER||h===N.SYSTEM_MEMORY||h===N.GPU_MEMORY)&&(n.push(u),++this.numVisibleChunksAvailable)})}if(n.length===0)return;const{source:i,chunkManager:s}=this;for(const{view:r}of this.attachments.values()){const o=r.visibility.value;if(o===Number.NEGATIVE_INFINITY)continue;const a=je(o),c=qe(o),l=r.projectionParameters.value,u=ug;try{qd(u,l.displayDimensionRenderInfo,e)}catch{continue}gr(u,l.viewProjectionMat,u);const h=yc(new Float32Array(24),u),d=this.renderScaleTarget.value;for(const p of n){const g=p.manifest.lodScales.length-1;ig(p.manifest,u,h,d,l.width,l.height,(f,v,S,I)=>{if(I)return;const C=i.getFragmentChunk(p,f,v);++this.numVisibleChunksNeeded,s.requestChunk(C,a,c+ol-g+f),C.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable})}}}};ca=os([L(Zp)],ca);function fl(t,e){const n=hl(t.vertexPositions,t.indices),i=new Uint8Array(n.length/3*2);cg(i,n);let s,r;t.indices.BYTES_PER_ELEMENT===4&&t.vertexPositions.length/3<65535?(s=new Uint16Array(t.indices.length),s.set(t.indices)):s=t.indices,r=!1;let o;if(e===xn.uint10){const a=t.vertexPositions,c=a.length/3;o=new Uint32Array(c);for(let l=0,u=0;u<c;l+=3,++u)o[u]=a[l]&1023|(a[l+1]&1023)<<10|(a[l+2]&1023)<<20}else if(e===xn.uint16){const a=t.vertexPositions;a.BYTES_PER_ELEMENT===2?o=a:(o=new Uint16Array(a.length),o.set(a))}else o=t.vertexPositions;return{vertexPositions:o,vertexNormals:i,indices:s,strips:r}}function en(t,e,n=xn.float32){t.meshData=fl(e,n)}function pl(t,e,n){t.meshData=fl(e,n),t.subChunkOffsets=e.subChunkOffsets}function gl(t,e,n){let i=n;for(let s=0;s<3;++s)t[i*5+s]=t[e*5+s]>>>1;t[i*5+3]=e;for(let s=e+1;s<n;++s){const r=t[s*5]>>>1,o=t[s*5+1]>>>1,a=t[s*5+2]>>>1;(r!==t[i*5]||o!==t[i*5+1]||a!==t[i*5+2])&&(t[i*5+4]=s,++i,t[i*5]=r,t[i*5+1]=o,t[i*5+2]=a,t[i*5+3]=s)}return t[i*5+4]=n,++i,i}function dg(t,e,n,i){let s=e;for(let r=n;r<i;++r){const o=t[r*5],a=t[r*5+1],c=t[r*5+2];for(;s<n;){const l=t[s*5]>>>1,u=t[s*5+1]>>>1,h=t[s*5+2]>>>1;if(!sl(l,u,h,o,a,c))break;++s}for(t[r*5+3]=s;s<n;){const l=t[s*5]>>>1,u=t[s*5+1]>>>1,h=t[s*5+2]>>>1;if(l!==o||u!==a||h!==c)break;++s}t[r*5+4]+=s}}/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function Ke(t){return{id:t}}const Tt=Ke("decodeGzip"),Ls=[],Ui=new Map,Tn=new Map,fg=typeof navigator.hardwareConcurrency>"u"?4:Math.min(12,navigator.hardwareConcurrency);let pg=0;function gg(t){for(const[e,n]of Ui){Ui.delete(e),t.postMessage(n.msg,n.transfer);return}Ls.push(t)}function mg(){const t=new Worker(new URL(""+new URL("async_computation.bundle-L6n5R0bn.js",import.meta.url).href,import.meta.url),{type:"module"});return t.onmessage=e=>{const{id:n,value:i,error:s}=e.data;gg(t);const r=Tn.get(n);Tn.delete(n),r!==void 0&&(r.cleanup(),s!==void 0?r.reject(new Error(s)):r.resolve(i))},t}function se(t,e,n,...i){if(e.isCanceled)return Promise.reject(St);const s=pg++,r={t:t.id,id:s,args:i},o=e.add(()=>{Ui.delete(s),Tn.delete(s)}),a=new Promise((c,l)=>{Tn.set(s,{resolve:c,reject:l,cleanup:o})});return Ls.length!==0?Ls.pop().postMessage(r,n):Tn.size<fg?mg().postMessage(r,n):Ui.set(s,{msg:r,transfer:n}),a}const yg=Ke("encodeCompressedSegmentationUint32"),vg=Ke("encodeCompressedSegmentationUint64");async function tn(t,e,n){const{spec:i}=t.source;if(i.compressedSegmentationBlockSize!==void 0){const{dataType:s}=i,r=t.chunkDataSize,o=[r[0],r[1],r[2],r[3]||1];switch(s){case V.UINT32:t.data=await se(yg,e,[n.buffer],n,o,i.compressedSegmentationBlockSize);break;case V.UINT64:t.data=await se(vg,e,[n.buffer],n,o,i.compressedSegmentationBlockSize);break;default:throw new Error(`Unsupported data type for compressed segmentation: ${V[s]}`)}}else t.data=n}const et=new Map;et.set("|u1",{endianness:te.LITTLE,dataType:V.UINT8});et.set("|i1",{endianness:te.LITTLE,dataType:V.INT8});for(const[t,e]of[["<",te.LITTLE],[">",te.BIG]]){for(const n of["u","i"])et.set(`${t}${n}8`,{endianness:e,dataType:V.UINT64});et.set(`${t}u2`,{endianness:e,dataType:V.UINT16}),et.set(`${t}i2`,{endianness:e,dataType:V.INT16}),et.set(`${t}u4`,{endianness:e,dataType:V.UINT32}),et.set(`${t}i4`,{endianness:e,dataType:V.INT32}),et.set(`${t}f4`,{endianness:e,dataType:V.FLOAT32})}function wg(t){const e=et.get(t);if(e===void 0)throw new Error(`Unsupported numpy data type: ${JSON.stringify(t)}`);return e}class Sg{constructor(e,n,i,s){this.data=e,this.shape=n,this.dataType=i,this.fortranOrder=s}}function ml(t){if(t[0]!==147||t[1]!==78||t[2]!==85||t[3]!==77||t[4]!==80||t[5]!==89)throw new Error("Data does not match npy format.");const e=t[6],n=t[7];if(e!==1||n!==0)throw new Error(`Unsupported npy version ${e}.${n}`);const s=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint16(8,!0),r=new TextDecoder("utf-8").decode(t.subarray(10,s+10));let o;const a=s+10;try{o=rd(r)}catch(I){throw new Error(`Failed to parse npy header: ${I}`)}const c=o.descr,l=o.shape;let u=1;if(!Array.isArray(l))throw new Error("Invalid shape ${JSON.stringify(shape)}");for(const I of l){if(typeof I!="number")throw new Error("Invalid shape ${JSON.stringify(shape)}");u*=I}const{dataType:h,endianness:d}=wg(c),p=Qt[h],g=Mc[h],f=bc[h],v=g*u;if(p*u+a!==t.byteLength)throw new Error("Expected length does not match length of data");const S=new f(t.buffer,t.byteOffset+a,v);return _r(S,d,p),new Sg(S,l,h,o.fortran_order===!0)}async function Ig(t,e,n){const i=ml(await se(Tt,e,[n],new Uint8Array(n))),s=t.chunkDataSize,r=t.source,{shape:o}=i;if(o.length!==3||o[0]!==s[2]||o[1]!==s[1]||o[2]!==s[0])throw new Error(`Shape ${JSON.stringify(o)} does not match chunkDataSize ${Vt(s)}`);const a=i.dataType,{spec:c}=r;if(a!==c.dataType)throw new Error(`Data type ${V[a]} does not match expected data type ${V[c.dataType]}`);await tn(t,e,i.data)}const Tr=Ke("decodeJpeg");async function ii(t,e,n){const i=t.chunkDataSize,{uint8Array:s}=await se(Tr,e,[n],new Uint8Array(n),i[0],i[1]*i[2],i[3]||1,!1);await tn(t,e,s)}class Eg extends Lc{constructor(){super(...arguments),this.source=null}initializeVolumeChunk(e,n){super.initializeVolumeChunk(e,n),this.chunkDataSize=null,this.data=null}serialize(e,n){super.serialize(e,n);const i=this.chunkDataSize;i!==this.source.spec.chunkDataSize&&(e.chunkDataSize=i);const s=e.data=this.data;s!==null&&n.push(s.buffer),this.data=null}downloadSucceeded(){var e;this.systemMemoryBytes=this.gpuMemoryBytes=((e=this.data)==null?void 0:e.byteLength)??0,super.downloadSucceeded()}freeSystemMemory(){this.data=null}}function yl(t,e){const{spec:n,tempChunkDataSize:i,tempChunkPosition:s}=t,{upperVoxelBound:r,rank:o,baseVoxelOffset:a}=n,c=n.chunkDataSize,l=i,u=xd(s,e.chunkGridPosition,c);let h=!1;for(let d=0;d<o;++d){const p=Math.min(r[d],u[d]+c[d]);(l[d]=p-u[d])!==c[d]&&(h=!0)}return Ad(u,u,a),h?e.chunkDataSize=Uint32Array.from(l):e.chunkDataSize=c,u}class ze extends zc{constructor(e,n){super(e,n);const i=this.spec.rank;this.tempChunkDataSize=new Uint32Array(i),this.tempChunkPosition=new Float32Array(i)}computeChunkBounds(e){return yl(this,e)}}ze.prototype.chunkConstructor=Eg;var Cg=Object.defineProperty,_g=Object.getOwnPropertyDescriptor,vl=(t,e,n,i)=>{for(var s=i>1?void 0:i?_g(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Cg(e,n,s),s};const Pr=new Map;Pr.set("npz",Ig);Pr.set("jpeg",ii);const Ar=new Map;Ar.set("npz","application/npygz");Ar.set("jpeg","image/jpeg");function wl(t,e){return re(ue()(t),e)}let la=class extends wl(ze,Kp){constructor(){super(...arguments),this.chunkDecoder=Pr.get(this.parameters.encoding)}async download(t,e){const{parameters:n}=this;let i=`${n.baseUrl}/latest/cutout/${n.collection}/${n.experiment}/${n.channel}/${n.resolution}`;{const r=this.computeChunkBounds(t),o=t.chunkDataSize;for(let a=0;a<3;++a)i+=`/${r[a]}:${r[a]+o[a]}`}i+="/",n.window!==void 0&&(i+=`?window=${n.window[0]},${n.window[1]}`);const s=await Yp(this.credentialsProvider,i,{headers:{Accept:Ar.get(n.encoding)}},oe,e);await this.chunkDecoder(t,e,s)}};la=vl([L()],la);function bg(t,e){return ll(t,e,"fragments")}function Mg(t,e){const i=new DataView(e).getUint32(0,!0);en(t,as(e,te.LITTLE,4,i))}let ha=class extends wl(Xt,Jp){download(t,e){const{parameters:n}=this;return Ye(`${n.baseUrl}${t.objectId}`,{},oe,e).then(i=>bg(t,i))}downloadFragment(t,e){const{parameters:n}=this;return Ye(`${n.baseUrl}${t.fragmentId}`,{},oe,e).then(i=>Mg(t,i))}};ha=vl([L()],ha);function Ei(t,e,n,i,s=pe){return t===void 0?Ye(e,n,i,s):Mr(t,e,n,i,(r,o)=>{if(!r.accessToken)return o;const a=new Headers(o.headers);return a.set("Authorization",`${r.tokenType} ${r.accessToken}`),{...o,headers:a}},(r,o)=>{const{status:a}=r;if(a===401||a===403&&!o.accessToken)return"refresh";throw r instanceof Error&&o.email!==void 0&&(r.message+=`  (Using credentials for ${JSON.stringify(o.email)})`),r},s)}function Ue(t,e,n,i=pe){return Ei(e,`${t.serverUrl}${n.path}`,{method:n.method,body:n.payload},n.responseType==="json"?rs:oe,i)}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var vt=(t=>(t[t.RAW=0]="RAW",t[t.JPEG=1]="JPEG",t[t.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION",t))(vt||{}),$n;let Tg=($n=class{},$n.RPC_ID="brainmaps/VolumeChunkSource",$n);var Fn;let Pg=(Fn=class{},Fn.RPC_ID="brainmaps/MultiscaleMeshSource",Fn);var Bn;let Ag=(Bn=class{},Bn.RPC_ID="brainmaps/MeshSource",Bn);var Vn;let xg=(Vn=class{},Vn.RPC_ID="brainmaps/SkeletonSource",Vn);var Gn;let Ng=(Gn=class{},Gn.RPC_ID="brainmaps/Annotation",Gn);var jn;let Og=(jn=class{},jn.RPC_ID="brainmaps/AnnotationSpatialIndex",jn);/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const Rg="skeleton/SkeletonLayer";var Dg=Object.defineProperty,kg=Object.getOwnPropertyDescriptor,Ug=(t,e,n,i)=>{for(var s=i>1?void 0:i?kg(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Dg(e,n,s),s};const Lg=60;class zg extends ne{constructor(){super(...arguments),this.objectId=new R,this.vertexPositions=null,this.vertexAttributes=null,this.indices=null}initializeSkeletonChunk(e,n){super.initialize(e),this.objectId.assign(n)}freeSystemMemory(){this.vertexPositions=this.indices=null}getVertexAttributeBytes(){let e=this.vertexPositions.byteLength;const{vertexAttributes:n}=this;return n!=null&&n.forEach(i=>{e+=i.byteLength}),e}serialize(e,n){super.serialize(e,n);const i=this.vertexPositions,s=this.indices;e.numVertices=i.length/3,e.indices=s,n.push(s.buffer);const{vertexAttributes:r}=this;if(r!=null&&r.length>0){const o=new Uint8Array(this.getVertexAttributeBytes());o.set(new Uint8Array(i.buffer,i.byteOffset,i.byteLength));const a=e.vertexAttributeOffsets=new Uint32Array(r.length+1);a[0]=0;let c=i.byteLength;r.forEach((l,u)=>{a[u+1]=c,o.set(new Uint8Array(l.buffer,l.byteOffset,l.byteLength),c),c+=l.byteLength}),n.push(o.buffer),e.vertexAttributes=o}else e.vertexAttributes=new Uint8Array(i.buffer,i.byteOffset,i.byteLength),e.vertexAttributeOffsets=Uint32Array.of(0),i.buffer!==n[0]&&n.push(i.buffer);this.vertexPositions=this.indices=this.vertexAttributes=null}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=this.indices.byteLength+this.getVertexAttributeBytes(),super.downloadSucceeded()}}class cs extends Le{getChunk(e){const n=ns(e);let i=this.chunks.get(n);return i===void 0&&(i=this.getNewChunk_(zg),i.initializeSkeletonChunk(n,e),this.addChunk(i)),i}}let ua=class extends is(bt(st(Sr))){constructor(t,e){super(t,e),this.source=this.registerDisposer(t.getRef(e.source)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateChunkPriorities()}))}updateChunkPriorities(){const t=this.visibility.value;if(t===Number.NEGATIVE_INFINITY)return;this.chunkManager.registerLayer(this);const e=je(t),n=qe(t),{source:i,chunkManager:s}=this;ni(this,r=>{const o=i.getChunk(r);++this.numVisibleChunksNeeded,o.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable,s.requestChunk(o,e,n+Lg)})}};ua=Ug([L(Rg)],ua);function Sl(t,e,n,i,s,r,o){const a=ul(2,e,n,i,s,r,o);t.vertexPositions=a.vertexPositions,t.indices=a.indices}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */async function xr(t,e,n){t.data=new Uint32Array(n)}async function ft(t,e,n,i=ti,s=0,r=n.byteLength){const{spec:o}=t.source,{dataType:a}=o,c=Nd(t.chunkDataSize),l=Qt[a],u=c*l;if(u!==r)throw new Error(`Raw-format chunk is ${r} bytes, but ${c} * ${l} = ${u} bytes are expected.`);const h=Tc(a,n,s,r);_r(h,i,l),await tn(t,e,h)}/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function $g(t,e){return t<e?-1:t>e?1:0}var Fg=Object.defineProperty,Bg=Object.getOwnPropertyDescriptor,nn=(t,e,n,i)=>{for(var s=i>1?void 0:i?Bg(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Fg(e,n,s),s};const Vg=new Map([[vt.RAW,ft],[vt.JPEG,ii],[vt.COMPRESSED_SEGMENTATION,xr]]);function Il(t,e){t&&(e.change_spec={change_stack_id:t.changeStackId},t.timeStamp&&(e.change_spec.time_stamp=t.timeStamp),t.skipEquivalences&&(e.change_spec.skip_equivalences=t.skipEquivalences))}function sn(t,e){return re(ue()(t),e)}const Gg=new R;let da=class extends sn(ze,Tg){constructor(){super(...arguments),this.chunkDecoder=Vg.get(this.parameters.encoding)}applyEncodingParams(t){const{encoding:e}=this.parameters;switch(e){case vt.RAW:t.subvolume_format="RAW";break;case vt.JPEG:t.subvolume_format="SINGLE_IMAGE",t.image_format_options={image_format:"JPEG",jpeg_quality:this.parameters.jpegQuality};return;case vt.COMPRESSED_SEGMENTATION:t.subvolume_format="RAW",t.image_format_options={compressed_segmentation_block_size:Vt(this.spec.compressedSegmentationBlockSize)};break;default:throw new Error(`Invalid encoding: ${e}`)}}async download(t,e){const{parameters:n}=this,i=this.computeChunkBounds(t),s=t.chunkDataSize,r=`/v1/volumes/${n.volumeId}/subvolume:binary`,o={geometry:{corner:Vt(i),size:Vt(s),scale:n.scaleIndex}};this.applyEncodingParams(o),Il(n.changeSpec,o);const a=await Ue(n.instance,this.credentialsProvider,{method:"POST",payload:JSON.stringify(o),path:r,responseType:"arraybuffer"},e);await this.chunkDecoder(t,e,a)}};da=nn([L()],da);function jg(t,e,n,i){const s=new R;if(!s.tryParseString(t,16))throw new Error(`Couldn't parse fragmentId ${t} as hex-encoded Uint64`);return tg(s,e,n,i)}function qg(t,e){Ge(e);const n=t.source,i=X(e,"fragmentKey",Kt),s=X(e,"supervoxelId",Kt),r=i.length;if(r!==s.length)throw new Error("Expected fragmentKey and supervoxelId arrays to have the same length.");const o=new Map;i.forEach((w,M)=>{let m=o.get(w);m===void 0&&(m=[],o.set(w,m)),m.push(s[M])});const{chunkShape:a}=n.parameters.info,c=n.parameters.info.lods[0].gridShape,l=Math.ceil(Math.log2(c[0])),u=Math.ceil(Math.log2(c[1])),h=Math.ceil(Math.log2(c[2])),d=Array.from(o.entries()).map(([w,M])=>({fragmentId:w,corner:jg(w,l,u,h),supervoxelIds:M}));d.sort((w,M)=>sl(w.corner[0],w.corner[1],w.corner[2],M.corner[0],M.corner[1],M.corner[2])?-1:1);let p,g,f=0,v;if(r===0)p=g=Si,v=Uint32Array.of(0,0,0,0,2147483648);else{const w=As(qu),M=As(Si);for(d.forEach(m=>{const{corner:E}=m;for(let y=0;y<3;++y)w[y]=Math.min(w[y],E[y]),M[y]=Math.max(M[y],E[y])}),f=1;M[0]>>>f-1!==w[0]>>>f-1||M[1]>>>f-1!==w[1]>>>f-1||M[2]>>>f-1!==w[2]>>>f-1;)++f;p=It(w,w,a),g=Bt(M,It(M,M,a),a)}const{lods:S}=n.parameters.info,I=new Float32Array(Math.max(S.length,f));for(let w=0;w<S.length;++w)I[w]=S[w].scale;if(r!==0){const w=new Uint32Array(d.length*I.length*5);d.forEach((E,y)=>{w.set(E.corner,y*5),w[y*5]=E.corner[0]});let M=0,m=d.length;for(let E=1;E<I.length;++E){const y=gl(w,M,m);M=m,m=y}v=w.slice(0,m*5)}const C={chunkShape:a,chunkGridSpatialOrigin:Si,clipLowerBound:p,clipUpperBound:g,octree:v,lodScales:I,vertexOffsets:new Float32Array(I.length*3)};t.manifest=C,t.fragmentSupervoxelIds=d}const zs=255;function El(t,e){const n=t.byteLength;let i=0;const s=new DataView(t),r=32;for(;i<n;){if(i+r>n)throw new Error("Invalid batch mesh fragment response.");const o=s.getUint32(i,!0),a=s.getUint32(i+4,!0),l=new R(o,a).toString()+"\0";i+=8;const u=s.getUint32(i,!0),h=s.getUint32(i+4,!0);if(i+=8,h!==0)throw new Error("Invalid batch mesh fragment response.");if(i+u+8+8>n)throw new Error("Invalid batch mesh fragment response.");const d=new TextDecoder().decode(new Uint8Array(t,i,u)),p=l+d;i+=u;const g=s.getUint32(i,!0),f=s.getUint32(i+4,!0);i+=8;const v=s.getUint32(i,!0),S=s.getUint32(i+4,!0);if(i+=8,f!==0||S!==0)throw new Error("Invalid batch mesh fragment response.");const I=i+v*12+g*12;if(I>n)throw new Error("Invalid batch mesh fragment response.");e({fullKey:p,buffer:t,verticesOffset:i,numVertices:g,indicesOffset:i+12*g,numIndices:v*3}),i=I}}function Cl(t){let e=0,n=0;for(const a of t)e+=a.numVertices,n+=a.numIndices;const i=new Float32Array(e*3),s=new Uint32Array(n);let r=0,o=0;for(const a of t){i.set(new Float32Array(a.buffer,a.verticesOffset,a.numVertices*3),r*3);const{numIndices:c}=a,l=new Uint32Array(a.buffer,a.indicesOffset,c);Ve(l,te.LITTLE);for(let u=0;u<c;++u)s[o++]=l[u]+r;r+=a.numVertices}return Ve(i,te.LITTLE),{vertexPositions:i,indices:s}}async function _l(t,e,n,i){const s="/v1/objects/meshes:batch",r=[];let o,a=0;const c=new Map;for(const[u,h]of n){c.set(u,h),n.delete(u);const d=u.indexOf("\0"),p=u.substring(0,d),g=u.substring(d+1);if(p!==o&&r.push({object_id:p,fragment_keys:[]}),r[r.length-1].fragment_keys.push(g),++a===zs)break}const l={volume_id:e.volumeId,mesh_name:e.meshName,batches:r};try{return await Ue(e.instance,t,{method:"POST",path:s,payload:JSON.stringify(l),responseType:"arraybuffer"},i)}finally{for(const[u,h]of c)n.set(u,h)}}let fa=class extends sn(dl,Pg){constructor(){super(...arguments),this.listFragmentsParams=(()=>{const{parameters:t}=this,{changeSpec:e}=t;return e!==void 0?`&header.changeStackId=${e.changeStackId}`:""})()}download(t,e){const{parameters:n}=this,i=`/v1/objects/${n.volumeId}/meshes/${n.info.lods[0].info.name}:listfragments?object_id=${t.objectId}&return_supervoxel_ids=true`+this.listFragmentsParams;return Ue(n.instance,this.credentialsProvider,{method:"GET",path:i,responseType:"json"},e).then(s=>qg(t,s))}async downloadFragment(t,e){const{parameters:n}=this,i=t.manifestChunk,{fragmentSupervoxelIds:s}=i,r=i.manifest,{lod:o}=t,{octree:a}=r,c=s.length,l=t.chunkIndex;let u=l;for(;u>=c;)u=a[u*5+3];let h=l+1;for(;h>c;)h=a[h*5-1]&2147483647;const{relativeBlockShape:d,gridShape:p}=n.info.lods[o],g=Math.ceil(Math.log2(p[0])),f=Math.ceil(Math.log2(p[1])),v=Math.ceil(Math.log2(p[2]));let S=new Map;for(let T=u;T<h;++T){const P=Math.floor(a[T*5]/d[0]),A=Math.floor(a[T*5+1]/d[1]),D=Math.floor(a[T*5+2]/d[2]),x=il(Gg,g,f,v,P,A,D).toString(16).padStart(16,"0"),F=s[T];for(const z of F.supervoxelIds)S.set(z+"\0"+x,T)}const I=Math.max(0,o-1),C=[],w=Array.from(S);w.sort((T,P)=>$g(T[0],P[0])),S=new Map(w);const M=n.info.lods[o].info.name;await new Promise((T,P)=>{let A=0,D=!1;const x=()=>{if(!D){for(;S.size!==0;)++A,_l(this.credentialsProvider,{instance:n.instance,volumeId:n.volumeId,meshName:M},S,e).then(F=>{--A,El(F,z=>{const U=S.get(z.fullKey);if(!S.delete(z.fullKey))throw new Error(`Received unexpected fragment key: ${JSON.stringify(z.fullKey)}.`);z.chunkIndex=U,C.push(z)}),x()}).catch(F=>{D=!0,P(F)});if(t.downloadSlots=Math.max(1,A),A===0){T(void 0);return}}};x()}),C.sort((T,P)=>T.chunkIndex-P.chunkIndex);let m=0;const E=1<<3*(o-I),y=new Uint32Array(E+1);let _=0;for(const T of C){const P=T.chunkIndex,A=eg(a[P*5]>>>I,a[P*5+1]>>>I,a[P*5+2]>>>I)&E-1;y.fill(m,_+1,A+1),_=A,m+=T.numIndices}y.fill(m,_+1,E+1),pl(t,{...Cl(C),subChunkOffsets:y},xn.float32)}};fa=nn([L()],fa);function Yg(t){const e=[];let n=0;const i=t.length;for(;n<i;)e.push(JSON.stringify(t.slice(n,n+zs))),n+=zs;return e}function Hg(t,e){Ge(e);const n=X(e,"fragmentKey",Kt),i=X(e,"supervoxelId",Kt);if(n.length!==i.length)throw new Error("Expected fragmentKey and supervoxelId arrays to have the same length.");const r=i.map((o,a)=>o+"\0"+n[a]);t.fragmentIds=Yg(r)}let pa=class extends sn(Xt,Ag){constructor(){super(...arguments),this.listFragmentsParams=(()=>{const{parameters:t}=this,{changeSpec:e}=t;return e!==void 0?`&header.changeStackId=${e.changeStackId}`:""})()}download(t,e){const{parameters:n}=this,i=`/v1/objects/${n.volumeId}/meshes/${n.meshName}:listfragments?object_id=${t.objectId}&return_supervoxel_ids=true`+this.listFragmentsParams;return Ue(n.instance,this.credentialsProvider,{method:"GET",path:i,responseType:"json"},e).then(s=>Hg(t,s))}async downloadFragment(t,e){const{parameters:n}=this,i=new Map;for(const o of JSON.parse(t.fragmentId))i.set(o,null);const s=[],{credentialsProvider:r}=this;for(;i.size!==0;){const o=await _l(r,n,i,e);El(o,a=>{if(!i.delete(a.fullKey))throw new Error(`Received unexpected fragment key: ${JSON.stringify(a.fullKey)}.`);s.push(a)})}en(t,Cl(s))}};pa=nn([L()],pa);function Kg(t,e){const n=new DataView(e),i=n.getUint32(0,!0);if(n.getUint32(4,!0)!==0)throw new Error("The number of vertices should not exceed 2^32-1.");const r=n.getUint32(8,!0);if(n.getUint32(12,!0)!==0)throw new Error("The number of edges should not exceed 2^32-1.");Sl(t,e,te.LITTLE,16,i,void 0,r)}let ga=class extends sn(cs,xg){download(t,e){const{parameters:n}=this,i={object_id:`${t.objectId}`},s=`/v1/objects/${n.volumeId}/meshes/${n.meshName}/skeleton:binary`;return Il(n.changeSpec,i),Ue(n.instance,this.credentialsProvider,{method:"POST",path:s,payload:JSON.stringify(i),responseType:"arraybuffer"},e).then(r=>Kg(t,r))}};ga=nn([L()],ga);const Nr=["LOCATION","LINE","VOLUME"];function ma(t){const e=/(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/,n=t.match(e);if(n===null)throw new Error(`Error parsing number triplet: ${JSON.stringify(t)}.`);return ve(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3]))}function $s(t){return t.volumeId+":"+t.changestack+":"}function bl(t,e){if(!e.startsWith(t))throw new Error(`Received annotation id ${JSON.stringify(e)} does not have expected prefix of ${JSON.stringify(t)}.`);return e.substring(t.length)}function Jg(t){if(t!=null)return[Ri(t,e=>R.parseString(""+e,10))]}function Ml(t,e,n){const i=X(t,"corner",u=>ma(Ft(u))),s=X(t,"size",u=>ma(Ft(u))),r=X(t,"payload",od),o=X(t,"type",Ft),a=X(t,"id",Ft),c=bl(e,a),l=X(t,"objectLabels",Jg);if(n!==void 0&&c!==n)throw new Error(`Received annotation has unexpected id ${JSON.stringify(a)}.`);switch(o){case"LOCATION":{if(Uu(s,Si))return{type:nt.POINT,id:c,point:i,description:r,relatedSegments:l,properties:[]};const u=pc(Q(),s,.5),h=Bt(Q(),i,u);return{type:nt.ELLIPSOID,id:c,center:h,radii:u,description:r,relatedSegments:l,properties:[]}}case"LINE":return{type:nt.LINE,id:c,pointA:i,pointB:Bt(Q(),i,s),description:r,relatedSegments:l,properties:[]};case"VOLUME":return{type:nt.AXIS_ALIGNED_BOUNDING_BOX,id:c,pointA:i,pointB:Bt(Q(),i,s),description:r,relatedSegments:l,properties:[]};default:throw new Error(`Unknown spatial annotation type: ${JSON.stringify(o)}.`)}}function Wg(t,e,n){Ge(t);const i=X(t,"annotations",s=>We([void 0],s,Ge))[0];return Ml(i,e,n)}const Zg=ep(3,[]);function Tl(t,e){const n=new np(Zg),i=t.source.parent,s=$s(i.parameters);e.forEach((r,o)=>{try{Ge(r);const a=X(r,"annotations",c=>c===void 0?[]:c);if(!Array.isArray(a))throw new Error(`Expected array, but received ${JSON.stringify(typeof a)}.`);for(const c of a)try{n.add(Ml(c,s))}catch(l){throw new Error(`Error parsing annotation: ${l.message}`)}}catch(a){throw new Error(`Error parsing ${Nr[o]} annotations: ${a.message}`)}}),t.data=Object.assign(new Xc,n.serialize())}function ya(t){const e=t.indexOf(".");return t.substring(0,e)}function gt(t){return`${Math.round(t[0])},${Math.round(t[1])},${Math.round(t[2])}`}function Cs(t,e){return`${t.volumeId}:${t.changestack}:${e}`}function va(t){const e=t.description||"",n=t.relatedSegments===void 0?void 0:t.relatedSegments[0].map(i=>i.toString());switch(t.type){case nt.LINE:{const{pointA:i,pointB:s}=t,r=gs(Q(),s,i);return{type:"LINE",corner:gt(i),size:gt(r),object_labels:n,payload:e}}case nt.AXIS_ALIGNED_BOUNDING_BOX:{const{pointA:i,pointB:s}=t,r=Od(Q(),i,s),o=Rd(Q(),i,s),a=gs(o,o,r);return{type:"VOLUME",corner:gt(r),size:gt(a),object_labels:n,payload:e}}case nt.POINT:return{type:"LOCATION",corner:gt(t.point),size:"0,0,0",object_labels:n,payload:e};case nt.ELLIPSOID:{const i=gs(Q(),t.center,t.radii),s=pc(Q(),t.radii,2);return{type:"LOCATION",corner:gt(i),size:gt(s),object_labels:n,payload:e}}}}let wa=class extends sn(br,Og){async download(t,e){const{parameters:n}=this;return Promise.all(Nr.map(i=>Ue(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:get`,payload:JSON.stringify({type:i,ignore_payload:!0}),responseType:"json"},e))).then(i=>{Tl(t,i)})}};wa=nn([L()],wa);let Sa=class extends sn(tl,Ng){downloadSegmentFilteredGeometry(t,e,n){const{parameters:i}=this;return Promise.all(Nr.map(s=>Ue(i.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${i.volumeId}/${i.changestack}/spatials:get`,payload:JSON.stringify({type:s,object_labels:[t.objectId.toString()],ignore_payload:!0}),responseType:"json"},n))).then(s=>{Tl(t,s)})}downloadMetadata(t,e){const{parameters:n}=this,i=t.key;return Ue(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:get`,payload:JSON.stringify({type:ya(i),id:Cs(n,i)}),responseType:"json"},e).then(s=>{t.annotation=Wg(s,$s(n),i)},()=>{t.annotation=null})}add(t){const{parameters:e}=this,n=va(t);return Ue(e.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${e.volumeId}/${e.changestack}/spatials:push`,payload:JSON.stringify({annotations:[n]}),responseType:"json"}).then(i=>{Ge(i);const s=X(i,"ids",Kt);if(s.length!==1)throw new Error(`Expected list of 1 id, but received ${JSON.stringify(s)}.`);const r=$s(this.parameters);return bl(r,s[0])})}update(t,e){const{parameters:n}=this,i=va(e);return i.id=Cs(n,t),Ue(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:push`,payload:JSON.stringify({annotations:[i]}),responseType:"json"})}delete(t){const{parameters:e}=this;return Ue(e.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${e.volumeId}/${e.changestack}/spatials:delete`,payload:JSON.stringify({type:ya(t),ids:[Cs(e,t)]}),responseType:"json"})}};Sa=nn([L()],Sa);const Pl=Ke("decodePng");/**
 * @license
 * Copyright 2016 Google Inc., 2023 Gergely Csucs
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var Ci=(t=>(t[t.JPG=0]="JPG",t[t.JPEG=1]="JPEG",t[t.PNG=2]="PNG",t))(Ci||{});const to=class to{};to.RPC_ID="deepzoom/ImageTileSource";let Fs=to;async function Qg(t,e,n,i,s=pe){return await Ye(`https://${t}.s3.amazonaws.com${e}`,n,i,s)}async function ge(t,e,n,i,s=pe){const r=jp(e);switch(r.protocol){case"gs":return Ei(t,`https://www.googleapis.com/storage/v1/b/${r.host}/o/${encodeURIComponent(r.path.substring(1))}?alt=media&neuroglancer=${Fo()}`,n,i,s);case"gs+xml":return Ei(t,`https://storage.googleapis.com/${r.host}${r.path}?neuroglancer=${Fo()}`,n,i,s);case"s3":return Qg(r.host,r.path,n,i,s);default:return Ei(t,e,n,i,s)}}var Xg=Object.defineProperty,em=Object.getOwnPropertyDescriptor,tm=(t,e,n,i)=>{for(var s=i>1?void 0:i?em(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Xg(e,n,s),s};let Ia=class extends re(ue()(ze),Fs){constructor(){super(...arguments),this.gridShape=(()=>{const t=new Uint32Array(2),{upperVoxelBound:e,chunkDataSize:n}=this.spec;for(let i=0;i<2;++i)t[i]=Math.ceil(e[i]/n[i]);return t})()}async download(t,e){const{parameters:n}=this,{tilesize:i,overlap:s,encoding:r}=n,[o,a]=t.chunkGridPosition,c=o===0?0:s,l=a===0?0:s,u=`${n.url}/${o}_${a}.${n.format}`;try{const h=await ge(this.credentialsProvider,u,{},oe,e);let d=0,p=0,g;switch(r){case Ci.PNG:{const f=await se(Pl,e,[h],new Uint8Array(h),void 0,void 0,3,1,!1);({width:d,height:p}=f),g=Gu(f.uint8Array,d*p,3);break}case Ci.JPG:case Ci.JPEG:{({uint8Array:g,width:d,height:p}=await se(Tr,e,[h],new Uint8Array(h),void 0,void 0,3,!1));break}}if(g!==void 0){const f=i*i,v=d*p,S=t.data=new Uint8Array(f*3);for(let I=0;I<3;I++)for(let C=0;C<p;C++)for(let w=0;w<d;w++)S[w+C*i+I*f]=g[w+c+(C+l)*d+I*v]}}catch(h){if(!Mt(h))throw h}}};Ia=tm([L()],Ia);class nm{constructor(e,n){this.baseUrl=e,this.nodeKey=n}getNodeApiUrl(e=""){return`${this.baseUrl}/api/node/${this.nodeKey}${e}`}getRepoInfoUrl(){return`${this.baseUrl}/api/repos/info`}getKeyValueUrl(e,n){return`${this.getNodeApiUrl()}/${e}/key/${n}`}getKeyValueRangeUrl(e,n,i){return`${this.getNodeApiUrl()}/${e}/keyrange/${n}/${i}`}getKeyValuesUrl(e){return`${this.getNodeApiUrl()}/${e}/keyvalues?jsontar=false`}}function Or(t,e){return t.includes("?")?t+="&":t+="?",t+="app=Neuroglancer",e&&(t+=`&u=${e}`),t}function im(t){return t.text()}function Rr(t,e,n=pe){return sm(t,e.url,{method:e.method,body:e.payload},e.responseType===""?im:e.responseType==="json"?rs:oe,n)}function sm(t,e,n,i,s=pe){return Mr(t,e,n,i,(r,o)=>{const a={...o};return r.token&&(a.headers={...a.headers,Authorization:`Bearer ${r}`}),a},r=>{const{status:o}=r;if(o===403||o===401)return"refresh";throw r},s)}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var yt=(t=>(t[t.JPEG=0]="JPEG",t[t.RAW=1]="RAW",t[t.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION",t[t.COMPRESSED_SEGMENTATIONARRAY=3]="COMPRESSED_SEGMENTATIONARRAY",t))(yt||{});class Dr{}var qn;let rm=(qn=class extends Dr{},qn.RPC_ID="dvid/VolumeChunkSource",qn);var Yn;let om=(Yn=class extends Dr{},Yn.RPC_ID="dvid/SkeletonSource",Yn);var Hn;let am=(Hn=class extends Dr{},Hn.RPC_ID="dvid/MeshSource",Hn);/**
 * @license
 * This work is a derivative of the Google Neuroglancer project,
 * Copyright 2016 Google Inc.
 * The Derivative Work is covered by
 * Copyright 2020 Howard Hughes Medical Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function cm(t,e){const n=lm(e);if(n.length<1)throw new Error("ERROR parsing swc data");const i=new Uint32Array(n.length);let s=0,r=0;n.forEach((u,h)=>{u&&(i[h]=s++,u.parent>=0&&++r)});const o=new Float32Array(3*s),a=new Uint32Array(2*r);let c=0,l=0;n.forEach(u=>{u&&(o[3*c]=u.x,o[3*c+1]=u.y,o[3*c+2]=u.z,u.parent>=0&&(a[2*l]=c,a[2*l+1]=i[u.parent],++l),++c)}),t.indices=a,t.vertexPositions=o}function lm(t){const e=t.split(`
`),n=[],i="-?\\d*(?:\\.\\d+)?",s=new RegExp("^[ \\t]*("+["\\d+","\\d+",i,i,i,i,"-1|\\d+"].join(")[ \\t]+(")+")[ \\t]*$");return e.forEach(r=>{const o=r.match(s);if(o){const a=n[parseInt(o[1],10)]=new hm;a.type=parseInt(o[2],10),a.x=parseFloat(o[3]),a.y=parseFloat(o[4]),a.z=parseFloat(o[5]),a.radius=parseFloat(o[6]),a.parent=parseInt(o[7],10)}}),n}class hm{}var um=Object.defineProperty,dm=Object.getOwnPropertyDescriptor,kr=(t,e,n,i)=>{for(var s=i>1?void 0:i?dm(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&um(e,n,s),s};function Ur(t,e){return re(ue()(t),e)}let Ea=class extends Ur(cs,om){download(t,e){const{parameters:n}=this,i=`${t.objectId}`,s=`${n.baseUrl}/api/node/${n.nodeKey}/${n.dataInstanceKey}/key/`+i+"_swc";return Rr(this.credentialsProvider,{method:"GET",url:Or(s,n.user),responseType:"arraybuffer"},e).then(r=>{const o=new TextDecoder("utf-8");cm(t,o.decode(r))})}};Ea=kr([L()],Ea);function fm(t,e){const i=new DataView(e).getUint32(0,!0);en(t,as(e,te.LITTLE,4,i))}let Ca=class extends Ur(Xt,am){download(t){return t.fragmentIds=[`${t.objectId}`],Promise.resolve(void 0)}downloadFragment(t,e){const{parameters:n}=this,s=new nm(n.baseUrl,n.nodeKey).getKeyValueUrl(n.dataInstanceKey,`${t.fragmentId}.ngmesh`);return Rr(this.credentialsProvider,{method:"GET",url:Or(s,n.user),responseType:"arraybuffer"},e).then(r=>fm(t,r))}};Ca=kr([L()],Ca);let _a=class extends Ur(ze,rm){async download(t,e){const n=this.parameters;let i;{const o=this.computeChunkBounds(t),a=t.chunkDataSize;i=this.getPath(o,a)}const s=this.getDecoder(n),r=await Rr(this.credentialsProvider,{method:"GET",url:Or(`${n.baseUrl}${i}`,n.user),responseType:"arraybuffer"},e);await s(t,e,n.encoding===yt.JPEG?r.slice(16):r)}getPath(t,e){const n=this.parameters;return n.encoding===yt.JPEG?`/api/node/${n.nodeKey}/${n.dataInstanceKey}/subvolblocks/${e[0]}_${e[1]}_${e[2]}/${t[0]}_${t[1]}_${t[2]}`:n.encoding===yt.RAW?`/api/node/${n.nodeKey}/${n.dataInstanceKey}/raw/0_1_2/${e[0]}_${e[1]}_${e[2]}/${t[0]}_${t[1]}_${t[2]}/jpeg`:n.encoding===yt.COMPRESSED_SEGMENTATIONARRAY?`/api/node/${n.nodeKey}/${n.dataInstanceKey}/raw/0_1_2/${e[0]}_${e[1]}_${e[2]}/${t[0]}_${t[1]}_${t[2]}?compression=googlegzip&scale=${n.dataScale}`:`/api/node/${n.nodeKey}/${n.dataInstanceKey}/raw/0_1_2/${e[0]}_${e[1]}_${e[2]}/${t[0]}_${t[1]}_${t[2]}?compression=googlegzip`}getDecoder(t){return t.encoding===yt.JPEG||t.encoding===yt.RAW?ii:xr}};_a=kr([L()],_a);const pm="GrapheneMeshSource:NewSegment";var Kn;let _y=(Kn=class{},Kn.RPC_ID="graphene/VolumeChunkSource",Kn);const no=class no{};no.RPC_ID="graphene/ChunkedGraphSource";let Bs=no;var Jn;let gm=(Jn=class{},Jn.RPC_ID="graphene/MeshSource",Jn);const mm=async t=>t;function Al(t,e){const n=R.rshift(new R,t,64-e);return R.equal(n,R.ONE)}function ym(t){if(t.charAt(0)==="~"){const n=t.substring(1).split(/:(.+)/);return{key:n[0],fragmentId:n[1]}}return{key:t,fragmentId:t}}const vm="ChunkedGraphLayer",wm="ChunkedGraphLayer:updateSources",Sm=5;/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const ba=Symbol("objectId");let Im=0;function xl(t){if(t instanceof Object){let e=t[ba];return e===void 0&&(e=t[ba]=Im++),`o${e}`}return""+JSON.stringify(t)}class Em extends ne{initialize(e){super.initialize(e),this.requesters=new Set}downloadSucceeded(){super.downloadSucceeded();const{requesters:e,data:n}=this;this.requesters=void 0;for(const i of e)i.resolve(n)}downloadFailed(e){super.downloadFailed(e);const{requesters:n}=this;this.requesters=void 0;for(const i of n)i.reject(e)}freeSystemMemory(){this.data=void 0}}class lt extends wr{constructor(e,n){super(e),this.registerDisposer(e);const{encodeKey:i=Be}=n;this.downloadFunction=n.download,this.encodeKeyFunction=i;const{sourceQueueLevel:s=0}=n;this.sourceQueueLevel=s,this.registerDisposer(this.chunkManager.recomputeChunkPrioritiesLate.add(()=>{this.updateChunkPriorities()}))}updateChunkPriorities(){const{chunkManager:e}=this;for(const n of this.chunks.values()){const{requesters:i}=n;if(i!==void 0)for(const s of i){const{priorityTier:r,priority:o}=s.getPriority();r!==q.RECENT&&e.requestChunk(n,r,o,N.SYSTEM_MEMORY_WORKER)}}}async download(e,n){const{size:i,data:s}=await this.downloadFunction(e.decodedKey,n);e.systemMemoryBytes=i,e.data=s}getData(e,n,i){const s=this.encodeKeyFunction(e);let r=this.chunks.get(s);return r===void 0&&(r=this.getNewChunk_(Em),r.decodedKey=e,r.initialize(s),this.addChunk(r)),sc(i,(o,a,c)=>{switch(r.state){case N.FAILED:a(r.error);return;case N.SYSTEM_MEMORY_WORKER:o(r.data);return}const l={resolve:o,reject:a,getPriority:n};r.requesters.add(l),c.add(()=>{const{requesters:u}=r;u!==void 0&&(u.delete(l),this.chunkManager.scheduleUpdateChunkPriorities()),a(St)}),this.chunkManager.scheduleUpdateChunkPriorities()})}static get(e,n,i){return e.memoize.get(`getFileSource:${n}`,()=>new lt(e.addRef(),i))}static getData(e,n,i,s,r,o){const a=lt.get(e,n,i),c=a.getData(s,r,o);return a.dispose(),c}static getUrl(e,n,i,s,r,o){return lt.getData(e,`${xl(i)}`,{download:(a,c)=>ge(n,a,{},oe,c).then(l=>i(l,c))},s,r,o)}}class Cm extends ne{initialize(e){super.initialize(e)}freeSystemMemory(){this.promise=void 0,this.cancellationSource=void 0}}class _m extends wr{constructor(e,n){super(e),this.registerDisposer(e),this.downloadFunction=n.get,this.encodeKeyFunction=n.encodeKey??Be}get(e,n){const i=this.encodeKeyFunction(e);let s=this.chunks.get(i);if(s===void 0&&(s=this.getNewChunk_(Cm),s.initialize(i),this.addChunk(s)),s.promise===void 0){let r=!1;const o=s.cancellationSource=new ic;o.add(()=>{r||(s.promise=void 0)}),s.promise=(async()=>{try{const{data:a,size:c}=await this.downloadFunction(e,o);return s.systemMemoryBytes=c,s.queueManager.updateChunkState(s,N.SYSTEM_MEMORY),a}catch(a){throw s.queueManager.updateChunkState(s,N.FAILED),a}finally{r=!0}})()}return s.cancellationSource.addConsumer(n),s.promise}}/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var rn=(t=>(t[t.RAW=0]="RAW",t[t.JPEG=1]="JPEG",t[t.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION",t[t.COMPRESSO=3]="COMPRESSO",t[t.PNG=4]="PNG",t))(rn||{}),Wn;let bm=(Wn=class{},Wn.RPC_ID="precomputed/VolumeChunkSource",Wn);var Zn;let Mm=(Zn=class{},Zn.RPC_ID="precomputed/MeshSource",Zn);var Lr=(t=>(t[t.RAW=0]="RAW",t[t.GZIP=1]="GZIP",t))(Lr||{}),Vs=(t=>(t[t.IDENTITY=0]="IDENTITY",t[t.MURMURHASH3_X86_128=1]="MURMURHASH3_X86_128",t))(Vs||{});const io=class io{};io.RPC_ID="precomputed/MultiscaleMeshSource";let Gs=io;var Qn;let Tm=(Qn=class{},Qn.RPC_ID="precomputed/SkeletonSource",Qn);const so=class so{};so.RPC_ID="precomputed/AnnotationSpatialIndexSource";let js=so;const ro=class ro{};ro.RPC_ID="precomputed/AnnotationSource";let qs=ro;const oo=class oo{};oo.RPC_ID="precomputed/IndexedSegmentPropertySource";let Ys=oo;/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */let Nn,Nl=0,Ol;const Ma={emscripten_notify_memory_growth:t=>{},neuroglancer_draco_receive_decoded_mesh:(t,e,n,i,s)=>{const r=t*3,o=Ol.exports.memory,a=new Uint32Array(o.buffer,n,r).slice(),c=new Uint32Array(o.buffer,i,3*e).slice(),l=new Uint32Array(o.buffer,s,Nl+1).slice();Nn={indices:a,vertexPositions:c,subChunkOffsets:l}},proc_exit:t=>{throw`proc exit: ${t}`}},Rl=(async()=>{const t=Ol=(await WebAssembly.instantiateStreaming(fetch(new URL(""+new URL("neuroglancer_draco-4IQwlA-R.wasm",import.meta.url).href,import.meta.url)),{env:Ma,wasi_snapshot_preview1:Ma})).instance;return t.exports._initialize(),t})();async function Pm(t,e,n){const i=await Rl,s=i.exports.malloc(t.byteLength);new Uint8Array(i.exports.memory.buffer).set(t,s),Nl=n?8:1;const o=i.exports.neuroglancer_draco_decode(s,t.byteLength,n,e,!0);if(o===0){const a=Nn;if(Nn=void 0,a instanceof Error)throw a;return a}throw new Error(`Failed to decode draco mesh: ${o}`)}async function Am(t){const e=await Rl,n=e.exports.malloc(t.byteLength);new Uint8Array(e.exports.memory.buffer).set(t,n);const s=e.exports.neuroglancer_draco_decode(n,t.byteLength,!1,0,!1);if(s===0){const r=Nn;if(Nn=void 0,r instanceof Error)throw r;return r.vertexPositions=new Float32Array(r.vertexPositions.buffer),r}throw new Error(`Failed to decode draco mesh: ${s}`)}function Dl(t,e,n){const i=new DataView(e),s=i.getUint32(0,!0),r=i.getUint32(4,!0),o=8;let a=8+s*4*3;Sl(t,e,te.LITTLE,o,s,a,r),a+=r*4*2;const c=[];for(const l of n.values()){const u=Qt[l.dataType]*l.numComponents,h=u*s,d=new Uint8Array(e,a,h);switch(u){case 2:Jf(d,te.LITTLE);break;case 4:case 8:Ve(d,te.LITTLE);break}c.push(d),a+=h}t.vertexAttributes=c}const xm=Ke("decodeCompresso");async function Nm(t,e,n){const i=await se(xm,e,[n],new Uint8Array(n));await ft(t,e,i.buffer)}async function Om(t,e,n){const i=t.chunkDataSize,s=t.source.spec.dataType,{uint8Array:r}=await se(Pl,e,[n],new Uint8Array(n),i[0],i[1]*i[2],i[3]||1,Qt[s],!1);await ft(t,e,r.buffer)}const Rm=navigator.userAgent.indexOf("Chrome")!==-1?"no-store":"default";function On(t,e,n,i,s){return ge(t,e,{headers:Gp(n,i),cache:Rm},oe,s)}function gi(t){return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,t}function Ta(t,e){return t<<e|t>>>32-e}function Dm(t,e,n,i){let s=e,r=e,o=e,a=e;const c=597399067,l=2869860233,u=951274213;let h=Math.imul(i,l);h=Ta(h,16),h=Math.imul(h,u),r^=h;let d=Math.imul(n,c);d=Ta(d,15),d=Math.imul(d,l),s^=d;const p=8;return s^=p,r^=p,o^=p,a^=p,s=s+r>>>0,s=s+o>>>0,s=s+a>>>0,r=r+s>>>0,o=o+s>>>0,a=a+s>>>0,s=gi(s),r=gi(r),o=gi(o),a=gi(a),s=s+r>>>0,s=s+o>>>0,s=s+a>>>0,r=r+s>>>0,t.low=s,t.high=r,t}var km=Object.defineProperty,Um=Object.getOwnPropertyDescriptor,Pt=(t,e,n,i)=>{for(var s=i>1?void 0:i?Um(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&km(e,n,s),s};const Lm=new Map([[Vs.MURMURHASH3_X86_128,t=>{Dm(t,0,t.low,t.high)}],[Vs.IDENTITY,t=>{}]]);function Et(t,e,n){const{url:i,sharding:s}=n;if(s===void 0)return;const r=lt.get(t,Be({type:"precomputed:shardedDataSource",url:i,sharding:s,credentialsProvider:xl(e)}),{download:async(o,a)=>{const c=R.lowMask(new R,s.minishardBits);R.and(c,c,o);const l=R.lowMask(new R,s.shardBits),u=new R;R.rshift(u,o,s.minishardBits),R.and(l,l,u);const h=`${i}/${l.toString(16).padStart(Math.ceil(s.shardBits/4),"0")}.shard`,d=new R(16);R.lshift(d,d,s.minishardBits);const p=R.lshift(new R,c,4),g=R.addUint32(new R,p,16);let f;try{f=await On(e,h,p,g,a)}catch(T){if(Mt(T))return{data:void 0,size:0};throw T}if(f.byteLength!==16)throw new Error("Failed to retrieve minishard offset");const v=new DataView(f),S=new R(v.getUint32(0,!0),v.getUint32(4,!0)),I=new R(v.getUint32(8,!0),v.getUint32(12,!0));if(R.equal(S,I))return{data:void 0,size:0};R.add(S,S,d),R.add(I,I,d);let C=await On(e,h,S,I,a);if(s.minishardIndexEncoding===Lr.GZIP&&(C=(await se(Tt,a,[C],new Uint8Array(C))).buffer),C.byteLength%24!==0)throw new Error(`Invalid minishard index length: ${C.byteLength}`);const w=new Uint32Array(C);Ve(w,te.LITTLE);const M=w.byteLength/24;let m=0,E=0,y=d.low,_=d.high;for(let T=0;T<M;++T){let P=m+w[T*2],A=E+w[T*2+1];P>=4294967296&&(P-=4294967296,A+=1),m=w[T*2]=P,E=w[T*2+1]=A;let D=y+w[(M+T)*2],x=_+w[(M+T)*2+1];D>=4294967296&&(D-=4294967296,x+=1),w[(M+T)*2]=D,w[(M+T)*2+1]=x;const F=w[(2*M+T)*2],z=w[(2*M+T)*2+1];let U=D+F,Y=x+z;U>=4294967296&&(U-=4294967296,Y+=1),y=U,_=Y,w[(2*M+T)*2]=U,w[(2*M+T)*2+1]=Y}return{data:{data:w,shardUrl:h},size:w.byteLength}},encodeKey:o=>o.toString(),sourceQueueLevel:1});return r.sharding=s,r.credentialsProvider=e,r}function zm(t,e){const n=t.data,i=n.length/6,s=e.low,r=e.high;for(let o=0;o<i;++o){if(n[o*2]!==s||n[o*2+1]!==r)continue;const a=new R(n[(i+o)*2],n[(i+o)*2+1]),c=new R(n[(2*i+o)*2],n[(2*i+o)*2+1]);return{startOffset:a,endOffset:c}}}async function ls(t,e,n,i){const{sharding:s}=t,r=Lm.get(s.hash),o=R.rshift(new R,n,s.preshiftBits);r(o);const a=R.lowMask(new R,s.minishardBits+s.shardBits);R.and(a,a,o);const c=()=>({priorityTier:e.priorityTier,priority:e.priority}),l=await t.getData(a,c,i);if(l===void 0)return;const u=zm(l,n);if(u===void 0)return;const{startOffset:h,endOffset:d}=u;let p=await On(t.credentialsProvider,l.shardUrl,h,d,i);return t.sharding.dataEncoding===Lr.GZIP&&(p=(await se(Tt,i,[p],new Uint8Array(p))).buffer),{data:p,shardInfo:{shardUrl:l.shardUrl,offset:h}}}function kl(t){if(t===void 0)throw new Error("not found");return t}const on=new Map;on.set(rn.RAW,ft);on.set(rn.JPEG,ii);on.set(rn.COMPRESSED_SEGMENTATION,xr);on.set(rn.COMPRESSO,Nm);on.set(rn.PNG,Om);let Pa=class extends re(ue()(ze),bm){constructor(){super(...arguments),this.chunkDecoder=on.get(this.parameters.encoding),this.minishardIndexSource=Et(this.chunkManager,this.credentialsProvider,this.parameters),this.gridShape=(()=>{const e=new Uint32Array(3),{upperVoxelBound:n,chunkDataSize:i}=this.spec;for(let s=0;s<3;++s)e[s]=Math.ceil(n[s]/i[s]);return e})()}async download(e,n){var o;const{parameters:i}=this,{minishardIndexSource:s}=this;let r;if(s===void 0){let a;{const c=this.computeChunkBounds(e),l=e.chunkDataSize;a=`${i.url}/${c[0]}-${c[0]+l[0]}_${c[1]}-${c[1]+l[1]}_${c[2]}-${c[2]+l[2]}`}try{r=await ge(this.credentialsProvider,a,{},oe,n)}catch(c){if(Mt(c))r=void 0;else throw c}}else{this.computeChunkBounds(e);const{gridShape:a}=this,{chunkGridPosition:c}=e,l=Math.ceil(Math.log2(a[0])),u=Math.ceil(Math.log2(a[1])),h=Math.ceil(Math.log2(a[2])),d=il(new R,l,u,h,c[0],c[1],c[2]);r=(o=await ls(s,e,d,n))==null?void 0:o.data}r!==void 0&&await this.chunkDecoder(e,n,r)}};Pa=Pt([L()],Pa);function Hs(t,e){return ll(t,e,"fragments")}function $m(t,e){const i=new DataView(e).getUint32(0,!0);en(t,as(e,te.LITTLE,4,i))}let Aa=class extends re(ue()(Xt),Mm){async download(t,e){const{parameters:n}=this,i=await ge(this.credentialsProvider,`${n.url}/${t.objectId}:${n.lod}`,{},rs,e);Hs(t,i)}async downloadFragment(t,e){const{parameters:n}=this,i=await ge(this.credentialsProvider,`${n.url}/${t.fragmentId}`,{},oe,e);$m(t,i)}};Aa=Pt([L()],Aa);function Fm(t,e){if(e.byteLength<28||e.byteLength%4!==0)throw new Error(`Invalid index file size: ${e.byteLength}`);const n=new DataView(e);let i=0;const s=ve(n.getFloat32(i,!0),n.getFloat32(i+4,!0),n.getFloat32(i+8,!0));i+=12;const r=ve(n.getFloat32(i,!0),n.getFloat32(i+4,!0),n.getFloat32(i+8,!0));i+=12;const o=n.getUint32(i,!0);if(i+=4,e.byteLength<i+(8+4*3)*o)throw new Error(`Invalid index file size for ${o} lods: ${e.byteLength}`);const a=new Float32Array(e,i,o);i+=4*o,Ve(a,te.LITTLE);const c=new Float32Array(e,i,o*3);Ve(c,te.LITTLE),i+=12*o;const l=new Uint32Array(e,i,o);i+=4*o,Ve(l,te.LITTLE);const u=l.reduce((m,E)=>m+E);if(e.byteLength!==i+16*u)throw new Error(`Invalid index file size for ${o} lods and ${u} total fragments: ${e.byteLength}`);const h=new Uint32Array(e,i);Ve(h,te.LITTLE);const d=ve(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),p=ve(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);let g=Math.max(1,a.length);{let m=0;for(let E=0;E<o;++E){const y=l[E];for(let _=0;_<3;++_){let T=Number.NEGATIVE_INFINITY,P=Number.POSITIVE_INFINITY;const A=m+y*_;for(let D=0;D<y;++D){const x=h[A+D];T=Math.max(T,x),P=Math.min(P,x)}if(y!==0){for(;T>>>g-E-1!==P>>>g-E-1;)++g;E===0&&(d[_]=Math.min(d[_],(1<<E)*P),p[_]=Math.max(p[_],(1<<E)*(T+1)))}}m+=y*4}}let f=0;{let m=0,E=0;for(let y=0;y<o;++y){const _=l[y];f+=m*(y-E),E=y,m=_,f+=_}f+=(g-1-E)*m}const v=new Uint32Array(5*f),S=new Float64Array(f+1);let I;{let m=0,E=0,y=0,_=0;for(let T=0;T<o;++T){const P=l[T];for(let A=0;A<P;++A){for(let x=0;x<3;++x)v[5*(E+A)+x]=h[_+A+x*P];const D=h[_+A+3*P];y+=D,S[E+A+1]=y,D===0&&(v[5*(E+A)+4]=2147483648)}for(_+=4*P,T!==0&&dg(v,m,E,E+P),m=E,E+=P;T+1<g&&(T+1>=a.length||a[T+1]===0);){const A=gl(v,m,E);S.fill(y,E+1,A+1),m=E,E=A,++T}}I=v.slice(0,5*E),t.offsets=S.slice(0,E+1)}const C=t.source,{lodScaleMultiplier:w}=C.parameters.metadata,M=new Float32Array(g);M.set(a,0);for(let m=0;m<a.length;++m)M[m]*=w;t.manifest={chunkShape:s,chunkGridSpatialOrigin:r,clipLowerBound:Bt(d,r,It(d,d,s)),clipUpperBound:Bt(p,r,It(p,p,s)),octree:I,lodScales:M,vertexOffsets:c}}async function Bm(t,e){const{lod:n}=t,i=t.manifestChunk.source,s=await Pm(new Uint8Array(e),i.parameters.metadata.vertexQuantizationBits,n!==0);pl(t,s,i.format.vertexPositionFormat)}let xa=class extends re(ue()(dl),Gs){constructor(){super(...arguments),this.minishardIndexSource=Et(this.chunkManager,this.credentialsProvider,{url:this.parameters.url,sharding:this.parameters.metadata.sharding})}async download(t,e){const{parameters:n,minishardIndexSource:i}=this;let s;i===void 0?s=await ge(this.credentialsProvider,`${n.url}/${t.objectId}.index`,{},oe,e):{data:s,shardInfo:t.shardInfo}=kl(await ls(i,t,t.objectId,e)),Fm(t,s)}async downloadFragment(t,e){const{parameters:n}=this,i=t.manifestChunk,s=t.chunkIndex,{shardInfo:r,offsets:o}=i,a=o[s],c=o[s+1];let l,u,h;if(r!==void 0){l=r.shardUrl;const p=o[o.length-1];let g=r.offset.low-p+a,f=r.offset.high,v=g+c-a,S=f;for(;g<0;)g+=4294967296,f-=1;for(;v<0;)v+=4294967296,S-=1;for(;v>4294967296;)v-=4294967296,S+=1;u=new R(g,f),h=new R(v,S)}else l=`${n.url}/${i.objectId}`,u=a,h=c;const d=await On(this.credentialsProvider,l,u,h,e);await Bm(t,d)}};xa=Pt([L()],xa);async function Ks(t,e,n,i,s,r){if(i===void 0)try{return await ge(t,`${e}/${s}`,{},oe,r)}catch(a){if(Mt(a))return;throw a}const o=await ls(i,n,s,r);if(o!==void 0)return o.data}let Na=class extends re(ue()(cs),Tm){constructor(){super(...arguments),this.minishardIndexSource=Et(this.chunkManager,this.credentialsProvider,{url:this.parameters.url,sharding:this.parameters.metadata.sharding})}async download(t,e){const{parameters:n}=this,i=kl(await Ks(this.credentialsProvider,n.url,t,this.minishardIndexSource,t.objectId,e));Dl(t,i,n.metadata.vertexAttributes)}};Na=Pt([L()],Na);function Ul(t,e,n){const i=new DataView(t);if(t.byteLength<=8)throw new Error("Expected at least 8 bytes");const s=i.getUint32(0,!0);if(i.getUint32(4,!0)!==0)throw new Error("Annotation count too high");const o=n.serializedBytes,a=8+(o+8)*s;if(t.byteLength!==a)throw new Error(`Expected ${a} bytes, but received: ${t.byteLength} bytes`);const c=8+o*s,l=new R,u=new Array(s);for(let I=0;I<s;++I)l.low=i.getUint32(c+I*8,!0),l.high=i.getUint32(c+I*8+4,!0),u[I]=l.toString();const h=new Xc,d=new Uint8Array(t,8,o*s);let p;const{propertyGroupBytes:g}=n;if(g.length>1){p=new Uint8Array(d.length);let I=0,C=0;for(let w=0;w<g.length;++w){const M=g[w];for(let m=0;m<s;++m){const E=I+m*o,y=C+m*M;for(let _=0;_<M;++_)p[y+_]=d[E+_]}I+=M,C+=M*s}}else p=d;h.data=p;const f=h.typeToOffset=new Array(Gt.length);f.fill(0),f[e.type]=0;const v=h.typeToIds=new Array(Gt.length),S=h.typeToIdMaps=new Array(Gt.length);return v.fill([]),v[e.type]=u,S.fill(new Map),S[e.type]=new Map(u.map((I,C)=>[I,C])),h}function Vm(t,e,n,i){const s=ts[e.type],r=n.serializedBytes,o=e.relationships.length,a=r+4*o;if(t.byteLength<a)throw new Error(`Expected at least ${a} bytes, but received: ${t.byteLength}`);const c=new DataView(t),l=s.deserialize(c,0,!0,e.rank,i);n.deserialize(c,0,0,1,!0,l.properties=new Array(e.properties.length));let u=r;const h=l.relatedSegments=[];h.length=o;for(let d=0;d<o;++d){const p=c.getUint32(u,!0);if(t.byteLength<a+p*8)throw new Error(`Expected at least ${a} bytes, but received: ${t.byteLength}`);u+=4;const g=h[d]=[];for(let f=0;f<p;++f)g[f]=new R(c.getUint32(u,!0),c.getUint32(u+4,!0)),u+=8}if(u!==t.byteLength)throw new Error(`Expected ${u} bytes, but received: ${t.byteLength}`);return l}let Oa=class extends re(ue()(br),js){constructor(){super(...arguments),this.minishardIndexSource=Et(this.chunkManager,this.credentialsProvider,this.parameters)}async download(t,e){const{parameters:n}=this,{minishardIndexSource:i}=this,{parent:s}=this;let r;const{chunkGridPosition:o}=t;if(i===void 0){const a=`${n.url}/${o.join("_")}`;try{r=await ge(this.credentialsProvider,a,{},oe,e)}catch(c){if(!Mt(c))throw c}}else{const{upperChunkBound:a}=this.spec,{chunkGridPosition:c}=t,l=ng(new R,c,a),u=await ls(i,t,l,e);u!==void 0&&(r=u.data)}r!==void 0&&(t.data=Ul(r,s.parameters,s.annotationPropertySerializer))}};Oa=Pt([L()],Oa);let Ra=class extends re(ue()(tl),qs){constructor(){super(...arguments),this.byIdMinishardIndexSource=Et(this.chunkManager,this.credentialsProvider,this.parameters.byId),this.relationshipIndexSource=this.parameters.relationships.map(t=>Et(this.chunkManager,this.credentialsProvider,t)),this.annotationPropertySerializer=new Gc(this.parameters.rank,ts[this.parameters.type].serializedBytes(this.parameters.rank),this.parameters.properties)}async downloadSegmentFilteredGeometry(t,e,n){const{parameters:i}=this,s=await Ks(this.credentialsProvider,i.relationships[e].url,t,this.relationshipIndexSource[e],t.objectId,n);s!==void 0&&(t.data=Ul(s,this.parameters,this.annotationPropertySerializer))}async downloadMetadata(t,e){const{parameters:n}=this,i=R.parseString(t.key),s=await Ks(this.credentialsProvider,n.byId.url,t,this.byIdMinishardIndexSource,i,e);s===void 0?t.annotation=null:t.annotation=Vm(s,this.parameters,this.annotationPropertySerializer,t.key)}};Ra=Pt([L()],Ra);let Da=class extends re(ue()(Mp),Ys){constructor(){super(...arguments),this.minishardIndexSource=Et(this.chunkManager,this.credentialsProvider,this.parameters)}};Da=Pt([L()],Da);var Gm=Object.defineProperty,jm=Object.getOwnPropertyDescriptor,zr=(t,e,n,i)=>{for(var s=i>1?void 0:i?jm(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Gm(e,n,s),s};function qm(t,e,n,i){if(e.fragmentId&&e.fragmentId.charAt(0)==="~"){const s=e.fragmentId.substr(1).split(":"),r=Number(s[1]),o=r+Number(s[2]);return On(t,`${n.fragmentUrl}/initial/${s[0]}`,r,o,i)}return ge(t,`${n.fragmentUrl}/dynamic/${e.fragmentId}`,{},oe,i)}function Ym(t,e,n,i){let s;return n.sharding?s=qm(t,e,n,i):s=ge(t,`${n.fragmentUrl}/${e.fragmentId}`,{},oe,i),s}async function Hm(t,e){const n=await Am(new Uint8Array(e));en(t,n)}let ka=class extends re(ue()(Xt),gm){constructor(){super(...arguments),this.manifestRequestCount=new Map,this.newSegments=new An}addNewSegment(t){const{newSegments:e}=this;e.add(t);const n=1e3*60*10;setTimeout(()=>{e.delete(t)},n)}async download(t,e){const{parameters:n,newSegments:i,manifestRequestCount:s}=this;if(Al(t.objectId,n.nBitsForLayerId))return Hs(t,{fragments:[]});const o=`${`${n.manifestUrl}/manifest`}/${t.objectId}:${n.lod}?verify=1&prepend_seg_ids=1`;await ge(this.credentialsProvider,o,{},rs,e).then(a=>{const c=o;if(i.has(t.objectId)){const l=(s.get(c)||0)+1;s.set(c,l),setTimeout(()=>{this.chunkManager.queueManager.updateChunkState(t,N.QUEUED)},2**l*1e3)}else s.delete(c);return Hs(t,a)})}async downloadFragment(t,e){const{parameters:n}=this,i=await Ym(void 0,t,n,e);await Hm(t,i)}getFragmentKey(t,e){return ym(e)}};ka=zr([L()],ka);class Km extends ne{constructor(){super(...arguments),this.source=null,this.leaves=[]}initializeVolumeChunk(e,n){super.initialize(e),this.chunkGridPosition=Float32Array.from(n)}initializeChunkedGraphChunk(e,n,i){this.initializeVolumeChunk(e,n),this.chunkDataSize=null,this.systemMemoryBytes=16,this.gpuMemoryBytes=0,this.segment=i}downloadSucceeded(){this.systemMemoryBytes=16,this.systemMemoryBytes+=16*this.leaves.length,this.queueManager.updateChunkState(this,N.SYSTEM_MEMORY_WORKER),this.priorityTier<q.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities(),super.downloadSucceeded()}freeSystemMemory(){this.leaves=[]}}function Jm(t){const e=new Array(t.length);for(let n=0;n<e.length;++n)e[n]=R.parseString(t[n]);return e}let Ua=class extends re(ue()(Le),Bs){constructor(t,e){super(t,e),this.spec=e.spec;const n=this.spec.rank;this.tempChunkDataSize=new Uint32Array(n),this.tempChunkPosition=new Float32Array(n)}async download(t,e){const{parameters:n}=this,i=this.computeChunkBounds(t),s=t.chunkDataSize,r=`${i[0]}-${i[0]+s[0]}_${i[1]}-${i[1]+s[1]}_${i[2]}-${i[2]+s[2]}`,o=ge(this.credentialsProvider,`${n.url}/${t.segment}/leaves?int64_as_str=1&bounds=${r}`,{},mm,e);await this.withErrorMessage(o,`Fetching leaves of segment ${t.segment} in region ${r}: `).then(a=>a.json()).then(a=>{t.leaves=Jm(a.leaf_ids)}).catch(a=>console.error(a))}getChunk(t,e){const n=`${Vt(t)}-${e}`;let i=this.chunks.get(n);return i===void 0&&(i=this.getNewChunk_(Km),i.initializeChunkedGraphChunk(n,t,e),this.addChunk(i)),i}computeChunkBounds(t){return yl(this,t)}async withErrorMessage(t,e){const n=await t;if(n.ok)return n;let i;try{i=(await n.json()).message}catch{i=await n.text()}throw new Error(`[${n.status}] ${e}${i}`)}};Ua=zr([L()],Ua);const La=Q(),Wm=Q(),Zm=Q();let za=class extends is(bt(st(Qi))){constructor(t,e){super(t,e),this.debouncedupdateDisplayState=ur(()=>{this.updateDisplayState()},100),this.source=this.registerDisposer(t.getRef(e.source)),this.localPosition=t.get(e.localPosition),this.leafRequestsActive=t.get(e.leafRequestsActive),this.nBitsForLayerId=t.get(e.nBitsForLayerId),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateChunkPriorities(),this.debouncedupdateDisplayState()}))}attach(t){const e=()=>this.chunkManager.scheduleUpdateChunkPriorities(),{view:n}=t;t.registerDisposer(e),t.registerDisposer(n.projectionParameters.changed.add(e)),t.registerDisposer(n.visibility.changed.add(e)),t.state={displayDimensionRenderInfo:n.projectionParameters.value.displayDimensionRenderInfo}}get renderRatioLimit(){return Sm}updateChunkPriorities(){const{source:t,chunkManager:e}=this;e.registerLayer(this);for(const n of this.attachments.values()){const{view:i}=n,s=i.visibility.value;if(s===Number.NEGATIVE_INFINITY)continue;const r=n.state,{transformedSource:o}=r,a=i.projectionParameters.value;if(!o)continue;const c=a.pixelSize*1.1,l=o.effectiveVoxelSize;if(this.leafRequestsActive.value=this.renderRatioLimit>=c/Math.min(...l),!this.leafRequestsActive.value)continue;const u=je(s),h=qe(s),{chunkLayout:d}=o,{size:p,finiteRank:g}=d,f=Zm,v=Wm;Wi(f,p);for(let I=g;I<3;++I)f[I]=0,v[I]=0;const{centerDataPosition:S}=a;d.globalToLocalSpatial(v,S),Rc(a,this.localPosition.value,o,Dc(a,d),I=>{It(La,I,f);const C=-mr(v,La),{curPositionInChunks:w}=o;ni(this,(M,m)=>{if(Al(M,this.nBitsForLayerId.value))return;const E=t.getChunk(w,M.clone());e.requestChunk(E,u,h+C,N.SYSTEM_MEMORY_WORKER),++this.numVisibleChunksNeeded,E.state===N.GPU_MEMORY&&++this.numVisibleChunksAvailable})})}}forEachSelectedRootWithLeaves(t){const{source:e}=this;for(const n of e.chunks.values())n.state===N.SYSTEM_MEMORY_WORKER&&n.priorityTier<q.RECENT&&this.visibleSegments.has(n.segment)&&n.leaves.length&&t(n.segment.toString(),n.leaves)}updateDisplayState(){const t=new Map,e=new Map;this.forEachSelectedRootWithLeaves((n,i)=>{e.has(n)?e.set(n,e.get(n)+i.length):e.set(n,i.length)}),this.forEachSelectedRootWithLeaves((n,i)=>{t.has(n)||(t.set(n,new An),t.get(n).reserve(e.get(n)),t.get(n).add(R.parseString(n))),t.get(n).add(i)});for(const[n,i]of t){const s=[...i].filter(o=>!this.segmentEquivalences.has(o)),r=R.parseString(n);for(const o of s)this.segmentEquivalences.link(r,o)}}};za=zr([L(vm)],za);K(wm,function(t){const e=this.get(t.view),n=this.get(t.layer),i=n.attachments.get(e);i.state.transformedSource=es(this,t.sources,n)[0][0],i.state.displayDimensionRenderInfo=t.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()});K(pm,function(t){this.get(t.rpcId).addNewSegment(R.parseString(t.segment))});const Ll=Ke("decodeBlosc"),zl=Ke("decodeZstd");/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var _i=(t=>(t[t.RAW=0]="RAW",t[t.GZIP=1]="GZIP",t[t.BLOSC=2]="BLOSC",t[t.ZSTD=3]="ZSTD",t))(_i||{}),Xn;let Qm=(Xn=class{},Xn.RPC_ID="n5/VolumeChunkSource",Xn);var Xm=Object.defineProperty,e0=Object.getOwnPropertyDescriptor,t0=(t,e,n,i)=>{for(var s=i>1?void 0:i?e0(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&Xm(e,n,s),s};async function n0(t,e,n,i){const s=new DataView(n),r=s.getUint16(0,!1);if(r!==0)throw new Error(`Unsupported mode: ${r}.`);const o=s.getUint16(2,!1);if(o!==t.source.spec.rank)throw new Error("Number of dimensions must be 3.");let a=4;const c=new Uint32Array(o);for(let u=0;u<o;++u)c[u]=s.getUint32(a,!1),a+=4;t.chunkDataSize=c;let l=new Uint8Array(n,a);switch(i){case _i.GZIP:l=await se(Tt,e,[l.buffer],l);break;case _i.BLOSC:l=await se(Ll,e,[l.buffer],l);break;case _i.ZSTD:l=await se(zl,e,[l.buffer],l);break}await ft(t,e,l.buffer,te.BIG,l.byteOffset,l.byteLength)}let $a=class extends re(ue()(ze),Qm){async download(t,e){const{parameters:n}=this,{chunkGridPosition:i}=t;let s=n.url;const r=this.spec.rank;for(let o=0;o<r;++o)s+=`/${i[o]}`;try{const o=await ge(this.credentialsProvider,s,{},oe,e);await n0(t,e,o,n.encoding)}catch(o){if(!Mt(o))throw o}}};$a=t0([L()],$a);var Lt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Ce={},$={};Object.defineProperty($,"__esModule",{value:!0});var Fa={},$l={};$l.default=function(t,e,n,i,s){var r=new Worker(Fa[e]||(Fa[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return r.onmessage=function(o){var a=o.data,c=a.$e$;if(c){var l=new Error(c[0]);l.code=c[1],l.stack=c[2],s(l,null)}else s(null,a)},r.postMessage(n,i),r};var G=Uint8Array,we=Uint16Array,si=Int32Array,an=new G([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]),cn=new G([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]),Rn=new G([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fl=function(t,e){for(var n=new we(31),i=0;i<31;++i)n[i]=e+=1<<t[i-1];for(var s=new si(n[30]),i=1;i<30;++i)for(var r=n[i];r<n[i+1];++r)s[r]=r-n[i]<<5|i;return{b:n,r:s}},Bl=Fl(an,2),$r=Bl.b,Li=Bl.r;$r[28]=258,Li[258]=28;var Vl=Fl(cn,0),Gl=Vl.b,Js=Vl.r,Dn=new we(32768);for(var ee=0;ee<32768;++ee){var at=(ee&43690)>>1|(ee&21845)<<1;at=(at&52428)>>2|(at&13107)<<2,at=(at&61680)>>4|(at&3855)<<4,Dn[ee]=((at&65280)>>8|(at&255)<<8)>>1}var Re=function(t,e,n){for(var i=t.length,s=0,r=new we(e);s<i;++s)t[s]&&++r[t[s]-1];var o=new we(e);for(s=1;s<e;++s)o[s]=o[s-1]+r[s-1]<<1;var a;if(n){a=new we(1<<e);var c=15-e;for(s=0;s<i;++s)if(t[s])for(var l=s<<4|t[s],u=e-t[s],h=o[t[s]-1]++<<u,d=h|(1<<u)-1;h<=d;++h)a[Dn[h]>>c]=l}else for(a=new we(i),s=0;s<i;++s)t[s]&&(a[s]=Dn[o[t[s]-1]++]>>15-t[s]);return a},it=new G(288);for(var ee=0;ee<144;++ee)it[ee]=8;for(var ee=144;ee<256;++ee)it[ee]=9;for(var ee=256;ee<280;++ee)it[ee]=7;for(var ee=280;ee<288;++ee)it[ee]=8;var Jt=new G(32);for(var ee=0;ee<32;++ee)Jt[ee]=5;var jl=Re(it,9,0),ql=Re(it,9,1),Yl=Re(Jt,5,0),Hl=Re(Jt,5,1),bi=function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},Oe=function(t,e,n){var i=e/8|0;return(t[i]|t[i+1]<<8)>>(e&7)&n},Mi=function(t,e){var n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},ln=function(t){return(t+7)/8|0},De=function(t,e,n){return(e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new G(t.subarray(e,n))};$.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 Kl=["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"],k=function(t,e,n){var i=new Error(e||Kl[t]);if(i.code=t,Error.captureStackTrace&&Error.captureStackTrace(i,k),!n)throw i;return i},ri=function(t,e,n,i){var s=t.length,r=i?i.length:0;if(!s||e.f&&!e.l)return n||new G(0);var o=!n,a=o||e.i!=2,c=e.i;o&&(n=new G(s*3));var l=function(Ae){var Je=n.length;if(Ae>Je){var rt=new G(Math.max(Je*2,Ae));rt.set(n),n=rt}},u=e.f||0,h=e.p||0,d=e.b||0,p=e.l,g=e.d,f=e.m,v=e.n,S=s*8;do{if(!p){u=Oe(t,h,1);var I=Oe(t,h+1,3);if(h+=3,I)if(I==1)p=ql,g=Hl,f=9,v=5;else if(I==2){var m=Oe(t,h,31)+257,E=Oe(t,h+10,15)+4,y=m+Oe(t,h+5,31)+1;h+=14;for(var _=new G(y),T=new G(19),P=0;P<E;++P)T[Rn[P]]=Oe(t,h+P*3,7);h+=E*3;for(var A=bi(T),D=(1<<A)-1,x=Re(T,A,1),P=0;P<y;){var F=x[Oe(t,h,D)];h+=F&15;var C=F>>4;if(C<16)_[P++]=C;else{var z=0,U=0;for(C==16?(U=3+Oe(t,h,3),h+=2,z=_[P-1]):C==17?(U=3+Oe(t,h,7),h+=3):C==18&&(U=11+Oe(t,h,127),h+=7);U--;)_[P++]=z}}var Y=_.subarray(0,m),H=_.subarray(m);f=bi(Y),v=bi(H),p=Re(Y,f,1),g=Re(H,v,1)}else k(1);else{var C=ln(h)+4,w=t[C-4]|t[C-3]<<8,M=C+w;if(M>s){c&&k(0);break}a&&l(d+w),n.set(t.subarray(C,M),d),e.b=d+=w,e.p=h=M*8,e.f=u;continue}if(h>S){c&&k(0);break}}a&&l(d+131072);for(var be=(1<<f)-1,ae=(1<<v)-1,Me=h;;Me=h){var z=p[Mi(t,h)&be],ce=z>>4;if(h+=z&15,h>S){c&&k(0);break}if(z||k(2),ce<256)n[d++]=ce;else if(ce==256){Me=h,p=null;break}else{var le=ce-254;if(ce>264){var P=ce-257,W=an[P];le=Oe(t,h,(1<<W)-1)+$r[P],h+=W}var de=g[Mi(t,h)&ae],he=de>>4;de||k(3),h+=de&15;var H=Gl[he];if(he>3){var W=cn[he];H+=Mi(t,h)&(1<<W)-1,h+=W}if(h>S){c&&k(0);break}a&&l(d+131072);var Ie=d+le;if(d<H){var Te=r-H,Pe=Math.min(H,Ie);for(Te+d<0&&k(3);d<Pe;++d)n[d]=i[Te+d]}for(;d<Ie;++d)n[d]=n[d-H]}}e.l=p,e.p=Me,e.b=d,e.f=u,p&&(u=1,e.m=f,e.d=g,e.n=v)}while(!u);return d!=n.length&&o?De(n,0,d):n.subarray(0,d)},$e=function(t,e,n){n<<=e&7;var i=e/8|0;t[i]|=n,t[i+1]|=n>>8},zt=function(t,e,n){n<<=e&7;var i=e/8|0;t[i]|=n,t[i+1]|=n>>8,t[i+2]|=n>>16},Ti=function(t,e){for(var n=[],i=0;i<t.length;++i)t[i]&&n.push({s:i,f:t[i]});var s=n.length,r=n.slice();if(!s)return{t:ct,l:0};if(s==1){var o=new G(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(M,m){return M.f-m.f}),n.push({s:-1,f:25001});var a=n[0],c=n[1],l=0,u=1,h=2;for(n[0]={s:-1,f:a.f+c.f,l:a,r:c};u!=s-1;)a=n[n[l].f<n[h].f?l++:h++],c=n[l!=u&&n[l].f<n[h].f?l++:h++],n[u++]={s:-1,f:a.f+c.f,l:a,r:c};for(var d=r[0].s,i=1;i<s;++i)r[i].s>d&&(d=r[i].s);var p=new we(d+1),g=zi(n[u-1],p,0);if(g>e){var i=0,f=0,v=g-e,S=1<<v;for(r.sort(function(m,E){return p[E.s]-p[m.s]||m.f-E.f});i<s;++i){var I=r[i].s;if(p[I]>e)f+=S-(1<<g-p[I]),p[I]=e;else break}for(f>>=v;f>0;){var C=r[i].s;p[C]<e?f-=1<<e-p[C]++-1:++i}for(;i>=0&&f;--i){var w=r[i].s;p[w]==e&&(--p[w],++f)}g=e}return{t:new G(p),l:g}},zi=function(t,e,n){return t.s==-1?Math.max(zi(t.l,e,n+1),zi(t.r,e,n+1)):e[t.s]=n},Ws=function(t){for(var e=t.length;e&&!t[--e];);for(var n=new we(++e),i=0,s=t[0],r=1,o=function(c){n[i++]=c},a=1;a<=e;++a)if(t[a]==s&&a!=e)++r;else{if(!s&&r>2){for(;r>138;r-=138)o(32754);r>2&&(o(r>10?r-11<<5|28690:r-3<<5|12305),r=0)}else if(r>3){for(o(s),--r;r>6;r-=6)o(8304);r>2&&(o(r-3<<5|8208),r=0)}for(;r--;)o(s);r=1,s=t[a]}return{c:n.subarray(0,i),n:e}},$t=function(t,e){for(var n=0,i=0;i<e.length;++i)n+=t[i]*e[i];return n},Fr=function(t,e,n){var i=n.length,s=ln(e+2);t[s]=i&255,t[s+1]=i>>8,t[s+2]=t[s]^255,t[s+3]=t[s+1]^255;for(var r=0;r<i;++r)t[s+r+4]=n[r];return(s+4+i)*8},Zs=function(t,e,n,i,s,r,o,a,c,l,u){$e(e,u++,n),++s[256];for(var h=Ti(s,15),d=h.t,p=h.l,g=Ti(r,15),f=g.t,v=g.l,S=Ws(d),I=S.c,C=S.n,w=Ws(f),M=w.c,m=w.n,E=new we(19),y=0;y<I.length;++y)++E[I[y]&31];for(var y=0;y<M.length;++y)++E[M[y]&31];for(var _=Ti(E,7),T=_.t,P=_.l,A=19;A>4&&!T[Rn[A-1]];--A);var D=l+5<<3,x=$t(s,it)+$t(r,Jt)+o,F=$t(s,d)+$t(r,f)+o+14+3*A+$t(E,T)+2*E[16]+3*E[17]+7*E[18];if(c>=0&&D<=x&&D<=F)return Fr(e,u,t.subarray(c,c+l));var z,U,Y,H;if($e(e,u,1+(F<x)),u+=2,F<x){z=Re(d,p,0),U=d,Y=Re(f,v,0),H=f;var be=Re(T,P,0);$e(e,u,C-257),$e(e,u+5,m-1),$e(e,u+10,A-4),u+=14;for(var y=0;y<A;++y)$e(e,u+3*y,T[Rn[y]]);u+=3*A;for(var ae=[I,M],Me=0;Me<2;++Me)for(var ce=ae[Me],y=0;y<ce.length;++y){var le=ce[y]&31;$e(e,u,be[le]),u+=T[le],le>15&&($e(e,u,ce[y]>>5&127),u+=ce[y]>>12)}}else z=jl,U=it,Y=Yl,H=Jt;for(var y=0;y<a;++y){var W=i[y];if(W>255){var le=W>>18&31;zt(e,u,z[le+257]),u+=U[le+257],le>7&&($e(e,u,W>>23&31),u+=an[le]);var de=W&31;zt(e,u,Y[de]),u+=H[de],de>3&&(zt(e,u,W>>5&8191),u+=cn[de])}else zt(e,u,z[W]),u+=U[W]}return zt(e,u,z[256]),u+U[256]},Jl=new si([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),ct=new G(0),Wl=function(t,e,n,i,s,r){var o=r.z||t.length,a=new G(i+o+5*(1+Math.ceil(o/7e3))+s),c=a.subarray(i,a.length-s),l=r.l,u=(r.r||0)&7;if(e){u&&(c[0]=r.r>>3);for(var h=Jl[e-1],d=h>>13,p=h&8191,g=(1<<n)-1,f=r.p||new we(32768),v=r.h||new we(g+1),S=Math.ceil(n/3),I=2*S,C=function(mn){return(t[mn]^t[mn+1]<<S^t[mn+2]<<I)&g},w=new si(25e3),M=new we(288),m=new we(32),E=0,y=0,_=r.i||0,T=0,P=r.w||0,A=0;_+2<o;++_){var D=C(_),x=_&32767,F=v[D];if(f[x]=F,v[D]=x,P<=_){var z=o-_;if((E>7e3||T>24576)&&(z>423||!l)){u=Zs(t,c,0,w,M,m,y,T,A,_-A,u),T=E=y=0,A=_;for(var U=0;U<286;++U)M[U]=0;for(var U=0;U<30;++U)m[U]=0}var Y=2,H=0,be=p,ae=x-F&32767;if(z>2&&D==C(_-ae))for(var Me=Math.min(d,z)-1,ce=Math.min(32767,_),le=Math.min(258,z);ae<=ce&&--be&&x!=F;){if(t[_+Y]==t[_+Y-ae]){for(var W=0;W<le&&t[_+W]==t[_+W-ae];++W);if(W>Y){if(Y=W,H=ae,W>Me)break;for(var de=Math.min(ae,W-2),he=0,U=0;U<de;++U){var Ie=_-ae+U&32767,Te=f[Ie],Pe=Ie-Te&32767;Pe>he&&(he=Pe,F=Ie)}}}x=F,F=f[x],ae+=x-F&32767}if(H){w[T++]=268435456|Li[Y]<<18|Js[H];var Ae=Li[Y]&31,Je=Js[H]&31;y+=an[Ae]+cn[Je],++M[257+Ae],++m[Je],P=_+Y,++E}else w[T++]=t[_],++M[t[_]]}}for(_=Math.max(_,P);_<o;++_)w[T++]=t[_],++M[t[_]];u=Zs(t,c,l,w,M,m,y,T,A,_-A,u),l||(r.r=u&7|c[u/8|0]<<3,u-=7,r.h=v,r.p=f,r.i=_,r.w=P)}else{for(var _=r.w||0;_<o+l;_+=65535){var rt=_+65535;rt>=o&&(c[u/8|0]=l,rt=o),u=Fr(c,u+1,t.subarray(_,rt))}r.i=o}return De(a,0,i+ln(u)+s)},Zl=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,i=9;--i;)n=(n&1&&-306674912)^n>>>1;t[e]=n}return t}(),hn=function(){var t=-1;return{p:function(e){for(var n=t,i=0;i<e.length;++i)n=Zl[n&255^e[i]]^n>>>8;t=n},d:function(){return~t}}},hs=function(){var t=1,e=0;return{p:function(n){for(var i=t,s=e,r=n.length|0,o=0;o!=r;){for(var a=Math.min(o+2655,r);o<a;++o)s+=i+=n[o];i=(i&65535)+15*(i>>16),s=(s&65535)+15*(s>>16)}t=i,e=s},d:function(){return t%=65521,e%=65521,(t&255)<<24|(t&65280)<<8|(e&255)<<8|e>>8}}},At=function(t,e,n,i,s){if(!s&&(s={l:1},e.dictionary)){var r=e.dictionary.subarray(-32768),o=new G(r.length+t.length);o.set(r),o.set(t,r.length),t=o,s.w=r.length}return Wl(t,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):12+e.mem,n,i,s)},oi=function(t,e){var n={};for(var i in t)n[i]=t[i];for(var i in e)n[i]=e[i];return n},Ba=function(t,e,n){for(var i=t(),s=t.toString(),r=s.slice(s.indexOf("[")+1,s.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o<i.length;++o){var a=i[o],c=r[o];if(typeof a=="function"){e+=";"+c+"=";var l=a.toString();if(a.prototype)if(l.indexOf("[native code]")!=-1){var u=l.indexOf(" ",8)+1;e+=l.slice(u,l.indexOf("(",u))}else{e+=l;for(var h in a.prototype)e+=";"+c+".prototype."+h+"="+a.prototype[h].toString()}else e+=l}else n[c]=a}return e},mi=[],i0=function(t){var e=[];for(var n in t)t[n].buffer&&e.push((t[n]=new t[n].constructor(t[n])).buffer);return e},Ql=function(t,e,n,i){if(!mi[n]){for(var s="",r={},o=t.length-1,a=0;a<o;++a)s=Ba(t[a],s,r);mi[n]={c:Ba(t[o],s,r),e:r}}var c=oi({},mi[n].e);return(0,$l.default)(mi[n].c+";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage="+e.toString()+"}",n,c,i0(c),i)},un=function(){return[G,we,si,an,cn,Rn,$r,Gl,ql,Hl,Dn,Kl,Re,bi,Oe,Mi,ln,De,k,ri,gn,pt,Br]},dn=function(){return[G,we,si,an,cn,Rn,Li,Js,jl,it,Yl,Jt,Dn,Jl,ct,Re,$e,zt,Ti,zi,Ws,$t,Fr,Zs,ln,De,Wl,At,ai,pt]},Xl=function(){return[Vr,jr,J,hn,Zl]},eh=function(){return[Gr,ih]},th=function(){return[qr,J,hs]},nh=function(){return[Yr]},pt=function(t){return postMessage(t,[t.buffer])},Br=function(t){return t&&{out:t.size&&new G(t.size),dictionary:t.dictionary}},fn=function(t,e,n,i,s,r){var o=Ql(n,i,s,function(a,c){o.terminate(),r(a,c)});return o.postMessage([t,e],e.consume?[t.buffer]:[]),function(){o.terminate()}},ke=function(t){return t.ondata=function(e,n){return postMessage([e,n],[e.buffer])},function(e){return t.push(e.data[0],e.data[1])}},pn=function(t,e,n,i,s,r){var o,a=Ql(t,i,s,function(c,l){c?(a.terminate(),e.ondata.call(e,c)):Array.isArray(l)?(l[1]&&a.terminate(),e.ondata.call(e,c,l[0],l[1])):r(l)});a.postMessage(n),e.push=function(c,l){e.ondata||k(5),o&&e.ondata(k(4,0,1),null,!!l),a.postMessage([c,o=l],[c.buffer])},e.terminate=function(){a.terminate()}},ye=function(t,e){return t[e]|t[e+1]<<8},ie=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},_s=function(t,e){return ie(t,e)+ie(t,e+4)*4294967296},J=function(t,e,n){for(;n;++e)t[e]=n,n>>>=8},Vr=function(t,e){var n=e.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=e.level<2?4:e.level==9?2:0,t[9]=3,e.mtime!=0&&J(t,4,Math.floor(new Date(e.mtime||Date.now())/1e3)),n){t[3]=8;for(var i=0;i<=n.length;++i)t[i+10]=n.charCodeAt(i)}},Gr=function(t){(t[0]!=31||t[1]!=139||t[2]!=8)&&k(6,"invalid gzip data");var e=t[3],n=10;e&4&&(n+=(t[10]|t[11]<<8)+2);for(var i=(e>>3&1)+(e>>4&1);i>0;i-=!t[n++]);return n+(e&2)},ih=function(t){var e=t.length;return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0},jr=function(t){return 10+(t.filename?t.filename.length+1:0)},qr=function(t,e){var n=e.level,i=n==0?0:n<6?1:n==9?3:2;if(t[0]=120,t[1]=i<<6|(e.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,e.dictionary){var s=hs();s.p(e.dictionary),J(t,2,s.d())}},Yr=function(t,e){return((t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31)&&k(6,"invalid zlib data"),(t[1]>>5&1)==+!e&&k(6,"invalid zlib data: "+(t[1]&32?"need":"unexpected")+" dictionary"),(t[1]>>3&4)+2};function xt(t,e){return typeof t=="function"&&(e=t,t={}),this.ondata=e,t}var He=function(){function t(e,n){if(typeof e=="function"&&(n=e,e={}),this.ondata=n,this.o=e||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new G(98304),this.o.dictionary){var i=this.o.dictionary.subarray(-32768);this.b.set(i,32768-i.length),this.s.i=32768-i.length}}return t.prototype.p=function(e,n){this.ondata(At(e,this.o,0,0,this.s),n)},t.prototype.push=function(e,n){this.ondata||k(5),this.s.l&&k(4);var i=e.length+this.s.z;if(i>this.b.length){if(i>2*this.b.length-32768){var s=new G(i&-32768);s.set(this.b.subarray(0,this.s.z)),this.b=s}var r=this.b.length-this.s.z;r&&(this.b.set(e.subarray(0,r),this.s.z),this.s.z=this.b.length,this.p(this.b,!1)),this.b.set(this.b.subarray(-32768)),this.b.set(e.subarray(r),32768),this.s.z=e.length-r+32768,this.s.i=32766,this.s.w=32768}else this.b.set(e,this.s.z),this.s.z+=e.length;this.s.l=n&1,(this.s.z>this.s.w+8191||n)&&(this.p(this.b,n||!1),this.s.w=this.s.i,this.s.i-=2)},t}();$.Deflate=He;var sh=function(){function t(e,n){pn([dn,function(){return[ke,He]}],this,xt.call(this,e,n),function(i){var s=new He(i.data);onmessage=ke(s)},6)}return t}();$.AsyncDeflate=sh;function rh(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[dn],function(i){return pt(ai(i.data[0],i.data[1]))},0,n)}$.deflate=rh;function ai(t,e){return At(t,e||{},0,0)}$.deflateSync=ai;var _e=function(){function t(e,n){typeof e=="function"&&(n=e,e={}),this.ondata=n;var i=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:i?i.length:0},this.o=new G(32768),this.p=new G(0),i&&this.o.set(i)}return t.prototype.e=function(e){if(this.ondata||k(5),this.d&&k(4),!this.p.length)this.p=e;else if(e.length){var n=new G(this.p.length+e.length);n.set(this.p),n.set(e,this.p.length),this.p=n}},t.prototype.c=function(e){this.s.i=+(this.d=e||!1);var n=this.s.b,i=ri(this.p,this.s,this.o);this.ondata(De(i,n,this.s.b),this.d),this.o=De(i,this.s.b-32768),this.s.b=this.o.length,this.p=De(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(e,n){this.e(e),this.c(n)},t}();$.Inflate=_e;var Hr=function(){function t(e,n){pn([un,function(){return[ke,_e]}],this,xt.call(this,e,n),function(i){var s=new _e(i.data);onmessage=ke(s)},7)}return t}();$.AsyncInflate=Hr;function Kr(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[un],function(i){return pt(gn(i.data[0],Br(i.data[1])))},1,n)}$.inflate=Kr;function gn(t,e){return ri(t,{i:2},e&&e.out,e&&e.dictionary)}$.inflateSync=gn;var $i=function(){function t(e,n){this.c=hn(),this.l=0,this.v=1,He.call(this,e,n)}return t.prototype.push=function(e,n){this.c.p(e),this.l+=e.length,He.prototype.push.call(this,e,n)},t.prototype.p=function(e,n){var i=At(e,this.o,this.v&&jr(this.o),n&&8,this.s);this.v&&(Vr(i,this.o),this.v=0),n&&(J(i,i.length-8,this.c.d()),J(i,i.length-4,this.l)),this.ondata(i,n)},t}();$.Gzip=$i;$.Compress=$i;var oh=function(){function t(e,n){pn([dn,Xl,function(){return[ke,He,$i]}],this,xt.call(this,e,n),function(i){var s=new $i(i.data);onmessage=ke(s)},8)}return t}();$.AsyncGzip=oh;$.AsyncCompress=oh;function ah(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[dn,Xl,function(){return[Fi]}],function(i){return pt(Fi(i.data[0],i.data[1]))},2,n)}$.gzip=ah;$.compress=ah;function Fi(t,e){e||(e={});var n=hn(),i=t.length;n.p(t);var s=At(t,e,jr(e),8),r=s.length;return Vr(s,e),J(s,r-8,n.d()),J(s,r-4,i),s}$.gzipSync=Fi;$.compressSync=Fi;var Bi=function(){function t(e,n){this.v=1,this.r=0,_e.call(this,e,n)}return t.prototype.push=function(e,n){if(_e.prototype.e.call(this,e),this.r+=e.length,this.v){var i=this.p.subarray(this.v-1),s=i.length>3?Gr(i):4;if(s>i.length){if(!n)return}else this.v>1&&this.onmember&&this.onmember(this.r-i.length);this.p=i.subarray(s),this.v=0}_e.prototype.c.call(this,n),this.s.f&&!this.s.l&&(this.v=ln(this.s.p)+9,this.s={i:0},this.o=new G(0),this.p.length&&this.push(new G(0),n))},t}();$.Gunzip=Bi;var ch=function(){function t(e,n){var i=this;pn([un,eh,function(){return[ke,_e,Bi]}],this,xt.call(this,e,n),function(s){var r=new Bi(s.data);r.onmember=function(o){return postMessage(o)},onmessage=ke(r)},9,function(s){return i.onmember&&i.onmember(s)})}return t}();$.AsyncGunzip=ch;function lh(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[un,eh,function(){return[Vi]}],function(i){return pt(Vi(i.data[0],i.data[1]))},3,n)}$.gunzip=lh;function Vi(t,e){var n=Gr(t);return n+8>t.length&&k(6,"invalid gzip data"),ri(t.subarray(n,-8),{i:2},e&&e.out||new G(ih(t)),e&&e.dictionary)}$.gunzipSync=Vi;var Qs=function(){function t(e,n){this.c=hs(),this.v=1,He.call(this,e,n)}return t.prototype.push=function(e,n){this.c.p(e),He.prototype.push.call(this,e,n)},t.prototype.p=function(e,n){var i=At(e,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(qr(i,this.o),this.v=0),n&&J(i,i.length-4,this.c.d()),this.ondata(i,n)},t}();$.Zlib=Qs;var s0=function(){function t(e,n){pn([dn,th,function(){return[ke,He,Qs]}],this,xt.call(this,e,n),function(i){var s=new Qs(i.data);onmessage=ke(s)},10)}return t}();$.AsyncZlib=s0;function r0(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[dn,th,function(){return[Xs]}],function(i){return pt(Xs(i.data[0],i.data[1]))},4,n)}$.zlib=r0;function Xs(t,e){e||(e={});var n=hs();n.p(t);var i=At(t,e,e.dictionary?6:2,4);return qr(i,e),J(i,i.length-4,n.d()),i}$.zlibSync=Xs;var Gi=function(){function t(e,n){_e.call(this,e,n),this.v=e&&e.dictionary?2:1}return t.prototype.push=function(e,n){if(_e.prototype.e.call(this,e),this.v){if(this.p.length<6&&!n)return;this.p=this.p.subarray(Yr(this.p,this.v-1)),this.v=0}n&&(this.p.length<4&&k(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),_e.prototype.c.call(this,n)},t}();$.Unzlib=Gi;var hh=function(){function t(e,n){pn([un,nh,function(){return[ke,_e,Gi]}],this,xt.call(this,e,n),function(i){var s=new Gi(i.data);onmessage=ke(s)},11)}return t}();$.AsyncUnzlib=hh;function uh(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),fn(t,e,[un,nh,function(){return[ji]}],function(i){return pt(ji(i.data[0],Br(i.data[1])))},5,n)}$.unzlib=uh;function ji(t,e){return ri(t.subarray(Yr(t,e&&e.dictionary),-4),{i:2},e&&e.out,e&&e.dictionary)}$.unzlibSync=ji;var er=function(){function t(e,n){this.G=Bi,this.I=_e,this.Z=Gi,this.o=xt.call(this,e,n)||{}}return t.prototype.push=function(e,n){if(this.ondata||k(5),this.s)this.s.push(e,n);else{if(this.p&&this.p.length){var i=new G(this.p.length+e.length);i.set(this.p),i.set(e,this.p.length)}else this.p=e;if(this.p.length>2){var s=this,r=function(){s.ondata.apply(s,arguments)};this.s=this.p[0]==31&&this.p[1]==139&&this.p[2]==8?new this.G(this.o,r):(this.p[0]&15)!=8||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(this.o,r):new this.Z(this.o,r),this.s.push(this.p,n),this.p=null}}},t}();$.Decompress=er;var o0=function(){function t(e,n){this.G=ch,this.I=Hr,this.Z=hh,er.call(this,e,n)}return t.prototype.push=function(e,n){er.prototype.push.call(this,e,n)},t}();$.AsyncDecompress=o0;function a0(t,e,n){return n||(n=e,e={}),typeof n!="function"&&k(7),t[0]==31&&t[1]==139&&t[2]==8?lh(t,e,n):(t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31?Kr(t,e,n):uh(t,e,n)}$.decompress=a0;function c0(t,e){return t[0]==31&&t[1]==139&&t[2]==8?Vi(t,e):(t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31?gn(t,e):ji(t,e)}$.decompressSync=c0;var Jr=function(t,e,n,i){for(var s in t){var r=t[s],o=e+s,a=i;Array.isArray(r)&&(a=oi(i,r[1]),r=r[0]),r instanceof G?n[o]=[r,a]:(n[o+="/"]=[new G(0),a],Jr(r,o,n,i))}},Va=typeof TextEncoder<"u"&&new TextEncoder,tr=typeof TextDecoder<"u"&&new TextDecoder,dh=0;try{tr.decode(ct,{stream:!0}),dh=1}catch{}var fh=function(t){for(var e="",n=0;;){var i=t[n++],s=(i>127)+(i>223)+(i>239);if(n+s>t.length)return{s:e,r:De(t,n-1)};s?s==3?(i=((i&15)<<18|(t[n++]&63)<<12|(t[n++]&63)<<6|t[n++]&63)-65536,e+=String.fromCharCode(55296|i>>10,56320|i&1023)):s&1?e+=String.fromCharCode((i&31)<<6|t[n++]&63):e+=String.fromCharCode((i&15)<<12|(t[n++]&63)<<6|t[n++]&63):e+=String.fromCharCode(i)}},l0=function(){function t(e){this.ondata=e,dh?this.t=new TextDecoder:this.p=ct}return t.prototype.push=function(e,n){if(this.ondata||k(5),n=!!n,this.t){this.ondata(this.t.decode(e,{stream:!0}),n),n&&(this.t.decode().length&&k(8),this.t=null);return}this.p||k(4);var i=new G(this.p.length+e.length);i.set(this.p),i.set(e,this.p.length);var s=fh(i),r=s.s,o=s.r;n?(o.length&&k(8),this.p=null):this.p=o,this.ondata(r,n)},t}();$.DecodeUTF8=l0;var h0=function(){function t(e){this.ondata=e}return t.prototype.push=function(e,n){this.ondata||k(5),this.d&&k(4),this.ondata(dt(e),this.d=n||!1)},t}();$.EncodeUTF8=h0;function dt(t,e){if(e){for(var n=new G(t.length),i=0;i<t.length;++i)n[i]=t.charCodeAt(i);return n}if(Va)return Va.encode(t);for(var s=t.length,r=new G(t.length+(t.length>>1)),o=0,a=function(u){r[o++]=u},i=0;i<s;++i){if(o+5>r.length){var c=new G(o+8+(s-i<<1));c.set(r),r=c}var l=t.charCodeAt(i);l<128||e?a(l):l<2048?(a(192|l>>6),a(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|t.charCodeAt(++i)&1023,a(240|l>>18),a(128|l>>12&63),a(128|l>>6&63),a(128|l&63)):(a(224|l>>12),a(128|l>>6&63),a(128|l&63))}return De(r,0,o)}$.strToU8=dt;function Wr(t,e){if(e){for(var n="",i=0;i<t.length;i+=16384)n+=String.fromCharCode.apply(null,t.subarray(i,i+16384));return n}else{if(tr)return tr.decode(t);var s=fh(t),r=s.s,n=s.r;return n.length&&k(8),r}}$.strFromU8=Wr;var ph=function(t){return t==1?3:t<6?2:t==9?1:0},gh=function(t,e){return e+30+ye(t,e+26)+ye(t,e+28)},mh=function(t,e,n){var i=ye(t,e+28),s=Wr(t.subarray(e+46,e+46+i),!(ye(t,e+8)&2048)),r=e+46+i,o=ie(t,e+20),a=n&&o==4294967295?yh(t,r):[o,ie(t,e+24),ie(t,e+42)],c=a[0],l=a[1],u=a[2];return[ye(t,e+10),c,l,s,r+ye(t,e+30)+ye(t,e+32),u]},yh=function(t,e){for(;ye(t,e)!=1;e+=4+ye(t,e+2));return[_s(t,e+12),_s(t,e+4),_s(t,e+20)]},ht=function(t){var e=0;if(t)for(var n in t){var i=t[n].length;i>65535&&k(9),e+=i+4}return e},Wt=function(t,e,n,i,s,r,o,a){var c=i.length,l=n.extra,u=a&&a.length,h=ht(l);J(t,e,o!=null?33639248:67324752),e+=4,o!=null&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(r<0&&8),t[e++]=s&&8,t[e++]=n.compression&255,t[e++]=n.compression>>8;var d=new Date(n.mtime==null?Date.now():n.mtime),p=d.getFullYear()-1980;if((p<0||p>119)&&k(10),J(t,e,p<<25|d.getMonth()+1<<21|d.getDate()<<16|d.getHours()<<11|d.getMinutes()<<5|d.getSeconds()>>1),e+=4,r!=-1&&(J(t,e,n.crc),J(t,e+4,r<0?-r-2:r),J(t,e+8,n.size)),J(t,e+12,c),J(t,e+14,h),e+=16,o!=null&&(J(t,e,u),J(t,e+6,n.attrs),J(t,e+10,o),e+=14),t.set(i,e),e+=c,h)for(var g in l){var f=l[g],v=f.length;J(t,e,+g),J(t,e+2,v),t.set(f,e+4),e+=4+v}return u&&(t.set(a,e),e+=u),e},Zr=function(t,e,n,i,s){J(t,e,101010256),J(t,e+8,n),J(t,e+10,n),J(t,e+12,i),J(t,e+16,s)},kn=function(){function t(e){this.filename=e,this.c=hn(),this.size=0,this.compression=0}return t.prototype.process=function(e,n){this.ondata(null,e,n)},t.prototype.push=function(e,n){this.ondata||k(5),this.c.p(e),this.size+=e.length,n&&(this.crc=this.c.d()),this.process(e,n||!1)},t}();$.ZipPassThrough=kn;var u0=function(){function t(e,n){var i=this;n||(n={}),kn.call(this,e),this.d=new He(n,function(s,r){i.ondata(null,s,r)}),this.compression=8,this.flag=ph(n.level)}return t.prototype.process=function(e,n){try{this.d.push(e,n)}catch(i){this.ondata(i,null,n)}},t.prototype.push=function(e,n){kn.prototype.push.call(this,e,n)},t}();$.ZipDeflate=u0;var d0=function(){function t(e,n){var i=this;n||(n={}),kn.call(this,e),this.d=new sh(n,function(s,r,o){i.ondata(s,r,o)}),this.compression=8,this.flag=ph(n.level),this.terminate=this.d.terminate}return t.prototype.process=function(e,n){this.d.push(e,n)},t.prototype.push=function(e,n){kn.prototype.push.call(this,e,n)},t}();$.AsyncZipDeflate=d0;var f0=function(){function t(e){this.ondata=e,this.u=[],this.d=1}return t.prototype.add=function(e){var n=this;if(this.ondata||k(5),this.d&2)this.ondata(k(4+(this.d&1)*8,0,1),null,!1);else{var i=dt(e.filename),s=i.length,r=e.comment,o=r&&dt(r),a=s!=e.filename.length||o&&r.length!=o.length,c=s+ht(e.extra)+30;s>65535&&this.ondata(k(11,0,1),null,!1);var l=new G(c);Wt(l,0,e,i,a,-1);var u=[l],h=function(){for(var v=0,S=u;v<S.length;v++){var I=S[v];n.ondata(null,I,!1)}u=[]},d=this.d;this.d=0;var p=this.u.length,g=oi(e,{f:i,u:a,o,t:function(){e.terminate&&e.terminate()},r:function(){if(h(),d){var v=n.u[p+1];v?v.r():n.d=1}d=1}}),f=0;e.ondata=function(v,S,I){if(v)n.ondata(v,S,I),n.terminate();else if(f+=S.length,u.push(S),I){var C=new G(16);J(C,0,134695760),J(C,4,e.crc),J(C,8,f),J(C,12,e.size),u.push(C),g.c=f,g.b=c+f+16,g.crc=e.crc,g.size=e.size,d&&g.r(),d=1}else d&&h()},this.u.push(g)}},t.prototype.end=function(){var e=this;if(this.d&2){this.ondata(k(4+(this.d&1)*8,0,1),null,!0);return}this.d?this.e():this.u.push({r:function(){e.d&1&&(e.u.splice(-1,1),e.e())},t:function(){}}),this.d=3},t.prototype.e=function(){for(var e=0,n=0,i=0,s=0,r=this.u;s<r.length;s++){var o=r[s];i+=46+o.f.length+ht(o.extra)+(o.o?o.o.length:0)}for(var a=new G(i+22),c=0,l=this.u;c<l.length;c++){var o=l[c];Wt(a,e,o,o.f,o.u,-o.c-2,n,o.o),e+=46+o.f.length+ht(o.extra)+(o.o?o.o.length:0),n+=o.b}Zr(a,e,this.u.length,i,n),this.ondata(null,a,!0),this.d=2},t.prototype.terminate=function(){for(var e=0,n=this.u;e<n.length;e++){var i=n[e];i.t()}this.d=2},t}();$.Zip=f0;function p0(t,e,n){n||(n=e,e={}),typeof n!="function"&&k(7);var i={};Jr(t,"",i,e);var s=Object.keys(i),r=s.length,o=0,a=0,c=r,l=new Array(r),u=[],h=function(){for(var v=0;v<u.length;++v)u[v]()},d=function(v,S){qi(function(){n(v,S)})};qi(function(){d=n});var p=function(){var v=new G(a+22),S=o,I=a-o;a=0;for(var C=0;C<c;++C){var w=l[C];try{var M=w.c.length;Wt(v,a,w,w.f,w.u,M);var m=30+w.f.length+ht(w.extra),E=a+m;v.set(w.c,E),Wt(v,o,w,w.f,w.u,M,a,w.m),o+=16+m+(w.m?w.m.length:0),a=E+M}catch(y){return d(y,null)}}Zr(v,o,l.length,I,S),d(null,v)};r||p();for(var g=function(v){var S=s[v],I=i[S],C=I[0],w=I[1],M=hn(),m=C.length;M.p(C);var E=dt(S),y=E.length,_=w.comment,T=_&&dt(_),P=T&&T.length,A=ht(w.extra),D=w.level==0?0:8,x=function(F,z){if(F)h(),d(F,null);else{var U=z.length;l[v]=oi(w,{size:m,crc:M.d(),c:z,f:E,m:T,u:y!=S.length||T&&_.length!=P,compression:D}),o+=30+y+A+U,a+=76+2*(y+A)+(P||0)+U,--r||p()}};if(y>65535&&x(k(11,0,1),null),!D)x(null,C);else if(m<16e4)try{x(null,ai(C,w))}catch(F){x(F,null)}else u.push(rh(C,w,x))},f=0;f<c;++f)g(f);return h}$.zip=p0;function g0(t,e){e||(e={});var n={},i=[];Jr(t,"",n,e);var s=0,r=0;for(var o in n){var a=n[o],c=a[0],l=a[1],u=l.level==0?0:8,h=dt(o),d=h.length,p=l.comment,g=p&&dt(p),f=g&&g.length,v=ht(l.extra);d>65535&&k(11);var S=u?ai(c,l):c,I=S.length,C=hn();C.p(c),i.push(oi(l,{size:c.length,crc:C.d(),c:S,f:h,m:g,u:d!=o.length||g&&p.length!=f,o:s,compression:u})),s+=30+d+v+I,r+=76+2*(d+v)+(f||0)+I}for(var w=new G(r+22),M=s,m=r-s,E=0;E<i.length;++E){var h=i[E];Wt(w,h.o,h,h.f,h.u,h.c.length);var y=30+h.f.length+ht(h.extra);w.set(h.c,h.o+y),Wt(w,s,h,h.f,h.u,h.c.length,h.o,h.m),s+=16+y+(h.m?h.m.length:0)}return Zr(w,s,i.length,m,M),w}$.zipSync=g0;var vh=function(){function t(){}return t.prototype.push=function(e,n){this.ondata(null,e,n)},t.compression=0,t}();$.UnzipPassThrough=vh;var m0=function(){function t(){var e=this;this.i=new _e(function(n,i){e.ondata(null,n,i)})}return t.prototype.push=function(e,n){try{this.i.push(e,n)}catch(i){this.ondata(i,null,n)}},t.compression=8,t}();$.UnzipInflate=m0;var y0=function(){function t(e,n){var i=this;n<32e4?this.i=new _e(function(s,r){i.ondata(null,s,r)}):(this.i=new Hr(function(s,r,o){i.ondata(s,r,o)}),this.terminate=this.i.terminate)}return t.prototype.push=function(e,n){this.i.terminate&&(e=De(e,0)),this.i.push(e,n)},t.compression=8,t}();$.AsyncUnzipInflate=y0;var v0=function(){function t(e){this.onfile=e,this.k=[],this.o={0:vh},this.p=ct}return t.prototype.push=function(e,n){var i=this;if(this.onfile||k(5),this.p||k(4),this.c>0){var s=Math.min(this.c,e.length),r=e.subarray(0,s);if(this.c-=s,this.d?this.d.push(r,!this.c):this.k[0].push(r),e=e.subarray(s),e.length)return this.push(e,n)}else{var o=0,a=0,c=void 0,l=void 0;this.p.length?e.length?(l=new G(this.p.length+e.length),l.set(this.p),l.set(e,this.p.length)):l=this.p:l=e;for(var u=l.length,h=this.c,d=h&&this.d,p=function(){var S,I=ie(l,a);if(I==67324752){o=1,c=a,g.d=null,g.c=0;var C=ye(l,a+6),w=ye(l,a+8),M=C&2048,m=C&8,E=ye(l,a+26),y=ye(l,a+28);if(u>a+30+E+y){var _=[];g.k.unshift(_),o=2;var T=ie(l,a+18),P=ie(l,a+22),A=Wr(l.subarray(a+30,a+=30+E),!M);T==4294967295?(S=m?[-2]:yh(l,a),T=S[0],P=S[1]):m&&(T=-1),a+=y,g.c=T;var D,x={name:A,compression:w,start:function(){if(x.ondata||k(5),!T)x.ondata(null,ct,!0);else{var F=i.o[w];F||x.ondata(k(14,"unknown compression type "+w,1),null,!1),D=T<0?new F(A):new F(A,T,P),D.ondata=function(H,be,ae){x.ondata(H,be,ae)};for(var z=0,U=_;z<U.length;z++){var Y=U[z];D.push(Y,!1)}i.k[0]==_&&i.c?i.d=D:D.push(ct,!0)}},terminate:function(){D&&D.terminate&&D.terminate()}};T>=0&&(x.size=T,x.originalSize=P),g.onfile(x)}return"break"}else if(h){if(I==134695760)return c=a+=12+(h==-2&&8),o=3,g.c=0,"break";if(I==33639248)return c=a-=4,o=3,g.c=0,"break"}},g=this;a<u-4;++a){var f=p();if(f==="break")break}if(this.p=ct,h<0){var v=o?l.subarray(0,c-12-(h==-2&&8)-(ie(l,c-16)==134695760&&4)):l.subarray(0,a);d?d.push(v,!!o):this.k[+(o==2)].push(v)}if(o&2)return this.push(l.subarray(a),n);this.p=l.subarray(a)}n&&(this.c&&k(13),this.p=null)},t.prototype.register=function(e){this.o[e.compression]=e},t}();$.Unzip=v0;var qi=typeof queueMicrotask=="function"?queueMicrotask:typeof setTimeout=="function"?setTimeout:function(t){t()};function w0(t,e,n){n||(n=e,e={}),typeof n!="function"&&k(7);var i=[],s=function(){for(var v=0;v<i.length;++v)i[v]()},r={},o=function(v,S){qi(function(){n(v,S)})};qi(function(){o=n});for(var a=t.length-22;ie(t,a)!=101010256;--a)if(!a||t.length-a>65558)return o(k(13,0,1),null),s;var c=ye(t,a+8);if(c){var l=c,u=ie(t,a+16),h=u==4294967295||l==65535;if(h){var d=ie(t,a-12);h=ie(t,d)==101075792,h&&(l=c=ie(t,d+32),u=ie(t,d+48))}for(var p=e&&e.filter,g=function(v){var S=mh(t,u,h),I=S[0],C=S[1],w=S[2],M=S[3],m=S[4],E=S[5],y=gh(t,E);u=m;var _=function(P,A){P?(s(),o(P,null)):(A&&(r[M]=A),--c||o(null,r))};if(!p||p({name:M,size:C,originalSize:w,compression:I}))if(!I)_(null,De(t,y,y+C));else if(I==8){var T=t.subarray(y,y+C);if(C<32e4)try{_(null,gn(T,{out:new G(w)}))}catch(P){_(P,null)}else i.push(Kr(T,{size:w},_))}else _(k(14,"unknown compression type "+I,1),null);else _(null,null)},f=0;f<l;++f)g(f)}else o(null,{});return s}$.unzip=w0;function S0(t,e){for(var n={},i=t.length-22;ie(t,i)!=101010256;--i)(!i||t.length-i>65558)&&k(13);var s=ye(t,i+8);if(!s)return{};var r=ie(t,i+16),o=r==4294967295||s==65535;if(o){var a=ie(t,i-12);o=ie(t,a)==101075792,o&&(s=ie(t,a+32),r=ie(t,a+48))}for(var c=e&&e.filter,l=0;l<s;++l){var u=mh(t,r,o),h=u[0],d=u[1],p=u[2],g=u[3],f=u[4],v=u[5],S=gh(t,v);r=f,(!c||c({name:g,size:d,originalSize:p,compression:h}))&&(h?h==8?n[g]=gn(t.subarray(S,S+d),{out:new G(p)}):k(14,"unknown compression type "+h):n[g]=De(t,S,S+d))}return n}$.unzipSync=S0;var Zt={},Ct={},ci={};Object.defineProperty(ci,"__esModule",{value:!0});ci.NIFTIEXTENSION=void 0;class I0{constructor(e,n,i,s){b(this,"esize");b(this,"ecode");b(this,"edata");b(this,"littleEndian");if(e%16!=0)throw new Error("This does not appear to be a NIFTI extension");this.esize=e,this.ecode=n,this.edata=i,this.littleEndian=s}toArrayBuffer(){let e=new Uint8Array(this.esize),n=new Uint8Array(this.edata);e.set(n,8);let i=new DataView(e.buffer);return i.setInt32(0,this.esize,this.littleEndian),i.setInt32(4,this.ecode,this.littleEndian),e.buffer}}ci.NIFTIEXTENSION=I0;Object.defineProperty(Ct,"__esModule",{value:!0});Ct.Utils=void 0;const E0=ci,fe=class fe{static getStringAt(e,n,i){var s="",r,o;for(r=n;r<i;r+=1)o=e.getUint8(r),o!==0&&(s+=String.fromCharCode(o));return s}static getIntAt(e,n,i){return e.getInt32(n,i)}static getFloatAt(e,n,i){return e.getFloat32(n,i)}static getDoubleAt(e,n,i){return e.getFloat64(n,i)}static getLongAt(e,n,i){var s,r=[],o=0;for(s=0;s<8;s+=1)r[s]=fe.getByteAt(e,n+s);for(s=r.length-1;s>=0;s--)o=o*256+r[s];return o}static getExtensionsAt(e,n,i,s){let r=[],o=n;for(;o<s;){let a=i,c=fe.getIntAt(e,o,i);if(!c)break;if(c+o>s&&(a=!a,c=fe.getIntAt(e,o,a),c+o>s))throw new Error("This does not appear to be a valid NIFTI extension");if(c%16!=0)throw new Error("This does not appear to be a NIFTI extension");let l=fe.getIntAt(e,o+4,a),u=e.buffer.slice(o+8,o+c);console.log("extensionByteIndex: "+(o+8)+" esize: "+c),console.log(u);let h=new E0.NIFTIEXTENSION(c,l,u,a);r.push(h),o+=c}return r}static toArrayBuffer(e){var n,i,s;for(n=new ArrayBuffer(e.length),i=new Uint8Array(n),s=0;s<e.length;s+=1)i[s]=e[s];return n}static isString(e){return typeof e=="string"||e instanceof String}static formatNumber(e,n=void 0){let i;return fe.isString(e)?i=Number(e):i=e,n?i=i.toPrecision(5):i=i.toPrecision(7),parseFloat(i)}static makeCRCTable(){let e,n=[];for(var i=0;i<256;i++){e=i;for(var s=0;s<8;s++)e=e&1?3988292384^e>>>1:e>>>1;n[i]=e}return n}static crc32(e){fe.crcTable||(fe.crcTable=fe.makeCRCTable());const n=fe.crcTable;let i=-1;for(var s=0;s<e.byteLength;s++)i=i>>>8^n[(i^e.getUint8(s))&255];return(i^-1)>>>0}};b(fe,"crcTable",null),b(fe,"GUNZIP_MAGIC_COOKIE1",31),b(fe,"GUNZIP_MAGIC_COOKIE2",139),b(fe,"getByteAt",function(e,n){return e.getInt8(n)}),b(fe,"getShortAt",function(e,n,i){return e.getInt16(n,i)});let nr=fe;Ct.Utils=nr;Object.defineProperty(Zt,"__esModule",{value:!0});Zt.NIFTI1=void 0;const B=Ct,O=class O{constructor(){b(this,"littleEndian",!1);b(this,"dim_info",0);b(this,"dims",[]);b(this,"intent_p1",0);b(this,"intent_p2",0);b(this,"intent_p3",0);b(this,"intent_code",0);b(this,"datatypeCode",0);b(this,"numBitsPerVoxel",0);b(this,"slice_start",0);b(this,"slice_end",0);b(this,"slice_code",0);b(this,"pixDims",[]);b(this,"vox_offset",0);b(this,"scl_slope",1);b(this,"scl_inter",0);b(this,"xyzt_units",0);b(this,"cal_max",0);b(this,"cal_min",0);b(this,"slice_duration",0);b(this,"toffset",0);b(this,"description","");b(this,"aux_file","");b(this,"intent_name","");b(this,"qform_code",0);b(this,"sform_code",0);b(this,"quatern_a",0);b(this,"quatern_b",0);b(this,"quatern_c",0);b(this,"quatern_d",0);b(this,"qoffset_x",0);b(this,"qoffset_y",0);b(this,"qoffset_z",0);b(this,"affine",[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]);b(this,"qfac",1);b(this,"quatern_R");b(this,"magic","0");b(this,"isHDR",!1);b(this,"extensionFlag",[0,0,0,0]);b(this,"extensionSize",0);b(this,"extensionCode",0);b(this,"extensions",[]);b(this,"getDatatypeCodeString",function(e){return e===O.TYPE_UINT8?"1-Byte Unsigned Integer":e===O.TYPE_INT16?"2-Byte Signed Integer":e===O.TYPE_INT32?"4-Byte Signed Integer":e===O.TYPE_FLOAT32?"4-Byte Float":e===O.TYPE_FLOAT64?"8-Byte Float":e===O.TYPE_RGB24?"RGB":e===O.TYPE_INT8?"1-Byte Signed Integer":e===O.TYPE_UINT16?"2-Byte Unsigned Integer":e===O.TYPE_UINT32?"4-Byte Unsigned Integer":e===O.TYPE_INT64?"8-Byte Signed Integer":e===O.TYPE_UINT64?"8-Byte Unsigned Integer":"Unknown"});b(this,"getTransformCodeString",function(e){return e===O.XFORM_SCANNER_ANAT?"Scanner":e===O.XFORM_ALIGNED_ANAT?"Aligned":e===O.XFORM_TALAIRACH?"Talairach":e===O.XFORM_MNI_152?"MNI":"Unknown"});b(this,"getUnitsCodeString",function(e){return e===O.UNITS_METER?"Meters":e===O.UNITS_MM?"Millimeters":e===O.UNITS_MICRON?"Microns":e===O.UNITS_SEC?"Seconds":e===O.UNITS_MSEC?"Milliseconds":e===O.UNITS_USEC?"Microseconds":e===O.UNITS_HZ?"Hz":e===O.UNITS_PPM?"PPM":e===O.UNITS_RADS?"Rads":"Unknown"});b(this,"nifti_mat33_mul",function(e,n){var i=[[0,0,0],[0,0,0],[0,0,0]],s,r;for(s=0;s<3;s+=1)for(r=0;r<3;r+=1)i[s][r]=e[s][0]*n[0][r]+e[s][1]*n[1][r]+e[s][2]*n[2][r];return i});b(this,"nifti_mat33_determ",function(e){var n,i,s,r,o,a,c,l,u;return n=e[0][0],i=e[0][1],s=e[0][2],r=e[1][0],o=e[1][1],a=e[1][2],c=e[2][0],l=e[2][1],u=e[2][2],n*o*u-n*l*a-r*i*u+r*l*s+c*i*a-c*o*s})}readHeader(e){var n=new DataView(e),i=B.Utils.getIntAt(n,0,this.littleEndian),s,r,o,a;if(i!==O.MAGIC_COOKIE&&(this.littleEndian=!0,i=B.Utils.getIntAt(n,0,this.littleEndian)),i!==O.MAGIC_COOKIE)throw new Error("This does not appear to be a NIFTI file!");for(this.dim_info=B.Utils.getByteAt(n,39),s=0;s<8;s+=1)a=40+s*2,this.dims[s]=B.Utils.getShortAt(n,a,this.littleEndian);for(this.intent_p1=B.Utils.getFloatAt(n,56,this.littleEndian),this.intent_p2=B.Utils.getFloatAt(n,60,this.littleEndian),this.intent_p3=B.Utils.getFloatAt(n,64,this.littleEndian),this.intent_code=B.Utils.getShortAt(n,68,this.littleEndian),this.datatypeCode=B.Utils.getShortAt(n,70,this.littleEndian),this.numBitsPerVoxel=B.Utils.getShortAt(n,72,this.littleEndian),this.slice_start=B.Utils.getShortAt(n,74,this.littleEndian),s=0;s<8;s+=1)a=76+s*4,this.pixDims[s]=B.Utils.getFloatAt(n,a,this.littleEndian);if(this.vox_offset=B.Utils.getFloatAt(n,108,this.littleEndian),this.scl_slope=B.Utils.getFloatAt(n,112,this.littleEndian),this.scl_inter=B.Utils.getFloatAt(n,116,this.littleEndian),this.slice_end=B.Utils.getShortAt(n,120,this.littleEndian),this.slice_code=B.Utils.getByteAt(n,122),this.xyzt_units=B.Utils.getByteAt(n,123),this.cal_max=B.Utils.getFloatAt(n,124,this.littleEndian),this.cal_min=B.Utils.getFloatAt(n,128,this.littleEndian),this.slice_duration=B.Utils.getFloatAt(n,132,this.littleEndian),this.toffset=B.Utils.getFloatAt(n,136,this.littleEndian),this.description=B.Utils.getStringAt(n,148,228),this.aux_file=B.Utils.getStringAt(n,228,252),this.qform_code=B.Utils.getShortAt(n,252,this.littleEndian),this.sform_code=B.Utils.getShortAt(n,254,this.littleEndian),this.quatern_b=B.Utils.getFloatAt(n,256,this.littleEndian),this.quatern_c=B.Utils.getFloatAt(n,260,this.littleEndian),this.quatern_d=B.Utils.getFloatAt(n,264,this.littleEndian),this.quatern_a=Math.sqrt(1-(Math.pow(this.quatern_b,2)+Math.pow(this.quatern_c,2)+Math.pow(this.quatern_d,2))),this.qoffset_x=B.Utils.getFloatAt(n,268,this.littleEndian),this.qoffset_y=B.Utils.getFloatAt(n,272,this.littleEndian),this.qoffset_z=B.Utils.getFloatAt(n,276,this.littleEndian),this.qform_code<1&&this.sform_code<1&&(this.affine[0][0]=this.pixDims[1],this.affine[1][1]=this.pixDims[2],this.affine[2][2]=this.pixDims[3]),this.qform_code>0&&this.sform_code<this.qform_code){const c=this.quatern_a,l=this.quatern_b,u=this.quatern_c,h=this.quatern_d;for(this.qfac=this.pixDims[0]===0?1:this.pixDims[0],this.quatern_R=[[c*c+l*l-u*u-h*h,2*l*u-2*c*h,2*l*h+2*c*u],[2*l*u+2*c*h,c*c+u*u-l*l-h*h,2*u*h-2*c*l],[2*l*h-2*c*u,2*u*h+2*c*l,c*c+h*h-u*u-l*l]],r=0;r<3;r+=1)for(o=0;o<3;o+=1)this.affine[r][o]=this.quatern_R[r][o]*this.pixDims[o+1],o===2&&(this.affine[r][o]*=this.qfac);this.affine[0][3]=this.qoffset_x,this.affine[1][3]=this.qoffset_y,this.affine[2][3]=this.qoffset_z}else if(this.sform_code>0)for(r=0;r<3;r+=1)for(o=0;o<4;o+=1)a=280+(r*4+o)*4,this.affine[r][o]=B.Utils.getFloatAt(n,a,this.littleEndian);if(this.affine[3][0]=0,this.affine[3][1]=0,this.affine[3][2]=0,this.affine[3][3]=1,this.intent_name=B.Utils.getStringAt(n,328,344),this.magic=B.Utils.getStringAt(n,344,348),this.isHDR=this.magic===String.fromCharCode.apply(null,O.MAGIC_NUMBER2),n.byteLength>O.MAGIC_COOKIE){this.extensionFlag[0]=B.Utils.getByteAt(n,348),this.extensionFlag[1]=B.Utils.getByteAt(n,349),this.extensionFlag[2]=B.Utils.getByteAt(n,350),this.extensionFlag[3]=B.Utils.getByteAt(n,351);let c=!0;!this.isHDR&&this.vox_offset<=352&&(c=!1),n.byteLength<=368&&(c=!1),c&&this.extensionFlag[0]&&(this.extensions=B.Utils.getExtensionsAt(n,this.getExtensionLocation(),this.littleEndian,this.vox_offset),this.extensionSize=this.extensions[0].esize,this.extensionCode=this.extensions[0].ecode)}}toFormattedString(){var e=B.Utils.formatNumber,n="";return n+="Dim Info = "+this.dim_info+`
`,n+="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+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+`
`,n+="Intent Code = "+this.intent_code+`
`,n+="Datatype = "+this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+`)
`,n+="Bits Per Voxel = "+this.numBitsPerVoxel+`
`,n+="Slice Start = "+this.slice_start+`
`,n+="Voxel Dimensions (1-8): "+e(this.pixDims[0])+", "+e(this.pixDims[1])+", "+e(this.pixDims[2])+", "+e(this.pixDims[3])+", "+e(this.pixDims[4])+", "+e(this.pixDims[5])+", "+e(this.pixDims[6])+", "+e(this.pixDims[7])+`
`,n+="Image Offset = "+this.vox_offset+`
`,n+="Data Scale:  Slope = "+e(this.scl_slope)+"  Intercept = "+e(this.scl_inter)+`
`,n+="Slice End = "+this.slice_end+`
`,n+="Slice Code = "+this.slice_code+`
`,n+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(O.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(O.TEMPORAL_UNITS_MASK&this.xyzt_units)+`)
`,n+="Display Range:  Max = "+e(this.cal_max)+"  Min = "+e(this.cal_min)+`
`,n+="Slice Duration = "+this.slice_duration+`
`,n+="Time Axis Shift = "+this.toffset+`
`,n+='Description: "'+this.description+`"
`,n+='Auxiliary File: "'+this.aux_file+`"
`,n+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+`)
`,n+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+`)
`,n+="Quaternion Parameters:  b = "+e(this.quatern_b)+"  c = "+e(this.quatern_c)+"  d = "+e(this.quatern_d)+`
`,n+="Quaternion Offsets:  x = "+this.qoffset_x+"  y = "+this.qoffset_y+"  z = "+this.qoffset_z+`
`,n+="S-Form Parameters X: "+e(this.affine[0][0])+", "+e(this.affine[0][1])+", "+e(this.affine[0][2])+", "+e(this.affine[0][3])+`
`,n+="S-Form Parameters Y: "+e(this.affine[1][0])+", "+e(this.affine[1][1])+", "+e(this.affine[1][2])+", "+e(this.affine[1][3])+`
`,n+="S-Form Parameters Z: "+e(this.affine[2][0])+", "+e(this.affine[2][1])+", "+e(this.affine[2][2])+", "+e(this.affine[2][3])+`
`,n+='Intent Name: "'+this.intent_name+`"
`,this.extensionFlag[0]&&(n+="Extension: Size = "+this.extensionSize+"  Code = "+this.extensionCode+`
`),n}getQformMat(){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])}convertNiftiQFormToNiftiSForm(e,n,i,s,r,o,a,c,l,u){var h=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],d,p=e,g=n,f=i,v,S,I;return h[3][0]=h[3][1]=h[3][2]=0,h[3][3]=1,d=1-(p*p+g*g+f*f),d<1e-7?(d=1/Math.sqrt(p*p+g*g+f*f),p*=d,g*=d,f*=d,d=0):d=Math.sqrt(d),v=a>0?a:1,S=c>0?c:1,I=l>0?l:1,u<0&&(I=-I),h[0][0]=(d*d+p*p-g*g-f*f)*v,h[0][1]=2*(p*g-d*f)*S,h[0][2]=2*(p*f+d*g)*I,h[1][0]=2*(p*g+d*f)*v,h[1][1]=(d*d+g*g-p*p-f*f)*S,h[1][2]=2*(g*f-d*p)*I,h[2][0]=2*(p*f-d*g)*v,h[2][1]=2*(g*f+d*p)*S,h[2][2]=(d*d+f*f-g*g-p*p)*I,h[0][3]=s,h[1][3]=r,h[2][3]=o,h}convertNiftiSFormToNEMA(e){var n,i,s,r,o,a,c,l,u,h,d,p,g,f,v,S,I,C,w,M,m,E,y,_,T,P,A,D,x,F,z,U,Y,H;if(v=0,A=[[0,0,0],[0,0,0],[0,0,0]],D=[[0,0,0],[0,0,0],[0,0,0]],n=e[0][0],i=e[0][1],s=e[0][2],r=e[1][0],o=e[1][1],a=e[1][2],c=e[2][0],l=e[2][1],u=e[2][2],h=Math.sqrt(n*n+r*r+c*c),h===0||(n/=h,r/=h,c/=h,h=Math.sqrt(i*i+o*o+l*l),h===0))return null;if(i/=h,o/=h,l/=h,h=n*i+r*o+c*l,Math.abs(h)>1e-4){if(i-=h*n,o-=h*r,l-=h*c,h=Math.sqrt(i*i+o*o+l*l),h===0)return null;i/=h,o/=h,l/=h}if(h=Math.sqrt(s*s+a*a+u*u),h===0?(s=r*l-c*o,a=c*i-l*n,u=n*o-r*i):(s/=h,a/=h,u/=h),h=n*s+r*a+c*u,Math.abs(h)>1e-4){if(s-=h*n,a-=h*r,u-=h*c,h=Math.sqrt(s*s+a*a+u*u),h===0)return null;s/=h,a/=h,u/=h}if(h=i*s+o*a+l*u,Math.abs(h)>1e-4){if(s-=h*i,a-=h*o,u-=h*l,h=Math.sqrt(s*s+a*a+u*u),h===0)return null;s/=h,a/=h,u/=h}if(A[0][0]=n,A[0][1]=i,A[0][2]=s,A[1][0]=r,A[1][1]=o,A[1][2]=a,A[2][0]=c,A[2][1]=l,A[2][2]=u,d=this.nifti_mat33_determ(A),d===0)return null;for(P=-666,w=E=y=_=1,M=2,m=3,g=1;g<=3;g+=1)for(f=1;f<=3;f+=1)if(g!==f){for(v=1;v<=3;v+=1)if(!(g===v||f===v))for(D[0][0]=D[0][1]=D[0][2]=D[1][0]=D[1][1]=D[1][2]=D[2][0]=D[2][1]=D[2][2]=0,S=-1;S<=1;S+=2)for(I=-1;I<=1;I+=2)for(C=-1;C<=1;C+=2)D[0][g-1]=S,D[1][f-1]=I,D[2][v-1]=C,p=this.nifti_mat33_determ(D),p*d>0&&(T=this.nifti_mat33_mul(D,A),h=T[0][0]+T[1][1]+T[2][2],h>P&&(P=h,w=g,M=f,m=v,E=S,y=I,_=C))}switch(x=F=z=U=Y=H="",w*E){case 1:x="X",U="+";break;case-1:x="X",U="-";break;case 2:x="Y",U="+";break;case-2:x="Y",U="-";break;case 3:x="Z",U="+";break;case-3:x="Z",U="-";break}switch(M*y){case 1:F="X",Y="+";break;case-1:F="X",Y="-";break;case 2:F="Y",Y="+";break;case-2:F="Y",Y="-";break;case 3:F="Z",Y="+";break;case-3:F="Z",Y="-";break}switch(m*_){case 1:z="X",H="+";break;case-1:z="X",H="-";break;case 2:z="Y",H="+";break;case-2:z="Y",H="-";break;case 3:z="Z",H="+";break;case-3:z="Z",H="-";break}return x+F+z+U+Y+H}getExtensionLocation(){return O.MAGIC_COOKIE+4}getExtensionSize(e){return B.Utils.getIntAt(e,this.getExtensionLocation(),this.littleEndian)}getExtensionCode(e){return B.Utils.getIntAt(e,this.getExtensionLocation()+4,this.littleEndian)}addExtension(e,n=-1){n==-1?this.extensions.push(e):this.extensions.splice(n,0,e),this.vox_offset+=e.esize}removeExtension(e){let n=this.extensions[e];n&&(this.vox_offset-=n.esize),this.extensions.splice(e,1)}toArrayBuffer(e=!1){let s=352;if(e)for(let c of this.extensions)s+=c.esize;let r=new Uint8Array(s),o=new DataView(r.buffer);o.setInt32(0,348,this.littleEndian),o.setUint8(39,this.dim_info);for(let c=0;c<8;c++)o.setUint16(40+2*c,this.dims[c],this.littleEndian);o.setFloat32(56,this.intent_p1,this.littleEndian),o.setFloat32(60,this.intent_p2,this.littleEndian),o.setFloat32(64,this.intent_p3,this.littleEndian),o.setInt16(68,this.intent_code,this.littleEndian),o.setInt16(70,this.datatypeCode,this.littleEndian),o.setInt16(72,this.numBitsPerVoxel,this.littleEndian),o.setInt16(74,this.slice_start,this.littleEndian);for(let c=0;c<8;c++)o.setFloat32(76+4*c,this.pixDims[c],this.littleEndian);o.setFloat32(108,this.vox_offset,this.littleEndian),o.setFloat32(112,this.scl_slope,this.littleEndian),o.setFloat32(116,this.scl_inter,this.littleEndian),o.setInt16(120,this.slice_end,this.littleEndian),o.setUint8(122,this.slice_code),o.setUint8(123,this.xyzt_units),o.setFloat32(124,this.cal_max,this.littleEndian),o.setFloat32(128,this.cal_min,this.littleEndian),o.setFloat32(132,this.slice_duration,this.littleEndian),o.setFloat32(136,this.toffset,this.littleEndian),r.set(Buffer.from(this.description),148),r.set(Buffer.from(this.aux_file),228),o.setInt16(252,this.qform_code,this.littleEndian),o.setInt16(254,this.sform_code,this.littleEndian),o.setFloat32(256,this.quatern_b,this.littleEndian),o.setFloat32(260,this.quatern_c,this.littleEndian),o.setFloat32(264,this.quatern_d,this.littleEndian),o.setFloat32(268,this.qoffset_x,this.littleEndian),o.setFloat32(272,this.qoffset_y,this.littleEndian),o.setFloat32(276,this.qoffset_z,this.littleEndian);const a=this.affine.flat();for(let c=0;c<12;c++)o.setFloat32(280+4*c,a[c],this.littleEndian);if(r.set(Buffer.from(this.intent_name),328),r.set(Buffer.from(this.magic),344),e){r.set(Uint8Array.from([1,0,0,0]),348);let c=this.getExtensionLocation();for(const l of this.extensions)o.setInt32(c,l.esize,l.littleEndian),o.setInt32(c+4,l.ecode,l.littleEndian),r.set(new Uint8Array(l.edata),c+8),c+=l.esize}else r.set(new Uint8Array(4).fill(0),348);return r.buffer}};b(O,"TYPE_NONE",0),b(O,"TYPE_BINARY",1),b(O,"TYPE_UINT8",2),b(O,"TYPE_INT16",4),b(O,"TYPE_INT32",8),b(O,"TYPE_FLOAT32",16),b(O,"TYPE_COMPLEX64",32),b(O,"TYPE_FLOAT64",64),b(O,"TYPE_RGB24",128),b(O,"TYPE_INT8",256),b(O,"TYPE_UINT16",512),b(O,"TYPE_UINT32",768),b(O,"TYPE_INT64",1024),b(O,"TYPE_UINT64",1280),b(O,"TYPE_FLOAT128",1536),b(O,"TYPE_COMPLEX128",1792),b(O,"TYPE_COMPLEX256",2048),b(O,"XFORM_UNKNOWN",0),b(O,"XFORM_SCANNER_ANAT",1),b(O,"XFORM_ALIGNED_ANAT",2),b(O,"XFORM_TALAIRACH",3),b(O,"XFORM_MNI_152",4),b(O,"SPATIAL_UNITS_MASK",7),b(O,"TEMPORAL_UNITS_MASK",56),b(O,"UNITS_UNKNOWN",0),b(O,"UNITS_METER",1),b(O,"UNITS_MM",2),b(O,"UNITS_MICRON",3),b(O,"UNITS_SEC",8),b(O,"UNITS_MSEC",16),b(O,"UNITS_USEC",24),b(O,"UNITS_HZ",32),b(O,"UNITS_PPM",40),b(O,"UNITS_RADS",48),b(O,"MAGIC_COOKIE",348),b(O,"STANDARD_HEADER_SIZE",348),b(O,"MAGIC_NUMBER_LOCATION",344),b(O,"MAGIC_NUMBER",[110,43,49]),b(O,"MAGIC_NUMBER2",[110,105,49]),b(O,"EXTENSION_HEADER_SIZE",8);let ir=O;Zt.NIFTI1=ir;var Un={};Object.defineProperty(Un,"__esModule",{value:!0});Un.NIFTI2=void 0;const Ee=Zt,j=Ct,Fe=class Fe{constructor(){b(this,"littleEndian",!1);b(this,"dim_info",0);b(this,"dims",[]);b(this,"intent_p1",0);b(this,"intent_p2",0);b(this,"intent_p3",0);b(this,"intent_code",0);b(this,"datatypeCode",0);b(this,"numBitsPerVoxel",0);b(this,"slice_start",0);b(this,"slice_end",0);b(this,"slice_code",0);b(this,"pixDims",[]);b(this,"vox_offset",0);b(this,"scl_slope",1);b(this,"scl_inter",0);b(this,"xyzt_units",0);b(this,"cal_max",0);b(this,"cal_min",0);b(this,"slice_duration",0);b(this,"toffset",0);b(this,"description","");b(this,"aux_file","");b(this,"intent_name","");b(this,"qform_code",0);b(this,"sform_code",0);b(this,"quatern_b",0);b(this,"quatern_c",0);b(this,"quatern_d",0);b(this,"qoffset_x",0);b(this,"qoffset_y",0);b(this,"qoffset_z",0);b(this,"affine",[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]);b(this,"magic","0");b(this,"extensionFlag",[0,0,0,0]);b(this,"extensions",[]);b(this,"extensionSize",0);b(this,"extensionCode",0);b(this,"getExtensionLocation",function(){return Fe.MAGIC_COOKIE+4});b(this,"getExtensionSize",Ee.NIFTI1.prototype.getExtensionSize);b(this,"getExtensionCode",Ee.NIFTI1.prototype.getExtensionCode);b(this,"addExtension",Ee.NIFTI1.prototype.addExtension);b(this,"removeExtension",Ee.NIFTI1.prototype.removeExtension);b(this,"getDatatypeCodeString",Ee.NIFTI1.prototype.getDatatypeCodeString);b(this,"getTransformCodeString",Ee.NIFTI1.prototype.getTransformCodeString);b(this,"getUnitsCodeString",Ee.NIFTI1.prototype.getUnitsCodeString);b(this,"getQformMat",Ee.NIFTI1.prototype.getQformMat);b(this,"convertNiftiQFormToNiftiSForm",Ee.NIFTI1.prototype.convertNiftiQFormToNiftiSForm);b(this,"convertNiftiSFormToNEMA",Ee.NIFTI1.prototype.convertNiftiSFormToNEMA);b(this,"nifti_mat33_mul",Ee.NIFTI1.prototype.nifti_mat33_mul);b(this,"nifti_mat33_determ",Ee.NIFTI1.prototype.nifti_mat33_determ)}readHeader(e){var n=new DataView(e),i=j.Utils.getIntAt(n,0,this.littleEndian),s,r,o,a;if(i!==Fe.MAGIC_COOKIE&&(this.littleEndian=!0,i=j.Utils.getIntAt(n,0,this.littleEndian)),i!==Fe.MAGIC_COOKIE)throw new Error("This does not appear to be a NIFTI file!");for(this.magic=j.Utils.getStringAt(n,4,12),this.datatypeCode=j.Utils.getShortAt(n,12,this.littleEndian),this.numBitsPerVoxel=j.Utils.getShortAt(n,14,this.littleEndian),s=0;s<8;s+=1)a=16+s*8,this.dims[s]=j.Utils.getLongAt(n,a,this.littleEndian);for(this.intent_p1=j.Utils.getDoubleAt(n,80,this.littleEndian),this.intent_p2=j.Utils.getDoubleAt(n,88,this.littleEndian),this.intent_p3=j.Utils.getDoubleAt(n,96,this.littleEndian),s=0;s<8;s+=1)a=104+s*8,this.pixDims[s]=j.Utils.getDoubleAt(n,a,this.littleEndian);for(this.vox_offset=j.Utils.getLongAt(n,168,this.littleEndian),this.scl_slope=j.Utils.getDoubleAt(n,176,this.littleEndian),this.scl_inter=j.Utils.getDoubleAt(n,184,this.littleEndian),this.cal_max=j.Utils.getDoubleAt(n,192,this.littleEndian),this.cal_min=j.Utils.getDoubleAt(n,200,this.littleEndian),this.slice_duration=j.Utils.getDoubleAt(n,208,this.littleEndian),this.toffset=j.Utils.getDoubleAt(n,216,this.littleEndian),this.slice_start=j.Utils.getLongAt(n,224,this.littleEndian),this.slice_end=j.Utils.getLongAt(n,232,this.littleEndian),this.description=j.Utils.getStringAt(n,240,320),this.aux_file=j.Utils.getStringAt(n,320,344),this.qform_code=j.Utils.getIntAt(n,344,this.littleEndian),this.sform_code=j.Utils.getIntAt(n,348,this.littleEndian),this.quatern_b=j.Utils.getDoubleAt(n,352,this.littleEndian),this.quatern_c=j.Utils.getDoubleAt(n,360,this.littleEndian),this.quatern_d=j.Utils.getDoubleAt(n,368,this.littleEndian),this.qoffset_x=j.Utils.getDoubleAt(n,376,this.littleEndian),this.qoffset_y=j.Utils.getDoubleAt(n,384,this.littleEndian),this.qoffset_z=j.Utils.getDoubleAt(n,392,this.littleEndian),r=0;r<3;r+=1)for(o=0;o<4;o+=1)a=400+(r*4+o)*8,this.affine[r][o]=j.Utils.getDoubleAt(n,a,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=j.Utils.getIntAt(n,496,this.littleEndian),this.xyzt_units=j.Utils.getIntAt(n,500,this.littleEndian),this.intent_code=j.Utils.getIntAt(n,504,this.littleEndian),this.intent_name=j.Utils.getStringAt(n,508,524),this.dim_info=j.Utils.getByteAt(n,524),n.byteLength>Fe.MAGIC_COOKIE&&(this.extensionFlag[0]=j.Utils.getByteAt(n,540),this.extensionFlag[1]=j.Utils.getByteAt(n,541),this.extensionFlag[2]=j.Utils.getByteAt(n,542),this.extensionFlag[3]=j.Utils.getByteAt(n,543),this.extensionFlag[0]&&(this.extensions=j.Utils.getExtensionsAt(n,this.getExtensionLocation(),this.littleEndian,this.vox_offset),this.extensionSize=this.extensions[0].esize,this.extensionCode=this.extensions[0].ecode))}toFormattedString(){var e=j.Utils.formatNumber,n="";return n+="Datatype = "+ +this.datatypeCode+" ("+this.getDatatypeCodeString(this.datatypeCode)+`)
`,n+="Bits Per Voxel =  = "+this.numBitsPerVoxel+`
`,n+="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+="Intent Parameters (1-3): "+this.intent_p1+", "+this.intent_p2+", "+this.intent_p3+`
`,n+="Voxel Dimensions (1-8): "+e(this.pixDims[0])+", "+e(this.pixDims[1])+", "+e(this.pixDims[2])+", "+e(this.pixDims[3])+", "+e(this.pixDims[4])+", "+e(this.pixDims[5])+", "+e(this.pixDims[6])+", "+e(this.pixDims[7])+`
`,n+="Image Offset = "+this.vox_offset+`
`,n+="Data Scale:  Slope = "+e(this.scl_slope)+"  Intercept = "+e(this.scl_inter)+`
`,n+="Display Range:  Max = "+e(this.cal_max)+"  Min = "+e(this.cal_min)+`
`,n+="Slice Duration = "+this.slice_duration+`
`,n+="Time Axis Shift = "+this.toffset+`
`,n+="Slice Start = "+this.slice_start+`
`,n+="Slice End = "+this.slice_end+`
`,n+='Description: "'+this.description+`"
`,n+='Auxiliary File: "'+this.aux_file+`"
`,n+="Q-Form Code = "+this.qform_code+" ("+this.getTransformCodeString(this.qform_code)+`)
`,n+="S-Form Code = "+this.sform_code+" ("+this.getTransformCodeString(this.sform_code)+`)
`,n+="Quaternion Parameters:  b = "+e(this.quatern_b)+"  c = "+e(this.quatern_c)+"  d = "+e(this.quatern_d)+`
`,n+="Quaternion Offsets:  x = "+this.qoffset_x+"  y = "+this.qoffset_y+"  z = "+this.qoffset_z+`
`,n+="S-Form Parameters X: "+e(this.affine[0][0])+", "+e(this.affine[0][1])+", "+e(this.affine[0][2])+", "+e(this.affine[0][3])+`
`,n+="S-Form Parameters Y: "+e(this.affine[1][0])+", "+e(this.affine[1][1])+", "+e(this.affine[1][2])+", "+e(this.affine[1][3])+`
`,n+="S-Form Parameters Z: "+e(this.affine[2][0])+", "+e(this.affine[2][1])+", "+e(this.affine[2][2])+", "+e(this.affine[2][3])+`
`,n+="Slice Code = "+this.slice_code+`
`,n+="Units Code = "+this.xyzt_units+" ("+this.getUnitsCodeString(Ee.NIFTI1.SPATIAL_UNITS_MASK&this.xyzt_units)+", "+this.getUnitsCodeString(Ee.NIFTI1.TEMPORAL_UNITS_MASK&this.xyzt_units)+`)
`,n+="Intent Code = "+this.intent_code+`
`,n+='Intent Name: "'+this.intent_name+`"
`,n+="Dim Info = "+this.dim_info+`
`,n}toArrayBuffer(e=!1){let s=544;if(e)for(let c of this.extensions)s+=c.esize;let r=new Uint8Array(s),o=new DataView(r.buffer);o.setInt32(0,540,this.littleEndian),r.set(Buffer.from(this.magic),4),o.setInt16(12,this.datatypeCode,this.littleEndian),o.setInt16(14,this.numBitsPerVoxel,this.littleEndian);for(let c=0;c<8;c++)o.setBigInt64(16+8*c,BigInt(this.dims[c]),this.littleEndian);o.setFloat64(80,this.intent_p1,this.littleEndian),o.setFloat64(88,this.intent_p2,this.littleEndian),o.setFloat64(96,this.intent_p3,this.littleEndian);for(let c=0;c<8;c++)o.setFloat64(104+8*c,this.pixDims[c],this.littleEndian);o.setBigInt64(168,BigInt(this.vox_offset),this.littleEndian),o.setFloat64(176,this.scl_slope,this.littleEndian),o.setFloat64(184,this.scl_inter,this.littleEndian),o.setFloat64(192,this.cal_max,this.littleEndian),o.setFloat64(200,this.cal_min,this.littleEndian),o.setFloat64(208,this.slice_duration,this.littleEndian),o.setFloat64(216,this.toffset,this.littleEndian),o.setBigInt64(224,BigInt(this.slice_start),this.littleEndian),o.setBigInt64(232,BigInt(this.slice_end),this.littleEndian),r.set(Buffer.from(this.description),240),r.set(Buffer.from(this.aux_file),320),o.setInt32(344,this.qform_code,this.littleEndian),o.setInt32(348,this.sform_code,this.littleEndian),o.setFloat64(352,this.quatern_b,this.littleEndian),o.setFloat64(360,this.quatern_c,this.littleEndian),o.setFloat64(368,this.quatern_d,this.littleEndian),o.setFloat64(376,this.qoffset_x,this.littleEndian),o.setFloat64(384,this.qoffset_y,this.littleEndian),o.setFloat64(392,this.qoffset_z,this.littleEndian);const a=this.affine.flat();for(let c=0;c<12;c++)o.setFloat64(400+8*c,a[c],this.littleEndian);if(o.setInt32(496,this.slice_code,this.littleEndian),o.setInt32(500,this.xyzt_units,this.littleEndian),o.setInt32(504,this.intent_code,this.littleEndian),r.set(Buffer.from(this.intent_name),508),o.setUint8(524,this.dim_info),e){r.set(Uint8Array.from([1,0,0,0]),540);let c=this.getExtensionLocation();for(const l of this.extensions)o.setInt32(c,l.esize,l.littleEndian),o.setInt32(c+4,l.ecode,l.littleEndian),r.set(new Uint8Array(l.edata),c+8),c+=l.esize}else r.set(new Uint8Array(4).fill(0),540);return r.buffer}};b(Fe,"MAGIC_COOKIE",540),b(Fe,"MAGIC_NUMBER_LOCATION",4),b(Fe,"MAGIC_NUMBER",[110,43,50,0,13,10,26,10]),b(Fe,"MAGIC_NUMBER2",[110,105,50,0,13,10,26,10]);let sr=Fe;Un.NIFTI2=sr;(function(t){var e=Lt&&Lt.__createBinding||(Object.create?function(m,E,y,_){_===void 0&&(_=y);var T=Object.getOwnPropertyDescriptor(E,y);(!T||("get"in T?!E.__esModule:T.writable||T.configurable))&&(T={enumerable:!0,get:function(){return E[y]}}),Object.defineProperty(m,_,T)}:function(m,E,y,_){_===void 0&&(_=y),m[_]=E[y]}),n=Lt&&Lt.__setModuleDefault||(Object.create?function(m,E){Object.defineProperty(m,"default",{enumerable:!0,value:E})}:function(m,E){m.default=E}),i=Lt&&Lt.__importStar||function(m){if(m&&m.__esModule)return m;var E={};if(m!=null)for(var y in m)y!=="default"&&Object.prototype.hasOwnProperty.call(m,y)&&e(E,m,y);return n(E,m),E};Object.defineProperty(t,"__esModule",{value:!0}),t.readExtensionData=t.readExtension=t.readImage=t.hasExtension=t.readHeader=t.decompress=t.isCompressed=t.isNIFTI=t.isNIFTI2=t.isNIFTI1=t.NIFTIEXTENSION=t.Utils=t.NIFTI2=t.NIFTI1=void 0;const s=i($),r=Zt,o=Un,a=Ct;var c=Zt;Object.defineProperty(t,"NIFTI1",{enumerable:!0,get:function(){return c.NIFTI1}});var l=Un;Object.defineProperty(t,"NIFTI2",{enumerable:!0,get:function(){return l.NIFTI2}});var u=Ct;Object.defineProperty(t,"Utils",{enumerable:!0,get:function(){return u.Utils}});var h=ci;Object.defineProperty(t,"NIFTIEXTENSION",{enumerable:!0,get:function(){return h.NIFTIEXTENSION}});function d(m,E=!1){var y,_,T,P;return m.byteLength<r.NIFTI1.STANDARD_HEADER_SIZE?!1:(y=new DataView(m),y&&(_=y.getUint8(r.NIFTI1.MAGIC_NUMBER_LOCATION)),T=y.getUint8(r.NIFTI1.MAGIC_NUMBER_LOCATION+1),P=y.getUint8(r.NIFTI1.MAGIC_NUMBER_LOCATION+2),E&&_===r.NIFTI1.MAGIC_NUMBER2[0]&&T===r.NIFTI1.MAGIC_NUMBER2[1]&&P===r.NIFTI1.MAGIC_NUMBER2[2]?!0:_===r.NIFTI1.MAGIC_NUMBER[0]&&T===r.NIFTI1.MAGIC_NUMBER[1]&&P===r.NIFTI1.MAGIC_NUMBER[2])}t.isNIFTI1=d;function p(m,E=!1){var y,_,T,P;return m.byteLength<r.NIFTI1.STANDARD_HEADER_SIZE?!1:(y=new DataView(m),_=y.getUint8(o.NIFTI2.MAGIC_NUMBER_LOCATION),T=y.getUint8(o.NIFTI2.MAGIC_NUMBER_LOCATION+1),P=y.getUint8(o.NIFTI2.MAGIC_NUMBER_LOCATION+2),E&&_===o.NIFTI2.MAGIC_NUMBER2[0]&&T===o.NIFTI2.MAGIC_NUMBER2[1]&&P===o.NIFTI2.MAGIC_NUMBER2[2]?!0:_===o.NIFTI2.MAGIC_NUMBER[0]&&T===o.NIFTI2.MAGIC_NUMBER[1]&&P===o.NIFTI2.MAGIC_NUMBER[2])}t.isNIFTI2=p;function g(m,E=!1){return d(m,E)||p(m,E)}t.isNIFTI=g;function f(m){var E,y,_;return!!(m&&(E=new DataView(m),y=E.getUint8(0),_=E.getUint8(1),y===a.Utils.GUNZIP_MAGIC_COOKIE1||_===a.Utils.GUNZIP_MAGIC_COOKIE2))}t.isCompressed=f;function v(m){return s.decompressSync(new Uint8Array(m)).buffer}t.decompress=v;function S(m,E=!1){var y=null;return f(m)&&(m=v(m)),d(m,E)?y=new r.NIFTI1:p(m,E)&&(y=new o.NIFTI2),y?y.readHeader(m):console.error("That file does not appear to be NIFTI!"),y}t.readHeader=S;function I(m){return m.extensionFlag[0]!=0}t.hasExtension=I;function C(m,E){var y=m.vox_offset,_=1,T=1;m.dims[4]&&(_=m.dims[4]),m.dims[5]&&(T=m.dims[5]);var P=m.dims[1]*m.dims[2]*m.dims[3]*_*T*(m.numBitsPerVoxel/8);return E.slice(y,y+P)}t.readImage=C;function w(m,E){var y=m.getExtensionLocation(),_=m.extensionSize;return E.slice(y,y+_)}t.readExtension=w;function M(m,E){var y=m.getExtensionLocation(),_=m.extensionSize;return E.slice(y+8,y+_)}t.readExtensionData=M})(Ce);/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const C0="nifti/getNiftiVolumeInfo",ao=class ao{};ao.RPC_ID="nifti/VolumeChunkSource";let rr=ao;var _0=Object.defineProperty,b0=Object.getOwnPropertyDescriptor,M0=(t,e,n,i)=>{for(var s=i>1?void 0:i?b0(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&_0(e,n,s),s};class T0{}async function P0(t,e){Ce.isCompressed(t)&&(t=(await se(Tt,e,[t],new Uint8Array(t))).buffer);const n=new T0;n.uncompressedData=t;const i=Ce.readHeader(t);if(i===null)throw new Error("Failed to parse NIFTI header.");return n.header=i,{data:n,size:t.byteLength}}function wh(t,e,n,i,s){return lt.getUrl(t,e,P0,n,i,s)}const A0=1e3;async function x0(t,e,n,i){return(await wh(t,e,n,()=>({priorityTier:q.VISIBLE,priority:A0}),i)).header}function N0(t){return Nu(t[0][0],t[1][0],t[2][0],t[3][0],t[0][1],t[1][1],t[2][1],t[3][1],t[0][2],t[1][2],t[2][2],t[3][2],t[0][3],t[1][3],t[2][3],t[3][3])}var Sh=(t=>(t[t.NONE=0]="NONE",t[t.BINARY=1]="BINARY",t[t.UINT8=2]="UINT8",t[t.INT16=4]="INT16",t[t.INT32=8]="INT32",t[t.FLOAT32=16]="FLOAT32",t[t.COMPLEX64=32]="COMPLEX64",t[t.FLOAT64=64]="FLOAT64",t[t.RGB24=128]="RGB24",t[t.INT8=256]="INT8",t[t.UINT16=512]="UINT16",t[t.UINT32=768]="UINT32",t[t.INT64=1024]="INT64",t[t.UINT64=1280]="UINT64",t[t.FLOAT128=1536]="FLOAT128",t[t.COMPLEX128=1792]="COMPLEX128",t[t.COMPLEX256=2048]="COMPLEX256",t))(Sh||{});const O0=new Map([[256,{dataType:V.INT8}],[2,{dataType:V.UINT8}],[4,{dataType:V.INT16}],[512,{dataType:V.UINT16}],[8,{dataType:V.INT32}],[768,{dataType:V.UINT32}],[1024,{dataType:V.UINT64}],[1280,{dataType:V.UINT64}],[16,{dataType:V.FLOAT32}]]);Ji(C0,async function(t,e){const n=this.getRef(t.chunkManager),i=this.getOptionalRef(t.credentialsProvider);try{const s=await x0(n,i,t.url,e),r=O0.get(s.datatypeCode);if(r===void 0)throw new Error(`Unsupported data type: ${Sh[s.datatypeCode]||s.datatypeCode}.`);let o=1,a="";switch(s.xyzt_units&Ce.NIFTI1.SPATIAL_UNITS_MASK){case Ce.NIFTI1.UNITS_METER:o=1,a="m";break;case Ce.NIFTI1.UNITS_MM:o=1e3,a="m";break;case Ce.NIFTI1.UNITS_MICRON:o=1e6,a="m";break}let c="",l=1;switch(s.xyzt_units&Ce.NIFTI1.TEMPORAL_UNITS_MASK){case Ce.NIFTI1.UNITS_SEC:c="s",l=1;break;case Ce.NIFTI1.UNITS_MSEC:c="s",l=1e3;break;case Ce.NIFTI1.UNITS_USEC:c="s",l=1e6;break;case Ce.NIFTI1.UNITS_HZ:c="Hz",l=1;break;case Ce.NIFTI1.UNITS_RADS:c="rad/s",l=1;break}let u=[a,a,a,c,"","",""],h=Float64Array.of(s.pixDims[1]/o,s.pixDims[2]/o,s.pixDims[3]/o,s.pixDims[4]/l,s.pixDims[5],s.pixDims[6],s.pixDims[7]),d=Float64Array.of(1/o,1/o,1/o,1/l,1,1,1),p=["i","j","k","m","c^","c1^","c2^"],g=["x","y","z","t","c^","c1^","c2^"];const f=s.dims[0];p=p.slice(0,f),g=g.slice(0,f),u=u.slice(0,f),h=h.slice(0,f),d=d.slice(0,f);const{quatern_b:v,quatern_c:S,quatern_d:I}=s,C=Math.sqrt(1-v*v-S*S-I*I),w=s.pixDims[0]===-1?-1:1,M=ve(s.qoffset_x,s.qoffset_y,s.qoffset_z),m=N0(s.affine),E=Ku(_t(),M,Vu(v,S,I,C),ju,w),y=kd(Float64Array,f+1),_=Math.min(3,f);for(let P=0;P<_;++P){for(let A=0;A<_;++A)y[A*(f+1)+P]=E[A*4+P];y[f*(f+1)+P]=E[12+P]}return{value:{rank:f,sourceNames:p,viewNames:g,units:u,sourceScales:h,viewScales:d,description:s.description,transform:y,dataType:r.dataType,volumeSize:Uint32Array.from(s.dims.slice(1,1+f))}}}finally{n.dispose(),i==null||i.dispose()}});let Ga=class extends re(ue()(ze),rr){async download(t,e){t.chunkDataSize=this.spec.chunkDataSize;const n=await wh(this.chunkManager,this.credentialsProvider,this.parameters.url,()=>({priorityTier:t.priorityTier,priority:t.priority}),e),i=Ce.readImage(n.header,n.uncompressedData);await ft(t,e,i,n.header.littleEndian?te.LITTLE:te.BIG)}};Ga=M0([L()],Ga);const R0=Ke("parseOBJFromArrayBuffer");/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const D0="single_mesh/SingleMeshLayer",k0="single_mesh/getSingleMeshInfo",U0="";class L0{}const co=class co extends L0{};co.RPC_ID="single_mesh/SingleMeshSource";let or=co;var z0=Object.defineProperty,$0=Object.getOwnPropertyDescriptor,Ih=(t,e,n,i)=>{for(var s=i>1?void 0:i?$0(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&z0(e,n,s),s};const F0=50;class B0 extends ne{constructor(){super(...arguments),this.data=null}freeSystemMemory(){this.data=null}serialize(e,n){super.serialize(e,n);const{vertexPositions:i,indices:s,vertexNormals:r,vertexAttributes:o}=this.data;e.vertexPositions=i,e.indices=s,e.vertexNormals=r,e.vertexAttributes=o;const a=new Set;a.add(i.buffer),a.add(s.buffer),a.add(r.buffer);for(const c of o)a.add(c.buffer);n.push(...a),this.data=null}downloadSucceeded(){const{vertexPositions:e,indices:n,vertexNormals:i,vertexAttributes:s}=this.data;let r=this.gpuMemoryBytes=e.byteLength+n.byteLength+i.byteLength;for(const o of s)r+=o.byteLength;this.systemMemoryBytes=this.gpuMemoryBytes=r,super.downloadSucceeded()}}const Eh=new Map;function Ch(t,e){Eh.set(t,e)}const V0=/^(?:([a-zA-Z-+_]+):\/\/)?(.*)$/;function G0(t,e){const n=e.match(V0);if(n===null||n[1]===void 0)throw new Error('Data source URL must have the form "<protocol>://<path>".');const i=n[1],s=t.get(i);if(s===void 0)throw new Error(`Unsupported data source: ${JSON.stringify(i)}.`);return[s,n[2],i]}function j0(t,e,n,i,s){const[r,o]=G0(Eh,n);return r.getMesh(t,e,o,i,s)}function _h(t,e,n,i,s){return j0(t,e,n.meshSourceUrl,i,s)}let ja=class extends re(ue()(Le),or){getChunk(){const t=U0;let e=this.chunks.get(t);return e===void 0&&(e=this.getNewChunk_(B0),e.initialize(t),this.addChunk(e)),e}download(t,e){const n=()=>({priorityTier:t.priorityTier,priority:t.priority});return _h(this.chunkManager,this.credentialsProvider,this.parameters,n,e).then(i=>{if(Be(i.info)!==Be(this.parameters.info))throw new Error("Mesh info has changed.");i.vertexNormals===void 0&&(i.vertexNormals=hl(i.vertexPositions,i.indices)),t.data=i})}};ja=Ih([L()],ja);const q0=bt(st(xe));let qa=class extends q0{constructor(t,e){super(t,e),this.source=this.registerDisposer(t.getRef(e.source)),this.registerDisposer(this.chunkManager.recomputeChunkPriorities.add(()=>{this.updateChunkPriorities()}))}updateChunkPriorities(){const t=this.visibility.value;if(t===Number.NEGATIVE_INFINITY)return;const e=je(t),n=qe(t),{source:i,chunkManager:s}=this,r=i.getChunk();s.requestChunk(r,e,n+F0)}};qa=Ih([L(D0)],qa);const Y0=1e3;Ji(k0,async function(t,e){const n=this.getRef(t.chunkManager),i=this.getOptionalRef(t.credentialsProvider);try{const s=t.parameters;return{value:(await _h(n,i,s,()=>({priorityTier:q.VISIBLE,priority:Y0}),e)).info}}finally{n.dispose(),i==null||i.dispose()}});function H0(t,e){return se(R0,e,[t],t)}Ch("obj",{description:"OBJ",getMesh:(t,e,n,i,s)=>lt.getUrl(t,e,H0,n,i,s)});/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var li=(t=>(t[t.JPEG=0]="JPEG",t[t.NPZ=1]="NPZ",t[t.RAW=2]="RAW",t))(li||{});class Qr{}var ei;let K0=(ei=class extends Qr{},ei.RPC_ID="python/VolumeChunkSource",ei);const lo=class lo extends Qr{};lo.RPC_ID="python/MeshSource";let ar=lo;const ho=class ho extends Qr{};ho.RPC_ID="python/SkeletonSource";let cr=ho;async function J0(t,e,n){const i=ml(await se(Tt,e,[n],new Uint8Array(n))),s=t.chunkDataSize,r=t.source,{shape:o}=i;if(!mt(o,s))throw new Error(`Shape ${JSON.stringify(o)} does not match chunkDataSize ${s.join()}`);const a=i.dataType,{spec:c}=r;if(a!==c.dataType)throw new Error(`Data type ${V[a]} does not match expected data type ${V[c.dataType]}`);await tn(t,e,i.data)}var W0=Object.defineProperty,Z0=Object.getOwnPropertyDescriptor,Xr=(t,e,n,i)=>{for(var s=i>1?void 0:i?Z0(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&W0(e,n,s),s};const us=new Map;us.set(li.NPZ,J0);us.set(li.JPEG,ii);us.set(li.RAW,ft);let Ya=class extends re(ze,K0){constructor(){super(...arguments),this.chunkDecoder=us.get(this.parameters.encoding),this.encoding=li[this.parameters.encoding].toLowerCase()}async download(t,e){const{parameters:n}=this;let i=`../../neuroglancer/${this.encoding}/${n.key}/${n.scaleKey}`;{const r=this.computeChunkBounds(t),o=t.chunkDataSize,a=r.length;i+=`/${r.join()}/`;for(let c=0;c<a;++c)c!==0&&(i+=","),i+=(r[c]+o[c]).toString()}const s=await Ye(new URL(i,n.baseUrl).href,{},oe,e);await this.chunkDecoder(t,e,s)}};Ya=Xr([L()],Ya);function Q0(t,e){const i=new DataView(e).getUint32(0,!0);en(t,as(e,te.LITTLE,4,i))}let Ha=class extends re(Xt,ar){download(t){return t.fragmentIds=[""],Promise.resolve(void 0)}downloadFragment(t,e){const{parameters:n}=this,i=`../../neuroglancer/mesh/${n.key}/${t.manifestChunk.objectId}`;return Ye(new URL(i,n.baseUrl).href,{},oe,e).then(s=>Q0(t,s))}};Ha=Xr([L()],Ha);let Ka=class extends re(cs,cr){download(t,e){const{parameters:n}=this,i=`../../neuroglancer/skeleton/${n.key}/${t.objectId}`;return Ye(new URL(i,n.baseUrl).href,{},oe,e).then(s=>Dl(t,s,n.vertexAttributes))}};Ka=Xr([L()],Ka);/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class X0{}class ey extends X0{}const uo=class uo extends ey{};uo.RPC_ID="render/TileChunkSource";let lr=uo;var ty=Object.defineProperty,ny=Object.getOwnPropertyDescriptor,iy=(t,e,n,i)=>{for(var s=i>1?void 0:i?ny(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&ty(e,n,s),s};const eo=new Map;eo.set("jpg",async(t,e,n)=>{const i=t.chunkDataSize,{uint8Array:s}=await se(Tr,e,[n],new Uint8Array(n),i[0],i[1]*i[2],3,!0);await tn(t,e,s)});eo.set("raw16",(t,e,n)=>ft(t,e,n,te.BIG));let Ja=class extends re(ze,lr){constructor(){super(...arguments),this.chunkDecoder=eo.get(this.parameters.encoding),this.queryString=(()=>{const{parameters:t}=this,e=[];return t.channel!==void 0&&e.push("channels="+t.channel),t.minIntensity!==void 0&&e.push(`minIntensity=${JSON.stringify(t.minIntensity)}`),t.maxIntensity!==void 0&&e.push(`maxIntensity=${JSON.stringify(t.maxIntensity)}`),t.maxTileSpecsToRender!==void 0&&e.push(`maxTileSpecsToRender=${JSON.stringify(t.maxTileSpecsToRender)}`),t.filter!==void 0&&e.push(`filter=${JSON.stringify(t.filter)}`),e.join("&")})()}async download(t,e){const{parameters:n}=this,{chunkGridPosition:i}=t,s=1/2**n.level;t.chunkDataSize=this.spec.chunkDataSize;const r=t.chunkDataSize[0]*2**n.level,o=t.chunkDataSize[1]*2**n.level,a=Q();a[0]=i[0]*r,a[1]=i[1]*o,a[2]=i[2];let c;n.encoding==="raw16"?c="raw16-image":c="jpeg-image";const l=`/render-ws/v1/owner/${n.owner}/project/${n.project}/stack/${n.stack}/z/${a[2]}/box/${a[0]},${a[1]},${r},${o},${s}/${c}`,u=await Ye(`${n.baseUrl}${l}?${this.queryString}`,{},oe,e);await this.chunkDecoder(t,e,u)}};Ja=iy([L()],Ja);const sy=Ke("parseVTKFromArrayBuffer");function ry(t,e){return se(sy,e,[t],t)}Ch("vtk",{description:"VTK",getMesh:(t,e,n,i,s)=>lt.getUrl(t,e,ry,n,i,s).then(r=>{const o={info:{numTriangles:r.numTriangles,numVertices:r.numVertices,vertexAttributes:[]},indices:r.indices,vertexPositions:r.vertexPositions,vertexAttributes:[]};for(const a of r.vertexAttributes)o.info.vertexAttributes.push({name:a.name,dataType:V.FLOAT32,numComponents:a.numComponents}),o.vertexAttributes.push(a.data);return o})});/**
 * @license
 * Copyright 2023 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var Z=(t=>(t[t.arrayToArray=0]="arrayToArray",t[t.arrayToBytes=1]="arrayToBytes",t[t.bytesToBytes=2]="bytesToBytes",t))(Z||{});const Yt={[Z.arrayToArray]:new Map,[Z.arrayToBytes]:new Map,[Z.bytesToBytes]:new Map,sharding:new Map};function Nt(t){t.kind===Z.arrayToBytes&&"getShardedKvStore"in t?Yt.sharding.set(t.name,t):Yt[t.kind].set(t.name,t)}async function bh(t,e,n){const i=t[Z.bytesToBytes];for(let o=i.length;o--;){const a=i[o],c=Yt[Z.bytesToBytes].get(a.name);if(c===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(a.name)}`);e=await c.decode(a.configuration,e,n)}let s;{const o=t[Z.arrayToBytes],a=Yt[Z.arrayToBytes].get(o.name);if(a===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(o.name)}`);s=await a.decode(o.configuration,t.arrayInfo[t.arrayInfo.length-1],e,n)}const r=t[Z.arrayToArray];for(let o=r.length;o--;){const a=r[o],c=Yt[Z.arrayToArray].get(a.name);if(c===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(a.name)}`);s=await c.decode(a.configuration,t.arrayInfo[o],s,n)}return s}function oy(t,e,n){let i=n,s=e;for(;;){const{shardingInfo:a}=s;if(a===void 0)break;const c=s[Z.arrayToBytes],l=Yt.sharding.get(c.name);if(l===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(c.name)}`);i=l.getShardedKvStore(c.configuration,t,i),s=a.subChunkCodecs}const r=s;function o(a,c){let l=c;const u=a.length;let h=e;for(;h.shardingInfo!==void 0;){const d=e.layoutInfo[e.layoutInfo.length-1],{physicalToLogicalDimension:p,readChunkShape:g}=d,{subChunkShape:f,subChunkGridShape:v,subChunkCodecs:S}=h.shardingInfo,I=new Array(u);for(let C=0;C<u;++C){const w=p[u-1-C];I[w]=Math.floor(a[C]*g[w]/f[w])%v[w]}l={base:l,subChunk:I},h=S}return l}return{kvStore:i,getChunkKey:o,decodeCodecs:r}}Nt({name:"blosc",kind:Z.bytesToBytes,decode(t,e,n){return se(Ll,n,[e.buffer],e)}});Nt({name:"zstd",kind:Z.bytesToBytes,decode(t,e,n){return se(zl,n,[e.buffer],e)}});Nt({name:"bytes",kind:Z.arrayToBytes,async decode(t,e,n,i){const{dataType:s,chunkShape:r}=e,o=r.reduce((u,h)=>u*h,1),a=Qt[s],c=o*a;if(n.byteLength!==c)throw new Error(`Raw-format chunk is ${n.byteLength} bytes, but ${o} * ${a} = ${c} bytes are expected.`);const l=Tc(s,n.buffer,n.byteOffset,n.byteLength);return _r(l,t.endian,a),l}});const bs=4;Nt({name:"crc32c",kind:Z.bytesToBytes,async decode(t,e,n){if(e.length<bs)throw new Error(`Expected buffer of size at least ${bs} bytes but received: ${e.length} bytes`);return e.subarray(0,e.length-bs)}});/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */const fo=class fo{};fo.RPC_ID="zarr/VolumeChunkSource";let hr=fo;Nt({name:"gzip",kind:Z.bytesToBytes,decode(t,e,n){return se(Tt,n,[e.buffer],e)}});function ay(t,e,n){Ge(t);const i=X(t,"name",r=>e(Ft(r))),s=X(t,"configuration",r=>(r===void 0?r={}:Ge(r),n(r,i)));return{name:i,configuration:s}}function cy(t){const{name:e,configuration:n}=ay(t,i=>{const s=Mh.get(i);if(s===void 0)throw new Error(`Unknown codec: ${JSON.stringify(i)}`);return s},i=>i);return{resolver:e,configuration:n}}const Mh=new Map;function ly(t){Mh.set(t.name,t)}function Wa(t,e){const n=[],i=[],s=[],r=[];i.push(e);const o=Ri(t,cy),a=o.length;let c=0;for(;c<a;++c){const{resolver:f,configuration:v}=o[c];if(f.kind!==Z.arrayToArray)break;const S=f,{configuration:I,encodedArrayInfo:C}=S.resolve(v,e);i.push(C),e=C,n.push({kind:Z.arrayToArray,name:f.name,configuration:I})}if(c===a||o[c].resolver.kind!==Z.arrayToBytes)throw new Error("Missing array -> bytes codec");const{codecSpec:l,layoutInfo:u,encodedSize:h,shardingInfo:d}=(()=>{const{resolver:f,configuration:v}=o[c],S=f,{configuration:I,shardingInfo:C,encodedSize:w}=S.resolve(v,e);if(C!==void 0&&c+1!==a)throw new Error("bytes -> bytes codecs not supported following sharding codec");const M=S.getDecodedArrayLayoutInfo(I,e);return{codecSpec:{name:f.name,kind:Z.arrayToBytes,configuration:I},layoutInfo:M,encodedSize:w,shardingInfo:C}})();s[c]=u,r.push(h);const p=h,g=[];for(++c;c<a;){const{resolver:f,configuration:v}=o[c];if(f.kind!==Z.bytesToBytes)throw new Error(`Expected bytes -> bytes codec, but received ${JSON.stringify(f.name)} of kind ${Z[f.kind]}`);const S=f,{configuration:I,encodedSize:C}=S.resolve(v,p);g.push({name:f.name,kind:f.kind,configuration:I}),r.push(C),++c}for(let f=n.length-1;f>=0;--f)s[f]=o[f].resolver.getDecodedArrayLayoutInfo(n[f].configuration,i[f],s[f+1]);return{[Z.arrayToArray]:n,[Z.arrayToBytes]:l,[Z.bytesToBytes]:g,arrayInfo:i,layoutInfo:s,shardingInfo:d,encodedSize:r}}/**
 * @license
 * Copyright 2023 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var Th=(t=>(t[t.DEFAULT=0]="DEFAULT",t[t.V2=1]="V2",t))(Th||{});function hy(t,e){return We(new Array(e),t,n=>{if(typeof n!="number"||!Number.isInteger(n)||n<=0)throw new Error(`Expected positive integer, but received: ${JSON.stringify(n)}`);return n})}const Za=new Map([["",{unit:"",scale:1}],["angstrom",{unit:"m",scale:1e-10}],["foot",{unit:"m",scale:.3048}],["inch",{unit:"m",scale:.0254}],["mile",{unit:"m",scale:1609.34}],["parsec",{unit:"m",scale:0x6da012f95c9e88}],["yard",{unit:"m",scale:.9144}],["minute",{unit:"s",scale:60}],["hour",{unit:"s",scale:60*60}],["day",{unit:"s",scale:60*60*24}]]);for(const t of["meter","second"])for(const e of Ec){const{longPrefix:n,prefix:i}=e;if(n===void 0)continue;const s={unit:t[0],scale:10**e.exponent};Za.set(`${n}${t}`,s),Za.set(`${i}${t[0]}`,s)}var Yi=(t=>(t[t.START=0]="START",t[t.END=1]="END",t))(Yi||{});ly({name:"sharding_indexed",kind:Z.arrayToBytes,resolve(t,e){Ge(t);const n=X(t,"chunk_shape",c=>hy(c,e.chunkShape.length)),i=ad(t,"index_location",c=>cd(c,Yi,/^[a-z]+$/),1),s=Array.from(e.chunkShape,(c,l)=>{const u=n[l];if(c%u!==0)throw new Error(`sub-chunk shape of ${JSON.stringify(u)} does not evenly divide outer chunk shape of ${JSON.stringify(e.chunkShape)}`);return c/u}),r=Array.from(s);r.push(2);const o=X(t,"index_codecs",c=>Wa(c,{dataType:V.UINT64,chunkShape:r}));if(o.encodedSize[o.encodedSize.length-1]===void 0)throw new Error("index_codecs must specify fixed-size encoding");const a=X(t,"codecs",c=>Wa(c,{dataType:e.dataType,chunkShape:n}));return{configuration:{indexCodecs:o,subChunkCodecs:a,subChunkShape:n,subChunkGridShape:s,indexLocation:i},shardingInfo:{subChunkShape:n,subChunkGridShape:s,subChunkCodecs:a}}},getDecodedArrayLayoutInfo(t,e){return t.subChunkCodecs.layoutInfo[0]}});/**
 * @license
 * Copyright 2023 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function Ph(t,e){if(e===void 0)return{outer:t,inner:{offset:0,length:t.length}};if("suffixLength"in e){const n=Math.min(t.length,e.suffixLength);return{outer:{offset:t.offset+(t.length-n),length:n},inner:{offset:t.length-n,length:n}}}if(e.offset+e.length>t.length)throw new Error(`Requested byte range ${JSON.stringify(e)} not valid for value of length ${t.length}`);return{outer:{offset:t.offset+e.offset,length:e.length},inner:e}}const Qa=BigInt("18446744073709551615");class uy extends wt{constructor(e,n,i){super(),this.configuration=e,this.base=i,this.indexCache=this.registerDisposer(new _m(n.addRef(),{get:async(l,u)=>{const{indexCodecs:h}=e,d=h.encodedSize[h.encodedSize.length-1];let p;switch(e.indexLocation){case Yi.START:p={offset:0,length:d};break;case Yi.END:p={suffixLength:d};break}const g=await i.read(l,{cancellationToken:u,byteRange:p});if(g===void 0)return{size:0,data:void 0};const f=await bh(e.indexCodecs,g.data,u);return{size:f.byteLength,data:new BigUint64Array(f.buffer,f.byteOffset,f.byteLength/8)}}}));const{subChunkGridShape:s}=this.configuration,r=s.length,o=this.configuration.indexCodecs.layoutInfo[0].physicalToLogicalDimension,a=this.indexStrides=new Array(r+1);let c=1;for(let l=r;l>=0;--l){const u=o[l];a[u]=c,c*=u===r?2:s[u]}}async read(e,n){const i=await this.indexCache.get(e.base,n.cancellationToken??pe);if(i===void 0)return;const s=this.configuration.subChunkShape.length,{subChunk:r}=e,{indexStrides:o}=this;let a=0;for(let g=0;g<s;++g){const f=r[g];a+=f*o[g]}const c=i[a],l=i[a+o[s]];if(c===Qa&&l===Qa)return;const u={offset:Number(c),length:Number(l)},{outer:h,inner:d}=Ph(u,n.byteRange);if(h.length===0)return{data:new Uint8Array(0),dataRange:d,totalSize:u.length};const p=await this.base.read(e.base,{cancellationToken:n.cancellationToken,byteRange:h});if(p!==void 0){if(p.dataRange.offset!==h.offset||p.dataRange.length!==h.length)throw new Error(`Received truncated response, expected ${JSON.stringify(h)} but received ${JSON.stringify(p.dataRange)}`);return{data:p.data,dataRange:d,totalSize:u.length}}}}Nt({name:"sharding_indexed",kind:Z.arrayToBytes,getShardedKvStore(t,e,n){return new uy(t,e,n)}});Nt({name:"transpose",kind:Z.arrayToArray,async decode(t,e,n,i){return n}});function dy(t){if(t!==void 0)return"suffixLength"in t?`bytes=-${t.suffixLength}`:`bytes=${t.offset}-${t.offset+t.length-1}`}const fy=navigator.userAgent.indexOf("Chrome")!==-1?"no-store":"default";class py{constructor(e,n){this.credentialsProvider=e,this.baseUrl=n}async read(e,n){const{cancellationToken:i=pe}=n;let{byteRange:s}=n;const r=this.baseUrl+e;for(let o=0;;++o)try{const a={},c=dy(s);c!==void 0&&(a.headers={range:c},a.cache=fy);const{response:l,data:u}=await ge(this.credentialsProvider,r,a,async p=>({response:p,data:await p.arrayBuffer()}),i);let h,d;if(l.status===206){const p=l.headers.get("content-range");if(p===null)if(s!==void 0){if("suffixLength"in s)throw new Error("Content-range header not provided with HTTP 206 response.  Check server CORS configuration.");h={offset:s.offset,length:u.byteLength}}else throw new Error("Unexpected HTTP 206 response when no byte range specified.");if(p!==null){const g=p.match(/bytes ([0-9]+)-([0-9]+)\/([0-9]+|\*)/);if(g===null)throw new Error(`Invalid content-range header: ${JSON.stringify(p)}`);const f=parseInt(g[1],10);if(parseInt(g[2],10)!==f+u.byteLength-1)throw new Error(`Length in content-range header ${JSON.stringify(p)} does not match content length ${u.byteLength}`);d=g[3]==="*"?void 0:parseInt(g[3],10),h={offset:f,length:u.byteLength}}}return h===void 0&&(h={offset:0,length:u.byteLength},d=u.byteLength),{data:new Uint8Array(u),dataRange:h,totalSize:d}}catch(a){if(o===0&&a instanceof ut&&a.status===416&&n.byteRange!==void 0&&"suffixLength"in n.byteRange){const c=await ge(this.credentialsProvider,r,{method:"HEAD"},async h=>h,i);if(c.status!==200)throw new Error("Failed to determine total size in order to fetch suffix");const l=c.headers.get("content-length");if(l===void 0)throw new Error("Failed to determine total size in order to fetch suffix");const u=Number(l);s=Ph({offset:0,length:u},s).outer;continue}if(Mt(a))return;throw a}}}function gy(t,e){return new py(t,e)}var my=Object.defineProperty,yy=Object.getOwnPropertyDescriptor,vy=(t,e,n,i)=>{for(var s=i>1?void 0:i?yy(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(s=(i?o(e,n,s):o(s))||s);return i&&s&&my(e,n,s),s};let Xa=class extends re(ue()(ze),hr){constructor(){super(...arguments),this.chunkKvStore=oy(this.chunkManager,this.parameters.metadata.codecs,gy(this.credentialsProvider,this.parameters.url+"/"))}async download(t,e){t.chunkDataSize=this.spec.chunkDataSize;const{parameters:n}=this,{chunkGridPosition:i}=t,{metadata:s}=n;let r="";const o=this.spec.rank,{physicalToLogicalDimension:a}=s.codecs.layoutInfo[0];let c;s.chunkKeyEncoding===Th.DEFAULT?(r+="c",c=s.dimensionSeparator):(c="",o===0&&(r+="0"));const l=new Array(o),{readChunkShape:u}=s.codecs.layoutInfo[0],{chunkShape:h}=s;for(let g=0;g<o;++g){const f=a[o-1-g];l[f]=Math.floor(i[g]*u[f]/h[f])}for(let g=0;g<o;++g)r+=`${c}${l[g]}`,c=s.dimensionSeparator;const{chunkKvStore:d}=this,p=await d.kvStore.read(d.getChunkKey(i,r),{cancellationToken:e});if(p!==void 0){const g=await bh(d.decodeCodecs,p.data,e);await tn(t,e,g)}}};Xa=vy([L()],Xa);const wy=new pu(self);self.rpc=wy;
