var lc={4242:(te,Se,x)=>{x.d(Se,{y6:()=>j});var ye=x(8796);/**
 * @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.
 */var j=(ce=>(ce[ce.MIN_REPRESENTATIVE=0]="MIN_REPRESENTATIVE",ce[ce.MAX_REPRESENTATIVE=1]="MAX_REPRESENTATIVE",ce[ce.REPRESENTATIVE_EXCLUDED=2]="REPRESENTATIVE_EXCLUDED",ce[ce.NONREPRESENTATIVE_EXCLUDED=4]="NONREPRESENTATIVE_EXCLUDED",ce))(j||{});function Y(ce){return!(ce.high>>>31)}const be=new ye.R(4294967295,4294967295)},3206:(te,Se,x)=>{x.d(Se,{B0:()=>be,DN:()=>ce,no:()=>ke});var ye=x(5716),j=x(2596),Y=x(4038);/**
 * @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 be{constructor(D){this.value_=D,this.changed=new Y.IY}get value(){return this.value_}set value(D){D!==this.value_&&(this.value_=D,this.changed.dispatch())}}class ce extends be{constructor(D,q,z=D){super(D),this.validator=q,this.defaultValue=z}toJSON(){const{value_:D}=this;if(D!==this.defaultValue)return this.value_}reset(){this.value=this.defaultValue}restoreState(D){if(D!==void 0){const{validator:q}=this;try{this.value=q(D);return}catch{}}this.value=this.defaultValue}}class ve extends j.O8{constructor(D,q){super(),this.changed=new Y.IY,this.f=D,this.ws=q;for(const z of q)this.registerDisposer(z.changed.add(this.changed.dispatch))}get value(){return this.f(...this.ws.map(D=>D.value))}}function Re(F,...D){return new ve(F,D)}class Ee extends j.O8{constructor(D,q){super(),this.changed=new Y.IY,this.valueGeneration=-1,this.f=D,this.ws=q;for(const z of q)this.registerDisposer(z.changed.add(this.changed.dispatch))}get value(){const D=this.changed.count;return D!==this.valueGeneration&&(this.value_=this.f(...this.ws.map(q=>q.value)),this.valueGeneration=D),this.value_}}function re(F,...D){return new Ee(F,D)}class de extends j.O8{constructor(D,q=(z,M)=>z===M){super(),this.changed=new Y.HN,this.value=D.value,this.registerDisposer(D.changed.add(()=>{const z=D.value;q(this.value,z)||(this.value=z,this.changed.dispatch())}))}}function Q(F,D,q){const z=new ve(F,D),M=new de(z,q);return M.registerDisposer(z),M}class Ge extends j.O8{constructor(D){super(),this.changed=new Y.IY;const q=D(this),z=Object.keys(q),M=()=>{const Te=Array.isArray(q)?[]:{};for(const se of z)Te[se]=q[se].value;this.value=Te,this.changed.dispatch()};M();for(const Te of z){const se=q[Te];this.registerDisposer(se.changed.add(()=>M()))}}}class We extends j.O8{constructor(D,...q){super(),this.f=D,this.changed=new Y.IY;for(const z of q)this.registerDisposer(z.add(this.changed.dispatch))}get value(){return this.f()}}class Ye extends j.O8{constructor(){super(...arguments),this.changed=new Y.IY}get value(){return this.value_}set value(D){const{value_:q}=this;if(this.value_=D,q!==void 0&&(q.dispose(),q.unregisterDisposer(this.valueHandler),this.valueHandler=void 0),D!==void 0){const z=this.valueHandler=()=>{this.value_===D&&(this.value_=void 0,this.changed.dispatch())};D.registerDisposer(z)}D!==q&&this.changed.dispatch()}reset(){this.value=void 0}disposed(){this.value_!==void 0&&(this.value_.unregisterDisposer(this.valueHandler),this.value_.dispose()),this.value_=void 0,super.disposed()}}class Xe extends Ye{constructor(D,q){super(),this.validator=D,this.jsonConverter=q}toJSON(){const{value:D}=this;return D&&this.jsonConverter(D)}restoreState(D){this.value=this.validator(D)}}class De{constructor(D){this.changed=new Y.HN,D===void 0?this.values=new Set:this.values=new Set(D)}add(D){const{values:q}=this;return q.has(D)||(q.add(D),this.changed.dispatch(D,!0)),this}delete(D){const{values:q}=this;return q.delete(D)?(this.changed.dispatch(D,!1),!0):!1}has(D){return this.values.has(D)}get size(){return this.values.size}[Symbol.iterator](){return this.values[Symbol.iterator]()}clear(){const{values:D}=this;D.size>0&&(D.clear(),this.changed.dispatch(null,!1))}}function ke(F,...D){const q=D.map(Ae=>Ae.value),z=D.length;let M=new j.O8,Te=F(M,...q);const se=(0,ye.A)(()=>{let Ae=!1;for(let Le=0;Le<z;++Le){const Qe=D[Le].value;q[Le]!==Qe&&(q[Le]=Qe,Ae=!0)}Ae&&(M.dispose(),M=new j.O8,Te=F(M,...q))},0),qe=D.map(Ae=>Ae.changed.add(se));return{flush(){se.flush()},dispose(){se.cancel(),(0,j.$F)(qe),M.dispose()},get value(){return se.flush(),Te}}}function U(F,...D){const q=D.map(Ae=>Ae.value),z=D.length;let M=new RefCounted,Te=F(M,...q);const se=()=>{let Ae=!1;for(let Le=0;Le<z;++Le){const Qe=D[Le].value;q[Le]!==Qe&&(q[Le]=Qe,Ae=!0)}Ae&&(M.dispose(),M=new RefCounted,Te=F(M,...q))},qe=D.map(Ae=>Ae.changed.add(se));return{dispose(){invokeDisposers(qe),M.dispose()},get value(){return Te}}}function W(F){return{changed:neverSignal,value:F}}function X(F,D){return F(D.value),D.changed.add(()=>F(D.value))}function O(F,D){return D.value=F.value,F.changed.add(()=>{D.value=F.value})}class ${constructor(D,q){this.outer=D,this.getInner=q,this.changed=new NullarySignal,this.update=()=>{const{disposer:z,outer:M}=this;z!==void 0&&z();const Te=this.inner=this.getInner(M.value);this.disposer=Te.changed.add(this.changed.dispatch),this.changed.dispatch()},D.changed.add(this.update),this.update()}dispose(){this.outer.changed.remove(this.update),this.disposer()}get value(){return this.inner.value}set value(D){this.inner.value=D}}class ae extends null{reset(){this.inner.reset()}restoreState(D){this.inner.restoreState(D)}toJSON(){return this.inner.toJSON()}}},4509:(te,Se,x)=>{x.d(Se,{Dq:()=>Y,Qi:()=>ve,fx:()=>ce,gI:()=>Ee,wS:()=>j,y3:()=>Re});/**
 * @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 ye extends Error{constructor(){super(...arguments),this.name="CancellationError",this.message="CANCELED"}toString(){return"CANCELED"}}const j=new ye;function Y(re){if(re.isCanceled===!0)throw j}const be=()=>{},ce={isCanceled:!1,add:()=>be,remove:be};class ve{cancel(){const{handlers:de}=this;if(de!==null&&(this.handlers=null,de!==void 0))for(const Q of de)Q()}get isCanceled(){return this.handlers===null}add(de){let{handlers:Q}=this;return Q===null?(de(),be):(Q===void 0&&(Q=this.handlers=new Set),Q.add(de),()=>{this.remove(de)})}remove(de){const{handlers:Q}=this;Q?.delete(de)}}class Re extends ve{constructor(){super(...arguments),this.consumers=new Set}addConsumer(de=ce){const{consumers:Q}=this;Q.has(de)||de.isCanceled||(Q.add(de),de.add(()=>{Q.delete(de),Q.size===0&&this.cancel()}))}}function Ee(re,de){return new Promise((Q,Ge)=>{if(re===ce){de(Q,Ge,ce);return}const We=new ve,Ye=re.add(()=>{We.cancel()});de(Xe=>{Ye(),Q(Xe)},Xe=>{Ye(),Ge(Xe)},We)})}},2596:(te,Se,x)=>{x.d(Se,{$F:()=>Y,O8:()=>ce,fL:()=>ve});/**
 * @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 ye=!1;function j(Ee){typeof Ee=="object"?Ee.dispose():Ee()}function Y(Ee){for(let re=Ee.length;re>0;--re)j(Ee[re-1])}function be(Ee,re,de,Q){return Ee.addEventListener(re,de,Q),()=>Ee.removeEventListener(re,de,Q)}class ce{constructor(){this.refCount=1}addRef(){return++this.refCount,this}dispose(){ye&&(this.disposedStacks=this.disposedStacks||[]).push(new Error().stack),--this.refCount===0&&this.refCountReachedZero()}refCountReachedZero(){this.disposed();const{disposers:re}=this;re!==void 0&&(Y(re),this.disposers=void 0),this.wasDisposed=!0}disposed(){}registerDisposer(re){const{disposers:de}=this;return de==null?this.disposers=[re]:de.push(re),re}unregisterDisposer(re){const{disposers:de}=this;if(de!=null){const Q=de.indexOf(re);Q!==-1&&de.splice(Q,1)}return re}registerEventListener(re,de,Q,Ge){this.registerDisposer(be(re,de,Q,Ge))}registerCancellable(re){return this.registerDisposer(()=>{re.cancel()}),re}}class ve extends ce{constructor(re){super(),this.value=re}}function Re(Ee){return()=>{if(Ee!==void 0){const re=Ee;Ee=void 0,j(re)}}}},3038:(te,Se,x)=>{x.d(Se,{I1:()=>Ae,Oi:()=>Q,T_:()=>z,WG:()=>Ge,Yu:()=>be,_A:()=>D,_S:()=>q,eG:()=>$,eR:()=>j,ln:()=>Y,nL:()=>De,pB:()=>ye,qp:()=>M,sJ:()=>Le,uD:()=>O,vs:()=>X,w0:()=>ce,w8:()=>re,xK:()=>Ye});var ye=x(7684),j=x(329),Y=x(4796),be=x(2221),ce=x(1409);/**
 * @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 ve=ye.create(),Re=null,Ee=[j.fromValues(1,0,0),j.fromValues(0,1,0),j.fromValues(0,0,1)],re=j.fromValues(0,0,0),de=Y.fromValues(0,0,0,0),Q=j.fromValues(1,1,1),Ge=j.fromValues(1/0,1/0,1/0),We=be.create();function Ye(P){return P[0]*P[1]*P[2]}function Xe(P){return P[0]*P[1]*P[2]*P[3]}function De(P){return`${P[0]},${P[1]},${P[2]}`}function ke(P,B){const ne=B[0],Z=B[1],le=B[2],ie=B[3];P[0]=ie,P[1]=le,P[2]=-Z,P[3]=-ne}function U(P,B){const ne=B[0],Z=B[1],le=B[2],ie=B[3];P[0]=-le,P[1]=ie,P[2]=ne,P[3]=-Z}function W(P,B){const ne=B[0],Z=B[1],le=B[2],ie=B[3];P[0]=Z,P[1]=-ne,P[2]=ie,P[3]=-le}function X(P,B,ne){const Z=B[0],le=B[1],ie=B[2];return P[0]=ne[0]*Z+ne[4]*le+ne[8]*ie,P[1]=ne[1]*Z+ne[5]*le+ne[9]*ie,P[2]=ne[2]*Z+ne[6]*le+ne[10]*ie,P}function O(P,B,ne){const Z=B[0],le=B[1],ie=B[2];return P[0]=ne[0]*Z+ne[1]*le+ne[2]*ie,P[1]=ne[4]*Z+ne[5]*le+ne[6]*ie,P[2]=ne[8]*Z+ne[9]*le+ne[10]*ie,P}function $(P,B,ne,Z,le){const ie=P;return P[0]=Z[0],P[1]=Z[1],P[2]=Z[2]*le,ye.fromRotationTranslationScale(P,ne,B,ie)}function ae(P,B,ne){const Z=ne.length;let le=0;for(let he=0;he<Z;++he)le+=(P[he]-B[he])**2;let ie=0;for(let he=0;he<Z;++he){const Pe=P[he];ie-=(Pe-ne[he])*(B[he]-Pe)}return ie/Math.max(le,1e-6)}function F(P,B,ne,Z){const le=P.length;let ie=ae(B,ne,Z);ie=Math.max(0,Math.min(1,ie));for(let he=0;he<le;++he){const Pe=B[he];P[he]=Pe+ie*(ne[he]-Pe)}return P}function D(P,B){const ne=B[0],Z=B[1],le=B[2],ie=B[4],he=B[5],Pe=B[6],Ne=B[8],xe=B[9],Ue=B[10];return P[0]=ne,P[1]=Z,P[2]=le,P[3]=ie,P[4]=he,P[5]=Pe,P[6]=Ne,P[7]=xe,P[8]=Ue,P}function q(P,B){const ne=B[0],Z=B[1],le=B[2],ie=B[3],he=B[4],Pe=B[5],Ne=B[6],xe=B[7],Ue=B[8],Ke=B[9],wt=B[10],ot=B[11],Ie=B[12],Jt=B[13],Ht=B[14],tt=B[15];P[0]=ie+ne,P[1]=xe+he,P[2]=ot+Ue,P[3]=tt+Ie,P[4]=ie-ne,P[5]=xe-he,P[6]=ot-Ue,P[7]=tt-Ie,P[8]=ie+Z,P[9]=xe+Pe,P[10]=ot+Ke,P[11]=tt+Jt,P[12]=ie-Z,P[13]=xe-Pe,P[14]=ot-Ke,P[15]=tt-Jt;const St=ie+le,hn=xe+Ne,fn=ot+wt,g=tt+Ht,_=ie-le,J=xe-Ne,K=ot-wt,oe=tt-Ht,pe=Math.sqrt(St**2+hn**2+fn**2);P[16]=St/pe,P[17]=hn/pe,P[18]=fn/pe,P[19]=g/pe;const Me=Math.sqrt(_**2+J**2+K**2);return P[20]=_/Me,P[21]=J/Me,P[22]=K/Me,P[23]=oe/Me,P}function z(P,B,ne,Z,le,ie,he){for(let Pe=0;Pe<6;++Pe){const Ne=he[Pe*4],xe=he[Pe*4+1],Ue=he[Pe*4+2],Ke=he[Pe*4+3];if(Math.max(Ne*P,Ne*Z)+Math.max(xe*B,xe*le)+Math.max(Ue*ne,Ue*ie)+Ke<0)return!1}return!0}function M(P,B,ne,Z,le,ie,he){for(let Pe=0;Pe<4;++Pe){const Ne=he[Pe*4],xe=he[Pe*4+1],Ue=he[Pe*4+2],Ke=he[Pe*4+3];if(Math.max(Ne*P,Ne*Z)+Math.max(xe*B,xe*le)+Math.max(Ue*ne,Ue*ie)+Ke<0)return!1}{const Ne=he[20],xe=he[5*4+1],Ue=he[5*4+2],Ke=he[5*4+3],wt=Math.max(Ne*P,Ne*Z)+Math.max(xe*B,xe*le)+Math.max(Ue*ne,Ue*ie),ot=Math.min(Ne*P,Ne*Z)+Math.min(xe*B,xe*le)+Math.min(Ue*ne,Ue*ie),Ie=Math.abs(Ke)*1e-6;if(ot>-Ke+Ie||wt<-Ke-Ie)return!1}return!0}function Te(P,B,ne,Z=!1){const le=ne.length,ie=[],he=Z?1:B+1,Pe=Z?B+1:1;for(let Ne=0;Ne<le;++Ne){const xe=ne[Ne];for(let Ue=0;Ue<B;++Ue)P[Ue*he+xe*Pe]!==0&&(ie[Ue]=!0)}return findMatchingIndices(ie,!0)}function se(P,B,ne){for(let Z=0;Z<3;++Z){const le=ne[Z];for(let ie=0;ie<3;++ie)P[ie+Z*3]=le*B[ie+Z*3]}return P}function qe(P,B,ne){for(let Z=0;Z<3;++Z){const le=ne[Z];for(let ie=0;ie<3;++ie)P[Z+ie*3]=le*B[Z+ie*3]}return P}function Ae(P){if(P[15]===1){const he=2/Math.abs(P[10]),Pe=2/Math.abs(P[0]),Ne=2/Math.abs(P[5]);return Pe*Ne*he}const B=P[10],Z=2*P[14]/(2*B-2),le=(B-1)*Z/(B+1);return 4/(P[0]*P[5])/3*(Math.abs(le)**3-Math.abs(Z)**3)}function Le(P){if(P[15]===1)return 2/Math.abs(P[10]);const B=P[10],Z=2*P[14]/(2*B-2),le=(B-1)*Z/(B+1);return Math.abs(le-Z)}function ut(P){return P[2]=0,P[6]=0,P[10]=0,P[14]=0,P}const Qe=j.create();function ps(P,B){B[0]=B[1]=B[2]=Number.POSITIVE_INFINITY,B[3]=B[4]=B[5]=Number.NEGATIVE_INFINITY;for(let ne=0;ne<8;++ne){Qe[0]=2*(ne&1)-1,Qe[1]=2*(ne>>>1&1)-1,Qe[2]=2*(ne>>>2&1)-1,vec3.transformMat4(Qe,Qe,P);for(let Z=0;Z<3;++Z){const le=Qe[Z];B[Z]=Math.min(B[Z],le),B[Z+3]=Math.max(B[Z+3],le)}}}},9808:(te,Se,x)=>{x.d(Se,{Bk:()=>Q,Dl:()=>Ye,El:()=>Xe,JD:()=>We,JZ:()=>Re,Rc:()=>re,cj:()=>de,j$:()=>Y});var ye=x(4509),j=x(8796);/**
 * @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 Y extends Error{constructor(ke,U,W,X){let O=`Fetching ${JSON.stringify(ke)} resulted in HTTP error ${U}`;W&&(O+=`: ${W}`),O+=".",super(O),this.name="HttpError",this.message=O,this.url=ke,this.status=U,this.statusText=W,X&&(this.response=X)}static fromResponse(ke){return new Y(ke.url,ke.status,ke.statusText,ke)}static fromRequestError(ke,U){if(U instanceof TypeError){let W;return typeof ke=="string"?W=ke:W=ke.url,new Y(W,0,"Network or CORS error")}return U}}const be=32,ce=500,ve=1e4;function Re(De){return Math.min(2**De*ce,ve/2)*(1+Math.random())}async function Ee(De,ke){for(let U=0;;){if(ke?.signal?.aborted)throw ye.wS;let W;try{W=await fetch(De,ke)}catch(X){throw Y.fromRequestError(De,X)}if(!W.ok){const{status:X}=W;if((X===429||X===503||X===504)&&++U!==be){await new Promise(O=>setTimeout(O,Re(U-1)));continue}throw Y.fromResponse(W)}return W}}function re(De){return De.arrayBuffer()}function de(De){return De.json()}async function Q(De,ke,U,W=ye.fx){if(W===ye.fx){const $=await Ee(De,ke);return await U($)}const X=new AbortController,O=W.add(()=>X.abort());try{const $=await Ee(De,{...ke,signal:X.signal});return await U($)}finally{O()}}const Ge=new j.R;function We(De,ke){let U;return typeof ke=="number"?U=`${ke-1}`:(j.R.decrement(Ge,ke),U=Ge.toString()),{Range:`bytes=${De}-${U}`}}function Ye(De){const ke=/^([^:/]+):\/\/([^/]+)((?:\/.*)?)$/,U=De.match(ke);if(U===null)throw new Error(`Invalid URL: ${JSON.stringify(De)}`);return{protocol:U[1],host:U[2],path:U[3]}}function Xe(De){return De instanceof Y?De.status===0||De.status===403||De.status===404:!1}},7900:(te,Se,x)=>{x.d(Se,{$v:()=>se,HB:()=>M,J6:()=>Te,JB:()=>de,MM:()=>he,Mo:()=>ce,Rf:()=>Ae,VH:()=>Ht,Vr:()=>Ee,Xu:()=>qe,Zw:()=>be,_D:()=>j,aO:()=>tt,bX:()=>Le,cQ:()=>ie,si:()=>Jt,sl:()=>Ke,xU:()=>Ne,z$:()=>B,zo:()=>Y,zr:()=>P});var ye=x(3038);/**
 * @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 j(g){const _=typeof g;if(_==="number"||_==="string"){const J=parseFloat(""+g);if(!Number.isNaN(J))return J}throw new Error(`Expected floating-point number, but received: ${JSON.stringify(g)}.`)}function Y(g){const _=j(g);if(Number.isFinite(_))return _;throw new Error(`Expected finite floating-point number, but received: ${_}.`)}function be(g){const _=j(g);if(Number.isFinite(_)&&_>=0)return _;throw new Error(`Expected finite non-negative floating-point number, but received: ${_}.`)}function ce(g){const _=Y(g);if(_>0)return _;throw new Error(`Expected positive finite floating-point number, but received: ${_}.`)}function ve(g,_){return J=>{const K=j(J);if(K>=g&&K<=_)return K;throw new Error(`Expected floating-point number in range [${g}, ${_}], but received: ${K}.`)}}function Re(g,_,J=j){Ae(_),g[0]=g[1]=g[2]=0;for(const K of Object.keys(_))switch(K){case"x":g[0]=J(_[K]);break;case"y":g[1]=J(_[K]);break;case"z":g[2]=J(_[K]);break;default:throw new Error(`Expected object to have keys ['x', 'y', 'z'], but received: ${JSON.stringify(_)}.`)}return g}function Ee(g,_){const J=g.length;if(!Array.isArray(_)||_.length!==J)throw new Error("Incompatible sizes");for(let K=0;K<J;++K)if(!Number.isFinite(parseFloat(_[K])))throw new Error("Non-finite value.");for(let K=0;K<J;++K)g[K]=parseFloat(_[K]);return g}function re(g,_){const J=g.length;if(!Array.isArray(_)||_.length!==J)throw new Error("Incompatible sizes.");for(let K=0;K<J;++K){const oe=parseInt(_[K],void 0);if(!Number.isInteger(oe))throw new Error("Non-integer value.")}for(let K=0;K<J;++K)g[K]=parseInt(_[K],void 0);return g}function de(g){if(typeof g=="object"){if(g===null)return"null";if(Array.isArray(g)){let pe="[";const Me=g.length;let ze=0;if(ze<Me)for(pe+=de(g[ze]);++ze<Me;)pe+=",",pe+=de(g[ze]);return pe+="]",pe}let _="{";const J=Object.keys(g).sort();let K=0;const oe=J.length;if(K<oe){let pe=J[K];for(_+=JSON.stringify(pe),_+=":",_+=de(g[pe]);++K<oe;)_+=",",pe=J[K],_+=JSON.stringify(pe),_+=":",_+=de(g[pe])}return _+="}",_}return JSON.stringify(g)}function Q(g){return g.replace(/['"]/g,_=>_==='"'?"'":'"')}function Ge(g){return Q(JSON.stringify(Q(g)))}const We="_";function Ye(g){if(typeof g=="object"){if(g===null)return"null";const _=g.toJSON;if(typeof _=="function")return Ye(_.call(g));if(Array.isArray(g)){let pe="[";const Me=g.length;let ze=0;if(ze<Me)for(pe+=Ye(g[ze]);++ze<Me;)pe+=We,pe+=Ye(g[ze]);return pe+="]",pe}let J="{";const K=Object.keys(g);let oe=!0;for(const pe of K){const Me=g[pe];if(Me===void 0)continue;const ze=Ye(Me);ze&&(oe?oe=!1:J+=We,J+=Ge(pe),J+=":",J+=ze)}return J+="}",J}return typeof g=="string"?Ge(g):JSON.stringify(g)}const Xe=/('(?:[^'\\]|(?:\\.))*')/,De=/("(?:[^"\\]|(?:\\.))*")/,ke=new RegExp(`${Xe.source}|${De.source}`),U=new RegExp(`${De.source}|${Xe.source}`),W=/^((?:[^"'\\]|(?:\\[^']))*)("|\\')/,X=/^((?:[^"'\\]|(?:\\.))*)'/;function O(g,_,J,K){if(g.length>=2&&g.charAt(0)===_&&g.charAt(g.length-1)===_){let oe=g.substr(1,g.length-2),pe=J;for(;oe.length>0;){const Me=oe.match(K);if(Me===null){pe+=oe;break}pe+=Me[1],Me[2]===J?(pe+="\\",pe+=J):pe+=_,oe=oe.substr(Me.index+Me[0].length)}return pe+=J,pe}return g}function $(g){return O(g,"'",'"',W)}function ae(g,_,J){const K=/[&_,]/g;let oe,pe,Me;J==='"'?(oe="'",pe=W,Me=ke):(oe='"',pe=X,Me=U);let ze="";for(;g.length>0;){const kt=g.match(Me);let nt,Tt;if(kt===null)nt=g,g="",Tt="";else{nt=g.substr(0,kt.index),g=g.substr(kt.index+kt[0].length);const Nn=kt[1];Nn!==void 0?Tt=O(Nn,oe,J,pe):Tt=kt[2]}ze+=nt.replace(K,_),ze+=Tt}return ze}function F(g){return ae(g,",",'"')}function D(g){return ae(g,"_","'")}function q(g){return JSON.parse(F(g))}function z(g){let _="";for(;g.length>0;){const J=g.match(ke);let K,oe;if(J===null)K=g,g="",oe="";else{K=g.substr(0,J.index),g=g.substr(J.index+J[0].length);const pe=J[1];pe!==void 0?oe=$(pe):oe=J[2]}_+=K.replace(/\(/g,"[").replace(/\)/g,"]").replace("True","true").replace("False","false").replace(/,\s*([}\]])/g,"$1"),_+=oe}return _}function M(g){return JSON.parse(z(g))}function Te(g,_){if(!Array.isArray(g))throw new Error(`Expected array, but received: ${JSON.stringify(g)}.`);if(_!==void 0&&g.length!==_)throw new Error(`Expected array of length ${_}, but received: ${JSON.stringify(g)}.`);return g}function se(g,_){if(!Array.isArray(g))throw new Error(`Expected array, but received: ${JSON.stringify(g)}.`);return g.map(_)}function qe(g,_,J){const K=g.length;if(!Array.isArray(_)||_.length!==K)throw new Error(`Expected length ${K} array, but received: ${JSON.stringify(_)}.`);for(let oe=0;oe<K;++oe)g[oe]=J(_[oe],oe);return g}function Ae(g){if(typeof g!="object"||g==null||Array.isArray(g))throw new Error(`Expected JSON object, but received: ${JSON.stringify(g)}.`);return g}function Le(g){const _=parseInt(g,10);if(!Number.isInteger(_))throw new Error(`Expected integer, but received: ${JSON.stringify(g)}.`);return _}function ut(g){const _=Le(g);if(_<=0)throw new Error(`Expected positive integer, but received: ${_}.`);return _}function Qe(g){const _=Le(g);if(_<0)throw new Error(`Expected non-negative integer, but received: ${_}.`);return _}function ps(g,_){const J=_.get(g);if(J===void 0)throw new Error(`Expected one of ${JSON.stringify(Array.from(_.keys()))}, but received: ${JSON.stringify(g)}.`);return J}function P(g){if(typeof g!="string")throw new Error(`Expected string, but received: ${JSON.stringify(g)}.`);return g}function B(g){if(g!==void 0)return P(g)}function ne(g){if(g!==void 0)return Le(g)}function Z(g){if(g!==void 0){if(typeof g=="boolean")return g;if(g==="true")return!0;if(g==="false")return!1;throw new Error(`Expected string or boolean but received: ${JSON.stringify(g)}`)}}function le(g,_){return g===void 0?_:g}function ie(g,_,J){const K=Object.prototype.hasOwnProperty.call(g,_)?g[_]:void 0;try{return J(K)}catch(oe){throw new Error(`Error parsing ${JSON.stringify(_)} property: ${oe.message}`)}}function he(g,_,J,K){return ie(g,_,oe=>oe===void 0?K:J(oe))}function Pe(g,_){Ae(g);const J=new Map;for(const K of Object.keys(g))try{J.set(K,_(g[K]))}catch(oe){throw new Error(`Error parsing value associated with key ${JSON.stringify(K)}: ${oe.message}`)}return J}function Ne(g){if(typeof g!="number"||!Number.isFinite(g)||g<0||g>1)throw new Error(`Expected floating point number in [0,1], but received: ${JSON.stringify(g)}.`);return g}function xe(g){if(g==="")return{};if(g.startsWith("{"))return q(g);const _={},J=g.split(/[&;]/);for(const K of J){const oe=K.match(/^([^=&;]+)=([^&;]*)$/);if(oe===null)throw new Error(`Invalid query string part: ${JSON.stringify(K)}.`);_[oe[1]]=decodeURIComponent(oe[2])}return _}function Ue(g){if(g===void 0)return"";const _=Object.keys(g);return _.length===0?"":_.some(J=>typeof g[J]!="string")?JSON.stringify(g):_.map(J=>`${encodeURIComponent(J)}=${encodeURIComponent(g[J])}`).join("&")}function Ke(g,_,J=/^[a-zA-Z]/){if(typeof g=="string"&&g.match(J)!==null){const K=g.toUpperCase();if(Object.prototype.hasOwnProperty.call(_,K))return _[K]}throw new Error(`Invalid enum value: ${JSON.stringify(g)}.`)}function wt(g){return qe(vec3.create(),g,Y)}function ot(g){return qe(vec3.create(),g,ce)}function Ie(g){return qe(vec3.create(),g,ut)}function Jt(g){if(!Array.isArray(g))throw new Error(`Expected array, received: ${JSON.stringify(g)}.`);for(const _ of g)if(typeof _!="string")throw new Error(`Expected string, received: ${JSON.stringify(_)}.`);return g}function Ht(g){if(!Array.isArray(g))throw new Error(`Expected array, received: ${JSON.stringify(g)}.`);for(const _ of g)if(!Number.isInteger(_))throw new Error(`Expected integer, received: ${JSON.stringify(_)}.`);return g}function tt(g){if(typeof g!="boolean")throw new Error(`Expected boolean, received: ${JSON.stringify(g)}`);return g}function St(g){for(const _ in g)return g}function hn(g,_){if(g!==_)throw new Error(`Expected ${JSON.stringify(_)}, but received: ${JSON.stringify(g)}`);return _}function fn(g,_){if(g===void 0){const J=new Array(_);return J.fill(null),J}return qe(new Array(_),g,J=>{if(J!==null&&typeof J!="string")throw new Error(`Expected string or null, but received: ${JSON.stringify(name)}`);return J})}},147:(te,Se,x)=>{x.d(Se,{DA:()=>Y,DI:()=>Q});/**
 * @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 ye(U,W,X,O,$,ae,F,D,q){for(let z=0;z<F;++z)for(let M=0;M<q;++M){let Te=0;for(let se=0;se<D;++se)Te+=X[z+O*se]*$[se+ae*M];U[z+W*M]=Te}return U}function j(U,W,X){for(let O=0;O<X;++O){const $=W*O;U.fill(0,$,$+X),U[$+O]=1}return U}function Y(U,W,X=W){return j(new U(W*X),W,Math.min(W,X))}function be(U,W,X=!0){const O=W.length,$=X?O+1:O,ae=new U($*(O+1));X&&(ae[ae.length-1]=1);for(let F=0;F<O;++F)ae[($+1)*F]=W[F];return ae}function ce(U,W,X=!0){const O=W.length,$=X?O+1:O,ae=Y(U,$,O+1);for(let F=0;F<O;++F)ae[$*O+F]=W[F];return ae}function ve(U,W,X){for(let O=0;O<X;++O)for(let $=0;$<X;++$)if(U[O*W+$]!==(O===$?1:0))return!1;return!0}function Re(U,W,X,O,$,ae){for(let F=0;F<ae;++F){const D=F*O,q=F*W;for(let z=0;z<$;++z)U[q+z]=X[D+z]}return U}function Ee(U,W,X,O){Re(U,W+1,X,O+1,O,O);for(let $=0;$<O;++$)U[(W+1)*W+$]=X[(O+1)*O+$];U[U.length-1]=1;for(let $=O;$<W;++$)U[(W+1)*$+$]=1;return U}let re;function de(U,W,X){let O=1;(re===void 0||re.length<X)&&(re=new Uint32Array(X));for(let $=0;$<X;++$)re[$]=$;for(let $=0;$<X;++$){const ae=W*$;let F=$;{let z=Math.abs(U[ae+$]);for(let M=$+1;M<X;++M){const Te=Math.abs(U[ae+M]);Te>z&&(z=Te,F=M)}}if($!==F){O*=-1;for(let z=0;z<X;++z){const M=W*z,Te=U[M+$];U[M+$]=U[M+F],U[M+F]=Te}{const z=re[$];re[$]=re[F],re[F]=z}}const D=U[ae+$],q=1/D;O*=D;for(let z=0;z<X;++z)U[W*z+$]*=q;U[ae+$]=q;for(let z=0;z<X;++z){if(z===$)continue;const M=-U[W*$+z];for(let Te=0;Te<X;++Te){const se=W*Te;U[se+z]+=M*U[se+$]}U[W*$+z]=M*q}}for(let $=0;$<X;++$){let ae=re[$];for(;ae!==$;){const F=W*$,D=W*ae;for(let z=0;z<X;++z){const M=F+z,Te=D+z,se=U[M];U[M]=U[Te],U[Te]=se}const q=re[$]=re[ae];re[ae]=ae,ae=q}}return O}function Q(U,W,X,O,$){return Re(U,W,X,O,$,$),de(U,W,$)}function Ge(U,W,X,O,$,ae){for(let F=0;F<ae;++F){const D=W*F,q=O*F;for(let z=0;z<$;++z)if(U[D+z]!==X[q+z])return!1}return!0}function We(U,W,X,O,$,ae){for(let F=0;F<$;++F)for(let D=0;D<ae;++D)U[D+F*W]=X[F+D*O];return U}function Ye(U,W,X,O,$){for(let ae=0;ae<$;++ae){let F=W[X*$+ae];for(let D=0;D<$;++D)F+=W[X*D+ae]*O[D];U[ae]=F}return U}function Xe(U,W,X,O,$){for(let ae=0;ae<$;++ae){let F=0;for(let D=0;D<$;++D)F+=W[X*D+ae]*O[D];U[ae]=F}return U}function De(U,W,X,O,$,ae){const F=$.length;for(let D=0;D<F;++D){const q=$[D];for(let z=0;z<ae;++z)U[z*W+D]=X[z*O+q]}return U}function ke(U,W,X,O,$,ae){const F=$.length;for(let D=0;D<F;++D){const q=$[D];for(let z=0;z<ae;++z)U[D*W+z]=X[q*O+z]}return U}},4038:(te,Se,x)=>{x.d(Se,{HN:()=>ye,IY:()=>Y});/**
 * @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 ye{constructor(){this.handlers=new Set,this.count=0;const ve=this;this.dispatch=function(){++ve.count,ve.handlers.forEach(Re=>{Re.apply(this,arguments)})}}add(ve){return this.handlers.add(ve),()=>this.remove(ve)}remove(ve){return this.handlers.delete(ve)}dispose(){this.handlers=void 0}}function j(ce,...ve){ce();for(let Re=0,Ee=ve.length;Re<Ee;++Re)ve[Re].add(ce);return()=>{for(let Re=0,Ee=ve.length;Re<Ee;++Re)ve[Re].remove(ce)}}class Y extends ye{}const be={count:0,add(ce){return()=>{}},remove(ce){return!1}}},8867:(te,Se,x)=>{te.exports=x.p+"neuroglancer_draco.ac67ec8d0d9050f8881d.wasm"},1075:(te,Se,x)=>{var ye=x(3206),j=x(4509),Y=x(2596);/**
 * @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 be=!(typeof Window<"u"&&self instanceof Window),ce=!1,ve=!1,Re="rpc.promise.response",Ee="rpc.promise.cancel",re="rpc.ready",de=new Map;function Q(t,e){de.set(t,e)}class Ge extends Error{constructor(e,n){super(n),this.name=e,this.message=n}}function We(t,e){Q(t,function(n){const s=n.id,i=new j.Qi,r=e.call(this,n,i);this.set(s,{promise:r,cancellationToken:i}),r.then(({value:o,transfers:a})=>{this.delete(s),this.invoke(Re,{id:s,value:o},a)},o=>{this.delete(s),this.invoke(Re,{id:s,error:o.message,errorName:o.name})})})}Q(Ee,function(t){const e=t.id,n=this.get(e);if(n!==void 0){const{cancellationToken:s}=n;s.cancel()}}),Q(Re,function(t){const e=t.id,{resolve:n,reject:s}=this.get(e);this.delete(e),Object.prototype.hasOwnProperty.call(t,"value")?n(t.value):t.errorName===j.wS.name?s(j.wS):s(new Ge(t.errorName,t.error))}),Q(re,function(t){this.onPeerReady()});const Ye=be?-1:0;class Xe{constructor(e,n){this.target=e,this.objects=new Map,this.nextId=Ye,n&&(this.queue=[]),e.onmessage=s=>{const i=s.data;ve&&console.log("Received message",i),de.get(i.functionName).call(this,i)}}sendReady(){this.invoke(re,{})}onPeerReady(){const{queue:e}=this;if(e!==void 0){this.queue=void 0;for(const{data:n,transfers:s}of e)this.target.postMessage(n,s)}}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,s=this.get(n);return s.referencedGeneration=e.gen,s.addRef(),s}getOptionalRef(e){if(e===void 0)return;const n=e.id,s=this.get(n);return s.referencedGeneration=e.gen,s.addRef(),s}invoke(e,n,s){n.functionName=e,ve&&console.trace("Sending message",n);const{queue:i}=this;if(i!==void 0){i.push({data:n,transfers:s});return}this.target.postMessage(n,s)}promiseInvoke(e,n,s=j.fx,i){return(0,j.gI)(s,(r,o,a)=>{const c=n.id=this.newId();this.set(c,{resolve:r,reject:o}),this.invoke(e,n,i),a.add(()=>{this.invoke(Ee,{id:c})})})}newId(){return be?this.nextId--:this.nextId++}}class De extends Y.O8{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(){ce&&console.log(`[${be}] #rpc object = ${this.rpc.numObjects}`);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 ke(t,e,n={}){e!=null&&t.initializeSharedObject(e,n.id)}class U extends De{constructor(e,n={}){super(),ke(this,e,n)}}Q("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.");ce&&console.log(`[${be}] #rpc objects: ${this.numObjects}`),e.disposed(),this.delete(e.rpcId),e.rpcId=null,e.rpc=null}),Q("SharedObject.refCountReachedZero",function(t){const e=this.get(t.id),n=t.gen;e.counterpartRefCountReachedZero(n)});const W=new Map;function X(t){return e=>{e.prototype.RPC_TYPE_ID=t}}function O(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");W.set(t,e)}}Q("SharedObject.new",function(t){const e=this,n=t.type,s=W.get(n),i=new s(e,t);--i.refCount});var $=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,F=(t,e,n,s)=>{for(var i=s>1?void 0:s?ae(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&$(e,n,i),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.
 */const D="SharedWatchableValue.changed";let q=class extends U{constructor(t,e={}){super(t,e),this.updatingValue_=!1,t!==void 0&&(this.base=new ye.B0(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(D,{id:this.rpcId,value:this.value})}}))}static makeFromExisting(t,e){const n=new q;return n.base=e,n.setupChangedHandler(),n.initializeCounterpart(t),n}static make(t,e){return q.makeFromExisting(t,new ye.B0(e))}get value(){return this.base.value}set value(t){this.base.value=t}get changed(){return this.base.changed}};q=F([O("SharedWatchableValue")],q),Q(D,function(t){const e=this.get(t.id);e.updatingValue_=!0,e.base.value=t.value,e.updatingValue_=!1});var z=x(4022);/**
 * @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 M=(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))(M||{});const Te=8;var se=(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))(se||{});const qe=3;var Ae=(t=>(t[t.totalTime=0]="totalTime",t[t.totalChunks=1]="totalChunks",t))(Ae||{}),Le=(t=>(t[t.numChunks=0]="numChunks",t[t.systemMemoryBytes=1]="systemMemoryBytes",t[t.gpuMemoryBytes=2]="gpuMemoryBytes",t))(Le||{});const ut=3,ps=Te*qe*ut+2;function P(t,e){return t*qe+e}function B(t){return Te*qe*ut+t}const ne=1e13,Z="ChunkQueueManager",le="ChunkManager",ie="ChunkSource.invalidate",he="ChunkQueueManager.requestChunkStatistics",Pe="ChunkManager.chunkLayerStatistics";class Ne{constructor(){this.numVisibleChunksNeeded=0,this.numVisibleChunksAvailable=0,this.numPrefetchChunksNeeded=0,this.numPrefetchChunksAvailable=0}}var xe=x(4472);/**
 * @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 Ue=class{static insertAfter(t,e){const n=t.next1;e.next1=n,e.prev1=t,t.next1=e,n.prev1=e}static insertBefore(t,e){const n=t.prev1;e.prev1=n,e.next1=t,t.prev1=e,n.next1=e}static front(t){const e=t.next1;return e===t?null:e}static back(t){const e=t.prev1;return e===t?null:e}static pop(t){const e=t.next1,n=t.prev1;return e.prev1=n,n.next1=e,t.next1=null,t.prev1=null,t}static*iterator(t){for(let e=t.next1;e!==t;e=e.next1)yield e}static*reverseIterator(t){for(let e=t.prev1;e!==t;e=e.prev1)yield e}static initializeHead(t){t.next1=t.prev1=t}};var Ke=x(4704);/**
 * @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 wt{constructor(e){this.compare=e}meld(e,n){if(n===null)return e;if(e===null)return n;const{compare:s}=this;if(s(n,e)){const r=e;e=n,n=r}const i=e.child0;return n.next0=i,n.prev0=e,i!==null&&(i.prev0=n),e.child0=n,e}combineChildren(e){let n=e.child0;if(n===null)return null;let s=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=s,s=a,o===null)break;n=o}let i=s;for(s=s.next0;s!==null;){const r=s.next0;i=this.meld(i,s),s=r}return i.prev0=null,i.next0=null,i}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 s=n.prev0,i=n.next0;s.child0===n?s.child0=i:s.next0=i,i!==null&&(i.prev0=s);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 s=n.next0;yield*this.entries(n),n=s}}}*removedEntries(e){if(e!==null){let n=e.child0;for(e.child0=null,e.next0=null,e.prev0=null,yield e;n!==null;){const s=n.next0;n.child0=null,n.next0=null,n.prev0=null,yield*this.entries(n),n=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.
 */class ot{constructor(e){this.compare=e}meld(e,n){if(n===null)return e;if(e===null)return n;const{compare:s}=this;if(s(n,e)){const r=e;e=n,n=r}const i=e.child1;return n.next1=i,n.prev1=e,i!==null&&(i.prev1=n),e.child1=n,e}combineChildren(e){let n=e.child1;if(n===null)return null;let s=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=s,s=a,o===null)break;n=o}let i=s;for(s=s.next1;s!==null;){const r=s.next1;i=this.meld(i,s),s=r}return i.prev1=null,i.next1=null,i}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 s=n.prev1,i=n.next1;s.child1===n?s.child1=i:s.next1=i,i!==null&&(i.prev1=s);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 s=n.next1;yield*this.entries(n),n=s}}}*removedEntries(e){if(e!==null){let n=e.child1;for(e.child1=null,e.next1=null,e.prev1=null,yield e;n!==null;){const s=n.next1;n.child1=null,n.next1=null,n.prev1=null,yield*this.entries(n),n=s}}}}var Ie=x(4038),Jt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,tt=(t,e,n,s)=>{for(var i=s>1?void 0:s?Ht(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Jt(e,n,i),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.
 */const St=!1;let hn=0;function fn(){return++hn}class g{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_=M.NEW,this.error=null,this.markGeneration=-1,this.priority=0,this.newPriority=0,this.priorityTier=se.RECENT,this.newPriorityTier=se.RECENT,this.systemMemoryBytes_=0,this.gpuMemoryBytes_=0,this.downloadSlots_=1,this.isComputational=!1,this.requestedState=M.NEW,this.newRequestedState=M.NEW,this.downloadCancellationToken=void 0}initialize(e){this.key=e,this.priority=Number.NEGATIVE_INFINITY,this.priorityTier=se.RECENT,this.newPriority=Number.NEGATIVE_INFINITY,this.newPriorityTier=se.RECENT,this.error=null,this.state=M.NEW,this.requestedState=M.NEW,this.newRequestedState=M.NEW}updatePriorityProperties(){this.priorityTier=this.newPriorityTier,this.priority=this.newPriority,this.newPriorityTier=se.RECENT,this.newPriority=Number.NEGATIVE_INFINITY,this.requestedState=this.newRequestedState,this.newRequestedState=M.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,M.FAILED)}downloadSucceeded(){this.requestedState===M.SYSTEM_MEMORY?(this.queueManager.moveChunkToFrontend(this),this.queueManager.updateChunkState(this,M.SYSTEM_MEMORY)):this.queueManager.updateChunkState(this,M.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){K(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.systemMemoryBytes_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),K(this,1),this.chunkManager.queueManager.scheduleUpdate()}get systemMemoryBytes(){return this.systemMemoryBytes_}set gpuMemoryBytes(e){K(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.gpuMemoryBytes_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),K(this,1),this.chunkManager.queueManager.scheduleUpdate()}get gpuMemoryBytes(){return this.gpuMemoryBytes_}get downloadSlots(){return this.downloadSlots_}set downloadSlots(e){e!==this.downloadSlots_&&(K(this,-1),this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!1),this.downloadSlots_=e,this.chunkManager.queueManager.adjustCapacitiesForChunk(this,!0),K(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 _=2;class J extends De{constructor(e){super(),this.chunkManager=e,this.listeners_=new Map,this.chunks=new Map,this.freeChunks=new Array,this.statistics=new Float64Array(ps),this.sourceQueueLevel=0,e.queueManager.sources.add(this)}disposed(){this.chunkManager.queueManager.sources.delete(this),super.disposed()}getNewChunk_(e){const n=this.freeChunks,s=n.length;if(s>0){const r=n[s-1];return n.length=s-1,r.source=this,r}const i=new e;return i.source=this,i}addChunk(e){const{chunks:n}=this;n.size===0&&this.addRef(),n.set(e.key,e),K(e,1)}removeChunk(e){const{chunks:n,freeChunks:s}=this;n.delete(e.key),e.dispose(),s[s.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 s=this.listeners_.get(e),i=s.indexOf(n);return i<0?!1:(s.splice(i,1),s.length===0&&this.listeners_.delete(e),!0)}chunkStateChanged(e,n){const{key:s}=e;if(s===null)return;const i=this.listeners_.get(s);if(i!==void 0)for(const r of i.slice())r(e,n)}}function K(t,e){const{statistics:n}=t.source,{systemMemoryBytes:s,gpuMemoryBytes:i}=t,r=P(t.state,t.priorityTier);n[r*ut+Le.numChunks]+=e,n[r*ut+Le.systemMemoryBytes]+=e*s,n[r*ut+Le.gpuMemoryBytes]+=e*i}class oe extends J{constructor(e,n){const s=e.get(n.chunkManager);super(s),ke(this,e,n)}}function pe(t){const e=t.downloadCancellationToken=new j.Qi,n=Date.now();t.source.download(t,e).then(()=>{if(t.downloadCancellationToken===e){t.downloadCancellationToken=void 0;const s=Date.now(),{statistics:i}=t.source;i[B(Ae.totalTime)]+=s-n,++i[B(Ae.totalChunks)],t.downloadSucceeded()}},s=>{t.downloadCancellationToken===e&&(t.downloadCancellationToken=void 0,t.downloadFailed(s),console.log(`Error retrieving chunk ${t}: ${s}`))})}function Me(t){const e=t.downloadCancellationToken;t.downloadCancellationToken=void 0,e.cancel()}class ze{constructor(e,n){this.heapOperations=e,this.linkedListOperations=n,this.heapRoots=[null,null],this.recentHead=new g,n.initializeHead(this.recentHead)}add(e){const n=e.priorityTier;if(n===se.RECENT)this.linkedListOperations.insertAfter(this.recentHead,e);else{const{heapRoots:s}=this;s[n]=this.heapOperations.meld(s[n],e)}}*candidates(){if(this.heapOperations.compare===g.priorityLess){const{linkedListOperations:e,recentHead:n}=this;for(;;){const i=e.back(n);if(i==null)break;yield i}const{heapRoots:s}=this;for(let i=se.LAST_ORDERED_TIER;i>=se.FIRST_ORDERED_TIER;--i)for(;;){const r=s[i];if(r==null)break;yield r}}else{const e=this.heapRoots;for(let i=se.FIRST_ORDERED_TIER;i<=se.LAST_ORDERED_TIER;++i)for(;;){const r=e[i];if(r==null)break;yield r}const{linkedListOperations:n,recentHead:s}=this;for(;;){const i=n.front(s);if(i==null)break;yield i}}}delete(e){const n=e.priorityTier;if(n===se.RECENT)this.linkedListOperations.pop(e);else{const s=this.heapRoots;s[n]=this.heapOperations.remove(s[n],e)}}}function kt(t){return new ze(new wt(t),xe.A)}function nt(t){return new ze(new ot(t),Ue)}function Tt(t,e,n,s,i,r){for(;e.availableItems<1||e.availableSize<t;){const o=i.next().value;if(o===void 0)return!1;const a=o.priorityTier;if(a<n||a===n&&o.priority>=s)return!1;r(o)}return!0}class Nn extends Y.O8{constructor(e,n){super(),this.itemLimit=e,this.sizeLimit=n,this.currentSize=0,this.currentItems=0,this.capacityChanged=new Ie.IY,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 Ci=class extends U{constructor(t,e){super(t,e),this.sources=new Set,this.queuedDownloadPromotionQueue=[nt(g.priorityGreater),nt(g.priorityGreater)],this.queuedComputePromotionQueue=nt(g.priorityGreater),this.downloadEvictionQueue=[nt(g.priorityLess),nt(g.priorityLess)],this.computeEvictionQueue=nt(g.priorityLess),this.systemMemoryEvictionQueue=kt(g.priorityLess),this.gpuMemoryPromotionQueue=nt(g.priorityGreater),this.gpuMemoryEvictionQueue=nt(g.priorityLess),this.updatePending=null,this.gpuMemoryChanged=new Ie.IY,this.numQueued=0,this.numFailed=0,this.gpuMemoryGeneration=0;const n=s=>{const i=this.registerDisposer(new Nn(t.get(s.itemLimit),t.get(s.sizeLimit)));return i.capacityChanged.add(()=>this.scheduleUpdate()),i};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 M.QUEUED:t.isComputational?yield this.queuedComputePromotionQueue:yield this.queuedDownloadPromotionQueue[t.source.sourceQueueLevel];break;case M.DOWNLOADING:t.isComputational?yield this.computeEvictionQueue:(yield this.downloadEvictionQueue[t.source.sourceQueueLevel],yield this.systemMemoryEvictionQueue);break;case M.SYSTEM_MEMORY_WORKER:case M.SYSTEM_MEMORY:yield this.systemMemoryEvictionQueue,t.requestedState===M.GPU_MEMORY&&(yield this.gpuMemoryPromotionQueue);break;case M.GPU_MEMORY:yield this.systemMemoryEvictionQueue,yield this.gpuMemoryEvictionQueue;break}}adjustCapacitiesForChunk(t,e){const n=e?-1:1;switch(t.state){case M.FAILED:this.numFailed-=n;break;case M.QUEUED:this.numQueued-=n;break;case M.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 M.SYSTEM_MEMORY:case M.SYSTEM_MEMORY_WORKER:this.systemMemoryCapacity.adjust(n,n*t.systemMemoryBytes);break;case M.GPU_MEMORY:this.systemMemoryCapacity.adjust(n,n*t.systemMemoryBytes),this.gpuMemoryCapacity.adjust(n,n*t.gpuMemoryBytes);break}}removeChunkFromQueues_(t){K(t,-1);for(const e of this.chunkQueuesForChunk(t))e.delete(t)}addChunkToQueues_(t){if(t.state===M.QUEUED&&t.priorityTier===se.RECENT){const{source:e}=t;return e.removeChunk(t),this.adjustCapacitiesForChunk(t,!1),!1}K(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=se.RECENT,t.newPriority=Number.NEGATIVE_INFINITY;return}St&&console.log(`${t}: changed priority ${t.priorityTier}:${t.priority} -> ${t.newPriorityTier}:${t.newPriority}`),this.removeChunkFromQueues_(t),t.updatePriorityProperties(),t.state===M.NEW&&(t.state=M.QUEUED,this.adjustCapacitiesForChunk(t,!0)),this.addChunkToQueues_(t)}updateChunkState(t,e){e!==t.state&&(St&&console.log(`${t}: changed state ${M[t.state]} -> ${M[e]}`),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,M.SYSTEM_MEMORY)}const n=this.gpuMemoryPromotionQueue.candidates(),s=this.gpuMemoryEvictionQueue.candidates(),i=this.gpuMemoryCapacity;for(;;){const r=n.next().value;if(r===void 0)break;const o=r.priorityTier,a=r.priority;if(!Tt(r.gpuMemoryBytes,i,o,a,s,e))break;this.copyChunkToGPU(r),this.updateChunkState(r,M.GPU_MEMORY)}}freeChunkGPUMemory(t){++this.gpuMemoryGeneration,this.rpc.invoke("Chunk.update",{id:t.key,state:M.SYSTEM_MEMORY,source:t.source.rpcId})}freeChunkSystemMemory(t){t.state===M.SYSTEM_MEMORY_WORKER?t.freeSystemMemory():this.rpc.invoke("Chunk.update",{id:t.key,state:M.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===M.SYSTEM_MEMORY)e.invoke("Chunk.update",{id:t.key,source:t.source.rpcId,state:M.GPU_MEMORY});else{const n={},s=[];t.serialize(n,s),n.state=M.GPU_MEMORY,e.invoke("Chunk.update",n,s)}}moveChunkToFrontend(t){const e=this.rpc,n={},s=[];t.serialize(n,s),n.state=M.SYSTEM_MEMORY,e.invoke("Chunk.update",n,s)}processQueuePromotions_(){const t=n=>{switch(n.state){case M.DOWNLOADING:Me(n);break;case M.GPU_MEMORY:this.freeChunkGPUMemory(n);case M.SYSTEM_MEMORY_WORKER:case M.SYSTEM_MEMORY:this.freeChunkSystemMemory(n);break}this.updateChunkState(n,M.QUEUED)},e=(n,s,i)=>{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,d=c.priority;if(!Tt(l,i,u,d,s,t)||!Tt(l,o,u,d,r,t))return;this.updateChunkState(c,M.DOWNLOADING),pe(c)}};for(let n=0;n<_;++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(){St&&console.log(`[Chunk status] QUEUED: ${this.numQueued}, FAILED: ${this.numFailed}, DOWNLOAD: ${this.downloadCapacity}, MEM: ${this.systemMemoryCapacity}, GPU: ${this.gpuMemoryCapacity}`)}invalidateSourceCache(t){for(const e of t.chunks.values()){switch(e.state){case M.DOWNLOADING:Me(e);break;case M.SYSTEM_MEMORY_WORKER:e.freeSystemMemory();break}this.updateChunkState(e,M.QUEUED)}this.rpc.invoke("Chunk.update",{source:t.rpcId}),this.scheduleUpdate()}};Ci=tt([O(Z)],Ci);class ms extends U{constructor(){super(...arguments),this.chunkManagerGeneration=-1,this.numVisibleChunksNeeded=0,this.numVisibleChunksAvailable=0,this.numPrefetchChunksNeeded=0,this.numPrefetchChunksAvailable=0}}const Ei=200;let ki=class extends U{constructor(t,e){super(t,e),this.existingTierChunks=[],this.newTierChunks=[],this.updatePending=null,this.recomputeChunkPriorities=new Ie.IY,this.recomputeChunkPrioritiesLate=new Ie.IY,this.memoize=new Ke.e,this.layers=[],this.sendLayerChunkStatistics=this.registerCancellable((0,z.A)(()=>{this.rpc.invoke(Pe,{id:this.rpcId,layers:this.layers.map(n=>({id:n.rpcId,numVisibleChunksAvailable:n.numVisibleChunksAvailable,numVisibleChunksNeeded:n.numVisibleChunksNeeded,numPrefetchChunksAvailable:n.numPrefetchChunksAvailable,numPrefetchChunksNeeded:n.numPrefetchChunksNeeded}))})},Ei)),this.queueManager=t.get(e.chunkQueueManager).addRef(),this.registerDisposer(this.queueManager.gpuMemoryChanged.add(this.registerCancellable((0,z.A)(()=>this.scheduleUpdateChunkPriorities(),Ei,{leading:!1,trailing:!0}))));for(let n=se.FIRST_TIER;n<=se.LAST_TIER;++n)n!==se.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([se.VISIBLE,se.PREFETCH]),this.sendLayerChunkStatistics()}requestChunk(t,e,n,s=M.GPU_MEMORY){if(Number.isNaN(n))return;if(e===se.RECENT)throw new Error("Not going to request a chunk with the RECENT tier");t.newRequestedState=Math.min(t.newRequestedState,s),t.newPriorityTier===se.RECENT&&this.newTierChunks.push(t);const i=t.newPriorityTier;(e<i||e===i&&n>t.newPriority)&&(t.newPriorityTier=e,t.newPriority=n)}updateQueueState(t){const e=this.existingTierChunks,n=this.queueManager;for(const i of t){const r=e[i];St&&console.log(`existingTierChunks[${se[i]}].length=${r.length}`);for(const o of r)o.newPriorityTier===se.RECENT&&n.performChunkPriorityUpdate(o);r.length=0}const s=this.newTierChunks;for(const i of s)n.performChunkPriorityUpdate(i),e[i.priorityTier].push(i);St&&console.log(`updateQueueState: newTierChunks.length = ${s.length}`),s.length=0,this.queueManager.scheduleUpdate()}};ki=tt([O(le)],ki);function Ve(t,e){let n=class extends t{constructor(...s){super(...s);const i=s[1];this.parameters=i.parameters}};return n=tt([X(e.RPC_ID)],n),n}function bt(t){return class extends t{constructor(...e){super(...e);const n=e[0],s=e[1];this.chunkManager=n.get(s.chunkManager)}}}Q(ie,function(t){const e=this.get(t.id);e.chunkManager.queueManager.invalidateSourceCache(e)}),We(he,function(t){const e=this.get(t.queue),n=new Map;for(const s of e.sources)n.set(s.rpcId,s.statistics);return Promise.resolve({value:n})});var xn=x(3517),dc=Object.defineProperty,hc=Object.getOwnPropertyDescriptor,fc=(t,e,n,s)=>{for(var i=s>1?void 0:s?hc(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&dc(e,n,i),i};/**
 * @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.
 */class pc extends Y.O8{constructor(e){super(),this.view=e,this.state=void 0}}class An extends ms{constructor(){super(...arguments),this.attachments=new Map}attach(e){}}Q(xn.sC,function(t){const e=this.get(t.view),n=this.get(t.layer),s=new pc(e);n.attachments.set(e,s),n.attach(s)}),Q(xn.lG,function(t){const e=this.get(t.view),n=this.get(t.layer),s=n.attachments.get(e);n.attachments.delete(e),s.dispose()});let Ti=class extends U{constructor(t,e){super(t,e),this.changed=new Ie.HN,this.value=e.value,this.oldValue=Object.assign({},this.value)}};Ti=fc([O(xn.Bh)],Ti),Q(xn.kg,function(t){const e=this.get(t.id),{value:n,oldValue:s}=e;Object.assign(s,n),Object.assign(n,t.value),e.changed.dispatch(s,n)});var mc=x(4104),k=x(7900),gc=x(310);/**
 * @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 Di{constructor(){this.width=0,this.height=0,this.logicalWidth=0,this.logicalHeight=0,this.visibleLeftFraction=0,this.visibleTopFraction=0,this.visibleWidthFraction=0,this.visibleHeightFraction=0}}function Ip(t,e){const n=1/t.visibleWidthFraction,s=1/t.visibleHeightFraction,i=-1-(-1+2*t.visibleLeftFraction)*n;let r=-1-(-1+2*t.visibleTopFraction)*s;r=-r,e[0]=e[0]*n+e[3]*i,e[4]=e[4]*n+e[7]*i,e[8]=e[8]*n+e[11]*i,e[12]=e[12]*n+e[15]*i,e[1]=e[1]*s+e[3]*r,e[5]=e[5]*s+e[7]*r,e[9]=e[9]*s+e[11]*r,e[13]=e[13]*s+e[15]*r}function Cp(t,e){return t.width===e.width&&t.height===e.height&&t.logicalWidth===e.logicalWidth&&t.logicalHeight===e.logicalHeight&&t.visibleLeftFraction===e.visibleLeftFraction&&t.visibleTopFraction===e.visibleTopFraction}class yc extends Y.O8{constructor(e,n,s){super(),this.context=e,this.element=n,this.visibility=s,this.boundsGeneration=-1,this.canvasRelativeClippedLeft=0,this.canvasRelativeClippedTop=0,this.canvasRelativeLogicalLeft=0,this.canvasRelativeLogicalTop=0,this.renderViewport=new Di,this.monitorState={},this.gl=e.gl,e.addPanel(this)}scheduleRedraw(){this.visible&&this.context.scheduleRedraw()}ensureBoundsUpdated(){const{context:e}=this;e.ensureBoundsUpdated();const{boundsGeneration:n}=e;if(n===this.boundsGeneration)return;this.boundsGeneration=n;const{element:s}=this,i=s.getBoundingClientRect();e.ensureMonitorPanel(s,this.monitorState,i);const r=e.container,o=e.canvasRect,{canvas:a}=e,{width:c,height:l}=a,u=c/o.width,d=l/o.height,h=o.left,p=o.top,m=this.canvasRelativeLogicalLeft=Math.round((i.left-h)*u+s.clientLeft),f=this.canvasRelativeLogicalTop=Math.round((i.top-p)*d+s.clientTop),b=s.clientWidth,I=s.clientHeight,E=m+b,V=f+I;let R=f,C=m,S=E,T=V;for(let y=s.parentElement;y!==null&&y!==r;y=y.parentElement){const A=y.getBoundingClientRect();A.x===0&&A.y===0&&A.width===0&&A.height===0||(C=Math.max(C,(A.left-h)*u),R=Math.max(R,(A.top-p)*d),S=Math.min(S,(A.right-h)*u),T=Math.min(T,(A.bottom-p)*d))}R=this.canvasRelativeClippedTop=Math.round(Math.max(R,0)),C=this.canvasRelativeClippedLeft=Math.round(Math.max(C,0)),S=Math.round(Math.min(S,c)),T=Math.round(Math.min(T,l));const v=this.renderViewport,N=v.width=Math.max(0,S-C),H=v.height=Math.max(0,T-R);v.logicalWidth=b,v.logicalHeight=I,v.visibleLeftFraction=(C-m)/b,v.visibleTopFraction=(R-f)/I,v.visibleWidthFraction=N/b,v.visibleHeightFraction=H/I}setGLClippedViewport(){const{gl:e,canvasRelativeClippedTop:n,canvasRelativeClippedLeft:s,renderViewport:{width:i,height:r}}=this,o=n+r;e.enable(WebGL2RenderingContext.SCISSOR_TEST);const a=this.context.canvas.height-o;e.viewport(s,a,i,r),e.scissor(s,a,i,r)}setGLLogicalViewport(){const{gl:e,renderViewport:{width:n,height:s,logicalWidth:i,logicalHeight:r}}=this,o=this.context.canvas.height;e.enable(WebGL2RenderingContext.SCISSOR_TEST),e.viewport(this.canvasRelativeLogicalLeft,o-(this.canvasRelativeLogicalTop+r),i,r),e.scissor(this.canvasRelativeClippedLeft,o-(this.canvasRelativeClippedTop+s),n,s)}disposed(){this.context.unmonitorPanel(this.element,this.monitorState),this.context.removePanel(this),super.disposed()}get visible(){return this.visibility.visible}getDepthArray(){}get shouldDraw(){if(!this.visible)return!1;const{element:e}=this;return!(e.clientWidth===0||e.clientHeight===0||e.offsetWidth===0||e.offsetHeight===0)}get drawOrder(){return 0}}class Ep extends yc{constructor(e,n,s){super(e,n,s),this.canvas=document.createElement("canvas"),this.canvasRenderingContext=this.canvas.getContext("2d");const{canvas:i}=this;n.appendChild(i),n.style.position="relative",i.style.position="absolute",i.style.left="0",i.style.right="0",i.style.top="0",i.style.bottom="0"}draw(){this.drawIndirect();const{renderViewport:e,canvas:n}=this,{logicalWidth:s,logicalHeight:i}=e;n.width=s,n.height=i;const{canvasRenderingContext:r}=this;r?.drawImage(this.context.canvas,this.canvasRelativeLogicalLeft,this.canvasRelativeLogicalTop,s,i,0,0,s,i)}}class kp extends ye.DN{constructor(){super(Float64Array.of(0,0,1,1),e=>(0,k.Xu)(new Float64Array(4),e,k.xU))}toJSON(){const{value:e}=this,[n,s,i,r]=e;if(!(n===0&&s===0&&i===1&&r===1))return Array.from(e)}}class Tp extends Y.O8{constructor(e){super(),this.container=e,this.canvas=document.createElement("canvas"),this.updateStarted=new Ie.IY,this.updateFinished=new Ie.IY,this.changed=this.updateFinished,this.panels=new Set,this.resizeGeneration=0,this.boundsGeneration=-1,this.orderedPanels=[],this.frameNumber=0,this.resizeCallback=()=>{++this.resizeGeneration,this.scheduleRedraw()},this.resizeObserver=new ResizeObserver(this.resizeCallback),this.scheduleRedraw=this.registerCancellable((0,mc.t)(()=>this.draw()));const{canvas:n,resizeObserver:s}=this;e.style.position="relative",n.style.position="absolute",n.style.top="0px",n.style.left="0px",n.style.width="100%",n.style.height="100%",n.style.zIndex="0",s.observe(n),e.appendChild(n),this.registerEventListener(n,"webglcontextlost",i=>{console.log(`Lost WebGL context: ${i.statusMessage}`),i.preventDefault()}),this.registerEventListener(n,"webglcontextrestored",()=>{console.log("WebGL context restored"),window.location.reload()}),this.gl=(0,gc.y)(n)}ensureMonitorPanel(e,n,s){n.addedToResizeObserver||(this.resizeObserver.observe(e),n.addedToResizeObserver=!0);const i=this.rootRect,r=i.top-s.top,o=i.left-s.left,a=s.right-i.right,c=s.bottom-i.bottom,l=`${r}px ${a}px ${c}px ${o}px`;n.intersectionObserverMargin!==l&&(n.intersectionObserverMargin=l,n.intersectionObserver?.disconnect(),(n.intersectionObserver=new IntersectionObserver(this.resizeCallback,{root:this.container,rootMargin:l,threshold:[.99,1]})).observe(e))}unmonitorPanel(e,n){n.addedToResizeObserver&&this.resizeObserver.unobserve(e),n.intersectionObserver?.disconnect()}applyWindowedViewportToElement(e,n){const[s,i,r,o]=n,a=1/r,c=1/o;e.style.position="absolute",e.style.top=`${-c*i*100}%`,e.style.left=`${-a*s*100}%`,e.style.width=`${a*100}%`,e.style.height=`${c*100}%`,++this.resizeGeneration,this.scheduleRedraw()}isReady(){for(const e of this.panels)if(e.visible&&!e.isReady())return!1;return!0}makeCanvasOverlayElement(){const e=document.createElement("div");return e.style.position="absolute",e.style.top="0px",e.style.left="0px",e.style.width="100%",e.style.height="100%",e.style.zIndex="2",this.container.appendChild(e),e}disposed(){this.orderedPanels.length=0,this.resizeObserver.disconnect()}addPanel(e){this.panels.add(e),this.orderedPanels.length=0,++this.resizeGeneration,this.scheduleRedraw()}removePanel(e){this.panels.delete(e),this.orderedPanels.length=0,++this.resizeGeneration,this.scheduleRedraw()}ensureBoundsUpdated(){const{resizeGeneration:e}=this;if(this.boundsGeneration===e)return;const{canvas:n}=this;n.width=n.offsetWidth,n.height=n.offsetHeight,this.canvasRect=n.getBoundingClientRect(),this.rootRect=this.container.getBoundingClientRect(),this.boundsGeneration=e}draw(){++this.frameNumber,this.updateStarted.dispatch();const e=this.gl;this.ensureBoundsUpdated(),this.gl.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const{orderedPanels:n,panels:s}=this;n.length!==s.size&&(n.push(...s),n.sort((i,r)=>i.drawOrder-r.drawOrder));for(const i of n){if(!i.shouldDraw)continue;i.ensureBoundsUpdated();const{renderViewport:r}=i;r.width===0||r.height===0||i.draw()}e.disable(e.SCISSOR_TEST),this.gl.clearColor(1,1,1,1),this.gl.colorMask(!1,!1,!1,!0),e.clear(e.COLOR_BUFFER_BIT),this.gl.colorMask(!0,!0,!0,!0),this.updateFinished.dispatch()}getDepthArray(){const{width:e,height:n}=this.canvas,s=new Float32Array(e*n);for(const i of this.panels){if(!i.shouldDraw)continue;const r=i.getDepthArray();if(r===void 0)continue;const{canvasRelativeClippedTop:o,canvasRelativeClippedLeft:a,renderViewport:{width:c,height:l}}=i;for(let u=0;u<l;++u){const d=(l-1-u)*c;s.set(r.subarray(d,d+c),(o+u)*c+a)}}return s}}var w=x(3038);/**
 * @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 Dp(t,e){const n=t.length;for(let s=0;s<n;++s)if(t[s]!==e[s])return!1;return!0}function Pi(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=e[i]+n[i];return t}function gs(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=e[i]-n[i];return t}function vc(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=e[i]*n[i];return t}function Pp(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=e[i]/n[i];return t}function wc(t,e,n,s){const i=t.length;for(let r=0;r<i;++r)t[r]=e[r]+n[r]*s;return t}function Rp(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=e[i]*n;return t}function Sc(t){let e=1;for(let n=0,s=t.length;n<s;++n)e*=t[n];return e}function bc(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=Math.min(e[i],n[i]);return t}function Ic(t,e,n){const s=t.length;for(let i=0;i<s;++i)t[i]=Math.max(e[i],n[i]);return t}const ys=new Float32Array(0),Ri=new Float64Array(0),_p=Float64Array.of(1,1,1);/**
 * @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.
 */class Cc extends Di{constructor(){super(...arguments),this.globalPosition=ys,this.projectionMat=w.pB.create(),this.viewMatrix=w.pB.create(),this.invViewMatrix=w.pB.create(),this.viewProjectionMat=w.pB.create(),this.invViewProjectionMat=w.pB.create()}}function Mp(t,e){return t.displayDimensionRenderInfo===e.displayDimensionRenderInfo&&renderViewportsEqual(t,e)&&arraysEqual(t.globalPosition,e.globalPosition)&&arraysEqual(t.projectionMat,e.projectionMat)&&arraysEqual(t.viewMatrix,e.viewMatrix)}function Op(t){const{viewMatrix:e,viewProjectionMat:n}=t;mat4.invert(e,t.invViewMatrix),mat4.multiply(n,t.projectionMat,e),mat4.invert(t.invViewProjectionMat,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 Ln=[{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:"\xB5",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"}],_i=[...Ln,{prefix:"h",exponent:2,longPrefix:"hecto"},{prefix:"da",exponent:1,longPrefix:"deca"},{prefix:"d",exponent:-1,longPrefix:"deci"},{prefix:"c",exponent:-2,longPrefix:"centi"}],Ec=[{prefix:"u",exponent:-6},..._i],pn=new Map;pn.set("",{unit:"",exponent:0});const kc=new Map;for(const{prefix:t,exponent:e}of Ec){kc.set(e,t);for(const n of["m","s","Hz","rad/s"])pn.set(`${t}${n}`,{unit:n,exponent:e})}function Tc(t){const e=Math.log10(t),n=Ln.length,s=binarySearchLowerBound(0,n,i=>Ln[i].exponent<=e);return Ln[Math.min(s,n-1)]}function Dc(t,e,n={}){const{precision:s=6,elide1:i=!0}=n;let r=t,o="";if(e!==""){const c=Tc(t);o=c.prefix,r=Mi(t,-c.exponent)}if(i&&r===1)return{scale:"",unit:e,prefix:o};let a;if(s!==0){r<1||r>=1e3?a=r.toPrecision(s):a=r.toFixed(s);const c=a.indexOf("e");let l,u;c!==-1?(l=a.substring(0,c),u=a.substring(c)):(l=a,u="");const d=l.match(/.*\.(?:[0-9]*[1-9])?(0+)$/);d!==null&&(l=l.substring(0,l.length-d[1].length),l.endsWith(".")&&(l=l.substring(0,l.length-1)),a=l+u)}else a=r.toString();return{scale:a,unit:e,prefix:o}}function Np(t,e,n){const{scale:s,unit:i,prefix:r}=Dc(t,e,n);return`${s}${r}${i}`}function xp(t){if(t==="")return{scale:1,unit:""};const e=t.match(/^((?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)?([µa-zA-Z]+)?$/);if(e===null)return;const n=e[1];let s=n===void 0?1:Number(n);if(Number.isNaN(s))return;let i="";if(e[2]!==void 0){const r=pn.get(e[2]);if(r===void 0)return;i=r.unit,r.exponent>0?s*=10**r.exponent:s/=10**-r.exponent}if(!(s<=0||!Number.isFinite(s)))return{scale:s,unit:i}}function Ap(t){const e=pn.get(t);if(e===void 0)throw new Error(`Invalid unit: ${JSON.stringify(t)}`);return e}function Mi(t,e){return e>=0?t*10**e:t/10**-e}/**
 * @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 Pc=0;function Oi(){return++Pc}function Rc(t,e){return arraysEqual(t.lowerBounds,e.lowerBounds)&&arraysEqual(t.upperBounds,e.upperBounds)}function _c(t,e){return t===void 0?e===void 0:e===void 0?!1:t.explicit===e.explicit&&arraysEqual(t.coordinates,e.coordinates)&&arraysEqual(t.labels,e.labels)}function Mc(t,e){const n=new Map;for(let s=0,i=t.length;s<i;++s)n.set(t[s],e[s]);return t=Array.from(n.keys()),t.sort((s,i)=>s-i),e=Array.from(t,s=>n.get(s)),{coordinates:t,labels:e}}function Ni(t){if(t.length===1)return t[0];const e=new Map;let n=!1;for(const r of t){r.explicit&&(n=!0);const{coordinates:o,labels:a}=r;for(let c=0,l=o.length;c<l;++c)e.set(o[c],a[c])}const s=Array.from(e.keys());s.sort((r,o)=>r-o);const i=Array.from(s,r=>e.get(r));return{explicit:n,coordinates:s,labels:i}}function xi(t){if(t=t.filter(e=>e!==void 0),t.length!==0)return Ni(t)}function Oc(t,e){return arraysEqual(t.transform,e.transform)&&Rc(t.box,e.box)}function Un(t,e){return t.valid===e.valid&&t.rank===e.rank&&arraysEqual(t.names,e.names)&&arraysEqual(t.ids,e.ids)&&arraysEqual(t.timestamps,e.timestamps)&&arraysEqual(t.units,e.units)&&arraysEqual(t.scales,e.scales)&&arraysEqualWithPredicate(t.boundingBoxes,e.boundingBoxes,Oc)&&arraysEqualWithPredicate(t.coordinateArrays,e.coordinateArrays,_c)}function Lp(t,e,n){parseFixedLengthArray(t,n,(s,i)=>{const r=unitFromJson(s);return e[i]=r.exponent,r.unit})}function st(t){const{names:e,units:n,scales:s}=t,{valid:i=!0,rank:r=e.length,timestamps:o=e.map(()=>Number.NEGATIVE_INFINITY),ids:a=e.map((d,h)=>-h),boundingBoxes:c=[]}=t,{coordinateArrays:l=new Array(r)}=t,{bounds:u=Bc(c,r)}=t;return{valid:i,rank:r,names:e,timestamps:o,ids:a,units:n,scales:s,boundingBoxes:c,bounds:u,coordinateArrays:l}}const Wt=st({valid:!1,names:[],units:[],scales:Ri,boundingBoxes:[]}),Nc=st({valid:!0,names:[],units:[],scales:Ri,boundingBoxes:[]});function xc(t){const[e,n]=(0,k.J6)(t,2),s=(0,k.Mo)(e),i=(0,k.zr)(n),r=pn.get(i);if(r===void 0)throw new Error(`Invalid unit: ${JSON.stringify(i)}`);return{unit:r.unit,scale:Mi(s,r.exponent)}}function vs(t,e=!1){if(t===void 0)return Wt;(0,k.Rf)(t);const n=zi(Object.keys(t),e),s=n.length,i=new Array(s),r=new Float64Array(s),o=new Array(s);for(let a=0;a<s;++a)(0,k.cQ)(t,n[a],c=>{if(Array.isArray(c)){const{unit:l,scale:u}=xc(c);i[a]=l,r[a]=u}else{(0,k.Rf)(c);const l=(0,k.cQ)(c,"coordinates",k.VH),u=(0,k.cQ)(c,"labels",k.si),d=l.length;if(d!==u.length)throw new Error(`Length of coordinates array (${d}) does not match length of labels array (${u.length})`);i[a]="",r[a]=1,o[a]={explicit:!0,...Mc(l,u)}}});return st({valid:!1,names:n,units:i,scales:r,coordinateArrays:o})}function ws(t){const{rank:e}=t;if(e===0)return;const{names:n,units:s,scales:i,coordinateArrays:r}=t,o={};for(let a=0;a<e;++a){const c=n[a],l=r[a];l?.explicit?o[c]={coordinates:Array.from(l.coordinates),labels:l.labels}:o[c]=[i[a],s[a]]}return o}class Up extends ye.B0{constructor(){super(Wt)}toJSON(){return ws(this.value)}reset(){this.value=Wt}restoreState(e){this.value=vs(e)}}function Ac(t,e,n){return t.voxelCenterAtIntegerCoordinates[e]?n=Math.round(n):n=Math.floor(n)+.5,n}function Vp(t,e){let n=t.lowerBounds[e],s=t.upperBounds[e];return t.voxelCenterAtIntegerCoordinates[e]&&(n+=.5,s+=.5),[n,s]}function Lc(t,e,n){const s=t.upperBounds[e];Number.isFinite(s)&&(n=Math.min(n,s-1));const i=t.lowerBounds[e];return Number.isFinite(i)&&(n=Math.max(n,i)),n}function Ai(t,e,n){return n=Lc(t,e,n),Ac(t,e,n)}function Li(t,e){let n=(t+e)/2;return Number.isFinite(n)||(n=Math.min(Math.max(0,t),e)),n}function Uc(t,e){const{lowerBounds:n,upperBounds:s}=e,i=t.length;for(let r=0;r<i;++r)t[r]=Li(n[r],s[r]);return t}function Bp(t){const e=t.lowerBounds.length;return{box:t,transform:matrix.createIdentity(Float64Array,e,e+1)}}function Vc(t,e,n){const{box:{lowerBounds:s,upperBounds:i},transform:r}=t,o=s.length,a=n,c=r[a*o+e];let l=c,u=c,d=!1;for(let h=0;h<o;++h){const p=r[a*h+e];if(p===0)continue;const m=p*s[h],f=p*i[h];l+=Math.min(m,f),u+=Math.max(m,f),d=!0}if(d)return{lower:l,upper:u}}function Bc(t,e){const n=new Float64Array(e),s=new Float64Array(e);n.fill(Number.NEGATIVE_INFINITY),s.fill(Number.POSITIVE_INFINITY);const i=new Array(e);i.fill(0);const r=new Array(e);r.fill(0);for(const a of t)for(let c=0;c<e;++c){const l=Vc(a,c,e);if(l===void 0)continue;const{lower:u,upper:d}=l;if(Number.isFinite(u)&&Number.isFinite(d)){const h=Math.floor(u),p=Math.floor(d);h===u&&p===d?++r[c]:u-h===.5&&d-p===.5&&++i[c]}n[c]=n[c]===Number.NEGATIVE_INFINITY?u:Math.min(n[c],u),s[c]=s[c]===Number.POSITIVE_INFINITY?d:Math.max(s[c],d)}const o=r.map((a,c)=>i[c]>0&&a===0);return{lowerBounds:n,upperBounds:s,voxelCenterAtIntegerCoordinates:o}}function $c(t,e,n){const{transform:s,box:i}=t,r=n.length,o=i.lowerBounds.length,a=new Float64Array((o+1)*e);for(let c=0;c<r;++c){const l=n[c];if(l!==-1)for(let u=0;u<=o;++u)a[u*e+l]=s[u*r+c]}return{transform:a,box:i}}function zc(t,e){const n={lowerBounds:Float64Array.of(0),upperBounds:Float64Array.of(1)},s=new Float64Array(2*t);return s[e]=1,{transform:s,box:n}}function Fc(t,e,n){if(e===n)return t;const{box:s}=t,i=s.lowerBounds.length,r=new Float64Array((i+1)*n);return matrix.copy(r,n,t.transform,e,e,i+1),{box:s,transform:r}}function $p(t,e){const{rank:n,sourceRank:s}=t;if(n!==e.rank||s!==e.sourceRank)return!1;const{inputSpace:i}=t,{inputSpace:r}=e;return!arraysEqual(r.scales,i.scales)||!arraysEqual(r.units,i.units)||!arraysEqual(e.outputSpace.names,t.outputSpace.names)?!1:Bi(t.transform,n,t.outputSpace.scales,e.transform,n,e.outputSpace.scales)}function zp(t){return{rank:t.rank,sourceRank:t.rank,inputSpace:t,outputSpace:t,transform:matrix.createIdentity(Float64Array,t.rank+1)}}function Gc(t,e,n,s){const{transform:i,box:r}=t,o=t.box.lowerBounds.length,a=s.length,c=new Float64Array((o+1)*a);for(let l=0;l<a;++l){const u=s[l];for(let h=0;h<o;++h){let p=0;for(let m=0;m<a;++m){const f=n[m];p+=e[(a+1)*m+l]*i[a*h+m]*(f/u)}c[a*h+l]=p}let d=e[(a+1)*a+l];for(let h=0;h<a;++h){const p=n[h];d+=e[(a+1)*h+l]*i[a*o+h]*(p/u)}c[o*a+l]=d}return{transform:c,box:r}}function Ui(t,e,n){return t.boundingBoxes.map(s=>Gc(s,e,t.scales,n))}function Ss(t,e,n){const s=st({valid:t.valid,rank:n.rank,ids:n.ids,names:n.names,timestamps:n.timestamps,scales:n.scales,units:n.units,boundingBoxes:Ui(t,e,n.scales),coordinateArrays:n.coordinateArrays});return Un(s,n)?n:s}function bs(t,e=!1){if(e){const n=Number(t);if(Number.isInteger(n)&&n>=0)return!0}return t.match(/^[a-zA-Z][a-zA-Z_0-9]*['^]?$/)!==null}function Vi(t,e=!1){const n=new Set;for(const s of t){if(!bs(s,e)||n.has(s))return!1;n.add(s)}return!0}function jc(t){const e=t.length,n=new Array(e);n.fill(!0);for(let s=0;s<e;++s){const i=t[s];if(!bs(i)){n[s]=!1;continue}const r=t.indexOf(i,s+1);r!==-1&&(n[s]=!1,n[r]=!1)}return n}function Fp(t){return t.endsWith("'")}function Yc(t){return t.endsWith("'")||t.endsWith("^")}function Gp(t){return t.endsWith("^")}function jp(t){return!Yc(t)}function Jc(t,e,n){const s=new Float64Array(t),i=e.length,r=(i+1)*i;for(let o=0;o<i;++o)s[r+o]*=e[o]/n[o];return s}function Bi(t,e,n,s,i,r){if(!matrix.equal(t,e+1,s,i+1,e,e))return!1;for(let o=0;o<e;++o){const a=t[(e+1)*e+o],c=s[(i+1)*i+o];if(a*(n[o]/r[o])!==c)return!1}for(let o=e;o<i;++o)if(s[(i+1)*i+o]!==0)return!1;for(let o=e;o<i;++o){for(let a=0;a<e;++a)if(s[(i+1)*a+o]!==0)return!1;for(let a=0;a<i;++a){const c=s[(i+1)*o+a];if(o===a){if(c!==1)return!1}else if(c!==0)return!1}}return!0}function Hc(t,e){if(!e.includes(t))return t;const[,n,s]=t.match(/^([^']*)('?)$/);for(let i=0;;++i){const r=`${n}${i}${s}`;if(!e.includes(r))return r}}function Wc(t,e){const{inputSpace:n,transform:s}=t,{ids:i,rank:r}=n,{rank:o,names:a,units:c,scales:l}=e,u=new Array(r);u.fill(!0);const d=[],h=e.ids.map((G,ue)=>{const we=i.indexOf(G);return we!==-1?u[we]=!1:d.push(ue),we}),{outputSpace:p}=t,{names:m,units:f,scales:b,ids:I,timestamps:E,coordinateArrays:V}=p,R=u,C=[],S=[],T=new Float64Array(o),v=[],N=[],H=new Array(o);let y=0;const A=new Float64Array((o+1)**2);A[A.length-1]=1;for(let G=0;G<r;++G)if(!R[G]){C[y]=m[G],v[y]=I[G],S[y]=f[G],T[y]=b[G],N[y]=E[G],H[y]=V[G];for(let ue=0;ue<o;++ue){const we=h[ue];we!==-1&&(A[ue*(o+1)+y]=s[we*(r+1)+G])}A[o*(o+1)+y]=s[r*(r+1)+G],++y}for(const G of d)v[y]=Oi(),C[y]=Hc(a[G],C),T[y]=l[G],S[y]=c[G],A[G*(o+1)+y]=1,++y;const L=st({valid:e.valid,rank:o,names:C,ids:v,timestamps:N,units:S,scales:T,boundingBoxes:Ui(e,A,T),coordinateArrays:H});return{rank:o,sourceRank:t.sourceRank,inputSpace:e,outputSpace:L,transform:A}}function $i(t){const e=Ss(t.inputSpace,t.transform,t.outputSpace);return e===t.outputSpace?t:{rank:t.rank,sourceRank:t.sourceRank,inputSpace:t.inputSpace,transform:t.transform,outputSpace:e}}class Yp{constructor(e,n=!1){this.mutableSourceRank=n,this.value_=void 0,this.changed=new NullarySignal,this.inputSpaceChanged=new NullarySignal,this.defaultTransform=$i(e);const s=this;this.outputSpace={changed:s.changed,get value(){return s.value.outputSpace},set value(i){const{value:r}=s;if(Un(r.outputSpace,i)||r.rank!==i.rank)return;const o=Jc(r.transform,r.outputSpace.scales,i.scales);s.value_={sourceRank:r.sourceRank,rank:r.rank,inputSpace:r.inputSpace,outputSpace:Ss(r.inputSpace,o,i),transform:o},s.changed.dispatch()}},this.inputSpace={changed:s.inputSpaceChanged,get value(){return s.value.inputSpace},set value(i){const{value:r}=s;Un(r.inputSpace,i)||(s.value_=Wc(r,i),s.inputSpaceChanged.dispatch(),s.changed.dispatch())}}}set value(e){const n=this.value;e!==n&&(this.value_=$i(e),e.inputSpace!==n.inputSpace&&this.inputSpaceChanged.dispatch(),this.changed.dispatch())}get value(){let{value_:e}=this;return e===void 0&&(e=this.value_=this.defaultTransform),e}reset(){this.value_!==this.defaultTransform&&(this.value_=this.defaultTransform,this.inputSpaceChanged.dispatch(),this.changed.dispatch())}get defaultInputSpace(){return this.defaultTransform.inputSpace}get spec(){const{value:e}=this,{rank:n,transform:s,inputSpace:i,outputSpace:r,sourceRank:o}=e,{defaultTransform:a,mutableSourceRank:c}=this,{inputSpace:l,rank:u,transform:d,outputSpace:h}=a,{units:p,scales:m}=i,f=o===n&&arraysEqual(m,c?r.scales:l.scales)&&arraysEqual(p,c?r.units:l.units),b=Bi(d,u,h.scales,s,n,r.scales),I=arraysEqual(h.names,r.names);if(!(b&&I&&f))return{sourceRank:o,transform:b?void 0:s,outputSpace:e.outputSpace,inputSpace:f?void 0:i}}set transform(e){const{value:n}=this,{inputSpace:s}=n;this.value_={rank:n.rank,sourceRank:n.sourceRank,inputSpace:s,transform:e,outputSpace:Ss(s,e,n.outputSpace)},this.changed.dispatch()}set spec(e){if(e===void 0){this.reset();return}if(this.mutableSourceRank){const y=e.inputSpace||e.outputSpace,A=y.rank,L=st({rank:A,names:y.names.map((G,ue)=>`${ue}`),units:y.units,scales:y.scales,coordinateArrays:y.coordinateArrays});this.value={rank:A,transform:e.transform||matrix.createIdentity(Float64Array,A+1),sourceRank:e.sourceRank,outputSpace:e.outputSpace,inputSpace:L};return}const{inputSpace:n,sourceRank:s,outputSpace:i,transform:r,rank:o}=this.defaultTransform,{inputSpace:a,sourceRank:c,outputSpace:l,transform:u}=e,d=e.outputSpace.rank,h=n.names,p=a!==void 0?a.names:h,m=new Array(s);for(let y=0;y<s;++y){let A=p.indexOf(h[y]);A>=c&&(A=-1),m[y]=A}const f=d-c+s;for(let y=c;y<d;++y)m[s+y-c]=y;const b=new Float64Array(f),I=new Array(f),E=[];for(let y=0;y<s;++y){const A=m[y];A===-1||a===void 0?(b[y]=n.scales[y],E[y]=n.units[y],I[y]=n.coordinateArrays[y]):(b[y]=a.scales[A],E[y]=a.units[A],I[y]=xi([n.coordinateArrays[y],a.coordinateArrays[A]]))}const V=a||l,R=h.slice(0,s),C=i.names.slice(0,s),S=i.coordinateArrays.slice(0,s),T=new Float64Array(f),v=[];for(let y=0;y<f;++y){const A=m[y];A===-1?(T[y]=i.scales[y],v[y]=i.units[y],S[y]=i.coordinateArrays[y]):(C[y]=l.names[A],v[y]=l.units[A],T[y]=l.scales[A],S[y]=l.coordinateArrays[A])}if(!Vi(C)){this.reset();return}for(let y=s;y<f;++y){const A=y-s+c;b[y]=V.scales[A],E[y]=V.units[A],R[y]=`${y}`}const N=new Float64Array((f+1)**2);N[N.length-1]=1;for(let y=0;y<f;++y){const A=m[y];let L;A===-1||u===void 0?y>=s?L=0:L=r[o*(o+1)+y]*(i.scales[y]/T[y]):L=u[d*(d+1)+A],N[f*(f+1)+y]=L;for(let G=0;G<f;++G){const ue=m[G];let we;A===-1!=(ue===-1)?we=0:A===-1||u===void 0?A>=s||ue>=s?we=A===ue?1:0:we=r[G*(o+1)+y]:we=u[ue*(d+1)+A],N[G*(f+1)+y]=we}}const H=n.boundingBoxes.map(y=>Fc(y,o,f));for(let y=s;y<f;++y)H.push(zc(f,y));for(let y=0;y<f;++y){if(N[f*(f+1)+y]!==0)continue;let L;for(let ue=0;ue<f;++ue){const we=N[ue*(f+1)+y];if(we!==0)if(we===1)if(L===void 0)L=ue;else{L=null;break}else{L=null;break}}if(L==null)continue;let G=I[L];G!==void 0&&(G.explicit&&(G={...G,explicit:!1}),S[y]=xi([G,S[y]]))}this.value={rank:f,transform:N,sourceRank:s,outputSpace:st({rank:f,names:C,scales:T,units:v,coordinateArrays:S}),inputSpace:st({rank:f,names:R,scales:b,units:E,coordinateArrays:I,boundingBoxes:H})}}toJSON(){return Qc(this.spec)}restoreState(e){this.spec=qc(e)}}function Kc(t,e=!1){const n=(0,k.zr)(t);if(!bs(n,e))throw new Error(`Invalid dimension name: ${JSON.stringify(n)}`);return n}function zi(t,e=!1){const n=(0,k.$v)(t,s=>Kc(s,e));if(!Vi(n,e))throw new Error(`Invalid dimensions: ${JSON.stringify(n)}`);return n}class Jp{constructor(e,n){this.combined=e,this.bindings=new Set,this.retainCount=0,this.prevCombined=this.combined.value,this.dimensionRefCounts=new Map,this.handleCombinedChanged=()=>{this.combined.value!==this.prevCombined&&this.update()},this.includeDimensionPredicate_=n}getRenameValidity(e){const n=this.combined.value.names,s=jc(e),i=e.length;for(let r=0;r<i;++r){if(!s[r])continue;const o=e[r];if(n.includes(o))continue;let a=!0;for(const c of this.bindings)if(c.space.value.names.includes(o)){a=!1;break}s[r]=a}return s}get includeDimensionPredicate(){return this.includeDimensionPredicate_}set includeDimensionPredicate(e){this.includeDimensionPredicate_=e,this.update()}update(){const{combined:e,bindings:n}=this,s=this.retainCount>0?1:0;if(n.size===0&&!s){e.value=Wt;return}const i=this.includeDimensionPredicate_,r=e.value;let o=Array.from(r.names),a=Array.from(r.units),c=Array.from(r.scales),l=Array.from(r.ids),u=Array.from(r.timestamps),d=r.names.map(()=>s?1:0);const h=[];let p=!1;for(const C of n){const{space:{value:S},prevValue:T,mappedDimensionIds:v}=C;p=p||S.valid;const{names:N,units:H,scales:y,ids:A,timestamps:L}=S,G=[],ue=[];h.push(ue),C.mappedDimensionIds=G,C.prevValue=S;const we=N.length;for(let fe=0;fe<we;++fe){const Fe=N[fe];if(!i(Fe))continue;if(T!==void 0){const Pn=A[fe],un=T.ids.indexOf(Pn);if(un!==-1){const Gt=v[un];if(Gt!==void 0){const rt=l.indexOf(Gt);if(rt!==-1){G[fe]=Gt,++d[rt],ue[fe]=rt;const yt=L[fe];yt!==void 0&&!(yt<=u[rt])&&(o[rt]=Fe,c[rt]=y[fe],a[rt]=H[fe],u[rt]=yt);continue}}}}let $e=o.indexOf(Fe);if($e!==-1){G[fe]=l[$e],++d[$e],ue[fe]=$e;continue}$e=o.length,ue[fe]=$e,d[$e]=1+s,o[$e]=Fe,a[$e]=H[fe],c[$e]=y[fe],u[$e]=L[fe];const Nt=Oi();l[$e]=Nt,G[fe]=Nt}}const{dimensionRefCounts:m}=this;m.clear();let f=0,b=o.length;for(const C of n){const{space:{value:S}}=C,T=h[f++],{rank:v}=S,N=Array.from(S.names),H=Array.from(S.timestamps),y=Float64Array.from(S.scales),A=Array.from(S.units);for(let L=0;L<v;++L){const G=T[L];G!==void 0&&(A[L]=a[G],y[L]=c[G],H[L]=u[G],N[L]=o[G])}for(const L of N){let G=m.get(L);G===void 0?G=1:++G,m.set(L,G)}if(!arraysEqual(A,S.units)||!arraysEqual(y,S.scales)||!arraysEqual(N,S.names)||!arraysEqual(H,S.timestamps)){const L=st({valid:S.valid,ids:S.ids,scales:y,units:A,names:N,timestamps:H,boundingBoxes:S.boundingBoxes,coordinateArrays:S.coordinateArrays});C.prevValue=L,C.space.value=L}}{for(let S=0;S<b;++S)i(o[S])||(d[S]=0);const C=(S,T)=>d[T]!==0;o=o.filter(C),a=a.filter(C),c=c.filter(C),l=l.filter(C),u=u.filter(C),d=d.filter(C),b=o.length}const I=[],E=new Array(b);for(let C=0,S=r.rank;C<S;++C){const T=r.coordinateArrays[C];if(!T?.explicit)continue;const v=l.indexOf(r.ids[C]);v!==-1&&(E[v]=[T])}for(const C of n){const{space:{value:S}}=C,{rank:T,boundingBoxes:v,coordinateArrays:N}=S,H=S.names.map(y=>o.indexOf(y));for(const y of v)I.push($c(y,b,H));for(let y=0;y<T;++y){const A=N[y];if(A===void 0)continue;const L=H[y],G=E[L];G===void 0?E[L]=[A]:G.push(A)}}const V=new Array(b);for(let C=0;C<b;++C){const S=E[C];S!==void 0&&(V[C]=Ni(S))}const R=st({valid:p,ids:l,names:o,units:a,scales:new Float64Array(c),boundingBoxes:I,coordinateArrays:V});if(s)for(let C=0;C<b;++C)--d[C];Un(r,R)||(this.prevCombined=R,e.value=R)}retain(){return++this.retainCount,()=>{--this.retainCount===0&&this.update()}}bind(e){const n={space:e,mappedDimensionIds:[],prevValue:void 0},{bindings:s}=this;s.size===0&&this.combined.changed.add(this.handleCombinedChanged),s.add(n);const i=e.changed.add(()=>{e.value!==n.prevValue&&this.update()}),r=()=>{i();const{bindings:o}=this;o.delete(n),o.size===0&&this.combined.changed.remove(this.handleCombinedChanged),this.update()};return this.update(),r}}function Hp(t,e,n,s,i){const r=i.length,o=new t((r+1)**2);o[o.length-1]=1;for(let a=0;a<r;++a){const c=s[a];o[(r+1)*r+a]=e[(n+1)*n+c];for(let l=0;l<r;++l){const u=i[l];o[(r+1)*l+a]=e[(n+1)*u+c]}}return o}function Wp(t){if(t===void 0)return;const e=new Float64Array(16);if(Array.isArray(t))if(t.length===16)for(let n=0;n<4;++n)for(let s=0;s<4;++s)e[n*4+s]=verifyFiniteFloat(t[s*4+n]);else{expectArray(t,4);for(let n=0;n<4;++n){const s=expectArray(t[n],4);for(let i=0;i<4;++i)e[i*4+n]=verifyFiniteFloat(s[i])}}else{verifyObject(t);const n=quat.create(),s=vec3.create(),i=vec3.fromValues(1,1,1);verifyOptionalObjectProperty(t,"rotation",o=>{parseFiniteVec(n,o),quat.normalize(n,n)}),verifyOptionalObjectProperty(t,"translation",o=>{parseFiniteVec(s,o)}),verifyOptionalObjectProperty(t,"scale",o=>{parseFiniteVec(i,o)});const r=mat4.create();mat4.fromRotationTranslationScale(r,n,s,i),e.set(r)}return{sourceRank:3,transform:e,outputSpace:st({valid:!0,names:["x","y","z"],units:["m","m","m"],scales:Float64Array.of(1e-9,1e-9,1e-9)}),inputSpace:void 0}}function qc(t){if(t===void 0)return;const e=verifyObject(t),n=verifyObjectProperty(e,"outputDimensions",vs),s=n.rank,i=verifyObjectProperty(e,"sourceRank",a=>{if(a===void 0)return s;if(!Number.isInteger(a)||a<0||a>s)throw new Error(`Expected integer in range [0, ${s}] but received: ${JSON.stringify(a)}`);return a}),r=verifyOptionalObjectProperty(e,"inputDimensions",a=>{const c=vs(a,!0);if(c.rank!==s)throw new Error(`Expected rank of ${s}, but received rank of: ${c.rank}`);return c});return{transform:verifyOptionalObjectProperty(e,"matrix",a=>{const c=new Float64Array((s+1)**2),l=expectArray(a,s);c[c.length-1]=1;for(let u=0;u<s;++u)try{const d=expectArray(l[u],s+1);for(let h=0;h<=s;++h)c[(s+1)*h+u]=verifyFiniteFloat(d[h])}catch(d){throw new Error(`Error in row ${u}: ${d.message}`)}return c}),outputSpace:n,inputSpace:r,sourceRank:i}}function Qc(t){if(t===void 0)return;const{transform:e,outputSpace:n,inputSpace:s,sourceRank:i}=t;let r;const o=n.rank;if(e!==void 0){r=[];for(let a=0;a<o;++a){const c=[];r[a]=c;for(let l=0;l<=o;++l)c[l]=e[(o+1)*l+a]}}return{sourceRank:i===o?void 0:i,matrix:r,outputDimensions:ws(n),inputDimensions:s===void 0?void 0:ws(s)}}function Xc(t,e,n){const{box:s,transform:i}=t,r=t.box.lowerBounds.length,o=e.length,a=new Float64Array((r+1)*o);if(matrix.permuteRows(a,o,i,n,e,r+1),!a.every(c=>c===0))return{transform:a,box:s}}function Zc(t,e){const{ids:n,names:s,scales:i,units:r,timestamps:o,coordinateArrays:a}=t;return st({rank:e.length,valid:t.valid,ids:e.map(c=>n[c]),names:e.map(c=>s[c]),timestamps:e.map(c=>o[c]),scales:Float64Array.from(e,c=>i[c]),units:e.map(c=>r[c]),coordinateArrays:e.map(c=>a[c]),boundingBoxes:t.boundingBoxes.map(c=>Xc(c,e,t.rank)).filter(c=>c!==void 0)})}function Kp(t,e,n){return e===n?t:Zc(t,getInsertPermutation(t.rank,n,e))}function qp(t,e){const{transform:n,rank:s}=t,i=getDependentTransformInputDimensions(n,s,[e]);if(i.length!==1)return;const[r]=i,o=Math.abs(n[(s+1)*r+e]),{inputSpace:a}=t;return{scale:a.scales[r]*o,unit:a.units[r]}}function Qp(t,e){const{scales:n,units:s}=t.defaultInputSpace;return e<n.length?{scale:n[e],unit:s[e]}:void 0}/**
 * @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 Xp={channelCoordinateSpace:Nc,shape:new Uint32Array(0),numChannels:1,coordinates:new Uint32Array(0)};function Zp(t){const{rank:e}=t,{bounds:{lowerBounds:n,upperBounds:s}}=t;if(n.some(a=>a!==0))throw new Error("Lower bounds of channel coordinate space must all be 0");if(s.some(a=>!Number.isInteger(a)||a<=0||a>=4294967296))throw new Error("Upper bounds of channel coordinate space must all be positive integers");const i=new Uint32Array(s),r=prod(i),o=new Uint32Array(r*e);for(let a=0;a<r;++a){let c=a;for(let l=0;l<e;++l){const u=c%i[l];c=(c-u)/i[l],o[a*e+l]=u}}return{channelCoordinateSpace:t,shape:i,numChannels:r,coordinates:o}}function Is(t,e,n,s,i,r){const{scales:o}=n,{scales:a,rank:c}=i,l=e+1;for(let u=0;u<c;++u){const d=r[u];if(d===-1)continue;const h=a[u];for(let p=0;p<e;++p){const m=s[p],f=o[m];t[l*p+d]*=f/h}}}function el(t,e,n,s,i=emptyValidCoordinateSpace){const{inputSpace:r,rank:o,sourceRank:a,outputSpace:c,transform:l}=n,{names:u}=r,{names:d}=c;let h;if(s!==void 0)h=Array.from(s.modelSubspaceDimensionIndices);else{h=[];for(let L=0;L<a;++L)h[L]=L}const p=h.length;for(let L=a;L<o;++L)h.push(L);const m=getDependentTransformInputDimensions(n.transform,o,h,!0),f=h.length,b=h.map(L=>u[L]||`${L}`),I=m.map(L=>d[L]);if(f!==m.length)return{error:"Rank mismatch between model subspace dimensions ("+b.join(", ")+") and corresponding layer/global dimensions ("+I.join(", ")+")"};let E=homogeneousTransformSubmatrix(Float32Array,l,o,m,h);const V=m.map(L=>d[L]),R=e.names.map(L=>V.indexOf(L)),C=t.names.map(L=>V.indexOf(L));Is(E,f,r,h,t,C),Is(E,f,r,h,e,R);const S=i.names.map(L=>V.indexOf(L));Is(E,f,r,h,i,S);const T=[],v=i.rank;if(s!==void 0){let{subsourceToModelSubspaceTransform:L}=s;p!==f&&(L=matrix.extendHomogeneousTransform(new Float32Array((f+1)**2),f,L,p)),E=matrix.multiply(new Float32Array((f+1)**2),f+1,E,f+1,L,f+1,f+1,f+1,f+1)}const N=new Uint32Array(v),{lowerBounds:H,upperBounds:y,voxelCenterAtIntegerCoordinates:A}=i.bounds;for(let L=0;L<v;++L){let G=H[L],ue=y[L];if(A[L]&&(G+=.5,ue+=.5),G!==0||!Number.isInteger(ue)||ue<=0||ue>=4294967296)return{error:`Channel dimension ${i.names[L]} must have lower bound of 0 and positive integer upper bound; current bounds are [${G}, ${ue}]`};N[L]=ue;const we=S[L];let fe=-1;if(we!==-1)for(let Fe=0;Fe<f;++Fe){const $e=E[we+Fe*(f+1)];if($e!==0){if($e!==1||fe!==-1)return{error:`Channel dimension ${I[we]} must map to a single source dimension`};fe=Fe}}T[L]=fe}return{rank:f,unpaddedRank:p,modelDimensionNames:b,layerDimensionNames:I,localToRenderLayerDimensions:R,globalToRenderLayerDimensions:C,channelToRenderLayerDimensions:S,modelToRenderLayerTransform:E,channelToModelDimensions:T,channelSpaceShape:N}}function tl(t,e){return t===e?!0:t.error!==void 0||e.error!==void 0?!1:arraysEqual(t.modelDimensionNames,e.modelDimensionNames)&&arraysEqual(t.layerDimensionNames,e.layerDimensionNames)&&arraysEqual(t.globalToRenderLayerDimensions,e.globalToRenderLayerDimensions)&&arraysEqual(t.localToRenderLayerDimensions,e.localToRenderLayerDimensions)&&arraysEqual(t.channelToRenderLayerDimensions,e.channelToRenderLayerDimensions)&&arraysEqual(t.modelToRenderLayerTransform,e.modelToRenderLayerTransform)&&arraysEqual(t.channelSpaceShape,e.channelSpaceShape)}function em(t,e,n,s,i){return makeCachedDerivedWatchableValue((r,o,a,c)=>el(r,o,a,s,c),[t,e,n,i===void 0?constantWatchableValue(void 0):i],tl)}function tm(t,e,n,s){const{globalToRenderLayerDimensions:i}=n;for(let r=0;r<3;++r){let o=0;const a=s[r];if(a!==-1){const c=i[a];c!==-1&&(o=e[c])}t[r]=o}}function nm(t,e,n,s){const{globalToRenderLayerDimensions:i}=n;for(let r=0;r<3;++r){const o=s[r];if(o!==-1){const a=i[o];a!==-1&&(t[a]=e[r])}}}function sm(t,e,n,s){const{globalToRenderLayerDimensions:i}=n.modelTransform,{layerRank:r,chunkToLayerTransform:o}=n,a=r+1;for(let c=0;c<3;++c){let l=0;const u=s[c];if(u!==-1){const d=i[u];if(d!==-1){l=o[a*r+d];for(let h=0;h<r;++h)l+=o[a*h+d]*e[h]}}t[c]=l}return t}function im(t,e){const n=t.rank,s=t.unpaddedRank;let i;s!==n&&e!==void 0&&(e=matrix.extendHomogeneousTransform(new Float32Array((n+1)**2),n,e,s)),e!==void 0?(i=new Float32Array((n+1)*(n+1)),matrix.multiply(i,n+1,t.modelToRenderLayerTransform,n+1,e,n+1,n+1,n+1,n+1)):i=t.modelToRenderLayerTransform;const r=new Float32Array((n+1)*(n+1)),o=matrix.inverse(r,n+1,i,n+1,n+1);if(o===0)throw new Error("Transform is singular");const{globalToRenderLayerDimensions:a,localToRenderLayerDimensions:c,channelToRenderLayerDimensions:l}=t,u=a.length,d=c.length,h=u+d,p=new Float32Array((h+1)*n);for(let C=0;C<n;++C){for(let S=0;S<u;++S){const T=a[S];T!==-1&&(p[C+S*n]=r[C+T*(n+1)])}for(let S=0;S<d;++S){const T=c[S];T!==-1&&(p[C+(u+S)*n]=r[C+T*(n+1)])}p[C+h*n]=r[C+n*(n+1)]}const m=l.length,f=new Array(m),b=[];for(let C=0;C<m;++C){const S=l[C];let T=-1;if(S!==-1){for(let v=0;v<n;++v){const N=i[S+v*(n+1)];if(N!==0){if(N!==1||T!==-1)throw new Error(`Channel dimension ${t.layerDimensionNames[S]} must map with stride 1 to a single data chunk dimensions`);T=v}}if(T!==-1){const v=i[S+n*(n+1)];if(v!==0&&v!==-.5)throw new Error(`Channel dimension ${t.layerDimensionNames[S]} must have an offset of 0 in the chunk coordinate space; current offset is ${v}`);b.push(T)}}f[C]=T}const{channelSpaceShape:I}=t,E=vector.prod(I),V=b.length,R=new Uint32Array(E*V);for(let C=0;C<E;++C){let S=C,T=0;for(let v=0;v<m;++v){const N=S%I[v];S=(S-N)/I[v],f[v]!==-1&&(R[C*V+T]=N,++T)}}return{layerRank:n,modelTransform:t,chunkToLayerTransform:i,layerToChunkTransform:r,chunkToLayerTransformDet:o,combinedGlobalLocalRank:h,combinedGlobalLocalToChunkTransform:p,channelToChunkDimensionIndices:f,chunkChannelDimensionIndices:b,numChannels:E,chunkChannelCoordinates:R,channelSpaceShape:I}}function rm(t,e){const{globalToRenderLayerDimensions:n}=t,s=[],i=[];for(let r=0;r<3;++r){const o=e[r];if(o===-1)continue;const a=n[o];i.push(a),a!==-1&&s.push(a)}for(let r=i.length;r<3;++r)i[r]=-1;return{layerDisplayDimensionIndices:s,displayToLayerDimensionIndices:i}}function om(t,e){const{chunkToLayerTransform:n,modelTransform:s}=t,i=s.rank,{layerDisplayDimensionIndices:r,displayToLayerDimensionIndices:o}=e,a=r.length,c=getDependentTransformInputDimensions(n,i,r);if(c.length!==a){const{modelDimensionNames:d,layerDimensionNames:h}=s;throw new Error(`Rank mismatch between displayed layer dimensions (${Array.from(r,p=>h[p]).join(",\xA0")}) and corresponding chunk dimensions (${Array.from(c,p=>d[p]).join(",\xA0")})`)}const l=mat4.create();for(let d=0;d<3;++d){const h=o[d];if(h!==-1){for(let p=0;p<a;++p){const m=c[p];l[p*4+d]=n[m*(i+1)+h]}l[12+d]=n[i*(i+1)+h]}}const u=mat4.create();mat4.invert(u,l);for(let d=c.length;d<3;++d)c[d]=-1;return{modelTransform:t.modelTransform,chunkTransform:t,displaySubspaceModelMatrix:l,displaySubspaceInvModelMatrix:u,chunkDisplayDimensionIndices:c,numChunkDisplayDims:a}}function nl(t,e,n,s,i){const r=e.length,o=n.length,a=t.length;let c=!0;for(let l=0;l<s;++l){let u=l,d=0;for(let h=0;h<r;++h)d+=i[u+h*s]*e[h];u+=r*s;for(let h=0;h<o;++h)d+=i[u+h*s]*n[h];d+=i[u+o*s],l<a?t[l]=d:(d<0||d>=1)&&(c=!1)}return c}function am(t,e,n,s){return scatterUpdate(t,e,s.globalToRenderLayerDimensions),scatterUpdate(t,n,s.localToRenderLayerDimensions),t}function sl(t,e,n){t.fill(0),t[15]=1;let s=!0;const{displayDimensionIndices:i}=e,{globalToRenderLayerDimensions:r,modelToRenderLayerTransform:o}=n,a=n.rank;for(let c=0;c<3;++c){const l=i[c];if(l===-1){s=!1;continue}const u=r[l];if(u===-1){s=!1;continue}t[c+12]=o[u+a*(a+1)];for(let d=0;d<3;++d)t[c+4*d]=o[u+(a+1)*d]}if(!s){const{globalDimensionNames:c}=e,l=Array.from(i.filter(u=>u!==-1),u=>c[u]).join(",\xA0");throw new Error(`Transform from model dimensions (${n.modelDimensionNames.join(",\xA0")}) to display dimensions (${l}) does not have full rank`)}}var Fi=x(9459);/**
 * @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 me=(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))(me||{});const cm={0:!1,1:!0,2:!1,3:!0,4:!1,5:!0,6:!1,7:void 0},Kt={0:1,1:1,2:2,3:2,4:4,5:4,6:8,7:4},Gi={0:Uint8Array,1:Int8Array,2:Uint16Array,3:Int16Array,4:Uint32Array,5:Int32Array,6:Uint32Array,7:Float32Array},ji={0:1,1:1,2:1,3:1,4:1,5:1,6:2,7:1};function Yi(t,e,n=0,s=e.byteLength){const i=Kt[t],r=ji[t];return new Gi[t](e,n,s/i*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.
 */const Vn=!1,il=!1,rl=w.pB.create();function ol(t,e){let n=0,s=Math.abs(t.detTransform);const{transform:i,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]*i[4*o+l];const c=r[o];n+=Math.abs(a)*c,s*=c}return s/n}function Ji(t,e,n){const{curPositionInChunks:s,fixedPositionWithinChunk:i}=t,{nonDisplayLowerClipBound:r,nonDisplayUpperClipBound:o}=t,{rank:a,chunkDataSize:c}=t.source.spec;if(!nl(s,e,n,t.layerRank,t.fixedLayerToChunkTransform))return!1;for(let l=0;l<a;++l){const u=s[l];if(u<r[l]||u>=o[l])return Vn&&console.log("excluding source",t,`because of chunkDim=${l}, sum=${u}`,r,o,t.fixedLayerToChunkTransform),!1;const d=c[l],h=s[l]=Math.floor(u/d);i[l]=u-h*d}return!0}function al(t,e){const n=e.length;let s=0;if(Vn&&console.log(e),n>1){let i=0;for(let r=0;r<n;++r){const o=e[r],{chunkLayout:a}=o,c=ol(a,t);Vn&&console.log(`chunksize = ${a.size}, sliceArea = ${c}`),c>i&&(i=c,s=r)}}return s}const qt=new Fi.i(w.eR.create(),w.pB.create(),0);class lm extends Cc{constructor(){super(...arguments),this.viewportNormalInGlobalCoordinates=w.eR.create(),this.viewportNormalInCanonicalCoordinates=w.eR.create(),this.centerDataPosition=w.eR.create(),this.pixelSize=0}}function cl(t,e){if(t.displayDimensionRenderInfo!==e.displayDimensionRenderInfo||t.pixelSize!==e.pixelSize)return!0;const{viewMatrix:n}=t,{viewMatrix:s}=e;for(let i=0;i<12;++i)if(n[i]!==s[i])return!0;return!1}class ll extends De{constructor(e){super(),this.projectionParameters=e,this.visibleLayers=new Map,this.visibleSourcesStale=!0,this.registerDisposer(e.changed.add((n,s)=>{cl(n,s)&&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[s,{allSources:i,visibleSources:r,displayDimensionRenderInfo:o}]of n){if(r.length=0,o!==e||i.length===0)continue;const a=al(this.projectionParameters.value.viewMatrix,i.map(l=>l[0])),c=i[a];for(const l of s.filterVisibleSources(this,c))r.push(l);r.reverse(),Vn&&console.log("visible sources chosen",r)}}}const ul=18;function Cs(t){let{rank:e,upperVoxelBound:n,maxVoxelsPerChunkLog2:s=ul,chunkToViewTransform:i,displayRank:r,minBlockSize:o,maxBlockSize:a}=t;const{lowerVoxelBound:c=new Uint32Array(e)}=t,l=new Float32Array(e);for(let p=0;p<e;++p){let m=0;for(let f=0;f<r;++f){const b=i[p*r+f];m+=b*b}l[p]=Math.sqrt(m)}const u=new Uint32Array(e);o!==void 0?u.set(o):u.fill(1);const d=new Array(e);for(let p=0;p<e;++p){let m=Number.POSITIVE_INFINITY;l[p]===0?m=u[p]:(n!==void 0&&(m=2**Math.floor(Math.log2(n[p]-c[p]))),a!==void 0&&(m=Math.min(m,a[p]))),d[p]=m}function h(){let p=1/0,m=-1;for(let f=0;f<e;++f){if(u[f]>=d[f])continue;const b=u[f]*l[f];b<p&&(p=b,m=f)}return m}s-=Math.log2(vector.prod(u));for(let p=0;p<s;++p){const m=h();if(m===-1)break;u[m]*=2}return u}function dl(t){const e=[],{displayRank:n,chunkToViewTransform:s,rank:i}=t;if(n>3)throw new Error("Unsupported view transform");if(n<3)return[Cs(t)];for(let r=0;r<3;++r){const o=(r+2)%3,a=new Float32Array(s);for(let c=0;c<i;++c)a[c*n+o]=0;e[r]=Cs({...t,chunkToViewTransform:a})}return e}var hl=(t=>(t[t.ISOTROPIC=0]="ISOTROPIC",t[t.FLAT=1]="FLAT",t))(hl||{});function um(t,e,n){return n===void 0?e:matrix.multiply(new Float32Array((t+1)*(t+1)),t+1,e,t+1,n,t+1,t+1,t+1,t+1)}function dm(t){if(t.chunkDataSizes!==void 0)return t.chunkDataSizes;const{chunkLayoutPreference:e=0}=t;switch(e){case 0:return[Cs(t)];case 1:return dl(t)}}function hm(t){const{rank:e,chunkDataSize:n,upperVoxelBound:s}=t,{lowerVoxelBound:i=new Float32Array(e)}=t,r=new Float32Array(e),o=new Float32Array(e);for(let a=0;a<e;++a)r[a]=Math.floor(i[a]/n[a]),o[a]=Math.floor((s[a]-1)/n[a]+1);return{rank:e,chunkDataSize:n,lowerChunkBound:r,upperChunkBound:o,lowerVoxelBound:i,upperVoxelBound:s}}function*fl(t,e,n){const s=t.projectionParameters.value.pixelSize*1.1,i=n[0].effectiveVoxelSize,r=e.renderScaleTarget.value,o=u=>{const d=s*r;for(let h=0;h<3;++h){const p=u[h];if(p>d&&p>1.01*i[h])return!0}return!1},a=(u,d)=>{const h=s*r;for(let p=0;p<3;++p){const m=u[p],f=d[p];if(Math.abs(h-m)<Math.abs(h-f)&&m<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 pl="SliceView",ml="sliceview/RenderLayer",gl="SliceView.addVisibleLayer",yl="SliceView.removeVisibleLayer",vl="ChunkManager.requestChunk",Es=new Float32Array(3),ks=new Float32Array(3),Hi=w.pB.create(),Wi=new Float32Array(24);function Ki(t,e,n,s){const i=Es,r=ks,{lowerChunkDisplayBound:o,upperChunkDisplayBound:a}=e;for(let d=0;d<3;++d)i[d]=Math.max(i[d],o[d]),r[d]=Math.min(r[d],a[d]);const{curPositionInChunks:c,chunkDisplayDimensionIndices:l}=e;function u(){if(!s(i[0],i[1],i[2],r[0],r[1],r[2],t))return;let d=0,h=Math.max(0,r[0]-i[0]),p=h;for(let I=1;I<3;++I){const E=Math.max(0,r[I]-i[I]);p*=E,E>h&&(h=E,d=I)}if(p===0)return;if(p===1){c[l[0]]=i[0],c[l[1]]=i[1],c[l[2]]=i[2],n(i,t);return}const m=i[d],f=r[d],b=Math.floor(.5*(m+f));r[d]=b,u(),r[d]=f,i[d]=b,u(),i[d]=m}u()}function qi(t,e,n,s){if(!Ji(n,t.globalPosition,e))return;const{size:i}=n.chunkLayout,r=w.pB.multiply(Hi,t.viewProjectionMat,n.chunkLayout.transform);for(let l=0;l<3;++l){const u=i[l];for(let d=0;d<4;++d)r[4*l+d]*=u}const o=Wi;(0,w._S)(o,r);const a=Es,c=ks;a.fill(Number.NEGATIVE_INFINITY),c.fill(Number.POSITIVE_INFINITY),Ki(o,n,s,w.T_)}function Qi(t,e,n,s,i){if(!Ji(n,t.globalPosition,e))return;const{size:r}=s,o=w.pB.multiply(Hi,t.viewProjectionMat,s.transform);for(let h=0;h<3;++h){const p=r[h];for(let m=0;m<4;++m)o[4*h+m]*=p}const a=rl;w.pB.invert(a,o);const c=Es,l=ks,u=.001;for(let h=0;h<3;++h){const p=a[12+h]+u/r[h],m=Math.abs(a[h]),f=Math.abs(a[4+h]);c[h]=Math.floor(p-m-f),l[h]=Math.floor(p+m+f+1)}const d=Wi;for(let h=0;h<3;++h){const p=o[4*h],m=o[4*h+1],f=o[4*h+2];d[h]=p,d[4+h]=-p,d[8+h]=+m,d[12+h]=-m,d[16+h]=+f,d[20+h]=-f}{const p=o[12],m=o[4*3+1],f=o[4*3+2];d[3]=1+p,d[7]=1-p,d[11]=1+m,d[15]=1-m,d[19]=f,d[23]=-f}il&&(console.log("clippingPlanes",d),console.log("modelViewProjection",o.join(",")),console.log(`lower=${c.join(",")}, upper=${l.join(",")}`)),Ki(d,n,i,w.qp)}function Xi(t,e){const{finiteRank:n}=e;if(n===3)return e;qt.finiteRank=n,w.eR.copy(qt.size,e.size);const s=w.pB.copy(qt.transform,e.transform),i=w.pB.copy(qt.invTransform,e.invTransform);qt.detTransform=e.detTransform;const{invViewMatrix:r,width:o,height:a}=t,c=(0,w.sJ)(t.projectionMat);for(let l=n;l<3;++l){const u=r[12+l];let d=u,h=u;const p=Math.abs(r[l]*o);d-=p,h+=p;const m=Math.abs(r[l+4]*a);d-=m,h+=m;const f=Math.abs(r[l+8]*c);d-=f,h+=f;const b=Math.max(1,h-d);s[12+l]=d,s[5*l]=b}return w.pB.invert(i,s),qt}/**
 * @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 wl(t){const e=.254829592,n=-.284496736,s=1.421413741,i=-1.453152027,r=1.061405429,a=1/(1+.3275911*Math.abs(t)),c=1-((((r*a+i)*a+s)*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 Sl=50,bl=1e3;class Il{constructor(e=Sl,n=bl){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 s=e.length;s!==this.rank&&this.reset(s);const i=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:d}=this;for(let h=0;h<s;++h){const p=(e[h]-l[h])/Math.max(r,1);l[h]=e[h];const m=c[h],f=c[h]=m+o*(p-m);if(i===1)u[h]=f;else{const b=u[h],I=d[h],E=f-b;u[h]=b+a*E,d[h]=(1-a)*(I+a*E*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.
 */function Lt(t){return class extends t{constructor(...e){super(...e);const n=e[0],s=e[1];this.visibility=n.get(s.visibility),this.registerDisposer(this.visibility.changed.add(()=>this.chunkManager.scheduleUpdateChunkPriorities()))}}}function dt(t){return t===Number.POSITIVE_INFINITY?se.VISIBLE:se.PREFETCH}function ht(t){return t===Number.POSITIVE_INFINITY?0:t*ne}var Cl=Object.defineProperty,El=Object.getOwnPropertyDescriptor,Zi=(t,e,n,s)=>{for(var i=s>1?void 0:s?El(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Cl(e,n,i),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.
 */const er=-1e12,Ts=1e9,tr=w.eR.create(),kl=w.eR.create(),Tl=w.eR.create();class Dl extends ll{constructor(e,n){super(e.get(n.projectionParameters)),this.initializeSharedObject(e,n.id)}}function nr(t){for(const e of t)for(const n of e)n.source.dispose()}const Pl=Lt(bt(Dl));let sr=class extends Pl{constructor(t,e){super(t,e),this.velocityEstimator=new Il,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:s}=t,i=dt(n);let r=ht(n);r+=er;const o=kl,a=Tl,c=[];this.velocityEstimator.addSample(this.projectionParameters.value.globalPosition);for(const[l,u]of this.visibleLayers){e.registerLayer(l);const{visibleSources:d}=u;for(let h=0,p=d.length;h<p;++h){const m=d[h],f=e.queueManager.enablePrefetch.value?_l(this.velocityEstimator,m):[],{chunkLayout:b}=m;b.globalToLocalSpatial(o,s);const{size:I,finiteRank:E}=b;w.eR.copy(a,I);for(let S=E;S<3;++S)a[S]=0,o[S]=0;const R=r+Ts*h;c.length=0;const C=fn();if(Qi(t,m.renderLayer.localPosition.value,m,Xi(t,m.chunkLayout),S=>{w.eR.multiply(tr,S,a);const T=-w.eR.distance(o,tr),{curPositionInChunks:v}=m,N=m.source.getChunk(v);e.requestChunk(N,i,R+T),++l.numVisibleChunksNeeded,N.state===M.GPU_MEMORY&&++l.numVisibleChunksAvailable,c.push(N),N.markGeneration=C}),f.length!==0){const{curPositionInChunks:S}=m;for(const T of c){S.set(T.chunkGridPosition);for(let v=0,N=f.length;v<N;){const H=f[v],y=f[v+2],A=f[v+3],L=f[v+4],G=f[v+5],ue=S[H],we=ue+f[v+1];if(we<y||we>A){v=G;continue}S[H]=we;const fe=m.source.getChunk(S);if(S[H]=ue,fe.markGeneration===C){v=G;continue}e.requestChunk(fe,se.PREFETCH,R+L),++l.numPrefetchChunksNeeded,fe.state===M.GPU_MEMORY&&++l.numPrefetchChunksAvailable,v+=mn}}}}}}removeVisibleLayer(t){const{visibleLayers:e}=this,n=e.get(t);e.delete(t),nr(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 s=this.visibleLayers.get(t);s===void 0?(s={allSources:e,visibleSources:[],displayDimensionRenderInfo:n},this.visibleLayers.set(t,s),t.renderScaleTarget.changed.add(()=>this.invalidateVisibleSources()),t.localPosition.changed.add(this.handleLayerChanged)):(nr(s.allSources),s.allSources=e,s.visibleSources.length=0,s.displayDimensionRenderInfo=n),this.invalidateVisibleSources()}disposed(){for(const t of this.visibleLayers.keys())this.removeVisibleLayer(t);super.disposed()}invalidateVisibleSources(){super.invalidateVisibleSources(),this.chunkManager.scheduleUpdateChunkPriorities()}};sr=Zi([O(pl)],sr);function Bn(t,e,n){return e.map(i=>i.map(r=>{const o=t.getRef(r.source),a=r.chunkLayout,{rank:c}=o.spec;return{renderLayer:n,source:o,chunkLayout:Fi.i.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)}}))}Q(gl,function(t){const e=this.get(t.id),n=this.get(t.layerId),s=Bn(this,t.sources,n);e.addVisibleLayer(n,s)}),Q(yl,function(t){const e=this.get(t.id),n=this.get(t.layerId);e.removeVisibleLayer(n)});class ir extends g{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()+":"+(0,w.nL)(this.chunkGridPosition)}}class rr extends oe{constructor(e,n){super(e,n),this.spec=n.spec}getChunk(e){const n=e.join();let s=this.chunks.get(n);return s===void 0&&(s=this.getNewChunk_(this.chunkConstructor),s.initializeVolumeChunk(n,e),this.addChunk(s)),s}}let or=class extends U{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 fl(t,this,e)}};or=Zi([O(ml)],or);const ar=2e3,Rl=.1,cr=32,lr=.05,mn=6;function _l(t,e){const n=[],s=t.rank,{combinedGlobalLocalToChunkTransform:i,layerRank:r}=e,{rank:o,chunkDataSize:a}=e.source.spec,{mean:c,variance:l}=t;for(let u=0;u<o;++u){const d=e.chunkDisplayDimensionIndices.includes(u);let h=0,p=0;for(let v=0;v<s;++v){const N=c[v],H=l[v],y=i[v*r+u];h+=y*N,p+=y*y*H}if(h>Rl)continue;const m=a[u],f=d?0:e.fixedPositionWithinChunk[u]/m,b=h/m*ar;let I=Math.sqrt(2*p)/m*ar;if(Math.abs(b)<.001&&I<.001)continue;I=Math.max(1e-6,I);const E=v=>.5*(1+wl((v-b)/I)),V=e.curPositionInChunks[u],R=Math.floor(e.lowerClipBound[u]/m),C=Math.ceil(e.upperClipBound[u]/m)-1;let S=n.length;for(let v=1;v<=cr&&!(!d&&V+v>C);++v){const N=1-E(v-f);if(N<lr)break;n.push(u,v,R,C,N,0)}let T=n.length;for(let v=S,N=n.length;v<N;v+=mn)n[v+mn-1]=T;S=T;for(let v=1;v<=cr&&!(!d&&V-v<R);++v){const N=E(-v+1-f);if(N<lr)break;n.push(u,-v,R,C,N,0)}T=n.length;for(let v=S,N=n.length;v<N;v+=mn)n[v+mn-1]=T}return n}We(vl,async function(t,e){const n=this.get(t.source),{chunkManager:s}=n,i=n.getChunk(t.chunkGridPosition),r=i.key;if(i.state<=M.SYSTEM_MEMORY)return{value:void 0};const o=s.recomputeChunkPriorities.add(()=>{s.requestChunk(i,se.VISIBLE,Number.POSITIVE_INFINITY,M.SYSTEM_MEMORY)});s.scheduleUpdateChunkPriorities();let a;const c=new Promise((u,d)=>{a=h=>{if(h.state===M.FAILED){d(h.error);return}h.state<=M.SYSTEM_MEMORY&&u()}});n.registerChunkListener(r,a);const l=new Promise((u,d)=>{e.add(()=>{d(j.wS)})});try{return await Promise.race([c,l]),{value:void 0}}finally{n.unregisterChunkListener(r,a),o(),s.scheduleUpdateChunkPriorities()}});var Ml=x(4373),Ol=Object.defineProperty,Nl=Object.getOwnPropertyDescriptor,xl=(t,e,n,s)=>{for(var i=s>1?void 0:s?Nl(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Ol(e,n,i),i};/**
 * @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.
 */let ur=class extends U{constructor(...t){super(...t);const e=t[0],n=t[1];this.visibility=e.get(n.visibility),this.projectionParameters=e.get(n.projectionParameters)}};ur=xl([O(Ml.l)],ur);class dr extends An{}/**
 * @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.
 */const Al="volume_rendering/VolumeRenderingRenderLayer",Ll="volume_rendering/VolumeRenderingRenderLayer/update",Ul=!1,Vl=w.w0.create();function fm(t,e,n){let s=0,i=0;for(let l=0;l<3;++l){const u=t[16+l],d=u*e[l],h=u*n[l];s+=Math.min(d,h),i+=Math.max(d,h)}const r=-t[19],o=Math.max(r,s),a=t[23],c=Math.min(a,i);return{near:r,far:a,adjustedNear:o,adjustedFar:c}}function Bl(t,e,n,s,i,r){if(s.length===0)return;const{viewMatrix:o,projectionMat:a,displayDimensionRenderInfo:c}=t,{voxelPhysicalScales:l}=c,u=(0,w.xK)(l),d=(0,w.sJ)(a),p=(d/n)**3,m=w.w0.determinant((0,w._A)(Vl,o)),f={spatialScales:new Map,activeIndex:-1},b=T=>{const v=s[T];return Math.abs(v.chunkLayout.detTransform*m)};let I=s.length-1,E=b(I);for(let T=I;T>=0;--T){const v=b(T),N=Math.cbrt(v*u/m),H=d/Math.cbrt(v);f.spatialScales.set(N,H),v-p>=0&&(E=v,I=T),f.activeIndex=I}if(Ul){console.log(s);for(let T=0;T<s.length;++T){const v=b(T),N=d/Math.cbrt(v);console.log(`scaleIndex=${T} viewVolume=${v} bestScaleIndex=${I} actualViewVolume=${p}, desiredSamples=${N}, difference=${v-p}`)}}const V=Math.cbrt(E*u/m),R=d/Math.cbrt(E);let C=!0;const S=s[I];qi(t,e,S,(T,v)=>{C&&(i(S,I,V,R,v,f),C=!1),r(S,I,T)})}var $l=Object.defineProperty,zl=Object.getOwnPropertyDescriptor,Fl=(t,e,n,s)=>{for(var i=s>1?void 0:s?zl(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&$l(e,n,i),i};/**
 * @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.
 */const hr=w.eR.create(),Gl=w.eR.create(),jl=w.eR.create(),Yl=w.eR.create();let Ds=class extends bt(An){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:s,displayDimensionRenderInfo:i}=t.state;if(s.length===0||i!==e.projectionParameters.value.displayDimensionRenderInfo)continue;const r=e.projectionParameters.value,o=dt(n);let a=ht(n);a+=er;const c=Gl,l=jl,u=Yl,{globalPosition:d,displayDimensionRenderInfo:{displayDimensionIndices:h}}=r;for(let f=0;f<3;++f){const b=h[f];u[f]=b===-1?0:d[b]}let p;const{chunkManager:m}=this;m.registerLayer(this),Bl(r,this.localPosition.value,this.renderScaleTarget.value,s[0],(f,b)=>{const{chunkLayout:I}=f;I.globalToLocalSpatial(c,u);const{size:E,finiteRank:V}=I;w.eR.copy(l,E);for(let C=V;C<3;++C)l[C]=0,c[C]=0;const R=s[0].length-1-b;p=a+Ts*R},(f,b,I)=>{w.eR.multiply(hr,I,l);const E=-w.eR.distance(c,hr),V=f.source.getChunk(f.curPositionInChunks);++this.numVisibleChunksNeeded,m.requestChunk(V,o,p+E),V.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable})}}};Ds=Fl([O(Al)],Ds),Q(Ll,function(t){const e=this.get(t.view),n=this.get(t.layer),s=n.attachments.get(e);s.state.transformedSources=Bn(this,t.sources,n),s.state.displayDimensionRenderInfo=s.view.projectionParameters.value.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()});/**
 * @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 Jl="annotation.MetadataChunkSource",pm="annotation.GeometryChunkSource",Hl="annotation.SubsetGeometryChunkSource",Wl="annotation.reference.add",Kl="annotation.reference.delete",ql="annotation.commit",fr="annotation.commit",Ql="annotation/SpatiallyIndexedRenderLayer",Xl="annotation/PerspectiveRenderLayer:updateSources",Zl="annotation/RenderLayer",eu="annotation/RenderLayer.updateSegmentation",tu=w.w0.create();function nu(t,e,n,s,i,r){const{displayDimensionRenderInfo:o,viewMatrix:a,projectionMat:c,width:l,height:u}=t,{voxelPhysicalScales:d}=o,h=Math.abs(w.w0.determinant((0,w._A)(tu,a))),p=(0,w.xK)(d),m=(0,w.I1)(c)/h*p;if(s.length===0)return;const f=s[0];let b=Math.abs(f.chunkLayout.detTransform)*p;const{lowerClipDisplayBound:I,upperClipDisplayBound:E}=f;for(let v=0;v<3;++v)b*=E[v]-I[v];const V=Math.min(b,m),R=l*u,S=R/n**2/V;let T=0;for(let v=s.length-1;v>=0&&T<S;--v){const N=s[v],H=N.source.spec,{chunkLayout:y}=N,A=(0,w.xK)(y.size)*Math.abs(y.detTransform)*p,{limit:L,rank:G}=H,{nonDisplayLowerClipBound:ue,nonDisplayUpperClipBound:we}=N;let fe=1;for(let yt=0;yt<G;++yt){const Rn=we[yt]-ue[yt];Number.isFinite(Rn)&&(fe/=Rn)}const Fe=L*fe/A;let $e=!0;const Nt=T+Fe,Pn=(1/Nt)**(1/3),un=Math.sqrt(R/(Nt*V)),Gt=(S-T)*A/fe,rt=Math.min(1,Gt/H.limit);qi(t,e,N,()=>{$e&&(i(N,v),$e=!1),r(N,v,rt,Pn,un)}),T=Nt}}/**
 * @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 mm(t,e,n,s){for(;e<n;){const i=t[e];if(s(i)){++e;continue}--n,t[e]=t[n],t[n]=i}return n}function gm(t,e){const n=t.length;let s=0;for(let i=0;i<n;++i)e(t[i],i,t)&&(t[s]=t[i],++s);t.length=s}function ym(t,e){if(t.length===e)return t;const n=new t.constructor(e);return n.set(t),n}function vm(t,e=1){const n=t.length,s=new Array(n);let i=s[0]=e;for(let r=1;r<n;++r)i*=t[r-1],s[r]=i;return s}function su(t,e,n){const s=new t.constructor(t.length);for(let i=0;i<e*n;i+=n)for(let r=0;r<n;r++){const o=i/n;s[r*e+o]=t[i+r]}return s}function wm(t,e,n,s){const i=t.length/e,r=t.length*n*s,o=new t.constructor(r),a=t.length*s,c=e,l=e*s;for(let u=0;u<i;++u)for(let d=0;d<e;++d){const h=t[u*e+d],p=u*l+d;for(let m=0;m<n;++m)for(let f=0;f<s;++f)o[m*a+f*c+p]=h}return o}function Sm(t,e,n,s=0,i=t.length){for(;s<i;){const r=s+i-1>>1,o=n(e,t[r]);if(o>0)s=r+1;else if(o<0)i=r;else return r}return~s}function bm(t,e,n){let s=e-t;for(;s>0;){const i=Math.floor(s/2),r=t+i;n(r)?s=i:(t=r+1,s-=i+1)}return t}function iu(t,e){const n=[];for(let s=0,i=t.length;s<i;++s)t[s]===e&&n.push(s);return n}function Im(t,e){const n=[];n.length=e;for(const s of t)n[s]=!0;return iu(n,void 0)}function It(t,e){const n=t.length;if(e.length!==n)return!1;for(let s=0;s<n;++s)if(t[s]!==e[s])return!1;return!0}function Cm(t,e,n=(s,i)=>s===i){const s=t.length;if(e.length!==s)return!1;for(let i=0;i<s;++i)if(!n(t[i],e[i]))return!1;return!0}function Em(t,e,n){const s=[];if(n===e){for(let i=0;i<t;++i)s[i]=i;return s}s[n]=e;for(let i=0,r=0;i<t;){if(i===e){++i;continue}r===n&&++r,s[r++]=i++}return s}function km(t,e,n){for(let s=0,i=n.length;s<i;++s){const r=n[s];r!==-1&&(t[r]=e[s])}return t}function Tm(t,e,n){for(let s=0,i=n.length;s<i;++s){const r=n[s];r!==-1&&(t[s]=e[r])}return t}function Dm(t){const e=[];for(let n=0,s=t.length;n<s;++n){const i=t[n];for(let r=0,o=i.length;r<o;++r){let a=e[r];a===void 0&&(a=e[r]=[]),a.push(i[r])}}return e}function Pm(t,e){const n=[];let s=0;for(let r=0,o=e.length;r<o;++r){const{retainCount:a,deleteCount:c,insertCount:l}=e[r];a!==0&&(n.push(t.slice(s,s+a)),s+=a),s+=c,l!==0&&n.push(new Array(l))}const i=t.length;return s!==i&&n.push(t.slice(s)),new Array(0).concat(...n)}function Rm(t,e,n){const s=[];let i=0,r=0;const o=t.length,a=e.length;for(;i<o&&r<a;){let c;const l=t[i],u=e[r];if(c=n(l,u),c===0){let d=1;for(++i,++r;i<o&&r<a&&(c=n(t[i],e[r]))===0;)++d,++i,++r;s.push({retainCount:d,deleteCount:0,insertCount:0});continue}if(c<0){let d=1;for(;++i<o&&(c=n(t[i],u))<0;)++d;s.push({retainCount:0,deleteCount:d,insertCount:0});continue}if(c>0){let d=1;for(;++r<a&&(c=n(l,e[r]))>0;)++d;s.push({retainCount:0,deleteCount:0,insertCount:d})}}return(i<o||r<a)&&s.push({retainCount:0,deleteCount:o-i,insertCount:a-r}),s}function _m(t,e,n){const s=[];let i=0,r=0;const o=t.length,a=e.length;for(;i<o;){let c=0;for(;i<o&&r<a&&n(t[i],e[r]);)++c,++i,++r;c!==0&&s.push({retainCount:c,deleteCount:0,insertCount:0});let l=0;for(;i<o&&(r===a||!n(t[i],e[r]));)++l,++i;l!==0&&s.push({retainCount:0,deleteCount:l,insertCount:0})}return r!==a&&s.push({retainCount:0,deleteCount:0,insertCount:a-r}),s}function Mm(t,e,n,s,i,r){let o=0,a=0;if(t!==0&&e!==0)for(;;){const c=n(o,a);if(c<0){if(s(o),++o===t)break}else if(c>0){if(i(a),++a===e)break}else if(r(o,a),++o,++a,o===t||a===e)break}for(;o<t;)s(o),++o;for(;a<e;)i(a),++a}var ru=x(8103);/**
 * @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 pr(t){return("0"+t.toString(16)).slice(-2)}function Om(t){return Array.prototype.map.call(t,pr).join("")}function Nm(t){if(!/^(?:[0-9a-fA-F]{2})*$/.test(t))throw new Error("Invalid hex-encoded string");const e=t.length/2,n=new Uint8Array(e);for(let s=0;s<e;++s)n[s]=parseInt(t.substr(s*2,2),16);return n}/**
 * @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.
 */function ou(t){const e=/^rgba\(([0-9]+), ([0-9]+), ([0-9]+), (0(?:\.[0-9]+)?)\)$/;{const s=t.match(e);if(s!==null)return[parseInt(s[1],10),parseInt(s[2],10),parseInt(s[3],10),parseFloat(s[4])]}const n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;{const s=t.match(n);if(s!==null)return[parseInt(s[1],16),parseInt(s[2],16),parseInt(s[3],16),1]}throw new Error(`Invalid serialized color: ${JSON.stringify(t)}.`)}function mr(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=ou(e.fillStyle);return w.ln.fromValues(n[0]/255,n[1]/255,n[2]/255,n[3])}catch(e){throw new Error(`Failed to parse color specification: ${e.message}`)}}function Ps(t){return mr(t).subarray(0,3)}function gr(t){const e=t[3]===void 0?3:4;let n=0;for(let s=0;s<e;s++)n=(n<<8>>>0)+Math.min(255,Math.max(0,Math.round(t[e-1-s]*255)));return n}function au(t){return w.eR.fromValues((t>>>0&255)/255,(t>>>8&255)/255,(t>>>16&255)/255)}function cu(t){return w.ln.fromValues((t>>>0&255)/255,(t>>>8&255)/255,(t>>>16&255)/255,(t>>>24&255)/255)}function gn(t){if(t[3]===void 0||t[3]===1){let n="#";for(let s=0;s<3;++s)n+=pr(Math.min(255,Math.max(0,Math.round(t[s]*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+=`, ${(0,ru.K)(t[3])})`,e}function Rs(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function lu(t){const[e,n,s]=t;return .2126*Rs(e)+.7152*Rs(n)+.0722*Rs(s)}function xm(t){return lu(t)<=.179}class Am extends ye.B0{constructor(e){super(w.eR.clone(e)),this.defaultValue=e}toString(){return gn(this.value)}toJSON(){if(!w.eR.equals(this.value,this.defaultValue))return gn(this.value)}reset(){this.value=w.eR.clone(this.defaultValue)}restoreState(e){if(e===void 0){this.reset();return}const{value:n}=this,s=Ps(e);w.eR.equals(n,s)||(this.value=s)}}class Lm extends ye.B0{constructor(){super(void 0)}toJSON(){const{value:e}=this;if(e!==void 0)return gn(e)}reset(){this.value=void 0}restoreState(e){if(e===void 0){this.reset();return}const{value:n}=this,s=Ps(e);(n===void 0||!w.eR.equals(n,s))&&(this.value=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 Oe=(t=>(t[t.LITTLE=0]="LITTLE",t[t.BIG=1]="BIG",t))(Oe||{});function uu(){const t=Uint16Array.of(4386);return new Uint8Array(t.buffer)[0]===17?1:0}const Qt=uu();function yr(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,s=e.length;n<s;n+=2){const i=e[n];e[n]=e[n+1],e[n+1]=i}}function vr(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,s=e.length;n<s;n+=4){let i=e[n];e[n]=e[n+3],e[n+3]=i,i=e[n+1],e[n+1]=e[n+2],e[n+2]=i}}function wr(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let n=0,s=e.length;n<s;n+=8){let i=e[n];e[n]=e[n+7],e[n+7]=i,i=e[n+1],e[n+1]=e[n+6],e[n+6]=i,i=e[n+2],e[n+2]=e[n+5],e[n+5]=i,i=e[n+3],e[n+3]=e[n+4],e[n+4]=i}}function du(t,e,n=Qt){e!==n&&yr(t)}function ft(t,e,n=Qt){e!==n&&vr(t)}function Um(t,e,n=Qt){e!==n&&wr(t)}function _s(t,e,n,s=Qt){if(!(e===s||n===1))switch(n){case 2:yr(t);break;case 4:vr(t);break;case 8:wr(t);break}}/**
 * @license
 * Copyright 2021 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 Sr=null,Ms=new Float64Array(1),Dt=new Uint32Array(Ms.buffer);function Vm(t,e){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(t===e)return e;if(t===0)return e<0?-Sr:Sr;Ms[0]=t;const n=ENDIANNESS===Endianness.LITTLE?0:1,s=1-n;return e>t==t>0?Dt[n]===4294967295?(Dt[n]=0,Dt[s]+=1):Dt[n]+=1:Dt[n]===0?(Dt[n]=4294967295,Dt[s]-=1):Dt[n]-=1,Ms[0]}var ee=x(8796);/**
 * @license
 * Copyright 2021 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 Xt={[me.UINT8]:[0,255],[me.INT8]:[-128,127],[me.UINT16]:[0,65535],[me.INT16]:[-32768,32767],[me.UINT32]:[0,4294967295],[me.INT32]:[-2147483648,2147483647],[me.UINT64]:[ee.R.ZERO,new ee.R(4294967295,4294967295)],[me.FLOAT32]:[0,1]};function Bm(t,e){if(typeof e=="number"){const o=t[0],a=t[1];return(e-o)/(a-o)}const n=t[0],s=t[1];let i;Uint64.compare(e,n)<0?i=-Uint64.subtract(Ze,n,e).toNumber():i=Uint64.subtract(Ze,e,n).toNumber();let r=Uint64.absDifference(Ze,s,n).toNumber();return Uint64.compare(n,s)>0&&(r*=-1),i/r}function $m(t,e,n){if(typeof t[0]=="number"){const a=t[0],c=t[1];let l=a*(1-n)+c*n;if(e!==DataType.FLOAT32){const u=Xt[e];l=Math.round(l),l=Math.max(u[0],l),l=Math.min(u[1],l)}return l}let s=t[0],i=t[1];Uint64.compare(s,i)>0&&([s,i]=[i,s],n=1-n);const r=Uint64.subtract(Ze,i,s).toNumber(),o=new Uint64;return n<=0?(Ze.setFromNumber(r*-n),Uint64.subtract(o,s,Uint64.min(Ze,s))):n>=1?(Ze.setFromNumber(r*(n-1)),Uint64.add(o,i,Ze),Uint64.less(o,i)&&(o.low=o.high=4294967295)):(Ze.setFromNumber(r*n),Uint64.add(o,s,Ze),Uint64.less(o,s)&&(o.low=o.high=4294967295)),o}function br(t,e){return typeof e=="number"?Math.min(Math.max(t[0],e),t[1]):Uint64.min(Uint64.max(t[0],e),t[1])}function zm(t,e){return[br(t,e[0]),br(t,e[1])]}function Fm(t){if(Ir(t[0],t[1])<=0)return t;throw new Error(`Invalid interval: [${t[0]}, ${t[1]}]`)}function Gm(t){return Ir(t[0],t[1])<=0?t:[t[1],t[0]]}function Ir(t,e){return typeof t=="number"?t-e:Uint64.compare(t,e)}const Ze=new ee.R,hu=new ee.R;function jm(t,e){return typeof e=="number"?Math.abs(e-t[0])<Math.abs(e-t[1])?0:1:Uint64.less(Uint64.absDifference(Ze,t[0],e),Uint64.absDifference(hu,t[1],e))?0:1}function fu(t,e){let n;switch(typeof e!="string"?n=""+e:n=e,t){case DataType.UINT64:return Uint64.parseString(n);case DataType.FLOAT32:{const s=parseFloat(n);if(!Number.isFinite(s))throw new Error(`Invalid float32 value: ${JSON.stringify(n)}`);return s}default:{const s=parseInt(n),i=Xt[t];if(!Number.isInteger(s)||s<i[0]||s>i[1])throw new Error(`Invalid ${DataType[t].toLowerCase()} value: ${JSON.stringify(n)}`);return s}}}function pu(t){if(typeof t=="number")return t;if(typeof t=="string"){const e=new Uint64,n=Number(t);if(e.tryParseString(t))return n.toString()===e.toString()?n:e;if(!Number.isFinite(n))throw new Error(`Invalid value: ${JSON.stringify(t)}`);return n}throw new Error(`Invalid value: ${JSON.stringify(t)}`)}function Ym(t,e){return parseFixedLengthArray(new Array(2),t,n=>fu(e,n))}function Jm(t){return parseFixedLengthArray(new Array(2),t,e=>pu(e))}function mu(t,e,n){return t===DataType.UINT64?Uint64.equal(e[0],n[0])&&Uint64.equal(e[1],n[1]):e[0]===n[0]&&e[1]===n[1]}function Hm(t,e,n=Xt[e]){if(!mu(e,t,n))return e===DataType.UINT64?[t[0].toString(),t[1].toString()]:t}function Wm(t,e,n){switch(t){case DataType.FLOAT32:return nextAfterFloat64(e,n*(1/0));case DataType.UINT64:{const s=e;return n===-1?s.low===0&&s.high===0?s:Uint64.decrement(new Uint64,s):s.low===4294967295&&s.high===4294967295?s:Uint64.increment(new Uint64,s)}default:{const s=Xt[t];return Math.max(s[0],Math.min(s[1],e+n))}}}function Km(t,e){switch(t){case DataType.FLOAT32:return 0;case DataType.UINT64:return .5/Uint64.absDifference(Ze,e[0],e[1]).toNumber();default:return .5/Math.abs(e[0]-e[1])}}function qm(t,e){switch(t){case DataType.FLOAT32:return 1;case DataType.UINT64:{const n=Uint64.absDifference(Ze,e[0],e[1]).toNumber();return n/(n+1)}default:{const n=Math.abs(e[0]-e[1]);return n/(n+1)}}}function Qm(t,e){if(t===void 0)return Xt[e];let[n,s]=t;if(e===DataType.UINT64)return typeof n=="number"&&(n=Uint64.fromNumber(n)),typeof s=="number"&&(s=Uint64.fromNumber(s)),[n,s];if(typeof n!="number"&&(n=n.toNumber()),typeof s!="number"&&(s=s.toNumber()),e!==DataType.FLOAT32){n=Math.round(n),s=Math.round(s);const i=Xt[e];Number.isFinite(n)?n=Math.min(Math.max(i[0],n),i[1]):n=i[0],Number.isFinite(s)?s=Math.min(Math.max(i[0],s),i[1]):s=i[1]}return[n,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.
 */function Os(t=128){const e=Math.ceil(t/32),n=new Uint32Array(e);crypto.getRandomValues(n);let s="";for(let i=0;i<e;++i)s+=("00000000"+n[i].toString(16)).slice(-8);return s}function gu(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=65536;for(let s=0,i=e.length;s<i;s+=n)crypto.getRandomValues(e.subarray(s,Math.min(i,s+n)));return t}function Xm(){const t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}/**
 * @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.
 */class yu extends Y.O8{constructor(e){super(),this.id=e,this.changed=new Ie.IY}}var at=(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))(at||{});const Zt=[0,1,2,3],Zm={float32:me.FLOAT32,uint32:me.UINT32,int32:me.INT32,uint16:me.UINT16,int16:me.INT16,uint8:me.UINT8,int8:me.INT8,rgb:void 0,rgba:void 0},Pt={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 gr(Ps(t))},serializeJson(t){return gn(au(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 gr(mr(t))},serializeJson(t){return gn(cu(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(0,k._D)(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(0,k.bX)(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(0,k.bX)(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(0,k.bX)(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(0,k.bX)(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(0,k.bX)(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(0,k.bX)(t)},serializeJson(t){return t}}},vu=255;function wu(t,e,n){let s=0;const i=n.length,r=new Array(i),o=[];for(let h=0;h<i;++h)r[h]=h;const a=h=>Pt[n[h].type].alignment(t);r.sort((h,p)=>a(p)-a(h));let c=0;const l=new Array(i);let u=e;const d=()=>{u+=(4-u%4)%4,s+=u,o[c]=u,u=0,++c};for(let h=0;h<i;++h){const p=r[h],m=n[p],f=Pt[m.type],b=f.serializedBytes(t),I=f.alignment(t),E=(I-u%I)%I,R=u+E+b;R+(4-R%4)%4<=vu?u+=E:d(),l[p]={offset:u,group:c},u+=b}return d(),{serializedBytes:s,offsets:l,propertyGroupBytes:o}}class Cr{constructor(e,n,s){if(this.rank=e,this.firstGroupInitialOffset=n,this.propertySpecs=s,s.length===0){this.serializedBytes=n,this.serialize=this.deserialize=()=>{},this.propertyGroupBytes=[n];return}const{serializedBytes:i,offsets:r,propertyGroupBytes:o}=wu(e,n,s);this.propertyGroupBytes=o;let a="let groupOffset0 = offset;";for(let d=1;d<o.length;++d)a+=`let groupOffset${d} = groupOffset${d-1} + ${o[d-1]}*annotationCount;`;for(let d=0;d<o.length;++d)a+=`groupOffset${d} += ${o[d]}*annotationIndex;`;let c=a,l=a;const u=s.length;for(let d=0;d<u;++d){const{group:h,offset:p}=r[d],m=s[d],f=Pt[m.type],b=`properties[${d}]`,I=`groupOffset${h} + ${p}`;c+=f.serializeCode(b,I,e),l+=f.deserializeCode(b,I,e)}this.serializedBytes=i,this.serialize=new Function("dv","offset","annotationIndex","annotationCount","isLittleEndian","properties",c),this.deserialize=new Function("dv","offset","annotationIndex","annotationCount","isLittleEndian","properties",l)}}function Ns(t,e){const n=[];for(const s of Zt){const i=en[s];n[s]=new Cr(t,i.serializedBytes(t),e)}return n}function Su(t,e){const n=t.type==="float32"?e.toPrecision(6):e.toString(),{enumValues:s,enumLabels:i}=t;if(s!==void 0){const r=s.indexOf(e);if(r!==-1)return`${i[r]} (${n})`}return n}function eg(t,e){switch(t.type){case"rgb":return serializeColor(unpackRGB(e));case"rgba":return serializeColor(unpackRGBA(e));default:return Su(t,e)}}function bu(t){const e=verifyString(t);if(e.match(/^[a-z][a-zA-Z0-9_]*$/)===null)throw new Error(`Invalid property identifier: ${JSON.stringify(t)}`);return e}function Iu(t){if(verifyString(t),!Object.prototype.hasOwnProperty.call(Pt,t))throw new Error("Unsupported property type: $JSON.stringify(obj)}");return t}function Cu(t){const e=new Set;for(const n of t){if(e.has(n.identifier))throw new Error(`Duplicate property identifier: ${n.identifier}`);e.add(n.identifier)}}function Eu(t){verifyObject(t);const e=verifyObjectProperty(t,"id",bu),n=verifyObjectProperty(t,"type",Iu),s=verifyOptionalObjectProperty(t,"description",verifyString),i=verifyOptionalObjectProperty(t,"default",a=>Pt[n].deserializeJson(a),0);let r,o;switch(n){case"rgb":case"rgba":break;default:{const a=DataType[n.toUpperCase()];r=verifyOptionalObjectProperty(t,"enum_values",c=>parseArray(c,l=>parseDataTypeValue(a,l))),r!==void 0&&(o=verifyObjectProperty(t,"enum_labels",c=>parseFixedLengthArray(new Array(r.length),c,verifyString)))}}return{type:n,identifier:e,description:s,default:i,enumValues:r,enumLabels:o}}function ku(t){const e=t.default;return{id:t.identifier,description:t.description,type:t.type,default:e===0?void 0:Pt[t.type].serializeJson(e)}}function tg(t){if(!(t===void 0||t.length===0))return t.map(ku)}function ng(t){if(t===void 0)return[];const e=parseArray(t,Eu);return Cu(e),e}function xs(t,e,n,s,i){for(let r=0;r<s;++r)t.setFloat32(e,i[r],n),e+=4;return e}function As(t,e,n,s,i,r){return e=xs(t,e,n,s,i),e=xs(t,e,n,s,r),e}function Ls(t,e,n,s,i){for(let r=0;r<s;++r)i[r]=t.getFloat32(e,n),e+=4;return e}function Us(t,e,n,s,i,r){return e=Ls(t,e,n,s,i),e=Ls(t,e,n,s,r),e}const en={1:{icon:"\uA579",description:"Line",toJSON(t){return{pointA:Array.from(t.pointA),pointB:Array.from(t.pointB)}},restoreState(t,e,n){t.pointA=(0,k.cQ)(e,"pointA",s=>(0,k.Xu)(new Float32Array(n),s,k.zo)),t.pointB=(0,k.cQ)(e,"pointB",s=>(0,k.Xu)(new Float32Array(n),s,k.zo))},serializedBytes(t){return 2*4*t},serialize(t,e,n,s,i){As(t,e,n,s,i.pointA,i.pointB)},deserialize:(t,e,n,s,i)=>{const r=new Float32Array(s),o=new Float32Array(s);return Us(t,e,n,s,r,o),{type:1,pointA:r,pointB:o,id:i,properties:[]}},visitGeometry(t,e){e(t.pointA,!1),e(t.pointB,!1)}},0:{icon:"\u26AC",description:"Point",toJSON:t=>({point:Array.from(t.point)}),restoreState:(t,e,n)=>{t.point=(0,k.cQ)(e,"point",s=>(0,k.Xu)(new Float32Array(n),s,k.zo))},serializedBytes:t=>t*4,serialize:(t,e,n,s,i)=>{xs(t,e,n,s,i.point)},deserialize:(t,e,n,s,i)=>{const r=new Float32Array(s);return Ls(t,e,n,s,r),{type:0,point:r,id:i,properties:[]}},visitGeometry(t,e){e(t.point,!1)}},2:{icon:"\u2751",description:"Bounding Box",toJSON:t=>({pointA:Array.from(t.pointA),pointB:Array.from(t.pointB)}),restoreState:(t,e,n)=>{t.pointA=(0,k.cQ)(e,"pointA",s=>(0,k.Xu)(new Float32Array(n),s,k.zo)),t.pointB=(0,k.cQ)(e,"pointB",s=>(0,k.Xu)(new Float32Array(n),s,k.zo))},serializedBytes:t=>2*4*t,serialize(t,e,n,s,i){As(t,e,n,s,i.pointA,i.pointB)},deserialize:(t,e,n,s,i)=>{const r=new Float32Array(s),o=new Float32Array(s);return Us(t,e,n,s,r,o),{type:2,pointA:r,pointB:o,id:i,properties:[]}},visitGeometry(t,e){e(t.pointA,!1),e(t.pointB,!1)}},3:{icon:"\u25CE",description:"Ellipsoid",toJSON:t=>({center:Array.from(t.center),radii:Array.from(t.radii)}),restoreState:(t,e,n)=>{t.center=(0,k.cQ)(e,"center",s=>(0,k.Xu)(new Float32Array(n),s,k.zo)),t.radii=(0,k.cQ)(e,"radii",s=>(0,k.Xu)(new Float32Array(n),s,k.Zw))},serializedBytes:t=>2*4*t,serialize(t,e,n,s,i){As(t,e,n,s,i.center,i.radii)},deserialize:(t,e,n,s,i)=>{const r=new Float32Array(s),o=new Float32Array(s);return Us(t,e,n,s,r,o),{type:3,center:r,radii:o,id:i,properties:[]}},visitGeometry(t,e){e(t.center,!1),e(t.radii,!0)}}};function Tu(t,e){const n=en[t.type].toJSON(t,e.rank);n.type=at[t.type].toLowerCase(),n.id=t.id,n.description=t.description||void 0;const{relatedSegments:s}=t;if(s?.some(i=>i.length!==0)&&(n.segments=s.map(i=>i.map(r=>r.toString()))),e.properties.length!==0){const i=e.properties;n.props=t.properties.map((r,o)=>Pt[i[o].type].serializeJson(r))}return n}function Du(t,e,n=!1){(0,k.Rf)(t);const s=(0,k.cQ)(t,"type",c=>(0,k.sl)(c,at)),i=(0,k.cQ)(t,"id",n?k.z$:k.zr)||kr(),r=(0,k.cQ)(t,"segments",c=>{if(c===void 0)return e.relationships.map(()=>[]);const l=(0,k.J6)(c);return l.length===0?e.relationships.map(()=>[]):e.relationships.length===1&&!Array.isArray(l[0])?[(0,k.$v)(l,u=>ee.R.parseString(u))]:(0,k.$v)((0,k.J6)(c,e.relationships.length),u=>(0,k.$v)(u,d=>ee.R.parseString(d)))}),o=(0,k.cQ)(t,"props",c=>{const l=e.properties;return c===void 0?l.map(u=>u.default):(0,k.$v)((0,k.J6)(c,e.properties.length),(u,d)=>Pt[l[d].type].deserializeJson(u))}),a={id:i,description:(0,k.cQ)(t,"description",k.z$),relatedSegments:r,properties:o,type:s};return en[s].restoreState(a,t,e.rank),a}class Er extends Y.O8{constructor(e,n=[],s=[]){super(),this.relationships=n,this.properties=s,this.annotationMap=new Map,this.changed=new Ie.IY,this.readonly=!1,this.childAdded=new Ie.HN,this.childUpdated=new Ie.HN,this.childCommitted=new Ie.HN,this.childDeleted=new Ie.HN,this.pending=new Set,this.references=new Map,this.rank_=e,this.annotationPropertySerializers=Ns(e,s)}get rank(){return this.rank_}hasNonSerializedProperties(){return!0}add(e,n=!0){if(this.ensureUpdated(),!e.id)e.id=kr();else if(this.annotationMap.has(e.id))throw new Error(`Annotation id already exists: ${JSON.stringify(e.id)}.`);return this.annotationMap.set(e.id,e),n||this.pending.add(e.id),this.changed.dispatch(),this.childAdded.dispatch(e),n&&this.childCommitted.dispatch(e.id),this.getReference(e.id)}commit(e){this.ensureUpdated();const n=e.id;this.pending.delete(n),this.changed.dispatch(),this.childCommitted.dispatch(n)}update(e,n){if(this.ensureUpdated(),e.value===null)throw new Error("Annotation already deleted.");e.value=n,this.annotationMap.set(n.id,n),e.changed.dispatch(),this.changed.dispatch(),this.childUpdated.dispatch(n)}[Symbol.iterator](){return this.ensureUpdated(),this.annotationMap.values()}get(e){return this.ensureUpdated(),this.annotationMap.get(e)}delete(e){e.value!==null&&(e.value=null,this.annotationMap.delete(e.id),this.pending.delete(e.id),e.changed.dispatch(),this.changed.dispatch(),this.childDeleted.dispatch(e.id))}getReference(e){let n=this.references.get(e);return n!==void 0?n.addRef():(n=new yu(e),n.value=this.annotationMap.get(e)||null,this.references.set(e,n),n.registerDisposer(()=>{this.references.delete(e)}),n)}ensureUpdated(){}toJSON(){this.ensureUpdated();const e=[],{pending:n}=this;for(const s of this)n.has(s.id)||e.push(Tu(s,this));return e}clear(){this.annotationMap.clear(),this.pending.clear(),this.changed.dispatch()}restoreState(e){this.ensureUpdated();const{annotationMap:n}=this;n.clear(),this.pending.clear(),e!==void 0&&(0,k.$v)(e,s=>{const i=Du(s,this);n.set(i.id,i)});for(const s of this.references.values()){const{id:i}=s,r=n.get(i);s.value=r||null,s.changed.dispatch()}this.changed.dispatch()}reset(){this.clear()}}class sg extends Er{constructor(e,n,s){super(e.value.sourceRank,s,n),this.watchableTransform=e,this.curCoordinateTransform=e.value,this.registerDisposer(e.changed.add(()=>this.ensureUpdated()))}get rank(){return this.ensureUpdated(),this.rank_}ensureUpdated(){const e=this.watchableTransform.value,{curCoordinateTransform:n}=this;if(e===n)return;this.curCoordinateTransform=e;const s=e.sourceRank,i=n.sourceRank;if(i===s&&(n.inputSpace===e.inputSpace||It(n.inputSpace.ids.slice(0,s),e.inputSpace.ids.slice(0,s))))return;const{ids:r}=e.inputSpace,o=n.inputSpace.ids,a=[];for(let l=0;l<s;++l){let u=o.indexOf(r[l]);u>=i&&(u=-1),a.push(u)}const c=l=>{const u=new Float32Array(s);for(let d=0;d<s;++d){const h=a[d];u[d]=h===-1?0:l[d]}return u};for(const l of this.annotationMap.values())switch(l.type){case 0:l.point=c(l.point);break;case 1:case 2:l.pointA=c(l.pointA),l.pointB=c(l.pointB);break;case 3:l.center=c(l.center),l.radii=c(l.radii);break}this.rank_!==s&&(this.rank_=s,this.annotationPropertySerializers=Ns(this.rank_,this.properties)),this.changed.dispatch()}}const Pu="Data Bounds";function kr(){return Os(160)}function Ru(t){return{type:2,id:"data-bounds",description:Pu,pointA:new Float32Array(t.lowerBounds),pointB:new Float32Array(t.upperBounds),properties:[]}}function ig(t){const e=new Er(t.lowerBounds.length);return e.readonly=!0,e.add(Ru(t)),e}function _u(t,e){let n=0;const s=[];for(const l of Zt){const d=e[l].serializedBytes;s[l]=n;const p=t[l].length;n+=d*p}const i=[],r=[],o=new ArrayBuffer(n),a=new DataView(o),c=Qt===Oe.LITTLE;for(const l of Zt){const u=e[l],{rank:d}=u,h=u.serialize,p=t[l];i[l]=p.map(E=>E.id),r[l]=new Map(p.map((E,V)=>[E.id,V]));const f=en[l].serialize,b=s[l],I=u.propertyGroupBytes[0];for(let E=0,V=p.length;E<V;++E){const R=p[E];f(a,b+E*I,c,d,R),h(a,b,E,V,c,R.properties)}}return{data:new Uint8Array(o),typeToIds:i,typeToOffset:s,typeToIdMaps:r}}class Mu{constructor(e){this.propertySerializers=e,this.annotations=[[],[],[],[]]}add(e){this.annotations[e.type].push(e)}serialize(){return _u(this.annotations,this.propertySerializers)}}function Ou(t){if(t==null)return t;const{relatedSegments:e}=t;if(e!==void 0)for(let n=0,s=e.length;n<s;++n){const i=e[n];i!==void 0&&(e[n]=i.map(r=>new ee.R(r.low,r.high)))}return t}/**
 * @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 Nu(t,e,n){(0,k.MM)(t,e,s=>n.restoreState(s))}class Tr extends Y.O8{constructor(){super(...arguments),this.children=new Map,this.changed=new Ie.IY}add(e,n){const{children:s}=this;if(s.has(e))throw new Error(`Key ${JSON.stringify(e)} already registered.`);return this.children.set(e,n),n.changed.add(this.changed.dispatch),this.changed.dispatch(),()=>{this.remove(e)}}remove(e){const{children:n}=this;if(n.has(e))throw new Error(`Key ${JSON.stringify(e)} not registered.`);const s=n.get(e);this.children.delete(e),s.changed.remove(this.changed.dispatch),this.changed.dispatch()}disposed(){const{changed:e}=this;for(const n of this.children.values())n.changed.remove(e.dispatch);this.children=void 0,super.disposed()}toJSON(){const e=this.baseJSON();for(const[n,s]of this.children)e[n]=s.toJSON();return e}baseJSON(){return{}}reset(){for(const e of this.children.values())e.reset()}restoreState(e){(0,k.Rf)(e);for(const[n,s]of this.children)try{if(Object.prototype.hasOwnProperty.call(e,n)){const i=e[n];if(i===void 0)continue;s.restoreState(i)}}catch(i){throw new Error(`Error restoring property ${JSON.stringify(n)}: ${i.message}`)}}}class rg extends Tr{constructor(){super(...arguments),this.lastState={}}restoreState(e){(0,k.Rf)(e),this.lastState=e,super.restoreState(e)}reset(){this.lastState={},super.reset()}baseJSON(){const e=Object.assign(super.baseJSON(),this.lastState);for(const n of this.children.keys())delete e[n];return e}toJSON(){const e=super.toJSON();return this.lastState=e,e}add(e,n){const s=super.add(e,n),i=this.lastState[e];return i!==void 0&&(n.reset(),n.restoreState(i)),s}}const Dr=new WeakMap;function xu(t){let e=Dr.get(t);const n=t.changed.count;if(e!==void 0&&e.generation===n)return e;let s;if(t instanceof Tr){s=t.baseJSON();for(const[i,r]of t.children)s[i]=xu(r).value}else s=t.toJSON();return e===void 0?(e={generation:n,value:s},Dr.set(t,e)):(e.generation=n,e.value=s),e}var Pr=x(6703);/**
 * @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 Rr=(t=>(t[t.LINKED=0]="LINKED",t[t.RELATIVE=1]="RELATIVE",t[t.UNLINKED=2]="UNLINKED",t))(Rr||{}),_r=(t=>(t[t.LINKED=0]="LINKED",t[t.UNLINKED=2]="UNLINKED",t))(_r||{});class Au extends Pr.F{constructor(e=0){super(Rr,e)}}class og extends Pr.F{constructor(e=0){super(_r,e)}}const $n=w.eR.create(),Mr=w.Yu.create();function yn(t,e,n,s){let i=!1;const r=!1;let o;t.registerDisposer(e);const a=()=>{if(!r){switch(i=!0,n.value){case 2:if(s.isValid(t))break;case 0:s.assign(t,e);break;case 1:s.add(t,e,o);break}i=!1}},c=()=>{if(!i)switch(n.value){case 2:break;case 0:s.assign(e,t);break;case 1:s.subtract(e,t,o);break}};let l=2;const u=()=>{const d=n.value;if(d!==l)switch(d){case 2:o=void 0;break;case 0:o=void 0,s.assign(t,e);break;case 1:o=s.difference(t,e);break}l=d,t.changed.dispatch()};return t.registerDisposer(t.changed.add(c)),t.registerDisposer(e.changed.add(a)),t.registerDisposer(n.changed.add(u)),u(),t}function Or(t,e,n,s){return yn(t,e,n,s)}class zn extends Y.O8{constructor(e){super(),this.coordinateSpace=e,this.coordinates_=ys,this.changed=new Ie.IY,this.registerDisposer(e.changed.add(()=>{this.handleCoordinateSpaceChanged()}))}get valid(){return this.coordinateSpace.value.valid}get value(){return this.handleCoordinateSpaceChanged(),this.coordinates_}reset(){this.curCoordinateSpace=void 0,this.coordinates_=ys,this.changed.dispatch()}set value(e){const{curCoordinateSpace:n}=this;if(n===void 0||!n.valid||n.rank!==e.length)return;const{coordinates_:s}=this;s.set(e),this.changed.dispatch()}handleCoordinateSpaceChanged(){const e=this.coordinateSpace.value,n=this.curCoordinateSpace;if(e===n)return;this.curCoordinateSpace=e;const{rank:s}=e;if(!e.valid)return;if(n===void 0||!n.valid){let{coordinates_:u}=this;if(!(u!==void 0&&u.length===s)){u=this.coordinates_=new Float32Array(s),Uc(u,e.bounds);const{voxelCenterAtIntegerCoordinates:d}=e.bounds;for(let h=0;h<s;++h)d[h]?u[h]=Math.round(u[h]):u[h]=Math.floor(u[h])+.5}this.changed.dispatch();return}const i=new Float32Array(s),r=this.coordinates_,{ids:o,scales:a}=e,{ids:c,scales:l}=n;for(let u=0;u<s;++u){const d=o[u],h=c.indexOf(d);h===-1?i[u]=Li(e.bounds.lowerBounds[u],e.bounds.upperBounds[u]):i[u]=r[h]*(l[h]/a[u])}this.coordinates_=i,this.changed.dispatch()}toJSON(){if(!this.valid&&this.coordinates_.length===0)return;this.handleCoordinateSpaceChanged();const{value:e}=this;if(e.length!==0)return Array.from(e)}restoreState(e){if(e===void 0){this.reset();return}this.curCoordinateSpace=void 0,this.coordinates_=Float32Array.from((0,k.$v)(e,k.zo)),this.handleCoordinateSpaceChanged(),this.changed.dispatch()}snapToVoxel(){this.handleCoordinateSpaceChanged();const{bounds:{voxelCenterAtIntegerCoordinates:e}}=this.coordinateSpace.value,{coordinates_:n}=this,s=n.length;for(let i=0;i<s;++i)e[i]?n[i]=Math.round(n[i]):n[i]=Math.floor(n[i])+.5;this.changed.dispatch()}assign(e){e.handleCoordinateSpaceChanged();const{curCoordinateSpace:n,coordinates_:s}=e;this.curCoordinateSpace=n,this.coordinates_=Float32Array.from(s),this.changed.dispatch()}static getOffset(e,n){const s=e.coordinates_,i=n.coordinates_;if(s.length===i.length)return gs(new Float32Array(s.length),s,i)}static addOffset(e,n,s,i=1){e.handleCoordinateSpaceChanged();const{value:r}=n;s!==void 0&&r.length===s.length&&(wc(e.value,r,s,i),e.changed.dispatch())}get legacyJsonView(){const e=this;return{changed:e.changed,toJSON(){return e.toJSON()},reset(){e.reset()},restoreState(n){if(n===void 0||Array.isArray(n)){e.restoreState(n);return}(0,k.Rf)(n),Nu(n,"voxelCoordinates",e)}}}}var Vs=(t=>(t[t.STOP=0]="STOP",t[t.LOOP=1]="LOOP",t[t.REVERSE=2]="REVERSE",t))(Vs||{});const Nr=10;class Bs{constructor(){this.velocity=Nr,this.atBoundary=2,this.paused=!0}}function Lu(t,e){return t.velocity===e.velocity&&t.atBoundary===e.atBoundary&&t.paused===e.paused}function Uu(t){return(0,k.Rf)(t),{velocity:(0,k.MM)(t,"velocity",k.zo,Nr),atBoundary:(0,k.MM)(t,"atBoundary",e=>(0,k.sl)(e,Vs),0),paused:(0,k.MM)(t,"paused",k.aO,!0)}}function Vu(t){const{velocity:e,atBoundary:n,paused:s}=t;return{velocity:e,atBoundary:n===0?void 0:Vs[n].toLowerCase(),paused:s?void 0:!1}}class Bu extends Y.O8{constructor(e){super(),this.coordinateSpace=e,this.changed=new Ie.IY,this.registerDisposer(e.changed.add(()=>{this.handleCoordinateSpaceChanged()})),this.curCoordinateSpace=e.value,this.velocities_=new Array(this.curCoordinateSpace?.rank??0)}get valid(){return this.coordinateSpace.value.valid}get value(){return this.handleCoordinateSpaceChanged(),this.velocities_}set value(e){const{curCoordinateSpace:n}=this;n===void 0||n.rank!==e.length||(this.velocities_=e,this.changed.dispatch())}get(e){const n=this.coordinateSpace.value?.ids;if(n===void 0)return;const s=n.indexOf(e);return s===-1?void 0:this.value[s]}dimensionVelocity(e,n){const s=new Ie.IY;let i=-1;const r=()=>{const l=this.coordinateSpace.value?.ids;l===void 0?i=-1:(i===-1||l[i]!==n)&&(i=l.indexOf(n))},o=()=>{if(r(),i!==-1)return this.value[i]},a=l=>{if(r(),i===-1)return;const u=this.value;u[i]!==l&&(u[i]=l,this.changed.dispatch())},c=o();return e.registerDisposer(this.changed.add(()=>{o()!==c&&s.dispatch()})),{get value(){return o()},set value(l){a(l)},changed:s}}modifyDimension(e,n){const s=this.coordinateSpace.value?.ids;if(s===void 0)return;const i=s.indexOf(e);if(i===-1)return;const r=this.value,o=r[i],a=n(o);o!==a&&(r[i]=a,this.changed.dispatch())}togglePlayback(e,n=void 0){this.modifyDimension(e,(s=new Bs)=>({...s,paused:n??!s.paused}))}playbackEnabled(e){const n=this;return{changed:this.changed,get value(){return n.get(e)!==void 0},set value(s){n.modifyDimension(e,i=>s?i??new Bs:void 0)}}}multiplyVelocity(e,n){this.modifyDimension(e,(s=new Bs)=>{let i=Math.round(s.velocity*n);return i===0&&(i=Math.sign(s.velocity)||1),{...s,velocity:i}})}handleCoordinateSpaceChanged(){const e=this.coordinateSpace.value,n=this.curCoordinateSpace;if(e===n)return;this.curCoordinateSpace=e;const{rank:s}=e;if(!e.valid)return;if(n===void 0){let{velocities_:c}=this;c.length===s||(c=new Array(s)),this.changed.dispatch();return}const i=new Array(s),r=this.velocities_,{ids:o}=e,{ids:a}=n;for(let c=0;c<s;++c){const l=o[c],u=a.indexOf(l);u!==-1&&(i[c]=r[u])}this.velocities_=i,this.changed.dispatch()}toJSON(){this.handleCoordinateSpaceChanged();const{velocities_:e,curCoordinateSpace:n}=this;if(!n?.valid||!e.some(o=>o!==void 0))return;const s={},{names:i,rank:r}=n;for(let o=0;o<r;++o){const a=e[o];a!==void 0&&(s[i[o]]=Vu(a))}return s}reset(){this.handleCoordinateSpaceChanged(),this.velocities_=new Array(this.curCoordinateSpace?.rank??0)}restoreState(e){if(e===void 0){this.reset();return}(0,k.Rf)(e);const n=this.curCoordinateSpace=this.coordinateSpace.value;if(this.velocities_=new Array(n?.rank??0),n===void 0)throw new Error("Must specify dimensions in order to specify velocities");const s=this.velocities_=new Array(n?.rank??0),{names:i}=n;for(const r of Object.keys(e)){const o=i.indexOf(r);if(o===-1)throw new Error(`Invalid dimension name: ${JSON.stringify(r)}`);s[o]=(0,k.cQ)(e,r,Uu)}this.changed.dispatch()}assign(e){const n=e.value,s=this.value,i=s.length;let r=!1;for(let o=0;o<i;++o){const a=n[o],c=s[o];a!==c&&((c===void 0||a===void 0||!Lu(c,a))&&(r=!0),s[o]=a)}r&&this.changed.dispatch()}}class ag extends Y.O8{constructor(e,n){super(),this.peer=e,this.positionLink=n,this.changed=new Ie.IY,this.velocity=this.registerDisposer(new Bu(this.peer.coordinateSpace)),this.registerDisposer(e),this.velocity.changed.add(()=>{this.positionLink.value===2?this.changed.dispatch():this.peer.assign(this.velocity)});const s=()=>{this.positionLink.value!==2&&this.velocity.assign(this.peer)};this.registerDisposer(e.changed.add(s)),s()}toJSON(){if(this.positionLink.value===2)return this.velocity.toJSON()}reset(){this.positionLink.value===2&&this.velocity.reset()}restoreState(e){this.positionLink.value===2&&this.velocity.restoreState(e)}copyToPeer(){this.positionLink.value===2&&this.peer.assign(this.velocity)}}class cg extends Y.O8{constructor(e,n,s){super(),this.display=e,this.position=n,this.velocity=s,this.dimensionStates=new Map,this.lastUpdateGeneration=0,this.handleVelocityChanged(),this.registerDisposer(s.changed.add(()=>this.handleVelocityChanged()))}disposed(){this.unregisterUpdateStartedCallback?.(),super.disposed()}handleVelocityChanged(){const{dimensionStates:e}=this,n=this.position.coordinateSpace.value?.ids??[],s=n.length,i=this.velocity.value,r=++this.lastUpdateGeneration,o=this.position.value,a=Date.now();for(let c=0;c<s;++c){const l=i[c];if(l===void 0||l.velocity===0||l.paused)continue;const u=n[c],d=e.get(u);d===void 0?e.set(u,{prevTime:a,dimensionIndex:c,prevCoordinate:o[c],generation:r}):(d.generation=r,d.dimensionIndex=c)}for(const[c,l]of e)l.generation!==r&&e.delete(c);if(e.size===0){const{unregisterUpdateStartedCallback:c}=this;c!==void 0&&(c(),this.unregisterUpdateStartedCallback=void 0)}else this.unregisterUpdateStartedCallback===void 0&&(this.unregisterUpdateStartedCallback=this.display.updateStarted.add(()=>this.updateStarted()),this.display.scheduleRedraw())}updateStarted(){const e=this.position.coordinateSpace.value;if(e===void 0)return;const n=e.ids,s=this.position.value;let i=!1,r=!1;const o=Date.now(),a=this.velocity.value,{bounds:{lowerBounds:c,upperBounds:l}}=e;for(const[u,d]of this.dimensionStates){const{dimensionIndex:h}=d;if(n[h]!==u)continue;const p=a[h];if(Math.floor(s[h])!==Math.floor(d.prevCoordinate)){p?.paused===!1&&(a[h]={...p,paused:!0},r=!0);continue}const m=o-d.prevTime,f=p?.velocity??0,b=m*f/1e3;if(b===0)continue;let I=s[h]+b;const E=c[h],V=Math.ceil(l[h]-1),R=b>0?V:E,C=b>0?E:V,S=Math.sign(b);if(Number.isFinite(R)&&I*S>=R*S)switch(p.atBoundary){case 1:if(Number.isFinite(C)){I=C;break}case 0:a[h]={...p,paused:!0},r=!0,I=R;break;case 2:a[h]={...p,velocity:-f},r=!0,I=R;break}s[h]=I,d.prevCoordinate=s[h],d.prevTime=o,i=!0}i&&this.position.changed.dispatch(),r&&this.velocity.changed.dispatch(),this.display.scheduleRedraw()}}function xr(t,e,n){if(n===void 0||Object.keys(n).length===0){t.value=0;return}(0,k.Rf)(n),t.value=2,(0,k.cQ)(n,"value",s=>{s!==void 0&&e.restoreState(s)}),(0,k.cQ)(n,"link",s=>t.restoreState(s))}class vn{constructor(e,n=new Au){this.peer=e,this.link=n}get changed(){return this.value.changed}toJSON(){const{link:e}=this;if(e.value!==0)return{link:e.toJSON(),value:this.getValueJson()}}getValueJson(){return this.value.toJSON()}reset(){this.link.value=0}restoreState(e){xr(this.link,this.value,e)}copyToPeer(){this.link.value!==0&&(this.link.value=2,this.peer.assign(this.value),this.link.value=0)}}class Ar extends vn{}class lg extends vn{constructor(){super(...arguments),this.value=yn(new zn(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,n)=>e.assign(n),isValid:e=>e.valid,difference:zn.getOffset,add:zn.addOffset,subtract:(e,n,s)=>{zn.addOffset(e,n,s,-1)}})}}function $u(t){return t[0]===0&&t[1]===0&&t[2]===0&&t[3]===1}class $s extends Y.O8{constructor(e){super(),this.changed=new Ie.IY,e==null&&(e=w.Yu.create()),this.orientation=e}toJSON(){const{orientation:e}=this;if(w.Yu.normalize(this.orientation,this.orientation),!$u(e))return Array.prototype.slice.call(this.orientation)}restoreState(e){try{(0,k.Vr)(this.orientation,e),w.Yu.normalize(this.orientation,this.orientation)}catch{w.Yu.identity(this.orientation)}this.changed.dispatch()}reset(){w.Yu.identity(this.orientation),this.changed.dispatch()}snap(){const e=w.w0.create();w.w0.fromQuat(e,this.orientation);const n=[!1,!1,!1];for(let s=0;s<3;++s){let i=0,r=0;for(let o=0;o<3;++o){const a=e[s*3+o];e[s*3+o]=0,!n[o]&&Math.abs(a)>Math.abs(i)&&(i=a,r=o)}e[s*3+r]=Math.sign(i),n[r]=!0}w.Yu.fromMat3(this.orientation,e),this.changed.dispatch()}static makeRelative(e,n){const s=new $s(w.Yu.multiply(w.Yu.create(),e.orientation,n));let i=!1;s.registerDisposer(e.changed.add(()=>{i||(r=!0,w.Yu.multiply(s.orientation,e.orientation,n),s.changed.dispatch(),r=!1)}));let r=!1;const o=w.Yu.invert(w.Yu.create(),n);return s.registerDisposer(s.changed.add(()=>{r||(i=!0,w.Yu.multiply(e.orientation,s.orientation,o),e.changed.dispatch(),i=!1)})),s}assign(e){w.Yu.copy(this.orientation,e.orientation),this.changed.dispatch()}}class ug extends vn{constructor(){super(...arguments),this.value=yn(new $s,this.peer,this.link,{assign:(e,n)=>e.assign(n),isValid:()=>!0,difference:(e,n)=>{const s=w.Yu.create();return w.Yu.multiply(s,w.Yu.invert(s,n.orientation),e.orientation)},add:(e,n,s)=>{w.Yu.multiply(e.orientation,n.orientation,s),e.changed.dispatch()},subtract:(e,n,s)=>{w.Yu.multiply(e.orientation,n.orientation,w.Yu.invert(Mr,s)),e.changed.dispatch()}})}}class zu extends Y.O8{constructor(e){super(),this.coordinateSpace=e,this.changed=new Ie.IY,this.curCoordinateSpace=Wt,this.value_={factors:new Float64Array(0)},this.registerDisposer(e.changed.add(()=>this.update())),this.update()}get value(){return this.update()}reset(){this.value_={factors:new Float64Array(0)},this.curCoordinateSpace=Wt,this.changed.dispatch()}toJSON(){const e={};let n=!1;const{value:s}=this,{factors:i}=s,{names:r,rank:o}=this.curCoordinateSpace;for(let a=0;a<o;++a){const c=i[a];c!==1&&(e[r[a]]=c,n=!0)}if(n)return e}restoreState(e){const{coordinateSpace:{value:n}}=this,{names:s,rank:i}=n,r=new Float64Array(i);if(r.fill(-1),e!==void 0){const o=(0,k.Rf)(e);for(let a=0;a<i;++a)r[a]=(0,k.cQ)(o,s[a],c=>c===void 0?1:(0,k.Mo)(c))}this.value_={factors:r},this.curCoordinateSpace=n,this.changed.dispatch()}setFactors(e){const{coordinateSpace:{value:n}}=this;e.length===n.rank&&(this.value_={factors:e},this.curCoordinateSpace=n,this.changed.dispatch())}update(){const{coordinateSpace:{value:e}}=this;let n=this.value_;const{curCoordinateSpace:s}=this;if(s===e)return n;const{ids:i}=s,{ids:r,rank:o}=e,a=n.factors,c=new Float64Array(o);c.fill(1);for(let l=0;l<o;++l){const u=r[l],d=i.indexOf(u);d!==-1&&(c[l]=a[d])}return It(c,a)||(n=this.value_={factors:c},this.curCoordinateSpace=e,this.changed.dispatch()),n}assign(e){this.setFactors(e.value.factors)}}function Lr(t,e,n,s,i){if(n===s)return e;const{ids:r}=n,{rank:o,ids:a}=s,c=new t(o);for(let l=0;l<o;++l){const u=a[l],d=r.indexOf(u);c[l]=d===-1?i(l):e[d]}return c}class dg extends vn{constructor(){super(...arguments),this.value=yn(new zu(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,n)=>e.assign(n),difference:(e,n)=>{const{factors:s}=e.value,i=e.coordinateSpace.value,r=n.value.factors;return{coordinateSpace:i,offsets:gs(new Float64Array(s.length),s,r)}},add:(e,n,s)=>{const i=Lr(Float64Array,s.offsets,s.coordinateSpace,e.coordinateSpace.value,()=>0);e.setFactors(Pi(new Float64Array(i.length),i,n.value.factors))},subtract:(e,n,s)=>{const i=Lr(Float64Array,s.offsets,s.coordinateSpace,e.coordinateSpace.value,()=>0);e.setFactors(gs(new Float64Array(i.length),n.value.factors,i))},isValid:()=>!0})}}function Ur(t,e,n){const{rank:s,names:i,units:r}=t,{displayRank:o,displayDimensionIndices:a}=e,c=new Float64Array(3),l=new Float64Array(3);let u;const{factors:d}=n,h=new Array(3),p=new Float64Array(3);if(c.fill(1),l.fill(1),p.fill(1),h.fill(""),o===0)u=1;else{u=Number.POSITIVE_INFINITY;const{scales:m}=t;for(let f=0;f<o;++f){const b=a[f],I=l[f]=d[b]*m[b];u=Math.min(u,I),h[f]=r[b],p[f]=m[b]}for(let f=0;f<o;++f)c[f]=l[f]/u}return{globalRank:s,globalDimensionNames:i,displayRank:o,displayDimensionIndices:a,displayDimensionUnits:h,displayDimensionScales:p,canonicalVoxelFactors:c,voxelPhysicalScales:l,canonicalVoxelPhysicalSize:u}}function Vr(t,e){return It(t.globalDimensionNames,e.globalDimensionNames)&&It(t.displayDimensionIndices,e.displayDimensionIndices)&&It(t.canonicalVoxelFactors,e.canonicalVoxelFactors)&&It(t.voxelPhysicalScales,e.voxelPhysicalScales)&&t.canonicalVoxelPhysicalSize===e.canonicalVoxelPhysicalSize&&It(t.displayDimensionUnits,e.displayDimensionUnits)&&It(t.displayDimensionScales,e.displayDimensionScales)}class hg extends Y.O8{constructor(e,n){super(),this.relativeDisplayScales=e,this.displayDimensions=n,this.changed=new Ie.IY,this.curRelativeDisplayScales=this.relativeDisplayScales.value,this.curDisplayDimensions=this.displayDimensions.value,this.curCoordinateSpace=this.relativeDisplayScales.coordinateSpace.value,this.value_=Ur(this.curCoordinateSpace,this.curDisplayDimensions,this.curRelativeDisplayScales),this.registerDisposer(e),this.registerDisposer(n);const s=()=>{this.value};this.registerDisposer(e.changed.add(s)),this.registerDisposer(n.changed.add(s))}get value(){const{relativeDisplayScales:{value:e,coordinateSpace:{value:n}},displayDimensions:{value:s},curRelativeDisplayScales:i,curDisplayDimensions:r,curCoordinateSpace:o}=this;let a=this.value_;if(i!==e||r!==s||o!==n){this.curRelativeDisplayScales=e,this.curDisplayDimensions=s,this.curCoordinateSpace=n;const c=Ur(n,s,e);Vr(a,c)||(this.value_=a=c,this.changed.dispatch())}return a}}class Fu extends Y.O8{constructor(e){super(),this.coordinateSpace=e,this.changed=new Ie.IY,this.default_=!0,this.value_=void 0,this.registerDisposer(this.coordinateSpace.changed.add(this.changed.dispatch)),this.update()}get value(){return this.update(),this.value_}update(){const{coordinateSpace:{value:e}}=this,n=this.value_;if(n!==void 0&&n.coordinateSpace===e)return;if(n===void 0||this.default_){this.setToDefault(e);return}const s=new Int32Array(3),{ids:i}=n.coordinateSpace,{ids:r}=e,o=n.displayDimensionIndices,a=n.displayRank;let c=0;for(let l=0;l<a;++l){const u=r.indexOf(i[o[l]]);u!==-1&&(s[c]=u,++c)}if(s.fill(-1,c),c===0){this.default_=!0,this.setToDefault(e);return}this.assignValue(e,c,s),this.changed.dispatch()}setToDefault(e){const n=Math.min(e.rank,3),s=new Int32Array(3);s.fill(-1);for(let i=0;i<n;++i)s[i]=i;this.assignValue(e,n,s)}assignValue(e,n,s){this.value_={coordinateSpace:e,displayRank:n,displayDimensionIndices:s},this.changed.dispatch()}reset(){this.default_=!0,this.value_=void 0,this.changed.dispatch()}restoreState(e){if(e===void 0){this.reset();return}const n=zi(e);if(n.length>3)throw new Error("Number of spatial dimensions must be <= 3");const{coordinateSpace:{value:s}}=this,i=new Int32Array(3);i.fill(-1);const{names:r}=s;let o=0;for(const a of n){const c=r.indexOf(a);c!==-1&&(i[o++]=c)}if(o===0){this.reset();return}this.default_=!1,this.assignValue(s,o,i)}get default(){return this.update(),this.default_}set default(e){this.default_!==e&&(e?(this.default_=!0,this.setToDefault(this.coordinateSpace.value)):(this.default_=!1,this.changed.dispatch()))}setDimensionIndices(e,n){this.default_=!1,this.assignValue(this.coordinateSpace.value,e,n)}toJSON(){if(this.default_)return;const{value:e}=this,n=[],{displayRank:s,displayDimensionIndices:i,coordinateSpace:{names:r}}=e;if(s!==0){for(let o=0;o<s;++o)n[o]=r[i[o]];return n}}assign(e){if(e.default)this.default=!0;else{const{displayRank:n,displayDimensionIndices:s}=e.value;this.setDimensionIndices(n,s)}}}class fg extends Ar{constructor(){super(...arguments),this.value=Or(new Fu(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,n)=>e.assign(n),isValid:()=>!0})}}class pg extends Y.O8{constructor(e,n,s){super(),this.position=e,this.displayDimensionRenderInfo=n,this.orientation=s,this.changed=new Ie.IY,this.registerDisposer(e),this.registerDisposer(s),this.registerDisposer(n),this.registerDisposer(e.changed.add(this.changed.dispatch)),this.registerDisposer(s.changed.add(this.changed.dispatch)),this.registerDisposer(n.changed.add(this.changed.dispatch))}get displayDimensions(){return this.displayDimensionRenderInfo.displayDimensions}get relativeDisplayScales(){return this.displayDimensionRenderInfo.relativeDisplayScales}get valid(){return this.position.valid}reset(){this.position.reset(),this.orientation.reset(),this.displayDimensions.reset()}updateDisplayPosition(e,n=$n){const{coordinateSpace:{value:s},value:i}=this.position,{displayDimensionIndices:r,displayRank:o}=this.displayDimensions.value;if(s===void 0)return!1;n.fill(0);for(let a=0;a<o;++a){const c=r[a];n[a]=i[c]}if(e(n)!==!1){for(let a=0;a<o;++a){const c=r[a];i[c]=n[a]}return this.position.changed.dispatch(),!0}return!1}toMat4(e,n){w.pB.fromQuat(e,this.orientation.orientation);const{value:s}=this.position,{canonicalVoxelFactors:i,displayDimensionIndices:r}=this.displayDimensionRenderInfo.value;for(let o=0;o<3;++o){const a=r[o],c=n/i[o];e[o]*=c,e[4+o]*=c,e[8+o]*=c,e[12+o]=s[a]||0}}toMat3(e,n){w.w0.fromQuat(e,this.orientation.orientation);const{canonicalVoxelFactors:s,displayRank:i}=this.displayDimensionRenderInfo.value;for(let r=0;r<i;++r){const o=n/s[r];e[r]*=o,e[3+r]*=o,e[6+r]*=o}}snap(){this.orientation.snap(),this.position.snapToVoxel(),this.changed.dispatch()}translateDimensionRelative(e,n){if(!this.valid)return;const{position:s}=this,{value:i}=s,{bounds:r}=s.coordinateSpace.value;i[e]=Ai(r,e,i[e]+n),s.changed.dispatch()}translateVoxelsRelative(e){if(!this.valid)return;const n=w.eR.transformQuat($n,e,this.orientation.orientation),{position:s}=this,{value:i}=s,{displayDimensionIndices:r,displayRank:o}=this.displayDimensions.value,{bounds:a}=s.coordinateSpace.value;for(let c=0;c<o;++c){const l=r[c],u=n[c];u!==0&&(i[l]=Ai(a,l,i[l]+u))}this.position.changed.dispatch()}rotateRelative(e,n){const s=w.Yu.create();w.Yu.setAxisAngle(s,e,n);const i=this.orientation.orientation;w.Yu.multiply(i,i,s),this.orientation.changed.dispatch()}rotateAbsolute(e,n,s){const{coordinateSpace:{value:i},value:r}=this.position;if(i===void 0)return;const{relativeDisplayScales:{value:{factors:o}},displayDimensions:{value:{displayDimensionIndices:a,displayRank:c}}}=this,{scales:l}=i,u=w.Yu.create();w.Yu.setAxisAngle(u,e,n);const d=this.orientation.orientation,h=$n;$n.fill(0);for(let m=0;m<c;++m){const f=a[m],b=s[f]-r[f];h[m]=b*l[f]*o[f]}const p=w.Yu.invert(Mr,d);w.eR.transformQuat(h,h,p),w.Yu.multiply(d,u,d),w.eR.transformQuat(h,h,d);for(let m=0;m<c;++m){const f=a[m];r[f]=s[f]-h[m]/(l[f]*o[f])}this.position.changed.dispatch(),this.orientation.changed.dispatch()}translateNonDisplayDimension(e,n){if(!this.valid)return;const{displayDimensionIndices:s}=this.displayDimensions.value,{position:i}=this,r=i.coordinateSpace.value.rank;for(let o=0;o<r;++o)if(s.indexOf(o)===-1&&e--===0){this.translateDimensionRelative(o,n);return}}}class mg extends vn{constructor(e,n){super(e),this.value=(()=>{const s=new e.constructor(n),i=(l,u)=>{l.assign(u)},r=(l,u)=>l.value/u.value*(l.canonicalVoxelPhysicalSize/u.canonicalVoxelPhysicalSize),o=(l,u,d)=>{l.setPhysicalScale(u.value*d,u.canonicalVoxelPhysicalSize)},a=(l,u,d)=>{l.setPhysicalScale(u.value/d,u.canonicalVoxelPhysicalSize)},c=l=>l.coordinateSpaceValue.valid&&l.canonicalVoxelPhysicalSize!==0;return yn(s,this.peer,this.link,{assign:i,isValid:c,difference:r,add:o,subtract:a}),s})()}}function gg(t){return{changed:t.changed,toJSON(){return t.toJSON()},restoreState(e){xr(t.link,t.value.legacyJsonView,e)},reset(){t.reset()}}}class yg extends Y.O8{constructor(e){super(),this.displayDimensionRenderInfo=e,this.changed=new Ie.IY,this.curCanonicalVoxelPhysicalSize=0,this.value_=Number.NaN,this.legacyValue_=Number.NaN,this.registerDisposer(e),this.registerDisposer(e.changed.add(()=>this.handleCoordinateSpaceChanged())),this.registerDisposer(e.relativeDisplayScales.coordinateSpace.changed.add(()=>this.handleCoordinateSpaceChanged())),this.handleCoordinateSpaceChanged()}get value(){return this.handleCoordinateSpaceChanged(),this.value_}set value(e){const{canonicalVoxelPhysicalSize:n}=this;Object.is(e,this.value_)&&n===this.curCanonicalVoxelPhysicalSize||(this.curCanonicalVoxelPhysicalSize=n,this.legacyValue_=Number.NaN,this.value_=e,this.changed.dispatch())}get canonicalVoxelPhysicalSize(){return this.displayDimensionRenderInfo.value.canonicalVoxelPhysicalSize}get coordinateSpaceValue(){return this.displayDimensionRenderInfo.relativeDisplayScales.coordinateSpace.value}set legacyValue(e){Object.is(e,this.legacyValue_)||(this.value_=Number.NaN,this.legacyValue_=e,this.curCanonicalVoxelPhysicalSize=0,this.changed.dispatch())}get legacyValue(){return this.legacyValue_}handleCoordinateSpaceChanged(){const{value_:e}=this,{displayDimensionRenderInfo:{value:{canonicalVoxelPhysicalSize:n},relativeDisplayScales:{coordinateSpace:{value:s}}}}=this,{curCanonicalVoxelPhysicalSize:i}=this;if(!(!Number.isNaN(e)&&n===i)){if(!Number.isNaN(e)){i!==0&&(this.value_=e*(i/n),this.curCanonicalVoxelPhysicalSize=n,this.changed.dispatch());return}!s.valid||n===0||(this.curCanonicalVoxelPhysicalSize=n,this.value_=this.getDefaultValue(),this.changed.dispatch())}}toJSON(){const{value:e}=this;return Number.isNaN(e)?void 0:e}restoreState(e){this.curCanonicalVoxelPhysicalSize=0,this.legacyValue_=Number.NaN,e===void 0?this.value_=Number.NaN:this.value_=(0,k.Mo)(e),this.changed.dispatch()}reset(){this.curCanonicalVoxelPhysicalSize=0,this.value_=Number.NaN,this.legacyValue_=Number.NaN,this.changed.dispatch()}get legacyJsonView(){const e=this;return{changed:e.changed,toJSON(){return e.toJSON()},reset(){return e.reset()},restoreState(n){e.legacyValue=(0,k.Mo)(n)}}}setPhysicalScale(e,n){const s=this.curCanonicalVoxelPhysicalSize=this.canonicalVoxelPhysicalSize;this.value=e*(n/s)}assign(e){const{legacyValue:n}=e;Number.isNaN(n)?this.setPhysicalScale(e.value,e.canonicalVoxelPhysicalSize):this.legacyValue=n}}class vg extends null{getDefaultValue(){const{legacyValue_:e}=this;if(Number.isNaN(e))return 1;const{canonicalVoxelPhysicalSize:n}=this;return this.legacyValue_*1e-9/n}}class wg extends null{getDefaultValue(){const{legacyValue_:e}=this;if(!Number.isNaN(e)){this.legacyValue_=Number.NaN;const{canonicalVoxelPhysicalSize:a}=this;return 200*Math.tan(Math.PI/8)*1e-9*e/a}const{coordinateSpaceValue:{bounds:{lowerBounds:n,upperBounds:s}}}=this,{canonicalVoxelFactors:i,displayDimensionIndices:r}=this.displayDimensionRenderInfo.value;let o=i.reduce((a,c,l)=>{const u=r[l],d=(s[u]-n[u])*c;return Math.max(a,d)},0);return Number.isFinite(o)?o=2**Math.ceil(Math.log2(o)):o=1024,o}}class Gu extends Y.O8{constructor(e,n){super(),this.defaultValue=e,this.displayDimensionRenderInfo=n,this.changed=new Ie.IY,this.value_=e,this.canonicalVoxelPhysicalSize=n.value.canonicalVoxelPhysicalSize,this.registerDisposer(n.changed.add(()=>{this.value}))}get value(){let{value_:e}=this;if(e>0){const{canonicalVoxelPhysicalSize:n}=this.displayDimensionRenderInfo.value,s=this.canonicalVoxelPhysicalSize;n!==s&&(this.canonicalVoxelPhysicalSize=n,e=this.value_=e=s/n,this.changed.dispatch())}return e}set value(e){if(e===this.value)return;this.value_=e;const{canonicalVoxelPhysicalSize:n}=this.displayDimensionRenderInfo.value;this.canonicalVoxelPhysicalSize=n,this.changed.dispatch()}toJSON(){const{value:e}=this;if(e!==this.defaultValue)return e}reset(){this.value=this.defaultValue}restoreState(e){typeof e!="number"||!Number.isFinite(e)||e===0?this.value=this.defaultValue:this.value=e}setValueAbsolute(e,n){if(e>0){const{canonicalVoxelPhysicalSize:s}=this.displayDimensionRenderInfo.value;e=e*(n/s)}this.value=e}assign(e){this.setValueAbsolute(e.value,e.canonicalVoxelPhysicalSize)}}class Sg extends Ar{constructor(e,n){super(e),this.value=Or(new Gu(e.defaultValue,n),this.peer,this.link,{assign:(s,i)=>s.assign(i),isValid:()=>!0})}}class bg extends Y.O8{constructor(e,n,s){super(),this.pose=e,this.zoomFactor=n,this.depthRange=s,this.changed=new Ie.IY,this.registerDisposer(e),this.registerDisposer(n),this.registerDisposer(s),this.registerDisposer(this.pose.changed.add(this.changed.dispatch)),this.registerDisposer(this.zoomFactor.changed.add(this.changed.dispatch)),this.registerDisposer(this.depthRange.changed.add(this.changed.dispatch))}get coordinateSpace(){return this.pose.position.coordinateSpace}reset(){this.pose.reset(),this.zoomFactor.reset()}get position(){return this.pose.position}get displayDimensions(){return this.pose.displayDimensions}get relativeDisplayScales(){return this.pose.relativeDisplayScales}get displayDimensionRenderInfo(){return this.pose.displayDimensionRenderInfo}toMat4(e){this.pose.toMat4(e,this.zoomFactor.value)}toMat3(e){this.pose.toMat3(e,this.zoomFactor.value)}get relativeDepthRange(){let e=this.depthRange.value;return e>0?e/=this.zoomFactor.value:e*=-1,e}get valid(){return this.pose.valid&&!Number.isNaN(this.zoomFactor.value)}zoomBy(e){this.zoomFactor.value*=e}}var ju=x(9100),Yu=Object.defineProperty,Ju=Object.getOwnPropertyDescriptor,Hu=(t,e,n,s)=>{for(var i=s>1?void 0:s?Ju(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Yu(e,n,i),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.
 */const Wu="DisjointUint64Sets",Br="DisjointUint64Sets.add",$r="DisjointUint64Sets.clear",zr="DisjointUint64Sets.highBitRepresentativeChanged",Fr="DisjointUint64Sets.deleteSet";let Fn=class extends U{constructor(){super(...arguments),this.disjointSets=new ju.I,this.changed=new Ie.IY}get value(){return this}static makeWithCounterpart(t,e){const n=new Fn;return n.disjointSets.visibleSegmentEquivalencePolicy=e,n.registerDisposer(e.changed.add(()=>{Gr(n)})),n.initializeCounterpart(t),e.value&&Gr(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(Br,{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($r,{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(Fr,{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 ee.R,new ee.R];(0,k.$v)(t,n=>{(0,k.$v)(n,(s,i)=>{e[i%2].parseString(String(s),10),i!==0&&this.link(e[0],e[1])})})}}assignFrom(t){this.clear(),t instanceof Fn&&(t=t.disjointSets);for(const[e,n]of t)this.link(e,n)}};Fn=Hu([O(Wu)],Fn);const tn=new ee.R,zs=new ee.R;Q(Br,function(t){const e=this.get(t.id);tn.low=t.al,tn.high=t.ah,zs.low=t.bl,zs.high=t.bh,e.disjointSets.link(tn,zs)&&e.changed.dispatch()}),Q($r,function(t){const e=this.get(t.id);e.disjointSets.clear()&&e.changed.dispatch()});function Gr(t){t.rpc.invoke(zr,{id:t.rpcId,value:t.disjointSets.visibleSegmentEquivalencePolicy.value})}Q(zr,function(t){const e=this.get(t.id);e.disjointSets.visibleSegmentEquivalencePolicy.value=t.value}),Q(Fr,function(t){const e=this.get(t.id);tn.low=t.l,tn.high=t.h,e.disjointSets.deleteSet(tn)&&e.changed.dispatch()});var Gn=x(9254);/**
 * @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 jr=3,Ku=.8,Rt=!1;let pt=0,mt=0,Yr=0,Jr=0;class wn{constructor(e=wn.generateHashSeeds(jr)){this.hashSeeds=e,this.loadFactor=Ku,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=wn.generateHashSeeds(e),this.mungedEmptyKey=-1}tableWithMungedEmptyKey(e){const n=this.hashSeeds.length,s=new Array(n);for(let c=0;c<n;++c)s[c]=this.getHash(c,this.emptyLow,this.emptyHigh);let{mungedEmptyKey:i}=this;if(i===-1)e:for(;;){i=Math.random()*16777216>>>0;for(let c=0;c<n;++c){const l=this.getHash(c,i,i);for(let u=0;u<n;++u)if(s[u]===l)continue e}this.mungedEmptyKey=i;break}const{table:r,emptyLow:o,emptyHigh:a}=this;for(let c=0;c<n;++c){const l=s[c];r[l]===o&&r[l+1]===a&&(r[l]=i,r[l+1]=i)}try{e(r)}finally{for(let c=0;c<n;++c){const l=s[c];r[l]===i&&r[l+1]===i&&(r[l]=o,r[l+1]=a)}}}static generateHashSeeds(e=jr){return gu(new Uint32Array(e))}getHash(e,n,s){let i=this.hashSeeds[e];return i=(0,Gn._)(i,n),i=(0,Gn._)(i,s),this.entryStride*(i&this.tableSize-1)}*keys(){const{emptyLow:e,emptyHigh:n,entryStride:s}=this,{table:i}=this;for(let r=0,o=i.length;r<o;r+=s){const a=i[r],c=i[r+1];(a!==e||c!==n)&&(yield new ee.R(a,c))}}*unsafeKeys(e=new ee.R){const{emptyLow:n,emptyHigh:s,entryStride:i}=this,{table:r}=this;for(let o=0,a=r.length;o<a;o+=i){const c=r[o],l=r[o+1];(c!==n||l!==s)&&(e.low=c,e.high=l,yield e)}}indexOfPair(e,n){const{table:s,emptyLow:i,emptyHigh:r}=this;if(e===i&&n===r)return-1;for(let o=0,a=this.hashSeeds.length;o<a;++o){const c=this.getHash(o,e,n);if(s[c]===e&&s[c+1]===n)return c}return-1}indexOf(e){return this.indexOfPair(e.low,e.high)}chooseAnotherEmptyKey(){const{emptyLow:e,emptyHigh:n,table:s,entryStride:i}=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=s.length;a<c;a+=i)s[a]===e&&s[a+1]===n&&(s[a]=r,s[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:s}=this;return s[n]=this.emptyLow,s[n+1]=this.emptyHigh,++this.generation,this.size--,!0}return!1}clearTable(){const{table:e,entryStride:n,emptyLow:s,emptyHigh:i}=this,r=e.length;for(let o=0;o<r;o+=n)e[o]=s,e[o+1]=i}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 s=pt,i=mt;this.storePending(e,n),e[n]=s,e[n+1]=i}storePending(e,n){pt=e[n],mt=e[n+1]}backupPending(){Yr=pt,Jr=mt}restorePending(){pt=Yr,mt=Jr}tryToInsert(){Rt&&console.log(`tryToInsert: ${pt}, ${mt}`);let e=0;const{emptyLow:n,emptyHigh:s,maxAttempts:i,table:r}=this,o=this.hashSeeds.length;let a=Math.floor(Math.random()*o);for(;;){const c=this.getHash(a,pt,mt);if(this.swapPending(r,c),pt===n&&mt===s)return!0;if(++e===i)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){Rt&&console.log("rehash begin"),this.allocate(n),this.updateHashFunctions(this.hashSeeds.length);const{emptyLow:s,emptyHigh:i,entryStride:r}=this;for(let o=0,a=e.length;o<a;o+=r){const c=e[o],l=e[o+1];if((c!==s||l!==i)&&(this.storePending(e,o),!this.tryToInsert()))return Rt&&console.log("rehash failed"),!1}return Rt&&console.log("rehash end"),!0}grow(e){Rt&&console.log(`grow: ${e}`);const n=this.table;let{tableSize:s}=this;for(;s<e;)s*=2;for(;;){for(let i=0;i<this.maxRehashAttempts;++i)if(this.rehash(n,s)){Rt&&console.log("grow end");return}s*=2}}insertInternal(){for(++this.generation,pt===this.emptyLow&&mt===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 Hr extends wn{add(e){const{low:n,high:s}=e;return this.hasPair(n,s)?!1:(Rt&&console.log(`add: ${n},${s}`),pt=n,mt=s,this.insertInternal(),!0)}[Symbol.iterator](){return this.unsafeKeys()}}Hr.prototype.entryStride=2;let Sn=0,bn=0,Wr=0,Kr=0;class qr extends wn{set(e,n){const{low:s,high:i}=e;return this.hasPair(s,i)?!1:(Rt&&console.log(`add: ${s},${i} -> ${n.low},${n.high}`),pt=s,mt=i,Sn=n.low,bn=n.high,this.insertInternal(),!0)}get(e,n){const s=this.indexOf(e);if(s===-1)return!1;const{table:i}=this;return n.low=i[s+2],n.high=i[s+3],!0}swapPending(e,n){const s=Sn,i=bn;super.swapPending(e,n),e[n+2]=s,e[n+3]=i}storePending(e,n){super.storePending(e,n),Sn=e[n+2],bn=e[n+3]}backupPending(){super.backupPending(),Wr=Sn,Kr=bn}restorePending(){super.restorePending(),Sn=Wr,bn=Kr}[Symbol.iterator](){return this.unsafeEntries()}*entries(){const{emptyLow:e,emptyHigh:n,entryStride:s}=this,{table:i}=this;for(let r=0,o=i.length;r<o;r+=s){const a=i[r],c=i[r+1];if(a!==e||c!==n){const l=new ee.R(a,c),u=new ee.R(i[r+2],i[r+3]);yield[l,u]}}}*unsafeEntries(e=[new ee.R,new ee.R]){const{emptyLow:n,emptyHigh:s,entryStride:i}=this,{table:r}=this,[o,a]=e;for(let c=0,l=r.length;c<l;c+=i){const u=r[c],d=r[c+1];(u!==n||d!==s)&&(o.low=u,o.high=d,a.low=r[c+2],a.high=r[c+3],yield e)}}}qr.prototype.entryStride=4;var qu=Object.defineProperty,Qu=Object.getOwnPropertyDescriptor,Xu=(t,e,n,s)=>{for(var i=s>1?void 0:s?Qu(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&qu(e,n,i),i};/**
 * @license
 * This work is a derivative of the Google Neuroglancer project,
 * Copyright 2016 Google Inc.
 * The Derivative Work is covered by
 * Copyright 2019 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.
 */let Fs=class extends U{constructor(){super(...arguments),this.hashTable=new qr,this.changed=new Ie.HN}get value(){return this}static makeWithCounterpart(t){const e=new Fs;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}};Fs=Xu([O("Uint64Map")],Fs),Q("Uint64Map.set",function(t){const e=this.get(t.id);e.set_(t.key,t.value)&&e.changed.dispatch()}),Q("Uint64Map.delete",function(t){const e=this.get(t.id);e.delete_(t.key)&&e.changed.dispatch()}),Q("Uint64Map.clear",function(t){const e=this.get(t.id);e.hashTable.clear()&&e.changed.dispatch()});var Zu=Object.defineProperty,ed=Object.getOwnPropertyDescriptor,td=(t,e,n,s)=>{for(var i=s>1?void 0:s?ed(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Zu(e,n,i),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.
 */let In=class extends U{constructor(){super(...arguments),this.hashTable=new Hr,this.changed=new Ie.HN}get value(){return this}static makeWithCounterpart(t){const e=new In;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)}};In=td([O("Uint64Set")],In),Q("Uint64Set.reserve",function(t){const e=this.get(t.id);e.reserve_(t.value)&&e.changed.dispatch()}),Q("Uint64Set.add",function(t){const e=this.get(t.id);e.add_(t.value)&&e.changed.dispatch()}),Q("Uint64Set.delete",function(t){const e=this.get(t.id);e.delete_(t.value)&&e.changed.dispatch()}),Q("Uint64Set.clear",function(t){const e=this.get(t.id);e.hashTable.clear()&&e.changed.dispatch()});var Gs=x(4242);/**
 * @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 nd=["visibleSegments","segmentEquivalences","temporaryVisibleSegments","temporarySegmentEquivalences","useTemporaryVisibleSegments","useTemporarySegmentEquivalences"];function Qr(t,e,n){t.registerDisposer(e.visibleSegments.changed.add(n)),t.registerDisposer(e.segmentEquivalences.changed.add(n))}function Xr(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 jn(t){return`${t.low},${t.high}`}function sd(t){return!!(t.high>>>31)}function id(t){return t.useTemporaryVisibleSegments.value?t.temporaryVisibleSegments:t.visibleSegments}function rd(t){return t.useTemporarySegmentEquivalences.value?t.temporarySegmentEquivalences:t.segmentEquivalences}function Cn(t,e){const n=id(t),s=rd(t),i=s.disjointSets.visibleSegmentEquivalencePolicy.value;for(const r of n.unsafeKeys())if(i&Gs.y6.NONREPRESENTATIVE_EXCLUDED){const o=s.get(r);e(r,o)}else{if(!s.disjointSets.isMinElement(r))continue;for(const o of s.setElements(r))i&Gs.y6.REPRESENTATIVE_EXCLUDED&&i&Gs.y6.MAX_REPRESENTATIVE&&sd(o)||e(o,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.
 */function Zr(t,e,n={}){for(const s of nd)n[s]=t.get(e[s]);return n}const Yn=t=>class extends t{constructor(...n){const[s,i]=n;super(s,i),Zr(s,i,this),this.transform=s.get(i.transform),this.renderScaleTarget=s.get(i.renderScaleTarget);const r=()=>{this.chunkManager.scheduleUpdateChunkPriorities()};Xr(this,this,r),Qr(this,this,r),this.registerDisposer(this.transform.changed.add(r)),this.registerDisposer(this.renderScaleTarget.changed.add(r))}};class od extends oe{constructor(e,n){super(e,n),this.properties=n.properties}}var ad=Object.defineProperty,cd=Object.getOwnPropertyDescriptor,Jn=(t,e,n,s)=>{for(var i=s>1?void 0:s?cd(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&ad(e,n,i),i};/**
 * @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 ld=200,ud=60;class dd extends g{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 eo{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 to(t){class e extends t{serialize(s,i){super.serialize(s,i);const{data:r}=this;r!==void 0&&(r.serialize(s,i),this.data=void 0)}downloadSucceeded(){const{data:s}=this;this.systemMemoryBytes=this.gpuMemoryBytes=s===void 0?0:s.numBytes,super.downloadSucceeded()}freeSystemMemory(){this.data=void 0}}return e}class hd extends to(ir){}class fd extends to(g){}let no=class extends oe{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_(dd),n.initialize(t),this.addChunk(n)),n}download(t,e){return this.parent.downloadMetadata(t,e)}};no=Jn([O(Jl)],no);class js extends rr{constructor(e,n){super(e,n),this.parent=e.get(n.parent)}}js.prototype.chunkConstructor=hd;let so=class extends oe{constructor(){super(...arguments),this.parent=void 0}getChunk(t){const e=jn(t),{chunks:n}=this;let s=n.get(e);return s===void 0&&(s=this.getNewChunk_(fd),s.initialize(e),s.objectId=t.clone(),this.addChunk(s)),s}download(t,e){return this.parent.downloadSegmentFilteredGeometry(t,this.relationshipIndex,e)}};so=Jn([O(Hl)],so);class io extends U{constructor(e,n){super(e,n),this.references=new Set;const s=this.chunkManager=e.get(n.chunkManager),i=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}),i.parent=this,this.registerDisposer(s.recomputeChunkPriorities.add(()=>this.recomputeChunkPriorities()))}recomputeChunkPriorities(){const{chunkManager:e,metadataChunkSource:n}=this;for(const s of this.references)e.requestChunk(n.getChunk(s),se.VISIBLE,ld)}add(e){throw new Error("Not implemented")}delete(e){throw new Error("Not implemented")}update(e,n){throw new Error("Not implemented")}}Q(Wl,function(t){const e=this.get(t.id);e.references.add(t.annotation),e.chunkManager.scheduleUpdateChunkPriorities()}),Q(Kl,function(t){const e=this.get(t.id);e.references.delete(t.annotation),e.chunkManager.scheduleUpdateChunkPriorities()}),Q(ql,function(t){const e=this.get(t.id),n=t.annotationId,s=Ou(t.newAnnotation);let i;n===void 0?i=e.add(s).then(r=>({...s,id:r})):s===null?i=e.delete(n).then(()=>null):i=e.update(n,s).then(()=>s),i.then(r=>{e.wasDisposed||this.invoke(fr,{id:e.rpcId,annotationId:n||s.id,newAnnotation:r})},r=>{e.wasDisposed||this.invoke(fr,{id:e.rpcId,annotationId:n||s?.id,error:r.message})})});let Ys=class extends bt(An){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 s=t.state,{transformedSources:i,displayDimensionRenderInfo:r}=s;if(i.length===0)continue;const o=e.projectionParameters.value.displayDimensionRenderInfo;if(r!==o){if(!Vr(r,o))continue;s.displayDimensionRenderInfo=o}const a=dt(n),c=ht(n),l=e.projectionParameters.value,{chunkManager:u}=this;nu(l,this.localPosition.value,this.renderScaleTarget.value,i[0],()=>{},(d,h)=>{const p=d.source.getChunk(d.curPositionInChunks);++this.numVisibleChunksNeeded,p.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable,u.requestChunk(p,a,c+0+Ts*h)})}}};Ys=Jn([O(Ql)],Ys),Q(Xl,function(t){const e=this.get(t.view),n=this.get(t.layer),s=n.attachments.get(e);s.state.transformedSources=Bn(this,t.sources,n),s.state.displayDimensionRenderInfo=t.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()});let Js=class extends Lt(bt(ms)){constructor(t,e){super(t,e),this.source=t.get(e.source),this.segmentationStates=new ye.B0(this.getSegmentationState(e.segmentationStates));const n=()=>this.chunkManager.scheduleUpdateChunkPriorities();this.registerDisposer((0,ye.no)((s,i)=>{if(i!==void 0){for(const r of i)r!=null&&(Qr(s,r,n),Xr(s,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:s}=this;s.registerLayer(this);const i=e.length;for(let r=0;r<i;++r){const o=e[r];if(o==null)continue;const a=dt(t),c=ht(t),l=n[r];Cn(o,u=>{const d=l.getChunk(u);++this.numVisibleChunksNeeded,d.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable,s.requestChunk(d,a,c+ud)})}}getSegmentationState(t){if(t!==void 0)return t.map(e=>e==null?e:Zr(this.rpc,e))}};Js=Jn([O(Zl)],Js),Q(eu,function(t){const e=this.get(t.id);e.segmentationStates.value=e.getSegmentationState(t.segmentationStates)});/**
 * @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 pd extends Y.O8{}function Hs(t){let e,n,s;return(i,r)=>n!==void 0&&(e===void 0||i===void 0||e.generation!==i.generation)?(e===void 0&&s.addConsumer(r),n):(e=void 0,s=new j.y3,n=t(i,s).then(o=>(e=o,s=void 0,o),o=>{throw s.isCanceled&&(s=void 0,n=void 0),o}),n)}function Ig(t){let e=0;return Hs((n,s)=>t(s).then(i=>({generation:++e,credentials:i})))}class md{constructor(){this.providers=new Map,this.topLevelManager=this}register(e,n){this.providers.set(e,n)}getCredentialsProvider(e,n){const s=this.providers.get(e);if(s===void 0)throw new Error(`No registered credentials provider: ${JSON.stringify(e)}`);return s(n,this.topLevelManager)}}class gd extends Y.O8{constructor(e){super(),this.base=e,this.memoize=new Ke.e}getCredentialsProvider(e,n){return this.memoize.get({key:e,parameters:n},()=>this.registerDisposer(this.base.getCredentialsProvider(e,n).addRef()))}}class Cg extends gd{constructor(){super(new md),this.base.topLevelManager=this}register(e,n){this.base.register(e,n)}}class Eg extends pd{constructor(e,n){super(),this.baseProvider=e,this.anonymousCredentials=n,this.anonymous=!0,this.get=Hs(s=>this.anonymous&&s===void 0?Promise.resolve({generation:-10,credentials:this.anonymousCredentials}):(this.anonymous=!1,this.baseProvider.get(s)))}}var ro=x(957),yd=Object.defineProperty,vd=Object.getOwnPropertyDescriptor,wd=(t,e,n,s)=>{for(var i=s>1?void 0:s?vd(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&yd(e,n,i),i};/**
 * @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.
 */let oo=class extends U{constructor(){super(...arguments),this.get=Hs((t,e)=>this.rpc.promiseInvoke(ro.y,{providerId:this.rpcId,invalidCredentials:t},e))}};oo=wd([O(ro.P)],oo);function je(){return t=>class extends t{constructor(...e){super(...e);const n=e[1];this.credentialsProvider=this.rpc.getOptionalRef(n.credentialsProvider)}}}var ao=x(2366),ge=x(9808);/**
 * @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 kg="boss";function Sd(t,e,n,s,i=j.fx){return(0,ge.Bk)(e,n,s,i).catch(r=>{if(r.status!==500&&r.status!==401&&r.status!==403&&r.status!==504)throw r;return(0,ao.R)(t,e,n,s,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},i)})}var co=x(6650),_t=x(3708);/**
 * @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 Hn=!1;function lo(t,e,n,s,i,r,o){const{octree:a,lodScales:c,chunkGridSpatialOrigin:l,chunkShape:u}=t,d=c.length-1,h=e[0],p=e[4],m=e[8],f=e[1],b=e[5],I=e[9],E=e[3],V=e[7],R=e[11],C=e[15],S=E>0?0:1,T=V>0?0:1,v=R>0?0:1,N=n[4*4],H=n[4*4+1],y=n[4*4+2],A=n[4*4+3];function L(vt,jt,xt){return E*vt+V*jt+R*xt+C}function G(vt,jt,xt,At,Yt,Si){return L(vt+S*(At-vt),jt+T*(Yt-jt),xt+v*(Si-xt))}const ue=L(-A*N,-A*H,-A*y),we=t.clipLowerBound[0],fe=t.clipLowerBound[1],Fe=t.clipLowerBound[2],$e=t.clipUpperBound[0],Nt=t.clipUpperBound[1],Pn=t.clipUpperBound[2],un=Math.sqrt((h*i)**2+(f*r)**2),Gt=Math.sqrt((p*i)**2+(b*r)**2),rt=Math.sqrt((m*i)**2+(I*r)**2),yt=Math.max(un,Gt,rt);function Rn(vt,jt,xt){const At=1<<vt,Yt=jt*5,Si=a[Yt],yp=a[Yt+1],vp=a[Yt+2],wp=a[Yt+3],cc=a[Yt+4];let _n=Si*At*u[0]+l[0],Mn=yp*At*u[1]+l[1],On=vp*At*u[2]+l[2],ds=_n+At*u[0],hs=Mn+At*u[1],fs=On+At*u[2];if(_n=Math.max(_n,we),Mn=Math.max(Mn,fe),On=Math.max(On,Fe),ds=Math.min(ds,$e),hs=Math.min(hs,Nt),fs=Math.min(fs,Pn),(0,w.T_)(_n,Mn,On,ds,hs,fs,n)){const bi=Math.max(ue,G(_n,Mn,On,ds,hs,fs))/yt;if(xt===0||bi*s<xt){const dn=c[vt];if(dn!==0&&o(vt,jt,dn/bi,cc>>>31),vt>0&&(dn===0||bi*s<dn)){const Sp=dn===0?xt:dn,bp=(cc&2147483647)>>>0;for(let Ii=wp;Ii<bp;++Ii)Rn(vt-1,Ii,Sp)}}}}Rn(d,a.length/5-1,0)}function Tg(t,e,n,s,i,r,o,a){const{lodScales:c}=t;let l=0;for(;l+1<c.length&&c[l+1]!==0;)++l;const u=3,d=[];let h=0,p=0;function m(I,E){for(Hn&&console.log(`emitChunksUpTo: stackDepth=${h}, targetStackIndex=${I}, subChunkIndex=${E}, priorSubChunkIndex=${p}`);;){if(h===0)return;const V=h-1,R=l-V,C=d[V*u],S=R===0?1:8,T=d[V*u+1],v=d[V*u+2];if(I===h){const N=E&S-1;p!==N&&C!==-1&&(Hn&&console.log(`  drawing chunk because priorSubChunkIndex (${p}) != endSubChunk (${N})`),a(R,C,p,N,v)),p=N+1;return}p!==S&&C!==-1&&a(R,C,p,S,v),p=T+1,--h}}let f=0;Hn&&(console.log(""),console.log("Starting to draw"));const{octree:b}=t;lo(t,e,n,s,i,r,(I,E,V,R)=>{if(!R&&!o(I,E,V)){f=Math.max(I,f);return}if(I<f)return;f=0;const C=E*5,S=b[C],T=b[C+1],v=b[C+2],N=getOctreeChildIndex(S,T,v),H=l-I;m(H,N);const y=H*u;d[y]=R?-1:E,d[y+1]=N,d[y+2]=V,Hn&&console.log(`Adding to stack: lod=${I}, row=${d[y]}, subChunkIndex=${N}`),p=0,h=H+1}),m(0,0)}function Dg(t){if(t.length%5!==0)throw new Error("Invalid length");const e=t.length/5,n=new Set;function s(i){if(n.has(i))throw new Error("Previously seen node");if(n.add(i),i<0||i>=e)throw new Error("Invalid node reference");const r=t[i*5],o=t[i*5+1],a=t[i*5+2],c=t[i*5+3],l=t[i*5+4];if(c<0||l<0||l<c||l>e||c+8<l)throw new Error("Invalid child references");for(let u=c;u<l;++u){const d=t[u*5],h=t[u*5+1],p=t[u*5+2];if(d>>>1!==r||h>>>1!==o||p>>>1!==a)throw new Error("invalid child");s(u)}}if(e!==0&&(s(e-1),n.size!==e))throw new Error("Orphan nodes in octree")}function Pg(t,e,n){return`${t}/${e}:${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 Wn=!1;function bd(t){let e=0;for(let n=0,s=t.length;n<s;n+=3){let i=t[n],r=t[n+1],o=t[n+2],a;i>r&&(a=i,i=r,r=a),r>o&&(a=r,r=o,o=a),i>r&&(a=i,i=r,r=a),t[n]=i,t[n+1]=r,t[n+2]=o,o>e&&(e=o)}return e}let Ws=0;function Id(t,e,n,s,i,r){const o=e-1>>>0;let a=(i&o)>>>0;for(let c=0;;++c){const l=t[a];if(l===s)return t[a]=n,n;if(r(l))return l;++Ws,a=(a+c+1&o)>>>0}}function Cd(t,e){return(0,Gn._)((0,Gn._)(0,t),e)}const Ed=1053042;function kd(t){return Ed>>>t*3&7}function Kn(t){return(t>>>2)*3}function qn(t){return t&3}function Ks(t){return t>>>1}function qs(t){return 1+(t+1>>>1)}function uo(t){return 2-t}function Td(t){return 2**Math.ceil(Math.log2(t))*4}function Dd(t,e,n){const s=e.length/3,i=n.length,r=4294967295;t.fill(r),n.fill(r);for(let o=0;o<s;++o){const a=o*3;for(let c=0;c<3;++c){const l=e[a+Ks(c)],u=e[a+qs(c)],d=o<<2|c,h=Id(n,i,d,r,Cd(l,u),p=>{const m=Kn(p),f=qn(p),b=e[m+Ks(f)],I=e[m+qs(f)];return l===b&&u===I});if(h!==d){const p=Kn(h),m=qn(h);t[p+m]=d,t[a+c]=h}}}return t}function Pd(t,e,n,s){const i=-1>>>32-8*n.BYTES_PER_ELEMENT,o=t.length/3,a=4294967295;e:for(let c=0;c<o;++c){let l=c*3;if(t[l]!==i){for(let u=0;u<3;++u){let d=e[l+u];if(d===a)continue;let h=Kn(d);if(t[h]===i)continue;const p=qn(d);n[s++]=t[l+uo(u)],n[s++]=t[l+Ks(u)],n[s++]=t[l+qs(u)];let m=p;for(;;){if(t[l]=i,l=h,n[s++]=t[l+uo(m&3)],m=kd(m),d=e[l+(m&3)],d===a||t[h=Kn(d)]===i){n[s++]=i,t[l]=i;continue e}m=qn(d)|m&4}}n[s++]=t[l],n[s++]=t[l+1],n[s++]=t[l+2],t[l]=i,n[s++]=i}}return s}function Rd(t,e){if(t.length===0)return t;Ws=0,e===void 0&&(e=Uint32Array.of(0,t.length));let n=0,s=0,i=0,r=0,o=0;const a=bd(t),c=t.length/3*4,l=a>=65535?new Uint32Array(c):new Uint16Array(c);let u=0,d=0;const h=e.length-1;for(let I=0;I<h;++I)d=Math.max(d,e[I+1]-e[I]);const p=new Uint32Array(d),m=new Uint32Array(Td(d));let f=e[0];for(let I=0;I<h;++I){e[I]=u;const E=e[I+1],V=t.subarray(f,E);Wn&&(i=Date.now()),Dd(p,V,m),Wn&&(r=Date.now()),u=Pd(V,p,l,u),Wn&&(o=Date.now(),n+=r-i,s+=o-r),f=E}--u,e[h]=u;const b=new l.constructor(u);return b.set(l.subarray(0,u)),Wn&&console.log(`reduced from ${t.byteLength}(${t.BYTES_PER_ELEMENT}) -> ${b.byteLength}(${b.BYTES_PER_ELEMENT}): adj=${n}, emit=${s}, ${Ws}/${t.length} collisions`),b}/**
 * @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 _d(t,e,n){return t&1|e<<1&2|n<<2&4}function Md(t,e,n,s){const i=Math.max(e,n,s);let r=0,o=t.low,a=0,c=0,l=0;for(let u=0;u<i;++u){if(u<e){const d=o>>>r&1;a|=d<<u,r===31?(r=0,o=t.high):++r}if(u<n){const d=o>>>r&1;c|=d<<u,r===31?(r=0,o=t.high):++r}if(u<s){const d=o>>>r&1;l|=d<<u,r===31?(r=0,o=t.high):++r}}return Uint32Array.of(a,c,l)}function ho(t,e,n,s,i,r,o){const a=Math.max(e,n,s);let c=0,l=0,u=!1;function d(h){l|=(h&1)<<c,++c===32&&(t.low=l>>>0,l=0,c=0,u=!0)}for(let h=0;h<a;++h)h<e&&d(i>>h&1),h<n&&d(r>>h&1),h<s&&d(o>>h&1);return u?t.high=l>>>0:(t.high=0,t.low=l>>>0),t}function Od(t,e,n){let s=0;const i=e.length;let r=0,o=!1;function a(c){r|=(c&1)<<s,++s===32&&(t.low=r>>>0,r=0,s=0,o=!0)}for(let c=0;c<32;++c)for(let l=0;l<i;++l)n[l]-1>>>c&&a(e[l]>>>c);return o?t.high=r>>>0:(t.high=0,t.low=r>>>0),t}function fo(t,e){return t<e&&t<(t^e)}function Qs(t,e,n,s,i,r){let o=n,a=r;return fo(o^a,e^i)&&(o=e,a=i),fo(o^a,t^s)&&(o=t,a=s),o<a}var Nd=Object.defineProperty,xd=Object.getOwnPropertyDescriptor,Qn=(t,e,n,s)=>{for(var i=s>1?void 0:s?xd(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Nd(e,n,i),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.
 */const po=100,mo=50,Ad=!1;class Ld extends g{constructor(){super(...arguments),this.objectId=new ee.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<se.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities()}toString(){return this.objectId.toString()}}function go(t,e,n){const{vertexPositions:s,indices:i,vertexNormals:r,strips:o}=t;e.vertexPositions=s,e.indices=i,e.strips=o,e.vertexNormals=r;const a=s.buffer;n.push(a);const c=i.buffer;c!==a&&n.push(c),n.push(r.buffer)}function yo(t){const{vertexPositions:e,indices:n,vertexNormals:s}=t;return e.byteLength+n.byteLength+s.byteLength}class Ud extends g{constructor(){super(...arguments),this.manifestChunk=null,this.fragmentId=null,this.meshData=null}initializeFragmentChunk(e,n,s){super.initialize(e),this.manifestChunk=n,this.fragmentId=s}freeSystemMemory(){this.manifestChunk=null,this.meshData=null,this.fragmentId=null}serialize(e,n){super.serialize(e,n),go(this.meshData,e,n),this.meshData=null}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=yo(this.meshData),super.downloadSucceeded()}}function vo(t,e,n){(0,k.Rf)(e),t.fragmentIds=(0,k.cQ)(e,n,k.si)}function wo(t,e){const n=w.eR.create(),s=w.eR.create(),i=w.eR.create(),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,d=e[c+2]*3;for(let h=0;h<3;++h)s[h]=t[u+h]-t[l+h],i[h]=t[d+h]-t[u+h];w.eR.cross(n,s,i),w.eR.normalize(n,n);for(let h=0;h<3;++h){const m=e[c+h]*3;for(let f=0;f<3;++f)r[m+f]+=n[f]}}const a=r.length;for(let c=0;c<a;c+=3){const l=r.subarray(c,c+3);w.eR.normalize(l,l)}return r}function Xn(t){return Math.min(Math.max(-127,t*127+.5),127)>>>0}function So(t){return t<0?-1:1}function Vd(t,e){const n=e.length;let s=0;for(let i=0;i<n;i+=3){const r=e[i],o=e[i+1],a=e[i+2],c=1/(Math.abs(r)+Math.abs(o)+Math.abs(a));a<0?(t[s]=Xn((1-Math.abs(o*c))*So(r)),t[s+1]=Xn((1-Math.abs(r*c))*So(o))):(t[s]=Xn(r*c),t[s+1]=Xn(o*c)),s+=2}}function bo(t,e,n,s,i,r,o){const a=new Float32Array(e,s,i*3);ft(a,n),r===void 0&&(r=s+12*i);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 ft(l,n),{vertexPositions:a,indices:l}}function Zn(t,e,n,s,i,r){return bo(3,t,e,n,s,i,r)}class nn extends oe{constructor(e,n){super(e,n);const s=this.fragmentSource=this.registerDisposer(e.getRef(n.fragmentSource));s.meshSource=this}getChunk(e){const n=jn(e);let s=this.chunks.get(n);return s===void 0&&(s=this.getNewChunk_(Ld),s.initializeManifestChunk(n,e),this.addChunk(s)),s}getFragmentKey(e,n){return{key:`${e}/${n}`,fragmentId:n}}getFragmentChunk(e,n){const s=this.fragmentSource,{key:i,fragmentId:r}=this.getFragmentKey(e.key,n);let o=s.chunks.get(i);return o===void 0&&(o=s.getNewChunk_(Ud),o.initializeFragmentChunk(i,e,r),s.addChunk(o)),o}}let Io=class extends oe{constructor(){super(...arguments),this.meshSource=null}download(t,e){return this.meshSource.downloadFragment(t,e)}};Io=Qn([O(_t.dI)],Io);let Co=class extends Yn(Lt(bt(dr))){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=dt(t),n=ht(t),{source:s,chunkManager:i}=this;Cn(this,r=>{const o=s.getChunk(r);++this.numVisibleChunksNeeded,i.requestChunk(o,e,n+po);const a=o.state;if(a===M.SYSTEM_MEMORY_WORKER||a===M.SYSTEM_MEMORY||a===M.GPU_MEMORY){++this.numVisibleChunksAvailable;for(const c of o.fragmentIds){const l=s.getFragmentChunk(o,c);++this.numVisibleChunksNeeded,i.requestChunk(l,e,n+mo),l.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable}}})}};Co=Qn([O(_t.Of)],Co);class Bd extends g{constructor(){super(...arguments),this.objectId=new ee.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<se.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities()}toString(){return this.objectId.toString()}}class $d extends g{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),go(this.meshData,e,n);const{subChunkOffsets:s}=this;e.subChunkOffsets=s,n.push(s.buffer),this.meshData=this.subChunkOffsets=null}downloadSucceeded(){const{subChunkOffsets:e}=this;this.systemMemoryBytes=this.gpuMemoryBytes=yo(this.meshData),this.systemMemoryBytes+=e.byteLength,super.downloadSucceeded()}}class Eo extends oe{constructor(e,n){super(e,n);const s=this.fragmentSource=this.registerDisposer(e.getRef(n.fragmentSource));this.format=n.format,s.meshSource=this}getChunk(e){const n=jn(e);let s=this.chunks.get(n);return s===void 0&&(s=this.getNewChunk_(Bd),s.initializeManifestChunk(n,e),this.addChunk(s)),s}getFragmentChunk(e,n,s){const i=`${e.key}/${n}:${s}`,r=this.fragmentSource;let o=r.chunks.get(i);return o===void 0&&(o=r.getNewChunk_($d),o.initialize(i),o.lod=n,o.chunkIndex=s,o.manifestChunk=e,r.addChunk(o)),o}}let ko=class extends oe{constructor(){super(...arguments),this.meshSource=null}download(t,e){return this.meshSource.downloadFragment(t,e)}};ko=Qn([O(_t.pi)],ko);const zd=w.pB.create();let To=class extends Yn(Lt(bt(dr))){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=dt(t),o=ht(t),{source:a,chunkManager:c}=this;Cn(this,l=>{const u=a.getChunk(l);++this.numVisibleChunksNeeded,c.requestChunk(u,r,o+po);const d=u.state;(d===M.SYSTEM_MEMORY_WORKER||d===M.SYSTEM_MEMORY||d===M.GPU_MEMORY)&&(n.push(u),++this.numVisibleChunksAvailable)})}if(n.length===0)return;const{source:s,chunkManager:i}=this;for(const{view:r}of this.attachments.values()){const o=r.visibility.value;if(o===Number.NEGATIVE_INFINITY)continue;const a=dt(o),c=ht(o),l=r.projectionParameters.value,u=zd;try{sl(u,l.displayDimensionRenderInfo,e)}catch{continue}w.pB.multiply(u,l.viewProjectionMat,u);const d=(0,w._S)(new Float32Array(24),u),h=this.renderScaleTarget.value;for(const p of n){const m=p.manifest.lodScales.length-1;lo(p.manifest,u,d,h,l.width,l.height,(f,b,I,E)=>{if(E)return;const V=s.getFragmentChunk(p,f,b);++this.numVisibleChunksNeeded,i.requestChunk(V,a,c+mo-m+f),V.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable})}}}};To=Qn([O(_t.Yo)],To);function Do(t,e){const n=wo(t.vertexPositions,t.indices),s=new Uint8Array(n.length/3*2);Vd(s,n);let i,r;Ad?(i=Rd(t.indices,t.subChunkOffsets),r=!0):(t.indices.BYTES_PER_ELEMENT===4&&t.vertexPositions.length/3<65535?(i=new Uint16Array(t.indices.length),i.set(t.indices)):i=t.indices,r=!1);let o;if(e===_t.Pc.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===_t.Pc.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:s,indices:i,strips:r}}function sn(t,e,n=_t.Pc.float32){t.meshData=Do(e,n)}function Po(t,e,n){t.meshData=Do(e,n),t.subChunkOffsets=e.subChunkOffsets}function Ro(t,e,n){let s=n;for(let i=0;i<3;++i)t[s*5+i]=t[e*5+i]>>>1;t[s*5+3]=e;for(let i=e+1;i<n;++i){const r=t[i*5]>>>1,o=t[i*5+1]>>>1,a=t[i*5+2]>>>1;(r!==t[s*5]||o!==t[s*5+1]||a!==t[s*5+2])&&(t[s*5+4]=i,++s,t[s*5]=r,t[s*5+1]=o,t[s*5+2]=a,t[s*5+3]=i)}return t[s*5+4]=n,++s,s}function Fd(t,e,n,s){let i=e;for(let r=n;r<s;++r){const o=t[r*5],a=t[r*5+1],c=t[r*5+2];for(;i<n;){const l=t[i*5]>>>1,u=t[i*5+1]>>>1,d=t[i*5+2]>>>1;if(!Qs(l,u,d,o,a,c))break;++i}for(t[r*5+3]=i;i<n;){const l=t[i*5]>>>1,u=t[i*5+1]>>>1,d=t[i*5+2]>>>1;if(l!==o||u!==a||d!==c)break;++i}t[r*5+4]+=i}}/**
 * @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 gt(t){return{id:t}}/**
 * @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 Ut=gt("decodeGzip");/**
 * @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 Xs=0;const Zs=[],es=new Map,En=new Map,Gd=typeof navigator.hardwareConcurrency>"u"?4:Math.min(12,navigator.hardwareConcurrency);let jd=0;function _o(t){for(const[e,n]of es){es.delete(e),t.postMessage(n.msg,n.transfer);return}Zs.push(t)}function Yd(){++Xs;const t=new Worker(new URL(x.p+x.u(491),x.b),{type:"module"});let e=!1;t.onmessage=n=>{if(!e){e=!0,_o(t);return}const{id:s,value:i,error:r}=n.data;_o(t);const o=En.get(s);En.delete(s),o!==void 0&&(o.cleanup(),r!==void 0?o.reject(new Error(r)):o.resolve(i))}}function Be(t,e,n,...s){if(e.isCanceled)return Promise.reject(j.wS);const i=jd++,r={t:t.id,id:i,args:s},o=e.add(()=>{es.delete(i),En.delete(i)}),a=new Promise((c,l)=>{En.set(i,{resolve:c,reject:l,cleanup:o})});return Zs.length!==0?Zs.pop().postMessage(r,n):(es.set(i,{msg:r,transfer:n}),En.size>Xs&&Xs<Gd&&Yd()),a}/**
 * @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 Jd=gt("encodeCompressedSegmentationUint32"),Hd=gt("encodeCompressedSegmentationUint64");/**
 * @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 rn(t,e,n){const{spec:s}=t.source;if(s.compressedSegmentationBlockSize!==void 0){const{dataType:i}=s,r=t.chunkDataSize,o=[r[0],r[1],r[2],r[3]||1];switch(i){case me.UINT32:t.data=await Be(Jd,e,[n.buffer],n,o,s.compressedSegmentationBlockSize);break;case me.UINT64:t.data=await Be(Hd,e,[n.buffer],n,o,s.compressedSegmentationBlockSize);break;default:throw new Error(`Unsupported data type for compressed segmentation: ${me[i]}`)}}else t.data=n}/**
 * @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 Ct=new Map;Ct.set("|u1",{endianness:Oe.LITTLE,dataType:me.UINT8}),Ct.set("|i1",{endianness:Oe.LITTLE,dataType:me.INT8});for(const[t,e]of[["<",Oe.LITTLE],[">",Oe.BIG]]){for(const n of["u","i"])Ct.set(`${t}${n}8`,{endianness:e,dataType:me.UINT64});Ct.set(`${t}u2`,{endianness:e,dataType:me.UINT16}),Ct.set(`${t}i2`,{endianness:e,dataType:me.INT16}),Ct.set(`${t}u4`,{endianness:e,dataType:me.UINT32}),Ct.set(`${t}i4`,{endianness:e,dataType:me.INT32}),Ct.set(`${t}f4`,{endianness:e,dataType:me.FLOAT32})}function Wd(t){const e=Ct.get(t);if(e===void 0)throw new Error(`Unsupported numpy data type: ${JSON.stringify(t)}`);return 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 Kd{constructor(e,n,s,i){this.data=e,this.shape=n,this.dataType=s,this.fortranOrder=i}}function Mo(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 i=new DataView(t.buffer,t.byteOffset,t.byteLength).getUint16(8,!0),r=new TextDecoder("utf-8").decode(t.subarray(10,i+10));let o;const a=i+10;try{o=(0,k.HB)(r)}catch(E){throw new Error(`Failed to parse npy header: ${E}`)}const c=o.descr,l=o.shape;let u=1;if(!Array.isArray(l))throw new Error("Invalid shape ${JSON.stringify(shape)}");for(const E of l){if(typeof E!="number")throw new Error("Invalid shape ${JSON.stringify(shape)}");u*=E}const{dataType:d,endianness:h}=Wd(c),p=Kt[d],m=ji[d],f=Gi[d],b=m*u;if(p*u+a!==t.byteLength)throw new Error("Expected length does not match length of data");const I=new f(t.buffer,t.byteOffset+a,b);return _s(I,h,p),new Kd(I,l,d,o.fortran_order===!0)}/**
 * @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 qd(t,e,n){const s=Mo(await Be(Ut,e,[n],new Uint8Array(n))),i=t.chunkDataSize,r=t.source,{shape:o}=s;if(o.length!==3||o[0]!==i[2]||o[1]!==i[1]||o[2]!==i[0])throw new Error(`Shape ${JSON.stringify(o)} does not match chunkDataSize ${(0,w.nL)(i)}`);const a=s.dataType,{spec:c}=r;if(a!==c.dataType)throw new Error(`Data type ${me[a]} does not match expected data type ${me[c.dataType]}`);await rn(t,e,s.data)}/**
 * @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 ei=gt("decodeJpeg");/**
 * @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 kn(t,e,n){const s=t.chunkDataSize,{uint8Array:i}=await Be(ei,e,[n],new Uint8Array(n),s[0],s[1]*s[2],s[3]||1,!1);await rn(t,e,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 Qd extends ir{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 s=this.chunkDataSize;s!==this.source.spec.chunkDataSize&&(e.chunkDataSize=s);const i=e.data=this.data;i!==null&&n.push(i.buffer),this.data=null}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=this.data?.byteLength??0,super.downloadSucceeded()}freeSystemMemory(){this.data=null}}function Oo(t,e){const{spec:n,tempChunkDataSize:s,tempChunkPosition:i}=t,{upperVoxelBound:r,rank:o,baseVoxelOffset:a}=n,c=n.chunkDataSize,l=s,u=vc(i,e.chunkGridPosition,c);let d=!1;for(let h=0;h<o;++h){const p=Math.min(r[h],u[h]+c[h]);(l[h]=p-u[h])!==c[h]&&(d=!0)}return Pi(u,u,a),d?e.chunkDataSize=Uint32Array.from(l):e.chunkDataSize=c,u}class ct extends rr{constructor(e,n){super(e,n);const s=this.spec.rank;this.tempChunkDataSize=new Uint32Array(s),this.tempChunkPosition=new Float32Array(s)}computeChunkBounds(e){return Oo(this,e)}}ct.prototype.chunkConstructor=Qd;var Xd=Object.defineProperty,Zd=Object.getOwnPropertyDescriptor,No=(t,e,n,s)=>{for(var i=s>1?void 0:s?Zd(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Xd(e,n,i),i};/**
 * @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 ti=new Map;ti.set("npz",qd),ti.set("jpeg",kn);const ni=new Map;ni.set("npz","application/npygz"),ni.set("jpeg","image/jpeg");function xo(t,e){return Ve(je()(t),e)}let Ao=class extends xo(ct,co.jj){constructor(){super(...arguments),this.chunkDecoder=ti.get(this.parameters.encoding)}async download(t,e){const{parameters:n}=this;let s=`${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)s+=`/${r[a]}:${r[a]+o[a]}`}s+="/",n.window!==void 0&&(s+=`?window=${n.window[0]},${n.window[1]}`);const i=await Sd(this.credentialsProvider,s,{headers:{Accept:ni.get(n.encoding)}},ge.Rc,e);await this.chunkDecoder(t,e,i)}};Ao=No([O()],Ao);function eh(t,e){return vo(t,e,"fragments")}function th(t,e){const s=new DataView(e).getUint32(0,!0);sn(t,Zn(e,Oe.LITTLE,4,s))}let Lo=class extends xo(nn,co.Ve){download(t,e){const{parameters:n}=this;return(0,ge.Bk)(`${n.baseUrl}${t.objectId}`,{},ge.Rc,e).then(s=>eh(t,s))}downloadFragment(t,e){const{parameters:n}=this;return(0,ge.Bk)(`${n.baseUrl}${t.fragmentId}`,{},ge.Rc,e).then(s=>th(t,s))}};Lo=No([O()],Lo);var ts=x(3551);/**
 * @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="google-brainmaps";function lt(t,e,n,s=j.fx){return(0,ts.Y)(e,`${t.serverUrl}${n.path}`,{method:n.method,body:n.payload},n.responseType==="json"?ge.cj:ge.Rc,s)}var it=x(2020),nh=x(3786),sh=Object.defineProperty,ih=Object.getOwnPropertyDescriptor,rh=(t,e,n,s)=>{for(var i=s>1?void 0:s?ih(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&sh(e,n,i),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.
 */const oh=60;class ah extends g{constructor(){super(...arguments),this.objectId=new ee.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?.forEach(s=>{e+=s.byteLength}),e}serialize(e,n){super.serialize(e,n);const s=this.vertexPositions,i=this.indices;e.numVertices=s.length/3,e.indices=i,n.push(i.buffer);const{vertexAttributes:r}=this;if(r!=null&&r.length>0){const o=new Uint8Array(this.getVertexAttributeBytes());o.set(new Uint8Array(s.buffer,s.byteOffset,s.byteLength));const a=e.vertexAttributeOffsets=new Uint32Array(r.length+1);a[0]=0;let c=s.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(s.buffer,s.byteOffset,s.byteLength),e.vertexAttributeOffsets=Uint32Array.of(0),s.buffer!==n[0]&&n.push(s.buffer);this.vertexPositions=this.indices=this.vertexAttributes=null}downloadSucceeded(){this.systemMemoryBytes=this.gpuMemoryBytes=this.indices.byteLength+this.getVertexAttributeBytes(),super.downloadSucceeded()}}class ns extends oe{getChunk(e){const n=jn(e);let s=this.chunks.get(n);return s===void 0&&(s=this.getNewChunk_(ah),s.initializeSkeletonChunk(n,e),this.addChunk(s)),s}}let Uo=class extends Yn(Lt(bt(ms))){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=dt(t),n=ht(t),{source:s,chunkManager:i}=this;Cn(this,r=>{const o=s.getChunk(r);++this.numVisibleChunksNeeded,o.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable,i.requestChunk(o,e,n+oh)})}};Uo=rh([O(nh.k)],Uo);function Vo(t,e,n,s,i,r,o){const a=bo(2,e,n,s,i,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 si(t,e,n){t.data=new Uint32Array(n)}/**
 * @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 Mt(t,e,n,s=Qt,i=0,r=n.byteLength){const{spec:o}=t.source,{dataType:a}=o,c=Sc(t.chunkDataSize),l=Kt[a],u=c*l;if(u!==r)throw new Error(`Raw-format chunk is ${r} bytes, but ${c} * ${l} = ${u} bytes are expected.`);const d=Yi(a,n,i,r);_s(d,s,l),await rn(t,e,d)}var ch=x(8795),lh=Object.defineProperty,uh=Object.getOwnPropertyDescriptor,on=(t,e,n,s)=>{for(var i=s>1?void 0:s?uh(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&lh(e,n,i),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.
 */const dh=new Map([[it.r7.RAW,Mt],[it.r7.JPEG,kn],[it.r7.COMPRESSED_SEGMENTATION,si]]);function Bo(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 an(t,e){return Ve(je()(t),e)}const hh=new ee.R;let $o=class extends an(ct,it.CR){constructor(){super(...arguments),this.chunkDecoder=dh.get(this.parameters.encoding)}applyEncodingParams(t){const{encoding:e}=this.parameters;switch(e){case it.r7.RAW:t.subvolume_format="RAW";break;case it.r7.JPEG:t.subvolume_format="SINGLE_IMAGE",t.image_format_options={image_format:"JPEG",jpeg_quality:this.parameters.jpegQuality};return;case it.r7.COMPRESSED_SEGMENTATION:t.subvolume_format="RAW",t.image_format_options={compressed_segmentation_block_size:(0,w.nL)(this.spec.compressedSegmentationBlockSize)};break;default:throw new Error(`Invalid encoding: ${e}`)}}async download(t,e){const{parameters:n}=this,s=this.computeChunkBounds(t),i=t.chunkDataSize,r=`/v1/volumes/${n.volumeId}/subvolume:binary`,o={geometry:{corner:(0,w.nL)(s),size:(0,w.nL)(i),scale:n.scaleIndex}};this.applyEncodingParams(o),Bo(n.changeSpec,o);const a=await lt(n.instance,this.credentialsProvider,{method:"POST",payload:JSON.stringify(o),path:r,responseType:"arraybuffer"},e);await this.chunkDecoder(t,e,a)}};$o=on([O()],$o);function fh(t,e,n,s){const i=new ee.R;if(!i.tryParseString(t,16))throw new Error(`Couldn't parse fragmentId ${t} as hex-encoded Uint64`);return Md(i,e,n,s)}function ph(t,e){(0,k.Rf)(e);const n=t.source,s=(0,k.cQ)(e,"fragmentKey",k.si),i=(0,k.cQ)(e,"supervoxelId",k.si),r=s.length;if(r!==i.length)throw new Error("Expected fragmentKey and supervoxelId arrays to have the same length.");const o=new Map;s.forEach((R,C)=>{let S=o.get(R);S===void 0&&(S=[],o.set(R,S)),S.push(i[C])});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])),d=Math.ceil(Math.log2(c[2])),h=Array.from(o.entries()).map(([R,C])=>({fragmentId:R,corner:fh(R,l,u,d),supervoxelIds:C}));h.sort((R,C)=>Qs(R.corner[0],R.corner[1],R.corner[2],C.corner[0],C.corner[1],C.corner[2])?-1:1);let p,m,f=0,b;if(r===0)p=m=w.w8,b=Uint32Array.of(0,0,0,0,2147483648);else{const R=w.eR.clone(w.WG),C=w.eR.clone(w.w8);for(h.forEach(S=>{const{corner:T}=S;for(let v=0;v<3;++v)R[v]=Math.min(R[v],T[v]),C[v]=Math.max(C[v],T[v])}),f=1;C[0]>>>f-1!==R[0]>>>f-1||C[1]>>>f-1!==R[1]>>>f-1||C[2]>>>f-1!==R[2]>>>f-1;)++f;p=w.eR.multiply(R,R,a),m=w.eR.add(C,w.eR.multiply(C,C,a),a)}const{lods:I}=n.parameters.info,E=new Float32Array(Math.max(I.length,f));for(let R=0;R<I.length;++R)E[R]=I[R].scale;if(r!==0){const R=new Uint32Array(h.length*E.length*5);h.forEach((T,v)=>{R.set(T.corner,v*5),R[v*5]=T.corner[0]});let C=0,S=h.length;for(let T=1;T<E.length;++T){const v=Ro(R,C,S);C=S,S=v}b=R.slice(0,S*5)}const V={chunkShape:a,chunkGridSpatialOrigin:w.w8,clipLowerBound:p,clipUpperBound:m,octree:b,lodScales:E,vertexOffsets:new Float32Array(E.length*3)};t.manifest=V,t.fragmentSupervoxelIds=h}const ii=255;function zo(t,e){const n=t.byteLength;let s=0;const i=new DataView(t),r=32;for(;s<n;){if(s+r>n)throw new Error("Invalid batch mesh fragment response.");const o=i.getUint32(s,!0),a=i.getUint32(s+4,!0),l=new ee.R(o,a).toString()+"\0";s+=8;const u=i.getUint32(s,!0),d=i.getUint32(s+4,!0);if(s+=8,d!==0)throw new Error("Invalid batch mesh fragment response.");if(s+u+8+8>n)throw new Error("Invalid batch mesh fragment response.");const h=new TextDecoder().decode(new Uint8Array(t,s,u)),p=l+h;s+=u;const m=i.getUint32(s,!0),f=i.getUint32(s+4,!0);s+=8;const b=i.getUint32(s,!0),I=i.getUint32(s+4,!0);if(s+=8,f!==0||I!==0)throw new Error("Invalid batch mesh fragment response.");const E=s+b*12+m*12;if(E>n)throw new Error("Invalid batch mesh fragment response.");e({fullKey:p,buffer:t,verticesOffset:s,numVertices:m,indicesOffset:s+12*m,numIndices:b*3}),s=E}}function Fo(t){let e=0,n=0;for(const a of t)e+=a.numVertices,n+=a.numIndices;const s=new Float32Array(e*3),i=new Uint32Array(n);let r=0,o=0;for(const a of t){s.set(new Float32Array(a.buffer,a.verticesOffset,a.numVertices*3),r*3);const{numIndices:c}=a,l=new Uint32Array(a.buffer,a.indicesOffset,c);ft(l,Oe.LITTLE);for(let u=0;u<c;++u)i[o++]=l[u]+r;r+=a.numVertices}return ft(s,Oe.LITTLE),{vertexPositions:s,indices:i}}async function Go(t,e,n,s){const i="/v1/objects/meshes:batch",r=[];let o,a=0;const c=new Map;for(const[u,d]of n){c.set(u,d),n.delete(u);const h=u.indexOf("\0"),p=u.substring(0,h),m=u.substring(h+1);if(p!==o&&r.push({object_id:p,fragment_keys:[]}),r[r.length-1].fragment_keys.push(m),++a===ii)break}const l={volume_id:e.volumeId,mesh_name:e.meshName,batches:r};try{return await lt(e.instance,t,{method:"POST",path:i,payload:JSON.stringify(l),responseType:"arraybuffer"},s)}finally{for(const[u,d]of c)n.set(u,d)}}let jo=class extends an(Eo,it.Ip){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,s=`/v1/objects/${n.volumeId}/meshes/${n.info.lods[0].info.name}:listfragments?object_id=${t.objectId}&return_supervoxel_ids=true`+this.listFragmentsParams;return lt(n.instance,this.credentialsProvider,{method:"GET",path:s,responseType:"json"},e).then(i=>ph(t,i))}async downloadFragment(t,e){const{parameters:n}=this,s=t.manifestChunk,{fragmentSupervoxelIds:i}=s,r=s.manifest,{lod:o}=t,{octree:a}=r,c=i.length,l=t.chunkIndex;let u=l;for(;u>=c;)u=a[u*5+3];let d=l+1;for(;d>c;)d=a[d*5-1]&2147483647;const{relativeBlockShape:h,gridShape:p}=n.info.lods[o],m=Math.ceil(Math.log2(p[0])),f=Math.ceil(Math.log2(p[1])),b=Math.ceil(Math.log2(p[2]));let I=new Map;for(let y=u;y<d;++y){const A=Math.floor(a[y*5]/h[0]),L=Math.floor(a[y*5+1]/h[1]),G=Math.floor(a[y*5+2]/h[2]),ue=ho(hh,m,f,b,A,L,G).toString(16).padStart(16,"0"),we=i[y];for(const fe of we.supervoxelIds)I.set(fe+"\0"+ue,y)}const E=Math.max(0,o-1),V=[],R=Array.from(I);R.sort((y,A)=>(0,ch.e)(y[0],A[0])),I=new Map(R);const C=n.info.lods[o].info.name,S=!0;await new Promise((y,A)=>{let L=0,G=!1;const ue=()=>{if(!G){for(;I.size!==0&&(++L,Go(this.credentialsProvider,{instance:n.instance,volumeId:n.volumeId,meshName:C},I,e).then(we=>{--L,zo(we,fe=>{const Fe=I.get(fe.fullKey);if(!I.delete(fe.fullKey))throw new Error(`Received unexpected fragment key: ${JSON.stringify(fe.fullKey)}.`);fe.chunkIndex=Fe,V.push(fe)}),ue()}).catch(we=>{G=!0,A(we)}),!!S););if(t.downloadSlots=Math.max(1,L),L===0){y(void 0);return}}};ue()}),V.sort((y,A)=>y.chunkIndex-A.chunkIndex);let T=0;const v=1<<3*(o-E),N=new Uint32Array(v+1);let H=0;for(const y of V){const A=y.chunkIndex,L=_d(a[A*5]>>>E,a[A*5+1]>>>E,a[A*5+2]>>>E)&v-1;N.fill(T,H+1,L+1),H=L,T+=y.numIndices}N.fill(T,H+1,v+1),Po(t,{...Fo(V),subChunkOffsets:N},_t.Pc.float32)}};jo=on([O()],jo);function mh(t){const e=[];let n=0;const s=t.length;for(;n<s;)e.push(JSON.stringify(t.slice(n,n+ii))),n+=ii;return e}function gh(t,e){(0,k.Rf)(e);const n=(0,k.cQ)(e,"fragmentKey",k.si),s=(0,k.cQ)(e,"supervoxelId",k.si);if(n.length!==s.length)throw new Error("Expected fragmentKey and supervoxelId arrays to have the same length.");const r=s.map((o,a)=>o+"\0"+n[a]);t.fragmentIds=mh(r)}let Yo=class extends an(nn,it.Ve){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,s=`/v1/objects/${n.volumeId}/meshes/${n.meshName}:listfragments?object_id=${t.objectId}&return_supervoxel_ids=true`+this.listFragmentsParams;return lt(n.instance,this.credentialsProvider,{method:"GET",path:s,responseType:"json"},e).then(i=>gh(t,i))}async downloadFragment(t,e){const{parameters:n}=this,s=new Map;for(const o of JSON.parse(t.fragmentId))s.set(o,null);const i=[],{credentialsProvider:r}=this;for(;s.size!==0;){const o=await Go(r,n,s,e);zo(o,a=>{if(!s.delete(a.fullKey))throw new Error(`Received unexpected fragment key: ${JSON.stringify(a.fullKey)}.`);i.push(a)})}sn(t,Fo(i))}};Yo=on([O()],Yo);function yh(t,e){const n=new DataView(e),s=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.");Vo(t,e,Oe.LITTLE,16,s,void 0,r)}let Jo=class extends an(ns,it.NV){download(t,e){const{parameters:n}=this,s={object_id:`${t.objectId}`},i=`/v1/objects/${n.volumeId}/meshes/${n.meshName}/skeleton:binary`;return Bo(n.changeSpec,s),lt(n.instance,this.credentialsProvider,{method:"POST",path:i,payload:JSON.stringify(s),responseType:"arraybuffer"},e).then(r=>yh(t,r))}};Jo=on([O()],Jo);const ri=["LOCATION","LINE","VOLUME"];function Ho(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 w.eR.fromValues(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3]))}function oi(t){return t.volumeId+":"+t.changestack+":"}function Wo(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 vh(t){if(t!=null)return[(0,k.$v)(t,e=>ee.R.parseString(""+e,10))]}function Ko(t,e,n){const s=(0,k.cQ)(t,"corner",u=>Ho((0,k.zr)(u))),i=(0,k.cQ)(t,"size",u=>Ho((0,k.zr)(u))),r=(0,k.cQ)(t,"payload",k.z$),o=(0,k.cQ)(t,"type",k.zr),a=(0,k.cQ)(t,"id",k.zr),c=Wo(e,a),l=(0,k.cQ)(t,"objectLabels",vh);if(n!==void 0&&c!==n)throw new Error(`Received annotation has unexpected id ${JSON.stringify(a)}.`);switch(o){case"LOCATION":{if(w.eR.equals(i,w.w8))return{type:at.POINT,id:c,point:s,description:r,relatedSegments:l,properties:[]};const u=w.eR.scale(w.eR.create(),i,.5),d=w.eR.add(w.eR.create(),s,u);return{type:at.ELLIPSOID,id:c,center:d,radii:u,description:r,relatedSegments:l,properties:[]}}case"LINE":return{type:at.LINE,id:c,pointA:s,pointB:w.eR.add(w.eR.create(),s,i),description:r,relatedSegments:l,properties:[]};case"VOLUME":return{type:at.AXIS_ALIGNED_BOUNDING_BOX,id:c,pointA:s,pointB:w.eR.add(w.eR.create(),s,i),description:r,relatedSegments:l,properties:[]};default:throw new Error(`Unknown spatial annotation type: ${JSON.stringify(o)}.`)}}function wh(t,e,n){(0,k.Rf)(t);const s=(0,k.cQ)(t,"annotations",i=>(0,k.Xu)([void 0],i,k.Rf))[0];return Ko(s,e,n)}const Sh=Ns(3,[]);function qo(t,e){const n=new Mu(Sh),s=t.source.parent,i=oi(s.parameters);e.forEach((r,o)=>{try{(0,k.Rf)(r);const a=(0,k.cQ)(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(Ko(c,i))}catch(l){throw new Error(`Error parsing annotation: ${l.message}`)}}catch(a){throw new Error(`Error parsing ${ri[o]} annotations: ${a.message}`)}}),t.data=Object.assign(new eo,n.serialize())}function Qo(t){const e=t.indexOf(".");return t.substring(0,e)}function Vt(t){return`${Math.round(t[0])},${Math.round(t[1])},${Math.round(t[2])}`}function ai(t,e){return`${t.volumeId}:${t.changestack}:${e}`}function Xo(t){const e=t.description||"",n=t.relatedSegments===void 0?void 0:t.relatedSegments[0].map(s=>s.toString());switch(t.type){case at.LINE:{const{pointA:s,pointB:i}=t,r=w.eR.subtract(w.eR.create(),i,s);return{type:"LINE",corner:Vt(s),size:Vt(r),object_labels:n,payload:e}}case at.AXIS_ALIGNED_BOUNDING_BOX:{const{pointA:s,pointB:i}=t,r=bc(w.eR.create(),s,i),o=Ic(w.eR.create(),s,i),a=w.eR.subtract(o,o,r);return{type:"VOLUME",corner:Vt(r),size:Vt(a),object_labels:n,payload:e}}case at.POINT:return{type:"LOCATION",corner:Vt(t.point),size:"0,0,0",object_labels:n,payload:e};case at.ELLIPSOID:{const s=w.eR.subtract(w.eR.create(),t.center,t.radii),i=w.eR.scale(w.eR.create(),t.radii,2);return{type:"LOCATION",corner:Vt(s),size:Vt(i),object_labels:n,payload:e}}}}let Zo=class extends an(js,it.Rw){async download(t,e){const{parameters:n}=this;return Promise.all(ri.map(s=>lt(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:get`,payload:JSON.stringify({type:s,ignore_payload:!0}),responseType:"json"},e))).then(s=>{qo(t,s)})}};Zo=on([O()],Zo);let ea=class extends an(io,it.rl){downloadSegmentFilteredGeometry(t,e,n){const{parameters:s}=this;return Promise.all(ri.map(i=>lt(s.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${s.volumeId}/${s.changestack}/spatials:get`,payload:JSON.stringify({type:i,object_labels:[t.objectId.toString()],ignore_payload:!0}),responseType:"json"},n))).then(i=>{qo(t,i)})}downloadMetadata(t,e){const{parameters:n}=this,s=t.key;return lt(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:get`,payload:JSON.stringify({type:Qo(s),id:ai(n,s)}),responseType:"json"},e).then(i=>{t.annotation=wh(i,oi(n),s)},()=>{t.annotation=null})}add(t){const{parameters:e}=this,n=Xo(t);return lt(e.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${e.volumeId}/${e.changestack}/spatials:push`,payload:JSON.stringify({annotations:[n]}),responseType:"json"}).then(s=>{(0,k.Rf)(s);const i=(0,k.cQ)(s,"ids",k.si);if(i.length!==1)throw new Error(`Expected list of 1 id, but received ${JSON.stringify(i)}.`);const r=oi(this.parameters);return Wo(r,i[0])})}update(t,e){const{parameters:n}=this,s=Xo(e);return s.id=ai(n,t),lt(n.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${n.volumeId}/${n.changestack}/spatials:push`,payload:JSON.stringify({annotations:[s]}),responseType:"json"})}delete(t){const{parameters:e}=this;return lt(e.instance,this.credentialsProvider,{method:"POST",path:`/v1/changes/${e.volumeId}/${e.changestack}/spatials:delete`,payload:JSON.stringify({type:Qo(t),ids:[ai(e,t)]}),responseType:"json"})}};ea=on([O()],ea);/**
 * @license
 * Copyright 2022 William Silversmith
 * 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 ta=gt("decodePng");var ss=x(5990);/**
 * @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.
 */async function bh(t,e,n,s,i){const r=await fetchWithOAuth2Credentials(t,`${e}?prefix=${encodeURIComponent(n)}&delimiter=${encodeURIComponent(s)}`,{},u=>u.text(),i),o=new DOMParser().parseFromString(r,"application/xml"),a=o.evaluate('//*[name()="CommonPrefixes"]/*[name()="Prefix"]',o,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null),c=[];for(let u=0,d=a.snapshotLength;u<d;++u)c.push(a.snapshotItem(u).textContent||"");const l=o.evaluate('//*[name()="Contents"]/*[name()="Key"]',o,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);for(let u=0,d=l.snapshotLength;u<d;++u)c.push(l.snapshotItem(u).textContent||"");return c}async function _g(t,e,n,s,i){if(!s.startsWith("/"))throw null;const o=await bh(t,n,s.substring(1),"/",i),a=s.lastIndexOf("/");return{offset:a+e.length+1,completions:o.map(c=>({value:c.substring(a)}))}}/**
 * @license
 * Copyright 2021 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 Ih(t,e,n,s,i=j.fx){return await(0,ge.Bk)(`https://${t}.s3.amazonaws.com${e}`,n,s,i)}async function Mg(t,e,n){return await getS3CompatiblePathCompletions(void 0,`s3://${t}`,`https://${t}.s3.amazonaws.com`,e,n)}/**
 * @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 Ch(t,e){return t.getCredentialsProvider("middleauthapp",new URL(e).origin)}function is(t,e,n){const s=/^\/([^/]+)/,i=n.match(s);if(i!==null)return pythonIntegration?t.getCredentialsProvider("gcs",{bucket:i[1]}):t.getCredentialsProvider("ngauth_gcs",{authServer:e,bucket:i[1]})}function Og(t,e){const n=parseUrl(t);switch(n.protocol){case"gs":case"gs+xml":return{credentialsProvider:pythonIntegration?e.getCredentialsProvider("gcs",{bucket:n.host}):void 0,url:t};case"gs+ngauth+http":return{credentialsProvider:is(e,`http://${n.host}`,n.path),url:"gs:/"+n.path};case"gs+ngauth+https":return{credentialsProvider:is(e,`https://${n.host}`,n.path),url:"gs:/"+n.path};case"gs+xml+ngauth+http":return{credentialsProvider:is(e,`http://${n.host}`,n.path),url:"gs+xml:/"+n.path};case"gs+xml+ngauth+https":return{credentialsProvider:is(e,`https://${n.host}`,n.path),url:"gs+xml:/"+n.path};case"middleauth+https":return t=t.substr(11),{credentialsProvider:Ch(e,t),url:t};case"s3":return{credentialsProvider:void 0,url:t};default:return{credentialsProvider:void 0,url:t}}}async function Je(t,e,n,s,i=j.fx){const r=(0,ge.Dl)(e);switch(r.protocol){case"gs":return(0,ts.Y)(t,`https://www.googleapis.com/storage/v1/b/${r.host}/o/${encodeURIComponent(r.path.substring(1))}?alt=media&neuroglancer=${Os()}`,n,s,i);case"gs+xml":return(0,ts.Y)(t,`https://storage.googleapis.com/${r.host}${r.path}?neuroglancer=${Os()}`,n,s,i);case"s3":return Ih(r.host,r.path,n,s,i);default:return(0,ts.Y)(t,e,n,s,i)}}var Eh=Object.defineProperty,kh=Object.getOwnPropertyDescriptor,Th=(t,e,n,s)=>{for(var i=s>1?void 0:s?kh(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Eh(e,n,i),i};/**
 * @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.
 */let na=class extends Ve(je()(ct),ss.D){constructor(){super(...arguments),this.gridShape=(()=>{const t=new Uint32Array(2),{upperVoxelBound:e,chunkDataSize:n}=this.spec;for(let s=0;s<2;++s)t[s]=Math.ceil(e[s]/n[s]);return t})()}async download(t,e){const{parameters:n}=this,{tilesize:s,overlap:i,encoding:r}=n,[o,a]=t.chunkGridPosition,c=o===0?0:i,l=a===0?0:i,u=`${n.url}/${o}_${a}.${n.format}`;try{const d=await Je(this.credentialsProvider,u,{},ge.Rc,e);let h=0,p=0,m;switch(r){case ss.j.PNG:{const f=await Be(ta,e,[d],new Uint8Array(d),void 0,void 0,3,1,!1);({width:h,height:p}=f),m=su(f.uint8Array,h*p,3);break}case ss.j.JPG:case ss.j.JPEG:{({uint8Array:m,width:h,height:p}=await Be(ei,e,[d],new Uint8Array(d),void 0,void 0,3,!1));break}}if(m!==void 0){const f=s*s,b=h*p,I=t.data=new Uint8Array(f*3);for(let E=0;E<3;E++)for(let V=0;V<p;V++)for(let R=0;R<h;R++)I[R+V*s+E*f]=m[R+c+(V+l)*h+E*b]}}catch(d){if(!(0,ge.El)(d))throw d}}};na=Th([O()],na);/**
 * @license
 * This work is a derivative of the Google Neuroglancer project,
 * Copyright 2016 Google Inc.
 * The Derivative Work is covered by
 * Copyright 2019 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.
 */const Ng="DVID";class Dh{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,s){return`${this.getNodeApiUrl()}/${e}/keyrange/${n}/${s}`}getKeyValuesUrl(e){return`${this.getNodeApiUrl()}/${e}/keyvalues?jsontar=false`}}function ci(t,e){return t.includes("?")?t+="&":t+="?",t+="app=Neuroglancer",e&&(t+=`&u=${e}`),t}function sa(t){return t.text()}function xg(t,e=uncancelableToken){const n=`${t.url}`,s={method:t.method,body:t.payload};return t.responseType===""?cancellableFetchOk(n,s,sa,e):cancellableFetchOk(n,s,responseJson,e)}function li(t,e,n=j.fx){return Ph(t,e.url,{method:e.method,body:e.payload},e.responseType===""?sa:e.responseType==="json"?ge.cj:ge.Rc,n)}function Ph(t,e,n,s,i=j.fx){return(0,ao.R)(t,e,n,s,(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},i)}var Et=x(8820);/**
 * @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 Rh(t,e){const n=_h(e);if(n.length<1)throw new Error("ERROR parsing swc data");const s=new Uint32Array(n.length);let i=0,r=0;n.forEach((u,d)=>{u&&(s[d]=i++,u.parent>=0&&++r)});const o=new Float32Array(3*i),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]=s[u.parent],++l),++c)}),t.indices=a,t.vertexPositions=o}function _h(t){const e=t.split(`
`),n=[],s="-?\\d*(?:\\.\\d+)?",i=new RegExp("^[ \\t]*("+["\\d+","\\d+",s,s,s,s,"-1|\\d+"].join(")[ \\t]+(")+")[ \\t]*$");return e.forEach(r=>{const o=r.match(i);if(o){const a=n[parseInt(o[1],10)]=new Mh;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 Mh{}var Oh=Object.defineProperty,Nh=Object.getOwnPropertyDescriptor,ui=(t,e,n,s)=>{for(var i=s>1?void 0:s?Nh(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Oh(e,n,i),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.
 */function di(t,e){return Ve(je()(t),e)}let ia=class extends di(ns,Et.NV){download(t,e){const{parameters:n}=this,s=`${t.objectId}`,i=`${n.baseUrl}/api/node/${n.nodeKey}/${n.dataInstanceKey}/key/`+s+"_swc";return li(this.credentialsProvider,{method:"GET",url:ci(i,n.user),responseType:"arraybuffer"},e).then(r=>{const o=new TextDecoder("utf-8");Rh(t,o.decode(r))})}};ia=ui([O()],ia);function xh(t,e){const s=new DataView(e).getUint32(0,!0);sn(t,Zn(e,Oe.LITTLE,4,s))}let ra=class extends di(nn,Et.Ve){download(t){return t.fragmentIds=[`${t.objectId}`],Promise.resolve(void 0)}downloadFragment(t,e){const{parameters:n}=this,i=new Dh(n.baseUrl,n.nodeKey).getKeyValueUrl(n.dataInstanceKey,`${t.fragmentId}.ngmesh`);return li(this.credentialsProvider,{method:"GET",url:ci(i,n.user),responseType:"arraybuffer"},e).then(r=>xh(t,r))}};ra=ui([O()],ra);let oa=class extends di(ct,Et.jj){async download(t,e){const n=this.parameters;let s;{const o=this.computeChunkBounds(t),a=t.chunkDataSize;s=this.getPath(o,a)}const i=this.getDecoder(n),r=await li(this.credentialsProvider,{method:"GET",url:ci(`${n.baseUrl}${s}`,n.user),responseType:"arraybuffer"},e);await i(t,e,n.encoding===Et.r7.JPEG?r.slice(16):r)}getPath(t,e){const n=this.parameters;return n.encoding===Et.r7.JPEG?`/api/node/${n.nodeKey}/${n.dataInstanceKey}/subvolblocks/${e[0]}_${e[1]}_${e[2]}/${t[0]}_${t[1]}_${t[2]}`:n.encoding===Et.r7.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===Et.r7.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===Et.r7.JPEG||t.encoding===Et.r7.RAW?kn:si}};oa=ui([O()],oa);var Ah=x(5716);/**
 * @license
 * Copyright 2019 The Neuroglancer Authors
 * 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 Ag=1,Lh="GrapheneMeshSource:NewSegment";var Uh=(t=>(t[t.RAW=0]="RAW",t[t.JPEG=1]="JPEG",t[t.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION",t))(Uh||{});class Vh{}Vh.RPC_ID="graphene/VolumeChunkSource";class aa{}aa.RPC_ID="graphene/ChunkedGraphSource";class ca{}ca.RPC_ID="graphene/MeshSource";class Lg{}const Bh=async t=>t;function la(t,e){const n=ee.R.rshift(new ee.R,t,64-e);return ee.R.equal(n,ee.R.ONE)}function $h(t){if(t.charAt(0)==="~"){const n=t.substring(1).split(/:(.+)/);return{key:n[0],fragmentId:n[1]}}return{key:t,fragmentId:t}}const zh="ChunkedGraphLayer",Fh="ChunkedGraphLayer:updateSources",Gh=5;function Ug(t){const{rank:e,dataType:n}=t,{baseVoxelOffset:s=new Float32Array(e)}=t;return{...makeSliceViewChunkSpecification(t),baseVoxelOffset:s,dataType:n}}/**
 * @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 ua=Symbol("objectId");let jh=0;function da(t){if(t instanceof Object){let e=t[ua];return e===void 0&&(e=t[ua]=jh++),`o${e}`}return""+JSON.stringify(t)}/**
 * @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 Yh extends g{initialize(e){super.initialize(e),this.requesters=new Set}downloadSucceeded(){super.downloadSucceeded();const{requesters:e,data:n}=this;this.requesters=void 0;for(const s of e)s.resolve(n)}downloadFailed(e){super.downloadFailed(e);const{requesters:n}=this;this.requesters=void 0;for(const s of n)s.reject(e)}freeSystemMemory(){this.data=void 0}}class Ot extends J{constructor(e,n){super(e),this.registerDisposer(e);const{encodeKey:s=k.JB}=n;this.downloadFunction=n.download,this.encodeKeyFunction=s;const{sourceQueueLevel:i=0}=n;this.sourceQueueLevel=i,this.registerDisposer(this.chunkManager.recomputeChunkPrioritiesLate.add(()=>{this.updateChunkPriorities()}))}updateChunkPriorities(){const{chunkManager:e}=this;for(const n of this.chunks.values()){const{requesters:s}=n;if(s!==void 0)for(const i of s){const{priorityTier:r,priority:o}=i.getPriority();r!==se.RECENT&&e.requestChunk(n,r,o,M.SYSTEM_MEMORY_WORKER)}}}async download(e,n){const{size:s,data:i}=await this.downloadFunction(e.decodedKey,n);e.systemMemoryBytes=s,e.data=i}getData(e,n,s){const i=this.encodeKeyFunction(e);let r=this.chunks.get(i);return r===void 0&&(r=this.getNewChunk_(Yh),r.decodedKey=e,r.initialize(i),this.addChunk(r)),(0,j.gI)(s,(o,a,c)=>{switch(r.state){case M.FAILED:a(r.error);return;case M.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(j.wS)}),this.chunkManager.scheduleUpdateChunkPriorities()})}static get(e,n,s){return e.memoize.get(`getFileSource:${n}`,()=>new Ot(e.addRef(),s))}static getData(e,n,s,i,r,o){const a=Ot.get(e,n,s),c=a.getData(i,r,o);return a.dispose(),c}static getUrl(e,n,s,i,r,o){return Ot.getData(e,`${da(s)}`,{download:(a,c)=>Je(n,a,{},ge.Rc,c).then(l=>s(l,c))},i,r,o)}}class Jh extends g{initialize(e){super.initialize(e)}freeSystemMemory(){this.promise=void 0,this.cancellationSource=void 0}}class ha extends J{constructor(e,n){super(e),this.registerDisposer(e),this.downloadFunction=n.get,this.encodeKeyFunction=n.encodeKey??k.JB}get(e,n){const s=this.encodeKeyFunction(e);let i=this.chunks.get(s);if(i===void 0&&(i=this.getNewChunk_(Jh),i.initialize(s),this.addChunk(i)),i.promise===void 0){let r=!1;const o=i.cancellationSource=new j.y3;o.add(()=>{r||(i.promise=void 0)}),i.promise=(async()=>{try{const{data:a,size:c}=await this.downloadFunction(e,o);return i.systemMemoryBytes=c,i.queueManager.updateChunkState(i,M.SYSTEM_MEMORY),a}catch(a){throw i.queueManager.updateChunkState(i,M.FAILED),a}finally{r=!0}})()}return i.cancellationSource.addConsumer(n),i.promise}}function Vg(t,e,n){return t.memoize.get(`simpleAsyncCache:${e}`,()=>new ha(t.addRef(),n))}var He=x(3819);/**
 * @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 Tn,fa=0,pa;const ma={emscripten_notify_memory_growth:t=>{},neuroglancer_draco_receive_decoded_mesh:(t,e,n,s,i)=>{const r=t*3,o=pa.exports.memory,a=new Uint32Array(o.buffer,n,r).slice(),c=new Uint32Array(o.buffer,s,3*e).slice(),l=new Uint32Array(o.buffer,i,fa+1).slice();Tn={indices:a,vertexPositions:c,subChunkOffsets:l}},proc_exit:t=>{throw`proc exit: ${t}`}},ga=(async()=>{const t=pa=(await WebAssembly.instantiateStreaming(fetch(new URL(x(8867),x.b)),{env:ma,wasi_snapshot_preview1:ma})).instance;return t.exports._initialize(),t})();async function Hh(t,e,n){const s=await ga,i=s.exports.malloc(t.byteLength);new Uint8Array(s.exports.memory.buffer).set(t,i),fa=n?8:1;const o=s.exports.neuroglancer_draco_decode(i,t.byteLength,n,e,!0);if(o===0){const a=Tn;if(Tn=void 0,a instanceof Error)throw a;return a}throw new Error(`Failed to decode draco mesh: ${o}`)}async function Wh(t){const e=await ga,n=e.exports.malloc(t.byteLength);new Uint8Array(e.exports.memory.buffer).set(t,n);const i=e.exports.neuroglancer_draco_decode(n,t.byteLength,!1,0,!1);if(i===0){const r=Tn;if(Tn=void 0,r instanceof Error)throw r;return r.vertexPositions=new Float32Array(r.vertexPositions.buffer),r}throw new Error(`Failed to decode draco mesh: ${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.
 */function ya(t,e,n){const s=new DataView(e),i=s.getUint32(0,!0),r=s.getUint32(4,!0),o=8;let a=8+i*4*3;Vo(t,e,Oe.LITTLE,o,i,a,r),a+=r*4*2;const c=[];for(const l of n.values()){const u=Kt[l.dataType]*l.numComponents,d=u*i,h=new Uint8Array(e,a,d);switch(u){case 2:du(h,Oe.LITTLE);break;case 4:case 8:ft(h,Oe.LITTLE);break}c.push(h),a+=d}t.vertexAttributes=c}/**
 * @license
 * Copyright 2021 William Silversmith
 * 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 Kh=gt("decodeCompresso");/**
 * @license
 * Copyright 2021 William Silvermsith.
 * 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 qh(t,e,n){const s=await Be(Kh,e,[n],new Uint8Array(n));await Mt(t,e,s.buffer)}/**
 * @license
 * Copyright 2022 William Silvermsith.
 * 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 Qh(t,e,n){const s=t.chunkDataSize,i=t.source.spec.dataType,{uint8Array:r}=await Be(ta,e,[n],new Uint8Array(n),s[0],s[1]*s[2],s[3]||1,Kt[i],!1);await Mt(t,e,r.buffer)}/**
 * @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 Xh=navigator.userAgent.indexOf("Chrome")!==-1?"no-store":"default";function Dn(t,e,n,s,i){return Je(t,e,{headers:(0,ge.JD)(n,s),cache:Xh},ge.Rc,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.
 */function Bg(t){let e=0;const n=t.length;for(let s=0;s<n;++s)e=e*31+t.charCodeAt(s)|0;return e}function va(t,e){return e=Math.imul(e,3432918353)>>>0,e=(e<<15|e>>>17)>>>0,e=Math.imul(e,461845907)>>>0,t^=e,t=(t<<13|t>>>19)>>>0,t=Math.imul(t,5)+3864292196>>>0,t}function Zh(t,e){return t^=e,t^=t>>>16,t=Math.imul(t,2246822507)>>>0,t^=t>>>13,t*=3266489909,t^=t>>>16,t>>>0}function $g(t,e,n){let s=t;return s=va(s,e),s=va(s,n),Zh(s,8)}function rs(t){return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,t}function wa(t,e){return t<<e|t>>>32-e}function ef(t,e,n,s){let i=e,r=e,o=e,a=e;const c=597399067,l=2869860233,u=951274213;let d=Math.imul(s,l);d=wa(d,16),d=Math.imul(d,u),r^=d;let h=Math.imul(n,c);h=wa(h,15),h=Math.imul(h,l),i^=h;const p=8;return i^=p,r^=p,o^=p,a^=p,i=i+r>>>0,i=i+o>>>0,i=i+a>>>0,r=r+i>>>0,o=o+i>>>0,a=a+i>>>0,i=rs(i),r=rs(r),o=rs(o),a=rs(a),i=i+r>>>0,i=i+o>>>0,i=i+a>>>0,r=r+i>>>0,t.low=i,t.high=r,t}var tf=Object.defineProperty,nf=Object.getOwnPropertyDescriptor,Bt=(t,e,n,s)=>{for(var i=s>1?void 0:s?nf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&tf(e,n,i),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.
 */const sf=!1,rf=new Map([[He.TV.MURMURHASH3_X86_128,t=>{ef(t,0,t.low,t.high)}],[He.TV.IDENTITY,t=>{}]]);function $t(t,e,n){const{url:s,sharding:i}=n;if(i===void 0)return;const r=Ot.get(t,(0,k.JB)({type:"precomputed:shardedDataSource",url:s,sharding:i,credentialsProvider:da(e)}),{download:async(o,a)=>{const c=ee.R.lowMask(new ee.R,i.minishardBits);ee.R.and(c,c,o);const l=ee.R.lowMask(new ee.R,i.shardBits),u=new ee.R;ee.R.rshift(u,o,i.minishardBits),ee.R.and(l,l,u);const d=`${s}/${l.toString(16).padStart(Math.ceil(i.shardBits/4),"0")}.shard`,h=new ee.R(16);ee.R.lshift(h,h,i.minishardBits);const p=ee.R.lshift(new ee.R,c,4),m=ee.R.addUint32(new ee.R,p,16);let f;try{f=await Dn(e,d,p,m,a)}catch(H){if((0,ge.El)(H))return{data:void 0,size:0};throw H}if(f.byteLength!==16)throw new Error("Failed to retrieve minishard offset");const b=new DataView(f),I=new ee.R(b.getUint32(0,!0),b.getUint32(4,!0)),E=new ee.R(b.getUint32(8,!0),b.getUint32(12,!0));if(ee.R.equal(I,E))return{data:void 0,size:0};ee.R.add(I,I,h),ee.R.add(E,E,h);let V=await Dn(e,d,I,E,a);if(i.minishardIndexEncoding===He.Y1.GZIP&&(V=(await Be(Ut,a,[V],new Uint8Array(V))).buffer),V.byteLength%24!==0)throw new Error(`Invalid minishard index length: ${V.byteLength}`);const R=new Uint32Array(V);ft(R,Oe.LITTLE);const C=R.byteLength/24;let S=0,T=0,v=h.low,N=h.high;for(let H=0;H<C;++H){let y=S+R[H*2],A=T+R[H*2+1];y>=4294967296&&(y-=4294967296,A+=1),S=R[H*2]=y,T=R[H*2+1]=A;let L=v+R[(C+H)*2],G=N+R[(C+H)*2+1];L>=4294967296&&(L-=4294967296,G+=1),R[(C+H)*2]=L,R[(C+H)*2+1]=G;const ue=R[(2*C+H)*2],we=R[(2*C+H)*2+1];let fe=L+ue,Fe=G+we;fe>=4294967296&&(fe-=4294967296,Fe+=1),v=fe,N=Fe,R[(2*C+H)*2]=fe,R[(2*C+H)*2+1]=Fe}return{data:{data:R,shardUrl:d},size:R.byteLength}},encodeKey:o=>o.toString(),sourceQueueLevel:1});return r.sharding=i,r.credentialsProvider=e,r}function of(t,e){const n=t.data,s=n.length/6,i=e.low,r=e.high;for(let o=0;o<s;++o){if(n[o*2]!==i||n[o*2+1]!==r)continue;const a=new ee.R(n[(s+o)*2],n[(s+o)*2+1]),c=new ee.R(n[(2*s+o)*2],n[(2*s+o)*2+1]);return{startOffset:a,endOffset:c}}}async function os(t,e,n,s){const{sharding:i}=t,r=rf.get(i.hash),o=ee.R.rshift(new ee.R,n,i.preshiftBits);r(o);const a=ee.R.lowMask(new ee.R,i.minishardBits+i.shardBits);ee.R.and(a,a,o);const c=()=>({priorityTier:e.priorityTier,priority:e.priority}),l=await t.getData(a,c,s);if(l===void 0)return;const u=of(l,n);if(u===void 0)return;const{startOffset:d,endOffset:h}=u;let p=await Dn(t.credentialsProvider,l.shardUrl,d,h,s);return t.sharding.dataEncoding===He.Y1.GZIP&&(p=(await Be(Ut,s,[p],new Uint8Array(p))).buffer),{data:p,shardInfo:{shardUrl:l.shardUrl,offset:d}}}function Sa(t){if(t===void 0)throw new Error("not found");return t}const cn=new Map;cn.set(He.r7.RAW,Mt),cn.set(He.r7.JPEG,kn),cn.set(He.r7.COMPRESSED_SEGMENTATION,si),cn.set(He.r7.COMPRESSO,qh),cn.set(He.r7.PNG,Qh);let ba=class extends Ve(je()(ct),He.jj){constructor(){super(...arguments),this.chunkDecoder=cn.get(this.parameters.encoding),this.minishardIndexSource=$t(this.chunkManager,this.credentialsProvider,this.parameters),this.gridShape=(()=>{const t=new Uint32Array(3),{upperVoxelBound:e,chunkDataSize:n}=this.spec;for(let s=0;s<3;++s)t[s]=Math.ceil(e[s]/n[s]);return t})()}async download(t,e){const{parameters:n}=this,{minishardIndexSource:s}=this;let i;if(s===void 0){let r;{const o=this.computeChunkBounds(t),a=t.chunkDataSize;r=`${n.url}/${o[0]}-${o[0]+a[0]}_${o[1]}-${o[1]+a[1]}_${o[2]}-${o[2]+a[2]}`}try{i=await Je(this.credentialsProvider,r,{},ge.Rc,e)}catch(o){if((0,ge.El)(o))i=void 0;else throw o}}else{this.computeChunkBounds(t);const{gridShape:r}=this,{chunkGridPosition:o}=t,a=Math.ceil(Math.log2(r[0])),c=Math.ceil(Math.log2(r[1])),l=Math.ceil(Math.log2(r[2])),u=ho(new ee.R,a,c,l,o[0],o[1],o[2]);i=(await os(s,t,u,e))?.data}i!==void 0&&await this.chunkDecoder(t,e,i)}};ba=Bt([O()],ba);function hi(t,e){return vo(t,e,"fragments")}function af(t,e){const s=new DataView(e).getUint32(0,!0);sn(t,Zn(e,Oe.LITTLE,4,s))}let Ia=class extends Ve(je()(nn),He.Ve){async download(t,e){const{parameters:n}=this,s=await Je(this.credentialsProvider,`${n.url}/${t.objectId}:${n.lod}`,{},ge.cj,e);hi(t,s)}async downloadFragment(t,e){const{parameters:n}=this,s=await Je(this.credentialsProvider,`${n.url}/${t.fragmentId}`,{},ge.Rc,e);af(t,s)}};Ia=Bt([O()],Ia);function cf(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 s=0;const i=w.eR.fromValues(n.getFloat32(s,!0),n.getFloat32(s+4,!0),n.getFloat32(s+8,!0));s+=12;const r=w.eR.fromValues(n.getFloat32(s,!0),n.getFloat32(s+4,!0),n.getFloat32(s+8,!0));s+=12;const o=n.getUint32(s,!0);if(s+=4,e.byteLength<s+20*o)throw new Error(`Invalid index file size for ${o} lods: ${e.byteLength}`);const a=new Float32Array(e,s,o);s+=4*o,ft(a,Oe.LITTLE);const c=new Float32Array(e,s,o*3);ft(c,Oe.LITTLE),s+=12*o;const l=new Uint32Array(e,s,o);s+=4*o,ft(l,Oe.LITTLE);const u=l.reduce((S,T)=>S+T);if(e.byteLength!==s+16*u)throw new Error(`Invalid index file size for ${o} lods and ${u} total fragments: ${e.byteLength}`);const d=new Uint32Array(e,s);ft(d,Oe.LITTLE);const h=w.eR.fromValues(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),p=w.eR.fromValues(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY);let m=Math.max(1,a.length);{let S=0;for(let T=0;T<o;++T){const v=l[T];if(sf)for(let N=1;N<v;++N){const H=d[S+v*0+(N-1)],y=d[S+v*1+(N-1)],A=d[S+v*2+(N-1)],L=d[S+v*0+N],G=d[S+v*1+N],ue=d[S+v*2+N];Qs(H,y,A,L,G,ue)||console.log(`Fragment index violates zorder constraint: lod=${T}, chunk ${N-1} = [${H},${y},${A}], chunk ${N} = [${L},${G},${ue}]`)}for(let N=0;N<3;++N){let H=Number.NEGATIVE_INFINITY,y=Number.POSITIVE_INFINITY;const A=S+v*N;for(let L=0;L<v;++L){const G=d[A+L];H=Math.max(H,G),y=Math.min(y,G)}if(v!==0){for(;H>>>m-T-1!==y>>>m-T-1;)++m;T===0&&(h[N]=Math.min(h[N],(1<<T)*y),p[N]=Math.max(p[N],(1<<T)*(H+1)))}}S+=v*4}}let f=0;{let S=0,T=0;for(let v=0;v<o;++v){const N=l[v];f+=S*(v-T),T=v,S=N,f+=N}f+=(m-1-T)*S}const b=new Uint32Array(5*f),I=new Float64Array(f+1);let E;{let S=0,T=0,v=0,N=0;for(let H=0;H<o;++H){const y=l[H];for(let A=0;A<y;++A){for(let G=0;G<3;++G)b[5*(T+A)+G]=d[N+A+G*y];const L=d[N+A+3*y];v+=L,I[T+A+1]=v,L===0&&(b[5*(T+A)+4]=2147483648)}for(N+=4*y,H!==0&&Fd(b,S,T,T+y),S=T,T+=y;H+1<m&&(H+1>=a.length||a[H+1]===0);){const A=Ro(b,S,T);I.fill(v,T+1,A+1),S=T,T=A,++H}}E=b.slice(0,5*T),t.offsets=I.slice(0,T+1)}const V=t.source,{lodScaleMultiplier:R}=V.parameters.metadata,C=new Float32Array(m);C.set(a,0);for(let S=0;S<a.length;++S)C[S]*=R;t.manifest={chunkShape:i,chunkGridSpatialOrigin:r,clipLowerBound:w.eR.add(h,r,w.eR.multiply(h,h,i)),clipUpperBound:w.eR.add(p,r,w.eR.multiply(p,p,i)),octree:E,lodScales:C,vertexOffsets:c}}async function lf(t,e){const{lod:n}=t,s=t.manifestChunk.source,i=await Hh(new Uint8Array(e),s.parameters.metadata.vertexQuantizationBits,n!==0);Po(t,i,s.format.vertexPositionFormat)}let Ca=class extends Ve(je()(Eo),He.Ip){constructor(){super(...arguments),this.minishardIndexSource=$t(this.chunkManager,this.credentialsProvider,{url:this.parameters.url,sharding:this.parameters.metadata.sharding})}async download(t,e){const{parameters:n,minishardIndexSource:s}=this;let i;s===void 0?i=await Je(this.credentialsProvider,`${n.url}/${t.objectId}.index`,{},ge.Rc,e):{data:i,shardInfo:t.shardInfo}=Sa(await os(s,t,t.objectId,e)),cf(t,i)}async downloadFragment(t,e){const{parameters:n}=this,s=t.manifestChunk,i=t.chunkIndex,{shardInfo:r,offsets:o}=s,a=o[i],c=o[i+1];let l,u,d;if(r!==void 0){l=r.shardUrl;const p=o[o.length-1];let m=r.offset.low-p+a,f=r.offset.high,b=m+c-a,I=f;for(;m<0;)m+=4294967296,f-=1;for(;b<0;)b+=4294967296,I-=1;for(;b>4294967296;)b-=4294967296,I+=1;u=new ee.R(m,f),d=new ee.R(b,I)}else l=`${n.url}/${s.objectId}`,u=a,d=c;const h=await Dn(this.credentialsProvider,l,u,d,e);await lf(t,h)}};Ca=Bt([O()],Ca);async function fi(t,e,n,s,i,r){if(s===void 0)try{return await Je(t,`${e}/${i}`,{},ge.Rc,r)}catch(a){if((0,ge.El)(a))return;throw a}const o=await os(s,n,i,r);if(o!==void 0)return o.data}let Ea=class extends Ve(je()(ns),He.NV){constructor(){super(...arguments),this.minishardIndexSource=$t(this.chunkManager,this.credentialsProvider,{url:this.parameters.url,sharding:this.parameters.metadata.sharding})}async download(t,e){const{parameters:n}=this,s=Sa(await fi(this.credentialsProvider,n.url,t,this.minishardIndexSource,t.objectId,e));ya(t,s,n.metadata.vertexAttributes)}};Ea=Bt([O()],Ea);function ka(t,e,n){const s=new DataView(t);if(t.byteLength<=8)throw new Error("Expected at least 8 bytes");const i=s.getUint32(0,!0);if(s.getUint32(4,!0)!==0)throw new Error("Annotation count too high");const o=n.serializedBytes,a=8+(o+8)*i;if(t.byteLength!==a)throw new Error(`Expected ${a} bytes, but received: ${t.byteLength} bytes`);const c=8+o*i,l=new ee.R,u=new Array(i);for(let E=0;E<i;++E)l.low=s.getUint32(c+E*8,!0),l.high=s.getUint32(c+E*8+4,!0),u[E]=l.toString();const d=new eo,h=new Uint8Array(t,8,o*i);let p;const{propertyGroupBytes:m}=n;if(m.length>1){p=new Uint8Array(h.length);let E=0,V=0;for(let R=0;R<m.length;++R){const C=m[R];for(let S=0;S<i;++S){const T=E+S*o,v=V+S*C;for(let N=0;N<C;++N)p[v+N]=h[T+N]}E+=C,V+=C*i}}else p=h;d.data=p;const f=d.typeToOffset=new Array(Zt.length);f.fill(0),f[e.type]=0;const b=d.typeToIds=new Array(Zt.length),I=d.typeToIdMaps=new Array(Zt.length);return b.fill([]),b[e.type]=u,I.fill(new Map),I[e.type]=new Map(u.map((E,V)=>[E,V])),d}function uf(t,e,n,s){const i=en[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=i.deserialize(c,0,!0,e.rank,s);n.deserialize(c,0,0,1,!0,l.properties=new Array(e.properties.length));let u=r;const d=l.relatedSegments=[];d.length=o;for(let h=0;h<o;++h){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 m=d[h]=[];for(let f=0;f<p;++f)m[f]=new ee.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 Ta=class extends Ve(je()(js),He.Rw){constructor(){super(...arguments),this.minishardIndexSource=$t(this.chunkManager,this.credentialsProvider,this.parameters)}async download(t,e){const{parameters:n}=this,{minishardIndexSource:s}=this,{parent:i}=this;let r;const{chunkGridPosition:o}=t;if(s===void 0){const a=`${n.url}/${o.join("_")}`;try{r=await Je(this.credentialsProvider,a,{},ge.Rc,e)}catch(c){if(!(0,ge.El)(c))throw c}}else{const{upperChunkBound:a}=this.spec,{chunkGridPosition:c}=t,l=Od(new ee.R,c,a),u=await os(s,t,l,e);u!==void 0&&(r=u.data)}r!==void 0&&(t.data=ka(r,i.parameters,i.annotationPropertySerializer))}};Ta=Bt([O()],Ta);let Da=class extends Ve(je()(io),He.rl){constructor(){super(...arguments),this.byIdMinishardIndexSource=$t(this.chunkManager,this.credentialsProvider,this.parameters.byId),this.relationshipIndexSource=this.parameters.relationships.map(t=>$t(this.chunkManager,this.credentialsProvider,t)),this.annotationPropertySerializer=new Cr(this.parameters.rank,en[this.parameters.type].serializedBytes(this.parameters.rank),this.parameters.properties)}async downloadSegmentFilteredGeometry(t,e,n){const{parameters:s}=this,i=await fi(this.credentialsProvider,s.relationships[e].url,t,this.relationshipIndexSource[e],t.objectId,n);i!==void 0&&(t.data=ka(i,this.parameters,this.annotationPropertySerializer))}async downloadMetadata(t,e){const{parameters:n}=this,s=ee.R.parseString(t.key),i=await fi(this.credentialsProvider,n.byId.url,t,this.byIdMinishardIndexSource,s,e);i===void 0?t.annotation=null:t.annotation=uf(i,this.parameters,this.annotationPropertySerializer,t.key)}};Da=Bt([O()],Da);let Pa=class extends Ve(je()(od),He.vq){constructor(){super(...arguments),this.minishardIndexSource=$t(this.chunkManager,this.credentialsProvider,this.parameters)}};Pa=Bt([O()],Pa);var df=Object.defineProperty,hf=Object.getOwnPropertyDescriptor,pi=(t,e,n,s)=>{for(var i=s>1?void 0:s?hf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&df(e,n,i),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.
 */function ff(t,e,n,s){if(e.fragmentId&&e.fragmentId.charAt(0)==="~"){const i=e.fragmentId.substr(1).split(":"),r=Number(i[1]),o=r+Number(i[2]);return Dn(t,`${n.fragmentUrl}/initial/${i[0]}`,r,o,s)}return Je(t,`${n.fragmentUrl}/dynamic/${e.fragmentId}`,{},ge.Rc,s)}function pf(t,e,n,s){let i;return n.sharding?i=ff(t,e,n,s):i=Je(t,`${n.fragmentUrl}/${e.fragmentId}`,{},ge.Rc,s),i}async function mf(t,e){const n=await Wh(new Uint8Array(e));sn(t,n)}let Ra=class extends Ve(je()(nn),ca){constructor(){super(...arguments),this.manifestRequestCount=new Map,this.newSegments=new In}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:s,manifestRequestCount:i}=this;if(la(t.objectId,n.nBitsForLayerId))return hi(t,{fragments:[]});const o=`${`${n.manifestUrl}/manifest`}/${t.objectId}:${n.lod}?verify=1&prepend_seg_ids=1`;await Je(this.credentialsProvider,o,{},ge.cj,e).then(a=>{const c=o;if(s.has(t.objectId)){const l=(i.get(c)||0)+1;i.set(c,l),setTimeout(()=>{this.chunkManager.queueManager.updateChunkState(t,M.QUEUED)},2**l*1e3)}else i.delete(c);return hi(t,a)})}async downloadFragment(t,e){const{parameters:n}=this,s=await pf(void 0,t,n,e);await mf(t,s)}getFragmentKey(t,e){return $h(e)}};Ra=pi([O()],Ra);class gf extends g{constructor(){super(...arguments),this.source=null,this.leaves=[]}initializeVolumeChunk(e,n){super.initialize(e),this.chunkGridPosition=Float32Array.from(n)}initializeChunkedGraphChunk(e,n,s){this.initializeVolumeChunk(e,n),this.chunkDataSize=null,this.systemMemoryBytes=16,this.gpuMemoryBytes=0,this.segment=s}downloadSucceeded(){this.systemMemoryBytes=16,this.systemMemoryBytes+=16*this.leaves.length,this.queueManager.updateChunkState(this,M.SYSTEM_MEMORY_WORKER),this.priorityTier<se.RECENT&&this.source.chunkManager.scheduleUpdateChunkPriorities(),super.downloadSucceeded()}freeSystemMemory(){this.leaves=[]}}function yf(t){const e=new Array(t.length);for(let n=0;n<e.length;++n)e[n]=ee.R.parseString(t[n]);return e}let _a=class extends Ve(je()(oe),aa){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,s=this.computeChunkBounds(t),i=t.chunkDataSize,r=`${s[0]}-${s[0]+i[0]}_${s[1]}-${s[1]+i[1]}_${s[2]}-${s[2]+i[2]}`,o=Je(this.credentialsProvider,`${n.url}/${t.segment}/leaves?int64_as_str=1&bounds=${r}`,{},Bh,e);await this.withErrorMessage(o,`Fetching leaves of segment ${t.segment} in region ${r}: `).then(a=>a.json()).then(a=>{t.leaves=yf(a.leaf_ids)}).catch(a=>console.error(a))}getChunk(t,e){const n=`${(0,w.nL)(t)}-${e}`;let s=this.chunks.get(n);return s===void 0&&(s=this.getNewChunk_(gf),s.initializeChunkedGraphChunk(n,t,e),this.addChunk(s)),s}computeChunkBounds(t){return Oo(this,t)}async withErrorMessage(t,e){const n=await t;if(n.ok)return n;let s;try{s=(await n.json()).message}catch{s=await n.text()}throw new Error(`[${n.status}] ${e}${s}`)}};_a=pi([O()],_a);const Ma=w.eR.create(),vf=w.eR.create(),wf=w.eR.create();let Oa=class extends Yn(Lt(bt(An))){constructor(t,e){super(t,e),this.debouncedupdateDisplayState=(0,Ah.A)(()=>{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 Gh}updateChunkPriorities(){const{source:t,chunkManager:e}=this;e.registerLayer(this);for(const n of this.attachments.values()){const{view:s}=n,i=s.visibility.value;if(i===Number.NEGATIVE_INFINITY)continue;const r=n.state,{transformedSource:o}=r,a=s.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=dt(i),d=ht(i),{chunkLayout:h}=o,{size:p,finiteRank:m}=h,f=wf,b=vf;w.eR.copy(f,p);for(let E=m;E<3;++E)f[E]=0,b[E]=0;const{centerDataPosition:I}=a;h.globalToLocalSpatial(b,I),Qi(a,this.localPosition.value,o,Xi(a,h),E=>{w.eR.multiply(Ma,E,f);const V=-w.eR.distance(b,Ma),{curPositionInChunks:R}=o;Cn(this,(C,S)=>{if(la(C,this.nBitsForLayerId.value))return;const T=t.getChunk(R,C.clone());e.requestChunk(T,u,d+V,M.SYSTEM_MEMORY_WORKER),++this.numVisibleChunksNeeded,T.state===M.GPU_MEMORY&&++this.numVisibleChunksAvailable})})}}forEachSelectedRootWithLeaves(t){const{source:e}=this;for(const n of e.chunks.values())n.state===M.SYSTEM_MEMORY_WORKER&&n.priorityTier<se.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,s)=>{e.has(n)?e.set(n,e.get(n)+s.length):e.set(n,s.length)}),this.forEachSelectedRootWithLeaves((n,s)=>{t.has(n)||(t.set(n,new In),t.get(n).reserve(e.get(n)),t.get(n).add(ee.R.parseString(n))),t.get(n).add(s)});for(const[n,s]of t){const i=[...s].filter(o=>!this.segmentEquivalences.has(o)),r=ee.R.parseString(n);for(const o of i)this.segmentEquivalences.link(r,o)}}};Oa=pi([O(zh)],Oa),Q(Fh,function(t){const e=this.get(t.view),n=this.get(t.layer),s=n.attachments.get(e);s.state.transformedSource=Bn(this,t.sources,n)[0][0],s.state.displayDimensionRenderInfo=t.displayDimensionRenderInfo,n.chunkManager.scheduleUpdateChunkPriorities()}),Q(Lh,function(t){this.get(t.rpcId).addNewSegment(ee.R.parseString(t.segment))});/**
 * @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.
 */const Na=gt("decodeBlosc");/**
 * @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.
 */const xa=gt("decodeZstd");var as=x(5926),Sf=Object.defineProperty,bf=Object.getOwnPropertyDescriptor,If=(t,e,n,s)=>{for(var i=s>1?void 0:s?bf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Sf(e,n,i),i};/**
 * @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.
 */async function Cf(t,e,n,s){const i=new DataView(n),r=i.getUint16(0,!1);if(r!==0)throw new Error(`Unsupported mode: ${r}.`);const o=i.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]=i.getUint32(a,!1),a+=4;t.chunkDataSize=c;let l=new Uint8Array(n,a);switch(s){case as.r.GZIP:l=await Be(Ut,e,[l.buffer],l);break;case as.r.BLOSC:l=await Be(Na,e,[l.buffer],l);break;case as.r.ZSTD:l=await Be(xa,e,[l.buffer],l);break}await Mt(t,e,l.buffer,Oe.BIG,l.byteOffset,l.byteLength)}let Aa=class extends Ve(je()(ct),as.j){async download(t,e){const{parameters:n}=this,{chunkGridPosition:s}=t;let i=n.url;const r=this.spec.rank;for(let o=0;o<r;++o)i+=`/${s[o]}`;try{const o=await Je(this.credentialsProvider,i,{},ge.Rc,e);await Cf(t,e,o,n.encoding)}catch(o){if(!(0,ge.El)(o))throw o}}};Aa=If([O()],Aa);var et=x(8053),La=x(6435);/**
 * @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 Ef=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.IMAGE=1]="IMAGE",t[t.SEGMENTATION=2]="SEGMENTATION",t))(Ef||{});const zg=18;function Ua(t){const{rank:e,dataType:n,fillValue:s=n===DataType.UINT64?Uint64.ZERO:0,compressedSegmentationBlockSize:i}=t,{baseVoxelOffset:r=new Float32Array(e)}=t;return{...makeSliceViewChunkSpecification(t),compressedSegmentationBlockSize:i,baseVoxelOffset:r,dataType:n,fillValue:s}}function kf(t){if(t.compressedSegmentationBlockSize!==void 0||t.volumeType!==2&&!t.volumeSourceOptions.discreteValues)return!1;switch(t.dataType){case DataType.UINT32:case DataType.UINT64:break;default:return!1}switch(t.rank){case 3:return!0;case 4:{const{chunkDataSize:e}=t;return e[3]===1}default:return!1}}function Tf(t){const{rank:e,lowerVoxelBound:n,upperVoxelBound:s}=t;if(!kf(t))return Ua(t);let{volumeSourceOptions:{displayRank:i,multiscaleToViewTransform:r},chunkToMultiscaleTransform:o,chunkToViewTransform:a}=t;a===void 0&&(a=matrix.multiply(new Float32Array(e*i),i,r,i,o,e+1,i,e,e));const{maxCompressedSegmentationBlockSize:c,chunkDataSize:l}=t;return Ua({...t,compressedSegmentationBlockSize:Float32Array.from(getNearIsotropicBlockSize({rank:e,chunkToViewTransform:a,displayRank:i,lowerVoxelBound:n,upperVoxelBound:s,maxVoxelsPerChunkLog2:9,maxBlockSize:c===void 0?l:vector.min(new Uint32Array(e),l,c)}))})}function Fg(t){const{rank:e}=t,{volumeSourceOptions:{displayRank:n,multiscaleToViewTransform:s,modelChannelDimensionIndices:i},chunkToMultiscaleTransform:r}=t,o=matrix.multiply(new Float32Array(n*e),n,s,n,r,e+1,n,e,e);let{minBlockSize:a}=t;a===void 0?(a=new Uint32Array(e),a.fill(1)):a=new Uint32Array(a);const{lowerVoxelBound:c,upperVoxelBound:l}=t;if(i.length!==0)for(const d of getDependentTransformInputDimensions(r,e,i)){let h=l[d];c!==void 0&&(h-=c[d]),a[d]=h}const{chunkDataSizes:u=getChunkDataSizes({...t,minBlockSize:a,chunkToViewTransform:o,displayRank:n})}=t;return u.map(d=>Tf({...t,chunkDataSize:d,chunkToViewTransform:o}))}const Gg="volume";var Df=x(147),Pf=Object.defineProperty,Rf=Object.getOwnPropertyDescriptor,_f=(t,e,n,s)=>{for(var i=s>1?void 0:s?Rf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Pf(e,n,i),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 Mf{}async function Of(t,e){(0,et.isCompressed)(t)&&(t=(await Be(Ut,e,[t],new Uint8Array(t))).buffer);const n=new Mf;n.uncompressedData=t;const s=(0,et.readHeader)(t);if(s===null)throw new Error("Failed to parse NIFTI header.");return n.header=s,{data:n,size:t.byteLength}}function Va(t,e,n,s,i){return Ot.getUrl(t,e,Of,n,s,i)}const Nf=1e3;async function xf(t,e,n,s){return(await Va(t,e,n,()=>({priorityTier:se.VISIBLE,priority:Nf}),s)).header}function Af(t){return w.pB.fromValues(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 Ba=(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))(Ba||{});const Lf=new Map([[256,{dataType:me.INT8}],[2,{dataType:me.UINT8}],[4,{dataType:me.INT16}],[512,{dataType:me.UINT16}],[8,{dataType:me.INT32}],[768,{dataType:me.UINT32}],[1024,{dataType:me.UINT64}],[1280,{dataType:me.UINT64}],[16,{dataType:me.FLOAT32}]]);We(La.Y,async function(t,e){const n=this.getRef(t.chunkManager),s=this.getOptionalRef(t.credentialsProvider);try{const i=await xf(n,s,t.url,e),r=Lf.get(i.datatypeCode);if(r===void 0)throw new Error(`Unsupported data type: ${Ba[i.datatypeCode]||i.datatypeCode}.`);let o=1,a="";switch(i.xyzt_units&et.NIFTI1.SPATIAL_UNITS_MASK){case et.NIFTI1.UNITS_METER:o=1,a="m";break;case et.NIFTI1.UNITS_MM:o=1e3,a="m";break;case et.NIFTI1.UNITS_MICRON:o=1e6,a="m";break}let c="",l=1;switch(i.xyzt_units&et.NIFTI1.TEMPORAL_UNITS_MASK){case et.NIFTI1.UNITS_SEC:c="s",l=1;break;case et.NIFTI1.UNITS_MSEC:c="s",l=1e3;break;case et.NIFTI1.UNITS_USEC:c="s",l=1e6;break;case et.NIFTI1.UNITS_HZ:c="Hz",l=1;break;case et.NIFTI1.UNITS_RADS:c="rad/s",l=1;break}let u=[a,a,a,c,"","",""],d=Float64Array.of(i.pixDims[1]/o,i.pixDims[2]/o,i.pixDims[3]/o,i.pixDims[4]/l,i.pixDims[5],i.pixDims[6],i.pixDims[7]),h=Float64Array.of(1/o,1/o,1/o,1/l,1,1,1),p=["i","j","k","m","c^","c1^","c2^"],m=["x","y","z","t","c^","c1^","c2^"];const f=i.dims[0];p=p.slice(0,f),m=m.slice(0,f),u=u.slice(0,f),d=d.slice(0,f),h=h.slice(0,f);const{quatern_b:b,quatern_c:I,quatern_d:E}=i,V=Math.sqrt(1-b*b-I*I-E*E),R=i.pixDims[0]===-1?-1:1,C=w.eR.fromValues(i.qoffset_x,i.qoffset_y,i.qoffset_z),S=Af(i.affine),T=(0,w.eG)(w.pB.create(),C,w.Yu.fromValues(b,I,E,V),w.Oi,R),v=Df.DA(Float64Array,f+1),N=Math.min(3,f);for(let y=0;y<N;++y){for(let A=0;A<N;++A)v[A*(f+1)+y]=T[A*4+y];v[f*(f+1)+y]=T[12+y]}return{value:{rank:f,sourceNames:p,viewNames:m,units:u,sourceScales:d,viewScales:h,description:i.description,transform:v,dataType:r.dataType,volumeSize:Uint32Array.from(i.dims.slice(1,1+f))}}}finally{n.dispose(),s?.dispose()}});let $a=class extends Ve(je()(ct),La.C){async download(t,e){t.chunkDataSize=this.spec.chunkDataSize;const n=await Va(this.chunkManager,this.credentialsProvider,this.parameters.url,()=>({priorityTier:t.priorityTier,priority:t.priority}),e),s=(0,et.readImage)(n.header,n.uncompressedData);await Mt(t,e,s,n.header.littleEndian?Oe.LITTLE:Oe.BIG)}};$a=_f([O()],$a);/**
 * @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.
 */const Uf=gt("parseOBJFromArrayBuffer");var cs=x(6015),Vf=Object.defineProperty,Bf=Object.getOwnPropertyDescriptor,za=(t,e,n,s)=>{for(var i=s>1?void 0:s?Bf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Vf(e,n,i),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.
 */const $f=50;class zf extends g{constructor(){super(...arguments),this.data=null}freeSystemMemory(){this.data=null}serialize(e,n){super.serialize(e,n);const{vertexPositions:s,indices:i,vertexNormals:r,vertexAttributes:o}=this.data;e.vertexPositions=s,e.indices=i,e.vertexNormals=r,e.vertexAttributes=o;const a=new Set;a.add(s.buffer),a.add(i.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:s,vertexAttributes:i}=this.data;let r=this.gpuMemoryBytes=e.byteLength+n.byteLength+s.byteLength;for(const o of i)r+=o.byteLength;this.systemMemoryBytes=this.gpuMemoryBytes=r,super.downloadSucceeded()}}const Fa=new Map;function Ga(t,e){Fa.set(t,e)}const Ff=/^(?:([a-zA-Z-+_]+):\/\/)?(.*)$/;function Gf(t,e){const n=e.match(Ff);if(n===null||n[1]===void 0)throw new Error('Data source URL must have the form "<protocol>://<path>".');const s=n[1],i=t.get(s);if(i===void 0)throw new Error(`Unsupported data source: ${JSON.stringify(s)}.`);return[i,n[2],s]}function jf(t,e,n,s,i){const[r,o]=Gf(Fa,n);return r.getMesh(t,e,o,s,i)}function jg(t){let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const s of t)e=Math.min(e,s),n=Math.max(n,s);return[e,n]}function ja(t,e,n,s,i){return jf(t,e,n.meshSourceUrl,s,i)}let Ya=class extends Ve(je()(oe),cs.Fe){getChunk(){const t=cs.b7;let e=this.chunks.get(t);return e===void 0&&(e=this.getNewChunk_(zf),e.initialize(t),this.addChunk(e)),e}download(t,e){const n=()=>({priorityTier:t.priorityTier,priority:t.priority});return ja(this.chunkManager,this.credentialsProvider,this.parameters,n,e).then(s=>{if((0,k.JB)(s.info)!==(0,k.JB)(this.parameters.info))throw new Error("Mesh info has changed.");s.vertexNormals===void 0&&(s.vertexNormals=wo(s.vertexPositions,s.indices)),t.data=s})}};Ya=za([O()],Ya);const Yf=Lt(bt(U));let Ja=class extends Yf{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=dt(t),n=ht(t),{source:s,chunkManager:i}=this,r=s.getChunk();i.requestChunk(r,e,n+$f)}};Ja=za([O(cs.nG)],Ja);const Jf=1e3;We(cs.N3,async function(t,e){const n=this.getRef(t.chunkManager),s=this.getOptionalRef(t.credentialsProvider);try{const i=t.parameters;return{value:(await ja(n,s,i,()=>({priorityTier:se.VISIBLE,priority:Jf}),e)).info}}finally{n.dispose(),s?.dispose()}});/**
 * @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 Hf(t,e){return Be(Uf,e,[t],t)}Ga("obj",{description:"OBJ",getMesh:(t,e,n,s,i)=>Ot.getUrl(t,e,Hf,n,s,i)});var zt=x(9063);/**
 * @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 Wf(t,e,n){const s=Mo(await Be(Ut,e,[n],new Uint8Array(n))),i=t.chunkDataSize,r=t.source,{shape:o}=s;if(!It(o,i))throw new Error(`Shape ${JSON.stringify(o)} does not match chunkDataSize ${i.join()}`);const a=s.dataType,{spec:c}=r;if(a!==c.dataType)throw new Error(`Data type ${me[a]} does not match expected data type ${me[c.dataType]}`);await rn(t,e,s.data)}var Kf=Object.defineProperty,qf=Object.getOwnPropertyDescriptor,mi=(t,e,n,s)=>{for(var i=s>1?void 0:s?qf(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Kf(e,n,i),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.
 */const ls=new Map;ls.set(zt.r7.NPZ,Wf),ls.set(zt.r7.JPEG,kn),ls.set(zt.r7.RAW,Mt);let Ha=class extends Ve(ct,zt.jj){constructor(){super(...arguments),this.chunkDecoder=ls.get(this.parameters.encoding),this.encoding=zt.r7[this.parameters.encoding].toLowerCase()}async download(t,e){const{parameters:n}=this;let s=`../../neuroglancer/${this.encoding}/${n.key}/${n.scaleKey}`;{const r=this.computeChunkBounds(t),o=t.chunkDataSize,a=r.length;s+=`/${r.join()}/`;for(let c=0;c<a;++c)c!==0&&(s+=","),s+=(r[c]+o[c]).toString()}const i=await(0,ge.Bk)(new URL(s,n.baseUrl).href,{},ge.Rc,e);await this.chunkDecoder(t,e,i)}};Ha=mi([O()],Ha);function Qf(t,e){const s=new DataView(e).getUint32(0,!0);sn(t,Zn(e,Oe.LITTLE,4,s))}let Wa=class extends Ve(nn,zt.Ve){download(t){return t.fragmentIds=[""],Promise.resolve(void 0)}downloadFragment(t,e){const{parameters:n}=this,s=`../../neuroglancer/mesh/${n.key}/${t.manifestChunk.objectId}`;return(0,ge.Bk)(new URL(s,n.baseUrl).href,{},ge.Rc,e).then(i=>Qf(t,i))}};Wa=mi([O()],Wa);let Ka=class extends Ve(ns,zt.NV){download(t,e){const{parameters:n}=this,s=`../../neuroglancer/skeleton/${n.key}/${t.objectId}`;return(0,ge.Bk)(new URL(s,n.baseUrl).href,{},ge.Rc,e).then(i=>ya(t,i,n.vertexAttributes))}};Ka=mi([O()],Ka);var Xf=x(8997),Zf=Object.defineProperty,ep=Object.getOwnPropertyDescriptor,tp=(t,e,n,s)=>{for(var i=s>1?void 0:s?ep(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&Zf(e,n,i),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.
 */const gi=new Map;gi.set("jpg",async(t,e,n)=>{const s=t.chunkDataSize,{uint8Array:i}=await Be(ei,e,[n],new Uint8Array(n),s[0],s[1]*s[2],3,!0);await rn(t,e,i)}),gi.set("raw16",(t,e,n)=>Mt(t,e,n,Oe.BIG));let qa=class extends Ve(ct,Xf.vc){constructor(){super(...arguments),this.chunkDecoder=gi.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:s}=t,i=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=w.eR.create();a[0]=s[0]*r,a[1]=s[1]*o,a[2]=s[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},${i}/${c}`,u=await(0,ge.Bk)(`${n.baseUrl}${l}?${this.queryString}`,{},ge.Rc,e);await this.chunkDecoder(t,e,u)}};qa=tp([O()],qa);/**
 * @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 np=gt("parseVTKFromArrayBuffer");/**
 * @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 sp(t,e){return Be(np,e,[t],t)}Ga("vtk",{description:"VTK",getMesh:(t,e,n,s,i)=>Ot.getUrl(t,e,sp,n,s,i).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:me.FLOAT32,numComponents:a.numComponents}),o.vertexAttributes.push(a.data);return o})});var _e=x(2334);/**
 * @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.
 */const ln={[_e.L.arrayToArray]:new Map,[_e.L.arrayToBytes]:new Map,[_e.L.bytesToBytes]:new Map,sharding:new Map};function Ft(t){t.kind===_e.L.arrayToBytes&&"getShardedKvStore"in t?ln.sharding.set(t.name,t):ln[t.kind].set(t.name,t)}async function Qa(t,e,n){const s=t[_e.L.bytesToBytes];for(let o=s.length;o--;){const a=s[o],c=ln[_e.L.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 i;{const o=t[_e.L.arrayToBytes],a=ln[_e.L.arrayToBytes].get(o.name);if(a===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(o.name)}`);i=await a.decode(o.configuration,t.arrayInfo[t.arrayInfo.length-1],e,n)}const r=t[_e.L.arrayToArray];for(let o=r.length;o--;){const a=r[o],c=ln[_e.L.arrayToArray].get(a.name);if(c===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(a.name)}`);i=await c.decode(a.configuration,t.arrayInfo[o],i,n)}return i}function ip(t,e,n){let s=n,i=e;for(;;){const{shardingInfo:a}=i;if(a===void 0)break;const c=i[_e.L.arrayToBytes],l=ln.sharding.get(c.name);if(l===void 0)throw new Error(`Unsupported codec: ${JSON.stringify(c.name)}`);s=l.getShardedKvStore(c.configuration,t,s),i=a.subChunkCodecs}const r=i;function o(a,c){let l=c;const u=a.length;let d=e;for(;d.shardingInfo!==void 0;){const h=e.layoutInfo[e.layoutInfo.length-1],{physicalToLogicalDimension:p,readChunkShape:m}=h,{subChunkShape:f,subChunkGridShape:b,subChunkCodecs:I}=d.shardingInfo,E=new Array(u);for(let V=0;V<u;++V){const R=p[u-1-V];E[R]=Math.floor(a[V]*m[R]/f[R])%b[R]}l={base:l,subChunk:E},d=I}return l}return{kvStore:s,getChunkKey:o,decodeCodecs: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.
 */Ft({name:"blosc",kind:_e.L.bytesToBytes,decode(t,e,n){return Be(Na,n,[e.buffer],e)}});/**
 * @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.
 */Ft({name:"zstd",kind:_e.L.bytesToBytes,decode(t,e,n){return Be(xa,n,[e.buffer],e)}});/**
 * @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.
 */Ft({name:"bytes",kind:_e.L.arrayToBytes,async decode(t,e,n,s){const{dataType:i,chunkShape:r}=e,o=r.reduce((u,d)=>u*d,1),a=Kt[i],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=Yi(i,n.buffer,n.byteOffset,n.byteLength);return _s(l,t.endian,a),l}});/**
 * @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.
 */const yi=4;Ft({name:"crc32c",kind:_e.L.bytesToBytes,async decode(t,e,n){if(e.length<yi)throw new Error(`Expected buffer of size at least ${yi} bytes but received: ${e.length} bytes`);return e.subarray(0,e.length-yi)}});var rp=x(6742);/**
 * @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.
 */Ft({name:"gzip",kind:_e.L.bytesToBytes,decode(t,e,n){return Be(Ut,n,[e.buffer],e)}});/**
 * @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 op(t,e,n){(0,k.Rf)(t);const s=(0,k.cQ)(t,"name",r=>e((0,k.zr)(r))),i=(0,k.cQ)(t,"configuration",r=>(r===void 0?r={}:(0,k.Rf)(r),n(r,s)));return{name:s,configuration:i}}/**
 * @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 ap(t){const{name:e,configuration:n}=op(t,s=>{const i=Xa.get(s);if(i===void 0)throw new Error(`Unknown codec: ${JSON.stringify(s)}`);return i},s=>s);return{resolver:e,configuration:n}}const Xa=new Map;function cp(t){Xa.set(t.name,t)}function Za(t,e){const n=[],s=[],i=[],r=[];s.push(e);const o=(0,k.$v)(t,ap),a=o.length;let c=0;for(;c<a;++c){const{resolver:f,configuration:b}=o[c];if(f.kind!==_e.L.arrayToArray)break;const I=f,{configuration:E,encodedArrayInfo:V}=I.resolve(b,e);s.push(V),e=V,n.push({kind:_e.L.arrayToArray,name:f.name,configuration:E})}if(c===a||o[c].resolver.kind!==_e.L.arrayToBytes)throw new Error("Missing array -> bytes codec");const{codecSpec:l,layoutInfo:u,encodedSize:d,shardingInfo:h}=(()=>{const{resolver:f,configuration:b}=o[c],I=f,{configuration:E,shardingInfo:V,encodedSize:R}=I.resolve(b,e);if(V!==void 0&&c+1!==a)throw new Error("bytes -> bytes codecs not supported following sharding codec");const C=I.getDecodedArrayLayoutInfo(E,e);return{codecSpec:{name:f.name,kind:_e.L.arrayToBytes,configuration:E},layoutInfo:C,encodedSize:R,shardingInfo:V}})();i[c]=u,r.push(d);const p=d,m=[];for(++c;c<a;){const{resolver:f,configuration:b}=o[c];if(f.kind!==_e.L.bytesToBytes)throw new Error(`Expected bytes -> bytes codec, but received ${JSON.stringify(f.name)} of kind ${_e.L[f.kind]}`);const I=f,{configuration:E,encodedSize:V}=I.resolve(b,p);m.push({name:f.name,kind:f.kind,configuration:E}),r.push(V),++c}for(let f=n.length-1;f>=0;--f)i[f]=o[f].resolver.getDecodedArrayLayoutInfo(n[f].configuration,s[f],i[f+1]);return{[_e.L.arrayToArray]:n,[_e.L.arrayToBytes]:l,[_e.L.bytesToBytes]:m,arrayInfo:s,layoutInfo:i,shardingInfo:h,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 ec=(t=>(t[t.DEFAULT=0]="DEFAULT",t[t.V2=1]="V2",t))(ec||{});/**
 * @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 tc(t){return parseArray(t,e=>{if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new Error(`Expected non-negative integer, but received: ${JSON.stringify(e)}`);return e})}function vi(t,e){return(0,k.Xu)(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})}function nc(t){if(t!=="."&&t!=="/")throw new Error(`Expected "." or "/", but received: ${JSON.stringify(t)}`);return t}const wi=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 _i){const{longPrefix:n,prefix:s}=e;if(n===void 0)continue;const i={unit:t[0],scale:10**e.exponent};wi.set(`${n}${t}`,i),wi.set(`${s}${t[0]}`,i)}function Yg(t){if(t===null)return{scale:1,unit:""};if(typeof t!="string")throw new Error(`Expected string but received: ${JSON.stringify(t)}`);const e=t.trim(),n=/^([-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?\d+)?)\s*(.*)/,s=e.match(n);let i,r;s===null?(i=1,r=e):(i=Number(s[1]),r=s[2]);const o=wi.get(r);if(o===void 0)throw new Error(`Unsupported unit: ${JSON.stringify(r)}`);return{unit:o.unit,scale:i*o.scale}}function sc(t,e){switch(t){case DataType.UINT8:case DataType.INT8:case DataType.UINT16:case DataType.INT16:case DataType.UINT32:case DataType.INT32:case DataType.UINT64:if(typeof e!="number"||!Number.isInteger(e))throw new Error(`Expected integer but received: ${JSON.stringify(e)}`);return e;case DataType.FLOAT32:if(typeof e=="number")return e;if(typeof e=="string"){if(e==="Infinity")return Number.POSITIVE_INFINITY;if(e==="-Infinity")return Number.NEGATIVE_INFINITY;if(e==="NaN")return new Float32Array(Uint32Array.of(2143289344).buffer)[0];if(e.match(/^0x[a-fA-F0-9]+$/))return new Float32Array(Uint32Array.of(Number(e)).buffer)[0]}throw new Error(`Expected number, "Infinity", "-Infinity", "NaN", or hex string but received: ${JSON.stringify(e)}`)}}function Jg(t,e){try{verifyObject(t),verifyObjectProperty(t,"zarr_format",m=>{verifyConstant(m,3)});const n=verifyObjectProperty(t,"node_type",m=>{if(e!==void 0&&verifyConstant(m,e),m!=="array"&&m!=="group")throw new Error(`Expected "array" or "group" but received: ${JSON.stringify(m)}`);return m});if(e=n,n==="group")return{zarrVersion:3,nodeType:"group",userAttributes:verifyOptionalObjectProperty(t,"attributes",verifyObject,{})};const s=verifyObjectProperty(t,"shape",tc),i=s.length,r=verifyObjectProperty(t,"dimension_names",m=>verifyOptionalFixedLengthArrayOfStringOrNull(m??void 0,i)),o=verifyObjectProperty(t,"data_type",m=>verifyEnumString(m,DataType,/^[a-z0-9]+$/)),{configuration:a}=verifyObjectProperty(t,"chunk_grid",m=>parseNameAndConfiguration(m,f=>verifyConstant(f,"regular"),f=>verifyObjectProperty(f,"chunk_shape",b=>vi(b,i)))),{userAttributes:c,dimensionUnits:l}=verifyObjectProperty(t,"attributes",m=>{m===void 0&&(m={}),verifyObject(m);const f=verifyObjectProperty(m,"dimension_units",b=>verifyOptionalFixedLengthArrayOfStringOrNull(b,i));return{userAttributes:m,dimensionUnits:f}}),{configuration:u,name:d}=verifyObjectProperty(t,"chunk_key_encoding",m=>parseNameAndConfiguration(m,f=>verifyEnumString(f,ChunkKeyEncoding,/^(v2|default)$/),(f,b)=>verifyOptionalObjectProperty(f,"separator",nc,b===ChunkKeyEncoding.DEFAULT?"/":"."))),h=verifyObjectProperty(t,"fill_value",m=>sc(o,m)),p=verifyObjectProperty(t,"codecs",m=>parseCodecChainSpec(m,{dataType:o,chunkShape:a}));return{zarrVersion:3,nodeType:n,rank:i,shape:s,chunkShape:a,dataType:o,fillValue:h,dimensionNames:r,dimensionUnits:l,chunkKeyEncoding:d,dimensionSeparator:u,userAttributes:c,codecs:p}}catch(n){const s=e===void 0?"":`${e} `;throw new Error(`Error parsing zarr v3 ${s}metadata: ${n.message}`)}}function Hg(t,e,n){try{verifyObject(t),verifyObjectProperty(t,"zarr_format",p=>{verifyConstant(p,2)});const s=verifyObjectProperty(t,"shape",tc),i=s.length,r=verifyObjectProperty(t,"chunks",p=>vi(p,i)),o=verifyObjectProperty(t,"order",p=>{if(p!=="C"&&p!=="F")throw new Error(`Expected "C" or "F", but received: ${JSON.stringify(p)}`);return p}),a=verifyOptionalObjectProperty(t,"dimension_separator",n===void 0?nc:p=>verifyConstant(p,n),n??"."),c=verifyObjectProperty(t,"dtype",p=>parseNumpyDtype(verifyString(p))),l=c.dataType,u=verifyObjectProperty(t,"fill_value",p=>p===null?0:sc(l,p)),d=[];o==="F"&&d.push({name:"transpose",configuration:{order:Array.from(s,(p,m)=>i-m-1)}}),d.push({name:"bytes",configuration:{endian:c.endianness===Endianness.LITTLE?"little":"big"}}),verifyObjectProperty(t,"compressor",p=>{if(p===null)return;verifyObject(p);const m=verifyObjectProperty(p,"id",verifyString);switch(m){case"blosc":d.push({name:"blosc",configuration:{cname:verifyObjectProperty(p,"cname",verifyString),clevel:verifyObjectProperty(p,"clevel",verifyInt),typesize:DATA_TYPE_BYTES[l],shuffle:verifyObjectProperty(p,"shuffle",f=>{switch(f){case-1:return DATA_TYPE_BYTES[l]===1?"bitshuffle":"shuffle";case 0:return"noshuffle";case 1:return"shuffle";case 2:return"bitshuffle"}throw new Error(`Invalid value: ${JSON.stringify(f)}`)}),blocksize:verifyOptionalObjectProperty(p,"blocksize",verifyInt,0)}});break;case"zlib":case"gzip":d.push({name:"gzip",configuration:{level:verifyObjectProperty(p,"level",verifyInt)}});break;case"zstd":d.push({name:"zstd",configuration:{level:verifyObjectProperty(p,"level",verifyInt)}});break;default:throw new Error(`Unsupported compressor: ${JSON.stringify(m)}`)}});const h=parseCodecChainSpec(d,{dataType:l,chunkShape:r});return{zarrVersion:2,nodeType:"array",rank:i,shape:s,chunkShape:r,dataType:l,fillValue:u,dimensionNames:verifyObjectProperty(e,"_ARRAY_DIMENSIONS",p=>verifyOptionalFixedLengthArrayOfStringOrNull(p,i)),dimensionUnits:verifyObjectProperty(e,"dimension_units",p=>verifyOptionalFixedLengthArrayOfStringOrNull(p,i)),userAttributes:e,dimensionSeparator:a,chunkKeyEncoding:ChunkKeyEncoding.V2,codecs:h}}catch(s){throw new Error(`Error parsing zarr v2 metadata: ${s.message}`)}}/**
 * @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 us=(t=>(t[t.START=0]="START",t[t.END=1]="END",t))(us||{});cp({name:"sharding_indexed",kind:_e.L.arrayToBytes,resolve(t,e){(0,k.Rf)(t);const n=(0,k.cQ)(t,"chunk_shape",c=>vi(c,e.chunkShape.length)),s=(0,k.MM)(t,"index_location",c=>(0,k.sl)(c,us,/^[a-z]+$/),1),i=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(i);r.push(2);const o=(0,k.cQ)(t,"index_codecs",c=>Za(c,{dataType:me.UINT64,chunkShape:r}));if(o.encodedSize[o.encodedSize.length-1]===void 0)throw new Error("index_codecs must specify fixed-size encoding");const a=(0,k.cQ)(t,"codecs",c=>Za(c,{dataType:e.dataType,chunkShape:n}));return{configuration:{indexCodecs:o,subChunkCodecs:a,subChunkShape:n,subChunkGridShape:i,indexLocation:s},shardingInfo:{subChunkShape:n,subChunkGridShape:i,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 ic(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}}/**
 * @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.
 */const rc=BigInt("18446744073709551615");class lp extends Y.O8{constructor(e,n,s){super(),this.configuration=e,this.base=s,this.indexCache=this.registerDisposer(new ha(n.addRef(),{get:async(l,u)=>{const{indexCodecs:d}=e,h=d.encodedSize[d.encodedSize.length-1];let p;switch(e.indexLocation){case us.START:p={offset:0,length:h};break;case us.END:p={suffixLength:h};break}const m=await s.read(l,{cancellationToken:u,byteRange:p});if(m===void 0)return{size:0,data:void 0};const f=await Qa(e.indexCodecs,m.data,u);return{size:f.byteLength,data:new BigUint64Array(f.buffer,f.byteOffset,f.byteLength/8)}}}));const{subChunkGridShape:i}=this.configuration,r=i.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:i[u]}}async read(e,n){const s=await this.indexCache.get(e.base,n.cancellationToken??j.fx);if(s===void 0)return;const i=this.configuration.subChunkShape.length,{subChunk:r}=e,{indexStrides:o}=this;let a=0;for(let m=0;m<i;++m){const f=r[m];a+=f*o[m]}const c=s[a],l=s[a+o[i]];if(c===rc&&l===rc)return;const u={offset:Number(c),length:Number(l)},{outer:d,inner:h}=ic(u,n.byteRange);if(d.length===0)return{data:new Uint8Array(0),dataRange:h,totalSize:u.length};const p=await this.base.read(e.base,{cancellationToken:n.cancellationToken,byteRange:d});if(p!==void 0){if(p.dataRange.offset!==d.offset||p.dataRange.length!==d.length)throw new Error(`Received truncated response, expected ${JSON.stringify(d)} but received ${JSON.stringify(p.dataRange)}`);return{data:p.data,dataRange:h,totalSize:u.length}}}}Ft({name:"sharding_indexed",kind:_e.L.arrayToBytes,getShardedKvStore(t,e,n){return new lp(t,e,n)}});/**
 * @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.
 */Ft({name:"transpose",kind:_e.L.arrayToArray,async decode(t,e,n,s){return n}});/**
 * @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 up(t){if(t!==void 0)return"suffixLength"in t?`bytes=-${t.suffixLength}`:`bytes=${t.offset}-${t.offset+t.length-1}`}const dp=navigator.userAgent.indexOf("Chrome")!==-1?"no-store":"default";class hp{constructor(e,n){this.credentialsProvider=e,this.baseUrl=n}async read(e,n){const{cancellationToken:s=j.fx}=n;let{byteRange:i}=n;const r=this.baseUrl+e;for(let o=0;;++o)try{const a={},c=up(i);c!==void 0&&(a.headers={range:c},a.cache=dp);const{response:l,data:u}=await Je(this.credentialsProvider,r,a,async p=>({response:p,data:await p.arrayBuffer()}),s);let d,h;if(l.status===206){const p=l.headers.get("content-range");if(p===null)if(i!==void 0){if("suffixLength"in i)throw new Error("Content-range header not provided with HTTP 206 response.  Check server CORS configuration.");d={offset:i.offset,length:u.byteLength}}else throw new Error("Unexpected HTTP 206 response when no byte range specified.");if(p!==null){const m=p.match(/bytes ([0-9]+)-([0-9]+)\/([0-9]+|\*)/);if(m===null)throw new Error(`Invalid content-range header: ${JSON.stringify(p)}`);const f=parseInt(m[1],10);if(parseInt(m[2],10)!==f+u.byteLength-1)throw new Error(`Length in content-range header ${JSON.stringify(p)} does not match content length ${u.byteLength}`);h=m[3]==="*"?void 0:parseInt(m[3],10),d={offset:f,length:u.byteLength}}}return d===void 0&&(d={offset:0,length:u.byteLength},h=u.byteLength),{data:new Uint8Array(u),dataRange:d,totalSize:h}}catch(a){if(o===0&&a instanceof ge.j$&&a.status===416&&n.byteRange!==void 0&&"suffixLength"in n.byteRange){const c=await Je(this.credentialsProvider,r,{method:"HEAD"},async d=>d,s);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);i=ic({offset:0,length:u},i).outer;continue}if((0,ge.El)(a))return;throw a}}}function fp(t,e){return new hp(t,e)}var pp=Object.defineProperty,mp=Object.getOwnPropertyDescriptor,gp=(t,e,n,s)=>{for(var i=s>1?void 0:s?mp(e,n):e,r=t.length-1,o;r>=0;r--)(o=t[r])&&(i=(s?o(e,n,i):o(i))||i);return s&&i&&pp(e,n,i),i};/**
 * @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.
 */let oc=class extends Ve(je()(ct),rp.j){constructor(){super(...arguments),this.chunkKvStore=ip(this.chunkManager,this.parameters.metadata.codecs,fp(this.credentialsProvider,this.parameters.url+"/"))}async download(t,e){t.chunkDataSize=this.spec.chunkDataSize;const{parameters:n}=this,{chunkGridPosition:s}=t,{metadata:i}=n;let r="";const o=this.spec.rank,{physicalToLogicalDimension:a}=i.codecs.layoutInfo[0];let c;i.chunkKeyEncoding===ec.DEFAULT?(r+="c",c=i.dimensionSeparator):(c="",o===0&&(r+="0"));const l=new Array(o),{readChunkShape:u}=i.codecs.layoutInfo[0],{chunkShape:d}=i;for(let m=0;m<o;++m){const f=a[o-1-m];l[f]=Math.floor(s[m]*u[f]/d[f])}for(let m=0;m<o;++m)r+=`${c}${l[m]}`,c=i.dimensionSeparator;const{chunkKvStore:h}=this,p=await h.kvStore.read(h.getChunkKey(s,r),{cancellationToken:e});if(p!==void 0){const m=await Qa(h.decodeCodecs,p.data,e);await rn(t,e,m)}}};oc=gp([O()],oc);/**
 * @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 ac=new Xe(self,!1);ac.sendReady(),globalThis.rpc=ac}},uc={};function Ce(te){var Se=uc[te];if(Se!==void 0)return Se.exports;var x=uc[te]={exports:{}};return lc[te].call(x.exports,x,x.exports,Ce),x.exports}Ce.m=lc,Ce.x=()=>{var te=Ce.O(void 0,[562,108,549],()=>Ce(1075));return te=Ce.O(te),te},(()=>{var te=[];Ce.O=(Se,x,ye,j)=>{if(x){j=j||0;for(var Y=te.length;Y>0&&te[Y-1][2]>j;Y--)te[Y]=te[Y-1];te[Y]=[x,ye,j];return}for(var be=1/0,Y=0;Y<te.length;Y++){for(var[x,ye,j]=te[Y],ce=!0,ve=0;ve<x.length;ve++)(j&!1||be>=j)&&Object.keys(Ce.O).every(Ge=>Ce.O[Ge](x[ve]))?x.splice(ve--,1):(ce=!1,j<be&&(be=j));if(ce){te.splice(Y--,1);var Re=ye();Re!==void 0&&(Se=Re)}}return Se}})(),Ce.d=(te,Se)=>{for(var x in Se)Ce.o(Se,x)&&!Ce.o(te,x)&&Object.defineProperty(te,x,{enumerable:!0,get:Se[x]})},Ce.f={},Ce.e=te=>Promise.all(Object.keys(Ce.f).reduce((Se,x)=>(Ce.f[x](te,Se),Se),[])),Ce.u=te=>te===562?"562.2601de1ad5d7e8b57b28.js":te===549?"549.03623816200b19900cb4.js":""+(te===491?"neuroglancer_async_computation":te)+"."+{108:"4606cff017742e5cb49d",491:"7a2236a27da923b7d515"}[te]+".js",Ce.miniCssF=te=>{},Ce.o=(te,Se)=>Object.prototype.hasOwnProperty.call(te,Se),Ce.r=te=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(te,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(te,"__esModule",{value:!0})},(()=>{var te;if(typeof import.meta.url=="string"&&(te=import.meta.url),!te)throw new Error("Automatic publicPath is not supported in this browser");te=te.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),Ce.p=te})(),(()=>{Ce.b=new URL("./",import.meta.url);var te={717:0},Se=x=>{var{ids:ye,modules:j,runtime:Y}=x,be,ce,ve=0;for(be in j)Ce.o(j,be)&&(Ce.m[be]=j[be]);for(Y&&Y(Ce);ve<ye.length;ve++)ce=ye[ve],Ce.o(te,ce)&&te[ce]&&te[ce][0](),te[ye[ve]]=0;Ce.O()};Ce.f.j=(x,ye)=>{var j=Ce.o(te,x)?te[x]:void 0;if(j!==0)if(j)ye.push(j[1]);else{var Y=import("./"+Ce.u(x)).then(Se,be=>{throw te[x]!==0&&(te[x]=void 0),be}),Y=Promise.race([Y,new Promise(be=>j=te[x]=[be])]);ye.push(j[1]=Y)}},Ce.O.j=x=>te[x]===0})(),(()=>{var te=Ce.x;Ce.x=()=>Promise.all([562,108,549].map(Ce.e,Ce)).then(te)})();var qg=Ce.x();

//# sourceMappingURL=neuroglancer_chunk_worker.746786d476662d9045b7.js.map