!function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=187)}([function(e,t,n){"use strict";n.d(t,"s",(function(){return r})),n.d(t,"p",(function(){return s})),n.d(t,"q",(function(){return o})),n.d(t,"r",(function(){return a})),n.d(t,"g",(function(){return c})),n.d(t,"c",(function(){return l})),n.d(t,"e",(function(){return d})),n.d(t,"h",(function(){return u})),n.d(t,"j",(function(){return S})),n.d(t,"a",(function(){return w})),n.d(t,"b",(function(){return x})),n.d(t,"d",(function(){return C})),n.d(t,"w",(function(){return O})),n.d(t,"u",(function(){return k})),n.d(t,"D",(function(){return E})),n.d(t,"v",(function(){return T})),n.d(t,"E",(function(){return M})),n.d(t,"C",(function(){return D})),n.d(t,"A",(function(){return L})),n.d(t,"z",(function(){return j})),n.d(t,"y",(function(){return I})),n.d(t,"B",(function(){return P})),n.d(t,"x",(function(){return A})),n.d(t,"t",(function(){return R})),n.d(t,"f",(function(){return N})),n.d(t,"i",(function(){return V})),n.d(t,"o",(function(){return _})),n.d(t,"m",(function(){return B})),n.d(t,"l",(function(){return F})),n.d(t,"k",(function(){return z})),n.d(t,"F",(function(){return U})),n.d(t,"n",(function(){return G}));var i=n(1);
/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function r(e){let t=typeof e;if("number"===t||"string"===t){let t=parseFloat(""+e);if(!Number.isNaN(t))return t}throw new Error(`Expected floating-point number, but received: ${JSON.stringify(e)}.`)}function s(e){let t=r(e);if(Number.isFinite(t))return t;throw new Error(`Expected finite floating-point number, but received: ${t}.`)}function o(e){let t=r(e);if(Number.isFinite(t)&&t>=0)return t;throw new Error(`Expected finite non-negative floating-point number, but received: ${t}.`)}function a(e){let t=s(e);if(t>0)return t;throw new Error(`Expected positive finite floating-point number, but received: ${t}.`)}function c(e,t,n=r){O(t),e[0]=e[1]=e[2]=0;for(const i of Object.keys(t))switch(i){case"x":e[0]=n(t[i]);break;case"y":e[1]=n(t[i]);break;case"z":e[2]=n(t[i]);break;default:throw new Error(`Expected object to have keys ['x', 'y', 'z'], but received: ${JSON.stringify(t)}.`)}return e}function l(e,t){let n=e.length;if(!Array.isArray(t)||t.length!==n)throw new Error("Incompatible sizes");for(let e=0;e<n;++e)if(!Number.isFinite(parseFloat(t[e])))throw new Error("Non-finite value.");for(let i=0;i<n;++i)e[i]=parseFloat(t[i]);return e}function d(e,t){let n=e.length;if(!Array.isArray(t)||t.length!==n)throw new Error("Incompatible sizes.");for(let e=0;e<n;++e){let n=parseInt(t[e],void 0);if(!Number.isInteger(n))throw new Error("Non-integer value.")}for(let i=0;i<n;++i)e[i]=parseInt(t[i],void 0);return e}function u(e){if("object"==typeof e){if(null===e)return"null";if(Array.isArray(e)){let t="[",n=e.length,i=0;if(i<n)for(t+=u(e[i]);++i<n;)t+=",",t+=u(e[i]);return t+="]",t}let t="{",n=Object.keys(e).sort(),i=0,r=n.length;if(i<r){let s=n[i];for(t+=JSON.stringify(s),t+=":",t+=u(e[s]);++i<r;)t+=",",s=n[i],t+=JSON.stringify(s),t+=":",t+=u(e[s])}return t+="}",t}return JSON.stringify(e)}const h=/('(?:[^'\\]|(?:\\.))*')/,p=/("(?:[^"\\]|(?:\\.))*")/,f=new RegExp(`${h.source}|${p.source}`),m=new RegExp(`${p.source}|${h.source}`),g=/^((?:[^"'\\]|(?:\\[^']))*)("|\\')/,v=/^((?:[^"'\\]|(?:\\.))*)'/;function b(e,t,n,i){if(e.length>=2&&e.charAt(0)===t&&e.charAt(e.length-1)===t){let r=e.substr(1,e.length-2),s=n;for(;r.length>0;){let e=r.match(i);if(null===e){s+=r;break}s+=e[1],e[2]===n?(s+="\\",s+=n):s+=t,r=r.substr(e.index+e[0].length)}return s+=n,s}return e}function y(e,t,n){const i=/[&_,]/g;let r,s,o;'"'===n?(r="'",s=g,o=f):(r='"',s=v,o=m);let a="";for(;e.length>0;){let c,l,d=e.match(o);if(null===d)c=e,e="",l="";else{c=e.substr(0,d.index),e=e.substr(d.index+d[0].length);let t=d[1];l=void 0!==t?b(t,r,n,s):d[2]}a+=c.replace(i,t),a+=l}return a}function S(e){return JSON.parse(function(e){return y(e,",",'"')}(e))}function w(e,t){if(!Array.isArray(e))throw new Error(`Expected array, but received: ${JSON.stringify(e)}.`);if(void 0!==t&&e.length!==t)throw new Error(`Expected array of length ${t}, but received: ${JSON.stringify(e)}.`);return e}function x(e,t){if(!Array.isArray(e))throw new Error(`Expected array, but received: ${JSON.stringify(e)}.`);return e.map(t)}function C(e,t,n){const i=e.length;if(!Array.isArray(t)||t.length!==i)throw new Error(`Expected length ${i} array, but received: ${JSON.stringify(t)}.`);for(let r=0;r<i;++r)e[r]=n(t[r],r);return e}function O(e){if("object"!=typeof e||null==e||Array.isArray(e))throw new Error(`Expected JSON object, but received: ${JSON.stringify(e)}.`);return e}function k(e){let t=parseInt(e,10);if(!Number.isInteger(t))throw new Error(`Expected integer, but received: ${JSON.stringify(e)}.`);return t}function E(e){let t=k(e);if(t<=0)throw new Error(`Expected positive integer, but received: ${t}.`);return t}function T(e,t){let n=t.get(e);if(void 0===n)throw new Error(`Expected one of ${JSON.stringify(Array.from(t.keys()))}, `+`but received: ${JSON.stringify(e)}.`);return n}function M(e){if("string"!=typeof e)throw new Error(`Expected string, but received: ${JSON.stringify(e)}.`);return e}function D(e){if(void 0!==e)return M(e)}function L(e){if(void 0!==e)return k(e)}function j(e){if(void 0!==e){if("boolean"==typeof e)return e;if("true"===e)return!0;if("false"===e)return!1;throw new Error(`Expected string or boolean but received: ${JSON.stringify(e)}`)}}function I(e,t,n){let i=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;try{return n(i)}catch(e){throw new Error(`Error parsing ${JSON.stringify(t)} property: ${e.message}`)}}function P(e,t,n,i){return I(e,t,e=>void 0===e?i:n(e))}function A(e,t){O(e);let n=new Map;for(let i of Object.keys(e))try{n.set(i,t(e[i]))}catch(e){throw new Error(`Error parsing value associated with key ${JSON.stringify(i)}: ${e.message}`)}return n}function R(e){if("number"!=typeof e||!Number.isFinite(e)||e<0||e>1)throw new Error(`Expected floating point number in [0,1], but received: ${JSON.stringify(e)}.`);return e}function N(e){if(""===e)return{};if(e.startsWith("{"))return S(e);{let t={},n=e.split(/[&;]/);for(let e of n){let n=e.match(/^([^=&;]+)=([^&;]*)$/);if(null===n)throw new Error(`Invalid query string part: ${JSON.stringify(e)}.`);t[n[1]]=decodeURIComponent(n[2])}return t}}function V(e){if(void 0===e)return"";const t=Object.keys(e);return 0===t.length?"":t.some(t=>"string"!=typeof e[t])?JSON.stringify(e):t.map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`).join("&")}function _(e,t){if("string"==typeof e&&null!==e.match(/^[a-zA-Z]/)&&(e=e.toUpperCase(),t.hasOwnProperty(e)))return t[e];throw new Error(`Invalid enum value: ${JSON.stringify(e)}.`)}function B(e){return C(i.u.create(),e,s)}function F(e){return C(i.u.create(),e,a)}function z(e){return C(i.u.create(),e,E)}function U(e){if(!Array.isArray(e))throw new Error(`Expected array, received: ${JSON.stringify(e)}.`);for(let t of e)if("string"!=typeof t)throw new Error(`Expected string, received: ${JSON.stringify(t)}.`);return e}function G(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, received: ${JSON.stringify(e)}`);return e}},function(e,t,n){"use strict";var i={};n.r(i),n.d(i,"create",(function(){return u})),n.d(i,"fromMat4",(function(){return h})),n.d(i,"clone",(function(){return p})),n.d(i,"copy",(function(){return f})),n.d(i,"fromValues",(function(){return m})),n.d(i,"set",(function(){return g})),n.d(i,"identity",(function(){return v})),n.d(i,"transpose",(function(){return b})),n.d(i,"invert",(function(){return y})),n.d(i,"adjoint",(function(){return S})),n.d(i,"determinant",(function(){return w})),n.d(i,"multiply",(function(){return x})),n.d(i,"translate",(function(){return C})),n.d(i,"rotate",(function(){return O})),n.d(i,"scale",(function(){return k})),n.d(i,"fromTranslation",(function(){return E})),n.d(i,"fromRotation",(function(){return T})),n.d(i,"fromScaling",(function(){return M})),n.d(i,"fromMat2d",(function(){return D})),n.d(i,"fromQuat",(function(){return L})),n.d(i,"normalFromMat4",(function(){return j})),n.d(i,"projection",(function(){return I})),n.d(i,"str",(function(){return P})),n.d(i,"frob",(function(){return A})),n.d(i,"add",(function(){return R})),n.d(i,"subtract",(function(){return N})),n.d(i,"multiplyScalar",(function(){return V})),n.d(i,"multiplyScalarAndAdd",(function(){return _})),n.d(i,"exactEquals",(function(){return B})),n.d(i,"equals",(function(){return F})),n.d(i,"mul",(function(){return z})),n.d(i,"sub",(function(){return U}));var r={};n.r(r),n.d(r,"create",(function(){return G})),n.d(r,"clone",(function(){return $})),n.d(r,"copy",(function(){return W})),n.d(r,"fromValues",(function(){return H})),n.d(r,"set",(function(){return J})),n.d(r,"identity",(function(){return q})),n.d(r,"transpose",(function(){return Y})),n.d(r,"invert",(function(){return X})),n.d(r,"adjoint",(function(){return K})),n.d(r,"determinant",(function(){return Q})),n.d(r,"multiply",(function(){return Z})),n.d(r,"translate",(function(){return ee})),n.d(r,"scale",(function(){return te})),n.d(r,"rotate",(function(){return ne})),n.d(r,"rotateX",(function(){return ie})),n.d(r,"rotateY",(function(){return re})),n.d(r,"rotateZ",(function(){return se})),n.d(r,"fromTranslation",(function(){return oe})),n.d(r,"fromScaling",(function(){return ae})),n.d(r,"fromRotation",(function(){return ce})),n.d(r,"fromXRotation",(function(){return le})),n.d(r,"fromYRotation",(function(){return de})),n.d(r,"fromZRotation",(function(){return ue})),n.d(r,"fromRotationTranslation",(function(){return he})),n.d(r,"fromQuat2",(function(){return pe})),n.d(r,"getTranslation",(function(){return fe})),n.d(r,"getScaling",(function(){return me})),n.d(r,"getRotation",(function(){return ge})),n.d(r,"fromRotationTranslationScale",(function(){return ve})),n.d(r,"fromRotationTranslationScaleOrigin",(function(){return be})),n.d(r,"fromQuat",(function(){return ye})),n.d(r,"frustum",(function(){return Se})),n.d(r,"perspective",(function(){return we})),n.d(r,"perspectiveFromFieldOfView",(function(){return xe})),n.d(r,"ortho",(function(){return Ce})),n.d(r,"lookAt",(function(){return Oe})),n.d(r,"targetTo",(function(){return ke})),n.d(r,"str",(function(){return Ee})),n.d(r,"frob",(function(){return Te})),n.d(r,"add",(function(){return Me})),n.d(r,"subtract",(function(){return De})),n.d(r,"multiplyScalar",(function(){return Le})),n.d(r,"multiplyScalarAndAdd",(function(){return je})),n.d(r,"exactEquals",(function(){return Ie})),n.d(r,"equals",(function(){return Pe})),n.d(r,"mul",(function(){return Ae})),n.d(r,"sub",(function(){return Re}));var s={};n.r(s),n.d(s,"create",(function(){return Ne})),n.d(s,"clone",(function(){return Ve})),n.d(s,"length",(function(){return _e})),n.d(s,"fromValues",(function(){return Be})),n.d(s,"copy",(function(){return Fe})),n.d(s,"set",(function(){return ze})),n.d(s,"add",(function(){return Ue})),n.d(s,"subtract",(function(){return Ge})),n.d(s,"multiply",(function(){return $e})),n.d(s,"divide",(function(){return We})),n.d(s,"ceil",(function(){return He})),n.d(s,"floor",(function(){return Je})),n.d(s,"min",(function(){return qe})),n.d(s,"max",(function(){return Ye})),n.d(s,"round",(function(){return Xe})),n.d(s,"scale",(function(){return Ke})),n.d(s,"scaleAndAdd",(function(){return Qe})),n.d(s,"distance",(function(){return Ze})),n.d(s,"squaredDistance",(function(){return et})),n.d(s,"squaredLength",(function(){return tt})),n.d(s,"negate",(function(){return nt})),n.d(s,"inverse",(function(){return it})),n.d(s,"normalize",(function(){return rt})),n.d(s,"dot",(function(){return st})),n.d(s,"cross",(function(){return ot})),n.d(s,"lerp",(function(){return at})),n.d(s,"hermite",(function(){return ct})),n.d(s,"bezier",(function(){return lt})),n.d(s,"random",(function(){return dt})),n.d(s,"transformMat4",(function(){return ut})),n.d(s,"transformMat3",(function(){return ht})),n.d(s,"transformQuat",(function(){return pt})),n.d(s,"rotateX",(function(){return ft})),n.d(s,"rotateY",(function(){return mt})),n.d(s,"rotateZ",(function(){return gt})),n.d(s,"angle",(function(){return vt})),n.d(s,"zero",(function(){return bt})),n.d(s,"str",(function(){return yt})),n.d(s,"exactEquals",(function(){return St})),n.d(s,"equals",(function(){return wt})),n.d(s,"sub",(function(){return Ct})),n.d(s,"mul",(function(){return Ot})),n.d(s,"div",(function(){return kt})),n.d(s,"dist",(function(){return Et})),n.d(s,"sqrDist",(function(){return Tt})),n.d(s,"len",(function(){return Mt})),n.d(s,"sqrLen",(function(){return Dt})),n.d(s,"forEach",(function(){return Lt}));var o={};n.r(o),n.d(o,"create",(function(){return jt})),n.d(o,"clone",(function(){return It})),n.d(o,"fromValues",(function(){return Pt})),n.d(o,"copy",(function(){return At})),n.d(o,"set",(function(){return Rt})),n.d(o,"add",(function(){return Nt})),n.d(o,"subtract",(function(){return Vt})),n.d(o,"multiply",(function(){return _t})),n.d(o,"divide",(function(){return Bt})),n.d(o,"ceil",(function(){return Ft})),n.d(o,"floor",(function(){return zt})),n.d(o,"min",(function(){return Ut})),n.d(o,"max",(function(){return Gt})),n.d(o,"round",(function(){return $t})),n.d(o,"scale",(function(){return Wt})),n.d(o,"scaleAndAdd",(function(){return Ht})),n.d(o,"distance",(function(){return Jt})),n.d(o,"squaredDistance",(function(){return qt})),n.d(o,"length",(function(){return Yt})),n.d(o,"squaredLength",(function(){return Xt})),n.d(o,"negate",(function(){return Kt})),n.d(o,"inverse",(function(){return Qt})),n.d(o,"normalize",(function(){return Zt})),n.d(o,"dot",(function(){return en})),n.d(o,"cross",(function(){return tn})),n.d(o,"lerp",(function(){return nn})),n.d(o,"random",(function(){return rn})),n.d(o,"transformMat4",(function(){return sn})),n.d(o,"transformQuat",(function(){return on})),n.d(o,"zero",(function(){return an})),n.d(o,"str",(function(){return cn})),n.d(o,"exactEquals",(function(){return ln})),n.d(o,"equals",(function(){return dn})),n.d(o,"sub",(function(){return un})),n.d(o,"mul",(function(){return hn})),n.d(o,"div",(function(){return pn})),n.d(o,"dist",(function(){return fn})),n.d(o,"sqrDist",(function(){return mn})),n.d(o,"len",(function(){return gn})),n.d(o,"sqrLen",(function(){return vn})),n.d(o,"forEach",(function(){return bn}));var a={};n.r(a),n.d(a,"create",(function(){return yn})),n.d(a,"identity",(function(){return Sn})),n.d(a,"setAxisAngle",(function(){return wn})),n.d(a,"getAxisAngle",(function(){return xn})),n.d(a,"getAngle",(function(){return Cn})),n.d(a,"multiply",(function(){return On})),n.d(a,"rotateX",(function(){return kn})),n.d(a,"rotateY",(function(){return En})),n.d(a,"rotateZ",(function(){return Tn})),n.d(a,"calculateW",(function(){return Mn})),n.d(a,"exp",(function(){return Dn})),n.d(a,"ln",(function(){return Ln})),n.d(a,"pow",(function(){return jn})),n.d(a,"slerp",(function(){return In})),n.d(a,"random",(function(){return Pn})),n.d(a,"invert",(function(){return An})),n.d(a,"conjugate",(function(){return Rn})),n.d(a,"fromMat3",(function(){return Nn})),n.d(a,"fromEuler",(function(){return Vn})),n.d(a,"str",(function(){return _n})),n.d(a,"clone",(function(){return Wn})),n.d(a,"fromValues",(function(){return Hn})),n.d(a,"copy",(function(){return Jn})),n.d(a,"set",(function(){return qn})),n.d(a,"add",(function(){return Yn})),n.d(a,"mul",(function(){return Xn})),n.d(a,"scale",(function(){return Kn})),n.d(a,"dot",(function(){return Qn})),n.d(a,"lerp",(function(){return Zn})),n.d(a,"length",(function(){return ei})),n.d(a,"len",(function(){return ti})),n.d(a,"squaredLength",(function(){return ni})),n.d(a,"sqrLen",(function(){return ii})),n.d(a,"normalize",(function(){return ri})),n.d(a,"exactEquals",(function(){return si})),n.d(a,"equals",(function(){return oi})),n.d(a,"rotationTo",(function(){return ai})),n.d(a,"sqlerp",(function(){return ci})),n.d(a,"setAxes",(function(){return li}));var c={};n.r(c),n.d(c,"create",(function(){return di})),n.d(c,"clone",(function(){return ui})),n.d(c,"fromValues",(function(){return hi})),n.d(c,"copy",(function(){return pi})),n.d(c,"set",(function(){return fi})),n.d(c,"add",(function(){return mi})),n.d(c,"subtract",(function(){return gi})),n.d(c,"multiply",(function(){return vi})),n.d(c,"divide",(function(){return bi})),n.d(c,"ceil",(function(){return yi})),n.d(c,"floor",(function(){return Si})),n.d(c,"min",(function(){return wi})),n.d(c,"max",(function(){return xi})),n.d(c,"round",(function(){return Ci})),n.d(c,"scale",(function(){return Oi})),n.d(c,"scaleAndAdd",(function(){return ki})),n.d(c,"distance",(function(){return Ei})),n.d(c,"squaredDistance",(function(){return Ti})),n.d(c,"length",(function(){return Mi})),n.d(c,"squaredLength",(function(){return Di})),n.d(c,"negate",(function(){return Li})),n.d(c,"inverse",(function(){return ji})),n.d(c,"normalize",(function(){return Ii})),n.d(c,"dot",(function(){return Pi})),n.d(c,"cross",(function(){return Ai})),n.d(c,"lerp",(function(){return Ri})),n.d(c,"random",(function(){return Ni})),n.d(c,"transformMat2",(function(){return Vi})),n.d(c,"transformMat2d",(function(){return _i})),n.d(c,"transformMat3",(function(){return Bi})),n.d(c,"transformMat4",(function(){return Fi})),n.d(c,"rotate",(function(){return zi})),n.d(c,"angle",(function(){return Ui})),n.d(c,"zero",(function(){return Gi})),n.d(c,"str",(function(){return $i})),n.d(c,"exactEquals",(function(){return Wi})),n.d(c,"equals",(function(){return Hi})),n.d(c,"len",(function(){return Ji})),n.d(c,"sub",(function(){return qi})),n.d(c,"mul",(function(){return Yi})),n.d(c,"div",(function(){return Xi})),n.d(c,"dist",(function(){return Ki})),n.d(c,"sqrDist",(function(){return Qi})),n.d(c,"sqrLen",(function(){return Zi})),n.d(c,"forEach",(function(){return er}));var l="undefined"!=typeof Float32Array?Float32Array:Array,d=Math.random;Math.PI;function u(){var e=new l(9);return l!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function h(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}function p(e){var t=new l(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function f(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function m(e,t,n,i,r,s,o,a,c){var d=new l(9);return d[0]=e,d[1]=t,d[2]=n,d[3]=i,d[4]=r,d[5]=s,d[6]=o,d[7]=a,d[8]=c,d}function g(e,t,n,i,r,s,o,a,c,l){return e[0]=t,e[1]=n,e[2]=i,e[3]=r,e[4]=s,e[5]=o,e[6]=a,e[7]=c,e[8]=l,e}function v(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function b(e,t){if(e===t){var n=t[1],i=t[2],r=t[5];e[1]=t[3],e[2]=t[6],e[3]=n,e[5]=t[7],e[6]=i,e[7]=r}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e}function y(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=d*o-a*l,h=-d*s+a*c,p=l*s-o*c,f=n*u+i*h+r*p;return f?(f=1/f,e[0]=u*f,e[1]=(-d*i+r*l)*f,e[2]=(a*i-r*o)*f,e[3]=h*f,e[4]=(d*n-r*c)*f,e[5]=(-a*n+r*s)*f,e[6]=p*f,e[7]=(-l*n+i*c)*f,e[8]=(o*n-i*s)*f,e):null}function S(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8];return e[0]=o*d-a*l,e[1]=r*l-i*d,e[2]=i*a-r*o,e[3]=a*c-s*d,e[4]=n*d-r*c,e[5]=r*s-n*a,e[6]=s*l-o*c,e[7]=i*c-n*l,e[8]=n*o-i*s,e}function w(e){var t=e[0],n=e[1],i=e[2],r=e[3],s=e[4],o=e[5],a=e[6],c=e[7],l=e[8];return t*(l*s-o*c)+n*(-l*r+o*a)+i*(c*r-s*a)}function x(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=n[0],p=n[1],f=n[2],m=n[3],g=n[4],v=n[5],b=n[6],y=n[7],S=n[8];return e[0]=h*i+p*o+f*l,e[1]=h*r+p*a+f*d,e[2]=h*s+p*c+f*u,e[3]=m*i+g*o+v*l,e[4]=m*r+g*a+v*d,e[5]=m*s+g*c+v*u,e[6]=b*i+y*o+S*l,e[7]=b*r+y*a+S*d,e[8]=b*s+y*c+S*u,e}function C(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=n[0],p=n[1];return e[0]=i,e[1]=r,e[2]=s,e[3]=o,e[4]=a,e[5]=c,e[6]=h*i+p*o+l,e[7]=h*r+p*a+d,e[8]=h*s+p*c+u,e}function O(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=Math.sin(n),p=Math.cos(n);return e[0]=p*i+h*o,e[1]=p*r+h*a,e[2]=p*s+h*c,e[3]=p*o-h*i,e[4]=p*a-h*r,e[5]=p*c-h*s,e[6]=l,e[7]=d,e[8]=u,e}function k(e,t,n){var i=n[0],r=n[1];return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=r*t[3],e[4]=r*t[4],e[5]=r*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function E(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=t[0],e[7]=t[1],e[8]=1,e}function T(e,t){var n=Math.sin(t),i=Math.cos(t);return e[0]=i,e[1]=n,e[2]=0,e[3]=-n,e[4]=i,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function M(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=t[1],e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function D(e,t){return e[0]=t[0],e[1]=t[1],e[2]=0,e[3]=t[2],e[4]=t[3],e[5]=0,e[6]=t[4],e[7]=t[5],e[8]=1,e}function L(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=n+n,a=i+i,c=r+r,l=n*o,d=i*o,u=i*a,h=r*o,p=r*a,f=r*c,m=s*o,g=s*a,v=s*c;return e[0]=1-u-f,e[3]=d-v,e[6]=h+g,e[1]=d+v,e[4]=1-l-f,e[7]=p-m,e[2]=h-g,e[5]=p+m,e[8]=1-l-u,e}function j(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],b=n*a-i*o,y=n*c-r*o,S=n*l-s*o,w=i*c-r*a,x=i*l-s*a,C=r*l-s*c,O=d*m-u*f,k=d*g-h*f,E=d*v-p*f,T=u*g-h*m,M=u*v-p*m,D=h*v-p*g,L=b*D-y*M+S*T+w*E-x*k+C*O;return L?(L=1/L,e[0]=(a*D-c*M+l*T)*L,e[1]=(c*E-o*D-l*k)*L,e[2]=(o*M-a*E+l*O)*L,e[3]=(r*M-i*D-s*T)*L,e[4]=(n*D-r*E+s*k)*L,e[5]=(i*E-n*M-s*O)*L,e[6]=(m*C-g*x+v*w)*L,e[7]=(g*S-f*C-v*y)*L,e[8]=(f*x-m*S+v*b)*L,e):null}function I(e,t,n){return e[0]=2/t,e[1]=0,e[2]=0,e[3]=0,e[4]=-2/n,e[5]=0,e[6]=-1,e[7]=1,e[8]=1,e}function P(e){return"mat3("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+")"}function A(e){return Math.hypot(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])}function R(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e}function N(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e}function V(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*n,e}function _(e,t,n,i){return e[0]=t[0]+n[0]*i,e[1]=t[1]+n[1]*i,e[2]=t[2]+n[2]*i,e[3]=t[3]+n[3]*i,e[4]=t[4]+n[4]*i,e[5]=t[5]+n[5]*i,e[6]=t[6]+n[6]*i,e[7]=t[7]+n[7]*i,e[8]=t[8]+n[8]*i,e}function B(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]}function F(e,t){var n=e[0],i=e[1],r=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=t[0],h=t[1],p=t[2],f=t[3],m=t[4],g=t[5],v=t[6],b=t[7],y=t[8];return Math.abs(n-u)<=1e-6*Math.max(1,Math.abs(n),Math.abs(u))&&Math.abs(i-h)<=1e-6*Math.max(1,Math.abs(i),Math.abs(h))&&Math.abs(r-p)<=1e-6*Math.max(1,Math.abs(r),Math.abs(p))&&Math.abs(s-f)<=1e-6*Math.max(1,Math.abs(s),Math.abs(f))&&Math.abs(o-m)<=1e-6*Math.max(1,Math.abs(o),Math.abs(m))&&Math.abs(a-g)<=1e-6*Math.max(1,Math.abs(a),Math.abs(g))&&Math.abs(c-v)<=1e-6*Math.max(1,Math.abs(c),Math.abs(v))&&Math.abs(l-b)<=1e-6*Math.max(1,Math.abs(l),Math.abs(b))&&Math.abs(d-y)<=1e-6*Math.max(1,Math.abs(d),Math.abs(y))}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});var z=x,U=N;function G(){var e=new l(16);return l!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function $(e){var t=new l(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function W(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function H(e,t,n,i,r,s,o,a,c,d,u,h,p,f,m,g){var v=new l(16);return v[0]=e,v[1]=t,v[2]=n,v[3]=i,v[4]=r,v[5]=s,v[6]=o,v[7]=a,v[8]=c,v[9]=d,v[10]=u,v[11]=h,v[12]=p,v[13]=f,v[14]=m,v[15]=g,v}function J(e,t,n,i,r,s,o,a,c,l,d,u,h,p,f,m,g){return e[0]=t,e[1]=n,e[2]=i,e[3]=r,e[4]=s,e[5]=o,e[6]=a,e[7]=c,e[8]=l,e[9]=d,e[10]=u,e[11]=h,e[12]=p,e[13]=f,e[14]=m,e[15]=g,e}function q(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Y(e,t){if(e===t){var n=t[1],i=t[2],r=t[3],s=t[6],o=t[7],a=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=i,e[9]=s,e[11]=t[14],e[12]=r,e[13]=o,e[14]=a}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function X(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15],b=n*a-i*o,y=n*c-r*o,S=n*l-s*o,w=i*c-r*a,x=i*l-s*a,C=r*l-s*c,O=d*m-u*f,k=d*g-h*f,E=d*v-p*f,T=u*g-h*m,M=u*v-p*m,D=h*v-p*g,L=b*D-y*M+S*T+w*E-x*k+C*O;return L?(L=1/L,e[0]=(a*D-c*M+l*T)*L,e[1]=(r*M-i*D-s*T)*L,e[2]=(m*C-g*x+v*w)*L,e[3]=(h*x-u*C-p*w)*L,e[4]=(c*E-o*D-l*k)*L,e[5]=(n*D-r*E+s*k)*L,e[6]=(g*S-f*C-v*y)*L,e[7]=(d*C-h*S+p*y)*L,e[8]=(o*M-a*E+l*O)*L,e[9]=(i*E-n*M-s*O)*L,e[10]=(f*x-m*S+v*b)*L,e[11]=(u*S-d*x-p*b)*L,e[12]=(a*k-o*T-c*O)*L,e[13]=(n*T-i*k+r*O)*L,e[14]=(m*y-f*w-g*b)*L,e[15]=(d*w-u*y+h*b)*L,e):null}function K(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15];return e[0]=a*(h*v-p*g)-u*(c*v-l*g)+m*(c*p-l*h),e[1]=-(i*(h*v-p*g)-u*(r*v-s*g)+m*(r*p-s*h)),e[2]=i*(c*v-l*g)-a*(r*v-s*g)+m*(r*l-s*c),e[3]=-(i*(c*p-l*h)-a*(r*p-s*h)+u*(r*l-s*c)),e[4]=-(o*(h*v-p*g)-d*(c*v-l*g)+f*(c*p-l*h)),e[5]=n*(h*v-p*g)-d*(r*v-s*g)+f*(r*p-s*h),e[6]=-(n*(c*v-l*g)-o*(r*v-s*g)+f*(r*l-s*c)),e[7]=n*(c*p-l*h)-o*(r*p-s*h)+d*(r*l-s*c),e[8]=o*(u*v-p*m)-d*(a*v-l*m)+f*(a*p-l*u),e[9]=-(n*(u*v-p*m)-d*(i*v-s*m)+f*(i*p-s*u)),e[10]=n*(a*v-l*m)-o*(i*v-s*m)+f*(i*l-s*a),e[11]=-(n*(a*p-l*u)-o*(i*p-s*u)+d*(i*l-s*a)),e[12]=-(o*(u*g-h*m)-d*(a*g-c*m)+f*(a*h-c*u)),e[13]=n*(u*g-h*m)-d*(i*g-r*m)+f*(i*h-r*u),e[14]=-(n*(a*g-c*m)-o*(i*g-r*m)+f*(i*c-r*a)),e[15]=n*(a*h-c*u)-o*(i*h-r*u)+d*(i*c-r*a),e}function Q(e){var t=e[0],n=e[1],i=e[2],r=e[3],s=e[4],o=e[5],a=e[6],c=e[7],l=e[8],d=e[9],u=e[10],h=e[11],p=e[12],f=e[13],m=e[14],g=e[15];return(t*o-n*s)*(u*g-h*m)-(t*a-i*s)*(d*g-h*f)+(t*c-r*s)*(d*m-u*f)+(n*a-i*o)*(l*g-h*p)-(n*c-r*o)*(l*m-u*p)+(i*c-r*a)*(l*f-d*p)}function Z(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=t[9],p=t[10],f=t[11],m=t[12],g=t[13],v=t[14],b=t[15],y=n[0],S=n[1],w=n[2],x=n[3];return e[0]=y*i+S*a+w*u+x*m,e[1]=y*r+S*c+w*h+x*g,e[2]=y*s+S*l+w*p+x*v,e[3]=y*o+S*d+w*f+x*b,y=n[4],S=n[5],w=n[6],x=n[7],e[4]=y*i+S*a+w*u+x*m,e[5]=y*r+S*c+w*h+x*g,e[6]=y*s+S*l+w*p+x*v,e[7]=y*o+S*d+w*f+x*b,y=n[8],S=n[9],w=n[10],x=n[11],e[8]=y*i+S*a+w*u+x*m,e[9]=y*r+S*c+w*h+x*g,e[10]=y*s+S*l+w*p+x*v,e[11]=y*o+S*d+w*f+x*b,y=n[12],S=n[13],w=n[14],x=n[15],e[12]=y*i+S*a+w*u+x*m,e[13]=y*r+S*c+w*h+x*g,e[14]=y*s+S*l+w*p+x*v,e[15]=y*o+S*d+w*f+x*b,e}function ee(e,t,n){var i,r,s,o,a,c,l,d,u,h,p,f,m=n[0],g=n[1],v=n[2];return t===e?(e[12]=t[0]*m+t[4]*g+t[8]*v+t[12],e[13]=t[1]*m+t[5]*g+t[9]*v+t[13],e[14]=t[2]*m+t[6]*g+t[10]*v+t[14],e[15]=t[3]*m+t[7]*g+t[11]*v+t[15]):(i=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],l=t[6],d=t[7],u=t[8],h=t[9],p=t[10],f=t[11],e[0]=i,e[1]=r,e[2]=s,e[3]=o,e[4]=a,e[5]=c,e[6]=l,e[7]=d,e[8]=u,e[9]=h,e[10]=p,e[11]=f,e[12]=i*m+a*g+u*v+t[12],e[13]=r*m+c*g+h*v+t[13],e[14]=s*m+l*g+p*v+t[14],e[15]=o*m+d*g+f*v+t[15]),e}function te(e,t,n){var i=n[0],r=n[1],s=n[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*r,e[5]=t[5]*r,e[6]=t[6]*r,e[7]=t[7]*r,e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11]*s,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ne(e,t,n,i){var r,s,o,a,c,l,d,u,h,p,f,m,g,v,b,y,S,w,x,C,O,k,E,T,M=i[0],D=i[1],L=i[2],j=Math.hypot(M,D,L);return j<1e-6?null:(M*=j=1/j,D*=j,L*=j,r=Math.sin(n),o=1-(s=Math.cos(n)),a=t[0],c=t[1],l=t[2],d=t[3],u=t[4],h=t[5],p=t[6],f=t[7],m=t[8],g=t[9],v=t[10],b=t[11],y=M*M*o+s,S=D*M*o+L*r,w=L*M*o-D*r,x=M*D*o-L*r,C=D*D*o+s,O=L*D*o+M*r,k=M*L*o+D*r,E=D*L*o-M*r,T=L*L*o+s,e[0]=a*y+u*S+m*w,e[1]=c*y+h*S+g*w,e[2]=l*y+p*S+v*w,e[3]=d*y+f*S+b*w,e[4]=a*x+u*C+m*O,e[5]=c*x+h*C+g*O,e[6]=l*x+p*C+v*O,e[7]=d*x+f*C+b*O,e[8]=a*k+u*E+m*T,e[9]=c*k+h*E+g*T,e[10]=l*k+p*E+v*T,e[11]=d*k+f*E+b*T,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function ie(e,t,n){var i=Math.sin(n),r=Math.cos(n),s=t[4],o=t[5],a=t[6],c=t[7],l=t[8],d=t[9],u=t[10],h=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=s*r+l*i,e[5]=o*r+d*i,e[6]=a*r+u*i,e[7]=c*r+h*i,e[8]=l*r-s*i,e[9]=d*r-o*i,e[10]=u*r-a*i,e[11]=h*r-c*i,e}function re(e,t,n){var i=Math.sin(n),r=Math.cos(n),s=t[0],o=t[1],a=t[2],c=t[3],l=t[8],d=t[9],u=t[10],h=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=s*r-l*i,e[1]=o*r-d*i,e[2]=a*r-u*i,e[3]=c*r-h*i,e[8]=s*i+l*r,e[9]=o*i+d*r,e[10]=a*i+u*r,e[11]=c*i+h*r,e}function se(e,t,n){var i=Math.sin(n),r=Math.cos(n),s=t[0],o=t[1],a=t[2],c=t[3],l=t[4],d=t[5],u=t[6],h=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=s*r+l*i,e[1]=o*r+d*i,e[2]=a*r+u*i,e[3]=c*r+h*i,e[4]=l*r-s*i,e[5]=d*r-o*i,e[6]=u*r-a*i,e[7]=h*r-c*i,e}function oe(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function ae(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ce(e,t,n){var i,r,s,o=n[0],a=n[1],c=n[2],l=Math.hypot(o,a,c);return l<1e-6?null:(o*=l=1/l,a*=l,c*=l,i=Math.sin(t),s=1-(r=Math.cos(t)),e[0]=o*o*s+r,e[1]=a*o*s+c*i,e[2]=c*o*s-a*i,e[3]=0,e[4]=o*a*s-c*i,e[5]=a*a*s+r,e[6]=c*a*s+o*i,e[7]=0,e[8]=o*c*s+a*i,e[9]=a*c*s-o*i,e[10]=c*c*s+r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)}function le(e,t){var n=Math.sin(t),i=Math.cos(t);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=n,e[7]=0,e[8]=0,e[9]=-n,e[10]=i,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function de(e,t){var n=Math.sin(t),i=Math.cos(t);return e[0]=i,e[1]=0,e[2]=-n,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=n,e[9]=0,e[10]=i,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ue(e,t){var n=Math.sin(t),i=Math.cos(t);return e[0]=i,e[1]=n,e[2]=0,e[3]=0,e[4]=-n,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function he(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=i+i,c=r+r,l=s+s,d=i*a,u=i*c,h=i*l,p=r*c,f=r*l,m=s*l,g=o*a,v=o*c,b=o*l;return e[0]=1-(p+m),e[1]=u+b,e[2]=h-v,e[3]=0,e[4]=u-b,e[5]=1-(d+m),e[6]=f+g,e[7]=0,e[8]=h+v,e[9]=f-g,e[10]=1-(d+p),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function pe(e,t){var n=new l(3),i=-t[0],r=-t[1],s=-t[2],o=t[3],a=t[4],c=t[5],d=t[6],u=t[7],h=i*i+r*r+s*s+o*o;return h>0?(n[0]=2*(a*o+u*i+c*s-d*r)/h,n[1]=2*(c*o+u*r+d*i-a*s)/h,n[2]=2*(d*o+u*s+a*r-c*i)/h):(n[0]=2*(a*o+u*i+c*s-d*r),n[1]=2*(c*o+u*r+d*i-a*s),n[2]=2*(d*o+u*s+a*r-c*i)),he(e,t,n),e}function fe(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function me(e,t){var n=t[0],i=t[1],r=t[2],s=t[4],o=t[5],a=t[6],c=t[8],l=t[9],d=t[10];return e[0]=Math.hypot(n,i,r),e[1]=Math.hypot(s,o,a),e[2]=Math.hypot(c,l,d),e}function ge(e,t){var n=new l(3);me(n,t);var i=1/n[0],r=1/n[1],s=1/n[2],o=t[0]*i,a=t[1]*r,c=t[2]*s,d=t[4]*i,u=t[5]*r,h=t[6]*s,p=t[8]*i,f=t[9]*r,m=t[10]*s,g=o+u+m,v=0;return g>0?(v=2*Math.sqrt(g+1),e[3]=.25*v,e[0]=(h-f)/v,e[1]=(p-c)/v,e[2]=(a-d)/v):o>u&&o>m?(v=2*Math.sqrt(1+o-u-m),e[3]=(h-f)/v,e[0]=.25*v,e[1]=(a+d)/v,e[2]=(p+c)/v):u>m?(v=2*Math.sqrt(1+u-o-m),e[3]=(p-c)/v,e[0]=(a+d)/v,e[1]=.25*v,e[2]=(h+f)/v):(v=2*Math.sqrt(1+m-o-u),e[3]=(a-d)/v,e[0]=(p+c)/v,e[1]=(h+f)/v,e[2]=.25*v),e}function ve(e,t,n,i){var r=t[0],s=t[1],o=t[2],a=t[3],c=r+r,l=s+s,d=o+o,u=r*c,h=r*l,p=r*d,f=s*l,m=s*d,g=o*d,v=a*c,b=a*l,y=a*d,S=i[0],w=i[1],x=i[2];return e[0]=(1-(f+g))*S,e[1]=(h+y)*S,e[2]=(p-b)*S,e[3]=0,e[4]=(h-y)*w,e[5]=(1-(u+g))*w,e[6]=(m+v)*w,e[7]=0,e[8]=(p+b)*x,e[9]=(m-v)*x,e[10]=(1-(u+f))*x,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function be(e,t,n,i,r){var s=t[0],o=t[1],a=t[2],c=t[3],l=s+s,d=o+o,u=a+a,h=s*l,p=s*d,f=s*u,m=o*d,g=o*u,v=a*u,b=c*l,y=c*d,S=c*u,w=i[0],x=i[1],C=i[2],O=r[0],k=r[1],E=r[2],T=(1-(m+v))*w,M=(p+S)*w,D=(f-y)*w,L=(p-S)*x,j=(1-(h+v))*x,I=(g+b)*x,P=(f+y)*C,A=(g-b)*C,R=(1-(h+m))*C;return e[0]=T,e[1]=M,e[2]=D,e[3]=0,e[4]=L,e[5]=j,e[6]=I,e[7]=0,e[8]=P,e[9]=A,e[10]=R,e[11]=0,e[12]=n[0]+O-(T*O+L*k+P*E),e[13]=n[1]+k-(M*O+j*k+A*E),e[14]=n[2]+E-(D*O+I*k+R*E),e[15]=1,e}function ye(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=n+n,a=i+i,c=r+r,l=n*o,d=i*o,u=i*a,h=r*o,p=r*a,f=r*c,m=s*o,g=s*a,v=s*c;return e[0]=1-u-f,e[1]=d+v,e[2]=h-g,e[3]=0,e[4]=d-v,e[5]=1-l-f,e[6]=p+m,e[7]=0,e[8]=h+g,e[9]=p-m,e[10]=1-l-u,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Se(e,t,n,i,r,s,o){var a=1/(n-t),c=1/(r-i),l=1/(s-o);return e[0]=2*s*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=2*s*c,e[6]=0,e[7]=0,e[8]=(n+t)*a,e[9]=(r+i)*c,e[10]=(o+s)*l,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*s*2*l,e[15]=0,e}function we(e,t,n,i,r){var s,o=1/Math.tan(t/2);return e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,null!=r&&r!==1/0?(s=1/(i-r),e[10]=(r+i)*s,e[14]=2*r*i*s):(e[10]=-1,e[14]=-2*i),e}function xe(e,t,n,i){var r=Math.tan(t.upDegrees*Math.PI/180),s=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),a=Math.tan(t.rightDegrees*Math.PI/180),c=2/(o+a),l=2/(r+s);return e[0]=c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=l,e[6]=0,e[7]=0,e[8]=-(o-a)*c*.5,e[9]=(r-s)*l*.5,e[10]=i/(n-i),e[11]=-1,e[12]=0,e[13]=0,e[14]=i*n/(n-i),e[15]=0,e}function Ce(e,t,n,i,r,s,o){var a=1/(t-n),c=1/(i-r),l=1/(s-o);return e[0]=-2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*a,e[13]=(r+i)*c,e[14]=(o+s)*l,e[15]=1,e}function Oe(e,t,n,i){var r,s,o,a,c,l,d,u,h,p,f=t[0],m=t[1],g=t[2],v=i[0],b=i[1],y=i[2],S=n[0],w=n[1],x=n[2];return Math.abs(f-S)<1e-6&&Math.abs(m-w)<1e-6&&Math.abs(g-x)<1e-6?q(e):(d=f-S,u=m-w,h=g-x,r=b*(h*=p=1/Math.hypot(d,u,h))-y*(u*=p),s=y*(d*=p)-v*h,o=v*u-b*d,(p=Math.hypot(r,s,o))?(r*=p=1/p,s*=p,o*=p):(r=0,s=0,o=0),a=u*o-h*s,c=h*r-d*o,l=d*s-u*r,(p=Math.hypot(a,c,l))?(a*=p=1/p,c*=p,l*=p):(a=0,c=0,l=0),e[0]=r,e[1]=a,e[2]=d,e[3]=0,e[4]=s,e[5]=c,e[6]=u,e[7]=0,e[8]=o,e[9]=l,e[10]=h,e[11]=0,e[12]=-(r*f+s*m+o*g),e[13]=-(a*f+c*m+l*g),e[14]=-(d*f+u*m+h*g),e[15]=1,e)}function ke(e,t,n,i){var r=t[0],s=t[1],o=t[2],a=i[0],c=i[1],l=i[2],d=r-n[0],u=s-n[1],h=o-n[2],p=d*d+u*u+h*h;p>0&&(d*=p=1/Math.sqrt(p),u*=p,h*=p);var f=c*h-l*u,m=l*d-a*h,g=a*u-c*d;return(p=f*f+m*m+g*g)>0&&(f*=p=1/Math.sqrt(p),m*=p,g*=p),e[0]=f,e[1]=m,e[2]=g,e[3]=0,e[4]=u*g-h*m,e[5]=h*f-d*g,e[6]=d*m-u*f,e[7]=0,e[8]=d,e[9]=u,e[10]=h,e[11]=0,e[12]=r,e[13]=s,e[14]=o,e[15]=1,e}function Ee(e){return"mat4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+")"}function Te(e){return Math.hypot(e[0],e[1],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15])}function Me(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e[9]=t[9]+n[9],e[10]=t[10]+n[10],e[11]=t[11]+n[11],e[12]=t[12]+n[12],e[13]=t[13]+n[13],e[14]=t[14]+n[14],e[15]=t[15]+n[15],e}function De(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e[9]=t[9]-n[9],e[10]=t[10]-n[10],e[11]=t[11]-n[11],e[12]=t[12]-n[12],e[13]=t[13]-n[13],e[14]=t[14]-n[14],e[15]=t[15]-n[15],e}function Le(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*n,e[9]=t[9]*n,e[10]=t[10]*n,e[11]=t[11]*n,e[12]=t[12]*n,e[13]=t[13]*n,e[14]=t[14]*n,e[15]=t[15]*n,e}function je(e,t,n,i){return e[0]=t[0]+n[0]*i,e[1]=t[1]+n[1]*i,e[2]=t[2]+n[2]*i,e[3]=t[3]+n[3]*i,e[4]=t[4]+n[4]*i,e[5]=t[5]+n[5]*i,e[6]=t[6]+n[6]*i,e[7]=t[7]+n[7]*i,e[8]=t[8]+n[8]*i,e[9]=t[9]+n[9]*i,e[10]=t[10]+n[10]*i,e[11]=t[11]+n[11]*i,e[12]=t[12]+n[12]*i,e[13]=t[13]+n[13]*i,e[14]=t[14]+n[14]*i,e[15]=t[15]+n[15]*i,e}function Ie(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]}function Pe(e,t){var n=e[0],i=e[1],r=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],h=e[10],p=e[11],f=e[12],m=e[13],g=e[14],v=e[15],b=t[0],y=t[1],S=t[2],w=t[3],x=t[4],C=t[5],O=t[6],k=t[7],E=t[8],T=t[9],M=t[10],D=t[11],L=t[12],j=t[13],I=t[14],P=t[15];return Math.abs(n-b)<=1e-6*Math.max(1,Math.abs(n),Math.abs(b))&&Math.abs(i-y)<=1e-6*Math.max(1,Math.abs(i),Math.abs(y))&&Math.abs(r-S)<=1e-6*Math.max(1,Math.abs(r),Math.abs(S))&&Math.abs(s-w)<=1e-6*Math.max(1,Math.abs(s),Math.abs(w))&&Math.abs(o-x)<=1e-6*Math.max(1,Math.abs(o),Math.abs(x))&&Math.abs(a-C)<=1e-6*Math.max(1,Math.abs(a),Math.abs(C))&&Math.abs(c-O)<=1e-6*Math.max(1,Math.abs(c),Math.abs(O))&&Math.abs(l-k)<=1e-6*Math.max(1,Math.abs(l),Math.abs(k))&&Math.abs(d-E)<=1e-6*Math.max(1,Math.abs(d),Math.abs(E))&&Math.abs(u-T)<=1e-6*Math.max(1,Math.abs(u),Math.abs(T))&&Math.abs(h-M)<=1e-6*Math.max(1,Math.abs(h),Math.abs(M))&&Math.abs(p-D)<=1e-6*Math.max(1,Math.abs(p),Math.abs(D))&&Math.abs(f-L)<=1e-6*Math.max(1,Math.abs(f),Math.abs(L))&&Math.abs(m-j)<=1e-6*Math.max(1,Math.abs(m),Math.abs(j))&&Math.abs(g-I)<=1e-6*Math.max(1,Math.abs(g),Math.abs(I))&&Math.abs(v-P)<=1e-6*Math.max(1,Math.abs(v),Math.abs(P))}var Ae=Z,Re=De;function Ne(){var e=new l(3);return l!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Ve(e){var t=new l(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function _e(e){var t=e[0],n=e[1],i=e[2];return Math.hypot(t,n,i)}function Be(e,t,n){var i=new l(3);return i[0]=e,i[1]=t,i[2]=n,i}function Fe(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function ze(e,t,n,i){return e[0]=t,e[1]=n,e[2]=i,e}function Ue(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e}function Ge(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e}function $e(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e}function We(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e}function He(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e}function Je(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e}function qe(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e}function Ye(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e}function Xe(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e}function Ke(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e}function Qe(e,t,n,i){return e[0]=t[0]+n[0]*i,e[1]=t[1]+n[1]*i,e[2]=t[2]+n[2]*i,e}function Ze(e,t){var n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2];return Math.hypot(n,i,r)}function et(e,t){var n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2];return n*n+i*i+r*r}function tt(e){var t=e[0],n=e[1],i=e[2];return t*t+n*n+i*i}function nt(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e}function it(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function rt(e,t){var n=t[0],i=t[1],r=t[2],s=n*n+i*i+r*r;return s>0&&(s=1/Math.sqrt(s)),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function st(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function ot(e,t,n){var i=t[0],r=t[1],s=t[2],o=n[0],a=n[1],c=n[2];return e[0]=r*c-s*a,e[1]=s*o-i*c,e[2]=i*a-r*o,e}function at(e,t,n,i){var r=t[0],s=t[1],o=t[2];return e[0]=r+i*(n[0]-r),e[1]=s+i*(n[1]-s),e[2]=o+i*(n[2]-o),e}function ct(e,t,n,i,r,s){var o=s*s,a=o*(2*s-3)+1,c=o*(s-2)+s,l=o*(s-1),d=o*(3-2*s);return e[0]=t[0]*a+n[0]*c+i[0]*l+r[0]*d,e[1]=t[1]*a+n[1]*c+i[1]*l+r[1]*d,e[2]=t[2]*a+n[2]*c+i[2]*l+r[2]*d,e}function lt(e,t,n,i,r,s){var o=1-s,a=o*o,c=s*s,l=a*o,d=3*s*a,u=3*c*o,h=c*s;return e[0]=t[0]*l+n[0]*d+i[0]*u+r[0]*h,e[1]=t[1]*l+n[1]*d+i[1]*u+r[1]*h,e[2]=t[2]*l+n[2]*d+i[2]*u+r[2]*h,e}function dt(e,t){t=t||1;var n=2*d()*Math.PI,i=2*d()-1,r=Math.sqrt(1-i*i)*t;return e[0]=Math.cos(n)*r,e[1]=Math.sin(n)*r,e[2]=i*t,e}function ut(e,t,n){var i=t[0],r=t[1],s=t[2],o=n[3]*i+n[7]*r+n[11]*s+n[15];return o=o||1,e[0]=(n[0]*i+n[4]*r+n[8]*s+n[12])/o,e[1]=(n[1]*i+n[5]*r+n[9]*s+n[13])/o,e[2]=(n[2]*i+n[6]*r+n[10]*s+n[14])/o,e}function ht(e,t,n){var i=t[0],r=t[1],s=t[2];return e[0]=i*n[0]+r*n[3]+s*n[6],e[1]=i*n[1]+r*n[4]+s*n[7],e[2]=i*n[2]+r*n[5]+s*n[8],e}function pt(e,t,n){var i=n[0],r=n[1],s=n[2],o=n[3],a=t[0],c=t[1],l=t[2],d=r*l-s*c,u=s*a-i*l,h=i*c-r*a,p=r*h-s*u,f=s*d-i*h,m=i*u-r*d,g=2*o;return d*=g,u*=g,h*=g,p*=2,f*=2,m*=2,e[0]=a+d+p,e[1]=c+u+f,e[2]=l+h+m,e}function ft(e,t,n,i){var r=[],s=[];return r[0]=t[0]-n[0],r[1]=t[1]-n[1],r[2]=t[2]-n[2],s[0]=r[0],s[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),s[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e}function mt(e,t,n,i){var r=[],s=[];return r[0]=t[0]-n[0],r[1]=t[1]-n[1],r[2]=t[2]-n[2],s[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),s[1]=r[1],s[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e}function gt(e,t,n,i){var r=[],s=[];return r[0]=t[0]-n[0],r[1]=t[1]-n[1],r[2]=t[2]-n[2],s[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),s[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),s[2]=r[2],e[0]=s[0]+n[0],e[1]=s[1]+n[1],e[2]=s[2]+n[2],e}function vt(e,t){var n=Be(e[0],e[1],e[2]),i=Be(t[0],t[1],t[2]);rt(n,n),rt(i,i);var r=st(n,i);return r>1?0:r<-1?Math.PI:Math.acos(r)}function bt(e){return e[0]=0,e[1]=0,e[2]=0,e}function yt(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"}function St(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function wt(e,t){var n=e[0],i=e[1],r=e[2],s=t[0],o=t[1],a=t[2];return Math.abs(n-s)<=1e-6*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(i-o)<=1e-6*Math.max(1,Math.abs(i),Math.abs(o))&&Math.abs(r-a)<=1e-6*Math.max(1,Math.abs(r),Math.abs(a))}var xt,Ct=Ge,Ot=$e,kt=We,Et=Ze,Tt=et,Mt=_e,Dt=tt,Lt=(xt=Ne(),function(e,t,n,i,r,s){var o,a;for(t||(t=3),n||(n=0),a=i?Math.min(i*t+n,e.length):e.length,o=n;o<a;o+=t)xt[0]=e[o],xt[1]=e[o+1],xt[2]=e[o+2],r(xt,xt,s),e[o]=xt[0],e[o+1]=xt[1],e[o+2]=xt[2];return e});function jt(){var e=new l(4);return l!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function It(e){var t=new l(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function Pt(e,t,n,i){var r=new l(4);return r[0]=e,r[1]=t,r[2]=n,r[3]=i,r}function At(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function Rt(e,t,n,i,r){return e[0]=t,e[1]=n,e[2]=i,e[3]=r,e}function Nt(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e}function Vt(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e}function _t(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e[3]=t[3]*n[3],e}function Bt(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e[3]=t[3]/n[3],e}function Ft(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e[3]=Math.ceil(t[3]),e}function zt(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e[3]=Math.floor(t[3]),e}function Ut(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e[3]=Math.min(t[3],n[3]),e}function Gt(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e[3]=Math.max(t[3],n[3]),e}function $t(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e[3]=Math.round(t[3]),e}function Wt(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e}function Ht(e,t,n,i){return e[0]=t[0]+n[0]*i,e[1]=t[1]+n[1]*i,e[2]=t[2]+n[2]*i,e[3]=t[3]+n[3]*i,e}function Jt(e,t){var n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return Math.hypot(n,i,r,s)}function qt(e,t){var n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return n*n+i*i+r*r+s*s}function Yt(e){var t=e[0],n=e[1],i=e[2],r=e[3];return Math.hypot(t,n,i,r)}function Xt(e){var t=e[0],n=e[1],i=e[2],r=e[3];return t*t+n*n+i*i+r*r}function Kt(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e}function Qt(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e[3]=1/t[3],e}function Zt(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=n*n+i*i+r*r+s*s;return o>0&&(o=1/Math.sqrt(o)),e[0]=n*o,e[1]=i*o,e[2]=r*o,e[3]=s*o,e}function en(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function tn(e,t,n,i){var r=n[0]*i[1]-n[1]*i[0],s=n[0]*i[2]-n[2]*i[0],o=n[0]*i[3]-n[3]*i[0],a=n[1]*i[2]-n[2]*i[1],c=n[1]*i[3]-n[3]*i[1],l=n[2]*i[3]-n[3]*i[2],d=t[0],u=t[1],h=t[2],p=t[3];return e[0]=u*l-h*c+p*a,e[1]=-d*l+h*o-p*s,e[2]=d*c-u*o+p*r,e[3]=-d*a+u*s-h*r,e}function nn(e,t,n,i){var r=t[0],s=t[1],o=t[2],a=t[3];return e[0]=r+i*(n[0]-r),e[1]=s+i*(n[1]-s),e[2]=o+i*(n[2]-o),e[3]=a+i*(n[3]-a),e}function rn(e,t){var n,i,r,s,o,a;t=t||1;do{o=(n=2*d()-1)*n+(i=2*d()-1)*i}while(o>=1);do{a=(r=2*d()-1)*r+(s=2*d()-1)*s}while(a>=1);var c=Math.sqrt((1-o)/a);return e[0]=t*n,e[1]=t*i,e[2]=t*r*c,e[3]=t*s*c,e}function sn(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3];return e[0]=n[0]*i+n[4]*r+n[8]*s+n[12]*o,e[1]=n[1]*i+n[5]*r+n[9]*s+n[13]*o,e[2]=n[2]*i+n[6]*r+n[10]*s+n[14]*o,e[3]=n[3]*i+n[7]*r+n[11]*s+n[15]*o,e}function on(e,t,n){var i=t[0],r=t[1],s=t[2],o=n[0],a=n[1],c=n[2],l=n[3],d=l*i+a*s-c*r,u=l*r+c*i-o*s,h=l*s+o*r-a*i,p=-o*i-a*r-c*s;return e[0]=d*l+p*-o+u*-c-h*-a,e[1]=u*l+p*-a+h*-o-d*-c,e[2]=h*l+p*-c+d*-a-u*-o,e[3]=t[3],e}function an(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e}function cn(e){return"vec4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"}function ln(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]}function dn(e,t){var n=e[0],i=e[1],r=e[2],s=e[3],o=t[0],a=t[1],c=t[2],l=t[3];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=1e-6*Math.max(1,Math.abs(i),Math.abs(a))&&Math.abs(r-c)<=1e-6*Math.max(1,Math.abs(r),Math.abs(c))&&Math.abs(s-l)<=1e-6*Math.max(1,Math.abs(s),Math.abs(l))}var un=Vt,hn=_t,pn=Bt,fn=Jt,mn=qt,gn=Yt,vn=Xt,bn=function(){var e=jt();return function(t,n,i,r,s,o){var a,c;for(n||(n=4),i||(i=0),c=r?Math.min(r*n+i,t.length):t.length,a=i;a<c;a+=n)e[0]=t[a],e[1]=t[a+1],e[2]=t[a+2],e[3]=t[a+3],s(e,e,o),t[a]=e[0],t[a+1]=e[1],t[a+2]=e[2],t[a+3]=e[3];return t}}();function yn(){var e=new l(4);return l!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function Sn(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function wn(e,t,n){n*=.5;var i=Math.sin(n);return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=Math.cos(n),e}function xn(e,t){var n=2*Math.acos(t[3]),i=Math.sin(n/2);return i>1e-6?(e[0]=t[0]/i,e[1]=t[1]/i,e[2]=t[2]/i):(e[0]=1,e[1]=0,e[2]=0),n}function Cn(e,t){var n=Qn(e,t);return Math.acos(2*n*n-1)}function On(e,t,n){var i=t[0],r=t[1],s=t[2],o=t[3],a=n[0],c=n[1],l=n[2],d=n[3];return e[0]=i*d+o*a+r*l-s*c,e[1]=r*d+o*c+s*a-i*l,e[2]=s*d+o*l+i*c-r*a,e[3]=o*d-i*a-r*c-s*l,e}function kn(e,t,n){n*=.5;var i=t[0],r=t[1],s=t[2],o=t[3],a=Math.sin(n),c=Math.cos(n);return e[0]=i*c+o*a,e[1]=r*c+s*a,e[2]=s*c-r*a,e[3]=o*c-i*a,e}function En(e,t,n){n*=.5;var i=t[0],r=t[1],s=t[2],o=t[3],a=Math.sin(n),c=Math.cos(n);return e[0]=i*c-s*a,e[1]=r*c+o*a,e[2]=s*c+i*a,e[3]=o*c-r*a,e}function Tn(e,t,n){n*=.5;var i=t[0],r=t[1],s=t[2],o=t[3],a=Math.sin(n),c=Math.cos(n);return e[0]=i*c+r*a,e[1]=r*c-i*a,e[2]=s*c+o*a,e[3]=o*c-s*a,e}function Mn(e,t){var n=t[0],i=t[1],r=t[2];return e[0]=n,e[1]=i,e[2]=r,e[3]=Math.sqrt(Math.abs(1-n*n-i*i-r*r)),e}function Dn(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=Math.sqrt(n*n+i*i+r*r),a=Math.exp(s),c=o>0?a*Math.sin(o)/o:0;return e[0]=n*c,e[1]=i*c,e[2]=r*c,e[3]=a*Math.cos(o),e}function Ln(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=Math.sqrt(n*n+i*i+r*r),a=o>0?Math.atan2(o,s)/o:0;return e[0]=n*a,e[1]=i*a,e[2]=r*a,e[3]=.5*Math.log(n*n+i*i+r*r+s*s),e}function jn(e,t,n){return Ln(e,t),Kn(e,e,n),Dn(e,e),e}function In(e,t,n,i){var r,s,o,a,c,l=t[0],d=t[1],u=t[2],h=t[3],p=n[0],f=n[1],m=n[2],g=n[3];return(s=l*p+d*f+u*m+h*g)<0&&(s=-s,p=-p,f=-f,m=-m,g=-g),1-s>1e-6?(r=Math.acos(s),o=Math.sin(r),a=Math.sin((1-i)*r)/o,c=Math.sin(i*r)/o):(a=1-i,c=i),e[0]=a*l+c*p,e[1]=a*d+c*f,e[2]=a*u+c*m,e[3]=a*h+c*g,e}function Pn(e){var t=d(),n=d(),i=d(),r=Math.sqrt(1-t),s=Math.sqrt(t);return e[0]=r*Math.sin(2*Math.PI*n),e[1]=r*Math.cos(2*Math.PI*n),e[2]=s*Math.sin(2*Math.PI*i),e[3]=s*Math.cos(2*Math.PI*i),e}function An(e,t){var n=t[0],i=t[1],r=t[2],s=t[3],o=n*n+i*i+r*r+s*s,a=o?1/o:0;return e[0]=-n*a,e[1]=-i*a,e[2]=-r*a,e[3]=s*a,e}function Rn(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Nn(e,t){var n,i=t[0]+t[4]+t[8];if(i>0)n=Math.sqrt(i+1),e[3]=.5*n,n=.5/n,e[0]=(t[5]-t[7])*n,e[1]=(t[6]-t[2])*n,e[2]=(t[1]-t[3])*n;else{var r=0;t[4]>t[0]&&(r=1),t[8]>t[3*r+r]&&(r=2);var s=(r+1)%3,o=(r+2)%3;n=Math.sqrt(t[3*r+r]-t[3*s+s]-t[3*o+o]+1),e[r]=.5*n,n=.5/n,e[3]=(t[3*s+o]-t[3*o+s])*n,e[s]=(t[3*s+r]+t[3*r+s])*n,e[o]=(t[3*o+r]+t[3*r+o])*n}return e}function Vn(e,t,n,i){var r=.5*Math.PI/180;t*=r,n*=r,i*=r;var s=Math.sin(t),o=Math.cos(t),a=Math.sin(n),c=Math.cos(n),l=Math.sin(i),d=Math.cos(i);return e[0]=s*c*d-o*a*l,e[1]=o*a*d+s*c*l,e[2]=o*c*l-s*a*d,e[3]=o*c*d+s*a*l,e}function _n(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"}var Bn,Fn,zn,Un,Gn,$n,Wn=It,Hn=Pt,Jn=At,qn=Rt,Yn=Nt,Xn=On,Kn=Wt,Qn=en,Zn=nn,ei=Yt,ti=ei,ni=Xt,ii=ni,ri=Zt,si=ln,oi=dn,ai=(Bn=Ne(),Fn=Be(1,0,0),zn=Be(0,1,0),function(e,t,n){var i=st(t,n);return i<-.999999?(ot(Bn,Fn,t),Mt(Bn)<1e-6&&ot(Bn,zn,t),rt(Bn,Bn),wn(e,Bn,Math.PI),e):i>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(ot(Bn,t,n),e[0]=Bn[0],e[1]=Bn[1],e[2]=Bn[2],e[3]=1+i,ri(e,e))}),ci=(Un=yn(),Gn=yn(),function(e,t,n,i,r,s){return In(Un,t,r,s),In(Gn,n,i,s),In(e,Un,Gn,2*s*(1-s)),e}),li=($n=u(),function(e,t,n,i){return $n[0]=n[0],$n[3]=n[1],$n[6]=n[2],$n[1]=i[0],$n[4]=i[1],$n[7]=i[2],$n[2]=-t[0],$n[5]=-t[1],$n[8]=-t[2],ri(e,Nn(e,$n))});function di(){var e=new l(2);return l!=Float32Array&&(e[0]=0,e[1]=0),e}function ui(e){var t=new l(2);return t[0]=e[0],t[1]=e[1],t}function hi(e,t){var n=new l(2);return n[0]=e,n[1]=t,n}function pi(e,t){return e[0]=t[0],e[1]=t[1],e}function fi(e,t,n){return e[0]=t,e[1]=n,e}function mi(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e}function gi(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e}function vi(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e}function bi(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e}function yi(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e}function Si(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e}function wi(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e}function xi(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e}function Ci(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e}function Oi(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e}function ki(e,t,n,i){return e[0]=t[0]+n[0]*i,e[1]=t[1]+n[1]*i,e}function Ei(e,t){var n=t[0]-e[0],i=t[1]-e[1];return Math.hypot(n,i)}function Ti(e,t){var n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}function Mi(e){var t=e[0],n=e[1];return Math.hypot(t,n)}function Di(e){var t=e[0],n=e[1];return t*t+n*n}function Li(e,t){return e[0]=-t[0],e[1]=-t[1],e}function ji(e,t){return e[0]=1/t[0],e[1]=1/t[1],e}function Ii(e,t){var n=t[0],i=t[1],r=n*n+i*i;return r>0&&(r=1/Math.sqrt(r)),e[0]=t[0]*r,e[1]=t[1]*r,e}function Pi(e,t){return e[0]*t[0]+e[1]*t[1]}function Ai(e,t,n){var i=t[0]*n[1]-t[1]*n[0];return e[0]=e[1]=0,e[2]=i,e}function Ri(e,t,n,i){var r=t[0],s=t[1];return e[0]=r+i*(n[0]-r),e[1]=s+i*(n[1]-s),e}function Ni(e,t){t=t||1;var n=2*d()*Math.PI;return e[0]=Math.cos(n)*t,e[1]=Math.sin(n)*t,e}function Vi(e,t,n){var i=t[0],r=t[1];return e[0]=n[0]*i+n[2]*r,e[1]=n[1]*i+n[3]*r,e}function _i(e,t,n){var i=t[0],r=t[1];return e[0]=n[0]*i+n[2]*r+n[4],e[1]=n[1]*i+n[3]*r+n[5],e}function Bi(e,t,n){var i=t[0],r=t[1];return e[0]=n[0]*i+n[3]*r+n[6],e[1]=n[1]*i+n[4]*r+n[7],e}function Fi(e,t,n){var i=t[0],r=t[1];return e[0]=n[0]*i+n[4]*r+n[12],e[1]=n[1]*i+n[5]*r+n[13],e}function zi(e,t,n,i){var r=t[0]-n[0],s=t[1]-n[1],o=Math.sin(i),a=Math.cos(i);return e[0]=r*a-s*o+n[0],e[1]=r*o+s*a+n[1],e}function Ui(e,t){var n=e[0],i=e[1],r=t[0],s=t[1],o=n*n+i*i;o>0&&(o=1/Math.sqrt(o));var a=r*r+s*s;a>0&&(a=1/Math.sqrt(a));var c=(n*r+i*s)*o*a;return c>1?0:c<-1?Math.PI:Math.acos(c)}function Gi(e){return e[0]=0,e[1]=0,e}function $i(e){return"vec2("+e[0]+", "+e[1]+")"}function Wi(e,t){return e[0]===t[0]&&e[1]===t[1]}function Hi(e,t){var n=e[0],i=e[1],r=t[0],s=t[1];return Math.abs(n-r)<=1e-6*Math.max(1,Math.abs(n),Math.abs(r))&&Math.abs(i-s)<=1e-6*Math.max(1,Math.abs(i),Math.abs(s))}var Ji=Mi,qi=gi,Yi=vi,Xi=bi,Ki=Ei,Qi=Ti,Zi=Di,er=function(){var e=di();return function(t,n,i,r,s,o){var a,c;for(n||(n=2),i||(i=0),c=r?Math.min(r*n+i,t.length):t.length,a=i;a<c;a+=n)e[0]=t[a],e[1]=t[a+1],s(e,e,o),t[a]=e[0],t[a+1]=e[1];return t}}(),tr=n(7);n.d(t,"f",(function(){return nr})),n.d(t,"a",(function(){return ir})),n.d(t,"i",(function(){return rr})),n.d(t,"j",(function(){return sr})),n.d(t,"n",(function(){return or})),n.d(t,"v",(function(){return ar})),n.d(t,"r",(function(){return cr})),n.d(t,"s",(function(){return lr})),n.d(t,"o",(function(){return dr})),n.d(t,"l",(function(){return ur})),n.d(t,"c",(function(){return hr})),n.d(t,"h",(function(){return pr})),n.d(t,"g",(function(){return fr})),n.d(t,"b",(function(){return mr})),n.d(t,"q",(function(){return gr})),n.d(t,"e",(function(){return vr})),n.d(t,"d",(function(){return br})),n.d(t,"k",(function(){return i})),n.d(t,"m",(function(){return r})),n.d(t,"p",(function(){return a})),n.d(t,"t",(function(){return c})),n.d(t,"u",(function(){return s})),n.d(t,"w",(function(){return o}));
/**
 * @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 nr=r.create(),ir=["x","y","z"],rr=[s.fromValues(1,0,0),s.fromValues(0,1,0),s.fromValues(0,0,1)],sr=(s.fromValues(0,0,0),s.fromValues(1,1,1));s.fromValues(1/0,1/0,1/0),a.create();function or(e){return e[0]*e[1]*e[2]}function ar(e){return`${e[0]},${e[1]},${e[2]}`}function cr(e,t,n){let i=t[0],r=t[1],s=t[2];return e[0]=n[0]*i+n[4]*r+n[8]*s,e[1]=n[1]*i+n[5]*r+n[9]*s,e[2]=n[2]*i+n[6]*r+n[10]*s,e}function lr(e,t,n){let i=t[0],r=t[1],s=t[2];return e[0]=n[0]*i+n[1]*r+n[2]*s,e[1]=n[4]*i+n[5]*r+n[6]*s,e[2]=n[8]*i+n[9]*r+n[10]*s,e}function dr(e,t,n,i){const r=e.length;let s=function(e,t,n){const i=n.length;let r=0;for(let n=0;n<i;++n)r+=(e[n]-t[n])**2;let s=0;for(let r=0;r<i;++r){const i=e[r];s-=(i-n[r])*(t[r]-i)}return s/Math.max(r,1e-6)}(t,n,i);s=Math.max(0,Math.min(1,s));for(let i=0;i<r;++i){const r=t[i];e[i]=r+s*(n[i]-r)}return e}function ur(e,t){const n=t[0],i=t[1],r=t[2],s=t[4],o=t[5],a=t[6],c=t[8],l=t[9],d=t[10];return e[0]=n,e[1]=i,e[2]=r,e[3]=s,e[4]=o,e[5]=a,e[6]=c,e[7]=l,e[8]=d,e}function hr(e,t){const n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],h=t[10],p=t[11],f=t[12],m=t[13],g=t[14],v=t[15];e[0]=s+n,e[1]=l+o,e[2]=p+d,e[3]=v+f,e[4]=s-n,e[5]=l-o,e[6]=p-d,e[7]=v-f,e[8]=s+i,e[9]=l+a,e[10]=p+u,e[11]=v+m,e[12]=s-i,e[13]=l-a,e[14]=p-u,e[15]=v-m;const b=s+r,y=l+c,S=p+h,w=v+g,x=s-r,C=l-c,O=p-h,k=v-g,E=Math.sqrt(b**2+y**2+S**2);e[16]=b/E,e[17]=y/E,e[18]=S/E,e[19]=w/E;const T=Math.sqrt(x**2+C**2+O**2);return e[20]=x/T,e[21]=C/T,e[22]=O/T,e[23]=k/T,e}function pr(e,t,n,i,r,s,o){for(let a=0;a<6;++a){const c=o[4*a],l=o[4*a+1],d=o[4*a+2],u=o[4*a+3];if(Math.max(c*e,c*i)+Math.max(l*t,l*r)+Math.max(d*n,d*s)+u<0)return!1}return!0}function fr(e,t,n,i,r,s,o){for(let a=0;a<4;++a){const c=o[4*a],l=o[4*a+1],d=o[4*a+2],u=o[4*a+3];if(Math.max(c*e,c*i)+Math.max(l*t,l*r)+Math.max(d*n,d*s)+u<0)return!1}{const a=5,c=o[4*a],l=o[4*a+1],d=o[4*a+2],u=o[4*a+3],h=Math.max(c*e,c*i)+Math.max(l*t,l*r)+Math.max(d*n,d*s),p=Math.min(c*e,c*i)+Math.min(l*t,l*r)+Math.min(d*n,d*s),f=1e-6*Math.abs(u);if(p>-u+f||h<-u-f)return!1}return!0}function mr(e,t,n,i=!1){const r=n.length,s=[],o=i?1:t+1,a=i?t+1:1;for(let i=0;i<r;++i){const r=n[i];for(let n=0;n<t;++n)0!==e[n*o+r*a]&&(s[n]=!0)}return Object(tr.e)(s,!0)}function gr(e,t,n){for(let i=0;i<3;++i){const r=n[i];for(let n=0;n<3;++n)e[i+3*n]=r*t[i+3*n]}return e}function vr(e){if(1===e[15]){const t=2/Math.abs(e[10]);return 2/Math.abs(e[0])*(2/Math.abs(e[5]))*t}const t=e[10],n=2*e[14]/(2*t-2),i=(t-1)*n/(t+1);return 4/(e[0]*e[5])/3*(Math.abs(i)**3-Math.abs(n)**3)}function br(e){if(1===e[15]){return 2/Math.abs(e[10])}const t=e[10],n=2*e[14]/(2*t-2),i=(t-1)*n/(t+1);return Math.abs(i-n)}},function(e,t,n){"use strict";n.d(t,"d",(function(){return r})),n.d(t,"e",(function(){return s})),n.d(t,"a",(function(){return o})),n.d(t,"b",(function(){return a})),n.d(t,"c",(function(){return c}));function i(e){"object"==typeof e?e.dispose():e()}function r(e){for(let t=e.length;t>0;--t)i(e[t-1])}function s(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}class o{constructor(){this.refCount=1}addRef(){return++this.refCount,this}dispose(){0==--this.refCount&&this.refCountReachedZero()}refCountReachedZero(){this.disposed();let{disposers:e}=this;void 0!==e&&(r(e),this.disposers=void 0),this.wasDisposed=!0}disposed(){}registerDisposer(e){let{disposers:t}=this;return null==t?this.disposers=[e]:t.push(e),e}unregisterDisposer(e){let{disposers:t}=this;if(null!=t){let n=t.indexOf(e);-1!==n&&t.splice(n,1)}return e}registerEventListener(e,t,n,i){this.registerDisposer(s(e,t,n,i))}registerCancellable(e){return this.registerDisposer(()=>{e.cancel()}),e}}class a extends o{constructor(e){super(),this.value=e}}function c(e){return()=>{if(void 0!==e){let t=e;e=void 0,i(t)}}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"d",(function(){return r})),n.d(t,"a",(function(){return s})),n.d(t,"c",(function(){return o}));
/**
 * @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 i{constructor(){this.handlers=new Set,this.count=0;const e=this;this.dispatch=function(){++e.count,e.handlers.forEach(e=>{e.apply(this,arguments)})}}add(e){return this.handlers.add(e),()=>this.remove(e)}remove(e){return this.handlers.delete(e)}dispose(){this.handlers=void 0}}function r(e,...t){e();for(let n=0,i=t.length;n<i;++n)t[n].add(e);return()=>{for(let n=0,i=t.length;n<i;++n)t[n].remove(e)}}class s extends i{}const o={count:0,add:e=>()=>{},remove:e=>!1}},function(e,t,n){"use strict";n.d(t,"e",(function(){return a})),n.d(t,"c",(function(){return c})),n.d(t,"i",(function(){return d})),n.d(t,"h",(function(){return h})),n.d(t,"g",(function(){return f})),n.d(t,"a",(function(){return m})),n.d(t,"b",(function(){return v})),n.d(t,"d",(function(){return b})),n.d(t,"k",(function(){return y})),n.d(t,"f",(function(){return S})),n.d(t,"j",(function(){return w}));var i=n(15),r=n.n(i),s=n(2),o=n(3);
/**
 * @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 a{constructor(e){this.value_=e,this.changed=new o.a}get value(){return this.value_}set value(e){e!==this.value_&&(this.value_=e,this.changed.dispatch())}}class c extends a{constructor(e,t,n=e){super(e),this.validator=t,this.defaultValue=n}toJSON(){let{value_:e}=this;if(e!==this.defaultValue)return this.value_}reset(){this.value=this.defaultValue}restoreState(e){if(void 0!==e){let{validator:t}=this;try{return void(this.value=t(e))}catch(e){}}this.value=this.defaultValue}}class l extends s.a{constructor(e,t){super(),this.changed=new o.a,this.f=e,this.ws=t;for(const e of t)this.registerDisposer(e.changed.add(this.changed.dispatch))}get value(){return this.f(...this.ws.map(e=>e.value))}}function d(e,...t){return new l(e,t)}class u extends s.a{constructor(e,t){super(),this.changed=new o.a,this.valueGeneration=-1,this.f=e,this.ws=t;for(const e of t)this.registerDisposer(e.changed.add(this.changed.dispatch))}get value(){const e=this.changed.count;return e!==this.valueGeneration&&(this.value_=this.f(...this.ws.map(e=>e.value)),this.valueGeneration=e),this.value_}}function h(e,...t){return new u(e,t)}class p extends s.a{constructor(e,t=((e,t)=>e===t)){super(),this.changed=new o.a,this.value=e.value,this.registerDisposer(e.changed.add(()=>{const n=e.value;t(this.value,n)||(this.value=n,this.changed.dispatch())}))}}function f(e,t,n){const i=new l(e,t),r=new p(i,n);return r.registerDisposer(i),r}class m extends s.a{constructor(e){super(),this.changed=new o.a;const t=e(this),n=Object.keys(t),i=()=>{const e=Array.isArray(t)?[]:{};for(const i of n)e[i]=t[i].value;this.value=e,this.changed.dispatch()};i();for(const e of n){const n=t[e];this.registerDisposer(n.changed.add(()=>i()))}}}s.a;class g extends s.a{constructor(){super(...arguments),this.changed=new o.a}get value(){return this.value_}set value(e){const{value_:t}=this;if(this.value_=e,void 0!==t&&(t.dispose(),t.unregisterDisposer(this.valueHandler),this.valueHandler=void 0),void 0!==e){const t=this.valueHandler=()=>{this.value_===e&&(this.value_=void 0,this.changed.dispatch())};e.registerDisposer(t)}e!==t&&this.changed.dispatch()}reset(){this.value=void 0}disposed(){void 0!==this.value_&&(this.value_.unregisterDisposer(this.valueHandler),this.value_.dispose()),this.value_=void 0,super.disposed()}}class v extends g{constructor(e,t){super(),this.validator=e,this.jsonConverter=t}toJSON(){const{value:e}=this;return e&&this.jsonConverter(e)}restoreState(e){this.value=this.validator(e)}}class b{constructor(e){this.changed=new o.a,this.values=void 0===e?new Set:new Set(e)}add(e){const{values:t}=this;return t.has(e)||(t.add(e),this.changed.dispatch()),this}delete(e){const{values:t}=this;return!!t.delete(e)&&(this.changed.dispatch(),!0)}has(e){return this.values.has(e)}get size(){return this.values.size}[Symbol.iterator](){return this.values[Symbol.iterator]()}clear(){const{values:e}=this;e.size>0&&(e.clear(),this.changed.dispatch())}}function y(e,...t){let n=t.map(e=>e.value);const i=t.length;let o=new s.a,a=e(o,...n);const c=r()(()=>{let r=!1;for(let e=0;e<i;++e){const i=t[e].value;n[e]!==i&&(n[e]=i,r=!0)}r&&(o.dispose(),o=new s.a,a=e(o,...n))},0),l=t.map(e=>e.changed.add(c));return{flush(){c.flush()},dispose(){c.cancel(),Object(s.d)(l),o.dispose()},get value(){return c.flush(),a}}}function S(e){return{changed:o.c,value:e}}function w(e,t){return e(t.value),t.changed.add(()=>e(t.value))}},function(e,t,n){"use strict";n.d(t,"C",(function(){return h})),n.d(t,"y",(function(){return m})),n.d(t,"k",(function(){return g})),n.d(t,"l",(function(){return v})),n.d(t,"e",(function(){return y})),n.d(t,"b",(function(){return w})),n.d(t,"o",(function(){return x})),n.d(t,"n",(function(){return C})),n.d(t,"A",(function(){return O})),n.d(t,"d",(function(){return k})),n.d(t,"B",(function(){return M})),n.d(t,"m",(function(){return D})),n.d(t,"f",(function(){return L})),n.d(t,"z",(function(){return j})),n.d(t,"E",(function(){return R})),n.d(t,"q",(function(){return N})),n.d(t,"w",(function(){return V})),n.d(t,"x",(function(){return _})),n.d(t,"u",(function(){return B})),n.d(t,"v",(function(){return F})),n.d(t,"c",(function(){return $})),n.d(t,"j",(function(){return W})),n.d(t,"a",(function(){return H})),n.d(t,"s",(function(){return J})),n.d(t,"h",(function(){return q})),n.d(t,"g",(function(){return Y})),n.d(t,"i",(function(){return X})),n.d(t,"D",(function(){return K})),n.d(t,"t",(function(){return Q})),n.d(t,"r",(function(){return Z})),n.d(t,"p",(function(){return ee}));var i=n(4),r=n(7),s=n(1),o=n(0),a=n(19),c=n(40),l=n(3),d=n(37);
/**
 * @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 u=0;function h(){return++u}function p(e,t){return Object(r.a)(e.transform,t.transform)&&function(e,t){return Object(r.a)(e.lowerBounds,t.lowerBounds)&&Object(r.a)(e.upperBounds,t.upperBounds)}(e.box,t.box)}function f(e,t){return e.valid===t.valid&&e.rank===t.rank&&Object(r.a)(e.names,t.names)&&Object(r.a)(e.ids,t.ids)&&Object(r.a)(e.timestamps,t.timestamps)&&Object(r.a)(e.units,t.units)&&Object(r.a)(e.scales,t.scales)&&Object(r.b)(e.boundingBoxes,t.boundingBoxes,p)}function m(e){const{names:t,units:n,scales:i}=e,{valid:r=!0,rank:s=t.length,timestamps:o=t.map(()=>Number.NEGATIVE_INFINITY),ids:a=t.map((e,t)=>-t),boundingBoxes:c=[]}=e,{bounds:l=E(c,s)}=e;return{valid:r,rank:s,names:t,timestamps:o,ids:a,units:n,scales:i,boundingBoxes:c,bounds:l}}const g=m({valid:!1,names:[],units:[],scales:d.c,boundingBoxes:[]}),v=m({valid:!0,names:[],units:[],scales:d.c,boundingBoxes:[]});function b(e){const[t,n]=Object(o.a)(e,2),i=Object(o.r)(t),r=Object(o.E)(n),s=c.f.get(r);if(void 0===s)throw new Error(`Invalid unit: ${JSON.stringify(r)}`);return{unit:s.unit,scale:Object(c.e)(i,s.exponent)}}function y(e,t=!1){if(void 0===e)return g;Object(o.w)(e);const n=W(Object.keys(e),t),i=n.length,r=new Array(i),s=new Float64Array(i);for(let t=0;t<i;++t)Object(o.y)(e,n[t],e=>{const{unit:n,scale:i}=b(e);r[t]=n,s[t]=i});return m({valid:!1,names:n,units:r,scales:s})}function S(e){const{rank:t}=e;if(0===t)return;const{names:n,units:i,scales:r}=e,s={};for(let e=0;e<t;++e)s[n[e]]=[r[e],i[e]];return s}class w extends i.e{constructor(){super(g)}toJSON(){return S(this.value)}reset(){this.value=g}restoreState(e){this.value=y(e)}}function x(e,t){let n=(e+t)/2;return Number.isFinite(n)||(n=Math.min(Math.max(0,e),t)),n}function C(e,t){const{lowerBounds:n,upperBounds:i}=t,r=e.length;for(let t=0;t<r;++t)e[t]=x(n[t],i[t]);return e}function O(e){const t=e.lowerBounds.length;return{box:e,transform:a.c(Float64Array,t,t+1)}}function k(e,t,n){const{box:{lowerBounds:i,upperBounds:r},transform:s}=e,o=i.length,a=n,c=s[a*o+t];let l=c,d=c,u=!1;for(let e=0;e<o;++e){let n=s[a*e+t];if(0===n)continue;const o=n*i[e],c=n*r[e];l+=Math.min(o,c),d+=Math.max(o,c),u=!0}if(u)return{lower:l,upper:d}}function E(e,t){const n=new Float64Array(t),i=new Float64Array(t);n.fill(Number.NEGATIVE_INFINITY),i.fill(Number.POSITIVE_INFINITY);for(const r of e)for(let e=0;e<t;++e){const s=k(r,e,t);if(void 0===s)continue;const{lower:o,upper:a}=s;n[e]=n[e]===Number.NEGATIVE_INFINITY?o:Math.min(n[e],o),i[e]=i[e]===Number.POSITIVE_INFINITY?a:Math.max(i[e],a)}return{lowerBounds:n,upperBounds:i}}function T(e,t,n){const{transform:i,box:r}=e,s=n.length,o=r.lowerBounds.length,a=new Float64Array((o+1)*t);for(let e=0;e<s;++e){const r=n[e];if(-1!==r)for(let n=0;n<=o;++n)a[n*t+r]=i[n*s+e]}return{transform:a,box:r}}function M(e,t){const n={lowerBounds:Float64Array.of(0),upperBounds:Float64Array.of(1)},i=new Float64Array(2*e);return i[t]=1,{transform:i,box:n}}function D(e,t,n){if(t===n)return e;const{box:i}=e,r=i.lowerBounds.length,s=new Float64Array((r+1)*n);return a.a(s,n,e.transform,t,t,r+1),{box:i,transform:s}}function L(e,t){const{rank:n,sourceRank:i}=e;if(n!==t.rank||i!==t.sourceRank)return!1;const{inputSpace:s}=e,{inputSpace:o}=t;return!!(Object(r.a)(o.scales,s.scales)&&Object(r.a)(o.units,s.units)&&Object(r.a)(t.outputSpace.names,e.outputSpace.names))&&z(e.transform,n,e.outputSpace.scales,t.transform,n,t.outputSpace.scales)}function j(e){return{rank:e.rank,sourceRank:e.rank,inputSpace:e,outputSpace:e,transform:a.c(Float64Array,e.rank+1)}}function I(e,t,n){return e.boundingBoxes.map(i=>function(e,t,n,i){let{transform:r,box:s}=e;const o=e.box.lowerBounds.length,a=i.length,c=new Float64Array((o+1)*a);for(let e=0;e<a;++e){const s=i[e];for(let i=0;i<o;++i){let o=0;for(let c=0;c<a;++c){const l=n[c];o+=t[(a+1)*c+e]*r[a*i+c]*(l/s)}c[a*i+e]=o}let l=t[(a+1)*a+e];for(let i=0;i<a;++i){const c=n[i];l+=t[(a+1)*i+e]*r[a*o+i]*(c/s)}c[o*a+e]=l}return{transform:c,box:s}}(i,t,e.scales,n))}function P(e,t,n){const i=m({valid:e.valid,rank:n.rank,ids:n.ids,names:n.names,timestamps:n.timestamps,scales:n.scales,units:n.units,boundingBoxes:I(e,t,n.scales)});return f(i,n)?n:i}function A(e,t=!1){if(t){const t=Number(e);if(Number.isInteger(t)&&t>=0)return!0}return null!==e.match(/^[a-zA-Z][a-zA-Z_0-9]*['^]?$/)}function R(e,t=!1){const n=new Set;for(const i of e){if(!A(i,t))return!1;if(n.has(i))return!1;n.add(i)}return!0}function N(e){const t=e.length,n=new Array(t);n.fill(!0);for(let i=0;i<t;++i){const t=e[i];if(!A(t)){n[i]=!1;continue}const r=e.indexOf(t,i+1);-1!==r&&(n[i]=!1,n[r]=!1)}return n}function V(e){return e.endsWith("'")}function _(e){return e.endsWith("'")||e.endsWith("^")}function B(e){return e.endsWith("^")}function F(e){return!_(e)}function z(e,t,n,i,r,s){if(!a.d(e,t+1,i,r+1,t,t))return!1;for(let o=0;o<t;++o){const a=e[(t+1)*t+o],c=i[(r+1)*r+o];if(a*(n[o]/s[o])!==c)return!1}for(let e=t;e<r;++e)if(0!==i[(r+1)*r+e])return!1;for(let e=t;e<r;++e){for(let n=0;n<t;++n)if(0!==i[(r+1)*n+e])return!1;for(let t=0;t<r;++t){const n=i[(r+1)*e+t];if(e===t){if(1!==n)return!1}else if(0!==n)return!1}}return!0}function U(e,t){if(!t.includes(e))return e;const[,n,i]=e.match(/^([^']*)('?)$/);for(let e=0;;++e){const r=`${n}${e}${i}`;if(!t.includes(r))return r}}function G(e){const t=P(e.inputSpace,e.transform,e.outputSpace);return t===e.outputSpace?e:{rank:e.rank,sourceRank:e.sourceRank,inputSpace:e.inputSpace,transform:e.transform,outputSpace:t}}class ${constructor(e,t=!1){this.mutableSourceRank=t,this.value_=void 0,this.changed=new l.a,this.inputSpaceChanged=new l.a,this.defaultTransform=G(e);const n=this;this.outputSpace={changed:n.changed,get value(){return n.value.outputSpace},set value(e){const{value:t}=n;if(f(t.outputSpace,e))return;if(t.rank!==e.rank)return;const i=function(e,t,n){const i=new Float64Array(e),r=t.length,s=(r+1)*r;for(let e=0;e<r;++e)i[s+e]*=t[e]/n[e];return i}(t.transform,t.outputSpace.scales,e.scales);n.value_={sourceRank:t.sourceRank,rank:t.rank,inputSpace:t.inputSpace,outputSpace:P(t.inputSpace,i,e),transform:i},n.changed.dispatch()}},this.inputSpace={changed:n.inputSpaceChanged,get value(){return n.value.inputSpace},set value(e){const{value:t}=n;f(t.inputSpace,e)||(n.value_=function(e,t){const{inputSpace:n,transform:i}=e,{ids:r,rank:s}=n,{rank:o,names:a,units:c,scales:l}=t,d=new Array(s);d.fill(!0);const u=[],p=t.ids.map((e,t)=>{const n=r.indexOf(e);return-1!==n?d[n]=!1:u.push(t),n}),{outputSpace:f}=e,{names:g,units:v,scales:b,ids:y,timestamps:S}=f,w=d,x=[],C=[],O=new Float64Array(o),k=[],E=[];let T=0;const M=new Float64Array((o+1)**2);M[M.length-1]=1;for(let e=0;e<s;++e)if(!w[e]){x[T]=g[e],k[T]=y[e],C[T]=v[e],O[T]=b[e],E[T]=S[e];for(let t=0;t<o;++t){const n=p[t];-1!==n&&(M[t*(o+1)+T]=i[n*(s+1)+e])}M[o*(o+1)+T]=i[s*(s+1)+e],++T}for(const e of u)k[T]=h(),x[T]=U(a[e],x),O[T]=l[e],C[T]=c[e],M[e*(o+1)+T]=1,++T;const D=m({valid:t.valid,rank:o,names:x,ids:k,timestamps:E,units:C,scales:O,boundingBoxes:I(t,M,O)});return{rank:o,sourceRank:e.sourceRank,inputSpace:t,outputSpace:D,transform:M}}(t,e),n.inputSpaceChanged.dispatch(),n.changed.dispatch())}}}set value(e){const t=this.value;e!==t&&(this.value_=G(e),e.inputSpace!==t.inputSpace&&this.inputSpaceChanged.dispatch(),this.changed.dispatch())}get value(){let{value_:e}=this;return void 0===e&&(e=this.value_=this.defaultTransform),e}reset(){this.value_!==this.defaultTransform&&(this.value_=this.defaultTransform,console.log("newValue",this.value_),this.inputSpaceChanged.dispatch(),this.changed.dispatch())}get defaultInputSpace(){return this.defaultTransform.inputSpace}get spec(){const{value:e}=this,{rank:t,transform:n,inputSpace:i,outputSpace:s,sourceRank:o}=e,{defaultTransform:a,mutableSourceRank:c}=this,{inputSpace:l,rank:d,transform:u,outputSpace:h}=a,{units:p,scales:f}=i,m=o===t&&Object(r.a)(f,c?s.scales:l.scales)&&Object(r.a)(p,c?s.units:l.units),g=z(u,d,h.scales,n,t,s.scales),v=Object(r.a)(h.names,s.names);if(!(g&&v&&m))return{sourceRank:o,transform:g?void 0:n,outputSpace:e.outputSpace,inputSpace:m?void 0:i}}set transform(e){const{value:t}=this,{inputSpace:n}=t;this.value_={rank:t.rank,sourceRank:t.sourceRank,inputSpace:n,transform:e,outputSpace:P(n,e,t.outputSpace)},this.changed.dispatch()}set spec(e){if(void 0===e)return void this.reset();if(this.mutableSourceRank){const t=e.inputSpace||e.outputSpace,n=t.rank,i=m({rank:n,names:t.names.map((e,t)=>`${t}`),units:t.units,scales:t.scales});return void(this.value={rank:n,transform:e.transform||a.c(Float64Array,n+1),sourceRank:e.sourceRank,outputSpace:e.outputSpace,inputSpace:i})}const{inputSpace:t,sourceRank:n,outputSpace:i,transform:r,rank:s}=this.defaultTransform,{inputSpace:o,sourceRank:c,outputSpace:l,transform:d}=e,u=e.outputSpace.rank,h=t.names,p=void 0!==o?o.names:h,f=new Array(n);for(let e=0;e<n;++e){let t=p.indexOf(h[e]);t>=c&&(t=-1),f[e]=t}const g=u-c+n;for(let e=c;e<u;++e)f[n+e-c]=e;const v=new Float64Array(g),b=[];for(let e=0;e<n;++e){const n=f[e];-1===n||void 0===o?(v[e]=t.scales[e],b[e]=t.units[e]):(v[e]=o.scales[n],b[e]=o.units[n])}const y=o||l,S=h.slice(0,n),w=i.names.slice(0,n),x=new Float64Array(g),C=[];for(let e=0;e<g;++e){const t=f[e];-1===t?(x[e]=i.scales[e],C[e]=i.units[e]):(w[e]=l.names[t],C[e]=l.units[t],x[e]=l.scales[t])}if(!R(w))return void this.reset();for(let e=n;e<g;++e){const t=e-n+c;v[e]=y.scales[t],b[e]=y.units[t],S[e]=`${e}`}const O=new Float64Array((g+1)**2);O[O.length-1]=1;for(let e=0;e<g;++e){const t=f[e];let o;o=-1===t||void 0===d?e>=n?0:r[s*(s+1)+e]*(i.scales[e]/x[e]):d[u*(u+1)+t],O[g*(g+1)+e]=o;for(let i=0;i<g;++i){const o=f[i];let a;a=-1===t!=(-1===o)?0:-1===t||void 0===d?t>=n||o>=n?t===o?1:0:r[i*(s+1)+e]:d[o*(u+1)+t],O[i*(g+1)+e]=a}}const k=t.boundingBoxes.map(e=>D(e,s,g));for(let e=n;e<g;++e)k.push(M(g,e));this.value={rank:g,transform:O,sourceRank:n,outputSpace:m({rank:g,names:w,scales:x,units:C}),inputSpace:m({rank:g,names:S,scales:v,units:b,boundingBoxes:k})}}toJSON(){return X(this.spec)}restoreState(e){this.spec=Y(e)}}function W(e,t=!1){const n=Object(o.b)(e,e=>function(e,t=!1){const n=Object(o.E)(e);if(!A(n,t))throw new Error(`Invalid dimension name: ${JSON.stringify(n)}`);return n}(e,t));if(!R(n,t))throw new Error(`Invalid dimensions: ${JSON.stringify(n)}`);return n}class H{constructor(e,t){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_=t}getRenameValidity(e){const t=this.combined.value.names,n=N(e),i=e.length;for(let r=0;r<i;++r){if(!n[r])continue;const i=e[r];if(t.includes(i))continue;let s=!0;for(const e of this.bindings){if(e.space.value.names.includes(i)){s=!1;break}}n[r]=s}return n}get includeDimensionPredicate(){return this.includeDimensionPredicate_}set includeDimensionPredicate(e){this.includeDimensionPredicate_=e,this.update()}update(){const{combined:e,bindings:t}=this,n=this.retainCount>0?1:0;if(0===t.size&&!n)return void(e.value=g);const i=this.includeDimensionPredicate_,s=e.value;let o=Array.from(s.names),a=Array.from(s.units),c=Array.from(s.scales),l=Array.from(s.ids),d=Array.from(s.timestamps),u=s.names.map(()=>n?1:0);const p=[];let v=!1;for(const e of t){const{space:{value:t},prevValue:r,mappedDimensionIds:s}=e;v=v||t.valid;const{names:f,units:m,scales:g,ids:b,timestamps:y}=t,S=[],w=[];p.push(w),e.mappedDimensionIds=S,e.prevValue=t;const x=f.length;for(let e=0;e<x;++e){const t=f[e];if(!i(t))continue;if(void 0!==r){const n=b[e],i=r.ids.indexOf(n);if(-1!==i){const n=s[i];if(void 0!==n){const i=l.indexOf(n);if(-1!==i){S[e]=n,++u[i],w[e]=i;const r=y[e];void 0===r||r<=d[i]||(o[i]=t,c[i]=g[e],a[i]=m[e],d[i]=r);continue}}}}let p=o.indexOf(t);if(-1!==p){S[e]=l[p],++u[p],w[e]=p;continue}p=o.length,w[e]=p,u[p]=1+n,o[p]=t,a[p]=m[e],c[p]=g[e],d[p]=y[e];const v=h();l[p]=v,S[e]=v}}const{dimensionRefCounts:b}=this;b.clear();let y=0;const S=[];let w=o.length;for(const e of t){const{space:{value:t}}=e,n=p[y++],{rank:i}=t,s=Array.from(t.names),l=Array.from(t.timestamps),u=Float64Array.from(t.scales),h=Array.from(t.units);for(let e=0;e<i;++e){const t=n[e];void 0!==t&&(h[e]=a[t],u[e]=c[t],l[e]=d[t],s[e]=o[t])}for(const e of s){let t=b.get(e);void 0===t?t=1:++t,b.set(e,t)}if(!(Object(r.a)(h,t.units)&&Object(r.a)(u,t.scales)&&Object(r.a)(s,t.names)&&Object(r.a)(l,t.timestamps))){const n=m({valid:t.valid,ids:t.ids,scales:u,units:h,names:s,timestamps:l,boundingBoxes:t.boundingBoxes});e.prevValue=n,e.space.value=n}}{for(let e=0;e<w;++e)i(o[e])||(u[e]=0);const e=(e,t)=>0!==u[t];o=o.filter(e),a=a.filter(e),c=c.filter(e),l=l.filter(e),d=d.filter(e),u=u.filter(e),w=o.length}for(const e of t){const{space:{value:t}}=e,{boundingBoxes:n}=t;if(0===n.length)continue;const i=t.names.map(e=>o.indexOf(e));for(const e of n)S.push(T(e,w,i))}const x=m({valid:v,ids:l,names:o,units:a,scales:new Float64Array(c),boundingBoxes:S});if(n)for(let e=0;e<w;++e)--u[e];f(s,x)||(this.prevCombined=x,e.value=x)}retain(){return++this.retainCount,()=>{0==--this.retainCount&&this.update()}}bind(e){const t={space:e,mappedDimensionIds:[],prevValue:void 0},{bindings:n}=this;0===n.size&&this.combined.changed.add(this.handleCombinedChanged),n.add(t);const i=e.changed.add(()=>{e.value!==t.prevValue&&this.update()});return this.update(),()=>{i();const{bindings:e}=this;e.delete(t),0===e.size&&this.combined.changed.remove(this.handleCombinedChanged),this.update()}}}function J(e,t,n,i,r){const s=r.length,o=new e((s+1)**2);o[o.length-1]=1;for(let e=0;e<s;++e){const a=i[e];o[(s+1)*s+e]=t[(n+1)*n+a];for(let i=0;i<s;++i){const c=r[i];o[(s+1)*i+e]=t[(n+1)*c+a]}}return o}function q(e){if(void 0===e)return;const t=new Float64Array(16);if(Array.isArray(e))if(16===e.length)for(let n=0;n<4;++n)for(let i=0;i<4;++i)t[4*n+i]=Object(o.p)(e[4*i+n]);else{Object(o.a)(e,4);for(let n=0;n<4;++n){const i=Object(o.a)(e[n],4);for(let e=0;e<4;++e)t[4*e+n]=Object(o.p)(i[e])}}else{Object(o.w)(e);const n=s.p.create(),i=s.u.create(),r=s.u.fromValues(1,1,1);Object(o.B)(e,"rotation",e=>{Object(o.c)(n,e),s.p.normalize(n,n)}),Object(o.B)(e,"translation",e=>{Object(o.c)(i,e)}),Object(o.B)(e,"scale",e=>{Object(o.c)(r,e)});const a=s.m.create();s.m.fromRotationTranslationScale(a,n,i,r),t.set(a)}return{sourceRank:3,transform:t,outputSpace:m({valid:!0,names:["x","y","z"],units:["m","m","m"],scales:Float64Array.of(1e-9,1e-9,1e-9)}),inputSpace:void 0}}function Y(e){if(void 0===e)return;const t=Object(o.w)(e),n=Object(o.y)(t,"outputDimensions",y),i=n.rank,r=Object(o.y)(t,"sourceRank",e=>{if(void 0===e)return i;if(!Number.isInteger(e)||e<0||e>i)throw new Error(`Expected integer in range [0, ${i}] but received: ${JSON.stringify(e)}`);return e}),s=Object(o.B)(t,"inputDimensions",e=>{const t=y(e,!0);if(t.rank!==i)throw new Error(`Expected rank of ${i}, but received rank of: ${t.rank}`);return t});return{transform:Object(o.B)(t,"matrix",e=>{const t=new Float64Array((i+1)**2),n=Object(o.a)(e,i);t[t.length-1]=1;for(let e=0;e<i;++e)try{const r=Object(o.a)(n[e],i+1);for(let n=0;n<=i;++n)t[(i+1)*n+e]=Object(o.p)(r[n])}catch(t){throw new Error(`Error in row ${e}: ${t.message}`)}return t}),outputSpace:n,inputSpace:s,sourceRank:r}}function X(e){if(void 0===e)return;const{transform:t,outputSpace:n,inputSpace:i,sourceRank:r}=e;let s;const o=n.rank;if(void 0!==t){s=[];for(let e=0;e<o;++e){const n=[];s[e]=n;for(let i=0;i<=o;++i)n[i]=t[(o+1)*i+e]}}return{sourceRank:r===o?void 0:r,matrix:s,outputDimensions:S(n),inputDimensions:void 0===i?void 0:S(i)}}function K(e,t){const{ids:n,names:i,scales:r,units:s,timestamps:o}=e;return m({rank:t.length,valid:e.valid,ids:t.map(e=>n[e]),names:t.map(e=>i[e]),timestamps:t.map(e=>o[e]),scales:Float64Array.from(t,e=>r[e]),units:t.map(e=>s[e]),boundingBoxes:e.boundingBoxes.map(n=>function(e,t,n){const{box:i,transform:r}=e,s=e.box.lowerBounds.length,o=t.length,a=new Float64Array((s+1)*o);for(let e=0;e<o;++e)for(let i=0;i<=s;++i){const s=t[e];a[e+i*o]=r[s+i*n]}if(!a.every(e=>0===e))return{transform:a,box:i}}(n,t,e.rank)).filter(e=>void 0!==e)})}function Q(e,t,n){return t===n?e:K(e,Object(r.g)(e.rank,n,t))}function Z(e,t){const{transform:n,rank:i}=e,r=Object(s.b)(n,i,[t]);if(1!==r.length)return;const[o]=r,a=n[(i+1)*o+t],{inputSpace:c}=e;return{scale:c.scales[o]*a,unit:c.units[o]}}function ee(e,t){const{scales:n,units:i}=e.defaultInputSpace;return t<n.length?{scale:n[t],unit:i[t]}:void 0}},function(e,t,n){"use strict";
/**
 * @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 i(e){for(;;){let t=e.firstChild;if(!t)break;e.removeChild(t)}}function r(e){let{parentElement:t}=e;return!!t&&(t.removeChild(e),!0)}function s(e,t=Math.max(1,e.value.length)){const n=`${t}ch`;e.style.width!==n&&(e.style.width="0px",e.offsetWidth,e.style.width=n)}function o(e,t){let n=e.firstElementChild;for(const i of t)i!==n&&e.insertBefore(i,n),n=i.nextElementSibling;for(;null!==n;){let t=n.nextElementSibling;e.removeChild(n),n=t}}function a(e){return e instanceof HTMLElement&&!!(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e.isContentEditable)}n.d(t,"b",(function(){return i})),n.d(t,"c",(function(){return r})),n.d(t,"e",(function(){return s})),n.d(t,"d",(function(){return o})),n.d(t,"a",(function(){return a}))},function(e,t,n){"use strict";function i(e,t){let n=e.length,i=0;for(let r=0;r<n;++r)t(e[r],r,e)&&(e[i]=e[r],++i);e.length=i}function r(e,t){if(e.length===t)return e;let n=new e.constructor(t);return n.set(e),n}function s(e,t,n,i){const r=e.length/t,s=e.length*n*i,o=new e.constructor(s),a=e.length*i,c=t,l=t*i;for(let s=0;s<r;++s)for(let r=0;r<t;++r){const d=e[s*t+r],u=s*l+r;for(let e=0;e<n;++e)for(let t=0;t<i;++t)o[e*a+t*c+u]=d}return o}function o(e,t,n){let i=t-e;for(;i>0;){let t=Math.floor(i/2),r=e+t;n(r)?i=t:(e=r+1,i-=t+1)}return e}function a(e,t){const n=[];for(let i=0,r=e.length;i<r;++i)e[i]===t&&n.push(i);return n}function c(e,t){const n=e.length;if(t.length!==n)return!1;for(let i=0;i<n;++i)if(e[i]!==t[i])return!1;return!0}function l(e,t,n=((e,t)=>e===t)){const i=e.length;if(t.length!==i)return!1;for(let r=0;r<i;++r)if(!n(e[r],t[r]))return!1;return!0}function d(e,t,n){const i=[];if(n===t){for(let t=0;t<e;++t)i[t]=t;return i}i[n]=t;for(let r=0,s=0;r<e;)r!==t?(s===n&&++s,i[s++]=r++):++r;return i}function u(e,t,n){for(let i=0,r=n.length;i<r;++i){const r=n[i];-1!==r&&(e[r]=t[i])}return e}function h(e,t,n){for(let i=0,r=n.length;i<r;++i){const r=n[i];-1!==r&&(e[i]=t[r])}return e}function p(e){const t=[];for(let n=0,i=e.length;n<i;++n){const i=e[n];for(let e=0,n=i.length;e<n;++e){let n=t[e];void 0===n&&(n=t[e]=[]),n.push(i[e])}}return t}function f(e,t){const n=[];let i=0;for(let r=0,s=t.length;r<s;++r){const{retainCount:s,deleteCount:o,insertCount:a}=t[r];0!==s&&(n.push(e.slice(i,i+s)),i+=s),i+=o,0!==a&&n.push(new Array(a))}return i!==e.length&&n.push(e.slice(i)),new Array(0).concat(...n)}function m(e,t,n){const i=[];let r=0,s=0,o=e.length,a=t.length;for(;r<o&&s<a;){let c,l=e[r],d=t[s];if(c=n(l,d),0!==c)if(c<0){let t=1;for(;++r<o&&(c=n(e[r],d))<0;)++t;i.push({retainCount:0,deleteCount:t,insertCount:0})}else if(c>0){let e=1;for(;++s<a&&(c=n(l,t[s]))>0;)++e;i.push({retainCount:0,deleteCount:0,insertCount:e})}else;else{let l=1;for(++r,++s;r<o&&s<a&&0===(c=n(e[r],t[s]));)++l,++r,++s;i.push({retainCount:l,deleteCount:0,insertCount:0})}}return(r<o||s<a)&&i.push({retainCount:0,deleteCount:o-r,insertCount:a-s}),i}n.d(t,"d",(function(){return i})),n.d(t,"i",(function(){return r})),n.d(t,"l",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"e",(function(){return a})),n.d(t,"a",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"g",(function(){return d})),n.d(t,"j",(function(){return u})),n.d(t,"f",(function(){return h})),n.d(t,"m",(function(){return p})),n.d(t,"k",(function(){return f})),n.d(t,"h",(function(){return m}))},function(e,t,n){"use strict";n.d(t,"b",(function(){return u})),n.d(t,"e",(function(){return i})),n.d(t,"j",(function(){return h})),n.d(t,"g",(function(){return p})),n.d(t,"l",(function(){return f})),n.d(t,"a",(function(){return m})),n.d(t,"i",(function(){return S})),n.d(t,"h",(function(){return w})),n.d(t,"d",(function(){return x})),n.d(t,"f",(function(){return C})),n.d(t,"m",(function(){return O})),n.d(t,"n",(function(){return k})),n.d(t,"c",(function(){return E})),n.d(t,"k",(function(){return T}));var i,r=n(7),s=n(2),o=n(116),a=n(0),c=n(84),l=n(3),d=n(18);
/**
 * @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 u extends s.a{constructor(e){super(),this.id=e,this.changed=new l.a}}!function(e){e[e.POINT=0]="POINT",e[e.LINE=1]="LINE",e[e.AXIS_ALIGNED_BOUNDING_BOX=2]="AXIS_ALIGNED_BOUNDING_BOX",e[e.ELLIPSOID=3]="ELLIPSOID"}(i||(i={}));const h=[i.POINT,i.LINE,i.AXIS_ALIGNED_BOUNDING_BOX,i.ELLIPSOID],p={rgb:{serializedBytes:()=>3,alignment:()=>1,serializeCode:(e,t)=>`dv.setUint16(${t}, ${e}, true);`+`dv.setUint8(${t} + 2, ${e} >>> 16);`,deserializeCode:(e,t)=>`${e} = dv.getUint16(${t}, true) | (dv.getUint8(${t} + 2) << 16);`},rgba:{serializedBytes:()=>4,alignment:()=>1,serializeCode:(e,t)=>`dv.setUint32(${t}, ${e}, true);`,deserializeCode:(e,t)=>`${e} = dv.getUint32(${t}, true);`},float32:{serializedBytes:()=>4,alignment:()=>4,serializeCode:(e,t)=>`dv.setFloat32(${t}, ${e}, isLittleEndian);`,deserializeCode:(e,t)=>`${e} = dv.getFloat32(${t}, isLittleEndian);`},uint32:{serializedBytes:()=>4,alignment:()=>4,serializeCode:(e,t)=>`dv.setUint32(${t}, ${e}, isLittleEndian);`,deserializeCode:(e,t)=>`${e} = dv.getUint32(${t}, isLittleEndian);`},int32:{serializedBytes:()=>4,alignment:()=>4,serializeCode:(e,t)=>`dv.setInt32(${t}, ${e}, isLittleEndian);`,deserializeCode:(e,t)=>`${e} = dv.getInt32(${t}, isLittleEndian);`},uint16:{serializedBytes:()=>2,alignment:()=>2,serializeCode:(e,t)=>`dv.setUint16(${t}, ${e}, isLittleEndian);`,deserializeCode:(e,t)=>`${e} = dv.getUint16(${t}, isLittleEndian);`},int16:{serializedBytes:()=>2,alignment:()=>2,serializeCode:(e,t)=>`dv.setInt16(${t}, ${e}, isLittleEndian);`,deserializeCode:(e,t)=>`${e} = dv.getInt16(${t}, isLittleEndian);`},uint8:{serializedBytes:()=>1,alignment:()=>1,serializeCode:(e,t)=>`dv.setUint8(${t}, ${e});`,deserializeCode:(e,t)=>`${e} = dv.getUint8(${t});`},int8:{serializedBytes:()=>2,alignment:()=>1,serializeCode:(e,t)=>`dv.setInt8(${t}, ${e});`,deserializeCode:(e,t)=>`${e} = dv.getInt8(${t});`}};function f(e,t){let n=0;const i=t.length,r=new Array(i);for(let e=0;e<i;++e)r[e]=e;const s=n=>p[t[n].type].alignment(e);r.sort((e,t)=>s(t)-s(e));const o=new Array(i);for(let s=0;s<i;++s){const i=r[s],a=t[i],c=p[a.type],l=c.serializedBytes(e),d=c.alignment(e);n+=(d-n%d)%d,o[i]=n,n+=l}return n+=(4-n%4)%4,{serializedBytes:n,offsets:o}}class m{constructor(e,t){if(this.rank=e,this.propertySpecs=t,0===t.length)return this.serializedBytes=0,void(this.serialize=this.deserialize=()=>{});let n="",i="";const{serializedBytes:r,offsets:s}=f(e,t),o=t.length;for(let r=0;r<o;++r){const o=t[r],a=p[o.type],c=`properties[${r}]`,l=`offset + ${s[r]}`;n+=a.serializeCode(c,l,e),i+=a.deserializeCode(c,l,e)}this.serializedBytes=r,this.serialize=new Function("dv","offset","isLittleEndian","properties",n),this.deserialize=new Function("dv","offset","isLittleEndian","properties",i)}}function g(e,t,n,i,r){for(let s=0;s<i;++s)e.setFloat32(t,r[s],n),t+=4;return t}function v(e,t,n,i,r,s){return t=g(e,t,n,i,r),t=g(e,t,n,i,s)}function b(e,t,n,i,r){for(let s=0;s<i;++s)r[s]=e.getFloat32(t,n),t+=4;return t}function y(e,t,n,i,r,s){return t=b(e,t,n,i,r),t=b(e,t,n,i,s)}const S={[i.LINE]:{icon:"ꕹ",description:"Line",toJSON:e=>({pointA:Array.from(e.pointA),pointB:Array.from(e.pointB)}),restoreState(e,t,n){e.pointA=Object(a.y)(t,"pointA",e=>Object(a.d)(new Float32Array(n),e,a.p)),e.pointB=Object(a.y)(t,"pointB",e=>Object(a.d)(new Float32Array(n),e,a.p))},serializedBytes:e=>8*e,serialize(e,t,n,i,r){v(e,t,n,i,r.pointA,r.pointB)},deserialize:(e,t,n,r,s)=>{const o=new Float32Array(r),a=new Float32Array(r);return y(e,t,n,r,o,a),{type:i.LINE,pointA:o,pointB:a,id:s,properties:[]}},visitGeometry(e,t){t(e.pointA,!1),t(e.pointB,!1)}},[i.POINT]:{icon:"⚬",description:"Point",toJSON:e=>({point:Array.from(e.point)}),restoreState:(e,t,n)=>{e.point=Object(a.y)(t,"point",e=>Object(a.d)(new Float32Array(n),e,a.p))},serializedBytes:e=>4*e,serialize:(e,t,n,i,r)=>{g(e,t,n,i,r.point)},deserialize:(e,t,n,r,s)=>{const o=new Float32Array(r);return b(e,t,n,r,o),{type:i.POINT,point:o,id:s,properties:[]}},visitGeometry(e,t){t(e.point,!1)}},[i.AXIS_ALIGNED_BOUNDING_BOX]:{icon:"❑",description:"Bounding Box",toJSON:e=>({pointA:Array.from(e.pointA),pointB:Array.from(e.pointB)}),restoreState:(e,t,n)=>{e.pointA=Object(a.y)(t,"pointA",e=>Object(a.d)(new Float32Array(n),e,a.p)),e.pointB=Object(a.y)(t,"pointB",e=>Object(a.d)(new Float32Array(n),e,a.p))},serializedBytes:e=>8*e,serialize(e,t,n,i,r){v(e,t,n,i,r.pointA,r.pointB)},deserialize:(e,t,n,r,s)=>{const o=new Float32Array(r),a=new Float32Array(r);return y(e,t,n,r,o,a),{type:i.AXIS_ALIGNED_BOUNDING_BOX,pointA:o,pointB:a,id:s,properties:[]}},visitGeometry(e,t){t(e.pointA,!1),t(e.pointB,!1)}},[i.ELLIPSOID]:{icon:"◎",description:"Ellipsoid",toJSON:e=>({center:Array.from(e.center),radii:Array.from(e.radii)}),restoreState:(e,t,n)=>{e.center=Object(a.y)(t,"center",e=>Object(a.d)(new Float32Array(n),e,a.p)),e.radii=Object(a.y)(t,"radii",e=>Object(a.d)(new Float32Array(n),e,a.q))},serializedBytes:e=>8*e,serialize(e,t,n,i,r){v(e,t,n,i,r.center,r.radii)},deserialize:(e,t,n,r,s)=>{const o=new Float32Array(r),a=new Float32Array(r);return y(e,t,n,r,o,a),{type:i.ELLIPSOID,center:o,radii:a,id:s,properties:[]}},visitGeometry(e,t){t(e.center,!1),t(e.radii,!0)}}};function w(e,t){const n=S[e.type].toJSON(e,t.rank);n.type=i[e.type].toLowerCase(),n.id=e.id,n.description=e.description||void 0;const{relatedSegments:r}=e;return void 0!==r&&r.some(e=>0!==e.length)&&(n.segments=r.map(e=>e.map(e=>e.toString()))),0!==t.properties.length&&(n.props=e.properties.slice()),n}class x extends s.a{constructor(e,t=[],n=[]){super(),this.relationships=t,this.properties=n,this.annotationMap=new Map,this.changed=new l.a,this.readonly=!1,this.childAdded=new l.b,this.childUpdated=new l.b,this.childDeleted=new l.b,this.pending=new Set,this.references=new Map,this.rank_=e,this.annotationPropertySerializer=new m(e,n)}get rank(){return this.rank_}add(e,t=!0){if(this.ensureUpdated(),e.id){if(this.annotationMap.has(e.id))throw new Error(`Annotation id already exists: ${JSON.stringify(e.id)}.`)}else e.id=O();return this.annotationMap.set(e.id,e),this.changed.dispatch(),this.childAdded.dispatch(e),t||this.pending.add(e.id),this.getReference(e.id)}commit(e){this.ensureUpdated();const t=e.id;this.pending.delete(t)}update(e,t){if(this.ensureUpdated(),null===e.value)throw new Error("Annotation already deleted.");e.value=t,this.annotationMap.set(t.id,t),e.changed.dispatch(),this.changed.dispatch(),this.childUpdated.dispatch(t)}[Symbol.iterator](){return this.ensureUpdated(),this.annotationMap.values()}get(e){return this.ensureUpdated(),this.annotationMap.get(e)}delete(e){null!==e.value&&(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 t=this.references.get(e);return void 0!==t?t.addRef():(t=new u(e),t.value=this.annotationMap.get(e)||null,this.references.set(e,t),t.registerDisposer(()=>{this.references.delete(e)}),t)}ensureUpdated(){}toJSON(){this.ensureUpdated();const e=[],{pending:t}=this;for(const n of this)t.has(n.id)||e.push(w(n,this));return e}clear(){this.annotationMap.clear(),this.pending.clear(),this.changed.dispatch()}restoreState(e){this.ensureUpdated();const{annotationMap:t}=this;t.clear(),this.pending.clear(),void 0!==e&&Object(a.b)(e,e=>{const n=function(e,t,n=!1){Object(a.w)(e);const r=Object(a.y)(e,"type",e=>Object(a.o)(e,i)),s=Object(a.y)(e,"id",n?a.C:a.E)||O(),o=Object(a.y)(e,"segments",e=>{if(void 0===e)return t.relationships.map(()=>[]);const n=Object(a.a)(e);return 0===n.length?t.relationships.map(()=>[]):1!==t.relationships.length||Array.isArray(n[0])?Object(a.b)(Object(a.a)(e,t.relationships.length),e=>Object(a.b)(e,e=>d.a.parseString(e))):[Object(a.b)(n,e=>d.a.parseString(e))]}),c=Object(a.y)(e,"props",e=>void 0===e?t.properties.map(e=>e.default):Object(a.b)(Object(a.a)(e,t.properties.length),e=>Number(e))),l={id:s,description:Object(a.y)(e,"description",a.C),relatedSegments:o,properties:c,type:r};return S[r].restoreState(l,e,t.rank),l}(e,this);t.set(n.id,n)});for(const e of this.references.values()){const{id:n}=e,i=t.get(n);e.value=i||null,e.changed.dispatch()}this.changed.dispatch()}reset(){this.clear()}}class C extends x{constructor(e){super(e.value.sourceRank,["segments"]),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:t}=this;if(e===t)return;this.curCoordinateTransform=e;const n=e.sourceRank,s=t.sourceRank;if(s===n&&(t.inputSpace===e.inputSpace||Object(r.a)(t.inputSpace.ids.slice(0,n),e.inputSpace.ids.slice(0,n))))return;const{ids:o}=e.inputSpace,a=t.inputSpace.ids,c=[];for(let e=0;e<n;++e){let t=a.indexOf(o[e]);t>=s&&(t=-1),c.push(t)}const l=e=>{const t=new Float32Array(n);for(let i=0;i<n;++i){const n=c[i];t[i]=-1===n?0:e[i]}return t};for(const e of this.annotationMap.values())switch(e.type){case i.POINT:e.point=l(e.point);break;case i.LINE:case i.AXIS_ALIGNED_BOUNDING_BOX:e.pointA=l(e.pointA),e.pointB=l(e.pointB);break;case i.ELLIPSOID:e.center=l(e.center),e.radii=l(e.radii)}this.rank_=n,this.changed.dispatch()}}function O(){return Object(c.a)(160)}function k(e){const t=new x(e.lowerBounds.length);return t.readonly=!0,t.add(function(e){return{type:i.AXIS_ALIGNED_BOUNDING_BOX,id:"data-bounds",description:"Data Bounds",pointA:new Float32Array(e.lowerBounds),pointB:new Float32Array(e.upperBounds),properties:[]}}(e)),t}class E{constructor(e){this.propertySerializer=e,this.annotations=[[],[],[],[]]}add(e){this.annotations[e.type].push(e)}serialize(){return function(e,t){const{rank:n}=t;let i=0;const r=[],s=t.serializedBytes;for(const t of h){r[t]=i;const o=e[t].length;i+=(S[t].serializedBytes(n)+s)*o,i+=(4-i%4)%4}const a=t.serialize,c=[],l=[],d=new ArrayBuffer(i),u=new DataView(d),p=o.a===o.b.LITTLE;for(const t of h){const i=e[t];c[t]=i.map(e=>e.id),l[t]=new Map(i.map((e,t)=>[e.id,t]));const o=S[t],d=o.serialize,h=o.serializedBytes(n);let f=r[t];for(const e of i)d(u,f,p,n,e),f+=h,a(u,f,p,e.properties),f+=s}return{data:new Uint8Array(d),typeToIds:c,typeToOffset:r,typeToIdMaps:l}}(this.annotations,this.propertySerializer)}}function T(e){if(null==e)return e;const{relatedSegments:t}=e;if(void 0!==t)for(let e=0,n=t.length;e<n;++e){const n=t[e];void 0!==n&&(t[e]=n.map(e=>new d.a(e.low,e.high)))}return e}},function(e,t,n){"use strict";n.d(t,"b",(function(){return s})),n.d(t,"d",(function(){return l})),n.d(t,"e",(function(){return d})),n.d(t,"c",(function(){return u}));var i=n(26),r=n(14);n.d(t,"a",(function(){return r.c}));var s,o=n(1),a=n(19),c=n(37);!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.IMAGE=1]="IMAGE",e[e.SEGMENTATION=2]="SEGMENTATION"}(s||(s={}));function l(e){const{rank:t,dataType:n,compressedSegmentationBlockSize:r}=e,{baseVoxelOffset:s=new Float32Array(t)}=e;return Object.assign(Object.assign({},Object(i.p)(e)),{compressedSegmentationBlockSize:r,baseVoxelOffset:s,dataType:n})}function d(e){let{rank:t,compressedSegmentationBlockSize:n,dataType:o,lowerVoxelBound:d,upperVoxelBound:u}=e;if(void 0===n&&3===t&&e.volumeType===s.SEGMENTATION&&(o===r.c.UINT32||o===r.c.UINT64)){let{volumeSourceOptions:{displayRank:n,multiscaleToViewTransform:r},chunkToMultiscaleTransform:s,chunkToViewTransform:o}=e;void 0===o&&(o=a.i(new Float32Array(t*n),n,r,n,s,t+1,n,t,t));const{maxCompressedSegmentationBlockSize:h,chunkDataSize:p}=e;return l(Object.assign(Object.assign({},e),{compressedSegmentationBlockSize:Float32Array.from(Object(i.n)({rank:t,chunkToViewTransform:o,displayRank:n,lowerVoxelBound:d,upperVoxelBound:u,maxVoxelsPerChunkLog2:9,maxBlockSize:void 0===h?p:c.d(new Uint32Array(t),p,h)}))}))}return l(e)}function u(e){const{rank:t}=e,{volumeSourceOptions:{displayRank:n,multiscaleToViewTransform:r,modelChannelDimensionIndices:s},chunkToMultiscaleTransform:c}=e,l=a.i(new Float32Array(n*t),n,r,n,c,t+1,n,t,t);let{minBlockSize:u}=e;void 0===u?(u=new Uint32Array(t),u.fill(1)):u=new Uint32Array(u);const{lowerVoxelBound:h,upperVoxelBound:p}=e;if(0!==s.length)for(const e of Object(o.b)(c,t,s)){let t=p[e];void 0!==h&&(t-=h[e]),u[e]=t}const{chunkDataSizes:f=Object(i.m)(Object.assign(Object.assign({rank:t},e),{minBlockSize:u,chunkToViewTransform:l,displayRank:n}))}=e;return f.map(t=>d(Object.assign(Object.assign({},e),{chunkDataSize:t,chunkToViewTransform:l})))}},function(e,t,n){"use strict";
/**
 * @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 i;n.d(t,"h",(function(){return i})),n.d(t,"n",(function(){return r})),n.d(t,"g",(function(){return s})),n.d(t,"e",(function(){return o})),n.d(t,"f",(function(){return a})),n.d(t,"m",(function(){return c})),n.d(t,"l",(function(){return l})),n.d(t,"k",(function(){return d})),n.d(t,"c",(function(){return u})),n.d(t,"b",(function(){return h})),n.d(t,"d",(function(){return p})),n.d(t,"j",(function(){return f})),n.d(t,"a",(function(){return m})),n.d(t,"i",(function(){return g})),function(e){e[e.GPU_MEMORY=0]="GPU_MEMORY",e[e.SYSTEM_MEMORY=1]="SYSTEM_MEMORY",e[e.SYSTEM_MEMORY_WORKER=2]="SYSTEM_MEMORY_WORKER",e[e.DOWNLOADING=3]="DOWNLOADING",e[e.QUEUED=4]="QUEUED",e[e.NEW=5]="NEW",e[e.FAILED=6]="FAILED",e[e.EXPIRED=7]="EXPIRED"}(i||(i={}));const r=8;var s;!function(e){e[e.FIRST_TIER=0]="FIRST_TIER",e[e.FIRST_ORDERED_TIER=0]="FIRST_ORDERED_TIER",e[e.VISIBLE=0]="VISIBLE",e[e.PREFETCH=1]="PREFETCH",e[e.LAST_ORDERED_TIER=1]="LAST_ORDERED_TIER",e[e.RECENT=2]="RECENT",e[e.LAST_TIER=2]="LAST_TIER"}(s||(s={}));var o,a;!function(e){e[e.totalTime=0]="totalTime",e[e.totalChunks=1]="totalChunks"}(o||(o={})),function(e){e[e.numChunks=0]="numChunks",e[e.systemMemoryBytes=1]="systemMemoryBytes",e[e.gpuMemoryBytes=2]="gpuMemoryBytes"}(a||(a={}));const c=3;function l(e,t){return 3*e+t}function d(e){return 3*r*c+e}const u="ChunkQueueManager",h="ChunkManager",p="ChunkSource.invalidate",f="ChunkQueueManager.requestChunkStatistics",m="ChunkManager.chunkLayerStatistics";class g{constructor(){this.numVisibleChunksNeeded=0,this.numVisibleChunksAvailable=0,this.numPrefetchChunksNeeded=0,this.numPrefetchChunksAvailable=0}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return a}));var i=n(2),r=n(13);n.d(t,"a",(function(){return r.a})),n.d(t,"c",(function(){return r.d}));
/**
 * @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 s=new Set(["f1","f2","f3","f4","f5","f6","f7","f8","f9","f10","f11","f12","escape","pause"]),o=new Set(["color","date","datetime","datetime-local","email","month","number","password","search","tel","text","time","url","week"]);class a extends i.a{constructor(e,t){super(),this.target=e,this.eventMap=t,this.modifierShortcutsAreGlobal=!0,this.allShortcutsAreGlobal=!1,this.allowSpaceKeyOnButtons=!1,this.registerEventListener(e,"keydown",this.handleKeyDown.bind(this),!1)}shouldIgnoreEvent(e,t){var n=t.target;let{tagName:i}=n;if(n===this.target)return!1;var r="TEXTAREA"===i||"INPUT"===i||"BUTTON"===i||"SELECT"===i,a=!r&&(n.isContentEditable||n.ownerDocument&&"on"===n.ownerDocument.designMode);return!(!r&&!a)&&(!this.allShortcutsAreGlobal&&!s.has(e)&&(!!a||(!(!this.modifierShortcutsAreGlobal||!(t.altKey||t.ctrlKey||t.metaKey))||("INPUT"===i&&o.has(n.type)?"enter"!==e:"INPUT"!==i&&"BUTTON"!==i||!this.allowSpaceKeyOnButtons&&"space"===e))))}handleKeyDown(e){const t=function(e){return e.code.toLowerCase()}(e);this.shouldIgnoreEvent(t,e)||Object(r.c)(t,e,e,this.eventMap)}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return f})),n.d(t,"a",(function(){return g})),n.d(t,"d",(function(){return v})),n.d(t,"c",(function(){return y})),n.d(t,"f",(function(){return S})),n.d(t,"g",(function(){return w})),n.d(t,"e",(function(){return x}));var i=n(10),r=n(58),s=n(17),o=n(4),a=n(39),c=n(0),l=n(91),d=n(45),u=n(3),h=n(16),p=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};class f{constructor(e){this.source=e,this.state=i.h.SYSTEM_MEMORY}get gl(){return this.source.gl}copyToGPU(e){this.state=i.h.GPU_MEMORY}freeGPUMemory(e){this.state=i.h.SYSTEM_MEMORY}}function m(e){if("number"!=typeof e||e<0)throw new Error(`Expected non-negative number as limit, but received: ${JSON.stringify(e)}`);return e}class g{constructor({defaultItemLimit:e=Number.POSITIVE_INFINITY,defaultSizeLimit:t=Number.POSITIVE_INFINITY}={}){this.sizeLimit=new o.c(t,m),this.itemLimit=new o.c(e,m)}}let v=class extends h.b{constructor(e,t,n,i){super(),this.gl=t,this.frameNumberCounter=n,this.capacities=i,this.visibleChunksChanged=new u.a,this.pendingChunkUpdates=null,this.pendingChunkUpdatesTail=null,this.chunkUpdateDeadline=null,this.chunkUpdateDelay=30,this.enablePrefetch=new s.b(!0,!0);const o=t=>({itemLimit:this.registerDisposer(r.a.makeFromExisting(e,t.itemLimit)).rpcId,sizeLimit:this.registerDisposer(r.a.makeFromExisting(e,t.sizeLimit)).rpcId});this.initializeCounterpart(e,{gpuMemoryCapacity:o(i.gpuMemory),systemMemoryCapacity:o(i.systemMemory),downloadCapacity:o(i.download),computeCapacity:o(i.compute),enablePrefetch:this.registerDisposer(r.a.makeFromExisting(e,this.enablePrefetch)).rpcId})}scheduleChunkUpdate(){let e,t=this.chunkUpdateDeadline;e=null===t||Date.now()<t?0:this.chunkUpdateDelay,setTimeout(this.processPendingChunkUpdates.bind(this),e)}processPendingChunkUpdates(){let e=this.chunkUpdateDeadline;null===e&&(e=Date.now()+30);let t=!1;for(;;){if(Date.now()>e){this.chunkUpdateDeadline=null,setTimeout(()=>this.processPendingChunkUpdates(),this.chunkUpdateDelay);break}let n=this.pendingChunkUpdates;if(this.applyChunkUpdate(n)&&(t=!0),null==(this.pendingChunkUpdates=n.nextUpdate)){this.pendingChunkUpdatesTail=null;break}}t&&this.visibleChunksChanged.dispatch()}handleFetch_(e,t){const{resolve:n,reject:i,cancellationToken:r}=t.promise;if(r.isCanceled)return void i(a.a);const s=t.key,o=e.chunks.get(s);if(!o)return void i(new Error(`No chunk found at ${s} for source ${e.constructor.name}`));const c=o.data;c?n({value:c}):i(new Error(`At ${s} for source ${e.constructor.name}: chunk has no data`))}applyChunkUpdate(e){let t=!1,{rpc:n}=this;const r=n.get(e.source);if(void 0!==e.promise)this.handleFetch_(r,e);else if(void 0===e.id){for(const e of r.chunks.keys())r.deleteChunk(e);t=!0}else{let n=e.state;if(n===i.h.EXPIRED)r.deleteChunk(e.id);else{let s,o=e.id;if(e.new?(s=r.getChunk(e),r.addChunk(o,s)):s=r.chunks.get(o),n!==s.state)switch(n){case i.h.GPU_MEMORY:s.copyToGPU(this.gl),t=!0;break;case i.h.SYSTEM_MEMORY:s.freeGPUMemory(this.gl);break;default:throw new Error(`INTERNAL ERROR: Invalid chunk state: ${i.h[n]}`)}}}return t}};function b(e,t){let n=e.get(t.source);let i=n.chunkManager.chunkQueueManager;if(n.immediateChunkUpdates)return void(i.applyChunkUpdate(t)&&i.visibleChunksChanged.dispatch());let r=i.pendingChunkUpdatesTail;null==r?(i.pendingChunkUpdates=t,i.pendingChunkUpdatesTail=t,i.scheduleChunkUpdate()):(r.nextUpdate=t,i.pendingChunkUpdatesTail=t)}v=p([Object(h.g)(i.c)],v),Object(h.e)("Chunk.update",(function(e){b(this,e)})),Object(h.d)("Chunk.retrieve",(function(e,t){return new Promise((n,i)=>{e.promise={resolve:n,reject:i,cancellationToken:t},b(this,e)})})),Object(h.e)(i.a,(function(e){const t=this.get(e.id);for(const e of t.prevStatisticsLayers)e.numVisibleChunksNeeded=0,e.numVisibleChunksAvailable=0,e.numPrefetchChunksNeeded=0,e.numPrefetchChunksAvailable=0;t.prevStatisticsLayers.length=0;for(const n of e.layers){const e=this.get(n.id);if(void 0===e)continue;const i=e.layerChunkProgressInfo;i.numVisibleChunksAvailable=n.numVisibleChunksAvailable,i.numVisibleChunksNeeded=n.numVisibleChunksNeeded,i.numPrefetchChunksAvailable=n.numPrefetchChunksAvailable,i.numPrefetchChunksNeeded=n.numPrefetchChunksNeeded,t.prevStatisticsLayers.push(i)}t.layerChunkStatisticsUpdated.dispatch()}));let y=class extends h.b{constructor(e){super(),this.chunkQueueManager=e,this.memoize=new l.b,this.prevStatisticsLayers=[],this.layerChunkStatisticsUpdated=new u.a,this.registerDisposer(e.addRef()),this.initializeCounterpart(e.rpc,{chunkQueueManager:e.rpcId})}get gl(){return this.chunkQueueManager.gl}getChunkSource(e,t){const n=e.encodeOptions(t);n.constructorId=Object(d.a)(e);const i=Object(c.h)(n);return this.memoize.get(i,()=>{const i=new e(this,t);return i.initializeCounterpart(this.rpc,{}),i.key=n,i})}};y=p([Object(h.g)(i.b)],y);class S extends h.b{constructor(e,t={}){super(),this.chunkManager=e,this.chunks=new Map,this.immediateChunkUpdates=!1}initializeCounterpart(e,t){t.chunkManager=this.chunkManager.rpcId,super.initializeCounterpart(e,t)}get gl(){return this.chunkManager.chunkQueueManager.gl}deleteChunk(e){const t=this.chunks.get(e);t.state===i.h.GPU_MEMORY&&t.freeGPUMemory(this.gl),this.chunks.delete(e)}addChunk(e,t){this.chunks.set(e,t)}getChunk(e){throw new Error("Not implemented.")}invalidateCache(){this.rpc.invoke(i.d,{id:this.rpcId})}static encodeOptions(e){return{}}}function w(e,t){let n=class extends e{constructor(...e){super(...e);const t=e[1];this.parameters=t.parameters}initializeCounterpart(e,t){t.parameters=this.parameters,super.initializeCounterpart(e,t)}static encodeOptions(e){return Object.assign({parameters:e.parameters},super.encodeOptions(e))}};return n=p([Object(h.g)(t.RPC_ID)],n),n}class x extends h.b{constructor(e){super(),this.layerChunkProgressInfo=e}}},function(e,t,n){"use strict";var i,r=n(2);
/**
 * @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 s(e,t){let n="";return 1&t&&(n+="control+"),2&t&&(n+="alt+"),4&t&&(n+="meta+"),8&t&&(n+="shift+"),n+=e,n}function o(e){return"string"==typeof e?{action:e}:e}function*a(e){const t=e.indexOf(":"),n=function(e){let t,n=e.split("+"),i=0;for(let e of n)switch(e){case"control":i|=1;break;case"alt":i|=2;break;case"meta":i|=4;break;case"shift":i|=8;break;default:if(void 0!==t)return;t=e}if(void 0!==t)return s(t,i)}(e.substring(t+1));if(void 0===n)throw new Error(`Invalid event identifier: ${JSON.stringify(e)}`);if(-1!==t){const i=e.substring(0,t);if("at"!==i&&"bubble"!==i)throw new Error(`Invalid event phase: ${JSON.stringify(i)}`);yield`${i}:${n}`}else yield`at:${n}`,yield`bubble:${n}`}n.d(t,"a",(function(){return c})),n.d(t,"b",(function(){return d})),n.d(t,"c",(function(){return u})),n.d(t,"d",(function(){return h})),function(e){e[e.CONTROL=1]="CONTROL",e[e.ALT=2]="ALT",e[e.META=4]="META",e[e.SHIFT=8]="SHIFT"}(i||(i={}));class c extends class{constructor(e){if(this.parents=new Array,this.parentPriorities=new Array,this.bindings=new Map,void 0!==e){this.parents.push(...e.parents),this.parentPriorities.push(...e.parentPriorities);for(const[t,n]of e.bindings)this.bindings.set(t,n)}}addParent(e,t){const{parents:n,parentPriorities:i}=this;let r=0;const{length:s}=n;for(;r<s&&t<i[r];)++r;return n.splice(r,0,e),i.splice(r,0,t),()=>{this.removeParent(e)}}removeParent(e){const t=this.parents.indexOf(e);if(-1===t)throw new Error("Attempt to remove non-existent parent map.");this.parents.splice(t,1),this.parentPriorities.splice(t,1)}set(e,t){this.bindings.set(e,t)}delete(e){this.bindings.delete(e)}clear(){this.bindings.clear(),this.parents.length=0,this.parentPriorities.length=0}get(e){const{parents:t,parentPriorities:n}=this,i=n.length;let r,s=0;for(;s<i&&n[s]>0;++s)if(r=t[s].get(e),void 0!==r)return r;if(r=this.bindings.get(e),void 0!==r)return r;for(;s<i;++s)if(r=t[s].get(e),void 0!==r)return r}*getAll(e){const{parents:t,parentPriorities:n}=this,i=n.length;let r;for(;0<i&&n[0]>0;)r=t[0].get(e),void 0!==r&&(yield r);for(r=this.bindings.get(e),void 0!==r&&(yield r);0<i;)r=t[0].get(e),void 0!==r&&(yield r)}*entries(){const{parents:e,parentPriorities:t}=this,n=t.length;for(;0<n&&t[0]>0;)yield*e[0].entries();for(yield*this.bindings.entries();0<n;)yield*e[0].entries()}}{static fromObject(e,t={}){const n=new c;if(n.label=t.label,void 0!==t.parents)for(const[e,i]of t.parents)n.addParent(e,i);for(const t of Object.keys(e))n.set(t,o(e[t]));return n}setFromObject(e){for(const t of Object.keys(e))this.set(t,o(e[t]))}set(e,t){const n=o(t);for(const t of a(e))super.set(t,n)}delete(e){for(const t of a(e))super.delete(t)}describe(){const e=[],t=new Map;for(const[e,n]of this.entries()){const i=e.indexOf(":");t.set(e.substring(i+1),n.action)}for(const[n,i]of t)e.push(`${n}→${i}`);return e.join(", ")}}const l=[];function d(e,t,n,i,r){const s=l[n]+":"+e;!function(e,t,n){if(void 0===n)return;!1!==n.stopPropagation&&e.stopPropagation();const i=new CustomEvent("action:"+n.action,{bubbles:!0,detail:t,cancelable:!0}),r=!e.target.dispatchEvent(i);(!1!==n.preventDefault||r)&&e.preventDefault()}(t,i,r.get(s))}function u(e,t,n,i){var r;d(s(e,((r=t).ctrlKey?1:0)|(r.altKey?2:0)|(r.metaKey?4:0)|(r.shiftKey?8:0)),t,t.eventPhase,n,i)}function h(e,t,n,i){return Object(r.e)(e,`action:${t}`,n,i)}l[Event.AT_TARGET]="at",l[Event.CAPTURING_PHASE]="capture",l[Event.BUBBLING_PHASE]="bubble"},function(e,t,n){"use strict";
/**
 * @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 i;n.d(t,"c",(function(){return i})),n.d(t,"b",(function(){return r})),n.d(t,"a",(function(){return s})),function(e){e[e.UINT8=0]="UINT8",e[e.INT8=1]="INT8",e[e.UINT16=2]="UINT16",e[e.INT16=3]="INT16",e[e.UINT32=4]="UINT32",e[e.INT32=5]="INT32",e[e.UINT64=6]="UINT64",e[e.FLOAT32=7]="FLOAT32"}(i||(i={}));const r=[];r[i.UINT8]=!1,r[i.INT8]=!0,r[i.UINT16]=!1,r[i.INT16]=!0,r[i.UINT32]=!1,r[i.INT32]=!0,r[i.UINT64]=!1;const s=[];s[i.UINT8]=1,s[i.INT8]=1,s[i.UINT16]=2,s[i.INT16]=2,s[i.UINT32]=4,s[i.INT32]=4,s[i.UINT64]=8,s[i.FLOAT32]=4},function(e,t,n){var i=n(142),r=n(188),s=n(190),o=Math.max,a=Math.min;e.exports=function(e,t,n){var c,l,d,u,h,p,f=0,m=!1,g=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var n=c,i=l;return c=l=void 0,f=t,u=e.apply(i,n)}function y(e){return f=e,h=setTimeout(w,t),m?b(e):u}function S(e){var n=e-p;return void 0===p||n>=t||n<0||g&&e-f>=d}function w(){var e=r();if(S(e))return x(e);h=setTimeout(w,function(e){var n=t-(e-p);return g?a(n,d-(e-f)):n}(e))}function x(e){return h=void 0,v&&c?b(e):(c=l=void 0,u)}function C(){var e=r(),n=S(e);if(c=arguments,l=this,p=e,n){if(void 0===h)return y(p);if(g)return clearTimeout(h),h=setTimeout(w,t),b(p)}return void 0===h&&(h=setTimeout(w,t)),u}return t=s(t)||0,i(n)&&(m=!!n.leading,d=(g="maxWait"in n)?o(s(n.maxWait)||0,t):d,v="trailing"in n?!!n.trailing:v),C.cancel=function(){void 0!==h&&clearTimeout(h),f=0,c=p=l=h=void 0},C.flush=function(){return void 0===h?u:x(r())},C}},function(e,t,n){"use strict";n.d(t,"e",(function(){return a})),n.d(t,"d",(function(){return l})),n.d(t,"a",(function(){return u})),n.d(t,"b",(function(){return h})),n.d(t,"c",(function(){return p})),n.d(t,"g",(function(){return m})),n.d(t,"f",(function(){return g}));var i=n(39),r=n(2);
/**
 * @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 s=!("undefined"!=typeof Window&&self instanceof Window);var o=new Map;function a(e,t){o.set(e,t)}class c extends Error{constructor(e,t){super(t),this.name=e,this.message=t}}function l(e,t){a(e,(function(e){let n=e.id;const r=new i.b;let s=t.call(this,e,r);this.set(n,{promise:s,cancellationToken:r}),s.then(({value:e,transfers:t})=>{this.delete(n),this.invoke("rpc.promise.response",{id:n,value:e},t)},e=>{this.delete(n),this.invoke("rpc.promise.response",{id:n,error:e.message,errorName:e.name})})}))}a("rpc.promise.cancel",(function(e){let t=e.id;const n=this.get(t);if(void 0!==n){let{cancellationToken:e}=n;e.cancel()}})),a("rpc.promise.response",(function(e){let t=e.id,{resolve:n,reject:r}=this.get(t);if(this.delete(t),e.hasOwnProperty("value"))n(e.value);else{e.errorName===i.a.name?r(i.a):r(new c(e.errorName,e.error))}}));const d=s?-1:0;class u{constructor(e){this.target=e,this.objects=new Map,this.nextId=d,e.onmessage=e=>{let t=e.data;o.get(t.functionName).call(this,t)}}get numObjects(){return this.objects.size}set(e,t){this.objects.set(e,t)}delete(e){this.objects.delete(e)}get(e){return this.objects.get(e)}getRef(e){let t=e.id,n=this.get(t);return n.referencedGeneration=e.gen,n.addRef(),n}invoke(e,t,n){t.functionName=e,this.target.postMessage(t,n)}promiseInvoke(e,t,n=i.e,r){return Object(i.d)(n,(n,i,s)=>{const o=t.id=this.newId();this.set(o,{resolve:n,reject:i}),this.invoke(e,t,r),s.add(()=>{this.invoke("rpc.promise.cancel",{id:o})})})}newId(){return s?this.nextId--:this.nextId++}}class h extends r.a{constructor(){super(...arguments),this.rpc=null,this.rpcId=null}initializeSharedObject(e,t=e.newId()){this.rpc=e,this.rpcId=t,this.isOwner=!1,e.set(t,this)}initializeCounterpart(e,t={}){this.initializeSharedObject(e),this.unreferencedGeneration=0,this.referencedGeneration=0,this.isOwner=!0,t.id=this.rpcId,t.type=this.RPC_TYPE_ID,e.invoke("SharedObject.new",t)}dispose(){super.dispose()}addCounterpartRef(){return{id:this.rpcId,gen:++this.referencedGeneration}}refCountReachedZero(){!0===this.isOwner?this.referencedGeneration===this.unreferencedGeneration&&this.ownerDispose():!1===this.isOwner?this.rpc.invoke("SharedObject.refCountReachedZero",{id:this.rpcId,gen:this.referencedGeneration}):super.refCountReachedZero()}ownerDispose(){let{rpc:e,rpcId:t}=this;super.refCountReachedZero(),e.delete(t),e.invoke("SharedObject.dispose",{id:t})}counterpartRefCountReachedZero(e){this.unreferencedGeneration=e,0===this.refCount&&e===this.referencedGeneration&&this.ownerDispose()}}class p extends h{constructor(e,t={}){super(),function(e,t,n={}){null!=t&&e.initializeSharedObject(t,n.id)}(this,e,t)}}a("SharedObject.dispose",(function(e){let t=this.get(e.id);if(0!==t.refCount)throw new Error("Attempted to dispose object with non-zero reference count.");t.disposed(),this.delete(t.rpcId),t.rpcId=null,t.rpc=null})),a("SharedObject.refCountReachedZero",(function(e){let t=this.get(e.id),n=e.gen;t.counterpartRefCountReachedZero(n)}));const f=new Map;function m(e){return t=>{t.prototype.RPC_TYPE_ID=e}}function g(e){return t=>{if(void 0!==e)t.prototype.RPC_TYPE_ID=e;else if(void 0===(e=t.prototype.RPC_TYPE_ID))throw new Error("RPC_TYPE_ID should have already been defined");f.set(e,t)}}a("SharedObject.new",(function(e){let t=e.type;--new(f.get(t))(this,e).refCount}))},function(e,t,n){"use strict";n.d(t,"b",(function(){return a})),n.d(t,"c",(function(){return c})),n.d(t,"a",(function(){return l}));var i=n(15),r=n.n(i),s=n(2),o=n(3);
/**
 * @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 a{constructor(e,t=e){this.value_=e,this.defaultValue=t,this.changed=new o.a}get value(){return this.value_}set value(e){e!==this.value_&&(this.value_=e,this.changed.dispatch())}toggle(){this.value=!this.value}toJSON(){let{value_:e}=this;if(e!==this.defaultValue)return this.value_}restoreState(e){this.value=!0!==e&&!1!==e?this.defaultValue:e}reset(){this.value=this.defaultValue}}class c extends s.a{constructor(e){super(),this.model=e,this.element=document.createElement("input");let{element:t}=this;t.type="checkbox",this.registerDisposer(e.changed.add(()=>{this.updateCheckbox()})),this.updateCheckbox(),this.registerEventListener(t,"change",(function(t){e.value=this.checked})),t.addEventListener("mousedown",e=>{e.preventDefault()})}updateCheckbox(){this.element.checked=this.model.value}disposed(){let{element:e}=this,{parentElement:t}=e;t&&t.removeChild(e),super.disposed()}}class l extends s.a{constructor(e,t){super(),this.model=e,this.element=t,this.initialDisplay=this.element.style.display,this.updateVisibility(),this.registerDisposer(e.changed.add(this.registerCancellable(r()(()=>this.updateVisibility(),0))))}updateVisibility(){this.element.style.display=this.model.value?this.initialDisplay:"none"}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));
/**
 * @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 i=new Uint32Array(2);let r=[];for(let e=2;e<=36;++e){let t=Math.floor(32/Math.log2(e)),n=Math.pow(e,t),i=`^[0-${String.fromCharCode("0".charCodeAt(0)+Math.min(9,e-1))}`;e>10&&(i+=`a-${String.fromCharCode("a".charCodeAt(0)+e-11)}`,i+=`A-${String.fromCharCode("A".charCodeAt(0)+e-11)}`),i+=`]{1,${Math.ceil(64/Math.log2(e))}}$`;let s=new RegExp(i);r[e]={lowDigits:t,lowBase:n,pattern:s}}function s(e,t){const n=65535&(e>>>=0),i=e>>>16,r=65535&(t>>>=0),s=t>>>16;let o=(n*r>>>16)+i*r,a=o>>>16;o=(65535&o)+n*s,a+=o>>>16;let c=a>>>16;return a=(65535&a)+i*s,c+=a>>>16,((65535&c)<<16|65535&a)>>>0}class o{constructor(e=0,t=0){this.low=e,this.high=t}clone(){return new o(this.low,this.high)}assign(e){this.low=e.low,this.high=e.high}toString(e=10){let t=this.low,n=this.high;if(0===n)return t.toString(e);n*=4294967296;let{lowBase:i,lowDigits:s}=r[e],o=n%i;n=Math.floor(n/i),t+=o,n+=Math.floor(t/i),t%=i;let a=t.toString(e);return n.toString(e)+"0".repeat(s-a.length)+a}static less(e,t){return e.high<t.high||e.high===t.high&&e.low<t.low}static compare(e,t){return e.high-t.high||e.low-t.low}static equal(e,t){return e.low===t.low&&e.high===t.high}static min(e,t){return o.less(e,t)?e:t}static max(e,t){return o.less(e,t)?t:e}static random(){return crypto.getRandomValues(i),new o(i[0],i[1])}tryParseString(e,t=10){const{lowDigits:n,lowBase:i,pattern:o}=r[t];if(!o.test(e))return!1;if(e.length<=n)return this.low=parseInt(e,t),this.high=0,!0;const a=e.length-n,c=parseInt(e.substr(a),t),l=parseInt(e.substr(0,a),t);let d,u;if(4294967296===i)d=l,u=c;else{const e=Math.imul(l,i)>>>0;d=s(l,i)+(Math.imul(Math.floor(l/4294967296),i)>>>0),u=c+e,u>=4294967296&&(++d,u-=4294967296)}return u>>>0===u&&d>>>0===d&&(this.low=u,this.high=d,!0)}parseString(e,t=10){if(!this.tryParseString(e,t))throw new Error(`Failed to parse string as uint64 value: ${JSON.stringify(e)}.`);return this}static parseString(e,t=10){return(new o).parseString(e,t)}valid(){let{low:e,high:t}=this;return e>>>0===e&&t>>>0===t}toJSON(){return this.toString()}static lshift(e,t,n){const{low:i,high:r}=t;return 0===n?(e.low=i,e.high=r):n<32?(e.low=i<<n,e.high=r<<n|i>>>32-n):(e.low=0,e.high=i<<n-32),e}static rshift(e,t,n){const{low:i,high:r}=t;return 0===n?(e.low=i,e.high=r):n<32?(e.low=i>>>n|r<<32-n,e.high=r>>>n):(e.low=r>>>n-32,e.high=0),e}static or(e,t,n){return e.low=t.low|n.low,e.high=t.high|n.high,e}static xor(e,t,n){return e.low=t.low^n.low,e.high=t.high^n.high,e}static and(e,t,n){return e.low=t.low&n.low,e.high=t.high&n.high,e}static add(e,t,n){let i=t.low+n.low,r=t.high+n.high;const s=i>>>0;return s!==i&&(r+=1),e.low=s,e.high=r>>>0,e}static addUint32(e,t,n){let i=t.low+n,r=t.high;const s=i>>>0;return s!==i&&(r+=1),e.low=s,e.high=r>>>0,e}static decrement(e,t){let{low:n,high:i}=t;return 0===n&&(i-=1),e.low=n-1>>>0,e.high=i>>>0,e}static increment(e,t){let{low:n,high:i}=t;return 4294967295===n&&(i+=1),e.low=n+1>>>0,e.high=i>>>0,e}static subtract(e,t,n){let i=t.low-n.low,r=t.high-n.high;const s=i>>>0;return s!==i&&(r-=1),e.low=s,e.high=r>>>0,e}static multiplyUint32(e,t,n){const{low:i,high:r}=t;return e.low=Math.imul(i,n)>>>0,e.high=Math.imul(r,n)+s(i,n)>>>0,e}static lowMask(e,t){return 0===t?e.high=e.low=0:t<=32?(e.high=0,e.low=4294967295>>>32-t):(e.high=4294967295>>>t-32,e.low=4294967295),e}}o.ZERO=new o(0,0),o.ONE=new o(1,0)},function(e,t,n){"use strict";
/**
 * @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 i(e,t,n,i,r,s,o,a,c){for(let l=0;l<o;++l)for(let o=0;o<c;++o){let c=0;for(let e=0;e<a;++e)c+=n[l+i*e]*r[e+s*o];e[l+t*o]=c}return e}function r(e,t,n){for(let i=0;i<n;++i){const r=t*i;e.fill(0,r,r+n),e[r+i]=1}return e}function s(e,t,n=t){return r(new e(t*n),t,Math.min(t,n))}function o(e,t,n=!0){const i=t.length,r=n?i+1:i,s=new e(r*(i+1));n&&(s[s.length-1]=1);for(let e=0;e<i;++e)s[(r+1)*e]=t[e];return s}function a(e,t,n){for(let i=0;i<n;++i)for(let r=0;r<n;++r)if(e[i*t+r]!=(i===r?1:0))return!1;return!0}function c(e,t,n,i,r,s){for(let o=0;o<s;++o){const s=o*i,a=o*t;for(let t=0;t<r;++t)e[a+t]=n[s+t]}return e}function l(e,t,n,i){c(e,t+1,n,i+1,i,i);for(let r=0;r<i;++r)e[(t+1)*t+r]=n[(i+1)*i+r];e[e.length-1]=1;for(let n=i;n<t;++n)e[(t+1)*n+n]=1;return e}let d;function u(e,t,n,i,r){return c(e,t,n,i,r,r),function(e,t,n){let i=1;(void 0===d||d.length<n)&&(d=new Uint32Array(n));for(let e=0;e<n;++e)d[e]=e;for(let r=0;r<n;++r){const s=t*r;let o=r;{let t=Math.abs(e[s+r]);for(let i=r+1;i<n;++i){const n=Math.abs(e[s+i]);n>t&&(t=n,o=i)}}if(r!==o){i*=-1;for(let i=0;i<n;++i){const n=t*i,s=e[n+r];e[n+r]=e[n+o],e[n+o]=s}{const e=d[r];d[r]=d[o],d[o]=e}}const a=e[s+r],c=1/a;i*=a;for(let i=0;i<n;++i)e[t*i+r]*=c;e[s+r]=c;for(let i=0;i<n;++i){if(i===r)continue;const s=-e[t*r+i];for(let o=0;o<n;++o){const n=t*o;e[n+i]+=s*e[n+r]}e[t*r+i]=s*c}}for(let i=0;i<n;++i){let r=d[i];for(;r!==i;){const s=t*i,o=t*r;for(let t=0;t<n;++t){const n=s+t,i=o+t,r=e[n];e[n]=e[i],e[i]=r}const a=d[i]=d[r];d[r]=r,r=a}}return i}(e,t,r)}function h(e,t,n,i,r,s){for(let o=0;o<s;++o){const s=t*o,a=i*o;for(let t=0;t<r;++t)if(e[s+t]!==n[a+t])return!1}return!0}function p(e,t,n,i,r){for(let s=0;s<r;++s){let o=t[n*r+s];for(let e=0;e<r;++e)o+=t[n*e+s]*i[e];e[s]=o}return e}function f(e,t,n,i,r){for(let s=0;s<r;++s){let o=0;for(let e=0;e<r;++e)o+=t[n*e+s]*i[e];e[s]=o}return e}n.d(t,"i",(function(){return i})),n.d(t,"f",(function(){return r})),n.d(t,"c",(function(){return s})),n.d(t,"b",(function(){return o})),n.d(t,"h",(function(){return a})),n.d(t,"a",(function(){return c})),n.d(t,"e",(function(){return l})),n.d(t,"g",(function(){return u})),n.d(t,"d",(function(){return h})),n.d(t,"j",(function(){return p})),n.d(t,"k",(function(){return f}))},function(e,t,n){"use strict";n.d(t,"l",(function(){return r})),n.d(t,"g",(function(){return s})),n.d(t,"o",(function(){return o})),n.d(t,"q",(function(){return a})),n.d(t,"d",(function(){return c})),n.d(t,"p",(function(){return l})),n.d(t,"j",(function(){return d})),n.d(t,"e",(function(){return u})),n.d(t,"m",(function(){return h})),n.d(t,"h",(function(){return p})),n.d(t,"n",(function(){return f})),n.d(t,"i",(function(){return m})),n.d(t,"f",(function(){return g})),n.d(t,"k",(function(){return v})),n.d(t,"c",(function(){return b})),n.d(t,"b",(function(){return y})),n.d(t,"a",(function(){return x}));var i=n(14);
/**
 * @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 r="\nfloat mixLinear(float x, float y, float a) { return mix(x, y, a); }\n";var s="\nvec3 hueToRgb(float hue) {\n  float hue6 = hue * 6.0;\n  float r = abs(hue6 - 3.0) - 1.0;\n  float g = 2.0 - abs(hue6 - 2.0);\n  float b = 2.0 - abs(hue6 - 4.0);\n  return clamp(vec3(r, g, b), 0.0, 1.0);\n}\nvec3 hsvToRgb(vec3 c) {\n  vec3 hueRgb = hueToRgb(c.x);\n  return c.z * ((hueRgb - 1.0) * c.y + 1.0);\n}\n";const o="\nstruct uint64_t {\n  highp uvec2 value;\n};\nstruct uint64x2_t {\n  highp uvec4 value;\n};\nuint64_t mixLinear(uint64_t x, uint64_t y, float a) {\n  return x;\n}\nuint64_t toUint64(uint64_t x) { return x; }\n",a=[o,"\nuint64_t unpackUint64leFromUint32(highp uvec2 x) {\n  uint64_t result;\n  result.value = x;\n  return result;\n}\nuint64x2_t unpackUint64leFromUint32(highp uvec4 x) {\n  uint64x2_t result;\n  result.value = x;\n  return result;\n}\n"],c=[o,"\nbool equals(uint64_t a, uint64_t b) {\n  return a.value == b.value;\n}\n"],l=[o,"\nstruct uint8_t {\n  highp uint value;\n};\nstruct uint8x2_t {\n  highp uvec2 value;\n};\nstruct uint8x3_t {\n  highp uvec3 value;\n};\nstruct uint8x4_t {\n  highp uvec4 value;\n};\nuint8_t mixLinear(uint8_t x, uint8_t y, float a) {\n  return uint8_t(uint(round(mix(float(x.value), float(y.value), a))));\n}\nhighp uint toRaw(uint8_t x) { return x.value; }\nhighp float toNormalized(uint8_t x) { return float(x.value) / 255.0; }\nhighp uvec2 toRaw(uint8x2_t x) { return x.value; }\nhighp vec2 toNormalized(uint8x2_t x) { return vec2(x.value) / 255.0; }\nhighp uvec3 toRaw(uint8x3_t x) { return x.value; }\nvec3 toNormalized(uint8x3_t x) { return vec3(x.value) / 255.0; }\nhighp uvec4 toRaw(uint8x4_t x) { return x.value; }\nvec4 toNormalized(uint8x4_t x) { return vec4(x.value) / 255.0; }\nuint64_t toUint64(uint8_t x) {\n  uint64_t result;\n  result.value[0] = x.value;\n  result.value[1] = 0u;\n  return result;\n}\n"],d="\nstruct int8_t {\n  highp uint value;\n};\nstruct int8x2_t {\n  highp ivec2 value;\n};\nstruct int8x3_t {\n  highp ivec3 value;\n};\nstruct int8x4_t {\n  highp ivec4 value;\n};\nint8_t mixLinear(int8_t x, int8_t y, float a) {\n  return int8_t(int(round(mix(float(x.value), float(y.value), a))));\n}\nhighp int toRaw(int8_t x) { return x.value; }\nhighp ivec2 toRaw(int8x2_t x) { return x.value; }\nhighp ivec3 toRaw(int8x3_t x) { return x.value; }\nhighp ivec4 toRaw(int8x4_t x) { return x.value; }\n",u="\nfloat toRaw(float x) { return x; }\nfloat toNormalized(float x) { return x; }\nvec2 toRaw(vec2 x) { return x; }\nvec2 toNormalized(vec2 x) { return x; }\nvec3 toRaw(vec3 x) { return x; }\nvec3 toNormalized(vec3 x) { return x; }\nvec4 toRaw(vec4 x) { return x; }\nvec4 toNormalized(vec4 x) { return x; }\n",h=[o,"\nstruct uint16_t {\n  highp uint value;\n};\nstruct uint16x2_t {\n  highp uvec2 value;\n};\nuint16_t mixLinear(uint16_t x, uint16_t y, float a) {\n  return uint16_t(uint(round(mix(float(x.value), float(y.value), a))));\n}\nhighp uint toRaw(uint16_t x) { return x.value; }\nhighp float toNormalized(uint16_t x) { return float(toRaw(x)) / 65535.0; }\nhighp uvec2 toRaw(uint16x2_t x) { return x.value; }\nhighp vec2 toNormalized(uint16x2_t x) { return vec2(toRaw(x)) / 65535.0; }\nuint64_t toUint64(uint16_t x) {\n  uint64_t result;\n  result.value[0] = x.value;\n  result.value[1] = 0u;\n  return result;\n}\n"],p="\nstruct int16_t {\n  highp int value;\n};\nstruct int16x2_t {\n  highp ivec2 value;\n};\nint16_t mixLinear(int16_t x, int16_t y, float a) {\n  return int16_t(int(round(mix(float(x.value), float(y.value), a))));\n}\nhighp int toRaw(int16_t x) { return x.value; }\nhighp ivec2 toRaw(int16x2_t x) { return x.value; }\n",f=[o,"\nstruct uint32_t {\n  highp uint value;\n};\nuint32_t mixLinear(uint32_t x, uint32_t y, float a) {\n  return uint32_t(uint(round(mix(float(x.value), float(y.value), a))));\n}\nhighp float toNormalized(uint32_t x) { return float(x.value) / 4294967295.0; }\nhighp uint toRaw(uint32_t x) { return x.value; }\nuint64_t toUint64(uint32_t x) {\n  uint64_t result;\n  result.value[0] = x.value;\n  result.value[1] = 0u;\n  return result;\n}\n"],m="\nstruct int32_t {\n  highp int value;\n};\nint32_t mixLinear(int32_t x, int32_t y, float a) {\n  return int32_t(int(round(mix(float(x.value), float(y.value), a))));\n}\nhighp int toRaw(int32_t x) { return x.value; }\n";var g="\nhighp int getFortranOrderIndex(ivec3 subscripts, ivec3 size) {\n  return subscripts.x + size.x * (subscripts.y + size.y * subscripts.z);\n}\n";const v="\nhighp uint log2Exact(highp uint i) {\n  highp uint r;\n  r = uint((i & 0xAAAAAAAAu) != 0u);\n  r |= uint((i & 0xFFFF0000u) != 0u) << 4;\n  r |= uint((i & 0xFF00FF00u) != 0u) << 3;\n  r |= uint((i & 0xF0F0F0F0u) != 0u) << 2;\n  r |= uint((i & 0xCCCCCCCCu) != 0u) << 1;\n  return r;\n}\n",b="\nbool clipLineToDepthRange(inout vec4 a, inout vec4 b) {\n  float tmin = 0.0, tmax = 1.0;\n  float k1 = b.w - a.w + a.z - b.z;\n  float k2 = a.w - b.w + a.z - b.z;\n  float q1 = (a.z - a.w) / k1;\n  float q2 = (a.z + a.w) / k2;\n  if (k1 > 0.0) tmin = max(tmin, q1);\n  else if (k1 < 0.0) tmax = min(tmax, q1);\n  if (k2 > 0.0) tmax = min(tmax, q2);\n  else if (k2 < 0.0) tmin = max(tmin, q2);\n  if (tmin <= tmax) {\n    vec4 tempA = a;\n    vec4 tempB = b;\n    a = mix(tempA, tempB, tmin);\n    b = mix(tempA, tempB, tmax);\n    return true;\n  }\n  return false;\n}\n";function y(e,t=1){switch(e){case i.c.FLOAT32:if(1===t)return"float";if(t>1&&t<=4)return`vec${t}`;break;case i.c.UINT8:case i.c.INT8:case i.c.UINT16:case i.c.INT16:case i.c.UINT32:case i.c.INT32:case i.c.UINT64:{const n=i.b[e]?"":"u",r=8*i.a[e];if(1===t)return`${n}int${r}_t`;if(t>1&&t*r<=32)return`${n}int${r}x${t}_t`;break}}throw new Error(`No shader type for ${i.c[e]}[${t}].`)}function S(e,t){return 1===t?e:"float"===e?`vec${t}`:`${e[0]}vec${t}`}const w={[WebGL2RenderingContext.UNSIGNED_BYTE]:1,[WebGL2RenderingContext.BYTE]:1,[WebGL2RenderingContext.UNSIGNED_SHORT]:2,[WebGL2RenderingContext.SHORT]:2,[WebGL2RenderingContext.FLOAT]:4,[WebGL2RenderingContext.INT]:4,[WebGL2RenderingContext.UNSIGNED_INT]:4};function x(e,t,n,i,r,s,o=1){let a=0,c=s*o;for(;c>0;){const n=Math.min(4,c),i=S(t,n);c-=n,e.addAttribute("highp "+i,`a${r}${a}`),++a}c=s*o;let l="";for(let e=0;e<o;++e){l+=`highp ${t}[${s}] get${r}${e}() {\n  highp ${t}[${s}] result;\n`;for(let t=0;t<s;++t){const n=e*s+t,i=Math.floor(n/4),o=n%4;l+=`  result[${t}] = a${r}${i}`,0===o&&n===c-1||(l+=`[${o}]`),l+=";\n"}l+="  return result;\n",l+="}\n"}e.addVertexCode(l);const d=w[n];e.addInitializer(e=>{const s=[];for(let t=0;t<a;++t)s[t]=e.attribute(`a${r}${t}`);e.vertexShaderInputBinders[r]={enable(t){const{gl:n}=e;for(let e=0;e<a;++e){const i=s[e];n.enableVertexAttribArray(i),n.vertexAttribDivisor(i,t)}},disable(){const{gl:t}=e;for(let e=0;e<a;++e){const n=s[e];t.vertexAttribDivisor(n,0),t.disableVertexAttribArray(n)}},bind(r,o){const{gl:l}=e;for(let e=0;e<a;++e){const a=s[e],u=Math.min(4,c-4*e);"float"===t?l.vertexAttribPointer(a,u,n,i,r,o):l.vertexAttribIPointer(a,Math.min(4,c-4*e),n,r,o),o+=d*u}}}})}},function(e,t,n){"use strict";n.d(t,"h",(function(){return i})),n.d(t,"k",(function(){return S})),n.d(t,"e",(function(){return O})),n.d(t,"j",(function(){return k})),n.d(t,"d",(function(){return E})),n.d(t,"p",(function(){return T})),n.d(t,"f",(function(){return D})),n.d(t,"q",(function(){return j})),n.d(t,"n",(function(){return I})),n.d(t,"c",(function(){return P})),n.d(t,"a",(function(){return A})),n.d(t,"g",(function(){return R})),n.d(t,"r",(function(){return N})),n.d(t,"l",(function(){return _})),n.d(t,"o",(function(){return B})),n.d(t,"m",(function(){return F})),n.d(t,"b",(function(){return z})),n.d(t,"i",(function(){return U}));var i,r,s=n(5),o=n(7),a=n(2),c=n(1),l=n(0),d=n(3),u=n(24),h=n(106),p=n(37);!function(e){e[e.LINKED=0]="LINKED",e[e.RELATIVE=1]="RELATIVE",e[e.UNLINKED=2]="UNLINKED"}(i||(i={})),function(e){e[e.LINKED=0]="LINKED",e[e.UNLINKED=2]="UNLINKED"}(r||(r={}));class f extends h.a{constructor(e=i.LINKED){super(i,e)}}class m extends h.a{constructor(e=r.LINKED){super(r,e)}}const g=c.u.create(),v=c.p.create();function b(e,t,n,r){let s,o=!1;e.registerDisposer(t);let a=i.UNLINKED;const c=()=>{const o=n.value;if(o!==a)switch(o){case i.UNLINKED:s=void 0;break;case i.LINKED:s=void 0,r.assign(e,t);break;case i.RELATIVE:s=r.difference(e,t)}a=o,e.changed.dispatch()};return e.registerDisposer(e.changed.add(()=>{if(!o)switch(n.value){case i.UNLINKED:break;case i.LINKED:r.assign(t,e);break;case i.RELATIVE:r.subtract(t,e,s)}})),e.registerDisposer(t.changed.add(()=>{switch(o=!0,n.value){case i.UNLINKED:if(r.isValid(e))break;case i.LINKED:r.assign(e,t);break;case i.RELATIVE:r.add(e,t,s)}o=!1})),e.registerDisposer(n.changed.add(c)),c(),e}function y(e,t,n,i){return b(e,t,n,i)}class S extends a.a{constructor(e){super(),this.coordinateSpace=e,this.coordinates_=p.b,this.changed=new d.a,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_=p.b,this.changed.dispatch()}set value(e){const{curCoordinateSpace:t}=this;if(void 0===t||!t.valid||t.rank!==e.length)return;const{coordinates_:n}=this;n.set(e),this.changed.dispatch()}handleCoordinateSpaceChanged(){const e=this.coordinateSpace.value,t=this.curCoordinateSpace;if(e===t)return;this.curCoordinateSpace=e;const{rank:n}=e;if(!e.valid)return;if(void 0===t||!t.valid){let{coordinates_:t}=this;if(void 0!==t&&t.length===n);else{t=this.coordinates_=new Float32Array(n),Object(s.n)(t,e.bounds);for(let e=0;e<n;++e)t[e]=Math.floor(t[e])+.5}return void this.changed.dispatch()}const i=new Float32Array(n),r=this.coordinates_,{ids:o,scales:a}=e,{ids:c,scales:l}=t;for(let t=0;t<n;++t){const n=o[t],d=c.indexOf(n);i[t]=-1===d?Object(s.o)(e.bounds.lowerBounds[t],e.bounds.upperBounds[t]):r[d]*(l[d]/a[t])}this.coordinates_=i,this.changed.dispatch()}toJSON(){if(!this.valid)return;this.handleCoordinateSpaceChanged();const{value:e}=this;return 0!==e.length?Array.from(e):void 0}restoreState(e){void 0!==e?(this.curCoordinateSpace=void 0,this.coordinates_=Float32Array.from(Object(l.b)(e,l.p)),this.handleCoordinateSpaceChanged(),this.changed.dispatch()):this.reset()}snapToVoxel(){this.handleCoordinateSpaceChanged();const{coordinates_:e}=this,t=e.length;for(let n=0;n<t;++n)e[n]=Math.floor(e[n])+.5;this.changed.dispatch()}assign(e){e.handleCoordinateSpaceChanged();const{curCoordinateSpace:t,coordinates_:n}=e;this.curCoordinateSpace=t,this.coordinates_=Float32Array.from(n),this.changed.dispatch()}static getOffset(e,t){const n=e.coordinates_,i=t.coordinates_;if(n.length===i.length)return p.h(new Float32Array(n.length),n,i)}static addOffset(e,t,n,i=1){e.handleCoordinateSpaceChanged();const{value:r}=t;void 0!==n&&r.length===n.length&&(p.g(e.value,r,n,i),e.changed.dispatch())}get legacyJsonView(){const e=this;return{changed:e.changed,toJSON:()=>e.toJSON(),reset(){e.reset()},restoreState(t){void 0===t||Array.isArray(t)?e.restoreState(t):(Object(l.w)(t),Object(u.d)(t,"voxelCoordinates",e))}}}}function w(e,t,n){void 0!==n&&0!==Object.keys(n).length?(Object(l.w)(n),e.value=i.UNLINKED,Object(l.y)(n,"value",e=>{void 0!==e&&t.restoreState(e)}),Object(l.y)(n,"link",t=>e.restoreState(t))):e.value=i.LINKED}class x{constructor(e,t=new f){this.peer=e,this.link=t}get changed(){return this.value.changed}toJSON(){const{link:e}=this;if(e.value!==i.LINKED)return{link:e.toJSON(),value:this.getValueJson()}}getValueJson(){return this.value.toJSON()}reset(){this.link.value=i.LINKED}restoreState(e){w(this.link,this.value,e)}copyToPeer(){this.link.value!==i.LINKED&&(this.link.value=i.UNLINKED,this.peer.assign(this.value),this.link.value=i.LINKED)}}class C extends x{constructor(e,t=new m){super(e,t)}}class O extends x{constructor(){super(...arguments),this.value=b(new S(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,t)=>e.assign(t),isValid:e=>e.valid,difference:S.getOffset,add:S.addOffset,subtract:(e,t,n)=>{S.addOffset(e,t,n,-1)}})}}class k extends a.a{constructor(e){super(),this.changed=new d.a,null==e&&(e=c.p.create()),this.orientation=e}toJSON(){let{orientation:e}=this;var t;if(c.p.normalize(this.orientation,this.orientation),0!==(t=e)[0]||0!==t[1]||0!==t[2]||1!==t[3])return Array.prototype.slice.call(this.orientation)}restoreState(e){try{Object(l.c)(this.orientation,e),c.p.normalize(this.orientation,this.orientation)}catch(e){c.p.identity(this.orientation)}this.changed.dispatch()}reset(){c.p.identity(this.orientation),this.changed.dispatch()}snap(){let e=c.k.create();c.k.fromQuat(e,this.orientation);let t=[!1,!1,!1];for(let n=0;n<3;++n){let i=0,r=0;for(let s=0;s<3;++s){let o=e[3*n+s];e[3*n+s]=0,t[s]||Math.abs(o)>Math.abs(i)&&(i=o,r=s)}e[3*n+r]=Math.sign(i),t[r]=!0}c.p.fromMat3(this.orientation,e),this.changed.dispatch()}static makeRelative(e,t){let n=new k(c.p.multiply(c.p.create(),e.orientation,t)),i=!1;n.registerDisposer(e.changed.add(()=>{i||(r=!0,c.p.multiply(n.orientation,e.orientation,t),n.changed.dispatch(),r=!1)}));let r=!1;const s=c.p.invert(c.p.create(),t);return n.registerDisposer(n.changed.add(()=>{r||(i=!0,c.p.multiply(e.orientation,n.orientation,s),e.changed.dispatch(),i=!1)})),n}assign(e){c.p.copy(this.orientation,e.orientation),this.changed.dispatch()}}class E extends x{constructor(){super(...arguments),this.value=b(new k,this.peer,this.link,{assign:(e,t)=>e.assign(t),isValid:()=>!0,difference:(e,t)=>{const n=c.p.create();return c.p.multiply(n,c.p.invert(n,t.orientation),e.orientation)},add:(e,t,n)=>{c.p.multiply(e.orientation,t.orientation,n),e.changed.dispatch()},subtract:(e,t,n)=>{c.p.multiply(e.orientation,t.orientation,c.p.invert(v,n)),e.changed.dispatch()}})}}class T extends a.a{constructor(e){super(),this.coordinateSpace=e,this.changed=new d.a,this.curCoordinateSpace=s.k,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=s.k,this.changed.dispatch()}toJSON(){const e={};let t=!1;const{value:n}=this,{factors:i}=n,{names:r,rank:s}=this.curCoordinateSpace;for(let n=0;n<s;++n){const s=i[n];1!==s&&(e[r[n]]=s,t=!0)}if(t)return e}restoreState(e){const{coordinateSpace:{value:t}}=this,{names:n,rank:i}=t,r=new Float64Array(i);if(r.fill(-1),void 0!==e){const t=Object(l.w)(e);for(let e=0;e<i;++e)r[e]=Object(l.y)(t,n[e],e=>void 0===e?1:Object(l.r)(e))}this.value_={factors:r},this.curCoordinateSpace=t,this.changed.dispatch()}setFactors(e){const{coordinateSpace:{value:t}}=this;e.length===t.rank&&(this.value_={factors:e},this.curCoordinateSpace=t,this.changed.dispatch())}update(){const{coordinateSpace:{value:e}}=this;let t=this.value_;const{curCoordinateSpace:n}=this;if(n===e)return t;const{ids:i}=n,{ids:r,rank:s}=e,a=t.factors,c=new Float64Array(s);c.fill(1);for(let e=0;e<s;++e){const t=r[e],n=i.indexOf(t);-1!==n&&(c[e]=a[n])}return Object(o.a)(c,a)?t:(t=this.value_={factors:c},this.curCoordinateSpace=e,this.changed.dispatch(),t)}assign(e){this.setFactors(e.value.factors)}}function M(e,t,n,i,r){if(n===i)return t;const{ids:s}=n,{rank:o,ids:a}=i,c=new e(o);for(let e=0;e<o;++e){const n=a[e],i=s.indexOf(n);c[e]=-1===i?r(e):t[i]}return c}class D extends x{constructor(){super(...arguments),this.value=b(new T(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,t)=>e.assign(t),difference:(e,t)=>{const{factors:n}=e.value,i=e.coordinateSpace.value,r=t.value.factors;return{coordinateSpace:i,offsets:p.h(new Float64Array(n.length),n,r)}},add:(e,t,n)=>{const i=M(Float64Array,n.offsets,n.coordinateSpace,e.coordinateSpace.value,()=>0);e.setFactors(p.a(new Float64Array(i.length),i,t.value.factors))},subtract:(e,t,n)=>{const i=M(Float64Array,n.offsets,n.coordinateSpace,e.coordinateSpace.value,()=>0);e.setFactors(p.h(new Float64Array(i.length),t.value.factors,i))},isValid:()=>!0})}}function L(e,t,n){const{rank:i,names:r,units:s}=e,{displayRank:o,displayDimensionIndices:a}=t,c=new Float64Array(3);let l,d=new Float64Array(3);const{factors:u}=n,h=new Array(3),p=new Float64Array(3);if(c.fill(1),d.fill(1),p.fill(1),h.fill(""),0===o)l=1;else{l=Number.POSITIVE_INFINITY;const{scales:t}=e;for(let e=0;e<o;++e){const n=a[e],i=d[e]=u[n]*t[n];l=Math.min(l,i),h[e]=s[n],p[e]=t[n]}for(let e=0;e<o;++e)c[e]=d[e]/l}return{globalRank:i,globalDimensionNames:r,displayRank:o,displayDimensionIndices:a,displayDimensionUnits:h,displayDimensionScales:p,canonicalVoxelFactors:c,voxelPhysicalScales:d,canonicalVoxelPhysicalSize:l}}class j extends a.a{constructor(e,t){super(),this.relativeDisplayScales=e,this.displayDimensions=t,this.changed=new d.a,this.curRelativeDisplayScales=this.relativeDisplayScales.value,this.curDisplayDimensions=this.displayDimensions.value,this.curCoordinateSpace=this.relativeDisplayScales.coordinateSpace.value,this.value_=L(this.curCoordinateSpace,this.curDisplayDimensions,this.curRelativeDisplayScales),this.registerDisposer(e),this.registerDisposer(t);const n=()=>{this.value};this.registerDisposer(e.changed.add(n)),this.registerDisposer(t.changed.add(n))}get value(){const{relativeDisplayScales:{value:e,coordinateSpace:{value:t}},displayDimensions:{value:n},curRelativeDisplayScales:i,curDisplayDimensions:r,curCoordinateSpace:s}=this;let a=this.value_;if(i!==e||r!==n||s!==t){this.curRelativeDisplayScales=e,this.curDisplayDimensions=n,this.curCoordinateSpace=t;const i=L(t,n,e);c=a,l=i,Object(o.a)(c.globalDimensionNames,l.globalDimensionNames)&&Object(o.a)(c.displayDimensionIndices,l.displayDimensionIndices)&&Object(o.a)(c.canonicalVoxelFactors,l.canonicalVoxelFactors)&&Object(o.a)(c.voxelPhysicalScales,l.voxelPhysicalScales)&&c.canonicalVoxelPhysicalSize===l.canonicalVoxelPhysicalSize&&Object(o.a)(c.displayDimensionUnits,l.displayDimensionUnits)&&Object(o.a)(c.displayDimensionScales,l.displayDimensionScales)||(this.value_=a=i,this.changed.dispatch())}var c,l;return a}}class I extends a.a{constructor(e){super(),this.coordinateSpace=e,this.changed=new d.a,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,t=this.value_;if(void 0!==t&&t.coordinateSpace===e)return;if(void 0===t||this.default_)return void this.setToDefault(e);const n=new Int32Array(3),{ids:i}=t.coordinateSpace,{ids:r}=e,s=t.displayDimensionIndices,o=t.displayRank;let a=0;for(let e=0;e<o;++e){const t=r.indexOf(i[s[e]]);-1!==t&&(n[a]=t,++a)}if(n.fill(-1,a),0===a)return this.default_=!0,void this.setToDefault(e);this.assignValue(e,a,n),this.changed.dispatch()}setToDefault(e){const t=Math.min(e.rank,3),n=new Int32Array(3);n.fill(-1);for(let e=0;e<t;++e)n[e]=e;this.assignValue(e,t,n)}assignValue(e,t,n){this.value_={coordinateSpace:e,displayRank:t,displayDimensionIndices:n},this.changed.dispatch()}reset(){this.default_=!0,this.value_=void 0,this.changed.dispatch()}restoreState(e){if(void 0===e)return void this.reset();const t=Object(s.j)(e);if(t.length>3)throw new Error("Number of spatial dimensions must be <= 3");const{coordinateSpace:{value:n}}=this,i=new Int32Array(3);i.fill(-1);const{names:r}=n;let o=0;for(const e of t){const t=r.indexOf(e);-1!==t&&(i[o++]=t)}0!==o?(this.default_=!1,this.assignValue(n,o,i)):this.reset()}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,t){this.default_=!1,this.assignValue(this.coordinateSpace.value,e,t)}toJSON(){if(this.default_)return;const{value:e}=this,t=[],{displayRank:n,displayDimensionIndices:i,coordinateSpace:{names:r}}=e;if(0!==n){for(let e=0;e<n;++e)t[e]=r[i[e]];return t}}assign(e){if(e.default)this.default=!0;else{const{displayRank:t,displayDimensionIndices:n}=e.value;this.setDimensionIndices(t,n)}}}class P extends C{constructor(e){super(e),this.value=y(new I(this.peer.coordinateSpace),this.peer,this.link,{assign:(e,t)=>e.assign(t),isValid:()=>!0})}}class A extends a.a{constructor(e,t,n){super(),this.position=e,this.displayDimensionRenderInfo=t,this.orientation=n,this.changed=new d.a,this.registerDisposer(e),this.registerDisposer(n),this.registerDisposer(t),this.registerDisposer(e.changed.add(this.changed.dispatch)),this.registerDisposer(n.changed.add(this.changed.dispatch)),this.registerDisposer(t.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,t=g){const{coordinateSpace:{value:n},value:i}=this.position,{displayDimensionIndices:r,displayRank:s}=this.displayDimensions.value;if(void 0===n)return!1;t.fill(0);for(let e=0;e<s;++e){const n=r[e];t[e]=i[n]}if(!1!==e(t)){for(let e=0;e<s;++e){i[r[e]]=t[e]}return this.position.changed.dispatch(),!0}return!1}toMat4(e,t){c.m.fromQuat(e,this.orientation.orientation);const{value:n}=this.position,{canonicalVoxelFactors:i,displayDimensionIndices:r}=this.displayDimensionRenderInfo.value;for(let s=0;s<3;++s){const o=r[s],a=t/i[s];e[s]*=a,e[4+s]*=a,e[8+s]*=a,e[12+s]=n[o]||0}}toMat3(e,t){c.k.fromQuat(e,this.orientation.orientation);const{canonicalVoxelFactors:n,displayRank:i}=this.displayDimensionRenderInfo.value;for(let r=0;r<i;++r){const i=t/n[r];e[r]*=i,e[3+r]*=i,e[6+r]*=i}}snap(){this.orientation.snap(),this.position.snapToVoxel(),this.changed.dispatch()}translateDimensionRelative(e,t){if(!this.valid)return;const{position:n}=this,{value:i}=n,{bounds:{lowerBounds:r,upperBounds:s}}=n.coordinateSpace.value;let o=i[e]+t;if(t>0){const t=s[e];Number.isFinite(t)&&(o=Math.min(o,Math.ceil(t-1)))}else{const t=r[e];Number.isFinite(t)&&(o=Math.max(o,Math.floor(t)))}i[e]=o,n.changed.dispatch()}translateVoxelsRelative(e,t=!1){if(!this.valid)return;const n=c.u.transformQuat(g,e,this.orientation.orientation),{position:i}=this,{value:r}=i,{displayDimensionIndices:s,displayRank:o}=this.displayDimensions.value,{bounds:{lowerBounds:a,upperBounds:l}}=i.coordinateSpace.value;for(let e=0;e<o;++e){const i=s[e],o=n[e];if(0===o)continue;let c=r[i]+o;if(o>0){const e=l[i];Number.isFinite(e)&&(c=Math.min(c,Math.ceil(e-1)))}else{const e=a[i];Number.isFinite(e)&&(c=Math.max(c,Math.floor(e)))}t&&(c=Math.floor(c)+.5),r[i]=c}this.position.changed.dispatch()}rotateRelative(e,t){var n=c.p.create();c.p.setAxisAngle(n,e,t);var i=this.orientation.orientation;c.p.multiply(i,i,n),this.orientation.changed.dispatch()}rotateAbsolute(e,t,n){const{coordinateSpace:{value:i},value:r}=this.position;if(void 0===i)return;const{relativeDisplayScales:{value:{factors:s}},displayDimensions:{value:{displayDimensionIndices:o,displayRank:a}}}=this,{scales:l}=i,d=c.p.create();c.p.setAxisAngle(d,e,t);const u=this.orientation.orientation,h=g;g.fill(0);for(let e=0;e<a;++e){const t=o[e],i=n[t]-r[t];h[e]=i*l[t]*s[t]}const p=c.p.invert(v,u);c.u.transformQuat(h,h,p),c.p.multiply(u,d,u),c.u.transformQuat(h,h,u);for(let e=0;e<a;++e){const t=o[e];r[t]=n[t]-h[e]/(l[t]*s[e])}this.position.changed.dispatch(),this.orientation.changed.dispatch()}translateNonDisplayDimension(e,t){if(!this.valid)return;const{displayDimensionIndices:n}=this.displayDimensions.value,{position:i}=this,r=i.coordinateSpace.value.rank;for(let i=0;i<r;++i)if(-1===n.indexOf(i)&&0==e--)return void this.translateDimensionRelative(i,t)}}class R extends x{constructor(e,t){super(e),this.value=(()=>{const n=new e.constructor(t);return b(n,this.peer,this.link,{assign:(e,t)=>{e.assign(t)},isValid:e=>e.coordinateSpaceValue.valid&&0!==e.canonicalVoxelPhysicalSize,difference:(e,t)=>e.value/t.value*(e.canonicalVoxelPhysicalSize/t.canonicalVoxelPhysicalSize),add:(e,t,n)=>{e.setPhysicalScale(t.value*n,t.canonicalVoxelPhysicalSize)},subtract:(e,t,n)=>{e.setPhysicalScale(t.value/n,t.canonicalVoxelPhysicalSize)}}),n})()}}function N(e){return{changed:e.changed,toJSON:()=>e.toJSON(),restoreState(t){w(e.link,e.value.legacyJsonView,t)},reset(){e.reset()}}}class V extends a.a{constructor(e){super(),this.displayDimensionRenderInfo=e,this.changed=new d.a,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:t}=this;Object.is(e,this.value_)&&t===this.curCanonicalVoxelPhysicalSize||(this.curCanonicalVoxelPhysicalSize=t,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:t},relativeDisplayScales:{coordinateSpace:{value:n}}}}=this,{curCanonicalVoxelPhysicalSize:i}=this;(Number.isNaN(e)||t!==i)&&(Number.isNaN(e)?n.valid&&0!==t&&(this.curCanonicalVoxelPhysicalSize=t,this.value_=this.getDefaultValue(),this.changed.dispatch()):0!==i&&(this.value_=e*(i/t),this.curCanonicalVoxelPhysicalSize=t,this.changed.dispatch()))}toJSON(){const{value:e}=this;return Number.isNaN(e)?void 0:e}restoreState(e){this.curCanonicalVoxelPhysicalSize=0,this.legacyValue_=Number.NaN,this.value_=void 0===e?Number.NaN:Object(l.r)(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:()=>e.toJSON(),reset:()=>e.reset(),restoreState(t){e.legacyValue=Object(l.r)(t)}}}setPhysicalScale(e,t){const n=this.curCanonicalVoxelPhysicalSize=this.canonicalVoxelPhysicalSize;this.value=e*(t/n)}assign(e){const{legacyValue:t}=e;Number.isNaN(t)?this.setPhysicalScale(e.value,e.canonicalVoxelPhysicalSize):this.legacyValue=t}}class _ extends V{getDefaultValue(){const{legacyValue_:e}=this;if(Number.isNaN(e))return 1;const{canonicalVoxelPhysicalSize:t}=this;return 1e-9*this.legacyValue_/t}}class B extends V{getDefaultValue(){const{legacyValue_:e}=this;if(!Number.isNaN(e)){this.legacyValue_=Number.NaN;const{canonicalVoxelPhysicalSize:t}=this;return 200*Math.tan(Math.PI/8)*1e-9*e/t}const{coordinateSpaceValue:{bounds:{lowerBounds:t,upperBounds:n}}}=this,{canonicalVoxelFactors:i,displayDimensionIndices:r}=this.displayDimensionRenderInfo.value;let s=i.reduce((e,i,s)=>{const o=r[s],a=(n[o]-t[o])*i;return Math.max(e,a)},0);return s=Number.isFinite(s)?2**Math.ceil(Math.log2(s)):1024,s}}class F extends a.a{constructor(e,t){super(),this.defaultValue=e,this.displayDimensionRenderInfo=t,this.changed=new d.a,this.value_=e,this.canonicalVoxelPhysicalSize=t.value.canonicalVoxelPhysicalSize,this.registerDisposer(t.changed.add(()=>{this.value}))}get value(){let{value_:e}=this;if(e>0){const{canonicalVoxelPhysicalSize:t}=this.displayDimensionRenderInfo.value,n=this.canonicalVoxelPhysicalSize;t!==n&&(this.canonicalVoxelPhysicalSize=t,e=this.value_=e=n/t,this.changed.dispatch())}return e}set value(e){if(e===this.value)return;this.value_=e;const{canonicalVoxelPhysicalSize:t}=this.displayDimensionRenderInfo.value;this.canonicalVoxelPhysicalSize=t,this.changed.dispatch()}toJSON(){const{value:e}=this;if(e!==this.defaultValue)return e}reset(){this.value=this.defaultValue}restoreState(e){"number"==typeof e&&Number.isFinite(e)&&0!==e?this.value=e:this.value=this.defaultValue}setValueAbsolute(e,t){if(e>0){const{canonicalVoxelPhysicalSize:n}=this.displayDimensionRenderInfo.value;e*=t/n}this.value=e}assign(e){this.setValueAbsolute(e.value,e.canonicalVoxelPhysicalSize)}}class z extends C{constructor(e,t){super(e),this.value=y(new F(e.defaultValue,t),this.peer,this.link,{assign:(e,t)=>e.assign(t),isValid:()=>!0})}}class U extends a.a{constructor(e,t,n){super(),this.pose=e,this.zoomFactor=t,this.depthRange=n,this.changed=new d.a,this.registerDisposer(e),this.registerDisposer(t),this.registerDisposer(n),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}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"f",(function(){return a})),n.d(t,"g",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"e",(function(){return d})),n.d(t,"d",(function(){return u}));var i=n(39),r=n(18);
/**
 * @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 s extends Error{constructor(e,t,n){let i=`Fetching ${JSON.stringify(e)} resulted in HTTP error ${t}`;n&&(i+=`: ${n}`),i+=".",super(i),this.name="HttpError",this.message=i,this.url=e,this.status=t,this.statusText=n}static fromResponse(e){return new s(e.url,e.status,e.statusText)}}async function o(e,t){let n;try{n=await fetch(e,t)}catch(t){if(t instanceof TypeError){let t;throw t="string"==typeof e?e:e.url,new s(t,0,"Network or CORS error")}throw t}if(!n.ok)throw s.fromResponse(n);return n}function a(e){return e.arrayBuffer()}function c(e){return e.json()}async function l(e,t,n,r=i.e){if(r===i.e){const i=await o(e,t);return await n(i)}const s=new AbortController,a=r.add(()=>s.abort());try{const i=await o(e,t);return await n(i)}finally{a()}}new r.a;function d(e){let t=e.match(/^([^:\/]+):\/\/([^\/]+)((?:\/.*)?)$/);if(null===t)throw new Error(`Invalid URL: ${JSON.stringify(e)}`);return{protocol:t[1],host:t[2],path:t[3]}}function u(e){const t=d(e);return"gs"===t.protocol?`https://storage.googleapis.com/${t.host}${t.path}`:e}},function(e,t,n){"use strict";var i=n(15),r=n.n(i),s=n(92),o=n.n(s),a=n(5),c=n(34),l=n(79),d=n(21),u=n(117),h=n(4),p=(n(206),n(50)),f=n(59),m=n(25),g=n(17),v=n(30),b=n(14),y=n(2),S=n(6),w=n(57),x=n(134),C=(n(208),n(174)),O=n.n(C),k=n(107),E=n.n(k),T=n(7),M=n(11),D=n(19),L=n(51),j=n(40),I=n(27);
/**
 * @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 P(e,t=e.value){e.style.minWidth=t.length+1+"ch"}function A(e,t){let n,i;return n=e===Number.NEGATIVE_INFINITY?"(-∞,":`[${Math.floor(e)},`,i=t===Number.POSITIVE_INFINITY?"+∞)":`${Math.floor(t)})`,{lower:n,upper:i}}const R=L.a.fromObject({arrowup:{action:"move-up"},arrowdown:{action:"move-down"},arrowleft:{action:"move-left",preventDefault:!1},arrowright:{action:"move-right",preventDefault:!1},enter:{action:"commit"},escape:{action:"cancel"}});function N(){const e=document.createElement("div"),t=document.createElement("input");e.classList.add("neuroglancer-coordinate-space-transform-scale-container"),t.spellcheck=!1,t.autocomplete="off",t.size=1,t.classList.add("neuroglancer-coordinate-space-transform-scale"),e.appendChild(t);const n=document.createElement("div"),i=document.createElement("span");i.innerHTML=O.a,n.appendChild(i);const r=document.createTextNode("");return n.appendChild(r),n.classList.add("neuroglancer-coordinate-space-transform-scale-suggestion"),e.appendChild(n),{cellElement:e,inputElement:t,suggestionElement:n}}function V(e,t,n,i,r){if(void 0===t||t.scale===n&&t.unit===i)e.style.display="none";else{e.style.display="";const n=Object(j.b)(t.scale,t.unit,{elide1:!1});e.lastChild.textContent=n,e.title=`${r}${n}`}}function _(){const e=document.createElement("input");return e.spellcheck=!1,e.autocomplete="off",e.size=1,e.placeholder=" ",e.classList.add("neuroglancer-coordinate-space-transform-output-name"),e}function B(e,t,n){const i=e.map(e=>Object(j.c)(e.value));if(i.includes(void 0))return!1;const r=Float64Array.from(i,e=>e.scale),s=Array.from(i,e=>e.unit),o=n.value,{scales:c,units:l,rank:d}=o;for(let e=0;e<d;++e)t[e]||(r[e]=c[e],s[e]=l[e]);if(Object(T.a)(c,r)&&Object(T.a)(l,s))return!1;const u=o.timestamps.map((e,t)=>r[t]===c[t]&&s[t]===l[t]?e:Date.now()),h=Object(a.y)({valid:o.valid,rank:o.rank,scales:r,units:s,timestamps:u,ids:o.ids,names:o.names,boundingBoxes:o.boundingBoxes});return n.value=h,!0}function F(e,t,n,i){const r=new Float64Array(e.scales),s=Array.from(e.units);if(r[t]===n&&s[t]===i)return e;const o=Array.from(e.timestamps);return r[t]=n,s[t]=i,o[t]=Date.now(),Object.assign(Object.assign({},e),{scales:r,units:s,timestamps:o})}class z extends y.a{constructor(e,t,n){super(),this.transform=e,this.localCombiner=t,this.globalCombiner=n,this.element=document.createElement("div"),this.coefficientContainer=document.createElement("div"),this.translationContainer=document.createElement("div"),this.outputNameContainer=document.createElement("div"),this.outputScaleContainer=document.createElement("div"),this.inputNameContainer=document.createElement("div"),this.inputScaleContainer=document.createElement("div"),this.inputLowerBoundsContainer=document.createElement("div"),this.inputUpperBoundsContainer=document.createElement("div"),this.coefficientElements=[],this.inputNameElements=[],this.outputNameElements=[],this.outputScaleElements=[],this.outputScaleSuggestionElements=[],this.inputScaleSuggestionElements=[],this.inputScaleElements=[],this.inputBoundsElements=[],this.outputBoundsElements=[],this.addSourceDimensionIcon=Object(I.a)({svg:E.a,text:"S"}),this.addOutputDimensionIcon=Object(I.a)({svg:E.a,text:"V"}),this.addOutputDimensionCell=document.createElement("div"),this.addOutputDimensionInput=_(),this.inputScaleModified=[],this.outputScaleModified=[],this.curSourceRank=-1,this.curRank=-1,this.curTransform=void 0,this.addingSourceDimension=!1,this.resetToIdentityButton=Object(I.a)({text:"Set to identity",title:"Reset to identity transform",onClick:()=>{const{transform:e}=this,t=e.value.rank;e.transform=Object(D.c)(Float64Array,t+1)}}),this.resetToDefaultButton=Object(I.a)({text:"Reset to default",title:"Reset to default input scales, transform, and output dimensions.",onClick:()=>{const{transform:e}=this;if(e.mutableSourceRank)return;const{defaultTransform:t}=e;let{outputSpace:n}=t;const i=n.ids.map(()=>Object(a.C)());e.value=Object.assign(Object.assign({},t),{outputSpace:Object.assign(Object.assign({},n),{ids:i})})}});const{element:i}=this;this.registerDisposer(new M.b(i,R)).allShortcutsAreGlobal=!0,i.classList.add("neuroglancer-coordinate-space-transform-widget"),this.registerDisposer(new L.b(i,R));const r=Object(v.a)(()=>this.updateView());this.registerDisposer(e.changed.add(r));const{coefficientContainer:s,translationContainer:o,outputNameContainer:c,inputNameContainer:l,inputScaleContainer:d,inputLowerBoundsContainer:u,inputUpperBoundsContainer:h,outputScaleContainer:p,addOutputDimensionCell:f,addOutputDimensionIcon:m,addSourceDimensionIcon:g,resetToIdentityButton:b,resetToDefaultButton:y}=this;s.style.display="contents",o.style.display="contents",c.style.display="contents",l.style.display="contents",d.style.display="contents",p.style.display="contents",u.style.display="contents",h.style.display="contents";const S=document.createElement("div");S.classList.add("neuroglancer-coordinate-space-transform-widget-reset-buttons"),b.classList.add("neuroglancer-coordinate-space-transform-widget-reset-to-identity"),y.classList.add("neuroglancer-coordinate-space-transform-widget-reset-to-default"),S.appendChild(b),S.appendChild(y),i.appendChild(S);for(const[e,t]of[["source","Source dimensions"],["output","Output dimensions"],["input-lower","Lower"],["input-upper","Upper"],["input-scale","Scale"],["translation","Translation"]]){const n=document.createElement("div");n.classList.add(`neuroglancer-coordinate-space-transform-${e}-label`),n.classList.add("neuroglancer-coordinate-space-transform-label"),n.textContent=t,i.appendChild(n)}e.mutableSourceRank&&f.appendChild(g),f.appendChild(m),f.classList.add("neuroglancer-coordinate-space-transform-output-extend");m.title="Embed in additional output dimension",g.title="Extend to additional source dimension",f.appendChild(this.addOutputDimensionInput),f.dataset.isActive="false",m.addEventListener("click",()=>{this.addingSourceDimension=!1,this.addOutputDimensionInput.title="Embed in additional output dimension",this.addOutputDimensionCell.dataset.isActive="true",this.addOutputDimensionInput.focus()}),g.addEventListener("click",()=>{this.addingSourceDimension=!0,this.addOutputDimensionInput.title="Extend to additional source dimension",this.addOutputDimensionCell.dataset.isActive="true",this.addOutputDimensionInput.focus()}),this.addOutputDimensionInput.addEventListener("blur",()=>{this.updateAddOutputDimensionCellStyle()}),i.appendChild(s),i.appendChild(c),i.appendChild(l),i.appendChild(d),i.appendChild(p),i.appendChild(u),i.appendChild(h),s.appendChild(o),i.addEventListener("input",e=>{const{target:t}=e;if(t instanceof HTMLInputElement){P(t);let e=this.inputScaleElements.indexOf(t);if(-1!==e)return this.inputScaleModified[e]=!0,void this.updateScaleValidity(t);if(e=this.outputScaleElements.indexOf(t),-1!==e)return this.outputScaleModified[e]=!0,void this.updateScaleValidity(t);if(e=this.outputNameElements.indexOf(t),-1!==e)return void this.updateOutputNameValidity();if(this.coefficientContainer.contains(t))return void this.updateCoefficientValidity(t)}});const w=(e,t,n)=>{Object(M.c)(i,e,e=>{e.stopPropagation();const i=e.target;if(!(i instanceof HTMLInputElement))return;if(0!==n&&(i.selectionStart!==i.selectionEnd||i.selectionStart!==(1===n?i.value.length:0)))return;const r=this.getElementGridPosition(i);if(void 0===r)return;const s=this.getElementByGridPosition(r.row+t,r.col+n);null!==s&&(s.focus(),e.preventDefault())})};w("move-up",-1,0),w("move-down",1,0),w("move-left",0,-1),w("move-right",0,1);const x=(e,t)=>{e.addEventListener("focusout",n=>{const{relatedTarget:i}=n;i instanceof Node&&e.contains(i)||t(n)})};x(s,()=>{this.updateModelTransform()||this.updateViewTransformCoefficients()}),x(c,()=>{this.updateModelOutputNames()||this.updateViewOutputNames()}),x(d,()=>{this.updateModelInputScales()||this.updateViewInputScales()}),x(p,()=>{this.updateModelOutputScales()||this.updateViewOutputScales()}),Object(M.c)(i,"cancel",e=>{this.curTransform=void 0,this.updateView(),e.target.blur()}),Object(M.c)(s,"commit",()=>{this.updateModelTransform()}),Object(M.c)(c,"commit",()=>{this.updateModelOutputNames()}),Object(M.c)(d,"commit",()=>{this.updateModelInputScales()}),Object(M.c)(p,"commit",()=>{this.updateModelOutputScales()}),i.addEventListener("focusin",e=>{const{target:t}=e;t instanceof HTMLInputElement&&t.select()}),this.updateView()}updateWillBeDeletedAttributes(e){const{rank:t}=this.transform.value;void 0===e&&(e=new Array(t)).fill(!1);const{coefficientElements:n,inputBoundsElements:i,inputScaleElements:r}=this;for(let s=0;s<t;++s){const o=e[s];for(let i=0;i<=t;++i){const r=n[t*i+s],a=i<t&&e[i];r.dataset.willBeDeleted=(o||a).toString()}r[s].dataset.willBeDeleted=o.toString();const{lower:a,upper:c}=i[s];a.dataset.willBeDeleted=o.toString(),c.dataset.willBeDeleted=o.toString()}}updateAddOutputDimensionCellStyle(){const{addOutputDimensionInput:e}=this;this.addOutputDimensionCell.dataset.isActive=(0!==e.value.length||document.activeElement===e).toString()}updateOutputNameValidity(){const{outputNameElements:e}=this,t=e.map(e=>e.value),{value:{sourceRank:n,rank:i},mutableSourceRank:r}=this.transform;if(e.length!==i+1)return;const s=Object(a.q)(t);let o=new Array(i);o.fill(!1);for(let a=0;a<=i;++a){let i=s[a];0===t[a].length&&(r||a>=n)&&(i=!0,o[a]=!0),e[a].dataset.isValid=i.toString()}this.updateWillBeDeletedAttributes(o),this.updateAddOutputDimensionCellStyle()}updateScaleValidity(e){const t=void 0!==Object(j.c)(e.value);e.dataset.isValid=t.toString()}updateCoefficientValidity(e){const t=Number.isFinite(Number(e.value));e.dataset.isValid=t.toString()}getElementGridPosition(e){{const t=this.outputNameElements.indexOf(e);if(-1!==t)return{row:t,col:-2}}{const t=this.inputScaleElements.indexOf(e);if(-1!==t)return{row:-1,col:t}}{const t=this.coefficientElements.indexOf(e),{rank:n}=this.transform.value;if(-1!==t)return{row:t%n,col:Math.floor(t/n)}}{const t=this.outputScaleElements.indexOf(e);if(-1!==t)return{row:t,col:-1}}}getElementByGridPosition(e,t){const{rank:n}=this.transform.value;return-1===e?t<0||t>=n?null:this.inputScaleElements[t]:-2===t?e<0||e>n?null:this.outputNameElements[e]:-1===t?e<0||e>=n?null:this.outputScaleElements[e]:e<0||e>=n||t<0||t>n?null:this.coefficientElements[t*n+e]}dimensionRefCount(e){return(Object(a.w)(e)?this.localCombiner:this.globalCombiner).dimensionRefCounts.get(e)||0}updateModelInputScales(){return B(this.inputScaleElements,this.inputScaleModified,this.transform.inputSpace)}updateModelOutputScales(){return B(this.outputScaleElements,this.outputScaleModified,this.transform.outputSpace)}updateModelOutputNames(){const e=this.outputNameElements.map(e=>e.value),{value:t,mutableSourceRank:n}=this.transform,{outputSpace:i,rank:r,sourceRank:s}=t;if(e.length!==r+1)return;const o=[],c=[],l=0!==e[r].length;let d=s;for(let t=0;t<=r;++t){const i=e[t];if(0!==i.length)c.push(i),o.push(t);else if(t<s){if(!n)return!1;--d}}if(!Object(a.E)(c))return!1;const u=i.names;if(!l&&Object(T.a)(u,c))return!0;let h=t.inputSpace,p=t.outputSpace,f=t.transform;if(l){this.addingSourceDimension&&++d;const t=e[r],n=(Object(a.w)(t)?this.localCombiner:this.globalCombiner).combined.value,s=n.names.indexOf(t);let o,c;-1!==s?(o=n.units[s],c=n.scales[s]):(o="",c=1);const l=h.boundingBoxes.map(e=>Object(a.m)(e,r,r+1));this.addingSourceDimension||l.push(Object(a.B)(r+1,r)),h=Object(a.y)({valid:h.valid,rank:r+1,names:[...h.names,""],ids:[...h.ids,Object(a.C)()],timestamps:[...h.timestamps,Date.now()],scales:Float64Array.from([...h.scales,c]),units:[...h.units,o],boundingBoxes:l}),p=Object(a.y)({valid:i.valid,rank:r+1,names:[...i.names,t],ids:[...i.ids,Object(a.C)()],timestamps:[...i.timestamps,Date.now()],scales:Float64Array.from([...i.scales,c]),units:[...i.units,o]}),f=Object(D.e)(new Float64Array((r+2)**2),r+1,f,r)}f=Object(a.s)(Float64Array,f,h.rank,o,o),h=Object(a.D)(h,o),p=Object(a.D)(p,o);const m=p.ids.map((e,t)=>{const n=o[t];if(n===r)return e;const i=c[t],s=u[n];return i===s||1===this.dimensionRefCount(s)&&this.dimensionRefCount(i)===(u.includes(i)?1:0)?e:Object(a.C)()}),g=p.timestamps.map((e,t)=>{const n=o[t];return n===r||c[t]===u[n]?e:Date.now()});p=Object.assign(Object.assign({},p),{names:c,ids:m,timestamps:g});let v={rank:p.rank,sourceRank:d,outputSpace:p,inputSpace:h,transform:f};return this.transform.value=v,!0}updateModelTransform(){const e=this.coefficientElements,{rank:t}=this.transform.value,n=new Float64Array((t+1)**2);n[n.length-1]=1;for(let i=0;i<t;++i)for(let r=0;r<=t;++r){const s=e[r*t+i],o=parseFloat(s.value);if(!Number.isFinite(o))return!1;n[r*(t+1)+i]=o}return this.transform.transform=n,!0}updateViewOutputNames(){const{transform:{value:{outputSpace:e,rank:t}}}=this;if(t!==this.curRank)return;const{outputNameElements:n}=this,{names:i}=e;for(let e=0;e<t;++e){const t=n[e];t.value=i[e],t.dataset.isValid="true",P(t)}n[t].value="",this.updateWillBeDeletedAttributes()}updateViewTransformCoefficients(){const{transform:{value:{transform:e,rank:t}}}=this,{coefficientElements:n}=this;for(let i=0;i<t;++i)for(let r=0;r<=t;++r){const s=n[r*t+i];s.value=e[r*(t+1)+i].toString(),s.dataset.isValid="true",P(s)}}ensureViewRankUpdated(){const e=this.transform.value,{rank:t}=e,n=e.sourceRank;if(this.curSourceRank===n&&this.curRank===t)return;const{inputBoundsElements:i,inputNameElements:r,inputScaleElements:s}=this,{element:o,coefficientElements:c,outputNameElements:l,outputScaleElements:d,outputScaleSuggestionElements:u,inputScaleSuggestionElements:h,outputBoundsElements:p,coefficientContainer:f,translationContainer:m,outputNameContainer:g,inputNameContainer:v,inputScaleContainer:b,inputLowerBoundsContainer:y,inputUpperBoundsContainer:w,outputScaleContainer:x}=this;o.style.gridTemplateColumns="[outputLabel headerStart] min-content [outputNames] 1fr [outputScales] 1fr [headerEnd] "+`repeat(${Math.max(1,t)+1}, [sourceDim] 1fr)`,o.style.gridTemplateRows="[sourceLabel headerStart] auto [sourceNames] auto [sourceLower] auto [sourceUpper] auto [sourceScales] auto [headerEnd]"+`repeat(${t+1}, [outputDim] auto)`,Object(S.b)(f),Object(S.b)(m),f.appendChild(m),Object(S.b)(g),Object(S.b)(v),Object(S.b)(b),Object(S.b)(y),Object(S.b)(w),Object(S.b)(x),r.length=0,s.length=0,i.length=0,d.length=0,u.length=0,h.length=0,c.length=0,l.length=0,p.length=0;for(let e=0;e<t;++e){const t=t=>{t.classList.add("neuroglancer-coordinate-space-transform-input"),e>=n&&t.classList.add("neuroglancer-coordinate-space-transform-singleton")};{const n=document.createElement("div");n.classList.add("neuroglancer-coordinate-space-transform-input-name"),t(n),n.style.gridRowStart="sourceNames",n.style.gridColumnStart=`sourceDim ${e+1}`,v.appendChild(n),r.push(n)}{const{cellElement:n,inputElement:i,suggestionElement:r}=N();n.classList.add("neuroglancer-coordinate-space-transform-input-scale-container"),t(n),n.style.gridRowStart="sourceScales",n.style.gridColumnStart=`sourceDim ${e+1}`,b.appendChild(n),s.push(i),h.push(r);const o=e;r.addEventListener("click",()=>{const e=Object(a.p)(this.transform,o);void 0!==e&&(this.transform.inputSpace.value=F(this.transform.inputSpace.value,o,e.scale,e.unit))})}{const n=document.createElement("div");t(n),n.classList.add("neuroglancer-coordinate-space-transform-input-bounds"),n.style.gridRowStart="sourceLower",n.style.gridColumnStart=`sourceDim ${e+1}`,y.appendChild(n);const r=document.createElement("div");t(r),r.classList.add("neuroglancer-coordinate-space-transform-input-bounds"),r.style.gridRowStart="sourceUpper",r.style.gridColumnStart=`sourceDim ${e+1}`,w.appendChild(r),i.push({lower:n,upper:r})}}for(let e=0;e<t;++e){for(let i=0;i<=t;++i){const r=document.createElement("input");r.classList.add("neuroglancer-coordinate-space-transform-coeff"),r.spellcheck=!1,r.autocomplete="off",r.size=1,r.style.gridRowStart=`outputDim ${e+1}`,r.placeholder=" ",r.style.gridColumnStart=`sourceDim ${i+1}`,c[i*t+e]=r,i===t?r.classList.add("neuroglancer-coordinate-space-transform-translation-coeff"):i==n&&r.classList.add("neuroglancer-coordinate-space-transform-singleton"),(i===t?m:f).appendChild(r)}{const{cellElement:t,suggestionElement:n,inputElement:i}=N();t.classList.add("neuroglancer-coordinate-space-transform-output-scale-container"),t.style.gridRowStart=`outputDim ${e+1}`,t.style.gridColumnStart="outputScales";const r=e;n.addEventListener("click",()=>{const{value:e}=this.transform,t=Object(a.r)(e,r);void 0!==t&&(this.transform.outputSpace.value=F(e.outputSpace,r,t.scale,t.unit))}),u.push(n),x.appendChild(t),d.push(i)}{const t=document.createElement("div");t.classList.add("neuroglancer-coordinate-space-transform-output-name-container"),t.style.gridRowStart=`outputDim ${e+1}`,t.style.gridColumnStart="outputNames";const i=_();i.title="Rebind to a different dimension",e>=n?i.title+=", or delete to remove singleton dimension":this.transform.mutableSourceRank&&(i.title+=", or delete to remove source dimension"),i.title+=".  Names ending in ' or ^ indicate dimensions local to the layer; names ending in ^ indicate channel dimensions (image layers only).",l.push(i),g.appendChild(t),t.appendChild(i);const r=document.createElement("div");r.classList.add("neuroglancer-coordinate-space-transform-output-bounds"),t.appendChild(r);const s=document.createElement("div");s.classList.add("neuroglancer-coordinate-space-transform-output-bounds"),t.appendChild(s),p.push({lower:r,upper:s}),t.addEventListener("mousedown",e=>{e.target!==i&&(i.focus(),e.preventDefault())})}}l.push(this.addOutputDimensionInput),this.addOutputDimensionInput.value="",g.appendChild(this.addOutputDimensionCell),this.curSourceRank=n,this.curRank=t}updateViewInputScales(){this.ensureViewRankUpdated(),this.inputScaleModified.length=0;const{inputSpace:e,rank:t,sourceRank:n}=this.transform.value,{inputBoundsElements:i,inputNameElements:r,inputScaleElements:s,inputScaleSuggestionElements:o}=this,{names:c,scales:l,units:d,bounds:{lowerBounds:u,upperBounds:h}}=e;for(let e=0;e<t;++e){const t=s[e],p=l[e],f=d[e];let m;if(t.value=Object(j.b)(p,f,{elide1:!1}),t.dataset.isValid="true",P(t),e<n){let n=c[e];n||(n=`${e}`),r[e].textContent=n,m=`source dimension ${n}`,t.title=`Override scale of ${m}`}else m="singleton dimension",t.title=`Set extent of ${m}`;const{lower:g,upper:v}=A(u[e],h[e]),b=i[e];b.lower.textContent=g,b.lower.title=`Lower bound of ${m}`,b.upper.title=`Upper bound of ${m}`,b.upper.textContent=v,V(o[e],Object(a.p)(this.transform,e),p,f,`Revert scale of ${m} to `)}}updateViewOutputScales(){const{value:e}=this.transform,{rank:t,names:n,units:i,scales:r,bounds:{lowerBounds:s,upperBounds:o}}=e.outputSpace,{outputScaleElements:c,outputBoundsElements:l,outputScaleSuggestionElements:d}=this;for(let u=0;u<t;++u){const t=c[u],h=r[u],p=i[u];t.value=Object(j.b)(h,p,{elide1:!1}),P(t);const f=n[u];t.dataset.isValid="true";const m=`Change coordinates of ${Object(a.w)(f)?"local":"global"} dimension ${f}`;t.title=`${m} (does not rescale the source)`;const{lower:g,upper:v}=A(s[u],o[u]),b=l[u];b.lower.textContent=g,b.upper.textContent=v,V(d[u],Object(a.r)(e,u),h,p,`${m} to inferred scale of `)}}updateResetButtonVisibility(e=!1,t=!1){const{transform:{value:n,mutableSourceRank:i,defaultTransform:r}}=this,{rank:s}=n;this.resetToIdentityButton.style.visibility=e||!Object(D.h)(n.transform,s+1,s+1)?"visible":"hidden",this.resetToDefaultButton.style.visibility=i||!e&&!t&&Object(a.f)(r,n)?"hidden":"visible"}updateView(){const e=this.transform.value;this.curTransform!==e&&(this.curTransform=e,this.ensureViewRankUpdated(),this.updateViewInputScales(),this.updateViewOutputNames(),this.updateViewTransformCoefficients(),this.updateViewOutputScales(),this.updateAddOutputDimensionCellStyle(),this.updateResetButtonVisibility())}disposed(){Object(S.c)(this.element),super.disposed()}}n(209);var U=n(39);var G=n(3),$=n(135),W=n(93);function H(e){let t=document.createElement("div");return t.textContent=e.value,t}function*J(e){for(;e.length>0;){const t=e.match(/[:/_]+/);if(null===t)return void(yield e);const n=t.index+t[0].length;yield e.substring(0,n),e=e.substring(n)}}function q(e){let t=document.createElement("div");t.className="neuroglancer-multiline-autocomplete-completion-with-description",t.textContent=e.value;let n=document.createElement("div");return n.className="neuroglancer-multiline-autocomplete-completion-description",n.textContent=e.description||"",t.appendChild(n),t}const Y=M.a.fromObject({arrowdown:{action:"cycle-next-active-completion"},arrowup:{action:"cycle-prev-active-completion"},home:{action:"home"},end:{action:"end"},tab:{action:"choose-active-completion-or-prefix",preventDefault:!1},enter:{action:"commit"},escape:{action:"cancel",preventDefault:!1,stopPropagation:!1}}),X=200;class K extends y.a{constructor(e){super(),this.element=document.createElement("div"),this.inputElement=document.createElement("span"),this.hintElement=document.createElement("span"),this.completionsVirtualList=void 0,this.onCommit=new G.b,this.onInput=new G.b,this.prevInputValue="",this.completionsVisible=!1,this.activeCompletionPromise=null,this.activeCompletionCancellationToken=void 0,this.hasFocus=!1,this.completionResult=null,this.dropdownContentsStale=!0,this.hasResultForDropdown=!1,this.commonPrefix="",this.completionDisabled=-1,this.activeIndex=-1,this.dropdownStyleStale=!0,this.resizeHandler=()=>{this.completionsVisible&&this.updateDropdownStyle()},this.resizeObserver=new W.a(this.resizeHandler),this.debouncedUpdateHintState=this.registerCancellable(r()(()=>this.updateHintState(),0)),this.completer=e.completer;const{delay:t=X}=e;let n=this.scheduleUpdateCompletions=r()(()=>{const e=this.activeCompletionCancellationToken=new U.b;let t=this.activeCompletionPromise=this.completer(this.value,e);null!==t&&t.then(e=>{this.activeCompletionPromise===t&&(this.setCompletions(e),this.activeCompletionPromise=null)})},t);this.registerDisposer(()=>{n.cancel()});const{element:i,inputElement:s,hintElement:o}=this;i.classList.add("neuroglancer-multiline-autocomplete"),this.registerEventListener(window,"resize",this.resizeHandler),this.resizeObserver.observe(i),this.registerDisposer(()=>this.resizeObserver.unobserve(s)),s.contentEditable="true",s.spellcheck=!1,i.appendChild(document.createTextNode("​")),i.appendChild(s),i.appendChild(o),s.classList.add("neuroglancer-multiline-autocomplete-input"),o.classList.add("neuroglancer-multiline-autocomplete-hint"),s.addEventListener("input",()=>{this.completionDisabled=-1,this.setValueAndSelection(this.value,this.getSelectionRange()),this.debouncedUpdateHintState()}),s.addEventListener("copy",e=>{const{clipboardData:t}=e;if(null!==t){const e=window.getSelection();null!==e&&!e.isCollapsed&&e.containsNode(s,!0)&&t.setData("text/plain",e.toString())}e.preventDefault(),e.stopPropagation()}),this.registerEventListener(document,"selectionchange",()=>{const e=this.getSelectionRange(),{completionDisabled:t}=this;void 0!==e&&e.begin===t&&e.end===t||(this.completionDisabled=-1,this.debouncedUpdateHintState())}),this.setValueAndSelection(""),this.updateHintState(),i.addEventListener("pointerdown",e=>{const{target:t}=e;if(t instanceof Node){if(s.contains(t))return;const{completionsVirtualList:e}=this;if(void 0!==e&&e.element.contains(t))return}s===document.activeElement&&(this.moveCaretToEndOfInput(),e.stopPropagation(),e.preventDefault())}),i.addEventListener("click",()=>{s.focus()}),this.registerEventListener(this.inputElement,"focus",()=>{if(!this.hasFocus){this.hasFocus=!0,this.dropdownStyleStale=!0,this.updateDropdown();const e=document.createRange(),{childNodes:t}=s;e.setStart(s,0),0===t.length?e.setEnd(s,0):e.setEndAfter(t[t.length-1]);const n=window.getSelection();null!==n&&(n.removeAllRanges(),n.addRange(e)),this.debouncedUpdateHintState()}}),this.registerEventListener(this.inputElement,"blur",()=>{this.hasFocus&&(this.hasFocus=!1,this.updateDropdown()),this.debouncedUpdateHintState();const e=window.getSelection();null!==e&&e.containsNode(this.inputElement,!0)&&e.removeAllRanges(),this.onCommit.dispatch(this.value,!1)}),this.registerEventListener(window,"resize",()=>{this.dropdownStyleStale=!0}),this.registerEventListener(window,"scroll",()=>{this.dropdownStyleStale=!0}),this.registerDisposer(new M.b(s,Y)).allShortcutsAreGlobal=!0,Object(M.c)(s,"cycle-next-active-completion",()=>{this.cycleActiveCompletion(1)}),Object(M.c)(s,"cycle-prev-active-completion",()=>{this.cycleActiveCompletion(-1)}),Object(M.c)(s,"home",()=>{this.moveCaretToBeginningOfInput()}),Object(M.c)(s,"end",()=>{this.moveCaretToEndOfInput()}),Object(M.c)(s,"choose-active-completion-or-prefix",e=>{this.selectActiveCompletion(!0)&&e.preventDefault()}),Object(M.c)(s,"commit",e=>{if(this.selectActiveCompletion(!1))e.stopPropagation();else{let e=!this.completionsVisible;this.disableCompletion(),this.hideCompletions(),this.onCommit.dispatch(this.value,e)}}),Object(M.c)(s,"cancel",e=>{e.stopPropagation(),this.cancel()&&(e.detail.preventDefault(),e.detail.stopPropagation())})}disableCompletion(){const e=this.getSelectionRange();this.completionDisabled=void 0!==e&&e.end===e.begin?e.end:-1}get placeholder(){return this.inputElement.dataset.placeholder||""}set placeholder(e){this.inputElement.dataset.placeholder=e}getSelectionRange(){const e=window.getSelection();if(null===e)return;if(0===e.rangeCount)return;const t=e.getRangeAt(0),{inputElement:n}=this,i=document.createRange();i.setStart(n,0),i.setEnd(t.startContainer,t.startOffset);const r=i.toString().length;return{begin:r,end:r+e.toString().length}}setValueAndSelection(e,t){const n=-1!==this.completionDisabled;this.onInput.dispatch(e);const{inputElement:i}=this;Object(S.b)(i);let r=0;const s=void 0!==t?document.createRange():void 0;let o=!0;for(const n of J(e)){o||i.appendChild(document.createElement("wbr")),o=!1;const e=r+n.length,a=document.createTextNode(n);if(i.appendChild(a),void 0!==s){const{begin:n,end:i}=t;n>=r&&n<=e&&s.setStart(a,n-r),i>=r&&i<=e&&s.setEnd(a,i-r)}r=e}if(void 0!==s){o&&(s.setStart(i,0),s.setEnd(i,0));const e=window.getSelection();null!==e&&(e.removeAllRanges(),e.addRange(s))}this.completionDisabled=n&&void 0!==t&&t.end===t.begin?t.end:-1}shouldAttemptCompletion(){const{inputElement:e}=this;if(document.activeElement!==e)return!1;const t=this.getSelectionRange();return void 0!==t&&t.end===t.begin&&t.end!=this.completionDisabled&&t.end===this.value.length}hideCompletions(){this.cancelActiveCompletion(),this.clearCompletions(),this.hintElement.textContent=""}updateHintState(){if(this.debouncedUpdateHintState.cancel(),this.shouldAttemptCompletion()){const{value:e}=this;if(e===this.prevInputValue)return;this.hideCompletions(),this.prevInputValue=e,this.scheduleUpdateCompletions()}else this.hideCompletions()}handleDropdownClick(e){let{completionsVirtualList:t}=this;if(void 0===t)return;const n=t.element;for(let t=e.target;t instanceof HTMLElement&&t!==n;t=t.parentElement){const e=t.dataset.completionIndex;if(void 0!==e){this.selectCompletion(Number(e));break}}}cycleActiveCompletion(e){if(null===this.completionResult)return;let{activeIndex:t}=this,n=this.completionResult.completions.length;t=-1===t?e>0?0:n-1:(t+e+n)%n,this.setActiveIndex(t)}shouldShowDropdown(){let{completionResult:e}=this;return!(null===e||!this.hasFocus)&&this.hasResultForDropdown}updateDropdownStyle(){const{completionsVirtualList:e,element:t}=this;void 0!==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(e,t,{horizontal:n=!1,vertical:i=!0,topMargin:r=6,bottomMargin:s=6,leftMargin:o=6,rightMargin:a=6,maxHeight:c=!0,maxWidth:l=!0}={}){let d=t.getBoundingClientRect();if(n){let t=e.ownerDocument.documentElement.clientHeight,n=d.right,i=t-d.left;n>i?(e.style.left="",e.style.right="0",l&&(e.style.maxWidth=n-o+"px")):(e.style.right="",e.style.left="0",l&&(e.style.maxWidth=i-a+"px"))}if(i){let t=e.ownerDocument.documentElement.clientHeight,n=d.top-r,i=t-d.bottom-s;n>3*i?(e.style.top="",e.style.bottom="100%",c&&(e.style.maxHeight=n+"px")):(e.style.top="100%",e.style.bottom="",c&&(e.style.maxHeight=i+"px"))}}
/**
 * @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.
 */(e.element,t,{horizontal:!1}),this.dropdownStyleStale=!1}updateDropdown(){let{completionsVirtualList:e}=this;if(this.shouldShowDropdown()){if(this.dropdownContentsStale){void 0!==e&&e.dispose();const t=this.completionResult,{makeElement:n=H}=t;e=this.completionsVirtualList=new $.a({source:{length:t.completions.length,render:e=>{const i=t.completions[e],r=n.call(t,i);return r.classList.add("neuroglancer-multiline-autocomplete-completion"),r.dataset.completionIndex=`${e}`,this.activeIndex===e&&r.classList.add("neuroglancer-multiline-autocomplete-completion-active"),r}},selectedIndex:-1===this.activeIndex?void 0:this.activeIndex}),e.element.classList.add("neuroglancer-multiline-autocomplete-dropdown"),e.element.addEventListener("mousedown",e=>{this.inputElement.focus(),e.preventDefault()}),e.element.addEventListener("mouseup",this.handleDropdownClick.bind(this)),this.element.appendChild(e.element),this.dropdownContentsStale=!1}this.dropdownStyleStale&&this.updateDropdownStyle(),this.completionsVisible||(this.completionsVisible=!0);const{activeIndex:t}=this;-1!==t&&this.completionsVirtualList.scrollItemIntoView(t)}else this.completionsVisible&&(void 0!==e&&(e.dispose(),this.completionsVirtualList=void 0,this.dropdownContentsStale=!0),this.completionsVisible=!1)}setCompletions(e){this.clearCompletions();let{completions:t}=e;if(0===t.length)return;const n=this.prevInputValue;if(void 0!==n){if(this.completionResult=e,1===t.length){let i=t[0];e.showSingleResult?this.hasResultForDropdown=!0:i.value.startsWith(n)?this.hasResultForDropdown=!1:this.hasResultForDropdown=!0,e.selectSingleResult?this.setActiveIndex(0):this.setHintValue(this.getCompletedValueByIndex(0))}else{this.hasResultForDropdown=!0;let t=function(e){let t=e[Symbol.iterator](),{value:n,done:i}=t.next();if(i)return"";let r=n.length;for(;r>0;){let{value:e,done:i}=t.next();if(i)break;let s=0;for(;s<r&&n.charCodeAt(s)===e.charCodeAt(s);++s);r=s}return n.substring(0,r)}(function*(){for(let t of e.completions)yield t.value}()),i=this.getCompletedValue(t);i.startsWith(n)&&(this.commonPrefix=i,this.setHintValue(i))}this.updateDropdown()}}setHintValue(e){const t=this.prevInputValue;if(void 0===t)return;e!==t&&e.startsWith(t)||(e=""),e=e.substring(t.length);const{hintElement:n}=this;Object(S.b)(n);let i=!0;for(const t of J(e)){i||n.appendChild(document.createElement("wbr")),i=!1;const e=document.createTextNode(t);n.appendChild(e)}}setActiveIndex(e){if(!this.dropdownContentsStale){let{activeIndex:t}=this;const{completionsVirtualList:n}=this;if(void 0!==n){if(-1!==t){const e=n.getItemElement(t);void 0!==e&&e.classList.remove("neuroglancer-multiline-autocomplete-completion-active")}if(-1!==e){let t=n.getItemElement(e);void 0!==t&&t.classList.add("neuroglancer-multiline-autocomplete-completion-active"),n.scrollItemIntoView(e)}}}-1!==e&&this.setHintValue(this.getCompletedValueByIndex(e)),this.activeIndex=e}getCompletedValueByIndex(e){return this.getCompletedValue(this.completionResult.completions[e].value)}getCompletedValue(e){let t=this.completionResult,n=this.prevInputValue;return void 0===n?"":n.substring(0,t.offset)+e}moveCaretToBeginningOfInput(){const e=document.createRange(),{inputElement:t}=this;e.setStart(t,0),e.setEnd(t,0);const n=window.getSelection();null!==n&&(n.removeAllRanges(),n.addRange(e),this.debouncedUpdateHintState())}moveCaretToEndOfInput(){const e=document.createRange(),{inputElement:t}=this,{childNodes:n}=t,i=n[n.length-1];void 0===i?(e.setStart(t,0),e.setEnd(t,0)):(e.setStartAfter(i),e.setEndAfter(i));const r=window.getSelection();null!==r&&(r.removeAllRanges(),r.addRange(e),this.debouncedUpdateHintState())}selectActiveCompletion(e){let{activeIndex:t}=this;if(-1===t){if(!e)return!1;let{completionResult:n}=this;if(null===n||1!==n.completions.length){let{commonPrefix:e}=this;return e.length>this.value.length&&(this.value=e,this.moveCaretToEndOfInput(),!0)}t=0}let n=this.getCompletedValueByIndex(t);return this.value!==n&&(this.value=n,this.moveCaretToEndOfInput(),!0)}selectCompletion(e){this.value=this.getCompletedValueByIndex(e),this.moveCaretToEndOfInput()}cancel(){return!1}cancelActiveCompletion(){this.prevInputValue=void 0;const e=this.activeCompletionCancellationToken;void 0!==e&&e.cancel(),this.activeCompletionCancellationToken=void 0,this.activeCompletionPromise=null}clearCompletions(){if(null!==this.completionResult){this.activeIndex=-1,this.completionResult=null,this.dropdownContentsStale=!0,this.dropdownStyleStale=!0,this.commonPrefix="";const{completionsVirtualList:e}=this;void 0!==e&&(e.dispose(),this.completionsVirtualList=void 0),this.updateDropdown()}}get value(){return this.inputElement.textContent||""}set value(e){e!==this.value&&(this.completionDisabled=-1,this.setValueAndSelection(e),this.debouncedUpdateHintState())}disposed(){const{completionsVirtualList:e}=this;void 0!==e&&e.dispose(),Object(S.c)(this.element),this.cancelActiveCompletion(),super.disposed()}}var Q=n(48);
/**
 * @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 Z extends K{constructor(e){const{manager:t}=e.source.layer;super({completer:(e,n)=>t.dataSourceProviderRegistry.completeUrl({url:e,chunkManager:t.chunkManager,cancellationToken:n}).then(e=>({completions:e.completions,makeElement:q,offset:e.offset,showSingleResult:!0})),delay:0}),this.placeholder="Data source URL",this.dataSourceView=e,this.element.classList.add("neuroglancer-layer-data-source-url-input"),this.dirty=new h.e(!1);const n=e=>{e!==this.dataSourceView.source.spec.url&&(this.dirty.value=!0)};n(""),this.onInput.add(n)}cancel(){return this.value=this.dataSourceView.source.spec.url,this.dirty.value=!1,this.inputElement.blur(),!0}}class ee extends y.a{constructor(e){super(),this.model=e,this.element=document.createElement("ul"),this.generation=-1,this.element.classList.add("neuroglancer-layer-data-sources-source-messages");const t=this.registerCancellable(Object(v.a)(()=>this.updateView()));this.registerDisposer(e.changed.add(t)),this.registerDisposer(()=>Object(S.c)(this.element)),this.updateView()}updateView(){const{model:e}=this,t=e.changed.count;if(t===this.generation)return;this.generation=t;const{element:n}=this;Object(S.b)(n);const i=new Set;for(const t of e){const e=`${t.severity} ${t.message}`;if(i.has(e))continue;i.add(e);const r=document.createElement("li");n.appendChild(r),r.classList.add("neuroglancer-message"),r.classList.add(`neuroglancer-message-${w.b[t.severity]}`),r.textContent=t.message}}}class te extends y.a{constructor(e,t){super(),this.loadedSubsource=t,this.element=document.createElement("div");const{element:n}=this;n.classList.add("neuroglancer-layer-data-source-subsource");const i=document.createElement("label"),r=document.createElement("span"),s=()=>{i.dataset.isActive=(void 0!==t.activated||!t.enabled).toString()};s(),this.registerDisposer(t.isActiveChanged.add(s)),this.registerDisposer(e.enabledSubsourcesChanged.add(s));const o=this.registerDisposer(new g.c({get value(){return t.enabled},set value(n){t.enabled=n,e.enableDefaultSubsources=!1,e.enabledSubsourcesChanged.dispatch()},changed:e.enabledSubsourcesChanged}));i.classList.add("neuroglancer-layer-data-sources-info-line"),i.appendChild(o.element);const a=document.createElement("span");a.classList.add("neuroglancer-layer-data-sources-source-id");const{id:l}=t.subsourceEntry;"default"!==l&&(a.textContent=l),i.appendChild(a),r.classList.add("neuroglancer-layer-data-sources-source-type");const d=this.registerDisposer(new ee(this.loadedSubsource.messages));n.appendChild(i),i.appendChild(r),n.appendChild(d.element);let u="";const{subsource:h}=t.subsourceEntry,{volume:v}=h;if(v instanceof m.a)u=`${b.c[v.dataType].toLowerCase()} volume`;else if(h.mesh instanceof p.b)u="meshes (single-res.)";else if(h.mesh instanceof p.d)u="meshes (multi-res.)";else if(h.mesh instanceof f.d)u="skeletons";else if(void 0!==h.segmentPropertyMap)u="segment property map";else if(void 0!==h.local)switch(h.local){case c.c.annotations:u="Local annotations"}else void 0!==h.staticAnnotations?u="default annotations":void 0!==h.annotation?u="annotations":void 0!==h.singleMesh&&(u="single mesh");r.textContent=u}}class ne extends y.a{constructor(e){super(),this.source=e,this.element=document.createElement("div");const{element:t}=this,n=document.createElement("label");n.classList.add("neuroglancer-layer-data-sources-source-default"),n.appendChild(this.registerDisposer(new g.c({changed:e.enabledSubsourcesChanged,get value(){return e.enableDefaultSubsources},set value(t){if(e.enableDefaultSubsources!==t){if(e.enableDefaultSubsources=t,t)for(const t of e.subsources)t.enabled=t.subsourceEntry.default;e.enabledSubsourcesChanged.dispatch()}}})).element),n.appendChild(document.createTextNode("Enable default subsource set")),n.title="Enable the default set of subsources for this data source.",t.appendChild(n);for(const n of e.subsources)t.appendChild(this.registerDisposer(new te(e,n)).element);const i=this.registerDisposer(new z(e.transform,e.layer.localCoordinateSpaceCombiner,e.layer.manager.root.coordinateSpaceCombiner));this.element.appendChild(i.element),this.registerDisposer(()=>Object(S.c)(this.element))}}class ie extends y.a{constructor(e,t){super(),this.tab=e,this.source=t,this.element=document.createElement("div"),this.seenGeneration=0,this.generation=-1;const n=this.urlInput=this.registerDisposer(new Z(this));n.onCommit.add((t,i)=>{const{source:r}=this,s=r.spec,o=this.source.layer;if((t=o.manager.dataSourceProviderRegistry.normalizeUrl({url:t}))!==n.value&&(n.disableCompletion(),n.setValueAndSelection(t,{begin:t.length,end:t.length})),n.dirty.value=!1,t&&t===s.url)i&&void 0!==e.detectedLayerConstructor&&re(r.layer);else{if(o instanceof Be)try{const e=o.manager.dataSourceProviderRegistry.suggestLayerName(t);Re(o.managedLayer,e)}catch(e){}r.spec=Object.assign(Object.assign({},s),{url:t})}});const{element:i}=this;i.classList.add("neuroglancer-layer-data-source"),i.appendChild(n.element),i.appendChild(this.registerDisposer(new ee(t.messages)).element),this.updateView()}updateView(){const e=this.source.changed.count;if(e===this.generation)return;this.generation=e,this.urlInput.value=this.source.spec.url,this.urlInput.dirty.value=!1;const{loadState:t}=this.source;let{loadedView:n}=this;if(void 0!==n){if(n.source===t)return;n.dispose(),n=this.loadedView=void 0}t instanceof l.b&&(n=this.loadedView=new ne(t),this.element.appendChild(n.element))}disposed(){const{loadedView:e}=this;void 0!==e&&e.dispose(),Object(S.c)(this.element),super.disposed()}}function re(e){if(e instanceof Be){const t=e.detectedLayerConstructor;if(void 0!==t)return Ae(e.managedLayer,t),!0}return!1}class se extends Q.b{constructor(e){super(),this.layer=e,this.generation=-1,this.sourceViews=new Map,this.addDataSourceIcon=Object(x.a)({title:"Add additional data source"}),this.layerTypeDetection=document.createElement("div"),this.layerTypeElement=document.createElement("span"),this.dataSourcesContainer=document.createElement("div"),this.detectedLayerConstructor=void 0;const{element:t,dataSourcesContainer:n}=this;t.classList.add("neuroglancer-layer-data-sources-tab"),n.classList.add("neuroglancer-layer-data-sources-container");const{addDataSourceIcon:i}=this;if(i.style.alignSelf="start",i.addEventListener("click",()=>{const e=this.layer.addDataSource(void 0);this.updateView();const t=this.sourceViews.get(e);void 0!==t&&t.urlInput.inputElement.focus()}),t.appendChild(this.dataSourcesContainer),e instanceof Be){const{layerTypeDetection:n,layerTypeElement:i}=this;n.style.display="none",i.classList.add("neuroglancer-layer-data-sources-tab-type-detection-type"),n.appendChild(document.createTextNode("Create as ")),n.appendChild(i),n.appendChild(document.createTextNode(" layer")),t.appendChild(n),n.classList.add("neuroglancer-layer-data-sources-tab-type-detection"),n.addEventListener("click",()=>{re(e)})}const r=this.reRender=Object(v.a)(()=>this.updateView());this.registerDisposer(e.dataSourcesChanged.add(r)),this.registerDisposer(this.visibility.changed.add(r)),this.updateView()}updateLayerTypeDetection(){const e=(()=>{const e=this.layer;if(!(e instanceof Be))return;const t=e.detectedLayerConstructor;if(void 0!==t){for(const e of this.sourceViews.values())if(e.urlInput.dirty.value)return;return t}})();if(e===this.detectedLayerConstructor)return;const{layerTypeDetection:t}=this;if(this.detectedLayerConstructor=e,void 0!==e){const{layerTypeElement:n}=this;n.textContent=e.type,t.title="Click here or press enter in the data source URL input box to create as "+`${e.type} layer`,t.style.display=""}else t.style.display="none"}disposed(){const{sourceViews:e}=this;for(const t of e.values())t.dispose();e.clear(),super.disposed()}updateView(){if(!this.visible)return;const e=this.layer.dataSourcesChanged.count;if(e!==this.generation){this.generation=e;const t=Date.now(),{sourceViews:n}=this,{layer:i}=this;Object(S.d)(this.dataSourcesContainer,function*(){let e=!0;const{dataSources:r}=i;for(const i of r){let s=n.get(i);void 0===s&&(s=new ie(this,i),s.registerDisposer(s.urlInput.dirty.changed.add(this.reRender)),n.set(i,s)),s.seenGeneration=t,s.updateView();const o=i.spec.url;1===r.length&&""===o&&setTimeout(()=>{s.urlInput.inputElement.focus()},0),e=0===i.spec.url.length,yield s.element}e||(yield this.addDataSourceIcon)}.call(this));for(const[e,i]of n)i.seenGeneration!==t&&(i.dispose(),n.delete(e))}this.updateLayerTypeDetection()}}var oe=n(103),ae=n(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.
 */
function ce(e,t){e.remove(t)}function le(e,t){e.add(t)}var de=n(18),ue=n(37);n.d(t,"k",(function(){return he})),n.d(t,"e",(function(){return fe})),n.d(t,"a",(function(){return me})),n.d(t,"f",(function(){return ge})),n.d(t,"c",(function(){return ve})),n.d(t,"j",(function(){return be})),n.d(t,"q",(function(){return xe})),n.d(t,"h",(function(){return Ce})),n.d(t,"b",(function(){return Oe})),n.d(t,"i",(function(){return Ee})),n.d(t,"d",(function(){return Te})),n.d(t,"p",(function(){return Me})),n.d(t,"r",(function(){return je})),n.d(t,"s",(function(){return Ie})),n.d(t,"t",(function(){return Pe})),n.d(t,"n",(function(){return Ae})),n.d(t,"m",(function(){return Re})),n.d(t,"o",(function(){return Ne})),n.d(t,"g",(function(){return Be})),n.d(t,"l",(function(){return ze}));class he extends y.a{constructor(e,t){super(),this.managedLayer=e,this.pick=new g.b(!0,!0),this.layersChanged=new G.a,this.readyStateChanged=new G.a,this.specificationChanged=new G.a,this.renderLayers=new Array,this.loadingCounter=1,this.tabs=this.registerDisposer(new Q.c),this.tool=this.registerDisposer(new h.b(e=>Object(oe.c)(this,e),e=>e.toJSON())),this.dataSourcesChanged=new G.a,this.dataSources=[],this.localCoordinateSpaceCombiner.includeDimensionPredicate=a.x,this.tabs.changed.add(this.specificationChanged.dispatch),this.tool.changed.add(this.specificationChanged.dispatch),this.localPosition.changed.add(this.specificationChanged.dispatch),this.pick.changed.add(this.specificationChanged.dispatch),this.pick.changed.add(this.layersChanged.dispatch),this.dataSourcesChanged.add(this.specificationChanged.dispatch),this.dataSourcesChanged.add(()=>this.updateDataSubsourceActivations()),this.tabs.add("source",{label:"Source",order:-100,getter:()=>new se(this)})}get localPosition(){return this.managedLayer.localPosition}get localCoordinateSpaceCombiner(){return this.managedLayer.localCoordinateSpaceCombiner}get localCoordinateSpace(){return this.managedLayer.localCoordinateSpace}get type(){return this.constructor.type}initializeSelectionState(e){e.generation=-1,e.localPositionValid=!1,e.localPosition=ue.b,e.localCoordinateSpace=void 0,e.annotationId=void 0,e.annotationSourceIndex=void 0,e.annotationSubsource=void 0,e.annotationPartIndex=void 0,e.value=void 0}resetSelectionState(e){e.localPositionValid=!1,e.annotationId=void 0,e.value=void 0}selectionStateFromJson(e,t){const n=e.localCoordinateSpace=this.localCoordinateSpace.value,{rank:i}=n;if(0!==i){const n=Object(ae.B)(t,"localPosition",e=>Object(ae.d)(new Float32Array(i),e,ae.p));void 0===n?e.localPositionValid=!1:(e.localPositionValid=!0,e.localPosition=n)}void 0!==(e.annotationId=Object(ae.B)(t,"annotationId",ae.E))&&(e.annotationSourceIndex=Object(ae.B)(t,"annotationSource",ae.u,0),e.annotationPartIndex=Object(ae.B)(t,"annotationPart",ae.u),e.annotationSubsource=Object(ae.B)(t,"annotationSubsource",ae.E)),e.value=t.value}displaySelectionState(e,t,n){return!1}selectionStateToJson(e,t){const n={};if(e.localPositionValid){const{localPosition:t}=e;t.length>0&&(n.localPosition=Array.from(t))}return void 0!==e.annotationId&&(n.annotationId=e.annotationId,n.annotationPart=e.annotationPartIndex,n.annotationSource=e.annotationSourceIndex,n.annotationSubsource=e.annotationSubsource),null!=e.value&&(n.value=e.value),n}captureSelectionState(e,t){e.localCoordinateSpace=this.localCoordinateSpace.value;const n=this.localPosition.value;let{localPosition:i}=e;i.length!==n.length?e.localPosition=n.slice():i.set(n),e.localPositionValid=!0,e.value=this.getValueAt(t.position,t)}copySelectionState(e,t){e.generation=t.generation,e.localPositionValid=t.localPositionValid,e.localCoordinateSpace=t.localCoordinateSpace;const n=t.localPosition;let{localPosition:i}=e;i.length!==n.length?e.localPosition=n.slice():e.localPosition.set(n),e.annotationId=t.annotationId,e.annotationSourceIndex=t.annotationSourceIndex,e.annotationSubsource=t.annotationSubsource,e.annotationPartIndex=t.annotationPartIndex,e.value=t.value}get isReady(){return 0===this.loadingCounter}get manager(){return this.managedLayer.manager}canAddDataSource(){return!0}addDataSource(e){const t=new l.a(this,e);return this.dataSources.push(t),this.dataSourcesChanged.dispatch(),t}activateDataSubsources(e){}updateDataSubsourceActivations(){this.activateDataSubsources(function*(){for(const e of this.dataSources){const{loadState:t}=e;if(void 0!==t&&void 0===t.error)for(const e of t.subsources)if(e.enabled)yield e;else{const{activated:n}=e;e.messages.clearMessages(),void 0!==n&&(n.dispose(),e.activated=void 0,t.activatedSubsourcesChanged.dispatch())}}}.call(this))}decrementLoadingCounter(){0==--this.loadingCounter&&this.readyStateChanged.dispatch()}markLoading(){const e=this.localCoordinateSpaceCombiner.retain(),t=this.manager.root.coordinateSpaceCombiner.retain();1==++this.loadingCounter&&this.readyStateChanged.dispatch();return()=>{e(),t(),this.decrementLoadingCounter()}}addCoordinateSpace(e){const t=this.manager.root.coordinateSpaceCombiner.bind(e),n=this.localCoordinateSpaceCombiner.bind(e);return()=>{t(),n()}}initializationDone(){const e=this.selectionState={};this.initializeSelectionState(e),this.decrementLoadingCounter()}getLegacyDataSourceSpecifications(e,t,n){return void 0===e?[]:[Object(l.c)(e,n)]}getDataSourceSpecifications(e){let t=void 0,n=Object(ae.y)(e,"source",e=>Array.isArray(e)?e.map(e=>Object(l.c)(e)):"object"==typeof e?[Object(l.c)(e)]:(t=e,[]));const i=Object(ae.y)(e,"transform",a.h);return n.push(...this.getLegacyDataSourceSpecifications(t,e,i)),n=n.filter(e=>e.url),0===n.length&&n.push(Object(c.f)()),n}restoreState(e){this.tool.restoreState(e.tool),this.tabs.restoreState(e.tab),this.localCoordinateSpace.restoreState(e.localDimensions),this.localPosition.restoreState(e.localPosition),this.constructor.supportsPickOption&&this.pick.restoreState(e.pick);for(const t of this.getDataSourceSpecifications(e))this.addDataSource(t)}addRenderLayer(e){this.renderLayers.push(e);const{layersChanged:t}=this;return e.layerChanged.add(t.dispatch),t.dispatch(),()=>this.removeRenderLayer(e)}removeRenderLayer(e){const{renderLayers:t,layersChanged:n}=this,i=t.indexOf(e);if(-1===i)throw new Error("Attempted to remove invalid RenderLayer");t.splice(i,1),e.layerChanged.remove(n.dispatch),e.dispose(),n.dispatch()}disposed(){const{layersChanged:e}=this;Object(y.d)(this.dataSources);for(const t of this.renderLayers)t.layerChanged.remove(e.dispatch),t.dispose();this.renderLayers.length=0,super.disposed()}getValueAt(e,t){let n,{renderLayers:i}=this,{pickedRenderLayer:r}=t;if(null!==r&&-1!==i.indexOf(r)&&(n=r.transformPickedValue(t.pickedValue,t.pickedOffset),n=this.transformPickedValue(n),null!=n))return n;for(let t of i)if(n=t.getValueAt(e),null!=n)break;return this.transformPickedValue(n)}transformPickedValue(e){return e}toJSON(){return{type:this.type,source:pe(this.dataSources),tab:this.tabs.toJSON(),tool:this.tool.toJSON(),localDimensions:this.localCoordinateSpace.toJSON(),localPosition:this.localPosition.toJSON(),pick:this.pick.toJSON()}}handleAction(e){}selectedValueToJson(e){return e}selectedValueFromJson(e){return e}}function pe(e){if(0!==e.length)return 1===e.length?e[0].toJSON():e.map(e=>e.toJSON())}he.supportsPickOption=!1;class fe extends y.a{constructor(e,t,n){super(),this.initialSpecification=t,this.manager=n,this.localCoordinateSpace=new a.b,this.localCoordinateSpaceCombiner=new a.a(this.localCoordinateSpace,a.w),this.localPosition=this.registerDisposer(new d.k(this.localCoordinateSpace)),this.readyStateChanged=new G.a,this.layerChanged=new G.a,this.specificationChanged=new G.a,this.containers=new Set,this.layer_=null,this.visible=!0,this.name_=e}get layer(){return this.layer_}set layer(e){let t=this.layer_;if(null!=t&&(this.unregisterUserLayer(),t.dispose()),this.layer_=e,null!=e){const t=[e.layersChanged.add(this.layerChanged.dispatch),e.readyStateChanged.add(this.readyStateChanged.dispatch),e.specificationChanged.add(this.specificationChanged.dispatch)];this.unregisterUserLayer=()=>{t.forEach(e=>e())},this.readyStateChanged.dispatch(),this.layerChanged.dispatch()}}isReady(){const{layer:e}=this;return null!==e&&e.isReady}get name(){return this.name_}set name(e){e!==this.name_&&(this.name_=e,this.layerChanged.dispatch())}get supportsPickOption(){const e=this.layer;return null!==e&&e.constructor.supportsPickOption}get pickEnabled(){const e=this.layer;return null!==e&&e.constructor.supportsPickOption&&e.pick.value}set pickEnabled(e){const t=this.layer;null!==t&&t.constructor.supportsPickOption&&(t.pick.value=e)}toJSON(){let e=this.layer;if(!e)return this.initialSpecification;let t=e.toJSON();return t.name=this.name,this.visible||(t.visible=!1),t}setVisible(e){e!==this.visible&&(this.visible=e,this.layerChanged.dispatch())}disposed(){this.layer=null,super.disposed()}}class me extends y.a{constructor(){super(),this.managedLayers=new Array,this.layerSet=new Set,this.layersChanged=new G.a,this.readyStateChanged=new G.a,this.specificationChanged=new G.a,this.boundPositions=new WeakSet,this.numDirectUsers=0,this.renderLayerToManagedLayerMapGeneration=-1,this.renderLayerToManagedLayerMap_=new Map,this.scheduleRemoveLayersWithSingleRef=this.registerCancellable(r()(()=>this.removeLayersWithSingleRef(),0)),this.layersChanged.add(this.scheduleRemoveLayersWithSingleRef)}get renderLayerToManagedLayerMap(){const e=this.layersChanged.count,t=this.renderLayerToManagedLayerMap_;if(this.renderLayerToManagedLayerMapGeneration!==e){this.renderLayerToManagedLayerMapGeneration=e,t.clear();for(const e of this.managedLayers){const n=e.layer;if(null!==n)for(const i of n.renderLayers)t.set(i,e)}}return t}filter(e){let t=!1;this.managedLayers=this.managedLayers.filter(n=>!!e(n)||(this.unbindManagedLayer(n),this.layerSet.delete(n),t=!0,!1)),t&&this.layersChanged.dispatch()}removeLayersWithSingleRef(){this.numDirectUsers>0||this.filter(e=>1!==e.refCount)}updateSignalBindings(e,t){t(e.layerChanged,this.layersChanged.dispatch),t(e.readyStateChanged,this.readyStateChanged.dispatch),t(e.specificationChanged,this.specificationChanged.dispatch)}useDirectly(){return 1==++this.numDirectUsers&&this.layersChanged.remove(this.scheduleRemoveLayersWithSingleRef),()=>{0==--this.numDirectUsers&&(this.layersChanged.add(this.scheduleRemoveLayersWithSingleRef),this.scheduleRemoveLayersWithSingleRef())}}addManagedLayer(e,t){return this.updateSignalBindings(e,le),this.layerSet.add(e),e.containers.add(this),void 0===t&&(t=this.managedLayers.length),this.managedLayers.splice(t,0,e),this.layersChanged.dispatch(),this.readyStateChanged.dispatch(),e}*readyRenderLayers(){for(let e of this.managedLayers)e.visible&&e.layer&&(yield*e.layer.renderLayers)}unbindManagedLayer(e){this.updateSignalBindings(e,ce),e.containers.delete(this),e.dispose()}clear(){for(let e of this.managedLayers)this.unbindManagedLayer(e);this.managedLayers.length=0,this.layerSet.clear(),this.layersChanged.dispatch()}remove(e){const t=this.managedLayers[e];this.unbindManagedLayer(t),this.managedLayers.splice(e,1),this.layerSet.delete(t),this.layersChanged.dispatch()}removeManagedLayer(e){let t=this.managedLayers.indexOf(e);if(-1===t)throw new Error("Internal error: invalid managed layer.");this.remove(t)}reorderManagedLayer(e,t){const n=this.managedLayers.length;if(e===t||e<0||e>=n||t<0||t>=n)return;let[i]=this.managedLayers.splice(e,1);this.managedLayers.splice(t,0,i),this.layersChanged.dispatch()}disposed(){this.clear(),super.disposed()}getLayerByName(e){return this.managedLayers.find(t=>t.name===e)}getUniqueLayerName(e){let t=e,n=0;for(;void 0!==this.getLayerByName(t);)t=e+ ++n;return t}has(e){return this.layerSet.has(e)}get renderLayers(){let e=this;return{*[Symbol.iterator](){for(let t of e.managedLayers)if(null!==t.layer)for(let e of t.layer.renderLayers)yield e}}}get visibleRenderLayers(){let e=this;return{*[Symbol.iterator](){for(let t of e.managedLayers)if(null!==t.layer&&t.visible)for(let e of t.layer.renderLayers)yield e}}}invokeAction(e){for(let t of this.managedLayers){if(null===t.layer||!t.visible)continue;let n=t.layer;n.handleAction(e);for(let t of n.renderLayers)t.handleAction(e)}}}class ge{constructor(){this.changed=new G.a,this.coordinateSpace=a.k,this.position=ue.b,this.active=!1,this.displayDimensions=void 0,this.pickedRenderLayer=null,this.pickedValue=new de.a(0,0),this.pickedOffset=0,this.pickedAnnotationLayer=void 0,this.pickedAnnotationId=void 0,this.pickedAnnotationBuffer=void 0,this.pickedAnnotationBufferOffset=void 0,this.forcerFunction=void 0}removeForcer(e){e===this.forcerFunction&&(this.forcerFunction=void 0,this.setActive(!1))}setForcer(e){this.forcerFunction=e,void 0===e&&this.setActive(!1)}updateUnconditionally(){const{forcerFunction:e}=this;return void 0!==e&&(e(),this.active)}setActive(e){this.active===e&&!0!==e||(this.active=e,this.changed.dispatch())}}class ve extends y.a{constructor(e,t){super(),this.layerManager=e,this.mouseState=t,this.changed=new G.a,this.needsUpdate=!0,this.registerDisposer(t.changed.add(()=>{this.handleChange()})),this.registerDisposer(e.layersChanged.add(()=>{this.handleLayerChange()}))}handleLayerChange(){this.mouseState.active&&this.handleChange()}handleChange(){this.needsUpdate=!0,this.changed.dispatch()}update(){if(!this.needsUpdate)return;this.needsUpdate=!1;let e=this.mouseState;const t=this.changed.count;if(e.active)for(const n of this.layerManager.managedLayers){const i=n.layer;if(n.visible&&null!==i){const{selectionState:n}=i;i.resetSelectionState(n),n.generation=t,i.captureSelectionState(n,e)}}}get(e){this.update();const{selectionState:t}=e;if(t.generation===this.changed.count)return t}toJSON(){this.update();const e={};for(const t of this.layerManager.managedLayers){const n=t.layer;if(n){const i=this.get(n);void 0!==i&&(e[t.name]=n.selectionStateToJson(i,!0))}}return e}}class be extends y.a{constructor(e,t){super(),this.coordinateSpace=e,this.layerSelectedValues=t,this.changed=new G.a,this.history=[],this.historyIndex=0,this.pin=new h.e(!0),this.visible=new h.e(!1),this.registerDisposer(Object(h.k)((e,n)=>{n||(this.capture(!0),e.registerDisposer(t.changed.add(e.registerCancellable(o()(()=>this.capture(!0),100,{leading:!0,trailing:!0})))))},this.pin)),this.visible.changed.add(this.changed.dispatch),this.pin.changed.add(this.changed.dispatch)}get value(){return this.value_}goBack(){const e=this.pin.value?this.historyIndex:this.history.length;e>0&&(this.historyIndex=e-1,this.value_=this.history[e-1],this.pin.value=!0,this.changed.dispatch())}canGoBack(){return(this.pin.value?this.historyIndex:this.history.length)>0}canGoForward(){if(!this.pin.value)return!1;return this.historyIndex+1<this.history.length}goForward(){if(!this.pin.value)return;const e=this.historyIndex;e+1<this.history.length&&(this.historyIndex=e+1,this.value_=this.history[e+1],this.changed.dispatch())}set value(e){if(e!==this.value_){if(this.value_=e,void 0!==e&&this.pin.value){const{history:t}=this;t.length=Math.min(t.length,this.historyIndex+1),t.push(e),t.length>10&&t.splice(0,t.length-10),this.historyIndex=t.length-1}this.changed.dispatch()}}captureSingleLayerState(e,t,n=!0){if(!1===n&&(!this.visible.value||this.pin.value))return;const i={};e.initializeSelectionState(i),t(i)&&(this.visible.value=!0,!0===n?this.pin.value=!0:"toggle"===n&&(this.pin.value=!this.pin.value),this.value={layers:[{layer:e,state:i}],coordinateSpace:this.coordinateSpace.value,position:void 0})}reset(){this.visible.value=!1,this.pin.value=!1,this.value=void 0}toJSON(){const{value:e}=this;if(!this.visible.value)return;if(!1===this.pin.value)return null;if(void 0===e)return null;const t={};for(const n of e.layers){const{layer:e}=n;let i=e.selectionStateToJson(n.state,!1);0===Object.keys(i).length&&(i=void 0),t[n.layer.managedLayer.name]=i}return{position:void 0===e.position?void 0:Array.from(e.position),layers:t}}select(){const{pin:e,visible:t}=this;t.value=!0,e.value=!e.value,e.value&&this.capture()}capture(e=!1){const t=function(e){const{mouseState:t}=e;if(!t.active)return;const n=[];for(const t of e.layerManager.managedLayers){const i=t.layer;if(null===i)continue;const r=e.get(i);if(void 0===r)continue;const s={};i.initializeSelectionState(s),i.copySelectionState(s,r),n.push({layer:i,state:s})}return{position:t.position.slice(),coordinateSpace:t.coordinateSpace,layers:n}}(this.layerSelectedValues);e&&void 0===t||(this.value=t)}restoreState(e){if(void 0===e)return this.pin.value=!0,this.visible.value=!1,void(this.value=void 0);if(null===e)return this.pin.value=!1,this.visible.value=!0,void(this.value=void 0);Object(ae.w)(e);const t=this.coordinateSpace.value,n=Object(ae.B)(e,"position",e=>Object(ae.d)(new Float32Array(t.rank),e,ae.p)),i=[];Object(ae.B)(e,"layers",e=>{Object(ae.w)(e);const{layerManager:t}=this.layerSelectedValues;for(const[n,r]of Object.entries(e)){const e=t.getLayerByName(n);if(void 0===e)return;const s=e.layer;if(null===s)return;Object(ae.w)(r);const o={};s.initializeSelectionState(o),s.selectionStateFromJson(o,r),i.push({layer:s,state:o})}}),this.visible.value=!0,this.pin.value=!0,this.value={position:n,coordinateSpace:t,layers:i}}}class ye extends y.a{constructor(e){super(),this.view=e,this.messages=new w.a,this.seenGeneration=-1,this.state=void 0}}let Se=0;class we extends y.a{constructor(e,t,n,i,s,o){super(),this.layerManager=e,this.renderLayerType=t,this.view=n,this.roles=i,this.layerAdded=s,this.visibility=o,this.visibleLayers_=new Map,this.debouncedUpdateVisibleLayers=this.registerCancellable(r()(()=>this.updateVisibleLayers(),0)),this.registerDisposer(e.layersChanged.add(this.debouncedUpdateVisibleLayers)),this.registerDisposer(i.changed.add(this.debouncedUpdateVisibleLayers)),this.updateVisibleLayers()}disposed(){this.visibleLayers.forEach(e=>e.dispose()),this.visibleLayers.clear(),super.disposed()}updateVisibleLayers(){const e=++Se,{visibleLayers_:t,renderLayerType:n,layerAdded:i,roles:r}=this;for(let s of this.layerManager.readyRenderLayers())if(s instanceof n&&r.has(s.role)){let n=s,r=t.get(n);void 0===r&&(r=new ye(this.view),r.registerDisposer(n.messages.addChild(r.messages)),r.registerDisposer(n.addRef()),r.registerDisposer(n.visibility.add(this.visibility)),t.set(n,r),i(n,r),n.attach(r)),r.seenGeneration=e}for(const[n,i]of t)i.seenGeneration!==e&&(t.delete(n),i.dispose())}get visibleLayers(){return this.debouncedUpdateVisibleLayers.flush(),this.visibleLayers_}}function xe(e,t,n,i,r){return i.registerDisposer(new we(e,t,i,n,(e,t)=>{t.registerDisposer(e.redrawNeeded.add(()=>i.scheduleRedraw()));const{backend:n}=e;n&&(n.rpc.invoke(u.c,{layer:n.rpcId,view:i.rpcId}),t.registerDisposer(()=>n.rpc.invoke(u.d,{layer:n.rpcId,view:i.rpcId}))),void 0!==r&&r(e,t),i.scheduleRedraw(),t.registerDisposer(()=>i.scheduleRedraw())},i.visibility))}class Ce extends y.a{constructor(e){super(),this.layerManager=e,this.changed=new G.a,this.visible_=!1,this.size=new h.c(300,ae.D),this.registerDisposer(e),this.size.changed.add(this.changed.dispatch)}get layer(){return this.layer_}get visible(){return this.visible_}set visible(e){const t=this.layer_;void 0===t&&(e=!1),this.visible_!==e&&(this.visible_=e,e||void 0===t||this.maybeDeleteNewLayer(t),this.changed.dispatch())}maybeDeleteNewLayer(e){if(e.wasDisposed)return;const t=e.layer;null!==t&&t instanceof Be&&(t.dataSources.some(e=>0!==e.spec.url.length)||Ne(e))}set layer(e){if(e===this.layer_)return;const t=this.layer_;if(void 0!==t&&(this.existingLayerDisposer(),this.existingLayerDisposer=void 0,this.maybeDeleteNewLayer(t)),this.layer_=e,void 0!==e){const t=()=>{this.layer_=void 0,this.visible=!1,this.existingLayerDisposer=void 0,this.changed.dispatch()};e.registerDisposer(t);const n=e.specificationChanged.add(()=>{this.changed.dispatch()});this.existingLayerDisposer=()=>{const i=e.layer;if(null!==i){const e=i.tool.value;void 0!==e&&e.deactivate()}e.unregisterDisposer(t),n()}}else this.visible_=!1;this.changed.dispatch()}toJSON(){if(void 0!==this.layer)return{layer:this.layer.name,visible:!0===this.visible||void 0,size:this.size.toJSON()}}restoreState(e){if(void 0===e)return void this.reset();Object(ae.w)(e);const t=Object(ae.y)(e,"layer",ae.C),n=void 0!==t?this.layerManager.getLayerByName(t):void 0;this.layer=n,this.visible=!!Object(ae.y)(e,"visible",ae.z),Object(ae.y)(e,"size",e=>this.size.restoreState(e))}reset(){this.layer=void 0}}class Oe extends y.a{constructor(e,t){super(),this.layerManager=e,this.filter=t,this.changed=new G.a,this.validate=r()(()=>{const{layerName_:e}=this;if(void 0!==e){const t=this.layerManager.getLayerByName(e);void 0!==t&&this.filter(t)?(this.layer_=t,this.changed.dispatch()):(this.layer_=void 0,this.layerName_=void 0,this.changed.dispatch())}},0),this.registerDisposer(e),this.registerDisposer(e.specificationChanged.add(()=>{const{layer_:e}=this;if(void 0!==e)if(this.layerManager.layerSet.has(e)&&this.filter(e)){const{name:t}=e;t!==this.layerName_&&(this.layerName_=t,this.changed.dispatch())}else this.layer_=void 0,this.layerName_=void 0,this.changed.dispatch()}))}get layer(){return this.layer_}get layerName(){return this.layerName_}set layer(e){this.layer_!==e&&(void 0!==e&&this.layerManager.layerSet.has(e)&&this.filter(e)?(this.layer_=e,this.layerName_=e.name):(this.layer_=void 0,this.layerName_=void 0),this.changed.dispatch())}set layerName(e){e!==this.layerName_&&(this.layer_=void 0,this.layerName_=e,this.changed.dispatch(),this.validate())}restoreState(e){const t=Object(ae.C)(e);this.layerName=t}toJSON(){const{layer_:e}=this;return void 0!==e?e.name:this.layerName_}reset(){this.layerName_=void 0,this.layer_=void 0,this.changed.dispatch()}}class ke extends y.a{constructor(){super(...arguments),this.changed=new G.a}get worker(){return this.rpc}}class Ee extends ke{constructor(e,t,n,i,r,s,o){super(),this.dataSourceProviderRegistry=e,this.layerManager=t,this.chunkManager=n,this.selectionState=i,this.selectedLayer=r,this.coordinateSpace=s,this.globalPosition=o,this.coordinateSpaceCombiner=new a.a(this.coordinateSpace,a.v),this.layerSelectedValues=this.selectionState.layerSelectedValues,this.registerDisposer(t.layersChanged.add(this.changed.dispatch)),this.registerDisposer(t.specificationChanged.add(this.changed.dispatch))}get rpc(){return this.chunkManager.rpc}get root(){return this}reset(){this.layerManager.clear()}restoreState(e){if(this.layerManager.clear(),Array.isArray(e))for(const t of e){Object(ae.w)(t);const e=this.layerManager.getUniqueLayerName(Object(ae.y)(t,"name",ae.E));this.layerManager.addManagedLayer(this.getLayer(e,t))}else{Object(ae.w)(e);for(let t of Object.keys(e))this.layerManager.addManagedLayer(this.getLayer(t,e[t]))}}initializeLayerFromSpec(e,t){e.initialSpecification=t,"string"==typeof t&&(t={source:t}),Object(ae.w)(t);const n=Object(ae.B)(t,"type",ae.E,"auto");e.visible=Object(ae.B)(t,"visible",ae.n,!0);const i=new(Me.get(n)||Be)(e,t);i.restoreState(t),i.initializationDone(),e.layer=i}getLayer(e,t){let n=new fe(e,t,this);return this.initializeLayerFromSpec(n,t),n}add(e,t){-1===this.layerManager.managedLayers.indexOf(e)&&(e.name=this.layerManager.getUniqueLayerName(e.name)),this.layerManager.addManagedLayer(e,t)}toJSON(){const e=[];let t=0;for(let n of this.layerManager.managedLayers){const i=n.toJSON();null!=i&&(e.push(i),++t)}if(0!==t)return e}get rootLayers(){return this.layerManager}}class Te extends ke{constructor(e){super(),this.master=e,this.changed=new G.a,this.layerManager=this.registerDisposer(new me),this.registerDisposer(e);const{layerManager:t}=this;this.registerDisposer(t.layersChanged.add(this.changed.dispatch)),this.registerDisposer(t.specificationChanged.add(this.changed.dispatch))}get rpc(){return this.master.rpc}get dataSourceProviderRegistry(){return this.master.dataSourceProviderRegistry}get chunkManager(){return this.master.chunkManager}get layerSelectedValues(){return this.master.layerSelectedValues}get root(){return this.master}reset(){this.layerManager.clear()}restoreState(e){const t=this.master.layerManager,n=[];for(const i of new Set(Object(ae.b)(e,ae.E))){const e=t.getLayerByName(i);if(void 0===e)throw new Error(`Undefined layer referenced in subset specification: ${JSON.stringify(i)}`);n.push(e)}this.layerManager.clear();for(const e of n)this.layerManager.addManagedLayer(e.addRef())}toJSON(){return this.layerManager.managedLayers.map(e=>e.name)}initializeLayerFromSpec(e,t){this.master.initializeLayerFromSpec(e,t)}getLayer(e,t){return this.master.getLayer(e,t)}add(e,t){-1===this.master.layerManager.managedLayers.indexOf(e)&&(e.name=this.master.layerManager.getUniqueLayerName(e.name),this.master.layerManager.addManagedLayer(e.addRef())),this.layerManager.addManagedLayer(e,t)}get rootLayers(){return this.master.rootLayers}}const Me=new Map,De=new Map,Le=[];function je(e,t){Me.set(e,t)}function Ie(e){Le.push(e)}function Pe(e,t){De.set(e,t)}function Ae(e,t){const n=e.layer;if(null===n)return;const i=n.toJSON();i.tab=n.tabs.value;const r=new t(e,i);r.restoreState(i),r.initializationDone(),e.layer=r}function Re(e,t){return t!==e.name&&(t=e.manager.root.layerManager.getUniqueLayerName(t),e.name=t,e.layerChanged.dispatch(),!0)}function Ne(e){if(!e.wasDisposed)for(const t of e.containers)t.removeManagedLayer(e)}function Ve(e){for(const t of Le){const n=t(e);if(void 0!==n)return n}const{volume:t}=e;if(void 0!==t){const e=De.get(t.volumeType);if(void 0!==e)return e}}function _e(e){for(const t of e){const{subsourceEntry:e}=t,{subsource:n}=e,i=Ve(n);if(void 0!==i)return i}}class Be extends he{activateDataSubsources(e){this.detectedLayerConstructor=_e(e)}}Be.type="new";class Fe extends he{activateDataSubsources(e){const t=_e(e);void 0!==t&&Ae(this.managedLayer,t)}}function ze(e,t){const n=new fe("new layer",{},e);e.initializeLayerFromSpec(n,{type:"new"}),e.add(n),t.layer=n,t.visible=!0}Fe.type="auto",je("new",Be),je("auto",Fe)},function(e,t,n){"use strict";n.d(t,"d",(function(){return o})),n.d(t,"a",(function(){return a})),n.d(t,"b",(function(){return c})),n.d(t,"c",(function(){return d}));var i=n(2),r=n(0),s=n(3);
/**
 * @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 o(e,t,n){Object(r.B)(e,t,e=>n.restoreState(e))}class a extends i.a{constructor(){super(...arguments),this.children=new Map,this.changed=new s.a}add(e,t){const{children:n}=this;if(n.has(e))throw new Error(`Key ${JSON.stringify(e)} already registered.`);return this.children.set(e,t),t.changed.add(this.changed.dispatch),this.changed.dispatch(),()=>{this.remove(e)}}remove(e){const{children:t}=this;if(t.has(e))throw new Error(`Key ${JSON.stringify(e)} not registered.`);const n=t.get(e);this.children.delete(e),n.changed.remove(this.changed.dispatch),this.changed.dispatch()}disposed(){const{changed:e}=this;for(let t of this.children.values())t.changed.remove(e.dispatch);this.children=void 0,super.disposed()}toJSON(){const e=this.baseJSON();for(let[t,n]of this.children)e[t]=n.toJSON();return e}baseJSON(){return{}}reset(){for(let e of this.children.values())e.reset()}restoreState(e){Object(r.w)(e);for(let[t,n]of this.children)try{if(e.hasOwnProperty(t)){const i=e[t];if(void 0===i)continue;n.restoreState(i)}}catch(e){throw new Error(`Error restoring property ${JSON.stringify(t)}: ${e.message}`)}}}class c extends a{constructor(){super(...arguments),this.lastState={}}restoreState(e){Object(r.w)(e),this.lastState=e,super.restoreState(e)}reset(){this.lastState={},super.reset()}baseJSON(){const e=Object.assign(super.baseJSON(),this.lastState);for(const t of this.children.keys())delete e[t];return e}toJSON(){const e=super.toJSON();return this.lastState=e,e}add(e,t){const n=super.add(e,t),i=this.lastState[e];return void 0!==i&&(t.reset(),t.restoreState(i)),n}}const l=new WeakMap;function d(e){let t=l.get(e);const n=e.changed.count;if(void 0!==t&&t.generation===n)return t;let i;if(e instanceof a){i=e.baseJSON();for(let[t,n]of e.children)i[t]=d(n).value}else i=e.toJSON();return void 0===t?(t={generation:n,value:i},l.set(e,t)):(t.generation=n,t.value=i),t}},function(e,t,n){"use strict";n.d(t,"d",(function(){return s})),n.d(t,"e",(function(){return a})),n.d(t,"c",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"a",(function(){return d}));var i=n(56),r=n(20);
/**
 * @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 s(e,t,n,i){const{dataType:s}=t;t.defineShader(e,n);let o="",a="";if(0===n)o+="highp int ignoredChannelIndex";else for(let e=0;e<n;++e)0!==e&&(o+=", "),o+=`highp int channelIndex${e}`,a+=`, channelIndex${e}`;e.addFragmentCode(r.l);let c=`\n${Object(r.b)(s)} getDataValue(${o}) {\n  highp ivec3 p = ivec3(max(vec3(0.0, 0.0, 0.0), min(floor(${i}), uChunkDataSize - 1.0)));\n  return getDataValueAt(p${a});\n}\n${Object(r.b)(s)} getInterpolatedDataValue(${o}) {\n  highp vec3 positionWithinChunk = ${i};\n  highp ivec3[2] points;\n  points[0] = ivec3(max(vec3(0.0, 0.0, 0.0), min(floor(positionWithinChunk - 0.5), uChunkDataSize - 1.0)));\n  points[1] = ivec3(max(vec3(0.0, 0.0, 0.0), min(ceil(positionWithinChunk - 0.5), uChunkDataSize - 1.0)));\n  highp vec3 mixCoeff = fract(positionWithinChunk - 0.5);\n  ${Object(r.b)(s)} xvalues[2];\n  for (int ix = 0; ix < 2; ++ix) {\n    ${Object(r.b)(s)} yvalues[2];\n    for (int iy = 0; iy < 2; ++iy) {\n      ${Object(r.b)(s)} zvalues[2];\n      for (int iz = 0; iz < 2; ++iz) {\n        zvalues[iz] = getDataValueAt(ivec3(points[ix].x, points[iy].y, points[iz].z)\n                                     ${a});\n      }\n      yvalues[iy] = mixLinear(zvalues[0], zvalues[1], mixCoeff.z);\n    }\n    xvalues[ix] = mixLinear(yvalues[0], yvalues[1], mixCoeff.y);\n  }\n  return mixLinear(xvalues[0], xvalues[1], mixCoeff.x);\n}\n`;e.addFragmentCode(c),n<=1&&e.addFragmentCode(`\n${Object(r.b)(s)} getDataValue() { return getDataValue(0); }\n${Object(r.b)(s)} getInterpolatedDataValue() { return getInterpolatedDataValue(0); }\n`)}var o=new Array;function a(e){o.push(e)}class c extends i.d{constructor(e,t){super(e,t),this.chunkFormatHandler=this.registerDisposer(function(e,t){for(let n of o){let i=n(e,t);if(null!=i)return i}throw new Error("No chunk format handler found.")}(e.chunkQueueManager.gl,this.spec));const n=this.spec.upperVoxelBound.length;this.tempChunkGridPosition=new Float32Array(n),this.tempPositionWithinChunk=new Uint32Array(n)}static encodeSpec(e){const t=e;return Object.assign(Object.assign({},super.encodeSpec(e)),{dataType:t.dataType,compressedSegmentationBlockSize:t.compressedSegmentationBlockSize&&Array.from(t.compressedSegmentationBlockSize),baseVoxelOffset:Array.from(t.baseVoxelOffset)})}get chunkFormat(){return this.chunkFormatHandler.chunkFormat}getValueAt(e,t){const n=this.spec.rank,i=this.tempChunkGridPosition,r=this.tempPositionWithinChunk,{spec:s}=this;{const{chunkDataSize:t}=s;for(let s=0;s<n;++s){const n=e[s],o=t[s],a=Math.floor(n/o);i[s]=a,r[s]=Math.floor(n-o*a)}}const o=this.chunks.get(i.join());if(void 0===o)return null;const a=o.chunkDataSize;for(let e=0;e<3;++e)if(r[e]>=a[e])return;if(0===t.channelSpaceShape.length)return o.getValueAt(r);const{numChannels:c,chunkChannelCoordinates:l,chunkChannelDimensionIndices:d}=t,u=d.length;let h=0;const p=new Array(c);for(let e=0;e<c;++e){for(let e=0;e<u;++e)r[d[e]]=l[h++];p[e]=o.getValueAt(r)}return p}getChunk(e){return this.chunkFormatHandler.getChunk(this,e)}}class l extends i.c{constructor(e,t){super(e,t),this.chunkDataSize=t.chunkDataSize||e.spec.chunkDataSize}get chunkFormat(){return this.source.chunkFormat}}class d extends i.a{}},function(e,t,n){"use strict";n.d(t,"i",(function(){return m})),n.d(t,"h",(function(){return g})),n.d(t,"b",(function(){return v})),n.d(t,"n",(function(){return b})),n.d(t,"a",(function(){return y})),n.d(t,"m",(function(){return S})),n.d(t,"p",(function(){return w})),n.d(t,"j",(function(){return x})),n.d(t,"g",(function(){return C})),n.d(t,"f",(function(){return O})),n.d(t,"d",(function(){return k})),n.d(t,"e",(function(){return E})),n.d(t,"l",(function(){return I})),n.d(t,"k",(function(){return P})),n.d(t,"o",(function(){return A}));var i=n(85),r=n(38),s=n(132),o=n(14);n.d(t,"c",(function(){return o.c}));var a=n(1),c=(n(19),n(37)),l=n(16);
/**
 * @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=a.m.create();function u(e,t){let n=0,i=e.detTransform;const{transform:r,size:s}=e;for(let e=0;e<3;++e){let o=0;for(let n=0;n<3;++n)o+=t[4*n+2]*r[4*e+n];const a=s[e];n+=Math.abs(o)*a,i*=a}return i/n}function h(e,t,n){const{curPositionInChunks:i,fixedPositionWithinChunk:s}=e,{nonDisplayLowerClipBound:o,nonDisplayUpperClipBound:a}=e,{rank:c,chunkDataSize:l}=e.source.spec;if(!Object(r.e)(i,t,n,e.layerRank,e.fixedLayerToChunkTransform))return!1;for(let e=0;e<c;++e){const t=i[e];if(t<o[e]||t>=a[e])return!1;const n=l[e],r=i[e]=Math.floor(t/n);s[e]=t-r*n}return!0}function p(e,t){let n=t.length,i=0;if(n>1){let r=0;for(let s=0;s<n;++s){let n=t[s];const{chunkLayout:o}=n;let a=u(o,e);0,a>r&&(r=a,i=s)}}return i}const f=new s.a(a.u.create(),a.m.create(),0);class m extends i.a{constructor(){super(...arguments),this.viewportNormalInGlobalCoordinates=a.u.create(),this.viewportNormalInCanonicalCoordinates=a.u.create(),this.centerDataPosition=a.u.create(),this.pixelSize=0}}class g extends l.b{constructor(e){super(),this.projectionParameters=e,this.visibleLayers=new Map,this.visibleSourcesStale=!0,this.registerDisposer(e.changed.add((e,t)=>{(function(e,t){if(e.displayDimensionRenderInfo!==t.displayDimensionRenderInfo)return!0;if(e.pixelSize!==t.pixelSize)return!0;const{viewMatrix:n}=e,{viewMatrix:i}=t;for(let e=0;e<12;++e)if(n[e]!==i[e])return!0;return!1})(e,t)&&this.invalidateVisibleSources(),this.invalidateVisibleChunks()}))}invalidateVisibleSources(){this.visibleSourcesStale=!0}invalidateVisibleChunks(){}updateVisibleSources(){if(!this.visibleSourcesStale)return;this.visibleSourcesStale=!1;const e=this.projectionParameters.value.displayDimensionRenderInfo,{visibleLayers:t}=this;for(const[n,{allSources:i,visibleSources:r,displayDimensionRenderInfo:s}]of t){if(r.length=0,s!==e||0===i.length)continue;const t=p(this.projectionParameters.value.viewMatrix,i.map(e=>e[0])),o=i[t];for(const e of n.filterVisibleSources(this,o))r.push(e);r.reverse()}}}const v=18;function b(e){let{rank:t,upperVoxelBound:n,maxVoxelsPerChunkLog2:i=v,chunkToViewTransform:r,displayRank:s,minBlockSize:o,maxBlockSize:a}=e;const{lowerVoxelBound:l=new Uint32Array(t)}=e,d=new Float32Array(t);for(let e=0;e<t;++e){let t=0;for(let n=0;n<s;++n){const i=r[e*s+n];t+=i*i}d[e]=Math.sqrt(t)}const u=new Uint32Array(t);void 0!==o?u.set(o):u.fill(1);const h=new Array(t);for(let e=0;e<t;++e){let t=Number.POSITIVE_INFINITY;0===d[e]?t=u[e]:(void 0!==n&&(t=Math.pow(2,Math.floor(Math.log2(n[e]-l[e])))),void 0!==a&&(t=Math.min(t,a[e]))),h[e]=t}function p(){let e=1/0,n=-1;for(let i=0;i<t;++i){if(u[i]>=h[i])continue;let t=u[i]*d[i];t<e&&(e=t,n=i)}return n}i-=Math.log2(c.e(u));for(let e=0;e<i;++e){let e=p();if(-1===e)break;u[e]*=2}return u}var y;function S(e){if(void 0!==e.chunkDataSizes)return e.chunkDataSizes;const{chunkLayoutPreference:t=y.ISOTROPIC}=e;switch(t){case y.ISOTROPIC:return[b(e)];case y.FLAT:return function(e){const t=[],{displayRank:n,chunkToViewTransform:i,rank:r}=e;if(n>3)throw new Error("Unsupported view transform");if(n<3)return[b(e)];for(let s=0;s<3;++s){const o=(s+2)%3,a=new Float32Array(i);for(let e=0;e<r;++e)a[e*n+o]=0;t[s]=b(Object.assign(Object.assign({},e),{chunkToViewTransform:a}))}return t}(e)}}function w(e){const{rank:t,chunkDataSize:n,upperVoxelBound:i}=e,{lowerVoxelBound:r=new Float32Array(t)}=e,s=new Float32Array(t),o=new Float32Array(t);for(let e=0;e<t;++e)s[e]=Math.floor(r[e]/n[e]),o[e]=Math.floor((i[e]-1)/n[e]+1);return{rank:t,chunkDataSize:n,lowerChunkBound:s,upperChunkBound:o,lowerVoxelBound:r,upperVoxelBound:i}}function*x(e,t,n){const i=1.1*e.projectionParameters.value.pixelSize,r=n[0].effectiveVoxelSize,s=t.renderScaleTarget.value,o=e=>{const t=i*s;for(let n=0;n<3;++n){const i=e[n];if(i>t&&i>1.01*r[n])return!0}return!1},a=(e,t)=>{const n=i*s;for(let i=0;i<3;++i){const r=e[i],s=t[i];if(Math.abs(n-r)<Math.abs(n-s)&&r<1.01*s)return!0}return!1};let c,l=n.length-1;for(;;){const e=n[l];if(void 0!==c&&!a(e.effectiveVoxelSize,c))break;if(yield e,0===l||!o(e.effectiveVoxelSize))break;c=e.effectiveVoxelSize,--l}}!function(e){e[e.ISOTROPIC=0]="ISOTROPIC",e[e.FLAT=1]="FLAT"}(y||(y={}));const C="SliceView",O="sliceview/RenderLayer",k="SliceView.addVisibleLayer",E="SliceView.removeVisibleLayer",T=new Float32Array(3),M=new Float32Array(3),D=a.m.create(),L=new Float32Array(24);function j(e,t,n,i){const r=T,s=M,{lowerChunkDisplayBound:o,upperChunkDisplayBound:a}=t;for(let e=0;e<3;++e)r[e]=Math.max(r[e],o[e]),s[e]=Math.min(s[e],a[e]);const{curPositionInChunks:c,chunkDisplayDimensionIndices:l}=t;!function t(){if(!i(r[0],r[1],r[2],s[0],s[1],s[2],e))return;let o=0,a=Math.max(0,s[0]-r[0]),d=a;for(let e=1;e<3;++e){const t=Math.max(0,s[e]-r[e]);d*=t,t>a&&(a=t,o=e)}if(0===d)return;if(1===d)return c[l[0]]=r[0],c[l[1]]=r[1],c[l[2]]=r[2],void n(r,e);const u=r[o],h=s[o],p=Math.floor(.5*(u+h));s[o]=p,t(),s[o]=h,r[o]=p,t(),r[o]=u}()}function I(e,t,n,i){if(!h(n,e.globalPosition,t))return;const{size:r}=n.chunkLayout,s=a.m.multiply(D,e.viewProjectionMat,n.chunkLayout.transform);for(let e=0;e<3;++e){const t=r[e];for(let n=0;n<4;++n)s[4*e+n]*=t}const o=L;Object(a.c)(o,s);const c=M;T.fill(Number.NEGATIVE_INFINITY),c.fill(Number.POSITIVE_INFINITY),j(o,n,i,a.h)}function P(e,t,n,i){if(!h(n,e.globalPosition,t))return;const{size:r}=n.chunkLayout,s=a.m.multiply(D,e.viewProjectionMat,n.chunkLayout.transform);for(let e=0;e<3;++e){const t=r[e];for(let n=0;n<4;++n)s[4*e+n]*=t}const o=d;a.m.invert(o,s);const c=T,l=M;for(let e=0;e<3;++e){const t=o[12+e]+.001/r[e],n=Math.abs(o[e]),i=Math.abs(o[4+e]);c[e]=Math.floor(t-n-i),l[e]=Math.floor(t+n+i+1)}const u=L;for(let e=0;e<3;++e){const t=s[4*e],n=s[4*e+1],i=s[4*e+2];u[e]=t,u[4+e]=-t,u[8+e]=+n,u[12+e]=-n,u[16+e]=+i,u[20+e]=-i}{const e=3,t=s[4*e],n=s[4*e+1],i=s[4*e+2];u[e]=1+t,u[4+e]=1-t,u[8+e]=1+n,u[12+e]=1-n,u[16+e]=i,u[20+e]=-i}j(u,n,i,a.g)}function A(e,t){const{finiteRank:n}=t;if(3===n)return t;f.finiteRank=n,a.u.copy(f.size,t.size);const i=a.m.copy(f.transform,t.transform),r=a.m.copy(f.invTransform,t.invTransform);f.detTransform=t.detTransform;const{invViewMatrix:s,width:o,height:c}=e;for(let e=n;e<3;++e){const t=s[12+e];let n=t,r=t;const a=Math.abs(s[e]*o);n-=a,r+=a;const l=Math.abs(s[e+4]*c);n-=l,r+=l;const d=Math.max(1,r-n);i[12+e]=n,i[5*e]=d}return a.m.invert(r,i),f}},function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));n(207);
/**
 * @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 i(e){const{title:t,onClick:n,href:i}=e;let r;void 0!==i?(r=document.createElement("a"),r.href=i,r.target="_blank"):r=document.createElement("div"),void 0!==t&&(r.title=t),void 0!==n&&r.addEventListener("click",n);const{svg:s}=e;return r.className="neuroglancer-icon",void 0!==s&&(r.innerHTML=s),void 0!==e.text&&r.appendChild(document.createTextNode(e.text)),r}},function(e,t,n){"use strict";n.d(t,"d",(function(){return a})),n.d(t,"c",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"e",(function(){return d})),n.d(t,"a",(function(){return u}));var i=n(4),r=n(0),s=n(31),o=n(3);
/**
 * @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 a=40;function c(e){return(Math.log2(e)- -4)/.5}function l(e){return 2**(.5*e-4)}function d(e){return new i.c(e,r.r)}class u{constructor(){this.visibility=new s.a,this.changed=new o.a,this.frameNumber=-1,this.spatialScales=new Map,this.numHistogramRows=1,this.value=new Uint32Array(a*this.numHistogramRows*2)}begin(e){e!==this.frameNumber&&(this.value.fill(0),this.frameNumber=e,this.spatialScales.clear(),this.changed.dispatch())}add(e,t,n,i){let{spatialScales:r,numHistogramRows:s,value:o}=this,l=r.get(e);if(void 0===l&&(l=r.size,r.set(e,l)),l>=s){this.numHistogramRows=s*=2;const e=new Uint32Array(s*a*2);e.set(o),this.value=o=e}const d=l*a*2+Math.min(Math.max(0,Math.round(c(t))),a-1);o[d]+=n,o[d+a]+=i}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"b",(function(){return o})),n.d(t,"c",(function(){return a})),n.d(t,"d",(function(){return c}));var i=n(76),r=n(20);
/**
 * @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 s=i.a;function o(e,t=!1){e.addVertexCode(i.c),e.addUniform("highp vec3","uLineParams"),e.addVarying("highp float","vLineCoord"),e.addVarying("highp float","vLineFeatherFraction"),t&&(e.addVarying("highp float","vEndpointFraction"),e.addVarying("highp float","vLineCoordT"),e.addVarying("highp float","vLineBorderStartFraction")),e.addVertexCode(r.c),e.addVertexCode(`\nvec2 getLineOffset() { return getQuadVertexPosition(vec2(0.0, -1.0), vec2(1.0, 1.0)); }\nfloat getLineEndpointCoefficient() { return getLineOffset().x; }\nuint getLineEndpointIndex() { return uint(getLineEndpointCoefficient()); }\nvoid emitLine(vec4 vertexAClip, vec4 vertexBClip, float lineWidthInPixels\n              ${t?", float borderWidth":""}) {\n  if (!clipLineToDepthRange(vertexAClip, vertexBClip)) {\n    gl_Position = vec4(2.0, 2.0, 2.0, 1.0);\n    return;\n  }\n  vec3 vertexADevice = vertexAClip.xyz / vertexAClip.w;\n  vec3 vertexBDevice = vertexBClip.xyz / vertexBClip.w;\n\n  vec2 lineDirectionUnnormalized = vertexBDevice.xy - vertexADevice.xy;\n  vec2 lineDirection;\n  float linePixelLength = length(lineDirectionUnnormalized / uLineParams.xy * 0.5);\n\n  if (linePixelLength < 1e-3) {\n    lineDirection = vec2(1.0, 0.0);\n    vertexADevice.z = vertexBDevice.z = 0.0;\n  } else {\n    lineDirection = normalize(lineDirectionUnnormalized);\n  }\n  vec2 lineNormal = normalize(vec2(lineDirection.y, -lineDirection.x) / uLineParams.yx * uLineParams.xy);\n\n  vec2 lineOffset = getLineOffset();\n  gl_Position = vec4(mix(vertexADevice, vertexBDevice, lineOffset.x), 1.0);\n  float totalLineWidth = lineWidthInPixels + 2.0 * uLineParams.z ${t?" + 2.0 * borderWidth":""};\n  vLineFeatherFraction = max(1e-6, uLineParams.z) / totalLineWidth;\n  gl_Position.xy += (lineOffset.y * lineNormal\n                     ${t?"+ lineDirection * (2.0 * lineOffset.x - 1.0)":""})\n                  * totalLineWidth * uLineParams.xy;\n  vLineCoord = lineOffset.y;\n  ${t?"vEndpointFraction = totalLineWidth / (linePixelLength + totalLineWidth * 2.0);":""}\n  ${t?"vLineCoordT = lineOffset.x; vLineBorderStartFraction = lineWidthInPixels / totalLineWidth;":""}\n}\nvoid emitLine(mat4 projection, vec3 vertexA, vec3 vertexB, float lineWidthInPixels\n              ${t?", float borderWidth":""}) {\n  emitLine(projection * vec4(vertexA, 1.0), projection * vec4(vertexB, 1.0),\n           lineWidthInPixels\n           ${t?", borderWidth":""});\n}\n`),t&&e.addFragmentCode("\nvec4 getRoundedLineColor(vec4 interiorColor, vec4 borderColor) {\n  float radius;\n  if (vLineCoordT < vEndpointFraction || vLineCoordT > 1.0 - vEndpointFraction) {\n    radius = length(vec2(1.0 - min(vLineCoordT, 1.0 - vLineCoordT) / vEndpointFraction,\n                         vLineCoord));\n    if (radius > 1.0) {\n      discard;\n    }\n  } else {\n    radius = abs(vLineCoord);\n  }\n  float borderColorFraction = clamp((radius - vLineBorderStartFraction) / vLineFeatherFraction, 0.0, 1.0);\n  float feather = clamp((1.0 - radius) / vLineFeatherFraction, 0.0, 1.0);\n  vec4 color = mix(interiorColor, borderColor, borderColorFraction);\n  return vec4(color.rgb, color.a * feather);\n}\n"),e.addFragmentCode("\nfloat getLineAlpha() {\n  return clamp((1.0 - abs(vLineCoord)) / vLineFeatherFraction, 0.0, 1.0);\n}\n")}function a(e,t,n){Object(i.b)(e,t,n)}function c(e,t,n){const{gl:i}=e;i.uniform3f(e.uniform("uLineParams"),1/t.width,1/t.height,n)}},function(e,t,n){"use strict";
/**
 * @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 i(e){let t=-1;return Object.assign(()=>{-1===t&&(t=requestAnimationFrame(()=>{t=-1,e()}))},{flush:()=>{-1!==t&&(t=-1,e())},cancel:()=>{-1!==t&&(cancelAnimationFrame(t),t=-1)}})}n.d(t,"a",(function(){return i}))},function(e,t,n){"use strict";n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return o})),n.d(t,"c",(function(){return a}));var i=n(58),r=n(4);
/**
 * @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 s extends r.e{constructor(e=Number.NEGATIVE_INFINITY){super(e)}get visible(){return this.value===Number.POSITIVE_INFINITY}get ignored(){return this.value===Number.NEGATIVE_INFINITY}}s.VISIBLE=Number.POSITIVE_INFINITY,s.IGNORED=Number.NEGATIVE_INFINITY;class o extends s{constructor(){super(...arguments),this.contributors=new Map}add(e){const{contributors:t}=this,n=e.changed.add(()=>{this.update()}),i=()=>{t.delete(i),n(),this.update()};return t.set(i,e),this.update(),i}update(){let e=Number.NEGATIVE_INFINITY;for(const t of this.contributors.values())e=Math.max(e,t.value);this.value=e}}function a(e){return class extends e{constructor(){super(...arguments),this.visibility=new o}initializeCounterpart(e,t={}){t.visibility=this.registerDisposer(i.a.makeFromExisting(e,this.visibility)).rpcId,super.initializeCounterpart(e,t)}}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return a})),n.d(t,"a",(function(){return c})),n.d(t,"c",(function(){return l})),n.d(t,"d",(function(){return d})),n.d(t,"e",(function(){return u}));var i=n(4),r=n(0),s=n(45),o=n(74);
/**
 * @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 a(){return new i.e(void 0)}function c(e){return new i.c(e,r.E)}function l(e,t,n){const s=new Map,{parameters:a,fallbackParameters:c,shaderError:l,encodeParameters:d=(e=>e),extraParameters:u=Object(i.f)(void 0),encodeExtraParameters:h=(e=>e),getContextKey:p,defineShader:f}=n;void 0!==l&&(l.value=void 0);const{encodeContext:m=p}=n,g=Object(r.h)(n.memoizeKey);function v(e,n,i){const r=JSON.stringify({id:g,context:m(e),parameters:d(n),extraParameters:h(i)});return t.memoize.get(r,()=>{const r=new o.a(t);return f(r,e,n,i),r.build()})}return e.registerDisposer(()=>{for(const e of s.values()){const{shader:t}=e;null!==t&&t.dispose()}}),function(e){const t=m(e);let n=s.get(t);void 0===n&&(n={parametersGeneration:-1,extraParametersGeneration:-1,shader:null,fallback:!1,parameters:a.value,extraParameters:u.value},s.set(t,n));const i=a.changed.count,r=u.changed.count;if(i===n.parametersGeneration&&r===n.extraParametersGeneration)return n;const o=n.parameters=a.value,d=n.extraParameters=u.value,h=n.shader;n.parametersGeneration=i,n.extraParametersGeneration=r;let p=null;try{p=v(e,o,d),n.fallback=!1,void 0!==c&&(c.value=o),void 0!==l&&(l.value=null)}catch(t){if(void 0!==l&&(l.value=t),void 0!==c)try{const t=c.value;p=v(e,t,d),n.parameters=t,n.fallback=!0}catch(e){}}return null!==h&&h.dispose(),n.shader=p,n}}function d(e,t,n){return l(e,t,{memoizeKey:n.memoizeKey,fallbackParameters:n.fallbackParameters,encodeParameters:n.encodeParameters,parameters:n.parameters,getContextKey:e=>e,encodeContext:e=>Object(s.a)(e),shaderError:n.shaderError,extraParameters:n.extraParameters,encodeExtraParameters:n.encodeExtraParameters,defineShader:(e,t,i,r)=>(e.require(t),n.defineShader(e,i,r))})}function u(e,t=1,n=0){return`\n#line ${n} ${t}\n`+e}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},function(e,t,n){"use strict";n.d(t,"d",(function(){return l})),n.d(t,"c",(function(){return i})),n.d(t,"f",(function(){return u})),n.d(t,"a",(function(){return h})),n.d(t,"e",(function(){return p})),n.d(t,"b",(function(){return g}));var i,r=n(5),s=n(39),o=n(42),a=n(2),c=n(19);
/**
 * @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 l extends Error{constructor(e){super(`Redirected to: ${e}`),this.redirectTarget=e}}function d(e,t){void 0===t&&(t=-1===e.indexOf("/")?":":"/");let n=e.lastIndexOf(t);return-1===n?0:n+1}function u(){return{url:"",transform:void 0,enableDefaultSubsources:!0,subsources:new Map}}!function(e){e[e.annotations=0]="annotations"}(i||(i={}));class h extends a.a{normalizeUrl(e){return e.url}convertLegacyUrl(e){return e.url}async completeUrl(e){throw null}}const p="local://annotations";class f extends h{constructor(){super(...arguments),this.description="Local in-memory"}async get(e){if(e.url===p){const{transform:t}=e;let n;if(void 0===t){const t=e.globalCoordinateSpace.value,{rank:i,names:s,scales:o,units:a}=t;n={rank:i,sourceRank:i,inputSpace:Object(r.y)({rank:i,scales:o,units:a,names:s.map((e,t)=>`${t}`)}),outputSpace:Object(r.y)({rank:i,scales:o,units:a,names:s}),transform:Object(c.c)(Float64Array,i+1)}}else n=Object(r.z)(r.l);return{modelTransform:n,canChangeModelSpaceRank:!0,subsources:[{id:"default",default:!0,subsource:{local:i.annotations}}]}}throw new Error("Invalid local data source URL")}async completeUrl(e){return{offset:0,completions:Object(o.d)(e.providerUrl,[{value:"annotations",description:"Annotations stored in the JSON state"}],e=>e.value,e=>e.description)}}}const m=/^(?:([a-zA-Z][a-zA-Z0-9-+_]*):\/\/)?(.*)$/;class g extends a.a{constructor(){super(...arguments),this.dataSources=new Map([["local",new f]])}register(e,t){this.dataSources.set(e,this.registerDisposer(t))}getProvider(e){const t=e.match(m);if(null===t||void 0===t[1])throw new Error('Data source URL must have the form "<protocol>://<path>".');const[,n,i]=t,r=this.dataSources.get(n);if(void 0===r)throw new Error(`Unsupported data source: ${JSON.stringify(n)}.`);return[r,i,n]}async get(e){const t=new Set,{cancellationToken:n=s.e}=e;let i=e.url;for(;;){const[r,s,o]=this.getProvider(e.url);t.add(e.url);try{return r.get(Object.assign(Object.assign({},e),{url:i,providerProtocol:o,providerUrl:s,registry:this,cancellationToken:n}))}catch(e){if(e instanceof l){const n=e.redirectTarget;if(t.has(n))throw Error(`Layer source redirection contains loop: ${JSON.stringify(Array.from(t))}`);if(t.size>=10)throw Error(`Too many layer source redirections: ${JSON.stringify(Array.from(t))}`);i=n;continue}throw e}}}convertLegacyUrl(e){try{const[t,n,i]=this.getProvider(e.url);return t.convertLegacyUrl(Object.assign(Object.assign({},e),{providerUrl:n,providerProtocol:i,registry:this}))}catch(t){return e.url}}normalizeUrl(e){try{const[t,n,i]=this.getProvider(e.url);return t.normalizeUrl(Object.assign(Object.assign({},e),{providerUrl:n,providerProtocol:i,registry:this}))}catch(t){return e.url}}async completeUrl(e){const{url:t,cancellationToken:n=s.e}=e;let i=t.match(m),r=i[1];if(void 0===r)return Promise.resolve({offset:0,completions:Object(o.d)(t,this.dataSources,([e])=>`${e}://`,([,e])=>e.description)});{const s=this.dataSources.get(r);if(void 0!==s){const a=await s.completeUrl({registry:this,url:t,providerUrl:i[2],chunkManager:e.chunkManager,cancellationToken:n});return Object(o.a)(r.length+3,a)}throw null}}suggestLayerName(e){let[t,n]=this.getProvider(e);n.endsWith("/")&&(n=n.substring(0,n.length-1));let i=t.suggestLayerName;return void 0!==i?i(n):function(e,t){let n=d(e,t);return e.substring(n)}(n)}findSourceGroup(e){let[t,n,i]=this.getProvider(e);return(t.findSourceGroup||d)(n)+i.length+3}}},function(e,t,n){"use strict";n.d(t,"c",(function(){return a})),n.d(t,"e",(function(){return b})),n.d(t,"d",(function(){return y})),n.d(t,"f",(function(){return S})),n.d(t,"h",(function(){return w})),n.d(t,"g",(function(){return x})),n.d(t,"a",(function(){return k})),n.d(t,"b",(function(){return E}));var i=n(7),r=n(14),s=n(20),o=n(101);
/**
 * @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 a{}const c=[-1,WebGL2RenderingContext.RED_INTEGER,WebGL2RenderingContext.RG_INTEGER,WebGL2RenderingContext.RGB_INTEGER,WebGL2RenderingContext.RGBA_INTEGER],l=[-1,WebGL2RenderingContext.RED,WebGL2RenderingContext.RG,WebGL2RenderingContext.RGB,WebGL2RenderingContext.RGBA],d=["","r","rg","rgb","rgba"],u=[-1,WebGL2RenderingContext.R8UI,WebGL2RenderingContext.RG8UI,WebGL2RenderingContext.RGB8UI,WebGL2RenderingContext.RGBA8UI],h=[-1,WebGL2RenderingContext.R8I,WebGL2RenderingContext.RG8I,WebGL2RenderingContext.RGB8I,WebGL2RenderingContext.RGBA8I],p=[-1,WebGL2RenderingContext.R16UI,WebGL2RenderingContext.RG16UI,WebGL2RenderingContext.RGB16UI,WebGL2RenderingContext.RGBA16UI],f=[-1,WebGL2RenderingContext.R16I,WebGL2RenderingContext.RG16I,WebGL2RenderingContext.RGB16I,WebGL2RenderingContext.RGBA16I],m=[-1,WebGL2RenderingContext.R32UI,WebGL2RenderingContext.RG32UI,WebGL2RenderingContext.RGB32UI,WebGL2RenderingContext.RGBA32UI],g=[-1,WebGL2RenderingContext.R32I,WebGL2RenderingContext.RG32I,WebGL2RenderingContext.RGB32I,WebGL2RenderingContext.RGBA32I],v=[-1,WebGL2RenderingContext.R32F,WebGL2RenderingContext.RG32F,WebGL2RenderingContext.RGB32F,WebGL2RenderingContext.RGBA32F];function b(e){return e===r.c.FLOAT32?"":r.b[e]?"i":"u"}function y(e,t,n=1){switch(t){case r.c.UINT8:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=u[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.UNSIGNED_BYTE,e.arrayElementsPerTexel=n,e.arrayConstructor=Uint8Array,e.samplerPrefix="u",e;case r.c.INT8:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=h[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.BYTE,e.arrayElementsPerTexel=n,e.arrayConstructor=Int8Array,e.samplerPrefix="i",e;case r.c.UINT16:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=p[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.UNSIGNED_SHORT,e.arrayElementsPerTexel=n,e.arrayConstructor=Uint16Array,e.samplerPrefix="u",e;case r.c.INT16:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=f[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.SHORT,e.arrayElementsPerTexel=n,e.arrayConstructor=Int16Array,e.samplerPrefix="i",e;case r.c.UINT32:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=m[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.UNSIGNED_INT,e.arrayElementsPerTexel=1,e.arrayConstructor=Uint32Array,e.samplerPrefix="u",e;case r.c.INT32:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=g[n],e.textureFormat=c[n],e.texelType=WebGL2RenderingContext.INT,e.arrayElementsPerTexel=1,e.arrayConstructor=Int32Array,e.samplerPrefix="i",e;case r.c.UINT64:if(n<1||n>2)break;return e.texelsPerElement=1,e.textureInternalFormat=m[2*n],e.textureFormat=c[2*n],e.texelType=WebGL2RenderingContext.UNSIGNED_INT,e.arrayElementsPerTexel=2*n,e.arrayConstructor=Uint32Array,e.samplerPrefix="u",e;case r.c.FLOAT32:if(n<1||n>4)break;return e.texelsPerElement=1,e.textureInternalFormat=v[n],e.textureFormat=l[n],e.texelType=WebGL2RenderingContext.FLOAT,e.arrayElementsPerTexel=n,e.arrayConstructor=Float32Array,e.samplerPrefix="",e}throw new Error(`No supported texture format for ${r.c[t]}[${n}].`)}function S(e,t,n){const{arrayConstructor:r,arrayElementsPerTexel:s,textureInternalFormat:a,textureFormat:c,texelsPerElement:l}=t,{maxTextureSize:d}=e,u=n.length/s;if(u*l>d*d)throw new Error("Number of elements exceeds maximum texture size: "+l+" * "+u);const h=Math.ceil(u/d),p=Math.ceil(Math.log2(h)),f=(1<<p)*l,m=Math.ceil(u/(1<<p)),g=f*m*s;n.constructor!==r&&(n=new r(n.buffer,n.byteOffset,n.byteLength/r.BYTES_PER_ELEMENT));let v=Object(i.i)(n,g);e.pixelStorei(WebGL2RenderingContext.UNPACK_ALIGNMENT,1),Object(o.c)(e),e.texImage2D(WebGL2RenderingContext.TEXTURE_2D,0,a,f,m,0,c,t.texelType,v)}function w(e,t,n,i,r){const{arrayConstructor:s,textureInternalFormat:a,textureFormat:c,texelsPerElement:l}=t;n.constructor!==s&&(n=new s(n.buffer,n.byteOffset,n.byteLength/s.BYTES_PER_ELEMENT)),e.pixelStorei(WebGL2RenderingContext.UNPACK_ALIGNMENT,1),Object(o.c)(e),e.texImage2D(WebGL2RenderingContext.TEXTURE_2D,0,a,i*l,r,0,c,t.texelType,n)}function x(e,t,n,i,r,s){const{arrayConstructor:a,textureInternalFormat:c,textureFormat:l,texelsPerElement:d}=t;n.constructor!==a&&(n=new a(n.buffer,n.byteOffset,n.byteLength/a.BYTES_PER_ELEMENT)),e.pixelStorei(WebGL2RenderingContext.UNPACK_ALIGNMENT,1),Object(o.b)(e),e.texImage3D(WebGL2RenderingContext.TEXTURE_3D,0,c,i*d,r,s,0,l,t.texelType,n)}function C(e){switch(e){case r.c.UINT8:return s.p;case r.c.INT8:return s.j;case r.c.UINT16:return s.m;case r.c.INT16:return s.h;case r.c.UINT32:return s.n;case r.c.INT32:return s.i;case r.c.UINT64:return s.o;case r.c.FLOAT32:return s.e}}function O(e,t,n,i,o,a){const c=Object(s.b)(o,a);let l=[C(o)],u=`\n${c} ${e}(${i} index) {\n`;switch(o){case r.c.UINT8:case r.c.UINT16:case r.c.UINT32:u+=`\n  ${c} result;\n  highp uvec4 temp;\n  ${t}(${n}, index, temp);\n  result.value = temp.${d[a]};\n  return result;\n`;break;case r.c.INT8:case r.c.INT16:case r.c.INT32:u+=`\n  ${c} result;\n  highp ivec4 temp;\n  ${t}(${n}, index, temp);\n  result.value = temp.${d[a]};\n  return result;\n`;break;case r.c.UINT64:l.push(s.q),u+=`\n  highp uvec4 temp;\n  ${t}(${n}, index, temp);\n  return unpackUint64leFromUint32(temp.${d[2*a]});\n`;break;case r.c.FLOAT32:l.push(s.e),u+=`\n  highp vec4 temp;\n  ${t}(${n}, index, temp);\n  return temp.${d[a]};\n`}return u+="\n}\n",l.push(u),l}class k{constructor(e){this.key=e,this.readTextureValue=`readTextureValue_${this.key}`}defineShader(e){}getReadTextureValueCode(e,t){let n=`\nvoid ${this.readTextureValue}(highp ${t}sampler2D sampler, highp uint index`;for(let i=0;i<e;++i)n+=`, out ${t}vec4 output${i}`;n+=`) {\n  highp int width = textureSize(sampler, 0).x / ${e};\n  highp uint log2width = log2Exact(uint(width));\n  highp int y = int(index >> log2width);\n  highp int x = int((index - (uint(y) << log2width)) * ${e}u);\n`;for(let t=0;t<e;++t)n+=`\n  output${t} = texelFetch(sampler, ivec2(x + ${t}, y), 0);\n`;return n+="\n}\n",[s.k,n]}getAccessor(e,t,n,i=1){const r=b(n);return[this.getReadTextureValueCode(1,r),...O(e,this.readTextureValue,t,"highp uint",n,i)]}}class E{constructor(e,t){this.key=e,this.textureDims=t,this.readTextureValue=`readTextureValue_${this.key}`}getReadTextureValueCode(e,t){const{textureDims:n}=this;let i=`\nvoid ${this.readTextureValue}(highp ${t}sampler${this.textureDims}D sampler, highp ivec${n} p`;for(let n=0;n<e;++n)i+=`, out ${t}vec4 output${n}`;i+=") {\n";for(let t=0;t<e;++t)i+=`\n  output${t} = texelFetch(sampler, ivec${n}(p.x * ${e} + ${t}, p.y\n                                         ${3===n?", p.z":""}), 0);\n`;return i+="\n}\n",i}getAccessor(e,t,n,i=1){const r=b(n);return[this.getReadTextureValueCode(1,r),...O(e,this.readTextureValue,t,`highp ivec${this.textureDims}`,n,i)]}}},function(e,t,n){"use strict";n.d(t,"c",(function(){return i})),n.d(t,"f",(function(){return y})),n.d(t,"b",(function(){return S})),n.d(t,"e",(function(){return w})),n.d(t,"g",(function(){return x})),n.d(t,"a",(function(){return C})),n.d(t,"d",(function(){return O}));var i,r=n(15),s=n.n(r),o=n(10),a=n(85),c=n(38),l=n(117),d=n(4),u=n(2),h=n(1),p=n(57),f=n(3),m=n(31),g=n(16),v=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o},b=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n};function y(){return new d.d([i.DATA,i.ANNOTATION,i.DEFAULT_ANNOTATION])}!function(e){e[e.DATA=0]="DATA",e[e.ANNOTATION=1]="ANNOTATION",e[e.DEFAULT_ANNOTATION=2]="DEFAULT_ANNOTATION"}(i||(i={}));class S extends u.a{constructor(){super(...arguments),this.role=i.DATA,this.messages=new p.a,this.layerChanged=new f.a,this.redrawNeeded=new f.a,this.layerChunkProgressInfo=new o.i}handleAction(e){}getValueAt(e){}transformPickedValue(e,t){return e}updateMouseState(e,t,n,i){}}class w extends S{constructor(){super(...arguments),this.visibility=new m.a}attach(e){}}function x(e,t,n){let{state:i}=n;if(void 0===i||i.transform!==e||i.displayDimensionRenderInfo!==t){if(n.messages.clearMessages(),i=n.state={transform:e,displayDimensionRenderInfo:t,modelTransform:void 0},void 0!==e.error)return void n.messages.addMessage({severity:p.b.error,message:e.error});try{const n=h.m.create();Object(c.b)(n,t,e),i.modelTransform=n}catch(e){n.messages.addMessage({severity:p.b.error,message:e.message})}}return i.modelTransform}class C extends u.a{constructor(e){super(),this.width=0,this.height=0,this.changed=new f.b;const{parametersConstructor:t=a.a,navigationState:n,update:i,isEqual:r=a.b}=e;this.oldValue_=new t,this.value_=new t;const o=()=>{const{oldValue_:e,value_:t}=this;e.displayDimensionRenderInfo=n.displayDimensionRenderInfo.value,e.width=this.width,e.height=this.height;let{globalPosition:s}=e;const o=n.position.value,a=o.length;s.length!==a&&(e.globalPosition=s=new Float32Array(a)),s.set(o),i(e,n),r(e,t)||(this.value_=e,this.oldValue_=t,this.changed.dispatch(t,e))},c=this.update=this.registerCancellable(s()(o,0));this.registerDisposer(n.changed.add(c)),o()}setViewportShape(e,t){this.width===e&&this.height===t||(this.width=e,this.height=t,this.update())}get value(){return this.update.flush(),this.value_}}let O=class extends g.b{constructor(e,t,n=10){super(),this.base=t,this.updateInterval=n,this.update=this.registerCancellable(s()((e,t)=>{let n;if(t.displayDimensionRenderInfo!==e.displayDimensionRenderInfo)n=t;else{const{displayDimensionRenderInfo:e}=t;n=b(t,["displayDimensionRenderInfo"])}this.rpc.invoke(l.a,{id:this.rpcId,value:n})},this.updateInterval)),this.initializeCounterpart(e,{value:t.value}),this.registerDisposer(t.changed.add(this.update))}flush(){this.update.flush()}};O=v([Object(g.g)(l.b)],O)},function(e,t,n){"use strict";function i(e,t,n){const i=e.length;for(let r=0;r<i;++r)e[r]=t[r]+n[r];return e}function r(e,t,n){const i=e.length;for(let r=0;r<i;++r)e[r]=t[r]-n[r];return e}function s(e,t,n,i){const r=e.length;for(let s=0;s<r;++s)e[s]=t[s]+n[s]*i;return e}function o(e,t,n){const i=e.length;for(let r=0;r<i;++r)e[r]=t[r]*n;return e}function a(e){let t=1;for(let n=0,i=e.length;n<i;++n)t*=e[n];return t}function c(e,t,n){const i=e.length;for(let r=0;r<i;++r)e[r]=Math.min(t[r],n[r]);return e}n.d(t,"a",(function(){return i})),n.d(t,"h",(function(){return r})),n.d(t,"g",(function(){return s})),n.d(t,"f",(function(){return o})),n.d(t,"e",(function(){return a})),n.d(t,"d",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"c",(function(){return d}));const l=new Float32Array(0),d=new Float64Array(0);Float64Array.of(1,1,1)},function(e,t,n){"use strict";n.d(t,"c",(function(){return l})),n.d(t,"h",(function(){return h})),n.d(t,"i",(function(){return p})),n.d(t,"a",(function(){return f})),n.d(t,"f",(function(){return m})),n.d(t,"g",(function(){return g})),n.d(t,"d",(function(){return v})),n.d(t,"e",(function(){return b})),n.d(t,"b",(function(){return y}));var i=n(5),r=n(4),s=n(7),o=n(1),a=n(19),c=n(37);
/**
 * @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.
 */
i.l,new Uint32Array(0),new Uint32Array(0);function l(e){const{rank:t}=e,{bounds:{lowerBounds:n,upperBounds:i}}=e;if(n.some(e=>0!==e))throw new Error("Lower bounds of channel coordinate space must all be 0");if(i.some(e=>!Number.isInteger(e)||e<=0||e>=2**32))throw new Error("Upper bounds of channel coordinate space must all be positive integers");const r=new Uint32Array(i),s=Object(c.e)(r),o=new Uint32Array(s*t);for(let e=0;e<s;++e){let n=e;for(let i=0;i<t;++i){const s=n%r[i];n=(n-s)/r[i],o[e*t+i]=s}}return{channelCoordinateSpace:e,shape:r,numChannels:s,coordinates:o}}function d(e,t,n,i,r,s){const{scales:o}=n,{scales:a,rank:c}=r,l=t+1;for(let n=0;n<c;++n){const r=s[n];if(-1===r)continue;const c=a[n];for(let n=0;n<t;++n){const t=o[i[n]];e[l*n+r]*=t/c}}}function u(e,t){return e===t||void 0===e.error&&void 0===t.error&&(Object(s.a)(e.modelDimensionNames,t.modelDimensionNames)&&Object(s.a)(e.layerDimensionNames,t.layerDimensionNames)&&Object(s.a)(e.globalToRenderLayerDimensions,t.globalToRenderLayerDimensions)&&Object(s.a)(e.localToRenderLayerDimensions,t.localToRenderLayerDimensions)&&Object(s.a)(e.channelToRenderLayerDimensions,t.channelToRenderLayerDimensions)&&Object(s.a)(e.modelToRenderLayerTransform,t.modelToRenderLayerTransform)&&Object(s.a)(e.channelSpaceShape,t.channelSpaceShape))}function h(e,t,n,s,c){return Object(r.g)((e,t,n,r)=>function(e,t,n,r,s=i.l){const{inputSpace:c,rank:l,sourceRank:u,outputSpace:h,transform:p}=n,{names:f}=c,{names:m}=h;let g;if(void 0!==r)g=Array.from(r.modelSubspaceDimensionIndices);else{g=[];for(let e=0;e<u;++e)g[e]=e}const v=g.length;for(let e=u;e<l;++e)g.push(e);const b=Object(o.b)(n.transform,l,g,!0),y=g.length,S=g.map(e=>f[e]||`${e}`),w=b.map(e=>m[e]);if(y!==b.length)return{error:"Rank mismatch between model subspace dimensions ("+S.join(", ")+") and corresponding layer/global dimensions ("+w.join(", ")+")"};let x=Object(i.s)(Float32Array,p,l,b,g);const C=b.map(e=>m[e]),O=t.names.map(e=>C.indexOf(e)),k=e.names.map(e=>C.indexOf(e));d(x,y,c,g,e,k),d(x,y,c,g,t,O);const E=s.names.map(e=>C.indexOf(e));d(x,y,c,g,s,E);const T=[],M=s.rank;if(void 0!==r){let{subsourceToModelSubspaceTransform:e}=r;v!==y&&(e=a.e(new Float32Array((y+1)**2),y,e,v)),x=a.i(new Float32Array((y+1)**2),y+1,x,y+1,e,y+1,y+1,y+1,y+1)}const D=new Uint32Array(M);for(let e=0;e<M;++e){const t=s.bounds.lowerBounds[e],n=s.bounds.upperBounds[e];if(0!==t||!Number.isInteger(n)||n<=0||n>=2**32)return{error:`Channel dimension ${s.names[e]} must have `+"lower bound of 0 and positive integer upper bound"};D[e]=n;const i=E[e];let r=-1;if(-1!==i)for(let e=0;e<y;++e){const t=x[i+e*(y+1)];if(0!==t){if(1!==t||-1!==r)return{error:`Channel dimension ${w[i]} `+"must map to a single source dimension"};r=e}}T[e]=r}return{rank:y,unpaddedRank:v,modelDimensionNames:S,layerDimensionNames:w,localToRenderLayerDimensions:O,globalToRenderLayerDimensions:k,channelToRenderLayerDimensions:E,modelToRenderLayerTransform:x,channelToModelDimensions:T,channelSpaceShape:D}}(e,t,n,s,r),[e,t,n,void 0===c?Object(r.f)(void 0):c],u)}function p(e,t,n,i){const{globalToRenderLayerDimensions:r}=n;for(let n=0;n<3;++n){let s=0;const o=i[n];if(-1!==o){const e=r[o];-1!==e&&(s=t[e])}e[n]=s}}function f(e,t,n,i){const{globalToRenderLayerDimensions:r}=n;for(let n=0;n<3;++n){const s=i[n];if(-1!==s){const i=r[s];-1!==i&&(e[i]=t[n])}}}function m(e,t){const n=e.rank,i=e.unpaddedRank;let r;i!==n&&void 0!==t&&(t=a.e(new Float32Array((n+1)**2),n,t,i)),void 0!==t?(r=new Float32Array((n+1)*(n+1)),a.i(r,n+1,e.modelToRenderLayerTransform,n+1,t,n+1,n+1,n+1,n+1)):r=e.modelToRenderLayerTransform;const s=new Float32Array((n+1)*(n+1)),o=a.g(s,n+1,r,n+1,n+1);if(0===o)throw new Error("Transform is singular");const{globalToRenderLayerDimensions:l,localToRenderLayerDimensions:d,channelToRenderLayerDimensions:u}=e,h=l.length,p=d.length,f=h+p,m=new Float32Array((f+1)*n);for(let e=0;e<n;++e){for(let t=0;t<h;++t){const i=l[t];-1!==i&&(m[e+t*n]=s[e+i*(n+1)])}for(let t=0;t<p;++t){const i=d[t];-1!==i&&(m[e+(h+t)*n]=s[e+i*(n+1)])}m[e+f*n]=s[e+n*(n+1)]}const g=u.length;let v=new Array(g);const b=[];for(let t=0;t<g;++t){const i=u[t];let s=-1;if(-1!==i){for(let t=0;t<n;++t){const o=r[i+t*(n+1)];if(0!==o){if(1!==o||-1!==s)throw new Error(`Channel dimension ${e.layerDimensionNames[i]} `+"must map with stride 1 to a single data chunk dimensions");s=t}}if(-1!==s){if(0!==r[i+n*(n+1)])throw new Error(`Channel dimension ${e.layerDimensionNames[i]} `+"must have an offset of 0 in the chunk coordinate space");b.push(s)}}v[t]=s}const{channelSpaceShape:y}=e,S=c.e(y),w=b.length,x=new Uint32Array(S*w);for(let e=0;e<S;++e){let t=e,n=0;for(let i=0;i<g;++i){const r=t%y[i];t=(t-r)/y[i],-1!==v[i]&&(x[e*w+n]=r,++n)}}return{layerRank:n,modelTransform:e,chunkToLayerTransform:r,layerToChunkTransform:s,chunkToLayerTransformDet:o,combinedGlobalLocalRank:f,combinedGlobalLocalToChunkTransform:m,channelToChunkDimensionIndices:v,chunkChannelDimensionIndices:b,numChannels:S,chunkChannelCoordinates:x,channelSpaceShape:y}}function g(e,t){const{globalToRenderLayerDimensions:n}=e,i=[],r=[];for(let e=0;e<3;++e){const s=t[e];if(-1==s)continue;const o=n[s];r.push(o),-1!==o&&i.push(o)}for(let e=r.length;e<3;++e)r[e]=-1;return{layerDisplayDimensionIndices:i,displayToLayerDimensionIndices:r}}function v(e,t){const{chunkToLayerTransform:n,modelTransform:i}=e,r=i.rank,{layerDisplayDimensionIndices:s,displayToLayerDimensionIndices:a}=t,c=s.length,l=Object(o.b)(n,r,s);if(l.length!==c){const{modelDimensionNames:e,layerDimensionNames:t}=i;throw new Error("Rank mismatch between displayed layer dimensions "+`(${Array.from(s,e=>t[e]).join(", ")}) `+"and corresponding chunk dimensions "+`(${Array.from(l,t=>e[t]).join(", ")})`)}const d=o.m.create();for(let e=0;e<3;++e){const t=a[e];if(-1!==t){for(let i=0;i<c;++i){const s=l[i];d[4*i+e]=n[s*(r+1)+t]}d[12+e]=n[r*(r+1)+t]}}const u=o.m.create();o.m.invert(u,d);for(let e=l.length;e<3;++e)l[e]=-1;return{modelTransform:e.modelTransform,chunkTransform:e,displaySubspaceModelMatrix:d,displaySubspaceInvModelMatrix:u,chunkDisplayDimensionIndices:l,numChunkDisplayDims:c}}function b(e,t,n,i,r){const s=t.length,o=n.length,a=e.length;let c=!0;for(let l=0;l<i;++l){let d=l,u=0;for(let e=0;e<s;++e)u+=r[d+e*i]*t[e];d+=s*i;for(let e=0;e<o;++e)u+=r[d+e*i]*n[e];u+=r[d+o*i],l<a?e[l]=u:(u<0||u>=1)&&(c=!1)}return c}function y(e,t,n){e.fill(0),e[15]=1;let i=!0;const{displayDimensionIndices:r}=t,{globalToRenderLayerDimensions:s,modelToRenderLayerTransform:o}=n,a=n.rank;for(let t=0;t<3;++t){const n=r[t];if(-1===n){i=!1;continue}const c=s[n];if(-1!==c){e[t+12]=o[c+a*(a+1)];for(let n=0;n<3;++n)e[t+4*n]=o[c+(a+1)*n]}else i=!1}if(!i){const{globalDimensionNames:e}=t,i=Array.from(r.filter(e=>-1!==e),t=>e[t]).join(", ");throw new Error(`Transform from model dimensions (${n.modelDimensionNames.join(", ")}) `+`to display dimensions (${i}) does not have full rank`)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"e",(function(){return s})),n.d(t,"b",(function(){return o})),n.d(t,"c",(function(){return a})),n.d(t,"d",(function(){return c}));const i=new
/**
 * @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{constructor(){this.name="CancellationError",this.message="CANCELED"}toString(){return"CANCELED"}};const r=()=>{},s={isCanceled:!1,add:()=>r,remove:r};class o{cancel(){const{handlers:e}=this;if(null!==e&&(this.handlers=null,void 0!==e))for(let t of e)t()}get isCanceled(){return null===this.handlers}add(e){let{handlers:t}=this;return null===t?(e(),r):(void 0===t&&(t=this.handlers=new Set),t.add(e),()=>{this.remove(e)})}remove(e){const{handlers:t}=this;null!=t&&t.delete(e)}}class a extends o{constructor(){super(...arguments),this.consumers=new Set}addConsumer(e=s){const{consumers:t}=this;t.has(e)||e.isCanceled||(t.add(e),e.add(()=>{t.delete(e),0===t.size&&this.cancel()}))}}function c(e,t){return new Promise((n,i)=>{if(e===s)return void t(n,i,s);const r=new o,a=e.add(()=>{r.cancel()});t(e=>{a(),n(e)},e=>{a(),i(e)},r)})}},function(e,t,n){"use strict";n.d(t,"f",(function(){return o})),n.d(t,"d",(function(){return c})),n.d(t,"a",(function(){return l})),n.d(t,"b",(function(){return d})),n.d(t,"c",(function(){return u})),n.d(t,"g",(function(){return h})),n.d(t,"e",(function(){return p}));var i=n(7);
/**
 * @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 r=[{prefix:"Y",exponent:24},{prefix:"Z",exponent:21},{prefix:"E",exponent:18},{prefix:"P",exponent:15},{prefix:"T",exponent:12},{prefix:"G",exponent:9},{prefix:"M",exponent:6},{prefix:"k",exponent:3},{prefix:"",exponent:0},{prefix:"c",exponent:-2},{prefix:"m",exponent:-3},{prefix:"µ",exponent:-6},{prefix:"n",exponent:-9},{prefix:"p",exponent:-12},{prefix:"f",exponent:-15},{prefix:"a",exponent:-18},{prefix:"z",exponent:-21},{prefix:"y",exponent:-24}],s=[{prefix:"u",exponent:-6},...r],o=new Map;o.set("",{unit:"",exponent:0});const a=new Map;for(const{prefix:e,exponent:t}of s){a.set(t,e);for(const n of["m","s","Hz","rad/s"])o.set(`${e}${n}`,{unit:n,exponent:t})}function c(e){const t=Math.log10(e),n=r.length,s=Object(i.c)(0,n,e=>r[e].exponent<=t);return r[Math.min(s,n-1)]}function l(e,t,n={}){const{precision:i=6,elide1:r=!0}=n;let s,o=e,a="";if(""!==t){const t=c(e);a=t.prefix,o=p(e,-t.exponent)}if(r&&1===o)return{scale:"",unit:t,prefix:a};if(0!=i){s=o<1||o>=1e3?o.toPrecision(i):o.toFixed(i);const e=s.indexOf("e");let t,n;-1!==e?(t=s.substring(0,e),n=s.substring(e)):(t=s,n="");const r=t.match(/.*\.(?:[0-9]*[1-9])?(0+)$/);null!==r&&(t=t.substring(0,t.length-r[1].length),t.endsWith(".")&&(t=t.substring(0,t.length-1)),s=t+n)}else s=o.toString();return{scale:s,unit:t,prefix:a}}function d(e,t,n){const{scale:i,unit:r,prefix:s}=l(e,t,n);return`${i}${s}${r}`}function u(e){if(""===e)return{scale:1,unit:""};const t=e.match(/^((?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)?([µa-zA-Z]+)?$/);if(null===t)return;const n=t[1];let i=void 0===n?1:Number(n);if(Number.isNaN(i))return;let r="";if(void 0!==t[2]){const e=o.get(t[2]);if(void 0===e)return;r=e.unit,e.exponent>0?i*=10**e.exponent:i/=10**-e.exponent}return i<=0||!Number.isFinite(i)?void 0:{scale:i,unit:r}}function h(e){const t=o.get(e);if(void 0===t)throw new Error(`Invalid unit: ${JSON.stringify(e)}`);return t}function p(e,t){return t>=0?e*10**t:e/10**-t}},function(e,t,n){"use strict";n.d(t,"c",(function(){return l})),n.d(t,"b",(function(){return u})),n.d(t,"a",(function(){return m})),n.d(t,"d",(function(){return v}));var i=n(4),r=n(68),s=n(2),o=n(0),a=n(3);const c=new Map([["slider",function(e,t){let n,i,r,s,o=[];"float"!==e&&"uint"!==e&&"int"!==e&&o.push("type must be float, int, or uint");for(const[a,c]of t){const t=()=>{if("number"==typeof c)return"int"!==e&&"uint"!==e||(Number.isInteger(c)||o.push(`Expected ${a} argument to be an integer`),"uint"===e&&c<0&&o.push(`Expected ${a} argument to be an unsigned integer`)),c;o.push(`Expected ${a} argument to be a number`)};"min"===a?n=t():"max"===a?i=t():"default"===a?s=t():"step"===a?r=t():o.push(`Invalid parameter: ${a}`)}return void 0===n&&o.push("min must be specified"),void 0===i&&o.push("max must be specified"),void 0!==n&&void 0!==i&&(n>i&&o.push("min must be less than max"),void 0===r&&(r="float"===e?(i-n)/100:1),void 0!==s?(s<n||s>i)&&o.push("default must be within valid range"):s="float"===e?(n+i)/2:n),o.length>0?{errors:o}:{control:{type:"slider",valueType:e,min:n,max:i,step:r,default:s},errors:void 0}}],["color",function(e,t){let n="white",i=[];"vec3"!==e&&i.push("type must be vec3");for(const[e,r]of t)"default"===e?"string"!=typeof r?i.push("Expected default argument to be a string"):n=r:i.push(`Invalid parameter: ${e}`);return i.length>0?{errors:i}:{control:{type:"color",valueType:e,defaultString:n,default:Object(r.c)(n)},errors:void 0}}]]);function l(e){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.
 */
function(e){return e.replace(/\/\/.*?$|\/\*(?:.|\n)*?\*\/|'(?:\\.|[^\\'])*'|"(?:\\.|[^\\"])*"/gm,e=>e.startsWith("/")?e.replace(/[^\s]/g," "):e)}(e);const t=/^([_a-zA-Z][_a-zA-Z0-9]*)[ \t]+([a-z][a-zA-Z0-9]*)[ \t]+([a-z]+)[ \t]*(?:\([ \t]*(.*)\)[ \t]*)?/;let n=[];const i=new Map,r=e.replace(/^[ \t]*#[ \t]*uicontrol[ \t]+(.*)$/gm,(r,s,o)=>{const a=s.match(t),l=()=>Math.max(0,e.substring(0,o).split("\n").length-1);if(null===a)return n.push({line:l(),message:"Invalid #uicontrol syntax, expected: #uicontrol <type> <name> <control>(<param>=<value>, ...)"}),"";const d=a[1],u=a[2],h=a[3],p=a[4],{parameters:f,errors:m}=function(e){let t=[],n=new Map;if(void 0===e)return{errors:t,parameters:n};const i=/^[ \t]*([_a-z][_a-zA-Z0-9]*)[ \t]*=[ \t]*(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|"(?:\\.|[^\\"])*")[ \t]*/;for(;0!=(e=e.trim()).length;){const r=e.match(i);if(null===r){t.push("Invalid #uicontrol parameter syntax, expected: <param>=<value>, ...");break}const s=r[1];let o;try{o=JSON.parse(r[2])}catch(e){t.push(`Invalid #uicontrol parameter value: ${o}`);break}n.has(s)?t.push(`Duplicate #uicontrol parameter: ${s}`):n.set(s,o),(e=e.substring(r[0].length)).length>0&&!e.startsWith(",")&&t.push("Invalid #uicontrol parameter syntax, expected: <param>=<value>, ..."),e=e.substring(1)}return{parameters:n,errors:t}}(p);for(const e of m)n.push({line:l(),message:e});if(i.has(u)&&n.push({line:l(),message:`Duplicate definition for control ${u}`}),m.length>0)return"";const g=c.get(h);if(void 0===g)return n.push({line:l(),message:`Invalid control type ${h}`}),"";const v=g(d,f);if(void 0!==v.errors){for(const e of v.errors)n.push({line:l(),message:e});return""}return i.set(u,v.control),""});return{source:e,code:r,errors:n,controls:i}}function d(e){return`u_shaderControl_${e}`}function u(e,t){for(const[n,i]of e)t.addUniform(`highp ${i.valueType}`,d(n)),t.addVertexCode(`#define ${n} ${d(n)}\n`),t.addFragmentCode(`#define ${n} ${d(n)}\n`)}function h(e){if(void 0!==e)return JSON.stringify(function(e){const t={};for(const[n,i]of e)t[n]=i;return t}(e))}class p{constructor(){this.changed=new a.a,this.controls=void 0}get value(){return this.controls}set value(e){h(e)!==h(this.controls)&&(this.controls=e,this.changed.dispatch())}}function f(e){switch(e.type){case"slider":return new i.c(e.default,t=>{let n;if(n="float"===e.valueType?Object(o.p)(t):Object(o.u)(t),n<e.min||n>e.max)throw new Error(`${JSON.stringify(t)} is outside valid range [${e.min}, ${e.max}]`);return n});case"color":return new r.a(e.default)}}class m extends s.a{constructor(e){super(),this.fragmentMain=e,this.changed=new a.a,this.controls=new p,this.fragmentMainGeneration=-1,this.parseErrors_=[],this.processedFragmentMain_="",this.controlsGeneration=-1,this.state_=new Map,this.unparsedJson=void 0,this.registerDisposer(e.changed.add(()=>this.handleFragmentMainChanged())),this.registerDisposer(this.controls.changed.add(()=>this.handleControlsChanged())),this.handleFragmentMainChanged();const t=this;this.parseErrors={changed:e.changed,get value(){return t.handleFragmentMainChanged(),t.parseErrors_}},this.processedFragmentMain={changed:e.changed,get value(){return t.handleFragmentMainChanged(),t.processedFragmentMain_}},this.parseResult={changed:e.changed,get value(){return t.parseResult_}}}handleFragmentMainChanged(){const e=this.fragmentMain.changed.count;if(e===this.fragmentMainGeneration)return;this.fragmentMainGeneration=e;const t=this.parseResult_=l(this.fragmentMain.value);this.parseErrors_=t.errors,this.processedFragmentMain_=t.code,0===t.errors.length&&(this.controls.value=t.controls)}handleControlsChanged(){const e=this.controls.changed.count;if(e===this.controlsGeneration)return;this.controlsGeneration=e;const t=this.controls.value;if(void 0===t)return;let n=!1;const{state_:i,unparsedJson:r}=this;for(const[e,r]of i){void 0!==t.get(e)||(r.trackable.changed.remove(this.changed.dispatch),i.delete(e),n=!0)}for(const[e,s]of t){let t=i.get(e);if(void 0!==t&&JSON.stringify(t.control)!==JSON.stringify(s)&&(t.trackable.changed.remove(this.changed.dispatch),t=void 0),void 0===t&&(t={control:s,trackable:f(s)},t.trackable.changed.add(this.changed.dispatch),i.set(e,t),n=!0),void 0!==r&&r.hasOwnProperty(e)){n=!0;try{t.trackable.restoreState(r[e])}catch(e){}}}void 0!==r&&(n=!0),this.unparsedJson=void 0,n&&this.changed.dispatch()}get state(){return this.controls.changed.count!==this.controlsGeneration&&this.handleControlsChanged(),this.state_}restoreState(e){if(void 0===e)return;const{state:t}=this;if(Object(o.w)(e),void 0===this.controls.value)return this.unparsedJson=e,void this.changed.dispatch();for(const[n,i]of t){const{trackable:t}=i;if(t.reset(),e.hasOwnProperty(n))try{t.restoreState(e[n])}catch(e){}}this.unparsedJson=void 0}reset(){for(const e of this.state.values())e.trackable.reset();void 0!==this.unparsedJson&&(this.unparsedJson=void 0,this.changed.dispatch())}toJSON(){const{state:e}=this,{unparsedJson:t}=this;if(void 0!==t)return t;const n={};let i=!0;for(const[t,r]of e){const e=r.trackable.toJSON();void 0!==e&&(n[t]=e,i=!1)}return i?void 0:n}}function g(e,t,n,i,r){const s=t.uniform(d(n));switch(i.type){case"slider":switch(i.valueType){case"int":case"uint":e.uniform1i(s,r);break;case"float":e.uniform1f(s,r)}break;case"color":e.uniform3fv(s,r)}}function v(e,t,n,i){const{state:r}=n;if(n.controls.value===i)for(const[n,i]of r)g(e,t,n,i.control,i.trackable.value);else for(const[n,s]of i){const i=r.get(n);g(e,t,n,s,void 0!==i&&JSON.stringify(i.control)===JSON.stringify(s)?i.trackable.value:s.default)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"d",(function(){return a})),n.d(t,"b",(function(){return c}));var i=n(105);
/**
 * @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 r={offset:0,completions:[]};function s(e,t){return t.offset+=e,t}function o(e,t){let n=[];for(let i of t)i.startsWith(e)&&n.push({value:i});return n.sort((e,t)=>Object(i.a)(e.value,t.value)),n}function a(e,t,n,r){let s=[];for(let i of t){let t=n(i);t.startsWith(e)&&s.push({value:t,description:r(i)})}return s.sort((e,t)=>Object(i.a)(e.value,t.value)),s}async function c(e,t){return async function(e,t,n){if(e.startsWith("{"))return r;const i=e.match(/^(?:(.*)[&;])?([^&;]*)$/)[2];let o=e.length-i.length;const a=i.indexOf("=");if(-1===a){const e=await t(i);return{offset:e.offset+o,completions:e.completions.map(e=>Object.assign(Object.assign({},e),{value:`${e.value}=`}))}}return s(o+a+1,await n(i.substring(0,a),i.substring(a+1)))}(e,async e=>{const n=[];for(const i of t){const t=i.key;t.value.startsWith(e)&&n.push(t)}return{offset:0,completions:n}},async(e,n)=>{for(const i of t)if(i.key.value===e)return{offset:0,completions:i.values.filter(e=>e.value.startsWith(n))};return r})}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o})),n.d(t,"b",(function(){return a}));var i=n(2),r=n(0),s=n(45);
/**
 * @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 o{constructor(e,t=WebGL2RenderingContext.ARRAY_BUFFER){this.gl=e,this.bufferType=t,this.gl=e,this.buffer=e.createBuffer()}bind(){this.gl.bindBuffer(this.bufferType,this.buffer)}bindToVertexAttrib(e,t,n=WebGL2RenderingContext.FLOAT,i=!1,r=0,s=0){this.bind(),this.gl.enableVertexAttribArray(e),this.gl.vertexAttribPointer(e,t,n,i,r,s)}bindToVertexAttribI(e,t,n=WebGL2RenderingContext.UNSIGNED_INT,i=0,r=0){this.bind(),this.gl.enableVertexAttribArray(e),this.gl.vertexAttribIPointer(e,t,n,i,r)}setData(e,t=WebGL2RenderingContext.STATIC_DRAW){let n=this.gl;this.bind(),n.bufferData(this.bufferType,e,t)}dispose(){this.gl.deleteBuffer(this.buffer),this.buffer=void 0,this.gl=void 0}static fromData(e,t,n,i){let r=new o(e,n);return r.setData(t,i),r}}function a(e,t,n,...a){return e.memoize.get(Object(r.h)({id:"getMemoizedBuffer",getter:Object(s.a)(n),args:a}),()=>{const r=new i.b(o.fromData(e,n(...a),t,WebGL2RenderingContext.STATIC_DRAW));return r.registerDisposer(r.value),r})}},function(e,t,n){"use strict";n.d(t,"c",(function(){return d})),n.d(t,"a",(function(){return u})),n.d(t,"h",(function(){return h})),n.d(t,"g",(function(){return p})),n.d(t,"f",(function(){return f})),n.d(t,"d",(function(){return v})),n.d(t,"e",(function(){return b})),n.d(t,"b",(function(){return S}));var i=n(12),r=n(58),s=n(2),o=n(1),a=n(3),c=n(18),l=n(31);
/**
 * @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 d{constructor(e,t,n){this.key=e,this.value=t,this.label=n}toString(){const{key:e,value:t,label:n}=this;let i;return i=void 0===t?`${e}`:`${e}→${t}`,void 0===n?i:`${i} ${n}`}}class u extends s.a{constructor(){super(...arguments),this.selectedSegment=new c.a,this.hasSelectedSegment=!1,this.changed=new a.a}get value(){return this.hasSelectedSegment?this.selectedSegment:void 0}set(e){if(null==e)this.hasSelectedSegment&&(this.hasSelectedSegment=!1,this.changed.dispatch());else{let t=this.selectedSegment;this.hasSelectedSegment&&e.low===t.low&&e.high===t.high||(t.low=e.low,t.high=e.high,this.hasSelectedSegment=!0,this.changed.dispatch())}}isSelected(e){return this.hasSelectedSegment&&c.a.equal(e,this.selectedSegment)}bindTo(e,t){let n=new c.a;this.registerDisposer(e.changed.add(()=>{const i=e.get(t);let r=void 0;void 0!==i&&(r=i.value,"number"==typeof r?(n.low=r,n.high=0,r=n):r instanceof d&&(r=r.value||r.key),null!=r&&0===r.low&&0===r.high&&t.displayState.hideSegmentZero.value&&(r=void 0)),this.set(r)}))}}function h(e,t){const{length:n}=t;e.value<n&&(e.value=n)}function p(e,t){const n=t.redrawNeeded.dispatch;t.registerDisposer(e.segmentColorHash.changed.add(n)),t.registerDisposer(e.visibleSegments.changed.add(n)),t.registerDisposer(e.saturation.changed.add(n)),t.registerDisposer(e.highlightedSegments.changed.add(n)),t.registerDisposer(e.segmentEquivalences.changed.add(n)),t.registerDisposer(e.segmentSelectionState.changed.add(n))}function f(e,t){!function(e,t){p(e,t),t.registerDisposer(e.objectAlpha.changed.add(t.redrawNeeded.dispatch))}(e,t),t.registerDisposer(e.transform.changed.add(t.redrawNeeded.dispatch)),t.registerDisposer(e.renderScaleTarget.changed.add(t.redrawNeeded.dispatch)),t.registerDisposer(e.transparentPickEnabled.changed.add(t.redrawNeeded.dispatch))}const m=o.w.create(),g=new c.a;function v(e,t,n=m){const{segmentStatedColors:i}=e;return 0!==i.size&&i.has(t)?(e.segmentStatedColors.get(t,g),n[0]=((16711680&g.low)>>>16)/255,n[1]=((65280&g.low)>>>8)/255,n[2]=(255&g.low)/255):e.segmentColorHash.compute(n,t),n}function b(e,t,n=1){const i=m;i[3]=n,v(e,t,i);let r=e.saturation.value;e.segmentSelectionState.isSelected(t)&&(r>.5?r=r-=.5:r+=.5);for(let e=0;e<3;++e)i[e]=i[e]*r+(1-r);return e.highlightedSegments.has(t)&&(i[0]=.2,i[1]=.2,i[2]=2,i[3]=1),i[0]*=n,i[1]*=n,i[2]*=n,i}const y=Object(l.c)(i.e);class S extends y{constructor(e,t,n){super(n),this.chunkManager=e,this.displayState=t}initializeCounterpartWithChunkManager(e){let{displayState:t}=this;e.chunkManager=this.chunkManager.rpcId,e.visibleSegments=t.visibleSegments.rpcId,e.segmentEquivalences=t.segmentEquivalences.rpcId,e.transform=this.registerDisposer(r.a.makeFromExisting(this.chunkManager.rpc,this.displayState.transform)).rpcId,e.renderScaleTarget=this.registerDisposer(r.a.makeFromExisting(this.chunkManager.rpc,this.displayState.renderScaleTarget)).rpcId,super.initializeCounterpart(this.chunkManager.rpc,e)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return 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.
 */
const i=Symbol("objectId");let r=0;function s(e){if(e instanceof Object){let t=e[i];return void 0===t&&(t=e[i]=r++),`o${t}`}return""+JSON.stringify(e)}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));n(196);
/**
 * @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 i=null;class r{constructor(e=!1){if(null===i){i=document.createElement("ul"),i.id="statusContainer";const e=document.getElementById("neuroglancer-container");e?e.appendChild(i):document.body.appendChild(i)}let t=document.createElement("li");this.element=t,!0===e&&(e=200),!1!==e?(this.setVisible(!1),this.timer=setTimeout(this.setVisible.bind(this,!0),e)):this.timer=null,i.appendChild(t)}dispose(){i.removeChild(this.element),this.element=void 0,null!==this.timer&&clearTimeout(this.timer)}setText(e,t){this.element.textContent=e,t&&this.setVisible(!0)}setHTML(e,t){this.element.innerHTML=e,t&&this.setVisible(!0)}setVisible(e){null!==this.timer&&(clearTimeout(this.timer),this.timer=null),this.element.style.display=e?"block":"none"}static forPromise(e,t){let n=new r(t.delay);n.setText(t.initialMessage);let i=n.dispose.bind(n);return e.then(i,e=>{let i;i=e instanceof Error?e.message:""+e;let{errorPrefix:r=""}=t;n.setErrorMessage(r+i),n.setVisible(!0)}),e}setErrorMessage(e){this.element.textContent=e+" ";let t=document.createElement("button");t.textContent="Dismiss",t.addEventListener("click",()=>{this.dispose()}),this.element.appendChild(t)}static showMessage(e){const t=new r;return t.element.textContent=e,t.setVisible(!0),t}static showTemporaryMessage(e,t=2e3){const n=this.showMessage(e);return setTimeout(()=>n.dispose(),t),n}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return c})),n.d(t,"a",(function(){return d})),n.d(t,"c",(function(){return u})),n.d(t,"d",(function(){return p}));n(210);var i=n(30),r=n(2),s=n(6),o=n(3),a=n(31);
/**
 * @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 c extends r.a{constructor(e=new a.b(a.b.VISIBLE)){super(),this.visibility=e,this.element=document.createElement("div");const{element:t}=this;t.classList.add("neuroglancer-tab-content")}get visible(){return this.visibility.visible}disposed(){Object(s.c)(this.element),super.disposed()}}class l extends r.a{constructor(){super(...arguments),this.changed=new o.a,this.options=new Map,this.optionsChanged=new o.a,this.selectedValue=void 0,this.defaultValue=void 0,this.ready_=!0}get value(){const{selectedValue:e}=this;return void 0!==e?e:this.defaultValue}set default(e){this.defaultValue!==e&&(this.defaultValue=e,this.changed.dispatch())}get default(){return this.defaultValue}set value(e){void 0!==e&&this.ready_&&!this.options.has(e)&&(e=void 0);const{selectedValue:t}=this;t!==e&&(this.selectedValue=e,this.changed.dispatch())}get validValue(){const e=this.selectedValue;return void 0!==e&&this.options.has(e)?e:this.defaultValue}add(e,t){const{options:n}=this;if(n.has(e))throw new Error(`Option already defined: ${JSON.stringify(e)}.`);n.set(e,t),this.optionsChanged.dispatch(),void 0===this.defaultValue&&(this.default=e)}toJSON(){const{value:e,defaultValue:t}=this;if(e!==t)return e}reset(){this.value=void 0}get ready(){return this.ready_}set ready(e){e!==this.ready_&&(this.ready_=e,e&&(this.value=this.value),this.changed.dispatch())}restoreState(e){"string"!=typeof e&&(e=void 0),this.value=e}}class d extends r.a{constructor(e,t,n=new a.b(a.b.VISIBLE),r=!1){super(),this.getter=e,this.selected=t,this.visibility=n,this.invalidateByDefault=r,this.element=document.createElement("div"),this.tabs=new Map,this.tabVisibilityChanged=new o.b,this.debouncedUpdateSelectedTab=this.registerCancellable(Object(i.a)(()=>this.updateSelectedTab()));const{element:s}=this;s.className="neuroglancer-stack-view",this.registerDisposer(n.changed.add(this.debouncedUpdateSelectedTab)),this.registerDisposer(t.changed.add(this.debouncedUpdateSelectedTab)),this.updateSelectedTab()}get visible(){return this.visibility.visible}flush(){this.debouncedUpdateSelectedTab.flush()}invalidate(e){const{tabs:t}=this,n=t.get(e);void 0!==n&&(n.dispose(),t.delete(e),e===this.displayedTab&&(this.displayedTab=void 0,this.debouncedUpdateSelectedTab()))}hideTab(e){const t=this.tabs.get(e);void 0!==t&&(t.visibility.value=a.b.IGNORED,t.element.style.display="none"),this.tabVisibilityChanged.dispatch(e,!1)}showTab(e){const{tabs:t}=this;let n=t.get(e);void 0===n&&(n=this.getter(e),this.element.appendChild(n.element),t.set(e,n)),n.element.style.display="",n.visibility.value=a.b.VISIBLE,this.tabVisibilityChanged.dispatch(e,!0)}updateSelectedTab(){const{displayedTab:e}=this,t=this.visible?this.selected.value:void 0;t!==e&&(void 0!==e&&this.hideTab(e),this.invalidateByDefault&&this.invalidateAll(),this.displayedTab=t,void 0!==t&&this.showTab(t))}invalidateAll(){const{tabs:e}=this;for(const t of e.values())t.dispose();e.clear(),this.debouncedUpdateSelectedTab()}disposed(){this.invalidateAll(),Object(s.c)(this.element),super.disposed()}}class u extends l{}function h(e,t){const n="neuroglancer-selected-tab-label";t?e.classList.add(n):e.classList.remove(n)}class p extends r.a{constructor(e,t=new a.b(a.b.VISIBLE)){super(),this.state=e,this.visibility=t,this.element=document.createElement("div"),this.tabBar=document.createElement("div"),this.tabLabels=new Map,this.tabsGeneration=-1,this.debouncedUpdateView=this.registerCancellable(Object(i.a)(()=>this.updateTabs()));const{element:n,tabBar:r}=this;n.className="neuroglancer-tab-view",r.className="neuroglancer-tab-view-bar",n.appendChild(r),this.registerDisposer(t.changed.add(this.debouncedUpdateView));const s=this.stack=this.registerDisposer(new d(e=>this.state.options.get(e).getter(),this.state,this.visibility));n.appendChild(s.element),this.registerDisposer(this.state.optionsChanged.add(this.debouncedUpdateView)),this.registerDisposer(this.state.changed.add(()=>this.updateTabLabelStyles())),this.updateTabs()}get visible(){return this.visibility.visible}updateTabLabelStyles(){const e=this.state.value;for(const[t,n]of this.tabLabels)h(n,t===e)}updateTabs(){this.tabsGeneration!==this.state.optionsChanged.count&&(this.destroyTabs(),this.visible&&this.makeTabs())}destroyTabs(){-1!==this.tabsGeneration&&(this.tabLabels.clear(),Object(s.b)(this.tabBar),this.tabsGeneration=-1,this.stack.invalidateAll())}makeTabs(){const{tabBar:e,tabLabels:t}=this,n=Array.from(this.state.options);n.sort(([,{order:e=0}],[,{order:t=0}])=>e-t);const i=this.state.value;for(const[r,{label:s}]of n){const n=document.createElement("div");n.classList.add("neuroglancer-tab-label"),n.textContent=s,h(n,r===i),n.addEventListener("click",()=>{this.state.value=r}),t.set(r,n),e.appendChild(n)}this.tabsGeneration=this.state.optionsChanged.count}disposed(){Object(s.b)(this.tabBar),this.tabLabels.clear(),Object(s.c)(this.element),super.disposed()}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return o}));var i=n(2),r=n(43);
/**
 * @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 s(e){e.addAttribute("int","aDummyVertexId",0),e.addVertexCode("\nint getVertexId () {\n  return aDummyVertexId + gl_VertexID;\n}\n#define gl_VertexID (getVertexId())\n")}class o extends i.a{constructor(e){super(),this.buffer=new r.a(e),this.size=0}disposed(){this.buffer.dispose()}enable(e=256){const{buffer:t}=this,{gl:n}=t;t.bind(),e>this.size&&(this.size=e,n.bufferData(WebGL2RenderingContext.ARRAY_BUFFER,new Int32Array(e),WebGL2RenderingContext.STATIC_DRAW)),n.vertexAttribIPointer(0,1,WebGL2RenderingContext.INT,0,0),n.vertexAttribDivisor(0,0),n.enableVertexAttribArray(0)}disable(){const{gl:e}=this.buffer;e.disableVertexAttribArray(0)}static get(e){return e.memoize.get("VertexIdHelper",()=>new o(e))}}},function(e,t,n){"use strict";var i=n(10),r=n(12),s=n(69),o=n(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.
 */
function a(e,t,n,i,r,s,a){const{octree:c,lodScales:l,chunkGridSpatialOrigin:d,chunkShape:u}=e,h=l.length-1,p=t[0],f=t[4],m=t[8],g=t[1],v=t[5],b=t[9],y=t[3],S=t[7],w=t[11],x=t[15],C=y>0?0:1,O=S>0?0:1,k=w>0?0:1,E=n[16],T=n[17],M=n[18],D=n[19];function L(e,t,n){return y*e+S*t+w*n+x}const j=L(-D*E,-D*T,-D*M),I=e.clipLowerBound[0],P=e.clipLowerBound[1],A=e.clipLowerBound[2],R=e.clipUpperBound[0],N=e.clipUpperBound[1],V=e.clipUpperBound[2],_=Math.sqrt((p*r)**2+(g*s)**2),B=Math.sqrt((f*r)**2+(v*s)**2),F=Math.sqrt((m*r)**2+(b*s)**2),z=Math.max(_,B,F);!function e(t,r,s){const h=1<<t,p=5*r,f=c[p],m=c[p+1],g=c[p+2],v=c[p+3],b=c[p+4];let y=f*h*u[0]+d[0],S=m*h*u[1]+d[1],w=g*h*u[2]+d[2],x=y+h*u[0],E=S+h*u[1],T=w+h*u[2];if(y=Math.max(y,I),S=Math.max(S,P),w=Math.max(w,A),x=Math.min(x,R),E=Math.min(E,N),T=Math.min(T,V),Object(o.h)(y,S,w,x,E,T,n)){const n=Math.max(j,function(e,t,n,i,r,s){return L(e+C*(i-e),t+O*(r-t),n+k*(s-n))}(y,S,w,x,E,T))/z;if(0===s||n*i<s){const o=l[t];if(0!==o&&a(t,r,o/n,b>>>31),t>0&&(0===o||n*i<o)){const n=0===o?s:o,i=(2147483647&b)>>>0;for(let r=v;r<i;++r)e(t-1,r,n)}}}}(h,c.length/5-1,0)}function c(e,t,n,i,r,s,o,c){const{lodScales:l}=e;let d=0;for(;d+1<l.length&&0!==l[d+1];)++d;const u=[];let h=0,p=0;function f(e,t){for(;;){if(0===h)return;const n=h-1,i=d-n,r=u[3*n],s=0===i?1:8,o=u[3*n+1],a=u[3*n+2];if(e===h){const e=t&s-1;return p!==e&&-1!==r&&c(i,r,p,e,a),void(p=e+1)}p!==s&&-1!==r&&c(i,r,p,s,a),p=o+1,--h}}let m=0;const{octree:g}=e;a(e,t,n,i,r,s,(e,t,n,i)=>{if(!i&&!o(e,t,n))return void(m=Math.max(e,m));if(e<m)return;m=0;const r=5*t,s=
/**
 * @license
 * Copyright 2019 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function(e,t,n){return 1&e|t<<1&2|n<<2&4}(g[r],g[r+1],g[r+2]),a=d-e;f(a,s);const c=3*a;u[c]=i?-1:t,u[c+1]=s,u[c+2]=n,p=0,h=a+1}),f(0,0)}function l(e,t,n){return`${e}/${t}:${n}`}var d=n(71),u=n(36),h=n(52),p=n(44),f=n(4),m=n(43),g=n(32),v=n(16);n.d(t,"a",(function(){return E})),n.d(t,"b",(function(){return D})),n.d(t,"c",(function(){return I})),n.d(t,"d",(function(){return 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.
 */
var b=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};const y=o.m.create(),S=o.k.create();function w(e,t){t.vertexBuffer=m.a.fromData(e,t.meshData.vertexPositions,e.ARRAY_BUFFER,e.STATIC_DRAW),t.indexBuffer=m.a.fromData(e,t.meshData.indices,e.ELEMENT_ARRAY_BUFFER,e.STATIC_DRAW),t.normalBuffer=m.a.fromData(e,t.meshData.vertexNormals,e.ARRAY_BUFFER,e.STATIC_DRAW)}function x(e){e.vertexBuffer.dispose(),e.indexBuffer.dispose(),e.normalBuffer.dispose()}function C(e){return{defineShader:e=>{e.addAttribute("highp vec3","aVertexPosition"),e.addVertexCode("highp vec3 getVertexPosition() { return aVertexPosition; }")},bind(t,n,i){i.vertexBuffer.bindToVertexAttrib(n.attribute("aVertexPosition"),3,e,!0)},endLayer:(e,t)=>{e.disableVertexAttribArray(t.attribute("aVertexPosition"))}}}const O={[s.e.float32]:C(WebGL2RenderingContext.FLOAT),[s.e.uint16]:C(WebGL2RenderingContext.UNSIGNED_SHORT),[s.e.uint10]:{defineShader:e=>{e.addAttribute("highp uint","aVertexPosition"),e.addVertexCode("\nhighp vec3 getVertexPosition() {\n  return vec3(float(aVertexPosition & 1023u),\n              float((aVertexPosition >> 10) & 1023u),\n              float((aVertexPosition >> 20) & 1023u)) / 1023.0;\n}\n")},bind(e,t,n){n.vertexBuffer.bindToVertexAttribI(t.attribute("aVertexPosition"),1,WebGL2RenderingContext.UNSIGNED_INT)},endLayer:(e,t)=>{e.disableVertexAttribArray(t.attribute("aVertexPosition"))}}};class k{constructor(e,t){this.fragmentRelativeVertices=e,this.vertexPositionFormat=t,this.tempLightVec=new Float32Array(4),this.vertexPositionHandler=O[this.vertexPositionFormat]}beginLayer(e,t,n,i){let{lightDirection:r,ambientLighting:s,directionalLighting:a}=n,c=this.tempLightVec;o.u.scale(c,r,a),c[3]=s,e.uniform4fv(t.uniform("uLightDirection"),c);const l=i.silhouetteRendering.value;l>0&&e.uniform1f(t.uniform("uSilhouettePower"),l)}setColor(e,t,n){e.uniform4fv(t.uniform("uColor"),n)}setPickID(e,t,n){e.uniform1ui(t.uniform("uPickID"),n)}beginModel(e,t,n,i){const{projectionParameters:r}=n;e.uniformMatrix4fv(t.uniform("uModelViewProjection"),!1,o.m.multiply(y,r.viewProjectionMat,i)),Object(o.l)(S,i),Object(o.q)(S,S,r.displayDimensionRenderInfo.canonicalVoxelFactors),o.k.invert(S,S),o.k.transpose(S,S),e.uniformMatrix3fv(t.uniform("uNormalMatrix"),!1,S)}drawFragmentHelper(e,t,n,i,r){this.vertexPositionHandler.bind(e,t,n);const{meshData:s}=n;n.normalBuffer.bindToVertexAttrib(t.attribute("aVertexNormal"),2,WebGL2RenderingContext.BYTE,!0),n.indexBuffer.bind();const{indices:o}=s;e.drawElements(s.strips?WebGL2RenderingContext.TRIANGLE_STRIP:WebGL2RenderingContext.TRIANGLES,r-i,2===o.BYTES_PER_ELEMENT?WebGL2RenderingContext.UNSIGNED_SHORT:WebGL2RenderingContext.UNSIGNED_INT,i*o.BYTES_PER_ELEMENT)}drawFragment(e,t,n){const{meshData:i}=n,{indices:r}=i;this.drawFragmentHelper(e,t,n,0,r.length)}drawMultiscaleFragment(e,t,n,i,r){const s=n.meshData.subChunkOffsets[i],o=n.meshData.subChunkOffsets[r];this.drawFragmentHelper(e,t,n,s,o)}endLayer(e,t){this.vertexPositionHandler.endLayer(e,t),e.disableVertexAttribArray(t.attribute("aVertexNormal"))}makeGetter(e){const t=e.registerDisposer(Object(f.g)(e=>e>0,[e.displayState.silhouetteRendering]));return Object(g.d)(e,e.gl,{memoizeKey:`mesh/MeshShaderManager/${this.fragmentRelativeVertices}/${this.vertexPositionFormat}`,parameters:t,defineShader:(e,t)=>{this.vertexPositionHandler.defineShader(e),e.addAttribute("highp vec2","aVertexNormal"),e.addVarying("highp vec4","vColor"),e.addUniform("highp vec4","uLightDirection"),e.addUniform("highp vec4","uColor"),e.addUniform("highp mat3","uNormalMatrix"),e.addUniform("highp mat4","uModelViewProjection"),e.addUniform("highp uint","uPickID"),t&&e.addUniform("highp float","uSilhouettePower"),this.fragmentRelativeVertices&&(e.addUniform("highp vec3","uFragmentOrigin"),e.addUniform("highp vec3","uFragmentShape")),e.addVertexCode("\nhighp vec3 decodeNormalOctahedronSnorm8(highp vec2 e) {\n  vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\n  if (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * vec2(v.x > 0.0 ? 1.0 : -1.0, v.y > 0.0 ? 1.0 : -1.0);\n  return normalize(v);\n}\n");let n="";this.fragmentRelativeVertices?n+="\nhighp vec3 vertexPosition = uFragmentOrigin + uFragmentShape * getVertexPosition();\nhighp vec3 normalMultiplier = 1.0 / uFragmentShape;\n":n+="\nhighp vec3 vertexPosition = getVertexPosition();\nhighp vec3 normalMultiplier = vec3(1.0, 1.0, 1.0);\n",n+="\ngl_Position = uModelViewProjection * vec4(vertexPosition, 1.0);\nvec3 origNormal = decodeNormalOctahedronSnorm8(aVertexNormal);\nvec3 normal = normalize(uNormalMatrix * (normalMultiplier * origNormal));\nfloat absCosAngle = abs(dot(normal, uLightDirection.xyz));\nfloat lightingFactor = absCosAngle + uLightDirection.w;\nvColor = vec4(lightingFactor * uColor.rgb, uColor.a);\n",t&&(n+="\nvColor *= pow(1.0 - absCosAngle, uSilhouettePower);\n"),e.setVertexMain(n),e.setFragmentMain("emit(vColor, uPickID);")}})}}class E extends d.a{constructor(e,t,n){super(),this.chunkManager=e,this.source=t,this.displayState=n,this.meshShaderManager=new k(!1,s.e.float32),this.getShader=this.meshShaderManager.makeGetter(this),Object(p.f)(n,this),this.registerDisposer(n.silhouetteRendering.changed.add(this.redrawNeeded.dispatch));let i=this.backend=this.registerDisposer(new p.b(e,n,this.layerChunkProgressInfo));i.RPC_TYPE_ID=s.b,i.initializeCounterpartWithChunkManager({source:t.addCounterpartRef()}),i.visibility.add(this.visibility),this.registerDisposer(n.renderScaleHistogram.visibility.add(this.visibility))}get isTransparent(){const{displayState:e}=this;return e.objectAlpha.value<1||e.silhouetteRendering.value>0}get transparentPickEnabled(){return this.displayState.transparentPickEnabled.value}get gl(){return this.chunkManager.chunkQueueManager.gl}draw(e,t){if(!e.emitColor&&e.alreadyEmittedPickID)return;const{gl:n,displayState:r,meshShaderManager:s}=this,o=Math.min(1,r.objectAlpha.value);if(o<=0)return;const a=Object(u.g)(r.transform.value,e.projectionParameters.displayDimensionRenderInfo,t);if(void 0===a)return;const{shader:c}=this.getShader(e.emitter);if(null===c)return;c.bind(),s.beginLayer(n,c,e,this.displayState),s.beginModel(n,c,e,a);let{pickIDs:l}=e;const d=this.source.chunks;let f=0,m=0;const{renderScaleHistogram:g}=this.displayState,v=this.source.fragmentSource.chunks;Object(h.a)(r,(t,a)=>{const u=Object(h.b)(t),g=d.get(u);if(++f,void 0!==g){++m,e.emitColor&&s.setColor(n,c,Object(p.e)(r,a,o)),e.emitPickID&&s.setPickID(n,c,l.registerUint64(this,t)),f+=g.fragmentIds.length;for(const e of g.fragmentIds){const t=v.get(`${u}/${e}`);void 0!==t&&t.state===i.h.GPU_MEMORY&&(s.drawFragment(n,c,t),++m)}}}),e.emitColor&&(g.begin(this.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber),g.add(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,m,f-m)),s.endLayer(n,c)}isReady(){const{displayState:e,source:t}=this;let n=!0;const r=t.fragmentSource.chunks;return Object(h.a)(e,e=>{const s=Object(h.b)(e),o=t.chunks.get(s);if(void 0!==o)for(const e of o.fragmentIds){const t=r.get(`${s}/${e}`);if(void 0===t||t.state!==i.h.GPU_MEMORY)return void(n=!1)}else n=!1}),n}}class T extends r.b{constructor(e,t){super(e),this.fragmentIds=t.fragmentIds}}class M extends r.b{constructor(e,t){super(e),this.meshData=t}copyToGPU(e){super.copyToGPU(e),w(e,this)}freeGPUMemory(e){super.freeGPUMemory(e),x(this)}}class D extends r.f{constructor(e,t){super(e,t),this.fragmentSource=this.registerDisposer(new L(this.chunkManager,this))}initializeCounterpart(e,t){this.fragmentSource.initializeCounterpart(this.chunkManager.rpc,{}),t.fragmentSource=this.fragmentSource.addCounterpartRef(),super.initializeCounterpart(e,t)}getChunk(e){return new T(this,e)}}let L=class extends r.f{constructor(e,t){super(e),this.meshSource=t}get key(){return this.meshSource.key}getChunk(e){return new M(this,e)}};function j(e,t,n,r){const s=e.get(l(t,n,r));return void 0!==s&&s.state===i.h.GPU_MEMORY}L=b([Object(v.g)(s.a)],L);class I extends d.a{constructor(e,t,n){super(),this.chunkManager=e,this.source=t,this.displayState=n,this.meshShaderManager=new k(this.source.format.fragmentRelativeVertices,this.source.format.vertexPositionFormat),this.getShader=this.meshShaderManager.makeGetter(this),Object(p.f)(n,this),this.registerDisposer(n.silhouetteRendering.changed.add(this.redrawNeeded.dispatch));let i=this.backend=this.registerDisposer(new p.b(e,n,this.layerChunkProgressInfo));i.RPC_TYPE_ID=s.d,i.initializeCounterpartWithChunkManager({source:t.addCounterpartRef()}),i.visibility.add(this.visibility),this.registerDisposer(n.renderScaleHistogram.visibility.add(this.visibility))}get isTransparent(){const{displayState:e}=this;return e.objectAlpha.value<1||e.silhouetteRendering.value>0}get transparentPickEnabled(){return this.displayState.transparentPickEnabled.value}get gl(){return this.chunkManager.chunkQueueManager.gl}draw(e,t){if(!e.emitColor&&e.alreadyEmittedPickID)return;const{gl:n,displayState:i,meshShaderManager:r}=this,s=Math.min(1,i.objectAlpha.value);if(s<=0)return;const a=Object(u.g)(i.transform.value,e.projectionParameters.displayDimensionRenderInfo,t);if(void 0===a)return;const{shader:d}=this.getShader(e.emitter);if(null===d)return;d.bind(),r.beginLayer(n,d,e,this.displayState);const{renderScaleHistogram:f}=this.displayState;e.emitColor&&f.begin(this.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber);let{pickIDs:m}=e;Object(o.l)(S,a),Object(o.q)(S,S,e.projectionParameters.displayDimensionRenderInfo.voxelPhysicalScales);const g=Math.pow(o.k.determinant(S),1/3),{chunks:v}=this.source,b=this.source.fragmentSource.chunks,{projectionParameters:y}=e,w=o.m.multiply(o.m.create(),y.viewProjectionMat,a),x=Object(o.c)(new Float32Array(24),w),C=this.displayState.renderScaleTarget.value,{fragmentRelativeVertices:O}=this.source.format;r.beginModel(n,d,e,a);let k=0,E=0;Object(h.a)(i,(t,o)=>{const a=Object(h.b)(t),u=v.get(a);if(++k,void 0===u)return;++E;const{manifest:S}=u,{octree:T,chunkShape:M,chunkGridSpatialOrigin:D,vertexOffsets:L}=S;e.emitColor&&r.setColor(n,d,Object(p.e)(i,o,s)),e.emitPickID&&r.setPickID(n,d,m.registerUint64(this,t)),c(S,w,x,C,y.width,y.height,(t,n,i)=>{const r=j(b,a,t,n);return e.emitColor&&f.add(S.lodScales[t]*g,i,r?1:0,r?0:1),r},(e,t,i,s)=>{const o=l(a,e,t),c=b.get(o),u=T[5*t],h=T[5*t+1],p=T[5*t+2],f=1<<e;O&&(n.uniform3f(d.uniform("uFragmentOrigin"),D[0]+u*M[0]*f+L[3*e+0],D[1]+h*M[1]*f+L[3*e+1],D[2]+p*M[2]*f+L[3*e+2]),n.uniform3f(d.uniform("uFragmentShape"),M[0]*f,M[1]*f,M[2]*f)),r.drawMultiscaleFragment(n,d,c,i,s)})}),f.add(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,E,k-E),r.endLayer(n,d)}isReady(e,t){let{displayState:n}=this;if(Math.min(1,n.objectAlpha.value)<=0)return!0;const i=Object(u.g)(n.transform.value,e.projectionParameters.displayDimensionRenderInfo,t);if(void 0===i)return!1;const{chunks:r}=this.source,s=this.source.fragmentSource.chunks,{projectionParameters:a}=e,l=o.m.multiply(o.m.create(),a.viewProjectionMat,i),d=Object(o.c)(new Float32Array(24),l),p=this.displayState.renderScaleTarget.value;let f=!0;return Object(h.a)(n,e=>{if(!f)return;const t=Object(h.b)(e),n=r.get(t);if(void 0===n)return void(f=!1);const{manifest:i}=n;c(i,l,d,p,a.width,a.height,(e,n)=>(f=f&&j(s,t,e,n),f),()=>{})}),f}}class P extends r.b{constructor(e,t){super(e),this.manifest=t.manifest}}class A extends r.b{constructor(e,t){super(e),this.meshData=t}copyToGPU(e){super.copyToGPU(e),w(e,this)}freeGPUMemory(e){super.freeGPUMemory(e),x(this)}}class R extends r.f{constructor(e,t){super(e,t),this.fragmentSource=this.registerDisposer(new N(this.chunkManager,this)),this.format=t.format}static encodeOptions(e){return Object.assign({format:e.format},super.encodeOptions(e))}initializeCounterpart(e,t){this.fragmentSource.initializeCounterpart(this.chunkManager.rpc,{}),t.fragmentSource=this.fragmentSource.addCounterpartRef(),t.format=this.format,super.initializeCounterpart(e,t)}getChunk(e){return new P(this,e)}}let N=class extends r.f{constructor(e,t){super(e),this.meshSource=t}get key(){return this.meshSource.key}getChunk(e){return new A(this,e)}};N=b([Object(v.g)(s.c)],N)},function(e,t,n){"use strict";n.d(t,"b",(function(){return s}));var i=n(2),r=n(13);n.d(t,"a",(function(){return r.a}));
/**
 * @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 s extends i.a{constructor(e,t){super(),this.target=e,this.eventMap=t,this.registerEventListener(e,"wheel",e=>{this.dispatch("wheel",e)}),this.registerEventListener(e,"click",e=>{this.dispatch(`click${e.button}`,e)}),this.registerEventListener(e,"dblclick",e=>{this.dispatch(`dblclick${e.button}`,e)}),this.registerEventListener(e,"mousedown",e=>{this.dispatch(`mousedown${e.button}`,e)}),this.registerEventListener(e,"mouseup",e=>{this.dispatch(`mouseup${e.button}`,e)})}dispatch(e,t){Object(r.c)(e,t,t,this.eventMap)}}},function(e,t,n){"use strict";
/**
 * @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 i(e){return`${e.low},${e.high}`}function r(e,t){let{visibleSegments:n,segmentEquivalences:i}=e;for(let e of n)if(i.disjointSets.isMinElement(e))for(let n of i.setElements(e))t(n,e)}n.d(t,"b",(function(){return i})),n.d(t,"a",(function(){return r}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return u})),n.d(t,"d",(function(){return h})),n.d(t,"e",(function(){return f})),n.d(t,"f",(function(){return m})),n.d(t,"b",(function(){return y})),n.d(t,"c",(function(){return S}));var i=n(2),r=n(1),s=n(45),o=n(125),a=n(101),c=n(126);
/**
 * @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 l extends i.a{constructor(){super(...arguments),this.width=Number.NaN,this.height=Number.NaN}hasSize(e,t){return this.width===e&&this.height===t}resize(e,t){this.hasSize(e,t)||(this.width=e,this.height=t,this.performResize())}}class d extends l{constructor(e,t){super(),this.gl=e,this.internalformat=t,this.renderbuffer=null,this.renderbuffer=e.createRenderbuffer()}performResize(){let{gl:e}=this;e.bindRenderbuffer(e.RENDERBUFFER,this.renderbuffer),e.renderbufferStorage(e.RENDERBUFFER,this.internalformat,this.width,this.height),e.bindRenderbuffer(e.RENDERBUFFER,null)}disposed(){this.gl.deleteRenderbuffer(this.renderbuffer)}attachToFramebuffer(e){let{gl:t}=this;t.framebufferRenderbuffer(t.FRAMEBUFFER,e,t.RENDERBUFFER,this.renderbuffer)}}class u extends d{constructor(e,t=!1){super(e,t?e.DEPTH_STENCIL:e.DEPTH_COMPONENT16),this.gl=e,this.includeStencilBuffer=t}attachToFramebuffer(){let{gl:e}=this;super.attachToFramebuffer(this.includeStencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT)}}const h=class extends u{constructor(e){super(e,!0)}};class p extends i.a{constructor(e){super(),this.gl=e,this.framebuffer=this.gl.createFramebuffer()}disposed(){let{gl:e}=this;e.deleteFramebuffer(this.framebuffer)}bind(){let{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer)}unbind(){let{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,null)}}class f extends l{constructor(e,t,n,i){super(),this.gl=e,this.internalFormat=t,this.format=n,this.dataType=i,this.texture=e.createTexture()}performResize(){Object(a.a)(this.gl,this.texture,this.width,this.height,this.internalFormat,this.format,this.dataType)}disposed(){this.gl.deleteTexture(this.texture)}attachToFramebuffer(e){let{gl:t}=this;t.framebufferTexture2D(t.FRAMEBUFFER,e,t.TEXTURE_2D,this.texture,0)}}function m(e,t,n=WebGL2RenderingContext.RGBA8,i=WebGL2RenderingContext.RGBA,r=WebGL2RenderingContext.UNSIGNED_BYTE){let s=new Array;for(let o=0;o<t;++o)s[o]=new f(e,n,i,r);return s}const g=new Uint8Array(4),v=new Uint32Array(1),b=new Float32Array(4);class y extends i.a{constructor(e,t){super(),this.gl=e,this.width=Number.NaN,this.height=Number.NaN,this.fullAttachmentList=new Array,this.attachmentVerified=!1,this.singleAttachmentList=[this.gl.COLOR_ATTACHMENT0];let{framebuffer:n=new p(e),colorBuffers:i,depthBuffer:r}=t;this.framebuffer=this.registerDisposer(n),this.colorBuffers=i,this.depthBuffer=r,void 0!==r&&this.registerDisposer(r);let{fullAttachmentList:s}=this;i.forEach((t,n)=>{this.registerDisposer(t),s[n]=e.COLOR_ATTACHMENT0+n})}hasSize(e,t){return this.width===e&&this.height===t}bind(e,t){this.width=e,this.height=t,this.framebuffer.bind();let{gl:n,depthBuffer:i}=this;void 0!==i&&(i.resize(e,t),i.attachToFramebuffer()),this.colorBuffers.forEach((i,r)=>{i.resize(e,t),i.attachToFramebuffer(n.COLOR_ATTACHMENT0+r)}),n.drawBuffers(this.fullAttachmentList),this.verifyAttachment(),n.viewport(0,0,e,t)}bindSingle(e){let{gl:t}=this;this.framebuffer.bind(),0!==e&&t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0),t.bindTexture(t.TEXTURE_2D,null),this.colorBuffers[e].attachToFramebuffer(t.COLOR_ATTACHMENT0),t.drawBuffers(this.singleAttachmentList)}unbind(){this.framebuffer.unbind()}readPixel(e,t,n){let{gl:i}=this;try{this.bindSingle(e),i.readPixels(t,n,1,1,i.RGBA,i.UNSIGNED_BYTE,g)}finally{this.framebuffer.unbind()}return g}readPixelUint32(e,t,n){let{gl:i}=this;try{this.bindSingle(e),i.readPixels(t,n,1,1,WebGL2RenderingContext.RED_INTEGER,WebGL2RenderingContext.UNSIGNED_INT,v)}finally{this.framebuffer.unbind()}return v[0]}readPixelFloat32(e,t,n){let{gl:i}=this;try{this.bindSingle(e),i.readPixels(t,n,1,1,WebGL2RenderingContext.RGBA,WebGL2RenderingContext.FLOAT,b)}finally{this.framebuffer.unbind()}return b[0]}readPixelFloat32IntoBuffer(e,t,n,i,r=1,s=1){let{gl:o}=this;try{this.bindSingle(e),o.readPixels(t,n,r,s,WebGL2RenderingContext.RGBA,WebGL2RenderingContext.FLOAT,i)}finally{this.framebuffer.unbind()}}verifyAttachment(){if(this.attachmentVerified)return;let{gl:e}=this,t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error(`Framebuffer configuration not supported: ${t}`);this.attachmentVerified=!0}}class S extends i.a{constructor(e,t){super(),this.gl=e,this.shader=t,this.copyVertexPositionsBuffer=Object(o.a)(this.gl),this.copyTexCoordsBuffer=Object(o.a)(this.gl,0,0,1,1),this.registerDisposer(t)}draw(...e){let{gl:t,shader:n}=this;n.bind();let i=e.length;for(let n=0;n<i;++n)t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,e[n]);t.uniformMatrix4fv(n.uniform("uProjectionMatrix"),!1,r.f);let s=n.attribute("aVertexPosition");this.copyVertexPositionsBuffer.bindToVertexAttrib(s,2);let o=n.attribute("aTexCoord");this.copyTexCoordsBuffer.bindToVertexAttrib(o,2),t.drawArrays(t.TRIANGLE_FAN,0,4),t.disableVertexAttribArray(s),t.disableVertexAttribArray(o);for(let e=0;e<i;++e)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,null)}static get(e,t=c.a,n=1){return e.memoize.get(`OffscreenCopyHelper:${n}:${Object(s.a)(t)}`,()=>new S(e,Object(c.b)(e,t,n)))}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return o}));var i=n(34);
/**
 * @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 r=new Map;function s(e,t){r.set(e,t)}function o(e){const t=new i.b;for(const[n,i]of r)t.register(n,i(e));return t}},function(e,t,n){"use strict";n.d(t,"a",(function(){return u})),n.d(t,"c",(function(){return p})),n.d(t,"b",(function(){return f}));var i=n(8),r=n(2),s=n(32),o=n(41);
/**
 * @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 a(e,t){return{defineShader(n,i){const r=`prop_${i}`,s=`a_${r}`;n.addAttribute(`${e}`,s),n.addVertexCode(`${e} ${r}() { return ${s}; }`),n.addInitializer(e=>{const n=e.attribute(s),{gl:i}=e;e.vertexShaderInputBinders[r]=-1===n?{enable(){},disable(){},bind(){}}:{enable(e){i.enableVertexAttribArray(n),i.vertexAttribDivisor(n,e)},disable(){i.vertexAttribDivisor(n,0),i.disableVertexAttribArray(n)},bind(e,r){t(i,n,e,r)}}})}}}function c(e,t,n,i){return a(e,(e,r,s,o)=>{e.vertexAttribPointer(r,t,n,i,s,o)})}function l(e,t,n){return a(e,(e,i,r,s)=>{e.vertexAttribIPointer(i,t,n,r,s)})}const d={rgb:c("highp vec3",3,WebGL2RenderingContext.UNSIGNED_BYTE,!0),rgba:c("highp vec4",4,WebGL2RenderingContext.UNSIGNED_BYTE,!0),float32:c("highp float",1,WebGL2RenderingContext.FLOAT,!1),uint32:l("highp uint",1,WebGL2RenderingContext.UNSIGNED_INT),int32:l("highp int",1,WebGL2RenderingContext.INT),uint16:l("highp uint",1,WebGL2RenderingContext.UNSIGNED_SHORT),int16:l("highp int",1,WebGL2RenderingContext.SHORT),uint8:l("highp uint",1,WebGL2RenderingContext.UNSIGNED_BYTE),int8:l("highp int",1,WebGL2RenderingContext.BYTE)};class u extends r.a{constructor(e,t,n,r,s,o,a){super(),this.gl=e,this.annotationType=t,this.rank=n,this.properties=r,this.shaderControlState=s,this.fallbackShaderParameters=o,this.shaderError=a;const c=this.serializedGeometryBytesPerAnnotation=i.i[t].serializedBytes(n),{offsets:l,serializedBytes:d}=Object(i.l)(n,r);this.serializedBytesPerAnnotation=d+c,this.propertyOffsets=l}getDependentShader(e,t){return Object(s.d)(this,this.gl,{memoizeKey:{t:"annotation",targetIsSliceView:this.targetIsSliceView,type:this.annotationType,subType:e,properties:this.properties},fallbackParameters:this.fallbackShaderParameters,parameters:this.shaderControlState.parseResult,shaderError:this.shaderError,defineShader:(e,n)=>{const{rank:i,properties:r}=this;for(const t of r){d[t.type].defineShader(e,t.identifier,i)}const{propertyOffsets:a}=this;e.addInitializer(e=>{const t=this.properties.map(t=>e.vertexShaderInputBinders[`prop_${t.identifier}`]),n=t.length;e.vertexShaderInputBinders.properties={enable(e){for(let i=0;i<n;++i)t[i].enable(e)},bind(e,i){for(let r=0;r<n;++r)t[r].bind(e,i+a[r])},disable(){for(let e=0;e<n;++e)t[e].disable()}}}),e.addUniform("highp vec3","uColor"),e.addUniform("highp uint","uSelectedIndex"),e.addVarying("highp vec4","vColor"),e.addUniform("highp vec3","uSubspaceMatrix",i),e.addUniform("highp mat4","uModelViewProjection"),e.addUniform("highp float","uModelClipBounds",2*i),e.addUniform("highp uint","uPickID"),e.addVarying("highp uint","vPickID","flat"),e.addVertexCode(`\nvec3 defaultColor() { return uColor; }\nhighp uint getPickBaseOffset() { return uint(gl_InstanceID) * ${this.pickIdsPerInstance}u; }\n`),e.addFragmentCode("\nvoid emitAnnotation(vec4 color) {\n  emit(color, vPickID);\n}\n");const c=`\nfloat getSubspaceClipCoefficient(float modelPoint[${this.rank}]) {\n  float coefficient = 1.0;\n  for (int i = 0; i < ${i}; ++i) {\n    float d = abs(modelPoint[i] - uModelClipBounds[i]) * uModelClipBounds[${i} + i];\n    coefficient *= max(0.0, 1.0 - d);\n  }\n  return coefficient;\n}\n`;e.addVertexCode(c),e.addFragmentCode(c),e.addVertexCode(`\nvec3 projectModelVectorToSubspace(float modelPoint[${this.rank}]) {\n  vec3 result = vec3(0.0, 0.0, 0.0);\n  for (int i = 0; i < ${i}; ++i) {\n    result += uSubspaceMatrix[i] * modelPoint[i];\n  }\n  return result;\n}\n\nfloat getMaxEndpointSubspaceClipCoefficient(float modelPointA[${this.rank}],  float modelPointB[${this.rank}]) {\n  float coefficient = 1.0;\n  for (int i = 0; i < ${i}; ++i) {\n    float dA = abs(modelPointA[i] - uModelClipBounds[i]) * uModelClipBounds[${i} + i];\n    float dB = abs(modelPointB[i] - uModelClipBounds[i]) * uModelClipBounds[${i} + i];\n    coefficient *= max(0.0, 1.0 - min(dA, dB));\n  }\n  return coefficient;\n}\n\nfloat getMaxSubspaceClipCoefficient(float modelPointA[${this.rank}],  float modelPointB[${this.rank}]) {\n  float coefficient = 1.0;\n  for (int i = 0; i < ${i}; ++i) {\n    float a = modelPointA[i];\n    float b = modelPointB[i];\n    float c = uModelClipBounds[i];\n    float x = clamp(c, min(a, b), max(a, b));\n    float d = abs(x - c) * uModelClipBounds[${i} + i];\n    coefficient *= max(0.0, 1.0 - d);\n  }\n  return coefficient;\n}\n\n`),Object(o.b)(n.controls,e),e.addVertexCode(`\nconst bool PROJECTION_VIEW = ${!this.targetIsSliceView};\nbool ng_discardValue;\n#define discard ng_discard()\nvoid ng_discard() {\n  ng_discardValue = true;\n}\nvoid setLineColor(vec4 startColor, vec4 endColor);\nvoid setLineWidth(float width);\n\nvoid setEndpointMarkerColor(vec4 startColor, vec4 endColor);\nvoid setEndpointMarkerBorderColor(vec4 startColor, vec4 endColor);\nvoid setEndpointMarkerSize(float startSize, float endSize);\nvoid setEndpointMarkerBorderWidth(float startSize, float endSize);\n\nvoid setPointMarkerColor(vec4 color);\nvoid setPointMarkerBorderColor(vec4 color);\nvoid setPointMarkerSize(float size);\nvoid setPointMarkerBorderWidth(float size);\nvoid setPointMarkerBorderColor(vec3 color) { setPointMarkerBorderColor(vec4(color, 1.0)); }\n\nvoid setEllipsoidFillColor(vec4 color);\n\nvoid setBoundingBoxBorderColor(vec4 color);\nvoid setBoundingBoxBorderWidth(float size);\nvoid setBoundingBoxFillColor(vec4 color);\n\nvoid setEndpointMarkerColor(vec3 startColor, vec3 endColor) {\n  setEndpointMarkerColor(vec4(startColor, 1.0), vec4(endColor, 1.0));\n}\nvoid setEndpointMarkerBorderColor(vec3 startColor, vec3 endColor) {\n  setEndpointMarkerBorderColor(vec4(startColor, 1.0), vec4(endColor, 1.0));\n}\nvoid setEndpointMarkerColor(vec3 color) { setEndpointMarkerColor(color, color); }\nvoid setEndpointMarkerColor(vec4 color) { setEndpointMarkerColor(color, color); }\nvoid setEndpointMarkerBorderColor(vec3 color) { setEndpointMarkerBorderColor(color, color); }\nvoid setEndpointMarkerBorderColor(vec4 color) { setEndpointMarkerBorderColor(color, color); }\nvoid setEndpointMarkerSize(float size) { setEndpointMarkerSize(size, size); }\nvoid setEndpointMarkerBorderWidth(float size) { setEndpointMarkerBorderWidth(size, size); }\nvoid setLineColor(vec4 color) { setLineColor(color, color); }\nvoid setLineColor(vec3 color) { setLineColor(vec4(color, 1.0)); }\nvoid setLineColor(vec3 startColor, vec3 endColor) { setLineColor(vec4(startColor, 1.0), vec4(endColor, 1.0)); }\nvoid setColor(vec4 color) {\n  setPointMarkerColor(color);\n  setLineColor(color);\n  setEndpointMarkerColor(color);\n  setBoundingBoxBorderColor(color);\n  setEllipsoidFillColor(vec4(color.rgb, color.a * (PROJECTION_VIEW ? 1.0 : 0.5)));\n}\nvoid setEllipsoidFillColor(vec3 color) { setEllipsoidFillColor(vec4(color, 1.0)); }\n\nvoid setBoundingBoxFillColor(vec3 color) { setBoundingBoxFillColor(vec4(color, 1.0)); }\nvoid setBoundingBoxBorderColor(vec3 color) { setBoundingBoxBorderColor(vec4(color, 1.0)); }\n\nvoid setColor(vec3 color) { setColor(vec4(color, 1.0)); }\nvoid userMain();\n`);for(const[t,n]of h)t!==this.annotationType&&n.defineShaderNoOpSetters(e);t(e),e.addVertexCode("\n#define main userMain\n"+Object(s.e)(n.code)+"\n#undef main\n")}})}setPartIndex(e,...t){let n=`\nvoid setPartIndex(${t.map((e,t)=>`highp uint partIndex${t}`).join()}) {\n  highp uint pickID = uPickID;\n  highp uint pickBaseOffset = getPickBaseOffset();\n${t.map((e,t)=>`highp uint pickOffset${t} = pickBaseOffset + partIndex${t};`).join("\n")}\n`;return 0===t.length&&(n+="\n  highp uint pickOffset0 = pickBaseOffset;\n"),n+=`\n  vPickID = pickID + pickOffset0;\n  highp uint selectedIndex = uSelectedIndex;\nif (selectedIndex == pickBaseOffset${t.map((e,t)=>` || selectedIndex == pickOffset${t}`).join("")}) {\n    vColor = vec4(mix(vColor.rgb, vec3(1.0, 1.0, 1.0), 0.75), vColor.a);\n  }\n}\n`,e.addVertexCode(n),`setPartIndex(${t.join()})`}get invokeUserMain(){return"\nng_discardValue = false;\nuserMain();\nif (ng_discardValue) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\n"}getCrossSectionFadeFactor(){return this.targetIsSliceView?"(clamp(1.0 - 2.0 * abs(0.5 - gl_FragCoord.z), 0.0, 1.0))":"(1.0)"}enable(e,t,n){const{shader:i,parameters:r}=e(t.renderContext.emitter);if(null===i)return;i.bind();const{gl:s}=this,{renderContext:a}=t,{annotationLayer:c}=t;if(Object(o.d)(s,i,this.shaderControlState,r.controls),s.uniform3fv(i.uniform("uSubspaceMatrix"),t.subspaceMatrix),s.uniform1fv(i.uniform("uModelClipBounds"),t.modelClipBounds),s.uniformMatrix4fv(i.uniform("uModelViewProjection"),!1,t.modelViewProjectionMatrix),a.emitPickID&&s.uniform1ui(i.uniform("uPickID"),t.basePickId),a.emitColor){const e=c.state.displayState.color.value;s.uniform3f(i.uniform("uColor"),e[0],e[1],e[2]),s.uniform1ui(i.uniform("uSelectedIndex"),t.selectedIndex)}const l=i.vertexShaderInputBinders.properties;l.enable(1),s.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER,t.buffer.buffer),l.bind(this.serializedBytesPerAnnotation,t.bufferOffset+this.serializedGeometryBytesPerAnnotation),n(i),l.disable()}}const h=new Map;function p(e,t){h.set(e,t)}function f(e){return h.get(e)}},function(e,t,n){"use strict";n.d(t,"g",(function(){return T})),n.d(t,"b",(function(){return D})),n.d(t,"d",(function(){return L})),n.d(t,"c",(function(){return j})),n.d(t,"e",(function(){return I})),n.d(t,"a",(function(){return P})),n.d(t,"f",(function(){return A}));var i=n(15),r=n.n(i),s=n(10),o=n(12),a=n(85),c=n(38),l=n(36),d=n(26),u=n(132),h=n(72),p=n(2),f=n(1),m=n(57),g=n(45),v=n(3),b=n(31),y=n(53),S=n(74),w=n(125),x=n(16),C=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};class O extends d.h{}const k=Object(b.c)(O);function E(e){return{source:e.source.addCounterpartRef(),effectiveVoxelSize:e.effectiveVoxelSize,layerRank:e.layerRank,nonDisplayLowerClipBound:e.nonDisplayLowerClipBound,nonDisplayUpperClipBound:e.nonDisplayUpperClipBound,lowerClipBound:e.lowerClipBound,upperClipBound:e.upperClipBound,lowerClipDisplayBound:e.lowerClipDisplayBound,upperClipDisplayBound:e.upperClipDisplayBound,chunkDisplayDimensionIndices:e.chunkDisplayDimensionIndices,lowerChunkDisplayBound:e.lowerChunkDisplayBound,upperChunkDisplayBound:e.upperChunkDisplayBound,fixedLayerToChunkTransform:e.fixedLayerToChunkTransform,combinedGlobalLocalToChunkTransform:e.combinedGlobalLocalToChunkTransform,chunkLayout:e.chunkLayout.toObject()}}function T(e){return e.map(e=>e.map(E))}function M(e,t){for(const n of t)for(const{source:t}of n)e.removeSource(t),t.dispose()}let D=class extends k{constructor(e,t,n,i){super(new l.a({parametersConstructor:d.i,navigationState:n,update:(e,t)=>{const{invViewMatrix:n,centerDataPosition:i}=e;t.toMat4(n);const{canonicalVoxelFactors:r,voxelPhysicalScales:s}=e.displayDimensionRenderInfo;for(let e=0;e<3;++e)i[e]=n[12+e];const{width:o,height:c,projectionMat:l,viewportNormalInGlobalCoordinates:d,viewportNormalInCanonicalCoordinates:u}=e,{relativeDepthRange:h}=t;f.m.ortho(l,-o/2,o/2,c/2,-c/2,-h,h),Object(a.c)(e);const{viewMatrix:p}=e;for(let e=0;e<3;++e){const t=d[e]=p[4*e+2];u[e]=t/r[e]}f.u.normalize(d,d),f.u.normalize(u,u);let m=0;for(let e=0;e<3;++e){m+=(s[e]*n[e])**2}m=Math.sqrt(m),e.pixelSize=m}})),this.chunkManager=e,this.layerManager=t,this.navigationState=n,this.wireFrame=i,this.gl=this.chunkManager.gl,this.viewChanged=new v.a,this.renderingStale=!0,this.visibleChunksStale=!0,this.visibleLayerList=new Array,this.offscreenFramebuffer=this.registerDisposer(new y.b(this.gl,{colorBuffers:Object(y.f)(this.gl,1),depthBuffer:new y.d(this.gl)})),this.updateVisibleLayers=this.registerCancellable(r()(()=>{this.updateVisibleLayersNow()},0)),this.registerDisposer(n),this.registerDisposer(this.projectionParameters),this.registerDisposer(this.projectionParameters.changed.add((e,t)=>{e.displayDimensionRenderInfo!==t.displayDimensionRenderInfo&&this.updateVisibleLayers()}));const s=this.chunkManager.rpc,o=this.sharedProjectionParameters=this.registerDisposer(new l.d(s,this.projectionParameters));this.initializeCounterpart(s,{chunkManager:e.rpcId,projectionParameters:o.rpcId}),this.registerDisposer(t.layersChanged.add(()=>{this.updateVisibleLayers()})),this.wireFrame.changed.add(this.viewChanged.dispatch),this.viewChanged.add(()=>{this.renderingStale=!0}),this.registerDisposer(e.chunkQueueManager.visibleChunksChanged.add(this.viewChanged.dispatch)),this.updateVisibleLayers()}flushBackendProjectionParameters(){this.sharedProjectionParameters.flush()}forEachVisibleChunk(e,t){Object(d.k)(this.projectionParameters.value,e.renderLayer.localPosition.value,e,()=>{t(e.curPositionInChunks.join())})}isReady(){if(!this.navigationState.valid)return!1;this.updateVisibleLayers.flush(),this.updateVisibleSources();let e=0,t=0;for(const{visibleSources:n}of this.visibleLayers.values())for(const i of n){const{source:n}=i,{chunks:r}=n;this.forEachVisibleChunk(i,n=>{const i=r.get(n);++t,i&&i.state===s.h.GPU_MEMORY&&++e})}return e===t}invalidateVisibleSources(){super.invalidateVisibleSources(),this.viewChanged.dispatch()}bindVisibleRenderLayer(e,t){t.push(e.localPosition.changed.add(()=>this.invalidateVisibleChunks())),t.push(e.redrawNeeded.add(this.viewChanged.dispatch)),t.push(e.transform.changed.add(this.updateVisibleLayers)),t.push(e.renderScaleTarget.changed.add(()=>this.invalidateVisibleSources()));const{renderScaleHistogram:n}=e;void 0!==n&&t.push(n.visibility.add(this.visibility))}updateVisibleLayersNow(){if(this.wasDisposed)return!1;if(!this.navigationState.valid)return!1;const e=Date.now(),{visibleLayers:t,visibleLayerList:n}=this,{displayDimensionRenderInfo:i}=this.projectionParameters.value;let r=this.rpc,s={id:this.rpcId},o=!1;n.length=0;for(let a of this.layerManager.readyRenderLayers())if(a instanceof h.b){n.push(a);let c=t.get(a);if(void 0===c){const n=[],r=new m.a;c={messages:r,allSources:this.getTransformedSources(a,r),transformGeneration:a.transform.changed.count,visibleSources:[],disposers:n,lastSeenGeneration:e,displayDimensionRenderInfo:i},n.push(a.messages.addChild(c.messages)),t.set(a.addRef(),c),this.bindVisibleRenderLayer(a,n)}else{c.lastSeenGeneration=e;const t=a.transform.changed.count;if(c.transformGeneration===t&&c.displayDimensionRenderInfo===i)continue;const n=c.allSources;c.allSources=this.getTransformedSources(a,c.messages),M(a,n),c.visibleSources.length=0,c.displayDimensionRenderInfo=i,c.transformGeneration=t}s.layerId=a.rpcId,s.sources=T(c.allSources),this.flushBackendProjectionParameters(),r.invoke(d.d,s),o=!0}for(const[n,i]of t)i.lastSeenGeneration!==e&&(s.layerId=n.rpcId,r.invoke(d.e,s),t.delete(n),M(n,i.allSources),Object(p.d)(i.disposers),n.dispose(),o=!0);return o&&(this.visibleSourcesStale=!0),this.viewChanged.dispatch(),o}invalidateVisibleChunks(){super.invalidateVisibleChunks(),this.viewChanged.dispatch()}get valid(){return this.navigationState.valid}updateRendering(){const e=this.projectionParameters.value,{width:t,height:n}=e;if(!this.renderingStale||!this.valid||0===t||0===n)return;this.renderingStale=!1,this.updateVisibleLayers.flush(),this.updateVisibleSources();let{gl:i,offscreenFramebuffer:r}=this;r.bind(t,n),i.disable(i.SCISSOR_TEST),i.clearStencil(0),i.clearColor(0,0,0,0),i.colorMask(!0,!0,!0,!0),i.clear(i.COLOR_BUFFER_BIT),i.enable(i.STENCIL_TEST),i.disable(i.DEPTH_TEST),i.stencilOpSeparate(i.FRONT_AND_BACK,i.KEEP,i.KEEP,i.REPLACE);let s=0;const o={sliceView:this,projectionParameters:e,wireFrame:this.wireFrame.value};for(let e of this.visibleLayerList)i.clear(i.STENCIL_BUFFER_BIT),i.stencilFuncSeparate(i.FRONT_AND_BACK,i.GREATER,1,1),e.setGLBlendMode(i,s),e.draw(o),++s;i.disable(i.BLEND),i.disable(i.STENCIL_TEST),r.unbind()}disposed(){for(const[e,t]of this.visibleLayers)M(e,t.allSources),Object(p.d)(t.disposers),e.dispose();this.visibleLayers.clear(),this.visibleLayerList.length=0}getTransformedSources(e,t){const n=A(this.projectionParameters.value.displayDimensionRenderInfo,e.transform.value,t=>e.getSources(t),t,e);for(const t of n)for(const n of t)e.addSource(n.source,n.chunkTransform);return n}};D=C([Object(x.g)(d.g)],D);class L extends o.f{constructor(e,t){super(e,t),this.spec=t.spec}static encodeSpec(e){return{chunkDataSize:Array.from(e.chunkDataSize),lowerVoxelBound:Array.from(e.lowerVoxelBound),upperVoxelBound:Array.from(e.upperVoxelBound)}}static encodeOptions(e){const t=super.encodeOptions(e);return t.spec=this.encodeSpec(e.spec),t}initializeCounterpart(e,t){t.spec=this.spec,super.initializeCounterpart(e,t)}}class j extends o.b{constructor(e,t){super(e),this.chunkGridPosition=t.chunkGridPosition,this.state=s.h.SYSTEM_MEMORY}}class I extends p.a{constructor(e,t){super(),this.gl=e,this.copyVertexPositionsBuffer=Object(w.a)(this.gl),this.textureCoordinateAdjustment=new Float32Array(4);let n=new S.a(e);n.addVarying("vec2","vTexCoord"),n.addUniform("sampler2D","uSampler"),n.addInitializer(t=>{e.uniform1i(t.uniform("uSampler"),0)}),n.addUniform("vec4","uColorFactor"),n.addUniform("vec4","uBackgroundColor"),n.addUniform("mat4","uProjectionMatrix"),n.addUniform("vec4","uTextureCoordinateAdjustment"),n.require(t),n.setFragmentMain("\nvec4 sampledColor = texture(uSampler, vTexCoord);\nif (sampledColor.a == 0.0) {\n  sampledColor = uBackgroundColor;\n}\nemit(sampledColor * uColorFactor, 0u);\n"),n.addAttribute("vec4","aVertexPosition"),n.setVertexMain("\nvTexCoord = uTextureCoordinateAdjustment.xy + 0.5 * (aVertexPosition.xy + 1.0) * uTextureCoordinateAdjustment.zw;\ngl_Position = uProjectionMatrix * aVertexPosition;\n"),this.shader=this.registerDisposer(n.build())}draw(e,t,n,i,r,s,o,a){let{gl:c,shader:l,textureCoordinateAdjustment:d}=this;d[0]=r,d[1]=s,d[2]=o-r,d[3]=a-s,l.bind(),c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,e),c.uniformMatrix4fv(l.uniform("uProjectionMatrix"),!1,t),c.uniform4fv(l.uniform("uColorFactor"),n),c.uniform4fv(l.uniform("uBackgroundColor"),i),c.uniform4fv(l.uniform("uTextureCoordinateAdjustment"),d);let u=l.attribute("aVertexPosition");this.copyVertexPositionsBuffer.bindToVertexAttrib(u,2),c.drawArrays(c.TRIANGLE_FAN,0,4),c.disableVertexAttribArray(u),c.bindTexture(c.TEXTURE_2D,null)}static get(e,t){return e.memoize.get(`sliceview/SliceViewRenderHelper:${Object(g.a)(t)}`,()=>new I(e,t))}}class P{constructor(e){this.chunkManager=e}}function A(e,t,n,i,r){i.clearMessages();const s=e=>(i.addMessage({severity:m.b.error,message:e}),[]);if(void 0!==t.error)return s(t.error);const o=t.rank,a=t.unpaddedRank,{displayDimensionIndices:l,displayRank:d,canonicalVoxelFactors:h}=e,p=Object(c.g)(t,l),{layerDisplayDimensionIndices:g}=p,v=new Float32Array(d*a),{modelToRenderLayerTransform:b}=t;for(let e=0;e<d;++e){const t=g[e];if(-1===t)continue;const n=h[e];for(let i=0;i<a;++i)v[d*i+e]=b[(o+1)*i+t]*n}const y=n({displayRank:d,multiscaleToViewTransform:v,modelChannelDimensionIndices:t.channelToRenderLayerDimensions}),{voxelPhysicalScales:S}=e;try{const e=e=>{const{chunkSource:n}=e,{spec:i}=n,{lowerClipBound:s=i.lowerVoxelBound,upperClipBound:o=i.upperVoxelBound}=e,l=Object(c.f)(t,e.chunkToMultiscaleTransform),{chunkDataSize:h}=i,{channelToChunkDimensionIndices:m}=l,g=new Float32Array(a),v=new Float32Array(a);g.set(s),v.set(o);const b=m.length,{channelSpaceShape:y}=t;for(let e=0;e<b;++e){const n=m[e];if(-1===n)continue;const i=y[e];if(h[n]!==i)throw new Error("Channel dimension "+t.layerDimensionNames[t.channelToRenderLayerDimensions[e]]+` has extent ${i} but corresponding chunk dimension has extent `+`${h[n]}`);g[n]=Number.NEGATIVE_INFINITY,v[n]=Number.POSITIVE_INFINITY}const w=Object(c.d)(l,p),x=f.u.create(),C=f.u.create(),O=f.u.create(),k=f.u.create(),E=f.u.create(),{numChunkDisplayDims:T,chunkDisplayDimensionIndices:M}=w,{combinedGlobalLocalToChunkTransform:D,layerRank:L,combinedGlobalLocalRank:j}=l,I=new Float32Array(D);for(let e=0;e<T;++e){const t=M[e];for(let e=0;e<=j;++e)I[t+e*L]=0;t<a?(E[e]=i.chunkDataSize[t],x[e]=i.lowerChunkBound[t],C[e]=i.upperChunkBound[t],O[e]=s[t],k[e]=o[t],g[t]=Number.NEGATIVE_INFINITY,v[t]=Number.POSITIVE_INFINITY):(E[e]=1,x[e]=0,C[e]=1,O[e]=0,k[e]=1)}E.fill(1,T),x.fill(0,T),C.fill(1,T),O.fill(0,T),k.fill(1,T);const P=new u.a(E,w.displaySubspaceModelMatrix,T),A=P.localSpatialVectorToGlobal(f.u.create(),f.j);for(let e=0;e<d;++e)A[e]*=S[e];return A.fill(1,d),{layerRank:L,lowerClipBound:s,upperClipBound:o,nonDisplayLowerClipBound:g,nonDisplayUpperClipBound:v,renderLayer:r,source:n,lowerChunkDisplayBound:x,upperChunkDisplayBound:C,lowerClipDisplayBound:O,upperClipDisplayBound:k,effectiveVoxelSize:A,chunkLayout:P,chunkDisplayDimensionIndices:M,fixedLayerToChunkTransform:I,curPositionInChunks:new Float32Array(a),combinedGlobalLocalToChunkTransform:l.combinedGlobalLocalToChunkTransform,fixedPositionWithinChunk:new Uint32Array(a),chunkTransform:l,chunkDisplayTransform:w}};return y.map(t=>t.map(t=>e(t)))}catch(t){for(const e of y)for(const{chunkSource:t}of e)t.dispose();const{globalDimensionNames:n}=e;return s(`Cannot render (${Array.from(e.displayDimensionIndices.filter(e=>-1!==e),e=>n[e]).join(", ")}) cross section: ${t.message}`)}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"a",(function(){return s}));var i,r=n(3);
/**
 * @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(e){e[e.info=0]="info",e[e.warning=1]="warning",e[e.error=2]="error"}(i||(i={}));class s{constructor(){this.changed=new r.a,this.messages=[],this.children=[]}addMessage(e){this.messages.push(e),this.changed.dispatch()}clearMessages(){const{messages:e}=this;0!==e.length&&(e.length=0,this.changed.dispatch())}isEmpty(){return 0===this.messages.length&&!this.children.some(e=>!e.isEmpty())}addChild(e){return this.children.push(e),e.changed.add(this.changed.dispatch),e.isEmpty()||this.changed.dispatch(),()=>{const{children:t}=this;t.splice(t.indexOf(e),1),e.changed.remove(this.changed.dispatch),e.isEmpty()||this.changed.dispatch()}}*[Symbol.iterator](){yield*this.messages;for(const e of this.children)yield*e}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i,r=n(4),s=n(16);let o=i=class extends s.c{constructor(e,t={}){super(e,t),this.updatingValue_=!1,void 0!==e&&(this.base=new r.e(t.value),this.setupChangedHandler())}initializeCounterpart(e,t={}){t.value=this.value,super.initializeCounterpart(e,t)}setupChangedHandler(){this.registerDisposer(this.base.changed.add(()=>{if(this.updatingValue_)this.updatingValue_=!1;else{const{rpc:e}=this;null!==e&&e.invoke("SharedWatchableValue.changed",{id:this.rpcId,value:this.value})}}))}static makeFromExisting(e,t){let n=new i;return n.base=t,n.setupChangedHandler(),n.initializeCounterpart(e),n}static make(e,t){return i.makeFromExisting(e,new r.e(t))}get value(){return this.base.value}set value(e){this.base.value=e}get changed(){return this.base.changed}};o=i=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}([Object(s.f)("SharedWatchableValue")],o),Object(s.e)("SharedWatchableValue.changed",(function(e){const t=this.get(e.id);t.updatingValue_=!0,t.base.value=e.value,t.updatingValue_=!1}))},function(e,t,n){"use strict";var i=n(10),r=n(12),s=n(71),o=n(36),a=n(52),c=n(44);var l=n(72),d=n(4),u=n(14),h=n(2),p=n(1),f=n(0),m=n(3),g=n(24),v=n(106),b=n(43),y=n(60),S=n(86),w=n(32),x=n(29),C=n(41),O=n(35),k=n(49);n.d(t,"c",(function(){return P})),n.d(t,"b",(function(){return A})),n.d(t,"a",(function(){return R})),n.d(t,"e",(function(){return N})),n.d(t,"d",(function(){return z}));
/**
 * @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 E=p.m.create(),T=[],M=Object(O.d)(new O.c,u.c.FLOAT32,3);class D extends h.a{constructor(e,t){super(),this.base=e,this.targetIsSliceView=t,this.textureAccessHelper=new O.a("vertexData"),this.vertexIdHelper=this.registerDisposer(k.a.get(this.gl)),this.edgeShaderGetter=Object(w.d)(this,this.gl,{memoizeKey:{type:"skeleton/SkeletonShaderManager/edge",vertexAttributes:this.vertexAttributes},fallbackParameters:this.base.fallbackShaderParameters,parameters:this.base.displayState.skeletonRenderingOptions.shaderControlState.parseResult,shaderError:this.base.displayState.shaderError,defineShader:(e,t)=>{this.defineCommonShader(e),this.defineAttributeAccess(e),Object(x.b)(e),e.addAttribute("highp uvec2","aVertexIndex"),e.addUniform("highp float","uLineWidth");let n="\nhighp vec3 vertexA = readAttribute0(aVertexIndex.x);\nhighp vec3 vertexB = readAttribute0(aVertexIndex.y);\nemitLine(uProjection, vertexA, vertexB, uLineWidth);\nhighp uint lineEndpointIndex = getLineEndpointIndex();\nhighp uint vertexIndex = aVertexIndex.x * lineEndpointIndex + aVertexIndex.y * (1u - lineEndpointIndex);\n";e.addFragmentCode(`\nvec4 segmentColor() {\n  return uColor;\n}\nvoid emitRGB(vec3 color) {\n  emit(vec4(color * uColor.a, uColor.a * getLineAlpha() * ${this.getCrossSectionFadeFactor()}), uPickID);\n}\nvoid emitDefault() {\n  emit(vec4(uColor.rgb, uColor.a * getLineAlpha() * ${this.getCrossSectionFadeFactor()}), uPickID);\n}\n`),e.addFragmentCode(S.a);const{vertexAttributes:i}=this,r=i.length;for(let t=1;t<r;++t){const r=i[t];e.addVarying(`highp ${r.glslDataType}`,`vCustom${t}`),n+=`vCustom${t} = readAttribute${t}(vertexIndex);\n`,e.addFragmentCode(`#define ${r.name} vCustom${t}\n`)}e.setVertexMain(n),Object(C.b)(t.controls,e),e.setFragmentMainFunction(Object(w.e)(t.code))}}),this.nodeShaderGetter=Object(w.d)(this,this.gl,{memoizeKey:{type:"skeleton/SkeletonShaderManager/node",vertexAttributes:this.vertexAttributes},fallbackParameters:this.base.fallbackShaderParameters,parameters:this.base.displayState.skeletonRenderingOptions.shaderControlState.parseResult,shaderError:this.base.displayState.shaderError,defineShader:(e,t)=>{this.defineCommonShader(e),this.defineAttributeAccess(e),Object(y.b)(e,this.targetIsSliceView),e.addUniform("highp float","uNodeDiameter");let n="\nhighp uint vertexIndex = uint(gl_InstanceID);\nhighp vec3 vertexPosition = readAttribute0(vertexIndex);\nemitCircle(uProjection * vec4(vertexPosition, 1.0), uNodeDiameter, 0.0);\n";e.addFragmentCode("\nvec4 segmentColor() {\n  return uColor;\n}\nvoid emitRGBA(vec4 color) {\n  vec4 borderColor = color;\n  emit(getCircleColor(color, borderColor), uPickID);\n}\nvoid emitRGB(vec3 color) {\n  emitRGBA(vec4(color, 1.0));\n}\nvoid emitDefault() {\n  emitRGBA(uColor);\n}\n"),e.addFragmentCode(S.a);const{vertexAttributes:i}=this,r=i.length;for(let t=1;t<r;++t){const r=i[t];e.addVarying(`highp ${r.glslDataType}`,`vCustom${t}`),n+=`vCustom${t} = readAttribute${t}(vertexIndex);\n`,e.addFragmentCode(`#define ${r.name} vCustom${t}\n`)}e.setVertexMain(n),Object(C.b)(t.controls,e),e.setFragmentMainFunction(Object(w.e)(t.code))}})}get vertexAttributes(){return this.base.vertexAttributes}defineCommonShader(e){Object(k.b)(e),e.addUniform("highp vec4","uColor"),e.addUniform("highp mat4","uProjection"),e.addUniform("highp uint","uPickID")}get gl(){return this.base.gl}defineAttributeAccess(e){const{textureAccessHelper:t}=this;t.defineShader(e);const n=this.vertexAttributes.length;for(let e=T.length;e<n;++e)T[e]=Symbol(`SkeletonShader.vertexAttributeTextureUnit${e}`);this.vertexAttributes.forEach((n,i)=>{e.addTextureSampler(`${Object(O.e)(n.dataType)}sampler2D`,`uVertexAttributeSampler${i}`,T[i]),e.addVertexCode(t.getAccessor(`readAttribute${i}`,`uVertexAttributeSampler${i}`,n.dataType,n.numComponents))})}getCrossSectionFadeFactor(){return this.targetIsSliceView?"(clamp(1.0 - 2.0 * abs(0.5 - gl_FragCoord.z), 0.0, 1.0))":"(1.0)"}beginLayer(e,t,n,i){const{viewProjectionMat:r}=n.projectionParameters;let s=p.m.multiply(E,r,i);e.uniformMatrix4fv(t.uniform("uProjection"),!1,s),this.vertexIdHelper.enable()}setColor(e,t,n){e.uniform4fv(t.uniform("uColor"),n)}setPickID(e,t,n){e.uniform1ui(t.uniform("uPickID"),n)}drawSkeleton(e,t,n,i,r){const{vertexAttributes:s}=this,o=s.length,{vertexAttributeTextures:a}=i;for(let n=0;n<o;++n){const i=WebGL2RenderingContext.TEXTURE0+t.textureUnit(T[n]);e.activeTexture(i),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,a[n])}{t.bind();const n=t.attribute("aVertexIndex");i.indexBuffer.bindToVertexAttribI(n,2,WebGL2RenderingContext.UNSIGNED_INT),e.vertexAttribDivisor(n,1),Object(x.d)(t,r,this.targetIsSliceView?1:0),Object(x.c)(e,1,i.numIndices/2),e.vertexAttribDivisor(n,0),e.disableVertexAttribArray(n)}null!==n&&(n.bind(),Object(y.d)(n,r,{featherWidthInPixels:this.targetIsSliceView?1:0}),Object(y.c)(n.gl,2,i.numVertices))}endLayer(e,t){const{vertexAttributes:n}=this,i=n.length;for(let n=0;n<i;++n){let i=t.textureUnit(T[n])+WebGL2RenderingContext.TEXTURE0;e.activeTexture(i),e.bindTexture(e.TEXTURE_2D,null)}this.vertexIdHelper.disable()}}var L;!function(e){e[e.LINES=0]="LINES",e[e.LINES_AND_POINTS=1]="LINES_AND_POINTS"}(L||(L={}));class j extends v.a{constructor(e,t=e){super(L,e,t)}}class I extends d.c{constructor(e,t=e){super(e,f.r,t)}}class P{constructor(){this.compound=new g.a,this.shader=Object(w.a)("void main() {\n  emitDefault();\n}\n"),this.shaderControlState=new C.a(this.shader),this.params2d={mode:new j(L.LINES_AND_POINTS),lineWidth:new I(2)},this.params3d={mode:new j(L.LINES),lineWidth:new I(1)};const{compound:e}=this;e.add("shader",this.shader),e.add("shaderControls",this.shaderControlState),e.add("mode2d",this.params2d.mode),e.add("lineWidth2d",this.params2d.lineWidth),e.add("mode3d",this.params3d.mode),e.add("lineWidth3d",this.params3d.lineWidth)}get changed(){return this.compound.changed}reset(){this.compound.reset()}restoreState(e){void 0!==e&&this.compound.restoreState(e)}toJSON(){const e=this.compound.toJSON();for(const t of Object.values(e))if(void 0!==t)return e}}class A extends h.a{constructor(e,t,n){super(),this.chunkManager=e,this.source=t,this.displayState=n,this.layerChunkProgressInfo=new i.i,this.redrawNeeded=new m.a,this.fallbackShaderParameters=new d.e(Object(C.c)("void main() {\n  emitDefault();\n}\n")),Object(c.f)(n,this),this.displayState.shaderError.value=void 0;const{skeletonRenderingOptions:r}=n;this.registerDisposer(r.shader.changed.add(()=>{this.displayState.shaderError.value=void 0,this.redrawNeeded.dispatch()}));let s=this.sharedObject=this.registerDisposer(new c.b(e,n,this.layerChunkProgressInfo));s.RPC_TYPE_ID="skeleton/SkeletonLayer",s.initializeCounterpartWithChunkManager({source:t.addCounterpartRef()});const o=this.vertexAttributes=[_];for(let[e,n]of t.vertexAttributes)o.push({name:e,dataType:n.dataType,numComponents:n.numComponents,webglDataType:V(n.dataType),glslDataType:n.numComponents>1?`vec${n.numComponents}`:"float"})}get visibility(){return this.sharedObject.visibility}get gl(){return this.chunkManager.chunkQueueManager.gl}draw(e,t,n,r,s){let l=r.lineWidth.value;const{gl:d,source:u,displayState:h}=this,p=Math.min(1,h.objectAlpha.value);if(p<=0)return;const f=Object(o.g)(h.transform.value,e.projectionParameters.displayDimensionRenderInfo,s);if(void 0===f)return;let m;m=r.mode.value===L.LINES_AND_POINTS?Math.max(5,2*l):l;const g=n.edgeShaderGetter(e.emitter),v=n.nodeShaderGetter(e.emitter),{shader:b,parameters:y}=g,{shader:S,parameters:w}=v;if(null===b||null===S)return;const{shaderControlState:x}=this.displayState.skeletonRenderingOptions;b.bind(),n.beginLayer(d,b,e,f),Object(C.d)(d,b,x,y.controls),d.uniform1f(b.uniform("uLineWidth"),l),S.bind(),n.beginLayer(d,S,e,f),d.uniform1f(S.uniform("uNodeDiameter"),m),Object(C.d)(d,S,x,w.controls);const O=u.chunks,{pickIDs:k}=e;Object(a.a)(h,(r,s)=>{const o=Object(a.b)(r),l=O.get(o);void 0!==l&&l.state===i.h.GPU_MEMORY&&(e.emitColor&&(b.bind(),n.setColor(d,b,Object(c.e)(h,s,p)),S.bind(),n.setColor(d,S,Object(c.e)(h,s,p))),e.emitPickID&&(b.bind(),n.setPickID(d,b,k.registerUint64(t,r)),S.bind(),n.setPickID(d,S,k.registerUint64(t,r))),n.drawSkeleton(d,b,S,l,e.projectionParameters))}),n.endLayer(d,b)}isReady(){const{source:e,displayState:t}=this;if(Math.min(1,t.objectAlpha.value)<=0)return!0;const n=e.chunks;let r=!0;return Object(a.a)(t,e=>{const t=Object(a.b)(e),s=n.get(t);void 0!==s&&s.state===i.h.GPU_MEMORY||(r=!1)}),r}}class R extends s.a{constructor(e){super(),this.base=e,this.renderHelper=this.registerDisposer(new D(this.base,!1)),this.renderOptions=this.base.displayState.skeletonRenderingOptions.params3d,this.layerChunkProgressInfo=e.layerChunkProgressInfo,this.registerDisposer(e),this.registerDisposer(e.redrawNeeded.add(this.redrawNeeded.dispatch));const{renderOptions:t}=this;this.registerDisposer(t.mode.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(t.lineWidth.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(e.visibility.add(this.visibility))}get gl(){return this.base.gl}get isTransparent(){return this.base.displayState.objectAlpha.value<1}draw(e,t){!e.emitColor&&e.alreadyEmittedPickID||this.base.draw(e,this,this.renderHelper,this.renderOptions,t)}isReady(){return this.base.isReady()}}class N extends l.a{constructor(e){super(),this.base=e,this.renderHelper=this.registerDisposer(new D(this.base,!0)),this.renderOptions=this.base.displayState.skeletonRenderingOptions.params2d,this.layerChunkProgressInfo=e.layerChunkProgressInfo,this.registerDisposer(e);const{renderOptions:t}=this;this.registerDisposer(t.mode.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(t.lineWidth.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(e.redrawNeeded.add(this.redrawNeeded.dispatch)),this.registerDisposer(e.visibility.add(this.visibility))}get gl(){return this.base.gl}draw(e,t){this.base.draw(e,this,this.renderHelper,this.renderOptions,t)}isReady(){return this.base.isReady()}}function V(e){switch(e){case u.c.FLOAT32:return WebGL2RenderingContext.FLOAT;default:throw new Error(`Data type not supported by WebGL: ${u.c[e]}`)}}const _={dataType:u.c.FLOAT32,numComponents:3,name:"",webglDataType:WebGL2RenderingContext.FLOAT,glslDataType:"vec3"};class B extends r.b{constructor(e,t){super(e),this.vertexAttributes=t.vertexAttributes;let n=this.indices=t.indices;this.numVertices=t.numVertices,this.vertexAttributeOffsets=t.vertexAttributeOffsets,this.numIndices=n.length}copyToGPU(e){super.copyToGPU(e);const{attributeTextureFormats:t}=this.source,{vertexAttributes:n,vertexAttributeOffsets:i}=this,r=this.vertexAttributeTextures=[];for(let s=0,o=i.length;s<o;++s){const a=e.createTexture();e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,a),Object(O.f)(e,t[s],n.subarray(i[s],s+1!==o?i[s+1]:n.length)),r[s]=a}e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null),this.indexBuffer=b.a.fromData(e,this.indices,WebGL2RenderingContext.ARRAY_BUFFER,WebGL2RenderingContext.STATIC_DRAW)}freeGPUMemory(e){super.freeGPUMemory(e);const{vertexAttributeTextures:t}=this;for(const n of t)e.deleteTexture(n);t.length=0,this.indexBuffer.dispose()}}const F=new Map;class z extends r.f{constructor(e,t){super(e,t)}get attributeTextureFormats(){let e=this.attributeTextureFormats_;return void 0===e&&(e=this.attributeTextureFormats_=function(e){const t=[M];for(const n of e.values())t.push(Object(O.d)(new O.c,n.dataType,n.numComponents));return t}(this.vertexAttributes)),e}getChunk(e){return new B(this,e)}get vertexAttributes(){return F}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return r})),n.d(t,"b",(function(){return s})),n.d(t,"d",(function(){return o})),n.d(t,"c",(function(){return a}));var i=n(76);
/**
 * @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 r=i.a;function s(e,t){e.addVertexCode(i.c),e.addUniform("highp vec3","uCircleParams"),e.addVarying("highp vec4","vCircleCoord"),e.addVertexCode("\nvoid emitCircle(vec4 position, float diameter, float borderWidth) {\n  gl_Position = position;\n  float totalDiameter = diameter + 2.0 * (borderWidth + uCircleParams.z);\n  vec2 circleCornerOffset = getQuadVertexPosition(vec2(-1.0, -1.0), vec2(1.0, 1.0));\n  gl_Position.xy += circleCornerOffset * uCircleParams.xy * gl_Position.w * totalDiameter;\n  vCircleCoord.xy = circleCornerOffset;\n  vCircleCoord.z = diameter / totalDiameter;\n  vCircleCoord.w = uCircleParams.z / totalDiameter;\n}\n"),t?e.addFragmentCode("\nfloat getCircleAlphaMultiplier() {\n  return 1.0 - 2.0 * abs(0.5 - gl_FragCoord.z);\n}\n"):e.addFragmentCode("\nfloat getCircleAlphaMultiplier() {\n  return 1.0;\n}\n"),e.addFragmentCode("\nvec4 getCircleColor(vec4 interiorColor, vec4 borderColor) {\n  float radius = length(vCircleCoord.xy);\n  if (radius > 1.0) {\n    discard;\n  }\n\n  float borderColorFraction = clamp((radius - vCircleCoord.z) / vCircleCoord.w, 0.0, 1.0);\n  float feather = clamp((1.0 - radius) / vCircleCoord.w, 0.0, 1.0);\n  vec4 color = mix(interiorColor, borderColor, borderColorFraction);\n\n  return vec4(color.rgb, color.a * feather * getCircleAlphaMultiplier());\n}\n")}function o(e,t,n){const{gl:i}=e;i.uniform3f(e.uniform("uCircleParams"),1/t.width,1/t.height,Math.max(1e-6,n.featherWidthInPixels))}function a(e,t,n){Object(i.b)(e,t,n)}},function(e,t,n){"use strict";n.d(t,"c",(function(){return m})),n.d(t,"a",(function(){return y})),n.d(t,"b",(function(){return k}));var i=n(8),r=n(70),s=n(55),o=n(12),a=n(52),c=n(56),l=n(47),d=n(116),u=n(19),h=n(3),p=n(16),f=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};function m(e){let t=0;const{typeToIds:n}=e;for(const e of i.j)t+=Object(s.b)(e).pickIdsPerInstance*n[e].length;return t}class g{constructor(e){this.bufferValid=!1,this.numPickIds=0,this.serializedAnnotations={data:e.data,typeToIds:e.typeToIds,typeToOffset:e.typeToOffset,typeToIdMaps:e.typeToIdMaps}}freeGPUMemory(e){const{buffer:t}=this;void 0!==t&&(t.dispose(),this.bufferValid=!1,this.buffer=void 0)}}class v extends o.b{constructor(e,t){super(e),void 0!==t.data&&(this.data=new g(t))}freeGPUMemory(e){super.freeGPUMemory(e);const{data:t}=this;void 0!==t&&t.freeGPUMemory(e)}dispose(){this.data=void 0}}class b extends c.c{constructor(e,t){super(e,t),void 0!==t.data&&(this.data=new g(t))}freeGPUMemory(e){super.freeGPUMemory(e);const{data:t}=this;void 0!==t&&t.freeGPUMemory(e)}dispose(){this.data=void 0}}let y=class extends c.d{constructor(e,t){super(e,t),this.immediateChunkUpdates=!0,(this.parent=t.parent).spatiallyIndexedSources.add(this);const{rank:n,chunkDataSize:i}=this.spec,r=this.multiscaleToChunkTransform=new Float32Array((n+1)**2);u.g(r,n+1,this.spec.chunkToMultiscaleTransform,n+1,n+1);for(let e=0;e<n;++e)for(let t=0;t<n+1;++t)r[(n+1)*t+e]/=i[e]}disposed(){this.parent.spatiallyIndexedSources.delete(this),super.disposed()}initializeCounterpart(e,t){t.parent=this.parent.rpcId,super.initializeCounterpart(e,t)}addChunk(e,t){super.addChunk(e,t)}getChunk(e){return new b(this,e)}};y=f([Object(p.g)(r.c)],y);let S=class extends o.f{constructor(e,t,n){super(e,{}),this.parent=t,this.relationshipIndex=n,this.immediateChunkUpdates=!0}addChunk(e,t){super.addChunk(e,t)}getChunk(e){return new v(this,e)}};S=f([Object(p.g)(r.k)],S);class w extends o.b{constructor(e,t){super(e),this.annotation=Object(i.k)(t.annotation)}}let x=class extends o.f{constructor(e,t){super(e),this.parent=t}getChunk(e){return new w(this,e)}addChunk(e,t){super.addChunk(e,t);const{references:n}=this.parent,i=n.get(e);void 0!==i&&(i.value=t.annotation,i.changed.dispatch())}deleteChunk(e){const{references:t}=this.parent,n=t.get(e);void 0!==n&&(n.value=void 0,n.changed.dispatch())}};function C(e,t,n){const{rank:r}=n,s=t.type,{serializedAnnotations:o}=e,a=o.typeToIds[s],c=o.typeToIdMaps[s],l=i.i[s],u=l.serializedBytes(r),h=u+n.serializedBytes;let p=c.get(t.id),f=0;if(void 0===p){p=c.size,a.push(t.id),c.set(t.id,p);const e=new Uint8Array(o.data.length+h);f=o.typeToOffset[s]+h*p,e.set(o.data.subarray(0,f),0),e.set(o.data.subarray(f),f+h),o.data=e;for(const e of i.j)e>s&&(o.typeToOffset[e]+=h)}else f=o.typeToOffset[s]+h*p;const m=new DataView(o.data.buffer,o.data.byteOffset,o.data.byteLength);let g=o.typeToOffset[s]+p*h;const v=d.a===d.b.LITTLE;l.serialize(m,g,v,r,t),g+=u,n.serialize(m,g,v,t.properties),e.bufferValid=!1}function O(e,t,n,r){const{serializedAnnotations:s}=e,o=s.typeToIdMaps[t],a=o.get(n);if(void 0===a)return!1;const c=s.typeToIds[t],l=i.i[t],{rank:d}=r,u=l.serializedBytes(d)+r.serializedBytes;c.splice(a,1),o.delete(n);for(let e=a,t=c.length;e<t;++e)o.set(c[e],e);const{typeToOffset:h}=s,p=h[t]+u*a,{data:f}=s,m=new Uint8Array(f.length-u);m.set(f.subarray(0,p),0),m.set(f.subarray(p+u),p),s.data=m;for(const e of i.j)e>t&&(h[e]-=u);return e.bufferValid=!1,!0}x=f([Object(p.g)(r.d)],x);class k extends p.b{constructor(e,t){super(),this.chunkManager=e,this.metadataChunkSource=this.registerDisposer(new x(this.chunkManager,this)),this.spatiallyIndexedSources=new Set,this.temporary=function(){const e=[],t=[],n=[];for(const r of i.j)e[r]=[],t[r]=0,n[r]=new Map;return new b(void 0,{data:new Uint8Array(0),numPickIds:0,typeToOffset:t,typeToIds:e,typeToIdMaps:n})}(),this.references=new Map,this.localUpdates=new Map,this.numCommitsInProgress=0,this.changed=new h.a,this.readonly=!1,this.rank=t.rank,this.properties=t.properties,this.annotationPropertySerializer=new i.a(this.rank,this.properties);const n=this.segmentFilteredSources=[],{relationships:r}=t;this.relationships=r;for(let t=0,i=r.length;t<i;++t)n.push(this.registerDisposer(new S(e,this,t)))}getSources(e){throw new Error("not implemented")}initializeCounterpart(e,t){this.metadataChunkSource.initializeCounterpart(e,{});for(const t of this.segmentFilteredSources)t.initializeCounterpart(e,{});t.segmentFilteredSource=this.segmentFilteredSources.map(e=>e.addCounterpartRef()),t.metadataChunkSource=this.metadataChunkSource.addCounterpartRef(),t.chunkManager=this.chunkManager.rpcId,super.initializeCounterpart(e,t)}add(e,t=!0){e.id=Object(i.m)();const n=new i.b(e.id);return n.value=e,this.references.set(n.id,n),n.registerDisposer(()=>{this.references.delete(n.id)}),this.applyLocalUpdate(n,!1,t,e),n}applyLocalUpdate(e,t,n,i){const{localUpdates:r}=this,{id:s}=e;let o=this.localUpdates.get(s);const a=e.value;if(null==a)throw new Error("Cannot create local update from null annotation");if(void 0===o?(o={type:a.type,reference:e.addRef(),existingAnnotation:t?a:void 0,pendingCommit:void 0,commitInProgress:void 0},r.set(s,o),this.forEachPossibleChunk(a,e=>{const{data:t}=e;void 0!==t&&O(t,a.type,s,this.annotationPropertySerializer)}),null!==i&&C(this.temporary.data,i,this.annotationPropertySerializer)):(null===i?O(this.temporary.data,a.type,a.id,this.annotationPropertySerializer):C(this.temporary.data,i,this.annotationPropertySerializer),e.value=i),n)if(void 0!==o.commitInProgress)o.pendingCommit=i;else{if(null===i&&void 0===o.existingAnnotation)return r.delete(s),void o.reference.dispose();this.sendCommitRequest(o,i)}this.notifyChanged(e.id,i||void 0)}sendCommitRequest(e,t){this.updateCommitsInProgress(1),e.commitInProgress=t,this.rpc.invoke(r.b,{id:this.rpcId,annotationId:e.existingAnnotation&&e.reference.id,newAnnotation:t})}delete(e){this.applyLocalUpdate(e,!0,!0,null)}update(e,t){this.applyLocalUpdate(e,!0,!1,t)}notifyChanged(e,t){const n=this.references.get(e),i=this.metadataChunkSource.chunks.get(e);void 0!==i&&(i.annotation=t||null),void 0!==n&&(n.value=t||null,n.changed.dispatch()),this.chunkManager.chunkQueueManager.visibleChunksChanged.dispatch()}commit(e){this.applyLocalUpdate(e,!0,!0,e.value)}getReference(e){let t=this.references.get(e);if(void 0!==t)return t.addRef();t=new i.b(e),this.references.set(e,t),this.rpc.invoke(r.f,{id:this.rpcId,annotation:e}),t.registerDisposer(()=>{this.references.delete(e),this.rpc.invoke(r.g,{id:this.rpcId,annotation:e})});const n=this.metadataChunkSource.chunks.get(e);return void 0!==n&&(t.value=n.annotation),t}forEachPossibleChunk(e,t){const{relatedSegments:n}=e;if(void 0!==n){const e=n.length,{segmentFilteredSources:i}=this;for(let r=0;r<e;++r){const e=n[r];if(void 0===e)return;const s=i[r];for(const n of e){const e=s.chunks.get(Object(a.b)(n));void 0!==e&&t(e)}}}const{rank:r}=this,s=new Float32Array(r),o=new Float32Array(r),c=new Float32Array(r);for(const n of this.spatiallyIndexedSources){switch(e.type){case i.e.POINT:u.j(s,n.multiscaleToChunkTransform,r+1,e.point,r),o.set(s);break;case i.e.LINE:case i.e.AXIS_ALIGNED_BOUNDING_BOX:u.j(s,n.multiscaleToChunkTransform,r+1,e.pointA,r),u.j(o,n.multiscaleToChunkTransform,r+1,e.pointB,r);break;case i.e.ELLIPSOID:u.j(s,n.multiscaleToChunkTransform,r+1,e.center,r),u.k(o,n.multiscaleToChunkTransform,r+1,e.radii,r);for(let e=0;e<r;++e){const t=s[e],n=o[e];s[e]=t-n,o[e]=t+n}}let a=1;for(let e=0;e<r;++e){const t=s[e],n=o[e],i=Math.min(t,n),r=Math.max(t,n);s[e]=Math.ceil(i-1),o[e]=Math.floor(r+1),a*=o[e]-s[e]}const{chunks:l}=n;for(let e=0;e<a;++e){let n=e;for(let e=0;e<r;++e){const t=s[e],i=o[e]-t;n=(n-(c[e]=n%i))/i}const i=l.get(c.join());void 0!==i&&t(i)}}}static encodeOptions(e){return{}}handleSuccessfulUpdate(e,t){const n=this.localUpdates.get(e);if(void 0===n||void 0===n.commitInProgress)throw new Error("Received invalid successful update notification");if(this.updateCommitsInProgress(-1),null!==t&&n.reference.id!==t.id){if(null===n.commitInProgress)throw new Error("Received invalid successful update notification");n.reference.id=t.id,this.references.delete(e),this.references.set(t.id,n.reference),this.localUpdates.delete(e),this.localUpdates.set(t.id,n),null!==n.reference.value&&(n.reference.value.id=t.id,O(this.temporary.data,n.type,e,this.annotationPropertySerializer),C(this.temporary.data,n.reference.value,this.annotationPropertySerializer)),n.reference.changed.dispatch()}n.existingAnnotation=t||void 0,n.commitInProgress=void 0;let{pendingCommit:i}=n;n.pendingCommit=void 0,null===t&&(i=void 0),void 0!==i?(null!==i&&(i.id=t.id),this.sendCommitRequest(n,i)):this.revertLocalUpdate(n)}disposed(){const{commitStatus:e}=this;void 0!==e&&e.dispose()}updateCommitsInProgress(e){if(this.numCommitsInProgress+=e,0===this.numCommitsInProgress)void 0!==this.commitStatus&&(this.commitStatus.dispose(),this.commitStatus=void 0);else if(void 0===this.commitStatus){(this.commitStatus=new l.a(!0)).setText("Commiting annotations")}}handleFailedUpdate(e,t){const n=this.localUpdates.get(e);if(void 0===n||void 0===n.commitInProgress)throw new Error("Received invalid update notification");(new l.a).setErrorMessage(`Error commiting annotation update: ${t}`),this.revertLocalUpdate(n),this.updateCommitsInProgress(-1)}revertLocalUpdate(e){O(this.temporary.data,e.type,e.reference.id,this.annotationPropertySerializer);const{existingAnnotation:t}=e;void 0!==t&&this.forEachPossibleChunk(t,e=>{const{data:n}=e;void 0!==n&&C(n,t,this.annotationPropertySerializer)});const{reference:n}=e,{id:i}=n;n.value=t||null,n.changed.dispatch(),n.dispose(),this.localUpdates.delete(i)}*[Symbol.iterator](){}}Object(p.e)(r.a,(function(e){const t=this.get(e.id),n=e.annotationId,r=e.error;if(void 0!==r)t.handleFailedUpdate(n,r);else{const r=Object(i.k)(e.newAnnotation);t.handleSuccessfulUpdate(n,r)}}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(175),r=n.n(i),s=n(27);
/**
 * @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 o(e={}){return Object(s.a)(Object.assign({svg:r.a},e))}},function(e,t,n){"use strict";n.d(t,"a",(function(){return a}));var i=n(30),r=n(2),s=n(6),o=n(31);
/**
 * @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 a extends r.a{constructor(e,t,n=new o.b(o.b.VISIBLE)){super(),this.model=e,this.render=t,this.visibility=n,this.element=document.createElement("div"),this.generation=-1,this.currentViewDisposer=void 0,this.element.style.display="contents";const r=this.registerCancellable(Object(i.a)(()=>this.updateView()));this.registerDisposer(e.changed.add(r)),this.registerDisposer(n.changed.add(()=>{this.visible&&r()})),this.updateView()}get visible(){return this.visibility.visible}updateView(){if(!this.visible)return;const{model:e}=this;if(e.changed.count===this.generation)return;this.disposeCurrentView();const t=this.currentViewDisposer=new r.a;this.render(e.value,this.element,t)}disposeCurrentView(){let{currentViewDisposer:e}=this;void 0!==e&&e.dispose(),Object(s.b)(this.element)}disposed(){this.disposeCurrentView(),super.disposed()}}},function(e,t,n){"use strict";var i=n(33),r=n(161);function s(){r.call(this)}i(s,r),s.prototype.removeAllListeners=function(e){e?delete this._listeners[e]:this._listeners={}},s.prototype.once=function(e,t){var n=this,i=!1;this.on(e,(function r(){n.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}))},s.prototype.emit=function(){var e=arguments[0],t=this._listeners[e];if(t){for(var n=arguments.length,i=new Array(n-1),r=1;r<n;r++)i[r-1]=arguments[r];for(var s=0;s<t.length;s++)t[s].apply(this,i)}},s.prototype.on=s.prototype.addListener=r.prototype.addEventListener,s.prototype.removeListener=r.prototype.removeEventListener,e.exports.EventEmitter=s},function(e,t,n){e.exports=function(){"use strict";var e=navigator.userAgent,t=navigator.platform,n=/gecko\/\d/i.test(e),i=/MSIE \d/.test(e),r=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),s=/Edge\/(\d+)/.exec(e),o=i||r||s,a=o&&(i?document.documentMode||6:+(s||r)[1]),c=!s&&/WebKit\//.test(e),l=c&&/Qt\/\d+\.\d+/.test(e),d=!s&&/Chrome\//.test(e),u=/Opera\//.test(e),h=/Apple Computer/.test(navigator.vendor),p=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),f=/PhantomJS/.test(e),m=!s&&/AppleWebKit/.test(e)&&/Mobile\/\w+/.test(e),g=/Android/.test(e),v=m||g||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),b=m||/Mac/.test(t),y=/\bCrOS\b/.test(e),S=/win/i.test(t),w=u&&e.match(/Version\/(\d*\.\d*)/);w&&(w=Number(w[1])),w&&w>=15&&(u=!1,c=!0);var x=b&&(l||u&&(null==w||w<12.11)),C=n||o&&a>=9;function O(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}var k,E=function(e,t){var n=e.className,i=O(t).exec(n);if(i){var r=n.slice(i.index+i[0].length);e.className=n.slice(0,i.index)+(r?i[1]+r:"")}};function T(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function M(e,t){return T(e).appendChild(t)}function D(e,t,n,i){var r=document.createElement(e);if(n&&(r.className=n),i&&(r.style.cssText=i),"string"==typeof t)r.appendChild(document.createTextNode(t));else if(t)for(var s=0;s<t.length;++s)r.appendChild(t[s]);return r}function L(e,t,n,i){var r=D(e,t,n,i);return r.setAttribute("role","presentation"),r}function j(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do{if(11==t.nodeType&&(t=t.host),t==e)return!0}while(t=t.parentNode)}function I(){var e;try{e=document.activeElement}catch(t){e=document.body||null}for(;e&&e.shadowRoot&&e.shadowRoot.activeElement;)e=e.shadowRoot.activeElement;return e}function P(e,t){var n=e.className;O(t).test(n)||(e.className+=(n?" ":"")+t)}function A(e,t){for(var n=e.split(" "),i=0;i<n.length;i++)n[i]&&!O(n[i]).test(t)&&(t+=" "+n[i]);return t}k=document.createRange?function(e,t,n,i){var r=document.createRange();return r.setEnd(i||e,n),r.setStart(e,t),r}:function(e,t,n){var i=document.body.createTextRange();try{i.moveToElementText(e.parentNode)}catch(e){return i}return i.collapse(!0),i.moveEnd("character",n),i.moveStart("character",t),i};var R=function(e){e.select()};function N(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function V(e,t,n){for(var i in t||(t={}),e)!e.hasOwnProperty(i)||!1===n&&t.hasOwnProperty(i)||(t[i]=e[i]);return t}function _(e,t,n,i,r){null==t&&-1==(t=e.search(/[^\s\u00a0]/))&&(t=e.length);for(var s=i||0,o=r||0;;){var a=e.indexOf("\t",s);if(a<0||a>=t)return o+(t-s);o+=a-s,o+=n-o%n,s=a+1}}m?R=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(R=function(e){try{e.select()}catch(e){}});var B=function(){this.id=null,this.f=null,this.time=0,this.handler=N(this.onTimeout,this)};function F(e,t){for(var n=0;n<e.length;++n)if(e[n]==t)return n;return-1}B.prototype.onTimeout=function(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)},B.prototype.set=function(e,t){this.f=t;var n=+new Date+e;(!this.id||n<this.time)&&(clearTimeout(this.id),this.id=setTimeout(this.handler,e),this.time=n)};var z={toString:function(){return"CodeMirror.Pass"}},U={scroll:!1},G={origin:"*mouse"},$={origin:"+move"};function W(e,t,n){for(var i=0,r=0;;){var s=e.indexOf("\t",i);-1==s&&(s=e.length);var o=s-i;if(s==e.length||r+o>=t)return i+Math.min(o,t-r);if(r+=s-i,i=s+1,(r+=n-r%n)>=t)return i}}var H=[""];function J(e){for(;H.length<=e;)H.push(q(H)+" ");return H[e]}function q(e){return e[e.length-1]}function Y(e,t){for(var n=[],i=0;i<e.length;i++)n[i]=t(e[i],i);return n}function X(){}function K(e,t){var n;return Object.create?n=Object.create(e):(X.prototype=e,n=new X),t&&V(t,n),n}var Q=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function Z(e){return/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||Q.test(e))}function ee(e,t){return t?!!(t.source.indexOf("\\w")>-1&&Z(e))||t.test(e):Z(e)}function te(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}var ne=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;function ie(e){return e.charCodeAt(0)>=768&&ne.test(e)}function re(e,t,n){for(;(n<0?t>0:t<e.length)&&ie(e.charAt(t));)t+=n;return t}function se(e,t,n){for(var i=t>n?-1:1;;){if(t==n)return t;var r=(t+n)/2,s=i<0?Math.ceil(r):Math.floor(r);if(s==t)return e(s)?t:n;e(s)?n=s:t=s+i}}var oe=null;function ae(e,t,n){var i;oe=null;for(var r=0;r<e.length;++r){var s=e[r];if(s.from<t&&s.to>t)return r;s.to==t&&(s.from!=s.to&&"before"==n?i=r:oe=r),s.from==t&&(s.from!=s.to&&"before"!=n?i=r:oe=r)}return null!=i?i:oe}var ce=function(){var e=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,t=/[stwN]/,n=/[LRr]/,i=/[Lb1n]/,r=/[1n]/;function s(e,t,n){this.level=e,this.from=t,this.to=n}return function(o,a){var c="ltr"==a?"L":"R";if(0==o.length||"ltr"==a&&!e.test(o))return!1;for(var l,d=o.length,u=[],h=0;h<d;++h)u.push((l=o.charCodeAt(h))<=247?"bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN".charAt(l):1424<=l&&l<=1524?"R":1536<=l&&l<=1785?"nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111".charAt(l-1536):1774<=l&&l<=2220?"r":8192<=l&&l<=8203?"w":8204==l?"b":"L");for(var p=0,f=c;p<d;++p){var m=u[p];"m"==m?u[p]=f:f=m}for(var g=0,v=c;g<d;++g){var b=u[g];"1"==b&&"r"==v?u[g]="n":n.test(b)&&(v=b,"r"==b&&(u[g]="R"))}for(var y=1,S=u[0];y<d-1;++y){var w=u[y];"+"==w&&"1"==S&&"1"==u[y+1]?u[y]="1":","!=w||S!=u[y+1]||"1"!=S&&"n"!=S||(u[y]=S),S=w}for(var x=0;x<d;++x){var C=u[x];if(","==C)u[x]="N";else if("%"==C){var O=void 0;for(O=x+1;O<d&&"%"==u[O];++O);for(var k=x&&"!"==u[x-1]||O<d&&"1"==u[O]?"1":"N",E=x;E<O;++E)u[E]=k;x=O-1}}for(var T=0,M=c;T<d;++T){var D=u[T];"L"==M&&"1"==D?u[T]="L":n.test(D)&&(M=D)}for(var L=0;L<d;++L)if(t.test(u[L])){var j=void 0;for(j=L+1;j<d&&t.test(u[j]);++j);for(var I="L"==(L?u[L-1]:c),P=I==("L"==(j<d?u[j]:c))?I?"L":"R":c,A=L;A<j;++A)u[A]=P;L=j-1}for(var R,N=[],V=0;V<d;)if(i.test(u[V])){var _=V;for(++V;V<d&&i.test(u[V]);++V);N.push(new s(0,_,V))}else{var B=V,F=N.length;for(++V;V<d&&"L"!=u[V];++V);for(var z=B;z<V;)if(r.test(u[z])){B<z&&N.splice(F,0,new s(1,B,z));var U=z;for(++z;z<V&&r.test(u[z]);++z);N.splice(F,0,new s(2,U,z)),B=z}else++z;B<V&&N.splice(F,0,new s(1,B,V))}return"ltr"==a&&(1==N[0].level&&(R=o.match(/^\s+/))&&(N[0].from=R[0].length,N.unshift(new s(0,0,R[0].length))),1==q(N).level&&(R=o.match(/\s+$/))&&(q(N).to-=R[0].length,N.push(new s(0,d-R[0].length,d)))),"rtl"==a?N.reverse():N}}();function le(e,t){var n=e.order;return null==n&&(n=e.order=ce(e.text,t)),n}var de=[],ue=function(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else if(e.attachEvent)e.attachEvent("on"+t,n);else{var i=e._handlers||(e._handlers={});i[t]=(i[t]||de).concat(n)}};function he(e,t){return e._handlers&&e._handlers[t]||de}function pe(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent("on"+t,n);else{var i=e._handlers,r=i&&i[t];if(r){var s=F(r,n);s>-1&&(i[t]=r.slice(0,s).concat(r.slice(s+1)))}}}function fe(e,t){var n=he(e,t);if(n.length)for(var i=Array.prototype.slice.call(arguments,2),r=0;r<n.length;++r)n[r].apply(null,i)}function me(e,t,n){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),fe(e,n||t.type,e,t),we(t)||t.codemirrorIgnore}function ge(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var n=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),i=0;i<t.length;++i)-1==F(n,t[i])&&n.push(t[i])}function ve(e,t){return he(e,t).length>0}function be(e){e.prototype.on=function(e,t){ue(this,e,t)},e.prototype.off=function(e,t){pe(this,e,t)}}function ye(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function Se(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function we(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function xe(e){ye(e),Se(e)}function Ce(e){return e.target||e.srcElement}function Oe(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),b&&e.ctrlKey&&1==t&&(t=3),t}var ke,Ee,Te=function(){if(o&&a<9)return!1;var e=D("div");return"draggable"in e||"dragDrop"in e}();function Me(e){if(null==ke){var t=D("span","​");M(e,D("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(ke=t.offsetWidth<=1&&t.offsetHeight>2&&!(o&&a<8))}var n=ke?D("span","​"):D("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return n.setAttribute("cm-text",""),n}function De(e){if(null!=Ee)return Ee;var t=M(e,document.createTextNode("AخA")),n=k(t,0,1).getBoundingClientRect(),i=k(t,1,2).getBoundingClientRect();return T(e),!(!n||n.left==n.right)&&(Ee=i.right-n.right<3)}var Le,je=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,n=[],i=e.length;t<=i;){var r=e.indexOf("\n",t);-1==r&&(r=e.length);var s=e.slice(t,"\r"==e.charAt(r-1)?r-1:r),o=s.indexOf("\r");-1!=o?(n.push(s.slice(0,o)),t+=o+1):(n.push(s),t=r+1)}return n}:function(e){return e.split(/\r\n?|\n/)},Ie=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){var t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},Pe="oncopy"in(Le=D("div"))||(Le.setAttribute("oncopy","return;"),"function"==typeof Le.oncopy),Ae=null,Re={},Ne={};function Ve(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Re[e]=t}function _e(e){if("string"==typeof e&&Ne.hasOwnProperty(e))e=Ne[e];else if(e&&"string"==typeof e.name&&Ne.hasOwnProperty(e.name)){var t=Ne[e.name];"string"==typeof t&&(t={name:t}),(e=K(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return _e("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return _e("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Be(e,t){t=_e(t);var n=Re[t.name];if(!n)return Be(e,"text/plain");var i=n(e,t);if(Fe.hasOwnProperty(t.name)){var r=Fe[t.name];for(var s in r)r.hasOwnProperty(s)&&(i.hasOwnProperty(s)&&(i["_"+s]=i[s]),i[s]=r[s])}if(i.name=t.name,t.helperType&&(i.helperType=t.helperType),t.modeProps)for(var o in t.modeProps)i[o]=t.modeProps[o];return i}var Fe={};function ze(e,t){V(t,Fe.hasOwnProperty(e)?Fe[e]:Fe[e]={})}function Ue(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var n={};for(var i in t){var r=t[i];r instanceof Array&&(r=r.concat([])),n[i]=r}return n}function Ge(e,t){for(var n;e.innerMode&&(n=e.innerMode(t))&&n.mode!=e;)t=n.state,e=n.mode;return n||{mode:e,state:t}}function $e(e,t,n){return!e.startState||e.startState(t,n)}var We=function(e,t,n){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0,this.lineOracle=n};function He(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var n=e;!n.lines;)for(var i=0;;++i){var r=n.children[i],s=r.chunkSize();if(t<s){n=r;break}t-=s}return n.lines[t]}function Je(e,t,n){var i=[],r=t.line;return e.iter(t.line,n.line+1,(function(e){var s=e.text;r==n.line&&(s=s.slice(0,n.ch)),r==t.line&&(s=s.slice(t.ch)),i.push(s),++r})),i}function qe(e,t,n){var i=[];return e.iter(t,n,(function(e){i.push(e.text)})),i}function Ye(e,t){var n=t-e.height;if(n)for(var i=e;i;i=i.parent)i.height+=n}function Xe(e){if(null==e.parent)return null;for(var t=e.parent,n=F(t.lines,e),i=t.parent;i;t=i,i=i.parent)for(var r=0;i.children[r]!=t;++r)n+=i.children[r].chunkSize();return n+t.first}function Ke(e,t){var n=e.first;e:do{for(var i=0;i<e.children.length;++i){var r=e.children[i],s=r.height;if(t<s){e=r;continue e}t-=s,n+=r.chunkSize()}return n}while(!e.lines);for(var o=0;o<e.lines.length;++o){var a=e.lines[o].height;if(t<a)break;t-=a}return n+o}function Qe(e,t){return t>=e.first&&t<e.first+e.size}function Ze(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function et(e,t,n){if(void 0===n&&(n=null),!(this instanceof et))return new et(e,t,n);this.line=e,this.ch=t,this.sticky=n}function tt(e,t){return e.line-t.line||e.ch-t.ch}function nt(e,t){return e.sticky==t.sticky&&0==tt(e,t)}function it(e){return et(e.line,e.ch)}function rt(e,t){return tt(e,t)<0?t:e}function st(e,t){return tt(e,t)<0?e:t}function ot(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function at(e,t){if(t.line<e.first)return et(e.first,0);var n=e.first+e.size-1;return t.line>n?et(n,He(e,n).text.length):function(e,t){var n=e.ch;return null==n||n>t?et(e.line,t):n<0?et(e.line,0):e}(t,He(e,t.line).text.length)}function ct(e,t){for(var n=[],i=0;i<t.length;i++)n[i]=at(e,t[i]);return n}We.prototype.eol=function(){return this.pos>=this.string.length},We.prototype.sol=function(){return this.pos==this.lineStart},We.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},We.prototype.next=function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},We.prototype.eat=function(e){var t=this.string.charAt(this.pos);if("string"==typeof e?t==e:t&&(e.test?e.test(t):e(t)))return++this.pos,t},We.prototype.eatWhile=function(e){for(var t=this.pos;this.eat(e););return this.pos>t},We.prototype.eatSpace=function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},We.prototype.skipToEnd=function(){this.pos=this.string.length},We.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},We.prototype.backUp=function(e){this.pos-=e},We.prototype.column=function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=_(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?_(this.string,this.lineStart,this.tabSize):0)},We.prototype.indentation=function(){return _(this.string,null,this.tabSize)-(this.lineStart?_(this.string,this.lineStart,this.tabSize):0)},We.prototype.match=function(e,t,n){if("string"!=typeof e){var i=this.string.slice(this.pos).match(e);return i&&i.index>0?null:(i&&!1!==t&&(this.pos+=i[0].length),i)}var r=function(e){return n?e.toLowerCase():e};if(r(this.string.substr(this.pos,e.length))==r(e))return!1!==t&&(this.pos+=e.length),!0},We.prototype.current=function(){return this.string.slice(this.start,this.pos)},We.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}},We.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)},We.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var lt=function(e,t){this.state=e,this.lookAhead=t},dt=function(e,t,n,i){this.state=t,this.doc=e,this.line=n,this.maxLookAhead=i||0,this.baseTokens=null,this.baseTokenPos=1};function ut(e,t,n,i){var r=[e.state.modeGen],s={};St(e,t.text,e.doc.mode,n,(function(e,t){return r.push(e,t)}),s,i);for(var o=n.state,a=function(i){n.baseTokens=r;var a=e.state.overlays[i],c=1,l=0;n.state=!0,St(e,t.text,a.mode,n,(function(e,t){for(var n=c;l<e;){var i=r[c];i>e&&r.splice(c,1,e,r[c+1],i),c+=2,l=Math.min(e,i)}if(t)if(a.opaque)r.splice(n,c-n,e,"overlay "+t),c=n+2;else for(;n<c;n+=2){var s=r[n+1];r[n+1]=(s?s+" ":"")+"overlay "+t}}),s),n.state=o,n.baseTokens=null,n.baseTokenPos=1},c=0;c<e.state.overlays.length;++c)a(c);return{styles:r,classes:s.bgClass||s.textClass?s:null}}function ht(e,t,n){if(!t.styles||t.styles[0]!=e.state.modeGen){var i=pt(e,Xe(t)),r=t.text.length>e.options.maxHighlightLength&&Ue(e.doc.mode,i.state),s=ut(e,t,i);r&&(i.state=r),t.stateAfter=i.save(!r),t.styles=s.styles,s.classes?t.styleClasses=s.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))}return t.styles}function pt(e,t,n){var i=e.doc,r=e.display;if(!i.mode.startState)return new dt(i,!0,t);var s=function(e,t,n){for(var i,r,s=e.doc,o=n?-1:t-(e.doc.mode.innerMode?1e3:100),a=t;a>o;--a){if(a<=s.first)return s.first;var c=He(s,a-1),l=c.stateAfter;if(l&&(!n||a+(l instanceof lt?l.lookAhead:0)<=s.modeFrontier))return a;var d=_(c.text,null,e.options.tabSize);(null==r||i>d)&&(r=a-1,i=d)}return r}(e,t,n),o=s>i.first&&He(i,s-1).stateAfter,a=o?dt.fromSaved(i,o,s):new dt(i,$e(i.mode),s);return i.iter(s,t,(function(n){ft(e,n.text,a);var i=a.line;n.stateAfter=i==t-1||i%5==0||i>=r.viewFrom&&i<r.viewTo?a.save():null,a.nextLine()})),n&&(i.modeFrontier=a.line),a}function ft(e,t,n,i){var r=e.doc.mode,s=new We(t,e.options.tabSize,n);for(s.start=s.pos=i||0,""==t&&mt(r,n.state);!s.eol();)gt(r,s,n.state),s.start=s.pos}function mt(e,t){if(e.blankLine)return e.blankLine(t);if(e.innerMode){var n=Ge(e,t);return n.mode.blankLine?n.mode.blankLine(n.state):void 0}}function gt(e,t,n,i){for(var r=0;r<10;r++){i&&(i[0]=Ge(e,n).mode);var s=e.token(t,n);if(t.pos>t.start)return s}throw new Error("Mode "+e.name+" failed to advance stream.")}dt.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},dt.prototype.baseToken=function(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},dt.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},dt.fromSaved=function(e,t,n){return t instanceof lt?new dt(e,Ue(e.mode,t.state),n,t.lookAhead):new dt(e,Ue(e.mode,t),n)},dt.prototype.save=function(e){var t=!1!==e?Ue(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new lt(t,this.maxLookAhead):t};var vt=function(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n};function bt(e,t,n,i){var r,s,o=e.doc,a=o.mode,c=He(o,(t=at(o,t)).line),l=pt(e,t.line,n),d=new We(c.text,e.options.tabSize,l);for(i&&(s=[]);(i||d.pos<t.ch)&&!d.eol();)d.start=d.pos,r=gt(a,d,l.state),i&&s.push(new vt(d,r,Ue(o.mode,l.state)));return i?s:new vt(d,r,l.state)}function yt(e,t){if(e)for(;;){var n=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!n)break;e=e.slice(0,n.index)+e.slice(n.index+n[0].length);var i=n[1]?"bgClass":"textClass";null==t[i]?t[i]=n[2]:new RegExp("(?:^|s)"+n[2]+"(?:$|s)").test(t[i])||(t[i]+=" "+n[2])}return e}function St(e,t,n,i,r,s,o){var a=n.flattenSpans;null==a&&(a=e.options.flattenSpans);var c,l=0,d=null,u=new We(t,e.options.tabSize,i),h=e.options.addModeClass&&[null];for(""==t&&yt(mt(n,i.state),s);!u.eol();){if(u.pos>e.options.maxHighlightLength?(a=!1,o&&ft(e,t,i,u.pos),u.pos=t.length,c=null):c=yt(gt(n,u,i.state,h),s),h){var p=h[0].name;p&&(c="m-"+(c?p+" "+c:p))}if(!a||d!=c){for(;l<u.start;)r(l=Math.min(u.start,l+5e3),d);d=c}u.start=u.pos}for(;l<u.pos;){var f=Math.min(u.pos,l+5e3);r(f,d),l=f}}var wt=!1,xt=!1;function Ct(e,t,n){this.marker=e,this.from=t,this.to=n}function Ot(e,t){if(e)for(var n=0;n<e.length;++n){var i=e[n];if(i.marker==t)return i}}function kt(e,t){for(var n,i=0;i<e.length;++i)e[i]!=t&&(n||(n=[])).push(e[i]);return n}function Et(e,t){if(t.full)return null;var n=Qe(e,t.from.line)&&He(e,t.from.line).markedSpans,i=Qe(e,t.to.line)&&He(e,t.to.line).markedSpans;if(!n&&!i)return null;var r=t.from.ch,s=t.to.ch,o=0==tt(t.from,t.to),a=function(e,t,n){var i;if(e)for(var r=0;r<e.length;++r){var s=e[r],o=s.marker;if(null==s.from||(o.inclusiveLeft?s.from<=t:s.from<t)||s.from==t&&"bookmark"==o.type&&(!n||!s.marker.insertLeft)){var a=null==s.to||(o.inclusiveRight?s.to>=t:s.to>t);(i||(i=[])).push(new Ct(o,s.from,a?null:s.to))}}return i}(n,r,o),c=function(e,t,n){var i;if(e)for(var r=0;r<e.length;++r){var s=e[r],o=s.marker;if(null==s.to||(o.inclusiveRight?s.to>=t:s.to>t)||s.from==t&&"bookmark"==o.type&&(!n||s.marker.insertLeft)){var a=null==s.from||(o.inclusiveLeft?s.from<=t:s.from<t);(i||(i=[])).push(new Ct(o,a?null:s.from-t,null==s.to?null:s.to-t))}}return i}(i,s,o),l=1==t.text.length,d=q(t.text).length+(l?r:0);if(a)for(var u=0;u<a.length;++u){var h=a[u];if(null==h.to){var p=Ot(c,h.marker);p?l&&(h.to=null==p.to?null:p.to+d):h.to=r}}if(c)for(var f=0;f<c.length;++f){var m=c[f];null!=m.to&&(m.to+=d),null==m.from?Ot(a,m.marker)||(m.from=d,l&&(a||(a=[])).push(m)):(m.from+=d,l&&(a||(a=[])).push(m))}a&&(a=Tt(a)),c&&c!=a&&(c=Tt(c));var g=[a];if(!l){var v,b=t.text.length-2;if(b>0&&a)for(var y=0;y<a.length;++y)null==a[y].to&&(v||(v=[])).push(new Ct(a[y].marker,null,null));for(var S=0;S<b;++S)g.push(v);g.push(c)}return g}function Tt(e){for(var t=0;t<e.length;++t){var n=e[t];null!=n.from&&n.from==n.to&&!1!==n.marker.clearWhenEmpty&&e.splice(t--,1)}return e.length?e:null}function Mt(e){var t=e.markedSpans;if(t){for(var n=0;n<t.length;++n)t[n].marker.detachLine(e);e.markedSpans=null}}function Dt(e,t){if(t){for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}}function Lt(e){return e.inclusiveLeft?-1:0}function jt(e){return e.inclusiveRight?1:0}function It(e,t){var n=e.lines.length-t.lines.length;if(0!=n)return n;var i=e.find(),r=t.find(),s=tt(i.from,r.from)||Lt(e)-Lt(t);if(s)return-s;var o=tt(i.to,r.to)||jt(e)-jt(t);return o||t.id-e.id}function Pt(e,t){var n,i=xt&&e.markedSpans;if(i)for(var r=void 0,s=0;s<i.length;++s)(r=i[s]).marker.collapsed&&null==(t?r.from:r.to)&&(!n||It(n,r.marker)<0)&&(n=r.marker);return n}function At(e){return Pt(e,!0)}function Rt(e){return Pt(e,!1)}function Nt(e,t){var n,i=xt&&e.markedSpans;if(i)for(var r=0;r<i.length;++r){var s=i[r];s.marker.collapsed&&(null==s.from||s.from<t)&&(null==s.to||s.to>t)&&(!n||It(n,s.marker)<0)&&(n=s.marker)}return n}function Vt(e,t,n,i,r){var s=He(e,t),o=xt&&s.markedSpans;if(o)for(var a=0;a<o.length;++a){var c=o[a];if(c.marker.collapsed){var l=c.marker.find(0),d=tt(l.from,n)||Lt(c.marker)-Lt(r),u=tt(l.to,i)||jt(c.marker)-jt(r);if(!(d>=0&&u<=0||d<=0&&u>=0)&&(d<=0&&(c.marker.inclusiveRight&&r.inclusiveLeft?tt(l.to,n)>=0:tt(l.to,n)>0)||d>=0&&(c.marker.inclusiveRight&&r.inclusiveLeft?tt(l.from,i)<=0:tt(l.from,i)<0)))return!0}}}function _t(e){for(var t;t=At(e);)e=t.find(-1,!0).line;return e}function Bt(e,t){var n=He(e,t),i=_t(n);return n==i?t:Xe(i)}function Ft(e,t){if(t>e.lastLine())return t;var n,i=He(e,t);if(!zt(e,i))return t;for(;n=Rt(i);)i=n.find(1,!0).line;return Xe(i)+1}function zt(e,t){var n=xt&&t.markedSpans;if(n)for(var i=void 0,r=0;r<n.length;++r)if((i=n[r]).marker.collapsed){if(null==i.from)return!0;if(!i.marker.widgetNode&&0==i.from&&i.marker.inclusiveLeft&&Ut(e,t,i))return!0}}function Ut(e,t,n){if(null==n.to){var i=n.marker.find(1,!0);return Ut(e,i.line,Ot(i.line.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var r=void 0,s=0;s<t.markedSpans.length;++s)if((r=t.markedSpans[s]).marker.collapsed&&!r.marker.widgetNode&&r.from==n.to&&(null==r.to||r.to!=n.from)&&(r.marker.inclusiveLeft||n.marker.inclusiveRight)&&Ut(e,t,r))return!0}function Gt(e){for(var t=0,n=(e=_t(e)).parent,i=0;i<n.lines.length;++i){var r=n.lines[i];if(r==e)break;t+=r.height}for(var s=n.parent;s;s=(n=s).parent)for(var o=0;o<s.children.length;++o){var a=s.children[o];if(a==n)break;t+=a.height}return t}function $t(e){if(0==e.height)return 0;for(var t,n=e.text.length,i=e;t=At(i);){var r=t.find(0,!0);i=r.from.line,n+=r.from.ch-r.to.ch}for(i=e;t=Rt(i);){var s=t.find(0,!0);n-=i.text.length-s.from.ch,n+=(i=s.to.line).text.length-s.to.ch}return n}function Wt(e){var t=e.display,n=e.doc;t.maxLine=He(n,n.first),t.maxLineLength=$t(t.maxLine),t.maxLineChanged=!0,n.iter((function(e){var n=$t(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)}))}var Ht=function(e,t,n){this.text=e,Dt(this,t),this.height=n?n(this):1};function Jt(e){e.parent=null,Mt(e)}Ht.prototype.lineNo=function(){return Xe(this)},be(Ht);var qt={},Yt={};function Xt(e,t){if(!e||/^\s*$/.test(e))return null;var n=t.addModeClass?Yt:qt;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function Kt(e,t){var n=L("span",null,null,c?"padding-right: .1px":null),i={pre:L("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(var r=0;r<=(t.rest?t.rest.length:0);r++){var s=r?t.rest[r-1]:t.line,o=void 0;i.pos=0,i.addToken=Zt,De(e.display.measure)&&(o=le(s,e.doc.direction))&&(i.addToken=en(i.addToken,o)),i.map=[],nn(s,i,ht(e,s,t!=e.display.externalMeasured&&Xe(s))),s.styleClasses&&(s.styleClasses.bgClass&&(i.bgClass=A(s.styleClasses.bgClass,i.bgClass||"")),s.styleClasses.textClass&&(i.textClass=A(s.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(Me(e.display.measure))),0==r?(t.measure.map=i.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(i.map),(t.measure.caches||(t.measure.caches=[])).push({}))}if(c){var a=i.content.lastChild;(/\bcm-tab\b/.test(a.className)||a.querySelector&&a.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return fe(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=A(i.pre.className,i.textClass||"")),i}function Qt(e){var t=D("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Zt(e,t,n,i,r,s,c){if(t){var l,d=e.splitSpaces?function(e,t){if(e.length>1&&!/  /.test(e))return e;for(var n=t,i="",r=0;r<e.length;r++){var s=e.charAt(r);" "!=s||!n||r!=e.length-1&&32!=e.charCodeAt(r+1)||(s=" "),i+=s,n=" "==s}return i}(t,e.trailingSpace):t,u=e.cm.state.specialChars,h=!1;if(u.test(t)){l=document.createDocumentFragment();for(var p=0;;){u.lastIndex=p;var f=u.exec(t),m=f?f.index-p:t.length-p;if(m){var g=document.createTextNode(d.slice(p,p+m));o&&a<9?l.appendChild(D("span",[g])):l.appendChild(g),e.map.push(e.pos,e.pos+m,g),e.col+=m,e.pos+=m}if(!f)break;p+=m+1;var v=void 0;if("\t"==f[0]){var b=e.cm.options.tabSize,y=b-e.col%b;(v=l.appendChild(D("span",J(y),"cm-tab"))).setAttribute("role","presentation"),v.setAttribute("cm-text","\t"),e.col+=y}else"\r"==f[0]||"\n"==f[0]?((v=l.appendChild(D("span","\r"==f[0]?"␍":"␤","cm-invalidchar"))).setAttribute("cm-text",f[0]),e.col+=1):((v=e.cm.options.specialCharPlaceholder(f[0])).setAttribute("cm-text",f[0]),o&&a<9?l.appendChild(D("span",[v])):l.appendChild(v),e.col+=1);e.map.push(e.pos,e.pos+1,v),e.pos++}}else e.col+=t.length,l=document.createTextNode(d),e.map.push(e.pos,e.pos+t.length,l),o&&a<9&&(h=!0),e.pos+=t.length;if(e.trailingSpace=32==d.charCodeAt(t.length-1),n||i||r||h||s){var S=n||"";i&&(S+=i),r&&(S+=r);var w=D("span",[l],S,s);if(c)for(var x in c)c.hasOwnProperty(x)&&"style"!=x&&"class"!=x&&w.setAttribute(x,c[x]);return e.content.appendChild(w)}e.content.appendChild(l)}}function en(e,t){return function(n,i,r,s,o,a,c){r=r?r+" cm-force-border":"cm-force-border";for(var l=n.pos,d=l+i.length;;){for(var u=void 0,h=0;h<t.length&&!((u=t[h]).to>l&&u.from<=l);h++);if(u.to>=d)return e(n,i,r,s,o,a,c);e(n,i.slice(0,u.to-l),r,s,null,a,c),s=null,i=i.slice(u.to-l),l=u.to}}}function tn(e,t,n,i){var r=!i&&n.widgetNode;r&&e.map.push(e.pos,e.pos+t,r),!i&&e.cm.display.input.needsContentAttribute&&(r||(r=e.content.appendChild(document.createElement("span"))),r.setAttribute("cm-marker",n.id)),r&&(e.cm.display.input.setUneditable(r),e.content.appendChild(r)),e.pos+=t,e.trailingSpace=!1}function nn(e,t,n){var i=e.markedSpans,r=e.text,s=0;if(i)for(var o,a,c,l,d,u,h,p=r.length,f=0,m=1,g="",v=0;;){if(v==f){c=l=d=a="",h=null,u=null,v=1/0;for(var b=[],y=void 0,S=0;S<i.length;++S){var w=i[S],x=w.marker;if("bookmark"==x.type&&w.from==f&&x.widgetNode)b.push(x);else if(w.from<=f&&(null==w.to||w.to>f||x.collapsed&&w.to==f&&w.from==f)){if(null!=w.to&&w.to!=f&&v>w.to&&(v=w.to,l=""),x.className&&(c+=" "+x.className),x.css&&(a=(a?a+";":"")+x.css),x.startStyle&&w.from==f&&(d+=" "+x.startStyle),x.endStyle&&w.to==v&&(y||(y=[])).push(x.endStyle,w.to),x.title&&((h||(h={})).title=x.title),x.attributes)for(var C in x.attributes)(h||(h={}))[C]=x.attributes[C];x.collapsed&&(!u||It(u.marker,x)<0)&&(u=w)}else w.from>f&&v>w.from&&(v=w.from)}if(y)for(var O=0;O<y.length;O+=2)y[O+1]==v&&(l+=" "+y[O]);if(!u||u.from==f)for(var k=0;k<b.length;++k)tn(t,0,b[k]);if(u&&(u.from||0)==f){if(tn(t,(null==u.to?p+1:u.to)-f,u.marker,null==u.from),null==u.to)return;u.to==f&&(u=!1)}}if(f>=p)break;for(var E=Math.min(p,v);;){if(g){var T=f+g.length;if(!u){var M=T>E?g.slice(0,E-f):g;t.addToken(t,M,o?o+c:c,d,f+M.length==v?l:"",a,h)}if(T>=E){g=g.slice(E-f),f=E;break}f=T,d=""}g=r.slice(s,s=n[m++]),o=Xt(n[m++],t.cm.options)}}else for(var D=1;D<n.length;D+=2)t.addToken(t,r.slice(s,s=n[D]),Xt(n[D+1],t.cm.options))}function rn(e,t,n){this.line=t,this.rest=function(e){for(var t,n;t=Rt(e);)e=t.find(1,!0).line,(n||(n=[])).push(e);return n}(t),this.size=this.rest?Xe(q(this.rest))-n+1:1,this.node=this.text=null,this.hidden=zt(e,t)}function sn(e,t,n){for(var i,r=[],s=t;s<n;s=i){var o=new rn(e.doc,He(e.doc,s),s);i=s+o.size,r.push(o)}return r}var on=null,an=null;function cn(e,t){var n=he(e,t);if(n.length){var i,r=Array.prototype.slice.call(arguments,2);on?i=on.delayedCallbacks:an?i=an:(i=an=[],setTimeout(ln,0));for(var s=function(e){i.push((function(){return n[e].apply(null,r)}))},o=0;o<n.length;++o)s(o)}}function ln(){var e=an;an=null;for(var t=0;t<e.length;++t)e[t]()}function dn(e,t,n,i){for(var r=0;r<t.changes.length;r++){var s=t.changes[r];"text"==s?pn(e,t):"gutter"==s?mn(e,t,n,i):"class"==s?fn(e,t):"widget"==s&&gn(e,t,i)}t.changes=null}function un(e){return e.node==e.text&&(e.node=D("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),o&&a<8&&(e.node.style.zIndex=2)),e.node}function hn(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):Kt(e,t)}function pn(e,t){var n=t.text.className,i=hn(e,t);t.text==t.node&&(t.node=i.pre),t.text.parentNode.replaceChild(i.pre,t.text),t.text=i.pre,i.bgClass!=t.bgClass||i.textClass!=t.textClass?(t.bgClass=i.bgClass,t.textClass=i.textClass,fn(e,t)):n&&(t.text.className=n)}function fn(e,t){!function(e,t){var n=t.bgClass?t.bgClass+" "+(t.line.bgClass||""):t.line.bgClass;if(n&&(n+=" CodeMirror-linebackground"),t.background)n?t.background.className=n:(t.background.parentNode.removeChild(t.background),t.background=null);else if(n){var i=un(t);t.background=i.insertBefore(D("div",null,n),i.firstChild),e.display.input.setUneditable(t.background)}}(e,t),t.line.wrapClass?un(t).className=t.line.wrapClass:t.node!=t.text&&(t.node.className="");var n=t.textClass?t.textClass+" "+(t.line.textClass||""):t.line.textClass;t.text.className=n||""}function mn(e,t,n,i){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var r=un(t);t.gutterBackground=D("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px; width: "+i.gutterTotalWidth+"px"),e.display.input.setUneditable(t.gutterBackground),r.insertBefore(t.gutterBackground,t.text)}var s=t.line.gutterMarkers;if(e.options.lineNumbers||s){var o=un(t),a=t.gutter=D("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px");if(e.display.input.setUneditable(a),o.insertBefore(a,t.text),t.line.gutterClass&&(a.className+=" "+t.line.gutterClass),!e.options.lineNumbers||s&&s["CodeMirror-linenumbers"]||(t.lineNumber=a.appendChild(D("div",Ze(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),s)for(var c=0;c<e.display.gutterSpecs.length;++c){var l=e.display.gutterSpecs[c].className,d=s.hasOwnProperty(l)&&s[l];d&&a.appendChild(D("div",[d],"CodeMirror-gutter-elt","left: "+i.gutterLeft[l]+"px; width: "+i.gutterWidth[l]+"px"))}}}function gn(e,t,n){t.alignable&&(t.alignable=null);for(var i=O("CodeMirror-linewidget"),r=t.node.firstChild,s=void 0;r;r=s)s=r.nextSibling,i.test(r.className)&&t.node.removeChild(r);bn(e,t,n)}function vn(e,t,n,i){var r=hn(e,t);return t.text=t.node=r.pre,r.bgClass&&(t.bgClass=r.bgClass),r.textClass&&(t.textClass=r.textClass),fn(e,t),mn(e,t,n,i),bn(e,t,i),t.node}function bn(e,t,n){if(yn(e,t.line,t,n,!0),t.rest)for(var i=0;i<t.rest.length;i++)yn(e,t.rest[i],t,n,!1)}function yn(e,t,n,i,r){if(t.widgets)for(var s=un(n),o=0,a=t.widgets;o<a.length;++o){var c=a[o],l=D("div",[c.node],"CodeMirror-linewidget"+(c.className?" "+c.className:""));c.handleMouseEvents||l.setAttribute("cm-ignore-events","true"),Sn(c,l,n,i),e.display.input.setUneditable(l),r&&c.above?s.insertBefore(l,n.gutter||n.text):s.appendChild(l),cn(c,"redraw")}}function Sn(e,t,n,i){if(e.noHScroll){(n.alignable||(n.alignable=[])).push(t);var r=i.wrapperWidth;t.style.left=i.fixedPos+"px",e.coverGutter||(r-=i.gutterTotalWidth,t.style.paddingLeft=i.gutterTotalWidth+"px"),t.style.width=r+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-i.gutterTotalWidth+"px"))}function wn(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!j(document.body,e.node)){var n="position: relative;";e.coverGutter&&(n+="margin-left: -"+t.display.gutters.offsetWidth+"px;"),e.noHScroll&&(n+="width: "+t.display.wrapper.clientWidth+"px;"),M(t.display.measure,D("div",[e.node],null,n))}return e.height=e.node.parentNode.offsetHeight}function xn(e,t){for(var n=Ce(t);n!=e.wrapper;n=n.parentNode)if(!n||1==n.nodeType&&"true"==n.getAttribute("cm-ignore-events")||n.parentNode==e.sizer&&n!=e.mover)return!0}function Cn(e){return e.lineSpace.offsetTop}function On(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function kn(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=M(e.measure,D("pre","x","CodeMirror-line-like")),n=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,i={left:parseInt(n.paddingLeft),right:parseInt(n.paddingRight)};return isNaN(i.left)||isNaN(i.right)||(e.cachedPaddingH=i),i}function En(e){return 30-e.display.nativeBarWidth}function Tn(e){return e.display.scroller.clientWidth-En(e)-e.display.barWidth}function Mn(e){return e.display.scroller.clientHeight-En(e)-e.display.barHeight}function Dn(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var i=0;i<e.rest.length;i++)if(e.rest[i]==t)return{map:e.measure.maps[i],cache:e.measure.caches[i]};for(var r=0;r<e.rest.length;r++)if(Xe(e.rest[r])>n)return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}function Ln(e,t,n,i){return Pn(e,In(e,t),n,i)}function jn(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[di(e,t)];var n=e.display.externalMeasured;return n&&t>=n.lineN&&t<n.lineN+n.size?n:void 0}function In(e,t){var n=Xe(t),i=jn(e,n);i&&!i.text?i=null:i&&i.changes&&(dn(e,i,n,si(e)),e.curOp.forceUpdate=!0),i||(i=function(e,t){var n=Xe(t=_t(t)),i=e.display.externalMeasured=new rn(e.doc,t,n);i.lineN=n;var r=i.built=Kt(e,i);return i.text=r.pre,M(e.display.lineMeasure,r.pre),i}(e,t));var r=Dn(i,t,n);return{line:t,view:i,rect:null,map:r.map,cache:r.cache,before:r.before,hasHeights:!1}}function Pn(e,t,n,i,r){t.before&&(n=-1);var s,c=n+(i||"");return t.cache.hasOwnProperty(c)?s=t.cache[c]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(function(e,t,n){var i=e.options.lineWrapping,r=i&&Tn(e);if(!t.measure.heights||i&&t.measure.width!=r){var s=t.measure.heights=[];if(i){t.measure.width=r;for(var o=t.text.firstChild.getClientRects(),a=0;a<o.length-1;a++){var c=o[a],l=o[a+1];Math.abs(c.bottom-l.bottom)>2&&s.push((c.bottom+l.top)/2-n.top)}}s.push(n.bottom-n.top)}}(e,t.view,t.rect),t.hasHeights=!0),(s=function(e,t,n,i){var r,s=Nn(t.map,n,i),c=s.node,l=s.start,d=s.end,u=s.collapse;if(3==c.nodeType){for(var h=0;h<4;h++){for(;l&&ie(t.line.text.charAt(s.coverStart+l));)--l;for(;s.coverStart+d<s.coverEnd&&ie(t.line.text.charAt(s.coverStart+d));)++d;if((r=o&&a<9&&0==l&&d==s.coverEnd-s.coverStart?c.parentNode.getBoundingClientRect():Vn(k(c,l,d).getClientRects(),i)).left||r.right||0==l)break;d=l,l-=1,u="right"}o&&a<11&&(r=function(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!function(e){if(null!=Ae)return Ae;var t=M(e,D("span","x")),n=t.getBoundingClientRect(),i=k(t,0,1).getBoundingClientRect();return Ae=Math.abs(n.left-i.left)>1}(e))return t;var n=screen.logicalXDPI/screen.deviceXDPI,i=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*n,right:t.right*n,top:t.top*i,bottom:t.bottom*i}}(e.display.measure,r))}else{var p;l>0&&(u=i="right"),r=e.options.lineWrapping&&(p=c.getClientRects()).length>1?p["right"==i?p.length-1:0]:c.getBoundingClientRect()}if(o&&a<9&&!l&&(!r||!r.left&&!r.right)){var f=c.parentNode.getClientRects()[0];r=f?{left:f.left,right:f.left+ri(e.display),top:f.top,bottom:f.bottom}:Rn}for(var m=r.top-t.rect.top,g=r.bottom-t.rect.top,v=(m+g)/2,b=t.view.measure.heights,y=0;y<b.length-1&&!(v<b[y]);y++);var S=y?b[y-1]:0,w=b[y],x={left:("right"==u?r.right:r.left)-t.rect.left,right:("left"==u?r.left:r.right)-t.rect.left,top:S,bottom:w};return r.left||r.right||(x.bogus=!0),e.options.singleCursorHeightPerLine||(x.rtop=m,x.rbottom=g),x}(e,t,n,i)).bogus||(t.cache[c]=s)),{left:s.left,right:s.right,top:r?s.rtop:s.top,bottom:r?s.rbottom:s.bottom}}var An,Rn={left:0,right:0,top:0,bottom:0};function Nn(e,t,n){for(var i,r,s,o,a,c,l=0;l<e.length;l+=3)if(a=e[l],c=e[l+1],t<a?(r=0,s=1,o="left"):t<c?s=1+(r=t-a):(l==e.length-3||t==c&&e[l+3]>t)&&(r=(s=c-a)-1,t>=c&&(o="right")),null!=r){if(i=e[l+2],a==c&&n==(i.insertLeft?"left":"right")&&(o=n),"left"==n&&0==r)for(;l&&e[l-2]==e[l-3]&&e[l-1].insertLeft;)i=e[2+(l-=3)],o="left";if("right"==n&&r==c-a)for(;l<e.length-3&&e[l+3]==e[l+4]&&!e[l+5].insertLeft;)i=e[(l+=3)+2],o="right";break}return{node:i,start:r,end:s,collapse:o,coverStart:a,coverEnd:c}}function Vn(e,t){var n=Rn;if("left"==t)for(var i=0;i<e.length&&(n=e[i]).left==n.right;i++);else for(var r=e.length-1;r>=0&&(n=e[r]).left==n.right;r--);return n}function _n(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function Bn(e){e.display.externalMeasure=null,T(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)_n(e.display.view[t])}function Fn(e){Bn(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function zn(){return d&&g?-(document.body.getBoundingClientRect().left-parseInt(getComputedStyle(document.body).marginLeft)):window.pageXOffset||(document.documentElement||document.body).scrollLeft}function Un(){return d&&g?-(document.body.getBoundingClientRect().top-parseInt(getComputedStyle(document.body).marginTop)):window.pageYOffset||(document.documentElement||document.body).scrollTop}function Gn(e){var t=0;if(e.widgets)for(var n=0;n<e.widgets.length;++n)e.widgets[n].above&&(t+=wn(e.widgets[n]));return t}function $n(e,t,n,i,r){if(!r){var s=Gn(t);n.top+=s,n.bottom+=s}if("line"==i)return n;i||(i="local");var o=Gt(t);if("local"==i?o+=Cn(e.display):o-=e.display.viewOffset,"page"==i||"window"==i){var a=e.display.lineSpace.getBoundingClientRect();o+=a.top+("window"==i?0:Un());var c=a.left+("window"==i?0:zn());n.left+=c,n.right+=c}return n.top+=o,n.bottom+=o,n}function Wn(e,t,n){if("div"==n)return t;var i=t.left,r=t.top;if("page"==n)i-=zn(),r-=Un();else if("local"==n||!n){var s=e.display.sizer.getBoundingClientRect();i+=s.left,r+=s.top}var o=e.display.lineSpace.getBoundingClientRect();return{left:i-o.left,top:r-o.top}}function Hn(e,t,n,i,r){return i||(i=He(e.doc,t.line)),$n(e,i,Ln(e,i,t.ch,r),n)}function Jn(e,t,n,i,r,s){function o(t,o){var a=Pn(e,r,t,o?"right":"left",s);return o?a.left=a.right:a.right=a.left,$n(e,i,a,n)}i=i||He(e.doc,t.line),r||(r=In(e,i));var a=le(i,e.doc.direction),c=t.ch,l=t.sticky;if(c>=i.text.length?(c=i.text.length,l="before"):c<=0&&(c=0,l="after"),!a)return o("before"==l?c-1:c,"before"==l);function d(e,t,n){return o(n?e-1:e,1==a[t].level!=n)}var u=ae(a,c,l),h=oe,p=d(c,u,"before"==l);return null!=h&&(p.other=d(c,h,"before"!=l)),p}function qn(e,t){var n=0;t=at(e.doc,t),e.options.lineWrapping||(n=ri(e.display)*t.ch);var i=He(e.doc,t.line),r=Gt(i)+Cn(e.display);return{left:n,right:n,top:r,bottom:r+i.height}}function Yn(e,t,n,i,r){var s=et(e,t,n);return s.xRel=r,i&&(s.outside=i),s}function Xn(e,t,n){var i=e.doc;if((n+=e.display.viewOffset)<0)return Yn(i.first,0,null,-1,-1);var r=Ke(i,n),s=i.first+i.size-1;if(r>s)return Yn(i.first+i.size-1,He(i,s).text.length,null,1,1);t<0&&(t=0);for(var o=He(i,r);;){var a=ei(e,o,r,t,n),c=Nt(o,a.ch+(a.xRel>0||a.outside>0?1:0));if(!c)return a;var l=c.find(1);if(l.line==r)return l;o=He(i,r=l.line)}}function Kn(e,t,n,i){i-=Gn(t);var r=t.text.length,s=se((function(t){return Pn(e,n,t-1).bottom<=i}),r,0);return{begin:s,end:r=se((function(t){return Pn(e,n,t).top>i}),s,r)}}function Qn(e,t,n,i){return n||(n=In(e,t)),Kn(e,t,n,$n(e,t,Pn(e,n,i),"line").top)}function Zn(e,t,n,i){return!(e.bottom<=n)&&(e.top>n||(i?e.left:e.right)>t)}function ei(e,t,n,i,r){r-=Gt(t);var s=In(e,t),o=Gn(t),a=0,c=t.text.length,l=!0,d=le(t,e.doc.direction);if(d){var u=(e.options.lineWrapping?ni:ti)(e,t,n,s,d,i,r);a=(l=1!=u.level)?u.from:u.to-1,c=l?u.to:u.from-1}var h,p,f=null,m=null,g=se((function(t){var n=Pn(e,s,t);return n.top+=o,n.bottom+=o,!!Zn(n,i,r,!1)&&(n.top<=r&&n.left<=i&&(f=t,m=n),!0)}),a,c),v=!1;if(m){var b=i-m.left<m.right-i,y=b==l;g=f+(y?0:1),p=y?"after":"before",h=b?m.left:m.right}else{l||g!=c&&g!=a||g++,p=0==g?"after":g==t.text.length?"before":Pn(e,s,g-(l?1:0)).bottom+o<=r==l?"after":"before";var S=Jn(e,et(n,g,p),"line",t,s);h=S.left,v=r<S.top?-1:r>=S.bottom?1:0}return Yn(n,g=re(t.text,g,1),p,v,i-h)}function ti(e,t,n,i,r,s,o){var a=se((function(a){var c=r[a],l=1!=c.level;return Zn(Jn(e,et(n,l?c.to:c.from,l?"before":"after"),"line",t,i),s,o,!0)}),0,r.length-1),c=r[a];if(a>0){var l=1!=c.level,d=Jn(e,et(n,l?c.from:c.to,l?"after":"before"),"line",t,i);Zn(d,s,o,!0)&&d.top>o&&(c=r[a-1])}return c}function ni(e,t,n,i,r,s,o){var a=Kn(e,t,i,o),c=a.begin,l=a.end;/\s/.test(t.text.charAt(l-1))&&l--;for(var d=null,u=null,h=0;h<r.length;h++){var p=r[h];if(!(p.from>=l||p.to<=c)){var f=Pn(e,i,1!=p.level?Math.min(l,p.to)-1:Math.max(c,p.from)).right,m=f<s?s-f+1e9:f-s;(!d||u>m)&&(d=p,u=m)}}return d||(d=r[r.length-1]),d.from<c&&(d={from:c,to:d.to,level:d.level}),d.to>l&&(d={from:d.from,to:l,level:d.level}),d}function ii(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==An){An=D("pre",null,"CodeMirror-line-like");for(var t=0;t<49;++t)An.appendChild(document.createTextNode("x")),An.appendChild(D("br"));An.appendChild(document.createTextNode("x"))}M(e.measure,An);var n=An.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),T(e.measure),n||1}function ri(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=D("span","xxxxxxxxxx"),n=D("pre",[t],"CodeMirror-line-like");M(e.measure,n);var i=t.getBoundingClientRect(),r=(i.right-i.left)/10;return r>2&&(e.cachedCharWidth=r),r||10}function si(e){for(var t=e.display,n={},i={},r=t.gutters.clientLeft,s=t.gutters.firstChild,o=0;s;s=s.nextSibling,++o){var a=e.display.gutterSpecs[o].className;n[a]=s.offsetLeft+s.clientLeft+r,i[a]=s.clientWidth}return{fixedPos:oi(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:i,wrapperWidth:t.wrapper.clientWidth}}function oi(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function ai(e){var t=ii(e.display),n=e.options.lineWrapping,i=n&&Math.max(5,e.display.scroller.clientWidth/ri(e.display)-3);return function(r){if(zt(e.doc,r))return 0;var s=0;if(r.widgets)for(var o=0;o<r.widgets.length;o++)r.widgets[o].height&&(s+=r.widgets[o].height);return n?s+(Math.ceil(r.text.length/i)||1)*t:s+t}}function ci(e){var t=e.doc,n=ai(e);t.iter((function(e){var t=n(e);t!=e.height&&Ye(e,t)}))}function li(e,t,n,i){var r=e.display;if(!n&&"true"==Ce(t).getAttribute("cm-not-content"))return null;var s,o,a=r.lineSpace.getBoundingClientRect();try{s=t.clientX-a.left,o=t.clientY-a.top}catch(t){return null}var c,l=Xn(e,s,o);if(i&&l.xRel>0&&(c=He(e.doc,l.line).text).length==l.ch){var d=_(c,c.length,e.options.tabSize)-c.length;l=et(l.line,Math.max(0,Math.round((s-kn(e.display).left)/ri(e.display))-d))}return l}function di(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var n=e.display.view,i=0;i<n.length;i++)if((t-=n[i].size)<0)return i}function ui(e,t,n,i){null==t&&(t=e.doc.first),null==n&&(n=e.doc.first+e.doc.size),i||(i=0);var r=e.display;if(i&&n<r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>t)&&(r.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=r.viewTo)xt&&Bt(e.doc,t)<r.viewTo&&pi(e);else if(n<=r.viewFrom)xt&&Ft(e.doc,n+i)>r.viewFrom?pi(e):(r.viewFrom+=i,r.viewTo+=i);else if(t<=r.viewFrom&&n>=r.viewTo)pi(e);else if(t<=r.viewFrom){var s=fi(e,n,n+i,1);s?(r.view=r.view.slice(s.index),r.viewFrom=s.lineN,r.viewTo+=i):pi(e)}else if(n>=r.viewTo){var o=fi(e,t,t,-1);o?(r.view=r.view.slice(0,o.index),r.viewTo=o.lineN):pi(e)}else{var a=fi(e,t,t,-1),c=fi(e,n,n+i,1);a&&c?(r.view=r.view.slice(0,a.index).concat(sn(e,a.lineN,c.lineN)).concat(r.view.slice(c.index)),r.viewTo+=i):pi(e)}var l=r.externalMeasured;l&&(n<l.lineN?l.lineN+=i:t<l.lineN+l.size&&(r.externalMeasured=null))}function hi(e,t,n){e.curOp.viewChanged=!0;var i=e.display,r=e.display.externalMeasured;if(r&&t>=r.lineN&&t<r.lineN+r.size&&(i.externalMeasured=null),!(t<i.viewFrom||t>=i.viewTo)){var s=i.view[di(e,t)];if(null!=s.node){var o=s.changes||(s.changes=[]);-1==F(o,n)&&o.push(n)}}}function pi(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function fi(e,t,n,i){var r,s=di(e,t),o=e.display.view;if(!xt||n==e.doc.first+e.doc.size)return{index:s,lineN:n};for(var a=e.display.viewFrom,c=0;c<s;c++)a+=o[c].size;if(a!=t){if(i>0){if(s==o.length-1)return null;r=a+o[s].size-t,s++}else r=a-t;t+=r,n+=r}for(;Bt(e.doc,n)!=n;){if(s==(i<0?0:o.length-1))return null;n+=i*o[s-(i<0?1:0)].size,s+=i}return{index:s,lineN:n}}function mi(e){for(var t=e.display.view,n=0,i=0;i<t.length;i++){var r=t[i];r.hidden||r.node&&!r.changes||++n}return n}function gi(e){e.display.input.showSelection(e.display.input.prepareSelection())}function vi(e,t){void 0===t&&(t=!0);for(var n=e.doc,i={},r=i.cursors=document.createDocumentFragment(),s=i.selection=document.createDocumentFragment(),o=0;o<n.sel.ranges.length;o++)if(t||o!=n.sel.primIndex){var a=n.sel.ranges[o];if(!(a.from().line>=e.display.viewTo||a.to().line<e.display.viewFrom)){var c=a.empty();(c||e.options.showCursorWhenSelecting)&&bi(e,a.head,r),c||Si(e,a,s)}}return i}function bi(e,t,n){var i=Jn(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),r=n.appendChild(D("div"," ","CodeMirror-cursor"));if(r.style.left=i.left+"px",r.style.top=i.top+"px",r.style.height=Math.max(0,i.bottom-i.top)*e.options.cursorHeight+"px",i.other){var s=n.appendChild(D("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));s.style.display="",s.style.left=i.other.left+"px",s.style.top=i.other.top+"px",s.style.height=.85*(i.other.bottom-i.other.top)+"px"}}function yi(e,t){return e.top-t.top||e.left-t.left}function Si(e,t,n){var i=e.display,r=e.doc,s=document.createDocumentFragment(),o=kn(e.display),a=o.left,c=Math.max(i.sizerWidth,Tn(e)-i.sizer.offsetLeft)-o.right,l="ltr"==r.direction;function d(e,t,n,i){t<0&&(t=0),t=Math.round(t),i=Math.round(i),s.appendChild(D("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px;\n                             top: "+t+"px; width: "+(null==n?c-e:n)+"px;\n                             height: "+(i-t)+"px"))}function u(t,n,i){var s,o,u=He(r,t),h=u.text.length;function p(n,i){return Hn(e,et(t,n),"div",u,i)}function f(t,n,i){var r=Qn(e,u,null,t),s="ltr"==n==("after"==i)?"left":"right";return p("after"==i?r.begin:r.end-(/\s/.test(u.text.charAt(r.end-1))?2:1),s)[s]}var m=le(u,r.direction);return function(e,t,n,i){if(!e)return i(t,n,"ltr",0);for(var r=!1,s=0;s<e.length;++s){var o=e[s];(o.from<n&&o.to>t||t==n&&o.to==t)&&(i(Math.max(o.from,t),Math.min(o.to,n),1==o.level?"rtl":"ltr",s),r=!0)}r||i(t,n,"ltr")}(m,n||0,null==i?h:i,(function(e,t,r,u){var g="ltr"==r,v=p(e,g?"left":"right"),b=p(t-1,g?"right":"left"),y=null==n&&0==e,S=null==i&&t==h,w=0==u,x=!m||u==m.length-1;if(b.top-v.top<=3){var C=(l?S:y)&&x,O=(l?y:S)&&w?a:(g?v:b).left,k=C?c:(g?b:v).right;d(O,v.top,k-O,v.bottom)}else{var E,T,M,D;g?(E=l&&y&&w?a:v.left,T=l?c:f(e,r,"before"),M=l?a:f(t,r,"after"),D=l&&S&&x?c:b.right):(E=l?f(e,r,"before"):a,T=!l&&y&&w?c:v.right,M=!l&&S&&x?a:b.left,D=l?f(t,r,"after"):c),d(E,v.top,T-E,v.bottom),v.bottom<b.top&&d(a,v.bottom,null,b.top),d(M,b.top,D-M,b.bottom)}(!s||yi(v,s)<0)&&(s=v),yi(b,s)<0&&(s=b),(!o||yi(v,o)<0)&&(o=v),yi(b,o)<0&&(o=b)})),{start:s,end:o}}var h=t.from(),p=t.to();if(h.line==p.line)u(h.line,h.ch,p.ch);else{var f=He(r,h.line),m=He(r,p.line),g=_t(f)==_t(m),v=u(h.line,h.ch,g?f.text.length+1:null).end,b=u(p.line,g?0:null,p.ch).start;g&&(v.top<b.top-2?(d(v.right,v.top,null,v.bottom),d(a,b.top,b.left,b.bottom)):d(v.right,v.top,b.left-v.right,v.bottom)),v.bottom<b.top&&d(a,v.bottom,null,b.top)}n.appendChild(s)}function wi(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var n=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval((function(){return t.cursorDiv.style.visibility=(n=!n)?"":"hidden"}),e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function xi(e){e.state.focused||(e.display.input.focus(),Oi(e))}function Ci(e){e.state.delayingBlurEvent=!0,setTimeout((function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,ki(e))}),100)}function Oi(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(fe(e,"focus",e,t),e.state.focused=!0,P(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),c&&setTimeout((function(){return e.display.input.reset(!0)}),20)),e.display.input.receivedFocus()),wi(e))}function ki(e,t){e.state.delayingBlurEvent||(e.state.focused&&(fe(e,"blur",e,t),e.state.focused=!1,E(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout((function(){e.state.focused||(e.display.shift=!1)}),150))}function Ei(e){for(var t=e.display,n=t.lineDiv.offsetTop,i=0;i<t.view.length;i++){var r=t.view[i],s=e.options.lineWrapping,c=void 0,l=0;if(!r.hidden){if(o&&a<8){var d=r.node.offsetTop+r.node.offsetHeight;c=d-n,n=d}else{var u=r.node.getBoundingClientRect();c=u.bottom-u.top,!s&&r.text.firstChild&&(l=r.text.firstChild.getBoundingClientRect().right-u.left-1)}var h=r.line.height-c;if((h>.005||h<-.005)&&(Ye(r.line,c),Ti(r.line),r.rest))for(var p=0;p<r.rest.length;p++)Ti(r.rest[p]);if(l>e.display.sizerWidth){var f=Math.ceil(l/ri(e.display));f>e.display.maxLineLength&&(e.display.maxLineLength=f,e.display.maxLine=r.line,e.display.maxLineChanged=!0)}}}}function Ti(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t){var n=e.widgets[t],i=n.node.parentNode;i&&(n.height=i.offsetHeight)}}function Mi(e,t,n){var i=n&&null!=n.top?Math.max(0,n.top):e.scroller.scrollTop;i=Math.floor(i-Cn(e));var r=n&&null!=n.bottom?n.bottom:i+e.wrapper.clientHeight,s=Ke(t,i),o=Ke(t,r);if(n&&n.ensure){var a=n.ensure.from.line,c=n.ensure.to.line;a<s?(s=a,o=Ke(t,Gt(He(t,a))+e.wrapper.clientHeight)):Math.min(c,t.lastLine())>=o&&(s=Ke(t,Gt(He(t,c))-e.wrapper.clientHeight),o=c)}return{from:s,to:Math.max(o,s+1)}}function Di(e,t){var n=e.display,i=ii(e.display);t.top<0&&(t.top=0);var r=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,s=Mn(e),o={};t.bottom-t.top>s&&(t.bottom=t.top+s);var a=e.doc.height+On(n),c=t.top<i,l=t.bottom>a-i;if(t.top<r)o.scrollTop=c?0:t.top;else if(t.bottom>r+s){var d=Math.min(t.top,(l?a:t.bottom)-s);d!=r&&(o.scrollTop=d)}var u=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft,h=Tn(e)-(e.options.fixedGutter?n.gutters.offsetWidth:0),p=t.right-t.left>h;return p&&(t.right=t.left+h),t.left<10?o.scrollLeft=0:t.left<u?o.scrollLeft=Math.max(0,t.left-(p?0:10)):t.right>h+u-3&&(o.scrollLeft=t.right+(p?0:10)-h),o}function Li(e,t){null!=t&&(Pi(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function ji(e){Pi(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function Ii(e,t,n){null==t&&null==n||Pi(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Pi(e){var t=e.curOp.scrollToPos;t&&(e.curOp.scrollToPos=null,Ai(e,qn(e,t.from),qn(e,t.to),t.margin))}function Ai(e,t,n,i){var r=Di(e,{left:Math.min(t.left,n.left),top:Math.min(t.top,n.top)-i,right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom)+i});Ii(e,r.scrollLeft,r.scrollTop)}function Ri(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||cr(e,{top:t}),Ni(e,t,!0),n&&cr(e),ir(e,100))}function Ni(e,t,n){t=Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t),(e.display.scroller.scrollTop!=t||n)&&(e.doc.scrollTop=t,e.display.scrollbars.setScrollTop(t),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t))}function Vi(e,t,n,i){t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!i||(e.doc.scrollLeft=t,ur(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function _i(e){var t=e.display,n=t.gutters.offsetWidth,i=Math.round(e.doc.height+On(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?n:0,docHeight:i,scrollHeight:i+En(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}var Bi=function(e,t,n){this.cm=n;var i=this.vert=D("div",[D("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r=this.horiz=D("div",[D("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");i.tabIndex=r.tabIndex=-1,e(i),e(r),ue(i,"scroll",(function(){i.clientHeight&&t(i.scrollTop,"vertical")})),ue(r,"scroll",(function(){r.clientWidth&&t(r.scrollLeft,"horizontal")})),this.checkedZeroWidth=!1,o&&a<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};Bi.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,n=e.scrollHeight>e.clientHeight+1,i=e.nativeBarWidth;if(n){this.vert.style.display="block",this.vert.style.bottom=t?i+"px":"0";var r=e.viewHeight-(t?i:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+r)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=n?i+"px":"0",this.horiz.style.left=e.barLeft+"px";var s=e.viewWidth-e.barLeft-(n?i:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+s)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==i&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:n?i:0,bottom:t?i:0}},Bi.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},Bi.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},Bi.prototype.zeroWidthHack=function(){var e=b&&!p?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new B,this.disableVert=new B},Bi.prototype.enableZeroWidthBar=function(e,t,n){e.style.pointerEvents="auto",t.set(1e3,(function i(){var r=e.getBoundingClientRect();("vert"==n?document.elementFromPoint(r.right-1,(r.top+r.bottom)/2):document.elementFromPoint((r.right+r.left)/2,r.bottom-1))!=e?e.style.pointerEvents="none":t.set(1e3,i)}))},Bi.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var Fi=function(){};function zi(e,t){t||(t=_i(e));var n=e.display.barWidth,i=e.display.barHeight;Ui(e,t);for(var r=0;r<4&&n!=e.display.barWidth||i!=e.display.barHeight;r++)n!=e.display.barWidth&&e.options.lineWrapping&&Ei(e),Ui(e,_i(e)),n=e.display.barWidth,i=e.display.barHeight}function Ui(e,t){var n=e.display,i=n.scrollbars.update(t);n.sizer.style.paddingRight=(n.barWidth=i.right)+"px",n.sizer.style.paddingBottom=(n.barHeight=i.bottom)+"px",n.heightForcer.style.borderBottom=i.bottom+"px solid transparent",i.right&&i.bottom?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=i.bottom+"px",n.scrollbarFiller.style.width=i.right+"px"):n.scrollbarFiller.style.display="",i.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=i.bottom+"px",n.gutterFiller.style.width=t.gutterWidth+"px"):n.gutterFiller.style.display=""}Fi.prototype.update=function(){return{bottom:0,right:0}},Fi.prototype.setScrollLeft=function(){},Fi.prototype.setScrollTop=function(){},Fi.prototype.clear=function(){};var Gi={native:Bi,null:Fi};function $i(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&E(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Gi[e.options.scrollbarStyle]((function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),ue(t,"mousedown",(function(){e.state.focused&&setTimeout((function(){return e.display.input.focus()}),0)})),t.setAttribute("cm-not-content","true")}),(function(t,n){"horizontal"==n?Vi(e,t):Ri(e,t)}),e),e.display.scrollbars.addClass&&P(e.display.wrapper,e.display.scrollbars.addClass)}var Wi=0;function Hi(e){var t;e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Wi},t=e.curOp,on?on.ops.push(t):t.ownsGroup=on={ops:[t],delayedCallbacks:[]}}function Ji(e){var t=e.curOp;t&&function(e,t){var n=e.ownsGroup;if(n)try{!function(e){var t=e.delayedCallbacks,n=0;do{for(;n<t.length;n++)t[n].call(null);for(var i=0;i<e.ops.length;i++){var r=e.ops[i];if(r.cursorActivityHandlers)for(;r.cursorActivityCalled<r.cursorActivityHandlers.length;)r.cursorActivityHandlers[r.cursorActivityCalled++].call(null,r.cm)}}while(n<t.length)}(n)}finally{on=null,t(n)}}(t,(function(e){for(var t=0;t<e.ops.length;t++)e.ops[t].cm.curOp=null;!function(e){for(var t=e.ops,n=0;n<t.length;n++)qi(t[n]);for(var i=0;i<t.length;i++)Yi(t[i]);for(var r=0;r<t.length;r++)Xi(t[r]);for(var s=0;s<t.length;s++)Ki(t[s]);for(var o=0;o<t.length;o++)Qi(t[o])}(e)}))}function qi(e){var t=e.cm,n=t.display;!function(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=En(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=En(e)+"px",t.scrollbarsClipped=!0)}(t),e.updateMaxLine&&Wt(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<n.viewFrom||e.scrollToPos.to.line>=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new sr(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Yi(e){e.updatedDisplay=e.mustUpdate&&or(e.cm,e.update)}function Xi(e){var t=e.cm,n=t.display;e.updatedDisplay&&Ei(t),e.barMeasure=_i(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Ln(t,n.maxLine,n.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(n.scroller.clientWidth,n.sizer.offsetLeft+e.adjustWidthTo+En(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Tn(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Ki(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&Vi(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1);var n=e.focus&&e.focus==I();e.preparedSelection&&t.display.input.showSelection(e.preparedSelection,n),(e.updatedDisplay||e.startHeight!=t.doc.height)&&zi(t,e.barMeasure),e.updatedDisplay&&dr(t,e.barMeasure),e.selectionChanged&&wi(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),n&&xi(e.cm)}function Qi(e){var t=e.cm,n=t.display,i=t.doc;e.updatedDisplay&&ar(t,e.update),null==n.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(n.wheelStartX=n.wheelStartY=null),null!=e.scrollTop&&Ni(t,e.scrollTop,e.forceScroll),null!=e.scrollLeft&&Vi(t,e.scrollLeft,!0,!0),e.scrollToPos&&function(e,t){if(!me(e,"scrollCursorIntoView")){var n=e.display,i=n.sizer.getBoundingClientRect(),r=null;if(t.top+i.top<0?r=!0:t.bottom+i.top>(window.innerHeight||document.documentElement.clientHeight)&&(r=!1),null!=r&&!f){var s=D("div","​",null,"position: absolute;\n                         top: "+(t.top-n.viewOffset-Cn(e.display))+"px;\n                         height: "+(t.bottom-t.top+En(e)+n.barHeight)+"px;\n                         left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;");e.display.lineSpace.appendChild(s),s.scrollIntoView(r),e.display.lineSpace.removeChild(s)}}}(t,function(e,t,n,i){var r;null==i&&(i=0),e.options.lineWrapping||t!=n||(n="before"==(t=t.ch?et(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t).sticky?et(t.line,t.ch+1,"before"):t);for(var s=0;s<5;s++){var o=!1,a=Jn(e,t),c=n&&n!=t?Jn(e,n):a,l=Di(e,r={left:Math.min(a.left,c.left),top:Math.min(a.top,c.top)-i,right:Math.max(a.left,c.left),bottom:Math.max(a.bottom,c.bottom)+i}),d=e.doc.scrollTop,u=e.doc.scrollLeft;if(null!=l.scrollTop&&(Ri(e,l.scrollTop),Math.abs(e.doc.scrollTop-d)>1&&(o=!0)),null!=l.scrollLeft&&(Vi(e,l.scrollLeft),Math.abs(e.doc.scrollLeft-u)>1&&(o=!0)),!o)break}return r}(t,at(i,e.scrollToPos.from),at(i,e.scrollToPos.to),e.scrollToPos.margin));var r=e.maybeHiddenMarkers,s=e.maybeUnhiddenMarkers;if(r)for(var o=0;o<r.length;++o)r[o].lines.length||fe(r[o],"hide");if(s)for(var a=0;a<s.length;++a)s[a].lines.length&&fe(s[a],"unhide");n.wrapper.offsetHeight&&(i.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&fe(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function Zi(e,t){if(e.curOp)return t();Hi(e);try{return t()}finally{Ji(e)}}function er(e,t){return function(){if(e.curOp)return t.apply(e,arguments);Hi(e);try{return t.apply(e,arguments)}finally{Ji(e)}}}function tr(e){return function(){if(this.curOp)return e.apply(this,arguments);Hi(this);try{return e.apply(this,arguments)}finally{Ji(this)}}}function nr(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);Hi(t);try{return e.apply(this,arguments)}finally{Ji(t)}}}function ir(e,t){e.doc.highlightFrontier<e.display.viewTo&&e.state.highlight.set(t,N(rr,e))}function rr(e){var t=e.doc;if(!(t.highlightFrontier>=e.display.viewTo)){var n=+new Date+e.options.workTime,i=pt(e,t.highlightFrontier),r=[];t.iter(i.line,Math.min(t.first+t.size,e.display.viewTo+500),(function(s){if(i.line>=e.display.viewFrom){var o=s.styles,a=s.text.length>e.options.maxHighlightLength?Ue(t.mode,i.state):null,c=ut(e,s,i,!0);a&&(i.state=a),s.styles=c.styles;var l=s.styleClasses,d=c.classes;d?s.styleClasses=d:l&&(s.styleClasses=null);for(var u=!o||o.length!=s.styles.length||l!=d&&(!l||!d||l.bgClass!=d.bgClass||l.textClass!=d.textClass),h=0;!u&&h<o.length;++h)u=o[h]!=s.styles[h];u&&r.push(i.line),s.stateAfter=i.save(),i.nextLine()}else s.text.length<=e.options.maxHighlightLength&&ft(e,s.text,i),s.stateAfter=i.line%5==0?i.save():null,i.nextLine();if(+new Date>n)return ir(e,e.options.workDelay),!0})),t.highlightFrontier=i.line,t.modeFrontier=Math.max(t.modeFrontier,i.line),r.length&&Zi(e,(function(){for(var t=0;t<r.length;t++)hi(e,r[t],"text")}))}}var sr=function(e,t,n){var i=e.display;this.viewport=t,this.visible=Mi(i,e.doc,t),this.editorIsHidden=!i.wrapper.offsetWidth,this.wrapperHeight=i.wrapper.clientHeight,this.wrapperWidth=i.wrapper.clientWidth,this.oldDisplayWidth=Tn(e),this.force=n,this.dims=si(e),this.events=[]};function or(e,t){var n=e.display,i=e.doc;if(t.editorIsHidden)return pi(e),!1;if(!t.force&&t.visible.from>=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==mi(e))return!1;hr(e)&&(pi(e),t.dims=si(e));var r=i.first+i.size,s=Math.max(t.visible.from-e.options.viewportMargin,i.first),o=Math.min(r,t.visible.to+e.options.viewportMargin);n.viewFrom<s&&s-n.viewFrom<20&&(s=Math.max(i.first,n.viewFrom)),n.viewTo>o&&n.viewTo-o<20&&(o=Math.min(r,n.viewTo)),xt&&(s=Bt(e.doc,s),o=Ft(e.doc,o));var a=s!=n.viewFrom||o!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;!function(e,t,n){var i=e.display;0==i.view.length||t>=i.viewTo||n<=i.viewFrom?(i.view=sn(e,t,n),i.viewFrom=t):(i.viewFrom>t?i.view=sn(e,t,i.viewFrom).concat(i.view):i.viewFrom<t&&(i.view=i.view.slice(di(e,t))),i.viewFrom=t,i.viewTo<n?i.view=i.view.concat(sn(e,i.viewTo,n)):i.viewTo>n&&(i.view=i.view.slice(0,di(e,n)))),i.viewTo=n}(e,s,o),n.viewOffset=Gt(He(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var l=mi(e);if(!a&&0==l&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var d=function(e){if(e.hasFocus())return null;var t=I();if(!t||!j(e.display.lineDiv,t))return null;var n={activeElt:t};if(window.getSelection){var i=window.getSelection();i.anchorNode&&i.extend&&j(e.display.lineDiv,i.anchorNode)&&(n.anchorNode=i.anchorNode,n.anchorOffset=i.anchorOffset,n.focusNode=i.focusNode,n.focusOffset=i.focusOffset)}return n}(e);return l>4&&(n.lineDiv.style.display="none"),function(e,t,n){var i=e.display,r=e.options.lineNumbers,s=i.lineDiv,o=s.firstChild;function a(t){var n=t.nextSibling;return c&&b&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var l=i.view,d=i.viewFrom,u=0;u<l.length;u++){var h=l[u];if(h.hidden);else if(h.node&&h.node.parentNode==s){for(;o!=h.node;)o=a(o);var p=r&&null!=t&&t<=d&&h.lineNumber;h.changes&&(F(h.changes,"gutter")>-1&&(p=!1),dn(e,h,d,n)),p&&(T(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(Ze(e.options,d)))),o=h.node.nextSibling}else{var f=vn(e,h,d,n);s.insertBefore(f,o)}d+=h.size}for(;o;)o=a(o)}(e,n.updateLineNumbers,t.dims),l>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,function(e){if(e&&e.activeElt&&e.activeElt!=I()&&(e.activeElt.focus(),e.anchorNode&&j(document.body,e.anchorNode)&&j(document.body,e.focusNode))){var t=window.getSelection(),n=document.createRange();n.setEnd(e.anchorNode,e.anchorOffset),n.collapse(!1),t.removeAllRanges(),t.addRange(n),t.extend(e.focusNode,e.focusOffset)}}(d),T(n.cursorDiv),T(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,a&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,ir(e,400)),n.updateLineNumbers=null,!0}function ar(e,t){for(var n=t.viewport,i=!0;(i&&e.options.lineWrapping&&t.oldDisplayWidth!=Tn(e)||(n&&null!=n.top&&(n={top:Math.min(e.doc.height+On(e.display)-Mn(e),n.top)}),t.visible=Mi(e.display,e.doc,n),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&or(e,t);i=!1){Ei(e);var r=_i(e);gi(e),zi(e,r),dr(e,r),t.force=!1}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function cr(e,t){var n=new sr(e,t);if(or(e,n)){Ei(e),ar(e,n);var i=_i(e);gi(e),zi(e,i),dr(e,i),n.finish()}}function lr(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px"}function dr(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+En(e)+"px"}function ur(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var i=oi(t)-t.scroller.scrollLeft+e.doc.scrollLeft,r=t.gutters.offsetWidth,s=i+"px",o=0;o<n.length;o++)if(!n[o].hidden){e.options.fixedGutter&&(n[o].gutter&&(n[o].gutter.style.left=s),n[o].gutterBackground&&(n[o].gutterBackground.style.left=s));var a=n[o].alignable;if(a)for(var c=0;c<a.length;c++)a[c].style.left=s}e.options.fixedGutter&&(t.gutters.style.left=i+r+"px")}}function hr(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=Ze(e.options,t.first+t.size-1),i=e.display;if(n.length!=i.lineNumChars){var r=i.measure.appendChild(D("div",[D("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=r.firstChild.offsetWidth,o=r.offsetWidth-s;return i.lineGutter.style.width="",i.lineNumInnerWidth=Math.max(s,i.lineGutter.offsetWidth-o)+1,i.lineNumWidth=i.lineNumInnerWidth+o,i.lineNumChars=i.lineNumInnerWidth?n.length:-1,i.lineGutter.style.width=i.lineNumWidth+"px",lr(e.display),!0}return!1}function pr(e,t){for(var n=[],i=!1,r=0;r<e.length;r++){var s=e[r],o=null;if("string"!=typeof s&&(o=s.style,s=s.className),"CodeMirror-linenumbers"==s){if(!t)continue;i=!0}n.push({className:s,style:o})}return t&&!i&&n.push({className:"CodeMirror-linenumbers",style:null}),n}function fr(e){var t=e.gutters,n=e.gutterSpecs;T(t),e.lineGutter=null;for(var i=0;i<n.length;++i){var r=n[i],s=r.className,o=r.style,a=t.appendChild(D("div",null,"CodeMirror-gutter "+s));o&&(a.style.cssText=o),"CodeMirror-linenumbers"==s&&(e.lineGutter=a,a.style.width=(e.lineNumWidth||1)+"px")}t.style.display=n.length?"":"none",lr(e)}function mr(e){fr(e.display),ui(e),ur(e)}function gr(e,t,i,r){var s=this;this.input=i,s.scrollbarFiller=D("div",null,"CodeMirror-scrollbar-filler"),s.scrollbarFiller.setAttribute("cm-not-content","true"),s.gutterFiller=D("div",null,"CodeMirror-gutter-filler"),s.gutterFiller.setAttribute("cm-not-content","true"),s.lineDiv=L("div",null,"CodeMirror-code"),s.selectionDiv=D("div",null,null,"position: relative; z-index: 1"),s.cursorDiv=D("div",null,"CodeMirror-cursors"),s.measure=D("div",null,"CodeMirror-measure"),s.lineMeasure=D("div",null,"CodeMirror-measure"),s.lineSpace=L("div",[s.measure,s.lineMeasure,s.selectionDiv,s.cursorDiv,s.lineDiv],null,"position: relative; outline: none");var l=L("div",[s.lineSpace],"CodeMirror-lines");s.mover=D("div",[l],null,"position: relative"),s.sizer=D("div",[s.mover],"CodeMirror-sizer"),s.sizerWidth=null,s.heightForcer=D("div",null,null,"position: absolute; height: 30px; width: 1px;"),s.gutters=D("div",null,"CodeMirror-gutters"),s.lineGutter=null,s.scroller=D("div",[s.sizer,s.heightForcer,s.gutters],"CodeMirror-scroll"),s.scroller.setAttribute("tabIndex","-1"),s.wrapper=D("div",[s.scrollbarFiller,s.gutterFiller,s.scroller],"CodeMirror"),o&&a<8&&(s.gutters.style.zIndex=-1,s.scroller.style.paddingRight=0),c||n&&v||(s.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(s.wrapper):e(s.wrapper)),s.viewFrom=s.viewTo=t.first,s.reportedViewFrom=s.reportedViewTo=t.first,s.view=[],s.renderedView=null,s.externalMeasured=null,s.viewOffset=0,s.lastWrapHeight=s.lastWrapWidth=0,s.updateLineNumbers=null,s.nativeBarWidth=s.barHeight=s.barWidth=0,s.scrollbarsClipped=!1,s.lineNumWidth=s.lineNumInnerWidth=s.lineNumChars=null,s.alignWidgets=!1,s.cachedCharWidth=s.cachedTextHeight=s.cachedPaddingH=null,s.maxLine=null,s.maxLineLength=0,s.maxLineChanged=!1,s.wheelDX=s.wheelDY=s.wheelStartX=s.wheelStartY=null,s.shift=!1,s.selForContextMenu=null,s.activeTouch=null,s.gutterSpecs=pr(r.gutters,r.lineNumbers),fr(s),i.init(s)}sr.prototype.signal=function(e,t){ve(e,t)&&this.events.push(arguments)},sr.prototype.finish=function(){for(var e=0;e<this.events.length;e++)fe.apply(null,this.events[e])};var vr=0,br=null;function yr(e){var t=e.wheelDeltaX,n=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==n&&e.detail&&e.axis==e.VERTICAL_AXIS?n=e.detail:null==n&&(n=e.wheelDelta),{x:t,y:n}}function Sr(e){var t=yr(e);return t.x*=br,t.y*=br,t}function wr(e,t){var i=yr(t),r=i.x,s=i.y,o=e.display,a=o.scroller,l=a.scrollWidth>a.clientWidth,d=a.scrollHeight>a.clientHeight;if(r&&l||s&&d){if(s&&b&&c)e:for(var h=t.target,p=o.view;h!=a;h=h.parentNode)for(var f=0;f<p.length;f++)if(p[f].node==h){e.display.currentWheelTarget=h;break e}if(r&&!n&&!u&&null!=br)return s&&d&&Ri(e,Math.max(0,a.scrollTop+s*br)),Vi(e,Math.max(0,a.scrollLeft+r*br)),(!s||s&&d)&&ye(t),void(o.wheelStartX=null);if(s&&null!=br){var m=s*br,g=e.doc.scrollTop,v=g+o.wrapper.clientHeight;m<0?g=Math.max(0,g+m-50):v=Math.min(e.doc.height,v+m+50),cr(e,{top:g,bottom:v})}vr<20&&(null==o.wheelStartX?(o.wheelStartX=a.scrollLeft,o.wheelStartY=a.scrollTop,o.wheelDX=r,o.wheelDY=s,setTimeout((function(){if(null!=o.wheelStartX){var e=a.scrollLeft-o.wheelStartX,t=a.scrollTop-o.wheelStartY,n=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,n&&(br=(br*vr+n)/(vr+1),++vr)}}),200)):(o.wheelDX+=r,o.wheelDY+=s))}}o?br=-.53:n?br=15:d?br=-.7:h&&(br=-1/3);var xr=function(e,t){this.ranges=e,this.primIndex=t};xr.prototype.primary=function(){return this.ranges[this.primIndex]},xr.prototype.equals=function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t<this.ranges.length;t++){var n=this.ranges[t],i=e.ranges[t];if(!nt(n.anchor,i.anchor)||!nt(n.head,i.head))return!1}return!0},xr.prototype.deepCopy=function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new Cr(it(this.ranges[t].anchor),it(this.ranges[t].head));return new xr(e,this.primIndex)},xr.prototype.somethingSelected=function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},xr.prototype.contains=function(e,t){t||(t=e);for(var n=0;n<this.ranges.length;n++){var i=this.ranges[n];if(tt(t,i.from())>=0&&tt(e,i.to())<=0)return n}return-1};var Cr=function(e,t){this.anchor=e,this.head=t};function Or(e,t,n){var i=e&&e.options.selectionsMayTouch,r=t[n];t.sort((function(e,t){return tt(e.from(),t.from())})),n=F(t,r);for(var s=1;s<t.length;s++){var o=t[s],a=t[s-1],c=tt(a.to(),o.from());if(i&&!o.empty()?c>0:c>=0){var l=st(a.from(),o.from()),d=rt(a.to(),o.to()),u=a.empty()?o.from()==o.head:a.from()==a.head;s<=n&&--n,t.splice(--s,2,new Cr(u?d:l,u?l:d))}}return new xr(t,n)}function kr(e,t){return new xr([new Cr(e,t||e)],0)}function Er(e){return e.text?et(e.from.line+e.text.length-1,q(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function Tr(e,t){if(tt(e,t.from)<0)return e;if(tt(e,t.to)<=0)return Er(t);var n=e.line+t.text.length-(t.to.line-t.from.line)-1,i=e.ch;return e.line==t.to.line&&(i+=Er(t).ch-t.to.ch),et(n,i)}function Mr(e,t){for(var n=[],i=0;i<e.sel.ranges.length;i++){var r=e.sel.ranges[i];n.push(new Cr(Tr(r.anchor,t),Tr(r.head,t)))}return Or(e.cm,n,e.sel.primIndex)}function Dr(e,t,n){return e.line==t.line?et(n.line,e.ch-t.ch+n.ch):et(n.line+(e.line-t.line),e.ch)}function Lr(e){e.doc.mode=Be(e.options,e.doc.modeOption),jr(e)}function jr(e){e.doc.iter((function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)})),e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first,ir(e,100),e.state.modeGen++,e.curOp&&ui(e)}function Ir(e,t){return 0==t.from.ch&&0==t.to.ch&&""==q(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Pr(e,t,n,i){function r(e){return n?n[e]:null}function s(e,n,r){!function(e,t,n,i){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),Mt(e),Dt(e,n);var r=i?i(e):1;r!=e.height&&Ye(e,r)}(e,n,r,i),cn(e,"change",e,t)}function o(e,t){for(var n=[],s=e;s<t;++s)n.push(new Ht(l[s],r(s),i));return n}var a=t.from,c=t.to,l=t.text,d=He(e,a.line),u=He(e,c.line),h=q(l),p=r(l.length-1),f=c.line-a.line;if(t.full)e.insert(0,o(0,l.length)),e.remove(l.length,e.size-l.length);else if(Ir(e,t)){var m=o(0,l.length-1);s(u,u.text,p),f&&e.remove(a.line,f),m.length&&e.insert(a.line,m)}else if(d==u)if(1==l.length)s(d,d.text.slice(0,a.ch)+h+d.text.slice(c.ch),p);else{var g=o(1,l.length-1);g.push(new Ht(h+d.text.slice(c.ch),p,i)),s(d,d.text.slice(0,a.ch)+l[0],r(0)),e.insert(a.line+1,g)}else if(1==l.length)s(d,d.text.slice(0,a.ch)+l[0]+u.text.slice(c.ch),r(0)),e.remove(a.line+1,f);else{s(d,d.text.slice(0,a.ch)+l[0],r(0)),s(u,h+u.text.slice(c.ch),p);var v=o(1,l.length-1);f>1&&e.remove(a.line+1,f-1),e.insert(a.line+1,v)}cn(e,"change",e,t)}function Ar(e,t,n){!function e(i,r,s){if(i.linked)for(var o=0;o<i.linked.length;++o){var a=i.linked[o];if(a.doc!=r){var c=s&&a.sharedHist;n&&!c||(t(a.doc,c),e(a.doc,i,c))}}}(e,null,!0)}function Rr(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,ci(e),Lr(e),Nr(e),e.options.lineWrapping||Wt(e),e.options.mode=t.modeOption,ui(e)}function Nr(e){("rtl"==e.doc.direction?P:E)(e.display.lineDiv,"CodeMirror-rtl")}function Vr(e){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function _r(e,t){var n={from:it(t.from),to:Er(t),text:Je(e,t.from,t.to)};return Gr(e,n,t.from.line,t.to.line+1),Ar(e,(function(e){return Gr(e,n,t.from.line,t.to.line+1)}),!0),n}function Br(e){for(;e.length&&q(e).ranges;)e.pop()}function Fr(e,t,n,i){var r=e.history;r.undone.length=0;var s,o,a=+new Date;if((r.lastOp==i||r.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&r.lastModTime>a-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(s=function(e,t){return t?(Br(e.done),q(e.done)):e.done.length&&!q(e.done).ranges?q(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),q(e.done)):void 0}(r,r.lastOp==i)))o=q(s.changes),0==tt(t.from,t.to)&&0==tt(t.from,o.to)?o.to=Er(t):s.changes.push(_r(e,t));else{var c=q(r.done);for(c&&c.ranges||Ur(e.sel,r.done),s={changes:[_r(e,t)],generation:r.generation},r.done.push(s);r.done.length>r.undoDepth;)r.done.shift(),r.done[0].ranges||r.done.shift()}r.done.push(n),r.generation=++r.maxGeneration,r.lastModTime=r.lastSelTime=a,r.lastOp=r.lastSelOp=i,r.lastOrigin=r.lastSelOrigin=t.origin,o||fe(e,"historyAdded")}function zr(e,t,n,i){var r=e.history,s=i&&i.origin;n==r.lastSelOp||s&&r.lastSelOrigin==s&&(r.lastModTime==r.lastSelTime&&r.lastOrigin==s||function(e,t,n,i){var r=t.charAt(0);return"*"==r||"+"==r&&n.ranges.length==i.ranges.length&&n.somethingSelected()==i.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}(e,s,q(r.done),t))?r.done[r.done.length-1]=t:Ur(t,r.done),r.lastSelTime=+new Date,r.lastSelOrigin=s,r.lastSelOp=n,i&&!1!==i.clearRedo&&Br(r.undone)}function Ur(e,t){var n=q(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Gr(e,t,n,i){var r=t["spans_"+e.id],s=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,i),(function(n){n.markedSpans&&((r||(r=t["spans_"+e.id]={}))[s]=n.markedSpans),++s}))}function $r(e){if(!e)return null;for(var t,n=0;n<e.length;++n)e[n].marker.explicitlyCleared?t||(t=e.slice(0,n)):t&&t.push(e[n]);return t?t.length?t:null:e}function Wr(e,t){var n=function(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var i=[],r=0;r<t.text.length;++r)i.push($r(n[r]));return i}(e,t),i=Et(e,t);if(!n)return i;if(!i)return n;for(var r=0;r<n.length;++r){var s=n[r],o=i[r];if(s&&o)e:for(var a=0;a<o.length;++a){for(var c=o[a],l=0;l<s.length;++l)if(s[l].marker==c.marker)continue e;s.push(c)}else o&&(n[r]=o)}return n}function Hr(e,t,n){for(var i=[],r=0;r<e.length;++r){var s=e[r];if(s.ranges)i.push(n?xr.prototype.deepCopy.call(s):s);else{var o=s.changes,a=[];i.push({changes:a});for(var c=0;c<o.length;++c){var l=o[c],d=void 0;if(a.push({from:l.from,to:l.to,text:l.text}),t)for(var u in l)(d=u.match(/^spans_(\d+)$/))&&F(t,Number(d[1]))>-1&&(q(a)[u]=l[u],delete l[u])}}}return i}function Jr(e,t,n,i){if(i){var r=e.anchor;if(n){var s=tt(t,r)<0;s!=tt(n,r)<0?(r=t,t=n):s!=tt(t,n)<0&&(t=n)}return new Cr(r,t)}return new Cr(n||t,t)}function qr(e,t,n,i,r){null==r&&(r=e.cm&&(e.cm.display.shift||e.extend)),Zr(e,new xr([Jr(e.sel.primary(),t,n,r)],0),i)}function Yr(e,t,n){for(var i=[],r=e.cm&&(e.cm.display.shift||e.extend),s=0;s<e.sel.ranges.length;s++)i[s]=Jr(e.sel.ranges[s],t[s],null,r);Zr(e,Or(e.cm,i,e.sel.primIndex),n)}function Xr(e,t,n,i){var r=e.sel.ranges.slice(0);r[t]=n,Zr(e,Or(e.cm,r,e.sel.primIndex),i)}function Kr(e,t,n,i){Zr(e,kr(t,n),i)}function Qr(e,t,n){var i=e.history.done,r=q(i);r&&r.ranges?(i[i.length-1]=t,es(e,t,n)):Zr(e,t,n)}function Zr(e,t,n){es(e,t,n),zr(e,e.sel,e.cm?e.cm.curOp.id:NaN,n)}function es(e,t,n){(ve(e,"beforeSelectionChange")||e.cm&&ve(e.cm,"beforeSelectionChange"))&&(t=function(e,t,n){var i={ranges:t.ranges,update:function(t){this.ranges=[];for(var n=0;n<t.length;n++)this.ranges[n]=new Cr(at(e,t[n].anchor),at(e,t[n].head))},origin:n&&n.origin};return fe(e,"beforeSelectionChange",e,i),e.cm&&fe(e.cm,"beforeSelectionChange",e.cm,i),i.ranges!=t.ranges?Or(e.cm,i.ranges,i.ranges.length-1):t}(e,t,n));var i=n&&n.bias||(tt(t.primary().head,e.sel.primary().head)<0?-1:1);ts(e,is(e,t,i,!0)),n&&!1===n.scroll||!e.cm||ji(e.cm)}function ts(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=1,e.cm.curOp.selectionChanged=!0,ge(e.cm)),cn(e,"cursorActivity",e))}function ns(e){ts(e,is(e,e.sel,null,!1))}function is(e,t,n,i){for(var r,s=0;s<t.ranges.length;s++){var o=t.ranges[s],a=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[s],c=ss(e,o.anchor,a&&a.anchor,n,i),l=ss(e,o.head,a&&a.head,n,i);(r||c!=o.anchor||l!=o.head)&&(r||(r=t.ranges.slice(0,s)),r[s]=new Cr(c,l))}return r?Or(e.cm,r,t.primIndex):t}function rs(e,t,n,i,r){var s=He(e,t.line);if(s.markedSpans)for(var o=0;o<s.markedSpans.length;++o){var a=s.markedSpans[o],c=a.marker,l="selectLeft"in c?!c.selectLeft:c.inclusiveLeft,d="selectRight"in c?!c.selectRight:c.inclusiveRight;if((null==a.from||(l?a.from<=t.ch:a.from<t.ch))&&(null==a.to||(d?a.to>=t.ch:a.to>t.ch))){if(r&&(fe(c,"beforeCursorEnter"),c.explicitlyCleared)){if(s.markedSpans){--o;continue}break}if(!c.atomic)continue;if(n){var u=c.find(i<0?1:-1),h=void 0;if((i<0?d:l)&&(u=os(e,u,-i,u&&u.line==t.line?s:null)),u&&u.line==t.line&&(h=tt(u,n))&&(i<0?h<0:h>0))return rs(e,u,t,i,r)}var p=c.find(i<0?-1:1);return(i<0?l:d)&&(p=os(e,p,i,p.line==t.line?s:null)),p?rs(e,p,t,i,r):null}}return t}function ss(e,t,n,i,r){var s=i||1,o=rs(e,t,n,s,r)||!r&&rs(e,t,n,s,!0)||rs(e,t,n,-s,r)||!r&&rs(e,t,n,-s,!0);return o||(e.cantEdit=!0,et(e.first,0))}function os(e,t,n,i){return n<0&&0==t.ch?t.line>e.first?at(e,et(t.line-1)):null:n>0&&t.ch==(i||He(e,t.line)).text.length?t.line<e.first+e.size-1?et(t.line+1,0):null:new et(t.line,t.ch+n)}function as(e){e.setSelection(et(e.firstLine(),0),et(e.lastLine()),U)}function cs(e,t,n){var i={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){return i.canceled=!0}};return n&&(i.update=function(t,n,r,s){t&&(i.from=at(e,t)),n&&(i.to=at(e,n)),r&&(i.text=r),void 0!==s&&(i.origin=s)}),fe(e,"beforeChange",e,i),e.cm&&fe(e.cm,"beforeChange",e.cm,i),i.canceled?(e.cm&&(e.cm.curOp.updateInput=2),null):{from:i.from,to:i.to,text:i.text,origin:i.origin}}function ls(e,t,n){if(e.cm){if(!e.cm.curOp)return er(e.cm,ls)(e,t,n);if(e.cm.state.suppressEdits)return}if(!(ve(e,"beforeChange")||e.cm&&ve(e.cm,"beforeChange"))||(t=cs(e,t,!0))){var i=wt&&!n&&function(e,t,n){var i=null;if(e.iter(t.line,n.line+1,(function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var n=e.markedSpans[t].marker;!n.readOnly||i&&-1!=F(i,n)||(i||(i=[])).push(n)}})),!i)return null;for(var r=[{from:t,to:n}],s=0;s<i.length;++s)for(var o=i[s],a=o.find(0),c=0;c<r.length;++c){var l=r[c];if(!(tt(l.to,a.from)<0||tt(l.from,a.to)>0)){var d=[c,1],u=tt(l.from,a.from),h=tt(l.to,a.to);(u<0||!o.inclusiveLeft&&!u)&&d.push({from:l.from,to:a.from}),(h>0||!o.inclusiveRight&&!h)&&d.push({from:a.to,to:l.to}),r.splice.apply(r,d),c+=d.length-3}}return r}(e,t.from,t.to);if(i)for(var r=i.length-1;r>=0;--r)ds(e,{from:i[r].from,to:i[r].to,text:r?[""]:t.text,origin:t.origin});else ds(e,t)}}function ds(e,t){if(1!=t.text.length||""!=t.text[0]||0!=tt(t.from,t.to)){var n=Mr(e,t);Fr(e,t,n,e.cm?e.cm.curOp.id:NaN),ps(e,t,n,Et(e,t));var i=[];Ar(e,(function(e,n){n||-1!=F(i,e.history)||(vs(e.history,t),i.push(e.history)),ps(e,t,null,Et(e,t))}))}}function us(e,t,n){var i=e.cm&&e.cm.state.suppressEdits;if(!i||n){for(var r,s=e.history,o=e.sel,a="undo"==t?s.done:s.undone,c="undo"==t?s.undone:s.done,l=0;l<a.length&&(r=a[l],n?!r.ranges||r.equals(e.sel):r.ranges);l++);if(l!=a.length){for(s.lastOrigin=s.lastSelOrigin=null;;){if(!(r=a.pop()).ranges){if(i)return void a.push(r);break}if(Ur(r,c),n&&!r.equals(e.sel))return void Zr(e,r,{clearRedo:!1});o=r}var d=[];Ur(o,c),c.push({changes:d,generation:s.generation}),s.generation=r.generation||++s.maxGeneration;for(var u=ve(e,"beforeChange")||e.cm&&ve(e.cm,"beforeChange"),h=function(n){var i=r.changes[n];if(i.origin=t,u&&!cs(e,i,!1))return a.length=0,{};d.push(_r(e,i));var s=n?Mr(e,i):q(a);ps(e,i,s,Wr(e,i)),!n&&e.cm&&e.cm.scrollIntoView({from:i.from,to:Er(i)});var o=[];Ar(e,(function(e,t){t||-1!=F(o,e.history)||(vs(e.history,i),o.push(e.history)),ps(e,i,null,Wr(e,i))}))},p=r.changes.length-1;p>=0;--p){var f=h(p);if(f)return f.v}}}}function hs(e,t){if(0!=t&&(e.first+=t,e.sel=new xr(Y(e.sel.ranges,(function(e){return new Cr(et(e.anchor.line+t,e.anchor.ch),et(e.head.line+t,e.head.ch))})),e.sel.primIndex),e.cm)){ui(e.cm,e.first,e.first-t,t);for(var n=e.cm.display,i=n.viewFrom;i<n.viewTo;i++)hi(e.cm,i,"gutter")}}function ps(e,t,n,i){if(e.cm&&!e.cm.curOp)return er(e.cm,ps)(e,t,n,i);if(t.to.line<e.first)hs(e,t.text.length-1-(t.to.line-t.from.line));else if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var r=t.text.length-1-(e.first-t.from.line);hs(e,r),t={from:et(e.first,0),to:et(t.to.line+r,t.to.ch),text:[q(t.text)],origin:t.origin}}var s=e.lastLine();t.to.line>s&&(t={from:t.from,to:et(s,He(e,s).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Je(e,t.from,t.to),n||(n=Mr(e,t)),e.cm?function(e,t,n){var i=e.doc,r=e.display,s=t.from,o=t.to,a=!1,c=s.line;e.options.lineWrapping||(c=Xe(_t(He(i,s.line))),i.iter(c,o.line+1,(function(e){if(e==r.maxLine)return a=!0,!0}))),i.sel.contains(t.from,t.to)>-1&&ge(e),Pr(i,t,n,ai(e)),e.options.lineWrapping||(i.iter(c,s.line+t.text.length,(function(e){var t=$t(e);t>r.maxLineLength&&(r.maxLine=e,r.maxLineLength=t,r.maxLineChanged=!0,a=!1)})),a&&(e.curOp.updateMaxLine=!0)),function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),!(e.highlightFrontier<t-10)){for(var n=e.first,i=t-1;i>n;i--){var r=He(e,i).stateAfter;if(r&&(!(r instanceof lt)||i+r.lookAhead<t)){n=i+1;break}}e.highlightFrontier=Math.min(e.highlightFrontier,n)}}(i,s.line),ir(e,400);var l=t.text.length-(o.line-s.line)-1;t.full?ui(e):s.line!=o.line||1!=t.text.length||Ir(e.doc,t)?ui(e,s.line,o.line+1,l):hi(e,s.line,"text");var d=ve(e,"changes"),u=ve(e,"change");if(u||d){var h={from:s,to:o,text:t.text,removed:t.removed,origin:t.origin};u&&cn(e,"change",e,h),d&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(h)}e.display.selForContextMenu=null}(e.cm,t,i):Pr(e,t,i),es(e,n,U),e.cantEdit&&ss(e,et(e.firstLine(),0))&&(e.cantEdit=!1)}}function fs(e,t,n,i,r){var s;i||(i=n),tt(i,n)<0&&(n=(s=[i,n])[0],i=s[1]),"string"==typeof t&&(t=e.splitLines(t)),ls(e,{from:n,to:i,text:t,origin:r})}function ms(e,t,n,i){n<e.line?e.line+=i:t<e.line&&(e.line=t,e.ch=0)}function gs(e,t,n,i){for(var r=0;r<e.length;++r){var s=e[r],o=!0;if(s.ranges){s.copied||((s=e[r]=s.deepCopy()).copied=!0);for(var a=0;a<s.ranges.length;a++)ms(s.ranges[a].anchor,t,n,i),ms(s.ranges[a].head,t,n,i)}else{for(var c=0;c<s.changes.length;++c){var l=s.changes[c];if(n<l.from.line)l.from=et(l.from.line+i,l.from.ch),l.to=et(l.to.line+i,l.to.ch);else if(t<=l.to.line){o=!1;break}}o||(e.splice(0,r+1),r=0)}}}function vs(e,t){var n=t.from.line,i=t.to.line,r=t.text.length-(i-n)-1;gs(e.done,n,i,r),gs(e.undone,n,i,r)}function bs(e,t,n,i){var r=t,s=t;return"number"==typeof t?s=He(e,ot(e,t)):r=Xe(t),null==r?null:(i(s,r)&&e.cm&&hi(e.cm,r,n),s)}function ys(e){this.lines=e,this.parent=null;for(var t=0,n=0;n<e.length;++n)e[n].parent=this,t+=e[n].height;this.height=t}function Ss(e){this.children=e;for(var t=0,n=0,i=0;i<e.length;++i){var r=e[i];t+=r.chunkSize(),n+=r.height,r.parent=this}this.size=t,this.height=n,this.parent=null}Cr.prototype.from=function(){return st(this.anchor,this.head)},Cr.prototype.to=function(){return rt(this.anchor,this.head)},Cr.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch},ys.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var n=e,i=e+t;n<i;++n){var r=this.lines[n];this.height-=r.height,Jt(r),cn(r,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,n){this.height+=n,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var i=0;i<t.length;++i)t[i].parent=this},iterN:function(e,t,n){for(var i=e+t;e<i;++e)if(n(this.lines[e]))return!0}},Ss.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var n=0;n<this.children.length;++n){var i=this.children[n],r=i.chunkSize();if(e<r){var s=Math.min(t,r-e),o=i.height;if(i.removeInner(e,s),this.height-=o-i.height,r==s&&(this.children.splice(n--,1),i.parent=null),0==(t-=s))break;e=0}else e-=r}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof ys))){var a=[];this.collapse(a),this.children=[new ys(a)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t<this.children.length;++t)this.children[t].collapse(e)},insertInner:function(e,t,n){this.size+=t.length,this.height+=n;for(var i=0;i<this.children.length;++i){var r=this.children[i],s=r.chunkSize();if(e<=s){if(r.insertInner(e,t,n),r.lines&&r.lines.length>50){for(var o=r.lines.length%25+25,a=o;a<r.lines.length;){var c=new ys(r.lines.slice(a,a+=25));r.height-=c.height,this.children.splice(++i,0,c),c.parent=this}r.lines=r.lines.slice(0,o),this.maybeSpill()}break}e-=s}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=new Ss(e.children.splice(e.children.length-5,5));if(e.parent){e.size-=t.size,e.height-=t.height;var n=F(e.parent.children,e);e.parent.children.splice(n+1,0,t)}else{var i=new Ss(e.children);i.parent=e,e.children=[i,t],e=i}t.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,n){for(var i=0;i<this.children.length;++i){var r=this.children[i],s=r.chunkSize();if(e<s){var o=Math.min(t,s-e);if(r.iterN(e,o,n))return!0;if(0==(t-=o))break;e=0}else e-=s}}};var ws=function(e,t,n){if(n)for(var i in n)n.hasOwnProperty(i)&&(this[i]=n[i]);this.doc=e,this.node=t};function xs(e,t,n){Gt(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Li(e,n)}ws.prototype.clear=function(){var e=this.doc.cm,t=this.line.widgets,n=this.line,i=Xe(n);if(null!=i&&t){for(var r=0;r<t.length;++r)t[r]==this&&t.splice(r--,1);t.length||(n.widgets=null);var s=wn(this);Ye(n,Math.max(0,n.height-s)),e&&(Zi(e,(function(){xs(e,n,-s),hi(e,i,"widget")})),cn(e,"lineWidgetCleared",e,this,i))}},ws.prototype.changed=function(){var e=this,t=this.height,n=this.doc.cm,i=this.line;this.height=null;var r=wn(this)-t;r&&(zt(this.doc,i)||Ye(i,i.height+r),n&&Zi(n,(function(){n.curOp.forceUpdate=!0,xs(n,i,r),cn(n,"lineWidgetChanged",n,e,Xe(i))})))},be(ws);var Cs=0,Os=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++Cs};function ks(e,t,n,i,r){if(i&&i.shared)return function(e,t,n,i,r){(i=V(i)).shared=!1;var s=[ks(e,t,n,i,r)],o=s[0],a=i.widgetNode;return Ar(e,(function(e){a&&(i.widgetNode=a.cloneNode(!0)),s.push(ks(e,at(e,t),at(e,n),i,r));for(var c=0;c<e.linked.length;++c)if(e.linked[c].isParent)return;o=q(s)})),new Es(s,o)}(e,t,n,i,r);if(e.cm&&!e.cm.curOp)return er(e.cm,ks)(e,t,n,i,r);var s=new Os(e,r),o=tt(t,n);if(i&&V(i,s,!1),o>0||0==o&&!1!==s.clearWhenEmpty)return s;if(s.replacedWith&&(s.collapsed=!0,s.widgetNode=L("span",[s.replacedWith],"CodeMirror-widget"),i.handleMouseEvents||s.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(s.widgetNode.insertLeft=!0)),s.collapsed){if(Vt(e,t.line,t,n,s)||t.line!=n.line&&Vt(e,n.line,t,n,s))throw new Error("Inserting collapsed marker partially overlapping an existing one");xt=!0}s.addToHistory&&Fr(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var a,c=t.line,l=e.cm;if(e.iter(c,n.line+1,(function(e){l&&s.collapsed&&!l.options.lineWrapping&&_t(e)==l.display.maxLine&&(a=!0),s.collapsed&&c!=t.line&&Ye(e,0),function(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}(e,new Ct(s,c==t.line?t.ch:null,c==n.line?n.ch:null)),++c})),s.collapsed&&e.iter(t.line,n.line+1,(function(t){zt(e,t)&&Ye(t,0)})),s.clearOnEnter&&ue(s,"beforeCursorEnter",(function(){return s.clear()})),s.readOnly&&(wt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),s.collapsed&&(s.id=++Cs,s.atomic=!0),l){if(a&&(l.curOp.updateMaxLine=!0),s.collapsed)ui(l,t.line,n.line+1);else if(s.className||s.startStyle||s.endStyle||s.css||s.attributes||s.title)for(var d=t.line;d<=n.line;d++)hi(l,d,"text");s.atomic&&ns(l.doc),cn(l,"markerAdded",l,s)}return s}Os.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Hi(e),ve(this,"clear")){var n=this.find();n&&cn(this,"clear",n.from,n.to)}for(var i=null,r=null,s=0;s<this.lines.length;++s){var o=this.lines[s],a=Ot(o.markedSpans,this);e&&!this.collapsed?hi(e,Xe(o),"text"):e&&(null!=a.to&&(r=Xe(o)),null!=a.from&&(i=Xe(o))),o.markedSpans=kt(o.markedSpans,a),null==a.from&&this.collapsed&&!zt(this.doc,o)&&e&&Ye(o,ii(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var c=0;c<this.lines.length;++c){var l=_t(this.lines[c]),d=$t(l);d>e.display.maxLineLength&&(e.display.maxLine=l,e.display.maxLineLength=d,e.display.maxLineChanged=!0)}null!=i&&e&&this.collapsed&&ui(e,i,r+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&ns(e.doc)),e&&cn(e,"markerCleared",e,this,i,r),t&&Ji(e),this.parent&&this.parent.clear()}},Os.prototype.find=function(e,t){var n,i;null==e&&"bookmark"==this.type&&(e=1);for(var r=0;r<this.lines.length;++r){var s=this.lines[r],o=Ot(s.markedSpans,this);if(null!=o.from&&(n=et(t?s:Xe(s),o.from),-1==e))return n;if(null!=o.to&&(i=et(t?s:Xe(s),o.to),1==e))return i}return n&&{from:n,to:i}},Os.prototype.changed=function(){var e=this,t=this.find(-1,!0),n=this,i=this.doc.cm;t&&i&&Zi(i,(function(){var r=t.line,s=Xe(t.line),o=jn(i,s);if(o&&(_n(o),i.curOp.selectionChanged=i.curOp.forceUpdate=!0),i.curOp.updateMaxLine=!0,!zt(n.doc,r)&&null!=n.height){var a=n.height;n.height=null;var c=wn(n)-a;c&&Ye(r,r.height+c)}cn(i,"markerChanged",i,e)}))},Os.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&-1!=F(t.maybeHiddenMarkers,this)||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},Os.prototype.detachLine=function(e){if(this.lines.splice(F(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}},be(Os);var Es=function(e,t){this.markers=e,this.primary=t;for(var n=0;n<e.length;++n)e[n].parent=this};function Ts(e){return e.findMarks(et(e.first,0),e.clipPos(et(e.lastLine())),(function(e){return e.parent}))}function Ms(e){for(var t=function(t){var n=e[t],i=[n.primary.doc];Ar(n.primary.doc,(function(e){return i.push(e)}));for(var r=0;r<n.markers.length;r++){var s=n.markers[r];-1==F(i,s.doc)&&(s.parent=null,n.markers.splice(r--,1))}},n=0;n<e.length;n++)t(n)}Es.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();cn(this,"clear")}},Es.prototype.find=function(e,t){return this.primary.find(e,t)},be(Es);var Ds=0,Ls=function(e,t,n,i,r){if(!(this instanceof Ls))return new Ls(e,t,n,i,r);null==n&&(n=0),Ss.call(this,[new ys([new Ht("",null)])]),this.first=n,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.modeFrontier=this.highlightFrontier=n;var s=et(n,0);this.sel=kr(s),this.history=new Vr(null),this.id=++Ds,this.modeOption=t,this.lineSep=i,this.direction="rtl"==r?"rtl":"ltr",this.extend=!1,"string"==typeof e&&(e=this.splitLines(e)),Pr(this,{from:s,to:s,text:e}),Zr(this,kr(s),U)};Ls.prototype=K(Ss.prototype,{constructor:Ls,iter:function(e,t,n){n?this.iterN(e-this.first,t-e,n):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var n=0,i=0;i<t.length;++i)n+=t[i].height;this.insertInner(e-this.first,t,n)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=qe(this,this.first,this.first+this.size);return!1===e?t:t.join(e||this.lineSeparator())},setValue:nr((function(e){var t=et(this.first,0),n=this.first+this.size-1;ls(this,{from:t,to:et(n,He(this,n).text.length),text:this.splitLines(e),origin:"setValue",full:!0},!0),this.cm&&Ii(this.cm,0,0),Zr(this,kr(t),U)})),replaceRange:function(e,t,n,i){fs(this,e,t=at(this,t),n=n?at(this,n):t,i)},getRange:function(e,t,n){var i=Je(this,at(this,e),at(this,t));return!1===n?i:i.join(n||this.lineSeparator())},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(Qe(this,e))return He(this,e)},getLineNumber:function(e){return Xe(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=He(this,e)),_t(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return at(this,e)},getCursor:function(e){var t=this.sel.primary();return null==e||"head"==e?t.head:"anchor"==e?t.anchor:"end"==e||"to"==e||!1===e?t.to():t.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:nr((function(e,t,n){Kr(this,at(this,"number"==typeof e?et(e,t||0):e),null,n)})),setSelection:nr((function(e,t,n){Kr(this,at(this,e),at(this,t||e),n)})),extendSelection:nr((function(e,t,n){qr(this,at(this,e),t&&at(this,t),n)})),extendSelections:nr((function(e,t){Yr(this,ct(this,e),t)})),extendSelectionsBy:nr((function(e,t){Yr(this,ct(this,Y(this.sel.ranges,e)),t)})),setSelections:nr((function(e,t,n){if(e.length){for(var i=[],r=0;r<e.length;r++)i[r]=new Cr(at(this,e[r].anchor),at(this,e[r].head));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),Zr(this,Or(this.cm,i,t),n)}})),addSelection:nr((function(e,t,n){var i=this.sel.ranges.slice(0);i.push(new Cr(at(this,e),at(this,t||e))),Zr(this,Or(this.cm,i,i.length-1),n)})),getSelection:function(e){for(var t,n=this.sel.ranges,i=0;i<n.length;i++){var r=Je(this,n[i].from(),n[i].to());t=t?t.concat(r):r}return!1===e?t:t.join(e||this.lineSeparator())},getSelections:function(e){for(var t=[],n=this.sel.ranges,i=0;i<n.length;i++){var r=Je(this,n[i].from(),n[i].to());!1!==e&&(r=r.join(e||this.lineSeparator())),t[i]=r}return t},replaceSelection:function(e,t,n){for(var i=[],r=0;r<this.sel.ranges.length;r++)i[r]=e;this.replaceSelections(i,t,n||"+input")},replaceSelections:nr((function(e,t,n){for(var i=[],r=this.sel,s=0;s<r.ranges.length;s++){var o=r.ranges[s];i[s]={from:o.from(),to:o.to(),text:this.splitLines(e[s]),origin:n}}for(var a=t&&"end"!=t&&function(e,t,n){for(var i=[],r=et(e.first,0),s=r,o=0;o<t.length;o++){var a=t[o],c=Dr(a.from,r,s),l=Dr(Er(a),r,s);if(r=a.to,s=l,"around"==n){var d=e.sel.ranges[o],u=tt(d.head,d.anchor)<0;i[o]=new Cr(u?l:c,u?c:l)}else i[o]=new Cr(c,c)}return new xr(i,e.sel.primIndex)}(this,i,t),c=i.length-1;c>=0;c--)ls(this,i[c]);a?Qr(this,a):this.cm&&ji(this.cm)})),undo:nr((function(){us(this,"undo")})),redo:nr((function(){us(this,"redo")})),undoSelection:nr((function(){us(this,"undo",!0)})),redoSelection:nr((function(){us(this,"redo",!0)})),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,n=0,i=0;i<e.done.length;i++)e.done[i].ranges||++t;for(var r=0;r<e.undone.length;r++)e.undone[r].ranges||++n;return{undo:t,redo:n}},clearHistory:function(){this.history=new Vr(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Hr(this.history.done),undone:Hr(this.history.undone)}},setHistory:function(e){var t=this.history=new Vr(this.history.maxGeneration);t.done=Hr(e.done.slice(0),null,!0),t.undone=Hr(e.undone.slice(0),null,!0)},setGutterMarker:nr((function(e,t,n){return bs(this,e,"gutter",(function(e){var i=e.gutterMarkers||(e.gutterMarkers={});return i[t]=n,!n&&te(i)&&(e.gutterMarkers=null),!0}))})),clearGutter:nr((function(e){var t=this;this.iter((function(n){n.gutterMarkers&&n.gutterMarkers[e]&&bs(t,n,"gutter",(function(){return n.gutterMarkers[e]=null,te(n.gutterMarkers)&&(n.gutterMarkers=null),!0}))}))})),lineInfo:function(e){var t;if("number"==typeof e){if(!Qe(this,e))return null;if(t=e,!(e=He(this,e)))return null}else if(null==(t=Xe(e)))return null;return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},addLineClass:nr((function(e,t,n){return bs(this,e,"gutter"==t?"gutter":"class",(function(e){var i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[i]){if(O(n).test(e[i]))return!1;e[i]+=" "+n}else e[i]=n;return!0}))})),removeLineClass:nr((function(e,t,n){return bs(this,e,"gutter"==t?"gutter":"class",(function(e){var i="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass",r=e[i];if(!r)return!1;if(null==n)e[i]=null;else{var s=r.match(O(n));if(!s)return!1;var o=s.index+s[0].length;e[i]=r.slice(0,s.index)+(s.index&&o!=r.length?" ":"")+r.slice(o)||null}return!0}))})),addLineWidget:nr((function(e,t,n){return function(e,t,n,i){var r=new ws(e,n,i),s=e.cm;return s&&r.noHScroll&&(s.display.alignWidgets=!0),bs(e,t,"widget",(function(t){var n=t.widgets||(t.widgets=[]);if(null==r.insertAt?n.push(r):n.splice(Math.min(n.length-1,Math.max(0,r.insertAt)),0,r),r.line=t,s&&!zt(e,t)){var i=Gt(t)<e.scrollTop;Ye(t,t.height+wn(r)),i&&Li(s,r.height),s.curOp.forceUpdate=!0}return!0})),s&&cn(s,"lineWidgetAdded",s,r,"number"==typeof t?t:Xe(t)),r}(this,e,t,n)})),removeLineWidget:function(e){e.clear()},markText:function(e,t,n){return ks(this,at(this,e),at(this,t),n,n&&n.type||"range")},setBookmark:function(e,t){var n={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared,handleMouseEvents:t&&t.handleMouseEvents};return ks(this,e=at(this,e),e,n,"bookmark")},findMarksAt:function(e){var t=[],n=He(this,(e=at(this,e)).line).markedSpans;if(n)for(var i=0;i<n.length;++i){var r=n[i];(null==r.from||r.from<=e.ch)&&(null==r.to||r.to>=e.ch)&&t.push(r.marker.parent||r.marker)}return t},findMarks:function(e,t,n){e=at(this,e),t=at(this,t);var i=[],r=e.line;return this.iter(e.line,t.line+1,(function(s){var o=s.markedSpans;if(o)for(var a=0;a<o.length;a++){var c=o[a];null!=c.to&&r==e.line&&e.ch>=c.to||null==c.from&&r!=e.line||null!=c.from&&r==t.line&&c.from>=t.ch||n&&!n(c.marker)||i.push(c.marker.parent||c.marker)}++r})),i},getAllMarks:function(){var e=[];return this.iter((function(t){var n=t.markedSpans;if(n)for(var i=0;i<n.length;++i)null!=n[i].from&&e.push(n[i].marker)})),e},posFromIndex:function(e){var t,n=this.first,i=this.lineSeparator().length;return this.iter((function(r){var s=r.text.length+i;if(s>e)return t=e,!0;e-=s,++n})),at(this,et(n,t))},indexFromPos:function(e){var t=(e=at(this,e)).ch;if(e.line<this.first||e.ch<0)return 0;var n=this.lineSeparator().length;return this.iter(this.first,e.line,(function(e){t+=e.text.length+n})),t},copy:function(e){var t=new Ls(qe(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep,this.direction);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,n=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<n&&(n=e.to);var i=new Ls(qe(this,t,n),e.mode||this.modeOption,t,this.lineSep,this.direction);return e.sharedHist&&(i.history=this.history),(this.linked||(this.linked=[])).push({doc:i,sharedHist:e.sharedHist}),i.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],function(e,t){for(var n=0;n<t.length;n++){var i=t[n],r=i.find(),s=e.clipPos(r.from),o=e.clipPos(r.to);if(tt(s,o)){var a=ks(e,s,o,i.primary,i.primary.type);i.markers.push(a),a.parent=i}}}(i,Ts(this)),i},unlinkDoc:function(e){if(e instanceof To&&(e=e.doc),this.linked)for(var t=0;t<this.linked.length;++t)if(this.linked[t].doc==e){this.linked.splice(t,1),e.unlinkDoc(this),Ms(Ts(this));break}if(e.history==this.history){var n=[e.id];Ar(e,(function(e){return n.push(e.id)}),!0),e.history=new Vr(null),e.history.done=Hr(this.history.done,n),e.history.undone=Hr(this.history.undone,n)}},iterLinkedDocs:function(e){Ar(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):je(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:nr((function(e){var t;"rtl"!=e&&(e="ltr"),e!=this.direction&&(this.direction=e,this.iter((function(e){return e.order=null})),this.cm&&Zi(t=this.cm,(function(){Nr(t),ui(t)})))}))}),Ls.prototype.eachLine=Ls.prototype.iter;var js=0;function Is(e){var t=this;if(Ps(t),!me(t,e)&&!xn(t.display,e)){ye(e),o&&(js=+new Date);var n=li(t,e,!0),i=e.dataTransfer.files;if(n&&!t.isReadOnly())if(i&&i.length&&window.FileReader&&window.File)for(var r=i.length,s=Array(r),a=0,c=function(e,i){if(!t.options.allowDropFileTypes||-1!=F(t.options.allowDropFileTypes,e.type)){var o=new FileReader;o.onload=er(t,(function(){var e=o.result;if(/[\x00-\x08\x0e-\x1f]{2}/.test(e)&&(e=""),s[i]=e,++a==r){var c={from:n=at(t.doc,n),to:n,text:t.doc.splitLines(s.join(t.doc.lineSeparator())),origin:"paste"};ls(t.doc,c),Qr(t.doc,kr(n,Er(c)))}})),o.readAsText(e)}},l=0;l<r;++l)c(i[l],l);else{if(t.state.draggingText&&t.doc.sel.contains(n)>-1)return t.state.draggingText(e),void setTimeout((function(){return t.display.input.focus()}),20);try{var d=e.dataTransfer.getData("Text");if(d){var u;if(t.state.draggingText&&!t.state.draggingText.copy&&(u=t.listSelections()),es(t.doc,kr(n,n)),u)for(var h=0;h<u.length;++h)fs(t.doc,"",u[h].anchor,u[h].head,"drag");t.replaceSelection(d,"around","paste"),t.display.input.focus()}}catch(e){}}}}function Ps(e){e.display.dragCursor&&(e.display.lineSpace.removeChild(e.display.dragCursor),e.display.dragCursor=null)}function As(e){if(document.getElementsByClassName){for(var t=document.getElementsByClassName("CodeMirror"),n=[],i=0;i<t.length;i++){var r=t[i].CodeMirror;r&&n.push(r)}n.length&&n[0].operation((function(){for(var t=0;t<n.length;t++)e(n[t])}))}}var Rs=!1;function Ns(){var e;Rs||(ue(window,"resize",(function(){null==e&&(e=setTimeout((function(){e=null,As(Vs)}),100))})),ue(window,"blur",(function(){return As(ki)})),Rs=!0)}function Vs(e){var t=e.display;t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize()}for(var _s={3:"Pause",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",106:"*",107:"=",109:"-",110:".",111:"/",145:"ScrollLock",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"},Bs=0;Bs<10;Bs++)_s[Bs+48]=_s[Bs+96]=String(Bs);for(var Fs=65;Fs<=90;Fs++)_s[Fs]=String.fromCharCode(Fs);for(var zs=1;zs<=12;zs++)_s[zs+111]=_s[zs+63235]="F"+zs;var Us={};function Gs(e){var t,n,i,r,s=e.split(/-(?!$)/);e=s[s.length-1];for(var o=0;o<s.length-1;o++){var a=s[o];if(/^(cmd|meta|m)$/i.test(a))r=!0;else if(/^a(lt)?$/i.test(a))t=!0;else if(/^(c|ctrl|control)$/i.test(a))n=!0;else{if(!/^s(hift)?$/i.test(a))throw new Error("Unrecognized modifier name: "+a);i=!0}}return t&&(e="Alt-"+e),n&&(e="Ctrl-"+e),r&&(e="Cmd-"+e),i&&(e="Shift-"+e),e}function $s(e){var t={};for(var n in e)if(e.hasOwnProperty(n)){var i=e[n];if(/^(name|fallthrough|(de|at)tach)$/.test(n))continue;if("..."==i){delete e[n];continue}for(var r=Y(n.split(" "),Gs),s=0;s<r.length;s++){var o=void 0,a=void 0;s==r.length-1?(a=r.join(" "),o=i):(a=r.slice(0,s+1).join(" "),o="...");var c=t[a];if(c){if(c!=o)throw new Error("Inconsistent bindings for "+a)}else t[a]=o}delete e[n]}for(var l in t)e[l]=t[l];return e}function Ws(e,t,n,i){var r=(t=Ys(t)).call?t.call(e,i):t[e];if(!1===r)return"nothing";if("..."===r)return"multi";if(null!=r&&n(r))return"handled";if(t.fallthrough){if("[object Array]"!=Object.prototype.toString.call(t.fallthrough))return Ws(e,t.fallthrough,n,i);for(var s=0;s<t.fallthrough.length;s++){var o=Ws(e,t.fallthrough[s],n,i);if(o)return o}}}function Hs(e){var t="string"==typeof e?e:_s[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t}function Js(e,t,n){var i=e;return t.altKey&&"Alt"!=i&&(e="Alt-"+e),(x?t.metaKey:t.ctrlKey)&&"Ctrl"!=i&&(e="Ctrl-"+e),(x?t.ctrlKey:t.metaKey)&&"Cmd"!=i&&(e="Cmd-"+e),!n&&t.shiftKey&&"Shift"!=i&&(e="Shift-"+e),e}function qs(e,t){if(u&&34==e.keyCode&&e.char)return!1;var n=_s[e.keyCode];return null!=n&&!e.altGraphKey&&(3==e.keyCode&&e.code&&(n=e.code),Js(n,e,t))}function Ys(e){return"string"==typeof e?Us[e]:e}function Xs(e,t){for(var n=e.doc.sel.ranges,i=[],r=0;r<n.length;r++){for(var s=t(n[r]);i.length&&tt(s.from,q(i).to)<=0;){var o=i.pop();if(tt(o.from,s.from)<0){s.from=o.from;break}}i.push(s)}Zi(e,(function(){for(var t=i.length-1;t>=0;t--)fs(e.doc,"",i[t].from,i[t].to,"+delete");ji(e)}))}function Ks(e,t,n){var i=re(e.text,t+n,n);return i<0||i>e.text.length?null:i}function Qs(e,t,n){var i=Ks(e,t.ch,n);return null==i?null:new et(t.line,i,n<0?"after":"before")}function Zs(e,t,n,i,r){if(e){var s=le(n,t.doc.direction);if(s){var o,a=r<0?q(s):s[0],c=r<0==(1==a.level)?"after":"before";if(a.level>0||"rtl"==t.doc.direction){var l=In(t,n);o=r<0?n.text.length-1:0;var d=Pn(t,l,o).top;o=se((function(e){return Pn(t,l,e).top==d}),r<0==(1==a.level)?a.from:a.to-1,o),"before"==c&&(o=Ks(n,o,1))}else o=r<0?a.to:a.from;return new et(i,o,c)}}return new et(i,r<0?n.text.length:0,r<0?"before":"after")}Us.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},Us.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},Us.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Us.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Us.default=b?Us.macDefault:Us.pcDefault;var eo={selectAll:as,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),U)},killLine:function(e){return Xs(e,(function(t){if(t.empty()){var n=He(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line<e.lastLine()?{from:t.head,to:et(t.head.line+1,0)}:{from:t.head,to:et(t.head.line,n)}}return{from:t.from(),to:t.to()}}))},deleteLine:function(e){return Xs(e,(function(t){return{from:et(t.from().line,0),to:at(e.doc,et(t.to().line+1,0))}}))},delLineLeft:function(e){return Xs(e,(function(e){return{from:et(e.from().line,0),to:e.from()}}))},delWrappedLineLeft:function(e){return Xs(e,(function(t){var n=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:n},"div"),to:t.from()}}))},delWrappedLineRight:function(e){return Xs(e,(function(t){var n=e.charCoords(t.head,"div").top+5,i=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div");return{from:t.from(),to:i}}))},undo:function(e){return e.undo()},redo:function(e){return e.redo()},undoSelection:function(e){return e.undoSelection()},redoSelection:function(e){return e.redoSelection()},goDocStart:function(e){return e.extendSelection(et(e.firstLine(),0))},goDocEnd:function(e){return e.extendSelection(et(e.lastLine()))},goLineStart:function(e){return e.extendSelectionsBy((function(t){return to(e,t.head.line)}),{origin:"+move",bias:1})},goLineStartSmart:function(e){return e.extendSelectionsBy((function(t){return no(e,t.head)}),{origin:"+move",bias:1})},goLineEnd:function(e){return e.extendSelectionsBy((function(t){return function(e,t){var n=He(e.doc,t),i=function(e){for(var t;t=Rt(e);)e=t.find(1,!0).line;return e}(n);return i!=n&&(t=Xe(i)),Zs(!0,e,n,t,-1)}(e,t.head.line)}),{origin:"+move",bias:-1})},goLineRight:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")}),$)},goLineLeft:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")}),$)},goLineLeftSmart:function(e){return e.extendSelectionsBy((function(t){var n=e.cursorCoords(t.head,"div").top+5,i=e.coordsChar({left:0,top:n},"div");return i.ch<e.getLine(i.line).search(/\S/)?no(e,t.head):i}),$)},goLineUp:function(e){return e.moveV(-1,"line")},goLineDown:function(e){return e.moveV(1,"line")},goPageUp:function(e){return e.moveV(-1,"page")},goPageDown:function(e){return e.moveV(1,"page")},goCharLeft:function(e){return e.moveH(-1,"char")},goCharRight:function(e){return e.moveH(1,"char")},goColumnLeft:function(e){return e.moveH(-1,"column")},goColumnRight:function(e){return e.moveH(1,"column")},goWordLeft:function(e){return e.moveH(-1,"word")},goGroupRight:function(e){return e.moveH(1,"group")},goGroupLeft:function(e){return e.moveH(-1,"group")},goWordRight:function(e){return e.moveH(1,"word")},delCharBefore:function(e){return e.deleteH(-1,"char")},delCharAfter:function(e){return e.deleteH(1,"char")},delWordBefore:function(e){return e.deleteH(-1,"word")},delWordAfter:function(e){return e.deleteH(1,"word")},delGroupBefore:function(e){return e.deleteH(-1,"group")},delGroupAfter:function(e){return e.deleteH(1,"group")},indentAuto:function(e){return e.indentSelection("smart")},indentMore:function(e){return e.indentSelection("add")},indentLess:function(e){return e.indentSelection("subtract")},insertTab:function(e){return e.replaceSelection("\t")},insertSoftTab:function(e){for(var t=[],n=e.listSelections(),i=e.options.tabSize,r=0;r<n.length;r++){var s=n[r].from(),o=_(e.getLine(s.line),s.ch,i);t.push(J(i-o%i))}e.replaceSelections(t)},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){return Zi(e,(function(){for(var t=e.listSelections(),n=[],i=0;i<t.length;i++)if(t[i].empty()){var r=t[i].head,s=He(e.doc,r.line).text;if(s)if(r.ch==s.length&&(r=new et(r.line,r.ch-1)),r.ch>0)r=new et(r.line,r.ch+1),e.replaceRange(s.charAt(r.ch-1)+s.charAt(r.ch-2),et(r.line,r.ch-2),r,"+transpose");else if(r.line>e.doc.first){var o=He(e.doc,r.line-1).text;o&&(r=new et(r.line,1),e.replaceRange(s.charAt(0)+e.doc.lineSeparator()+o.charAt(o.length-1),et(r.line-1,o.length-1),r,"+transpose"))}n.push(new Cr(r,r))}e.setSelections(n)}))},newlineAndIndent:function(e){return Zi(e,(function(){for(var t=e.listSelections(),n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(var i=0;i<t.length;i++)e.indentLine(t[i].from().line,null,!0);ji(e)}))},openLine:function(e){return e.replaceSelection("\n","start")},toggleOverwrite:function(e){return e.toggleOverwrite()}};function to(e,t){var n=He(e.doc,t),i=_t(n);return i!=n&&(t=Xe(i)),Zs(!0,e,i,t,1)}function no(e,t){var n=to(e,t.line),i=He(e.doc,n.line),r=le(i,e.doc.direction);if(!r||0==r[0].level){var s=Math.max(0,i.text.search(/\S/)),o=t.line==n.line&&t.ch<=s&&t.ch;return et(n.line,o?0:s,n.sticky)}return n}function io(e,t,n){if("string"==typeof t&&!(t=eo[t]))return!1;e.display.input.ensurePolled();var i=e.display.shift,r=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),r=t(e)!=z}finally{e.display.shift=i,e.state.suppressEdits=!1}return r}var ro=new B;function so(e,t,n,i){var r=e.state.keySeq;if(r){if(Hs(t))return"handled";if(/\'$/.test(t)?e.state.keySeq=null:ro.set(50,(function(){e.state.keySeq==r&&(e.state.keySeq=null,e.display.input.reset())})),oo(e,r+" "+t,n,i))return!0}return oo(e,t,n,i)}function oo(e,t,n,i){var r=function(e,t,n){for(var i=0;i<e.state.keyMaps.length;i++){var r=Ws(t,e.state.keyMaps[i],n,e);if(r)return r}return e.options.extraKeys&&Ws(t,e.options.extraKeys,n,e)||Ws(t,e.options.keyMap,n,e)}(e,t,i);return"multi"==r&&(e.state.keySeq=t),"handled"==r&&cn(e,"keyHandled",e,t,n),"handled"!=r&&"multi"!=r||(ye(n),wi(e)),!!r}function ao(e,t){var n=qs(t,!0);return!!n&&(t.shiftKey&&!e.state.keySeq?so(e,"Shift-"+n,t,(function(t){return io(e,t,!0)}))||so(e,n,t,(function(t){if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return io(e,t)})):so(e,n,t,(function(t){return io(e,t)})))}var co=null;function lo(e){var t=this;if(t.curOp.focus=I(),!me(t,e)){o&&a<11&&27==e.keyCode&&(e.returnValue=!1);var i=e.keyCode;t.display.shift=16==i||e.shiftKey;var r=ao(t,e);u&&(co=r?i:null,!r&&88==i&&!Pe&&(b?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),n&&!b&&!r&&46==i&&e.shiftKey&&!e.ctrlKey&&document.execCommand&&document.execCommand("cut"),18!=i||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||function(e){var t=e.display.lineDiv;function n(e){18!=e.keyCode&&e.altKey||(E(t,"CodeMirror-crosshair"),pe(document,"keyup",n),pe(document,"mouseover",n))}P(t,"CodeMirror-crosshair"),ue(document,"keyup",n),ue(document,"mouseover",n)}(t)}}function uo(e){16==e.keyCode&&(this.doc.sel.shift=!1),me(this,e)}function ho(e){var t=this;if(!(xn(t.display,e)||me(t,e)||e.ctrlKey&&!e.altKey||b&&e.metaKey)){var n=e.keyCode,i=e.charCode;if(u&&n==co)return co=null,void ye(e);if(!u||e.which&&!(e.which<10)||!ao(t,e)){var r=String.fromCharCode(null==i?n:i);"\b"!=r&&(function(e,t,n){return so(e,"'"+n+"'",t,(function(t){return io(e,t,!0)}))}(t,e,r)||t.display.input.onKeyPress(e))}}}var po,fo,mo=function(e,t,n){this.time=e,this.pos=t,this.button=n};function go(e){var t=this,n=t.display;if(!(me(t,e)||n.activeTouch&&n.input.supportsTouch()))if(n.input.ensurePolled(),n.shift=e.shiftKey,xn(n,e))c||(n.scroller.draggable=!1,setTimeout((function(){return n.scroller.draggable=!0}),100));else if(!yo(t,e)){var i=li(t,e),r=Oe(e),s=i?function(e,t){var n=+new Date;return fo&&fo.compare(n,e,t)?(po=fo=null,"triple"):po&&po.compare(n,e,t)?(fo=new mo(n,e,t),po=null,"double"):(po=new mo(n,e,t),fo=null,"single")}(i,r):"single";window.focus(),1==r&&t.state.selectingText&&t.state.selectingText(e),i&&function(e,t,n,i,r){var s="Click";return"double"==i?s="Double"+s:"triple"==i&&(s="Triple"+s),so(e,Js(s=(1==t?"Left":2==t?"Middle":"Right")+s,r),r,(function(t){if("string"==typeof t&&(t=eo[t]),!t)return!1;var i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),i=t(e,n)!=z}finally{e.state.suppressEdits=!1}return i}))}(t,r,i,s,e)||(1==r?i?function(e,t,n,i){o?setTimeout(N(xi,e),0):e.curOp.focus=I();var r,s=function(e,t,n){var i=e.getOption("configureMouse"),r=i?i(e,t,n):{};if(null==r.unit){var s=y?n.shiftKey&&n.metaKey:n.altKey;r.unit=s?"rectangle":"single"==t?"char":"double"==t?"word":"line"}return(null==r.extend||e.doc.extend)&&(r.extend=e.doc.extend||n.shiftKey),null==r.addNew&&(r.addNew=b?n.metaKey:n.ctrlKey),null==r.moveOnDrag&&(r.moveOnDrag=!(b?n.altKey:n.ctrlKey)),r}(e,n,i),l=e.doc.sel;e.options.dragDrop&&Te&&!e.isReadOnly()&&"single"==n&&(r=l.contains(t))>-1&&(tt((r=l.ranges[r]).from(),t)<0||t.xRel>0)&&(tt(r.to(),t)>0||t.xRel<0)?function(e,t,n,i){var r=e.display,s=!1,l=er(e,(function(t){c&&(r.scroller.draggable=!1),e.state.draggingText=!1,pe(r.wrapper.ownerDocument,"mouseup",l),pe(r.wrapper.ownerDocument,"mousemove",d),pe(r.scroller,"dragstart",u),pe(r.scroller,"drop",l),s||(ye(t),i.addNew||qr(e.doc,n,null,null,i.extend),c||o&&9==a?setTimeout((function(){r.wrapper.ownerDocument.body.focus(),r.input.focus()}),20):r.input.focus())})),d=function(e){s=s||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},u=function(){return s=!0};c&&(r.scroller.draggable=!0),e.state.draggingText=l,l.copy=!i.moveOnDrag,r.scroller.dragDrop&&r.scroller.dragDrop(),ue(r.wrapper.ownerDocument,"mouseup",l),ue(r.wrapper.ownerDocument,"mousemove",d),ue(r.scroller,"dragstart",u),ue(r.scroller,"drop",l),Ci(e),setTimeout((function(){return r.input.focus()}),20)}(e,i,t,s):function(e,t,n,i){var r=e.display,s=e.doc;ye(t);var o,a,c=s.sel,l=c.ranges;if(i.addNew&&!i.extend?(a=s.sel.contains(n),o=a>-1?l[a]:new Cr(n,n)):(o=s.sel.primary(),a=s.sel.primIndex),"rectangle"==i.unit)i.addNew||(o=new Cr(n,n)),n=li(e,t,!0,!0),a=-1;else{var d=vo(e,n,i.unit);o=i.extend?Jr(o,d.anchor,d.head,i.extend):d}i.addNew?-1==a?(a=l.length,Zr(s,Or(e,l.concat([o]),a),{scroll:!1,origin:"*mouse"})):l.length>1&&l[a].empty()&&"char"==i.unit&&!i.extend?(Zr(s,Or(e,l.slice(0,a).concat(l.slice(a+1)),0),{scroll:!1,origin:"*mouse"}),c=s.sel):Xr(s,a,o,G):(a=0,Zr(s,new xr([o],0),G),c=s.sel);var u=n;function h(t){if(0!=tt(u,t))if(u=t,"rectangle"==i.unit){for(var r=[],l=e.options.tabSize,d=_(He(s,n.line).text,n.ch,l),h=_(He(s,t.line).text,t.ch,l),p=Math.min(d,h),f=Math.max(d,h),m=Math.min(n.line,t.line),g=Math.min(e.lastLine(),Math.max(n.line,t.line));m<=g;m++){var v=He(s,m).text,b=W(v,p,l);p==f?r.push(new Cr(et(m,b),et(m,b))):v.length>b&&r.push(new Cr(et(m,b),et(m,W(v,f,l))))}r.length||r.push(new Cr(n,n)),Zr(s,Or(e,c.ranges.slice(0,a).concat(r),a),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var y,S=o,w=vo(e,t,i.unit),x=S.anchor;tt(w.anchor,x)>0?(y=w.head,x=st(S.from(),w.anchor)):(y=w.anchor,x=rt(S.to(),w.head));var C=c.ranges.slice(0);C[a]=function(e,t){var n=t.anchor,i=t.head,r=He(e.doc,n.line);if(0==tt(n,i)&&n.sticky==i.sticky)return t;var s=le(r);if(!s)return t;var o=ae(s,n.ch,n.sticky),a=s[o];if(a.from!=n.ch&&a.to!=n.ch)return t;var c,l=o+(a.from==n.ch==(1!=a.level)?0:1);if(0==l||l==s.length)return t;if(i.line!=n.line)c=(i.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{var d=ae(s,i.ch,i.sticky),u=d-o||(i.ch-n.ch)*(1==a.level?-1:1);c=d==l-1||d==l?u<0:u>0}var h=s[l+(c?-1:0)],p=c==(1==h.level),f=p?h.from:h.to,m=p?"after":"before";return n.ch==f&&n.sticky==m?t:new Cr(new et(n.line,f,m),i)}(e,new Cr(at(s,x),y)),Zr(s,Or(e,C,a),G)}}var p=r.wrapper.getBoundingClientRect(),f=0;function m(t){e.state.selectingText=!1,f=1/0,t&&(ye(t),r.input.focus()),pe(r.wrapper.ownerDocument,"mousemove",g),pe(r.wrapper.ownerDocument,"mouseup",v),s.history.lastSelOrigin=null}var g=er(e,(function(t){0!==t.buttons&&Oe(t)?function t(n){var o=++f,a=li(e,n,!0,"rectangle"==i.unit);if(a)if(0!=tt(a,u)){e.curOp.focus=I(),h(a);var c=Mi(r,s);(a.line>=c.to||a.line<c.from)&&setTimeout(er(e,(function(){f==o&&t(n)})),150)}else{var l=n.clientY<p.top?-20:n.clientY>p.bottom?20:0;l&&setTimeout(er(e,(function(){f==o&&(r.scroller.scrollTop+=l,t(n))})),50)}}(t):m(t)})),v=er(e,m);e.state.selectingText=v,ue(r.wrapper.ownerDocument,"mousemove",g),ue(r.wrapper.ownerDocument,"mouseup",v)}(e,i,t,s)}(t,i,s,e):Ce(e)==n.scroller&&ye(e):2==r?(i&&qr(t.doc,i),setTimeout((function(){return n.input.focus()}),20)):3==r&&(C?t.display.input.onContextMenu(e):Ci(t)))}}function vo(e,t,n){if("char"==n)return new Cr(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new Cr(et(t.line,0),at(e.doc,et(t.line+1,0)));var i=n(e,t);return new Cr(i.from,i.to)}function bo(e,t,n,i){var r,s;if(t.touches)r=t.touches[0].clientX,s=t.touches[0].clientY;else try{r=t.clientX,s=t.clientY}catch(t){return!1}if(r>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;i&&ye(t);var o=e.display,a=o.lineDiv.getBoundingClientRect();if(s>a.bottom||!ve(e,n))return we(t);s-=a.top-o.viewOffset;for(var c=0;c<e.display.gutterSpecs.length;++c){var l=o.gutters.childNodes[c];if(l&&l.getBoundingClientRect().right>=r)return fe(e,n,e,Ke(e.doc,s),e.display.gutterSpecs[c].className,t),we(t)}}function yo(e,t){return bo(e,t,"gutterClick",!0)}function So(e,t){xn(e.display,t)||function(e,t){return!!ve(e,"gutterContextMenu")&&bo(e,t,"gutterContextMenu",!1)}(e,t)||me(e,t,"contextmenu")||C||e.display.input.onContextMenu(t)}function wo(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Fn(e)}mo.prototype.compare=function(e,t,n){return this.time+400>e&&0==tt(t,this.pos)&&n==this.button};var xo={toString:function(){return"CodeMirror.Init"}},Co={},Oo={};function ko(e,t,n){if(!t!=!(n&&n!=xo)){var i=e.display.dragFunctions,r=t?ue:pe;r(e.display.scroller,"dragstart",i.start),r(e.display.scroller,"dragenter",i.enter),r(e.display.scroller,"dragover",i.over),r(e.display.scroller,"dragleave",i.leave),r(e.display.scroller,"drop",i.drop)}}function Eo(e){e.options.lineWrapping?(P(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(E(e.display.wrapper,"CodeMirror-wrap"),Wt(e)),ci(e),ui(e),Fn(e),setTimeout((function(){return zi(e)}),100)}function To(e,t){var n=this;if(!(this instanceof To))return new To(e,t);this.options=t=t?V(t):{},V(Co,t,!1);var i=t.value;"string"==typeof i?i=new Ls(i,t.mode,null,t.lineSeparator,t.direction):t.mode&&(i.modeOption=t.mode),this.doc=i;var r=new To.inputStyles[t.inputStyle](this),s=this.display=new gr(e,i,r,t);for(var l in s.wrapper.CodeMirror=this,wo(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),$i(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:-1,cutIncoming:-1,selectingText:!1,draggingText:!1,highlight:new B,keySeq:null,specialChars:null},t.autofocus&&!v&&s.input.focus(),o&&a<11&&setTimeout((function(){return n.display.input.reset(!0)}),20),function(e){var t=e.display;ue(t.scroller,"mousedown",er(e,go)),ue(t.scroller,"dblclick",o&&a<11?er(e,(function(t){if(!me(e,t)){var n=li(e,t);if(n&&!yo(e,t)&&!xn(e.display,t)){ye(t);var i=e.findWordAt(n);qr(e.doc,i.anchor,i.head)}}})):function(t){return me(e,t)||ye(t)}),ue(t.scroller,"contextmenu",(function(t){return So(e,t)}));var n,i={end:0};function r(){t.activeTouch&&(n=setTimeout((function(){return t.activeTouch=null}),1e3),(i=t.activeTouch).end=+new Date)}function s(e,t){if(null==t.left)return!0;var n=t.left-e.left,i=t.top-e.top;return n*n+i*i>400}ue(t.scroller,"touchstart",(function(r){if(!me(e,r)&&!function(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}(r)&&!yo(e,r)){t.input.ensurePolled(),clearTimeout(n);var s=+new Date;t.activeTouch={start:s,moved:!1,prev:s-i.end<=300?i:null},1==r.touches.length&&(t.activeTouch.left=r.touches[0].pageX,t.activeTouch.top=r.touches[0].pageY)}})),ue(t.scroller,"touchmove",(function(){t.activeTouch&&(t.activeTouch.moved=!0)})),ue(t.scroller,"touchend",(function(n){var i=t.activeTouch;if(i&&!xn(t,n)&&null!=i.left&&!i.moved&&new Date-i.start<300){var o,a=e.coordsChar(t.activeTouch,"page");o=!i.prev||s(i,i.prev)?new Cr(a,a):!i.prev.prev||s(i,i.prev.prev)?e.findWordAt(a):new Cr(et(a.line,0),at(e.doc,et(a.line+1,0))),e.setSelection(o.anchor,o.head),e.focus(),ye(n)}r()})),ue(t.scroller,"touchcancel",r),ue(t.scroller,"scroll",(function(){t.scroller.clientHeight&&(Ri(e,t.scroller.scrollTop),Vi(e,t.scroller.scrollLeft,!0),fe(e,"scroll",e))})),ue(t.scroller,"mousewheel",(function(t){return wr(e,t)})),ue(t.scroller,"DOMMouseScroll",(function(t){return wr(e,t)})),ue(t.wrapper,"scroll",(function(){return t.wrapper.scrollTop=t.wrapper.scrollLeft=0})),t.dragFunctions={enter:function(t){me(e,t)||xe(t)},over:function(t){me(e,t)||(function(e,t){var n=li(e,t);if(n){var i=document.createDocumentFragment();bi(e,n,i),e.display.dragCursor||(e.display.dragCursor=D("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),M(e.display.dragCursor,i)}}(e,t),xe(t))},start:function(t){return function(e,t){if(o&&(!e.state.draggingText||+new Date-js<100))xe(t);else if(!me(e,t)&&!xn(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!h)){var n=D("img",null,null,"position: fixed; left: 0; top: 0;");n.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",u&&(n.width=n.height=1,e.display.wrapper.appendChild(n),n._top=n.offsetTop),t.dataTransfer.setDragImage(n,0,0),u&&n.parentNode.removeChild(n)}}(e,t)},drop:er(e,Is),leave:function(t){me(e,t)||Ps(e)}};var c=t.input.getField();ue(c,"keyup",(function(t){return uo.call(e,t)})),ue(c,"keydown",er(e,lo)),ue(c,"keypress",er(e,ho)),ue(c,"focus",(function(t){return Oi(e,t)})),ue(c,"blur",(function(t){return ki(e,t)}))}(this),Ns(),Hi(this),this.curOp.forceUpdate=!0,Rr(this,i),t.autofocus&&!v||this.hasFocus()?setTimeout(N(Oi,this),20):ki(this),Oo)Oo.hasOwnProperty(l)&&Oo[l](this,t[l],xo);hr(this),t.finishInit&&t.finishInit(this);for(var d=0;d<Mo.length;++d)Mo[d](this);Ji(this),c&&t.lineWrapping&&"optimizelegibility"==getComputedStyle(s.lineDiv).textRendering&&(s.lineDiv.style.textRendering="auto")}To.defaults=Co,To.optionHandlers=Oo;var Mo=[];function Do(e,t,n,i){var r,s=e.doc;null==n&&(n="add"),"smart"==n&&(s.mode.indent?r=pt(e,t).state:n="prev");var o=e.options.tabSize,a=He(s,t),c=_(a.text,null,o);a.stateAfter&&(a.stateAfter=null);var l,d=a.text.match(/^\s*/)[0];if(i||/\S/.test(a.text)){if("smart"==n&&((l=s.mode.indent(r,a.text.slice(d.length),a.text))==z||l>150)){if(!i)return;n="prev"}}else l=0,n="not";"prev"==n?l=t>s.first?_(He(s,t-1).text,null,o):0:"add"==n?l=c+e.options.indentUnit:"subtract"==n?l=c-e.options.indentUnit:"number"==typeof n&&(l=c+n),l=Math.max(0,l);var u="",h=0;if(e.options.indentWithTabs)for(var p=Math.floor(l/o);p;--p)h+=o,u+="\t";if(h<l&&(u+=J(l-h)),u!=d)return fs(s,u,et(t,0),et(t,d.length),"+input"),a.stateAfter=null,!0;for(var f=0;f<s.sel.ranges.length;f++){var m=s.sel.ranges[f];if(m.head.line==t&&m.head.ch<d.length){var g=et(t,d.length);Xr(s,f,new Cr(g,g));break}}}To.defineInitHook=function(e){return Mo.push(e)};var Lo=null;function jo(e){Lo=e}function Io(e,t,n,i,r){var s=e.doc;e.display.shift=!1,i||(i=s.sel);var o=+new Date-200,a="paste"==r||e.state.pasteIncoming>o,c=je(t),l=null;if(a&&i.ranges.length>1)if(Lo&&Lo.text.join("\n")==t){if(i.ranges.length%Lo.text.length==0){l=[];for(var d=0;d<Lo.text.length;d++)l.push(s.splitLines(Lo.text[d]))}}else c.length==i.ranges.length&&e.options.pasteLinesPerSelection&&(l=Y(c,(function(e){return[e]})));for(var u=e.curOp.updateInput,h=i.ranges.length-1;h>=0;h--){var p=i.ranges[h],f=p.from(),m=p.to();p.empty()&&(n&&n>0?f=et(f.line,f.ch-n):e.state.overwrite&&!a?m=et(m.line,Math.min(He(s,m.line).text.length,m.ch+q(c).length)):a&&Lo&&Lo.lineWise&&Lo.text.join("\n")==t&&(f=m=et(f.line,0)));var g={from:f,to:m,text:l?l[h%l.length]:c,origin:r||(a?"paste":e.state.cutIncoming>o?"cut":"+input")};ls(e.doc,g),cn(e,"inputRead",e,g)}t&&!a&&Ao(e,t),ji(e),e.curOp.updateInput<2&&(e.curOp.updateInput=u),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function Po(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||Zi(t,(function(){return Io(t,n,0,null,"paste")})),!0}function Ao(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,i=n.ranges.length-1;i>=0;i--){var r=n.ranges[i];if(!(r.head.ch>100||i&&n.ranges[i-1].head.line==r.head.line)){var s=e.getModeAt(r.head),o=!1;if(s.electricChars){for(var a=0;a<s.electricChars.length;a++)if(t.indexOf(s.electricChars.charAt(a))>-1){o=Do(e,r.head.line,"smart");break}}else s.electricInput&&s.electricInput.test(He(e.doc,r.head.line).text.slice(0,r.head.ch))&&(o=Do(e,r.head.line,"smart"));o&&cn(e,"electricInput",e,r.head.line)}}}function Ro(e){for(var t=[],n=[],i=0;i<e.doc.sel.ranges.length;i++){var r=e.doc.sel.ranges[i].head.line,s={anchor:et(r,0),head:et(r+1,0)};n.push(s),t.push(e.getRange(s.anchor,s.head))}return{text:t,ranges:n}}function No(e,t,n,i){e.setAttribute("autocorrect",n?"":"off"),e.setAttribute("autocapitalize",i?"":"off"),e.setAttribute("spellcheck",!!t)}function Vo(){var e=D("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"),t=D("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return c?e.style.width="1000px":e.setAttribute("wrap","off"),m&&(e.style.border="1px solid black"),No(e),t}function _o(e,t,n,i,r){var s=t,o=n,a=He(e,t.line);function c(i){var s,o;if(null==(s=r?function(e,t,n,i){var r=le(t,e.doc.direction);if(!r)return Qs(t,n,i);n.ch>=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");var s=ae(r,n.ch,n.sticky),o=r[s];if("ltr"==e.doc.direction&&o.level%2==0&&(i>0?o.to>n.ch:o.from<n.ch))return Qs(t,n,i);var a,c=function(e,n){return Ks(t,e instanceof et?e.ch:e,n)},l=function(n){return e.options.lineWrapping?(a=a||In(e,t),Qn(e,t,a,n)):{begin:0,end:t.text.length}},d=l("before"==n.sticky?c(n,-1):n.ch);if("rtl"==e.doc.direction||1==o.level){var u=1==o.level==i<0,h=c(n,u?1:-1);if(null!=h&&(u?h<=o.to&&h<=d.end:h>=o.from&&h>=d.begin)){var p=u?"before":"after";return new et(n.line,h,p)}}var f=function(e,t,i){for(var s=function(e,t){return t?new et(n.line,c(e,1),"before"):new et(n.line,e,"after")};e>=0&&e<r.length;e+=t){var o=r[e],a=t>0==(1!=o.level),l=a?i.begin:c(i.end,-1);if(o.from<=l&&l<o.to)return s(l,a);if(l=a?o.from:c(o.to,-1),i.begin<=l&&l<i.end)return s(l,a)}},m=f(s+i,i,d);if(m)return m;var g=i>0?d.end:c(d.begin,-1);return null==g||i>0&&g==t.text.length||!(m=f(i>0?0:r.length-1,i,l(g)))?null:m}(e.cm,a,t,n):Qs(a,t,n))){if(i||(o=t.line+n)<e.first||o>=e.first+e.size||(t=new et(o,t.ch,t.sticky),!(a=He(e,o))))return!1;t=Zs(r,e.cm,a,t.line,n)}else t=s;return!0}if("char"==i)c();else if("column"==i)c(!0);else if("word"==i||"group"==i)for(var l=null,d="group"==i,u=e.cm&&e.cm.getHelper(t,"wordChars"),h=!0;!(n<0)||c(!h);h=!1){var p=a.text.charAt(t.ch)||"\n",f=ee(p,u)?"w":d&&"\n"==p?"n":!d||/\s/.test(p)?null:"p";if(!d||h||f||(f="s"),l&&l!=f){n<0&&(n=1,c(),t.sticky="after");break}if(f&&(l=f),n>0&&!c(!h))break}var m=ss(e,t,s,o,!0);return nt(s,m)&&(m.hitSide=!0),m}function Bo(e,t,n,i){var r,s,o=e.doc,a=t.left;if("page"==i){var c=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),l=Math.max(c-.5*ii(e.display),3);r=(n>0?t.bottom:t.top)+n*l}else"line"==i&&(r=n>0?t.bottom+3:t.top-3);for(;(s=Xn(e,a,r)).outside;){if(n<0?r<=0:r>=o.height){s.hitSide=!0;break}r+=5*n}return s}var Fo=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new B,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function zo(e,t){var n=jn(e,t.line);if(!n||n.hidden)return null;var i=He(e.doc,t.line),r=Dn(n,i,t.line),s=le(i,e.doc.direction),o="left";s&&(o=ae(s,t.ch)%2?"right":"left");var a=Nn(r.map,t.ch,o);return a.offset="right"==a.collapse?a.end:a.start,a}function Uo(e,t){return t&&(e.bad=!0),e}function Go(e,t,n){var i;if(t==e.display.lineDiv){if(!(i=e.display.lineDiv.childNodes[n]))return Uo(e.clipPos(et(e.display.viewTo-1)),!0);t=null,n=0}else for(i=t;;i=i.parentNode){if(!i||i==e.display.lineDiv)return null;if(i.parentNode&&i.parentNode==e.display.lineDiv)break}for(var r=0;r<e.display.view.length;r++){var s=e.display.view[r];if(s.node==i)return $o(s,t,n)}}function $o(e,t,n){var i=e.text.firstChild,r=!1;if(!t||!j(i,t))return Uo(et(Xe(e.line),0),!0);if(t==i&&(r=!0,t=i.childNodes[n],n=0,!t)){var s=e.rest?q(e.rest):e.line;return Uo(et(Xe(s),s.text.length),r)}var o=3==t.nodeType?t:null,a=t;for(o||1!=t.childNodes.length||3!=t.firstChild.nodeType||(o=t.firstChild,n&&(n=o.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var c=e.measure,l=c.maps;function d(t,n,i){for(var r=-1;r<(l?l.length:0);r++)for(var s=r<0?c.map:l[r],o=0;o<s.length;o+=3){var a=s[o+2];if(a==t||a==n){var d=Xe(r<0?e.line:e.rest[r]),u=s[o]+i;return(i<0||a!=t)&&(u=s[o+(i?1:0)]),et(d,u)}}}var u=d(o,a,n);if(u)return Uo(u,r);for(var h=a.nextSibling,p=o?o.nodeValue.length-n:0;h;h=h.nextSibling){if(u=d(h,h.firstChild,0))return Uo(et(u.line,u.ch-p),r);p+=h.textContent.length}for(var f=a.previousSibling,m=n;f;f=f.previousSibling){if(u=d(f,f.firstChild,-1))return Uo(et(u.line,u.ch+m),r);m+=f.textContent.length}}Fo.prototype.init=function(e){var t=this,n=this,i=n.cm,r=n.div=e.lineDiv;function s(e){if(!me(i,e)){if(i.somethingSelected())jo({lineWise:!1,text:i.getSelections()}),"cut"==e.type&&i.replaceSelection("",null,"cut");else{if(!i.options.lineWiseCopyCut)return;var t=Ro(i);jo({lineWise:!0,text:t.text}),"cut"==e.type&&i.operation((function(){i.setSelections(t.ranges,0,U),i.replaceSelection("",null,"cut")}))}if(e.clipboardData){e.clipboardData.clearData();var s=Lo.text.join("\n");if(e.clipboardData.setData("Text",s),e.clipboardData.getData("Text")==s)return void e.preventDefault()}var o=Vo(),a=o.firstChild;i.display.lineSpace.insertBefore(o,i.display.lineSpace.firstChild),a.value=Lo.text.join("\n");var c=document.activeElement;R(a),setTimeout((function(){i.display.lineSpace.removeChild(o),c.focus(),c==r&&n.showPrimarySelection()}),50)}}No(r,i.options.spellcheck,i.options.autocorrect,i.options.autocapitalize),ue(r,"paste",(function(e){me(i,e)||Po(e,i)||a<=11&&setTimeout(er(i,(function(){return t.updateFromDOM()})),20)})),ue(r,"compositionstart",(function(e){t.composing={data:e.data,done:!1}})),ue(r,"compositionupdate",(function(e){t.composing||(t.composing={data:e.data,done:!1})})),ue(r,"compositionend",(function(e){t.composing&&(e.data!=t.composing.data&&t.readFromDOMSoon(),t.composing.done=!0)})),ue(r,"touchstart",(function(){return n.forceCompositionEnd()})),ue(r,"input",(function(){t.composing||t.readFromDOMSoon()})),ue(r,"copy",s),ue(r,"cut",s)},Fo.prototype.prepareSelection=function(){var e=vi(this.cm,!1);return e.focus=this.cm.state.focused,e},Fo.prototype.showSelection=function(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))},Fo.prototype.getSelection=function(){return this.cm.display.wrapper.ownerDocument.getSelection()},Fo.prototype.showPrimarySelection=function(){var e=this.getSelection(),t=this.cm,i=t.doc.sel.primary(),r=i.from(),s=i.to();if(t.display.viewTo==t.display.viewFrom||r.line>=t.display.viewTo||s.line<t.display.viewFrom)e.removeAllRanges();else{var o=Go(t,e.anchorNode,e.anchorOffset),a=Go(t,e.focusNode,e.focusOffset);if(!o||o.bad||!a||a.bad||0!=tt(st(o,a),r)||0!=tt(rt(o,a),s)){var c=t.display.view,l=r.line>=t.display.viewFrom&&zo(t,r)||{node:c[0].measure.map[2],offset:0},d=s.line<t.display.viewTo&&zo(t,s);if(!d){var u=c[c.length-1].measure,h=u.maps?u.maps[u.maps.length-1]:u.map;d={node:h[h.length-1],offset:h[h.length-2]-h[h.length-3]}}if(l&&d){var p,f=e.rangeCount&&e.getRangeAt(0);try{p=k(l.node,l.offset,d.offset,d.node)}catch(e){}p&&(!n&&t.state.focused?(e.collapse(l.node,l.offset),p.collapsed||(e.removeAllRanges(),e.addRange(p))):(e.removeAllRanges(),e.addRange(p)),f&&null==e.anchorNode?e.addRange(f):n&&this.startGracePeriod()),this.rememberSelection()}else e.removeAllRanges()}}},Fo.prototype.startGracePeriod=function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout((function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation((function(){return e.cm.curOp.selectionChanged=!0}))}),20)},Fo.prototype.showMultipleSelections=function(e){M(this.cm.display.cursorDiv,e.cursors),M(this.cm.display.selectionDiv,e.selection)},Fo.prototype.rememberSelection=function(){var e=this.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},Fo.prototype.selectionInEditor=function(){var e=this.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return j(this.div,t)},Fo.prototype.focus=function(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()||this.showSelection(this.prepareSelection(),!0),this.div.focus())},Fo.prototype.blur=function(){this.div.blur()},Fo.prototype.getField=function(){return this.div},Fo.prototype.supportsTouch=function(){return!0},Fo.prototype.receivedFocus=function(){var e=this;this.selectionInEditor()?this.pollSelection():Zi(this.cm,(function(){return e.cm.curOp.selectionChanged=!0})),this.polling.set(this.cm.options.pollInterval,(function t(){e.cm.state.focused&&(e.pollSelection(),e.polling.set(e.cm.options.pollInterval,t))}))},Fo.prototype.selectionChanged=function(){var e=this.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},Fo.prototype.pollSelection=function(){if(null==this.readDOMTimeout&&!this.gracePeriod&&this.selectionChanged()){var e=this.getSelection(),t=this.cm;if(g&&d&&this.cm.display.gutterSpecs.length&&function(e){for(var t=e;t;t=t.parentNode)if(/CodeMirror-gutter-wrapper/.test(t.className))return!0;return!1}(e.anchorNode))return this.cm.triggerOnKeyDown({type:"keydown",keyCode:8,preventDefault:Math.abs}),this.blur(),void this.focus();if(!this.composing){this.rememberSelection();var n=Go(t,e.anchorNode,e.anchorOffset),i=Go(t,e.focusNode,e.focusOffset);n&&i&&Zi(t,(function(){Zr(t.doc,kr(n,i),U),(n.bad||i.bad)&&(t.curOp.selectionChanged=!0)}))}}},Fo.prototype.pollContent=function(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);var e,t,n,i=this.cm,r=i.display,s=i.doc.sel.primary(),o=s.from(),a=s.to();if(0==o.ch&&o.line>i.firstLine()&&(o=et(o.line-1,He(i.doc,o.line-1).length)),a.ch==He(i.doc,a.line).text.length&&a.line<i.lastLine()&&(a=et(a.line+1,0)),o.line<r.viewFrom||a.line>r.viewTo-1)return!1;o.line==r.viewFrom||0==(e=di(i,o.line))?(t=Xe(r.view[0].line),n=r.view[0].node):(t=Xe(r.view[e].line),n=r.view[e-1].node.nextSibling);var c,l,d=di(i,a.line);if(d==r.view.length-1?(c=r.viewTo-1,l=r.lineDiv.lastChild):(c=Xe(r.view[d+1].line)-1,l=r.view[d+1].node.previousSibling),!n)return!1;for(var u=i.doc.splitLines(function(e,t,n,i,r){var s="",o=!1,a=e.doc.lineSeparator(),c=!1;function l(){o&&(s+=a,c&&(s+=a),o=c=!1)}function d(e){e&&(l(),s+=e)}function u(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)return void d(n);var s,h=t.getAttribute("cm-marker");if(h){var p=e.findMarks(et(i,0),et(r+1,0),(g=+h,function(e){return e.id==g}));return void(p.length&&(s=p[0].find(0))&&d(Je(e.doc,s.from,s.to).join(a)))}if("false"==t.getAttribute("contenteditable"))return;var f=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;f&&l();for(var m=0;m<t.childNodes.length;m++)u(t.childNodes[m]);/^(pre|p)$/i.test(t.nodeName)&&(c=!0),f&&(o=!0)}else 3==t.nodeType&&d(t.nodeValue.replace(/\u200b/g,"").replace(/\u00a0/g," "));var g}for(;u(t),t!=n;)t=t.nextSibling,c=!1;return s}(i,n,l,t,c)),h=Je(i.doc,et(t,0),et(c,He(i.doc,c).text.length));u.length>1&&h.length>1;)if(q(u)==q(h))u.pop(),h.pop(),c--;else{if(u[0]!=h[0])break;u.shift(),h.shift(),t++}for(var p=0,f=0,m=u[0],g=h[0],v=Math.min(m.length,g.length);p<v&&m.charCodeAt(p)==g.charCodeAt(p);)++p;for(var b=q(u),y=q(h),S=Math.min(b.length-(1==u.length?p:0),y.length-(1==h.length?p:0));f<S&&b.charCodeAt(b.length-f-1)==y.charCodeAt(y.length-f-1);)++f;if(1==u.length&&1==h.length&&t==o.line)for(;p&&p>o.ch&&b.charCodeAt(b.length-f-1)==y.charCodeAt(y.length-f-1);)p--,f++;u[u.length-1]=b.slice(0,b.length-f).replace(/^\u200b+/,""),u[0]=u[0].slice(p).replace(/\u200b+$/,"");var w=et(t,p),x=et(c,h.length?q(h).length-f:0);return u.length>1||u[0]||tt(w,x)?(fs(i.doc,u,w,x,"+input"),!0):void 0},Fo.prototype.ensurePolled=function(){this.forceCompositionEnd()},Fo.prototype.reset=function(){this.forceCompositionEnd()},Fo.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},Fo.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout((function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}e.updateFromDOM()}),80))},Fo.prototype.updateFromDOM=function(){var e=this;!this.cm.isReadOnly()&&this.pollContent()||Zi(this.cm,(function(){return ui(e.cm)}))},Fo.prototype.setUneditable=function(e){e.contentEditable="false"},Fo.prototype.onKeyPress=function(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||er(this.cm,Io)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},Fo.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},Fo.prototype.onContextMenu=function(){},Fo.prototype.resetPosition=function(){},Fo.prototype.needsContentAttribute=!0;var Wo=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new B,this.hasSelection=!1,this.composing=null};Wo.prototype.init=function(e){var t=this,n=this,i=this.cm;this.createField(e);var r=this.textarea;function s(e){if(!me(i,e)){if(i.somethingSelected())jo({lineWise:!1,text:i.getSelections()});else{if(!i.options.lineWiseCopyCut)return;var t=Ro(i);jo({lineWise:!0,text:t.text}),"cut"==e.type?i.setSelections(t.ranges,null,U):(n.prevInput="",r.value=t.text.join("\n"),R(r))}"cut"==e.type&&(i.state.cutIncoming=+new Date)}}e.wrapper.insertBefore(this.wrapper,e.wrapper.firstChild),m&&(r.style.width="0px"),ue(r,"input",(function(){o&&a>=9&&t.hasSelection&&(t.hasSelection=null),n.poll()})),ue(r,"paste",(function(e){me(i,e)||Po(e,i)||(i.state.pasteIncoming=+new Date,n.fastPoll())})),ue(r,"cut",s),ue(r,"copy",s),ue(e.scroller,"paste",(function(t){if(!xn(e,t)&&!me(i,t)){if(!r.dispatchEvent)return i.state.pasteIncoming=+new Date,void n.focus();var s=new Event("paste");s.clipboardData=t.clipboardData,r.dispatchEvent(s)}})),ue(e.lineSpace,"selectstart",(function(t){xn(e,t)||ye(t)})),ue(r,"compositionstart",(function(){var e=i.getCursor("from");n.composing&&n.composing.range.clear(),n.composing={start:e,range:i.markText(e,i.getCursor("to"),{className:"CodeMirror-composing"})}})),ue(r,"compositionend",(function(){n.composing&&(n.poll(),n.composing.range.clear(),n.composing=null)}))},Wo.prototype.createField=function(e){this.wrapper=Vo(),this.textarea=this.wrapper.firstChild},Wo.prototype.prepareSelection=function(){var e=this.cm,t=e.display,n=e.doc,i=vi(e);if(e.options.moveInputWithCursor){var r=Jn(e,n.sel.primary().head,"div"),s=t.wrapper.getBoundingClientRect(),o=t.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+o.top-s.top)),i.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+o.left-s.left))}return i},Wo.prototype.showSelection=function(e){var t=this.cm.display;M(t.cursorDiv,e.cursors),M(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},Wo.prototype.reset=function(e){if(!this.contextMenuPending&&!this.composing){var t=this.cm;if(t.somethingSelected()){this.prevInput="";var n=t.getSelection();this.textarea.value=n,t.state.focused&&R(this.textarea),o&&a>=9&&(this.hasSelection=n)}else e||(this.prevInput=this.textarea.value="",o&&a>=9&&(this.hasSelection=null))}},Wo.prototype.getField=function(){return this.textarea},Wo.prototype.supportsTouch=function(){return!1},Wo.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!v||I()!=this.textarea))try{this.textarea.focus()}catch(e){}},Wo.prototype.blur=function(){this.textarea.blur()},Wo.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Wo.prototype.receivedFocus=function(){this.slowPoll()},Wo.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,(function(){e.poll(),e.cm.state.focused&&e.slowPoll()}))},Wo.prototype.fastPoll=function(){var e=!1,t=this;t.pollingFast=!0,t.polling.set(20,(function n(){t.poll()||e?(t.pollingFast=!1,t.slowPoll()):(e=!0,t.polling.set(60,n))}))},Wo.prototype.poll=function(){var e=this,t=this.cm,n=this.textarea,i=this.prevInput;if(this.contextMenuPending||!t.state.focused||Ie(n)&&!i&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var r=n.value;if(r==i&&!t.somethingSelected())return!1;if(o&&a>=9&&this.hasSelection===r||b&&/[\uf700-\uf7ff]/.test(r))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var s=r.charCodeAt(0);if(8203!=s||i||(i="​"),8666==s)return this.reset(),this.cm.execCommand("undo")}for(var c=0,l=Math.min(i.length,r.length);c<l&&i.charCodeAt(c)==r.charCodeAt(c);)++c;return Zi(t,(function(){Io(t,r.slice(c),i.length-c,null,e.composing?"*compose":null),r.length>1e3||r.indexOf("\n")>-1?n.value=e.prevInput="":e.prevInput=r,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))})),!0},Wo.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Wo.prototype.onKeyPress=function(){o&&a>=9&&(this.hasSelection=null),this.fastPoll()},Wo.prototype.onContextMenu=function(e){var t=this,n=t.cm,i=n.display,r=t.textarea;t.contextMenuPending&&t.contextMenuPending();var s=li(n,e),l=i.scroller.scrollTop;if(s&&!u){n.options.resetSelectionOnContextMenu&&-1==n.doc.sel.contains(s)&&er(n,Zr)(n.doc,kr(s),U);var d,h=r.style.cssText,p=t.wrapper.style.cssText,f=t.wrapper.offsetParent.getBoundingClientRect();if(t.wrapper.style.cssText="position: static",r.style.cssText="position: absolute; width: 30px; height: 30px;\n      top: "+(e.clientY-f.top-5)+"px; left: "+(e.clientX-f.left-5)+"px;\n      z-index: 1000; background: "+(o?"rgba(255, 255, 255, .05)":"transparent")+";\n      outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",c&&(d=window.scrollY),i.input.focus(),c&&window.scrollTo(null,d),i.input.reset(),n.somethingSelected()||(r.value=t.prevInput=" "),t.contextMenuPending=v,i.selForContextMenu=n.doc.sel,clearTimeout(i.detectingSelectAll),o&&a>=9&&g(),C){xe(e);var m=function(){pe(window,"mouseup",m),setTimeout(v,20)};ue(window,"mouseup",m)}else setTimeout(v,50)}function g(){if(null!=r.selectionStart){var e=n.somethingSelected(),s="​"+(e?r.value:"");r.value="⇚",r.value=s,t.prevInput=e?"":"​",r.selectionStart=1,r.selectionEnd=s.length,i.selForContextMenu=n.doc.sel}}function v(){if(t.contextMenuPending==v&&(t.contextMenuPending=!1,t.wrapper.style.cssText=p,r.style.cssText=h,o&&a<9&&i.scrollbars.setScrollTop(i.scroller.scrollTop=l),null!=r.selectionStart)){(!o||o&&a<9)&&g();var e=0,s=function(){i.selForContextMenu==n.doc.sel&&0==r.selectionStart&&r.selectionEnd>0&&"​"==t.prevInput?er(n,as)(n):e++<10?i.detectingSelectAll=setTimeout(s,500):(i.selForContextMenu=null,i.input.reset())};i.detectingSelectAll=setTimeout(s,200)}}},Wo.prototype.readOnlyChanged=function(e){e||this.reset(),this.textarea.disabled="nocursor"==e},Wo.prototype.setUneditable=function(){},Wo.prototype.needsContentAttribute=!1,function(e){var t=e.optionHandlers;function n(n,i,r,s){e.defaults[n]=i,r&&(t[n]=s?function(e,t,n){n!=xo&&r(e,t,n)}:r)}e.defineOption=n,e.Init=xo,n("value","",(function(e,t){return e.setValue(t)}),!0),n("mode",null,(function(e,t){e.doc.modeOption=t,Lr(e)}),!0),n("indentUnit",2,Lr,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,(function(e){jr(e),Fn(e),ui(e)}),!0),n("lineSeparator",null,(function(e,t){if(e.doc.lineSep=t,t){var n=[],i=e.doc.first;e.doc.iter((function(e){for(var r=0;;){var s=e.text.indexOf(t,r);if(-1==s)break;r=s+t.length,n.push(et(i,s))}i++}));for(var r=n.length-1;r>=0;r--)fs(e.doc,t,n[r],et(n[r].line,n[r].ch+t.length))}})),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(function(e,t,n){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=xo&&e.refresh()})),n("specialCharPlaceholder",Qt,(function(e){return e.refresh()}),!0),n("electricChars",!0),n("inputStyle",v?"contenteditable":"textarea",(function(){throw new Error("inputStyle can not (yet) be changed in a running editor")}),!0),n("spellcheck",!1,(function(e,t){return e.getInputField().spellcheck=t}),!0),n("autocorrect",!1,(function(e,t){return e.getInputField().autocorrect=t}),!0),n("autocapitalize",!1,(function(e,t){return e.getInputField().autocapitalize=t}),!0),n("rtlMoveVisually",!S),n("wholeLineUpdateBefore",!0),n("theme","default",(function(e){wo(e),mr(e)}),!0),n("keyMap","default",(function(e,t,n){var i=Ys(t),r=n!=xo&&Ys(n);r&&r.detach&&r.detach(e,i),i.attach&&i.attach(e,r||null)})),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,Eo,!0),n("gutters",[],(function(e,t){e.display.gutterSpecs=pr(t,e.options.lineNumbers),mr(e)}),!0),n("fixedGutter",!0,(function(e,t){e.display.gutters.style.left=t?oi(e.display)+"px":"0",e.refresh()}),!0),n("coverGutterNextToScrollbar",!1,(function(e){return zi(e)}),!0),n("scrollbarStyle","native",(function(e){$i(e),zi(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)}),!0),n("lineNumbers",!1,(function(e,t){e.display.gutterSpecs=pr(e.options.gutters,t),mr(e)}),!0),n("firstLineNumber",1,mr,!0),n("lineNumberFormatter",(function(e){return e}),mr,!0),n("showCursorWhenSelecting",!1,gi,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,(function(e,t){"nocursor"==t&&(ki(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)})),n("disableInput",!1,(function(e,t){t||e.display.input.reset()}),!0),n("dragDrop",!0,ko),n("allowDropFileTypes",null),n("cursorBlinkRate",530),n("cursorScrollMargin",0),n("cursorHeight",1,gi,!0),n("singleCursorHeightPerLine",!0,gi,!0),n("workTime",100),n("workDelay",100),n("flattenSpans",!0,jr,!0),n("addModeClass",!1,jr,!0),n("pollInterval",100),n("undoDepth",200,(function(e,t){return e.doc.history.undoDepth=t})),n("historyEventDelay",1250),n("viewportMargin",10,(function(e){return e.refresh()}),!0),n("maxHighlightLength",1e4,jr,!0),n("moveInputWithCursor",!0,(function(e,t){t||e.display.input.resetPosition()})),n("tabindex",null,(function(e,t){return e.display.input.getField().tabIndex=t||""})),n("autofocus",null),n("direction","ltr",(function(e,t){return e.doc.setDirection(t)}),!0),n("phrases",null)}(To),function(e){var t=e.optionHandlers,n=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,n){var i=this.options,r=i[e];i[e]==n&&"mode"!=e||(i[e]=n,t.hasOwnProperty(e)&&er(this,t[e])(this,n,r),fe(this,"optionChange",this,e))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Ys(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,n=0;n<t.length;++n)if(t[n]==e||t[n].name==e)return t.splice(n,1),!0},addOverlay:tr((function(t,n){var i=t.token?t:e.getMode(this.options,t);if(i.startState)throw new Error("Overlays may not be stateful.");!function(e,t,n){for(var i=0,r=n(t);i<e.length&&n(e[i])<=r;)i++;e.splice(i,0,t)}(this.state.overlays,{mode:i,modeSpec:t,opaque:n&&n.opaque,priority:n&&n.priority||0},(function(e){return e.priority})),this.state.modeGen++,ui(this)})),removeOverlay:tr((function(e){for(var t=this.state.overlays,n=0;n<t.length;++n){var i=t[n].modeSpec;if(i==e||"string"==typeof e&&i.name==e)return t.splice(n,1),this.state.modeGen++,void ui(this)}})),indentLine:tr((function(e,t,n){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),Qe(this.doc,e)&&Do(this,e,t,n)})),indentSelection:tr((function(e){for(var t=this.doc.sel.ranges,n=-1,i=0;i<t.length;i++){var r=t[i];if(r.empty())r.head.line>n&&(Do(this,r.head.line,e,!0),n=r.head.line,i==this.doc.sel.primIndex&&ji(this));else{var s=r.from(),o=r.to(),a=Math.max(n,s.line);n=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(var c=a;c<n;++c)Do(this,c,e);var l=this.doc.sel.ranges;0==s.ch&&t.length==l.length&&l[i].from().ch>0&&Xr(this.doc,i,new Cr(s,l[i].to()),U)}}})),getTokenAt:function(e,t){return bt(this,e,t)},getLineTokens:function(e,t){return bt(this,et(e),t,!0)},getTokenTypeAt:function(e){e=at(this.doc,e);var t,n=ht(this,He(this.doc,e.line)),i=0,r=(n.length-1)/2,s=e.ch;if(0==s)t=n[2];else for(;;){var o=i+r>>1;if((o?n[2*o-1]:0)>=s)r=o;else{if(!(n[2*o+1]<s)){t=n[2*o+2];break}i=o+1}}var a=t?t.indexOf("overlay "):-1;return a<0?t:0==a?null:t.slice(0,a-1)},getModeAt:function(t){var n=this.doc.mode;return n.innerMode?e.innerMode(n,this.getTokenAt(t).state).mode:n},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var i=[];if(!n.hasOwnProperty(t))return i;var r=n[t],s=this.getModeAt(e);if("string"==typeof s[t])r[s[t]]&&i.push(r[s[t]]);else if(s[t])for(var o=0;o<s[t].length;o++){var a=r[s[t][o]];a&&i.push(a)}else s.helperType&&r[s.helperType]?i.push(r[s.helperType]):r[s.name]&&i.push(r[s.name]);for(var c=0;c<r._global.length;c++){var l=r._global[c];l.pred(s,this)&&-1==F(i,l.val)&&i.push(l.val)}return i},getStateAfter:function(e,t){var n=this.doc;return pt(this,(e=ot(n,null==e?n.first+n.size-1:e))+1,t).state},cursorCoords:function(e,t){var n=this.doc.sel.primary();return Jn(this,null==e?n.head:"object"==typeof e?at(this.doc,e):e?n.from():n.to(),t||"page")},charCoords:function(e,t){return Hn(this,at(this.doc,e),t||"page")},coordsChar:function(e,t){return Xn(this,(e=Wn(this,e,t||"page")).left,e.top)},lineAtHeight:function(e,t){return e=Wn(this,{top:e,left:0},t||"page").top,Ke(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t,n){var i,r=!1;if("number"==typeof e){var s=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>s&&(e=s,r=!0),i=He(this.doc,e)}else i=e;return $n(this,i,{top:0,left:0},t||"page",n||r).top+(r?this.doc.height-Gt(i):0)},defaultTextHeight:function(){return ii(this.display)},defaultCharWidth:function(){return ri(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,i,r){var s,o,a,c=this.display,l=(e=Jn(this,at(this.doc,e))).bottom,d=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),c.sizer.appendChild(t),"over"==i)l=e.top;else if("above"==i||"near"==i){var u=Math.max(c.wrapper.clientHeight,this.doc.height),h=Math.max(c.sizer.clientWidth,c.lineSpace.clientWidth);("above"==i||e.bottom+t.offsetHeight>u)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=u&&(l=e.bottom),d+t.offsetWidth>h&&(d=h-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==r?(d=c.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==r?d=0:"middle"==r&&(d=(c.sizer.clientWidth-t.offsetWidth)/2),t.style.left=d+"px"),n&&(s=this,o={left:d,top:l,right:d+t.offsetWidth,bottom:l+t.offsetHeight},null!=(a=Di(s,o)).scrollTop&&Ri(s,a.scrollTop),null!=a.scrollLeft&&Vi(s,a.scrollLeft))},triggerOnKeyDown:tr(lo),triggerOnKeyPress:tr(ho),triggerOnKeyUp:uo,triggerOnMouseDown:tr(go),execCommand:function(e){if(eo.hasOwnProperty(e))return eo[e].call(null,this)},triggerElectric:tr((function(e){Ao(this,e)})),findPosH:function(e,t,n,i){var r=1;t<0&&(r=-1,t=-t);for(var s=at(this.doc,e),o=0;o<t&&!(s=_o(this.doc,s,r,n,i)).hitSide;++o);return s},moveH:tr((function(e,t){var n=this;this.extendSelectionsBy((function(i){return n.display.shift||n.doc.extend||i.empty()?_o(n.doc,i.head,e,t,n.options.rtlMoveVisually):e<0?i.from():i.to()}),$)})),deleteH:tr((function(e,t){var n=this.doc.sel,i=this.doc;n.somethingSelected()?i.replaceSelection("",null,"+delete"):Xs(this,(function(n){var r=_o(i,n.head,e,t,!1);return e<0?{from:r,to:n.head}:{from:n.head,to:r}}))})),findPosV:function(e,t,n,i){var r=1,s=i;t<0&&(r=-1,t=-t);for(var o=at(this.doc,e),a=0;a<t;++a){var c=Jn(this,o,"div");if(null==s?s=c.left:c.left=s,(o=Bo(this,c,r,n)).hitSide)break}return o},moveV:tr((function(e,t){var n=this,i=this.doc,r=[],s=!this.display.shift&&!i.extend&&i.sel.somethingSelected();if(i.extendSelectionsBy((function(o){if(s)return e<0?o.from():o.to();var a=Jn(n,o.head,"div");null!=o.goalColumn&&(a.left=o.goalColumn),r.push(a.left);var c=Bo(n,a,e,t);return"page"==t&&o==i.sel.primary()&&Li(n,Hn(n,c,"div").top-a.top),c}),$),r.length)for(var o=0;o<i.sel.ranges.length;o++)i.sel.ranges[o].goalColumn=r[o]})),findWordAt:function(e){var t=He(this.doc,e.line).text,n=e.ch,i=e.ch;if(t){var r=this.getHelper(e,"wordChars");"before"!=e.sticky&&i!=t.length||!n?++i:--n;for(var s=t.charAt(n),o=ee(s,r)?function(e){return ee(e,r)}:/\s/.test(s)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!ee(e)};n>0&&o(t.charAt(n-1));)--n;for(;i<t.length&&o(t.charAt(i));)++i}return new Cr(et(e.line,n),et(e.line,i))},toggleOverwrite:function(e){null!=e&&e==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?P(this.display.cursorDiv,"CodeMirror-overwrite"):E(this.display.cursorDiv,"CodeMirror-overwrite"),fe(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==I()},isReadOnly:function(){return!(!this.options.readOnly&&!this.doc.cantEdit)},scrollTo:tr((function(e,t){Ii(this,e,t)})),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-En(this)-this.display.barHeight,width:e.scrollWidth-En(this)-this.display.barWidth,clientHeight:Mn(this),clientWidth:Tn(this)}},scrollIntoView:tr((function(e,t){null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:et(e,0),to:null}:null==e.from&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0,null!=e.from.line?function(e,t){Pi(e),e.curOp.scrollToPos=t}(this,e):Ai(this,e.from,e.to,e.margin)})),setSize:tr((function(e,t){var n=this,i=function(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e};null!=e&&(this.display.wrapper.style.width=i(e)),null!=t&&(this.display.wrapper.style.height=i(t)),this.options.lineWrapping&&Bn(this);var r=this.display.viewFrom;this.doc.iter(r,this.display.viewTo,(function(e){if(e.widgets)for(var t=0;t<e.widgets.length;t++)if(e.widgets[t].noHScroll){hi(n,r,"widget");break}++r})),this.curOp.forceUpdate=!0,fe(this,"refresh",this)})),operation:function(e){return Zi(this,e)},startOperation:function(){return Hi(this)},endOperation:function(){return Ji(this)},refresh:tr((function(){var e=this.display.cachedTextHeight;ui(this),this.curOp.forceUpdate=!0,Fn(this),Ii(this,this.doc.scrollLeft,this.doc.scrollTop),lr(this.display),(null==e||Math.abs(e-ii(this.display))>.5)&&ci(this),fe(this,"refresh",this)})),swapDoc:tr((function(e){var t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Rr(this,e),Fn(this),this.display.input.reset(),Ii(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,cn(this,"swapDoc",this,t),t})),phrase:function(e){var t=this.options.phrases;return t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:e},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},be(e),e.registerHelper=function(t,i,r){n.hasOwnProperty(t)||(n[t]=e[t]={_global:[]}),n[t][i]=r},e.registerGlobalHelper=function(t,i,r,s){e.registerHelper(t,i,s),n[t]._global.push({pred:r,val:s})}}(To);var Ho="iter insert remove copy getEditor constructor".split(" ");for(var Jo in Ls.prototype)Ls.prototype.hasOwnProperty(Jo)&&F(Ho,Jo)<0&&(To.prototype[Jo]=function(e){return function(){return e.apply(this.doc,arguments)}}(Ls.prototype[Jo]));return be(Ls),To.inputStyles={textarea:Wo,contenteditable:Fo},To.defineMode=function(e){To.defaults.mode||"null"==e||(To.defaults.mode=e),Ve.apply(this,arguments)},To.defineMIME=function(e,t){Ne[e]=t},To.defineMode("null",(function(){return{token:function(e){return e.skipToEnd()}}})),To.defineMIME("text/plain","null"),To.defineExtension=function(e,t){To.prototype[e]=t},To.defineDocExtension=function(e,t){Ls.prototype[e]=t},To.fromTextArea=function(e,t){if((t=t?V(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){var n=I();t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}function i(){e.value=a.getValue()}var r;if(e.form&&(ue(e.form,"submit",i),!t.leaveSubmitMethodAlone)){var s=e.form;r=s.submit;try{var o=s.submit=function(){i(),s.submit=r,s.submit(),s.submit=o}}catch(e){}}t.finishInit=function(n){n.save=i,n.getTextArea=function(){return e},n.toTextArea=function(){n.toTextArea=isNaN,i(),e.parentNode.removeChild(n.getWrapperElement()),e.style.display="",e.form&&(pe(e.form,"submit",i),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=r))}},e.style.display="none";var a=To((function(t){return e.parentNode.insertBefore(t,e.nextSibling)}),t);return a},function(e){e.off=pe,e.on=ue,e.wheelEventPixels=Sr,e.Doc=Ls,e.splitLines=je,e.countColumn=_,e.findColumn=W,e.isWordChar=Z,e.Pass=z,e.signal=fe,e.Line=Ht,e.changeEnd=Er,e.scrollbarModel=Gi,e.Pos=et,e.cmpPos=tt,e.modes=Re,e.mimeModes=Ne,e.resolveMode=_e,e.getMode=Be,e.modeExtensions=Fe,e.extendMode=ze,e.copyState=Ue,e.startState=$e,e.innerMode=Ge,e.commands=eo,e.keyMap=Us,e.keyName=qs,e.isModifierKey=Hs,e.lookupKey=Ws,e.normalizeKeyMap=$s,e.StringStream=We,e.SharedTextMarker=Es,e.TextMarker=Os,e.LineWidget=ws,e.e_preventDefault=ye,e.e_stopPropagation=Se,e.e_stop=xe,e.addClass=P,e.contains=j,e.rmClass=E,e.keyNames=_s}(To),To.version="5.50.2",To}()},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(2);
/**
 * @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 r(e,t="text/plain"){let n=!1;const r=Object(i.e)(document,"copy",i=>{const{clipboardData:r}=i;null!==r&&(r.setData(t,e),n=!0),i.stopPropagation(),i.preventDefault()},!0);try{document.execCommand("copy")}finally{r()}return n}},function(e,t,n){"use strict";n.d(t,"b",(function(){return o})),n.d(t,"a",(function(){return c}));var i=n(100),r=n(2),s=n(11);n(211);let o=0;const a=s.a.fromObject({escape:{action:"close"}});class c extends r.a{constructor(){super(),this.keyMap=new s.a,this.keyMap.addParent(a,Number.NEGATIVE_INFINITY),++o;let e=this.container=document.createElement("div");e.className="overlay";let t=this.content=document.createElement("div");this.registerDisposer(new i.a(t)),t.className="overlay-content",e.appendChild(t),document.body.appendChild(e),this.registerDisposer(new s.b(this.container,this.keyMap)),this.registerEventListener(e,"action:close",()=>{this.dispose()}),t.focus()}disposed(){--o,document.body.removeChild(this.container),super.disposed()}}},function(e,t,n){"use strict";var i=n(4);
/**
 * @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 r=new Float32Array(1);var s=n(1),o=n(124);function a(e){try{if("string"!=typeof e)throw new Error(`Expected string, but received ${JSON.stringify(e)}.`);const t=document.createElement("canvas").getContext("2d");t.fillStyle=e;const 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(e){const t=/^rgba\(([0-9]+), ([0-9]+), ([0-9]+), (0(?:\.[0-9]+)?)\)$/;{const n=e.match(t);if(null!==n)return[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10),parseFloat(n[4])]}const n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;{const t=e.match(n);if(null!==t)return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16),1]}throw new Error(`Invalid serialized color: ${JSON.stringify(e)}.`)}(t.fillStyle);return s.w.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 c(e){return a(e).subarray(0,3)}function l(e){const t=void 0===e[3]?3:4;let n=0;for(let i=0;i<t;i++)n=(n<<8>>>0)+Math.min(255,Math.max(0,Math.round(255*e[i])));return n}function d(e){if(void 0===e[3]||1===e[3]){let t="#";for(let n=0;n<3;++n)t+=Object(o.c)(Math.min(255,Math.max(0,Math.round(255*e[n]))));return t}{let t="rgba(";for(let n=0;n<3;++n)0!==n&&(t+=", "),t+=Math.min(255,Math.max(0,Math.round(255*e[n])));return t+=`, ${function(e){r[0]=e,e=r[0];for(let t=1;t<21;++t){let n=e.toPrecision(t);if(r[0]=parseFloat(n),r[0]===e)return n}return e.toString()}(e[3])})`,t}}n.d(t,"c",(function(){return c})),n.d(t,"b",(function(){return l})),n.d(t,"d",(function(){return d})),n.d(t,"a",(function(){return u}));class u extends i.e{constructor(e){super(s.u.clone(e)),this.defaultValue=e}toString(){return d(this.value)}toJSON(){return s.u.equals(this.value,this.defaultValue)?void 0:d(this.value)}reset(){this.value=s.u.clone(this.defaultValue)}restoreState(e){if(void 0===e)return void this.reset();const{value:t}=this,n=c(e);s.u.equals(t,n)||(this.value=n)}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"d",(function(){return r})),n.d(t,"a",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"e",(function(){return a}));
/**
 * @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 i="mesh/MeshLayer",r="mesh/MultiscaleMeshLayer",s="mesh/FragmentSource",o="mesh/MultiscaleFragmentSource";var a;!function(e){e[e.float32=0]="float32",e[e.uint10=1]="uint10",e[e.uint16=2]="uint16"}(a||(a={}))},function(e,t,n){"use strict";n.d(t,"d",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"k",(function(){return a})),n.d(t,"f",(function(){return c})),n.d(t,"g",(function(){return l})),n.d(t,"b",(function(){return d})),n.d(t,"a",(function(){return u})),n.d(t,"j",(function(){return h})),n.d(t,"e",(function(){return p})),n.d(t,"h",(function(){return f})),n.d(t,"i",(function(){return m})),n.d(t,"l",(function(){return v}));var i=n(26),r=n(1);
/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const s="annotation.MetadataChunkSource",o="annotation.GeometryChunkSource",a="annotation.SubsetGeometryChunkSource",c="annotation.reference.add",l="annotation.reference.delete",d="annotation.commit",u="annotation.commit",h="annotation/SpatiallyIndexedRenderLayer",p="annotation/PerspectiveRenderLayer:updateSources",f="annotation/RenderLayer",m="annotation/RenderLayer.updateSegmentation",g=r.k.create();function v(e,t,n,s,o,a){const{displayDimensionRenderInfo:c,viewMatrix:l,projectionMat:d,width:u,height:h}=e,{voxelPhysicalScales:p}=c,f=r.k.determinant(Object(r.l)(g,l)),m=Object(r.n)(p),v=Object(r.e)(d)/f*m;if(0===s.length)return;const b=s[0];let y=b.chunkLayout.detTransform*m;const{lowerClipDisplayBound:S,upperClipDisplayBound:w}=b;for(let e=0;e<3;++e)y*=w[e]-S[e];const x=Math.min(y,v),C=u*h,O=C/n**2/x;let k=0;for(let n=s.length-1;n>=0&&k<O;--n){const c=s[n],l=c.source.spec,{chunkLayout:d}=c,u=Object(r.n)(d.size)*d.detTransform*m,{limit:h,rank:p}=l,{nonDisplayLowerClipBound:f,nonDisplayUpperClipBound:g}=c;let v=1;for(let e=0;e<p;++e){const t=g[e]-f[e];Number.isFinite(t)&&(v/=t)}let b=!0;const y=k+h*v/u,S=Math.pow(1/y,1/3),w=Math.sqrt(C/(y*x)),E=(O-k)*u/v,T=Math.min(1,E/l.limit);Object(i.l)(e,t,c,()=>{b&&(o(c,n),b=!1),a(c,n,T,S,w)}),k=y}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(36);
/**
 * @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 r extends i.e{draw(e,t){}isReady(e,t){return!0}get transparentPickEnabled(){return!0}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return c})),n.d(t,"a",(function(){return l}));var i=n(12),r=n(28),s=n(36),o=n(58),a=n(26);
/**
 * @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 c extends s.b{constructor(e,t,n){super(),this.chunkManager=e,this.multiscaleSource=t,this.rpcId=null,this.visibleSources=new Map,this.visibleSourcesList_=[];const{renderScaleTarget:i=Object(r.e)(1)}=n;this.renderScaleTarget=i,this.renderScaleHistogram=n.renderScaleHistogram,this.transform=n.transform,this.localPosition=n.localPosition}getSources(e){return this.multiscaleSource.getSources(e)}addSource(e,t){const{visibleSources:n}=this,i=n.get(e);void 0!==i?++i.refCount:(n.set(e,{source:e,refCount:1,chunkTransform:t}),this.visibleSourcesList_.length=0)}removeSource(e){const{visibleSources:t}=this,n=t.get(e);1!==n.refCount?--n.refCount:(t.delete(e),this.visibleSourcesList_.length=0)}get visibleSourcesList(){const{visibleSources:e,visibleSourcesList_:t}=this;if(0===t.length&&0!==e.size){for(const n of e.values())t.push(n);t.sort((e,t)=>e.chunkTransform.chunkToLayerTransformDet-t.chunkTransform.chunkToLayerTransformDet)}return t}initializeCounterpart(){const e=this.registerDisposer(new i.e(this.layerChunkProgressInfo)),t=this.chunkManager.rpc;e.RPC_TYPE_ID=this.RPC_TYPE_ID,e.initializeCounterpart(t,{localPosition:this.registerDisposer(o.a.makeFromExisting(t,this.localPosition)).rpcId,renderScaleTarget:this.registerDisposer(o.a.makeFromExisting(t,this.renderScaleTarget)).rpcId}),this.rpcId=e.rpcId}get gl(){return this.chunkManager.chunkQueueManager.gl}setGLBlendMode(e,t){t>0&&(e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA))}filterVisibleSources(e,t){return Object(a.j)(e,this,t)}}c.prototype.RPC_TYPE_ID=a.f;class l extends s.e{draw(e,t){}isReady(e,t){return!0}}},function(e,t,n){"use strict";var i=n(160);e.exports={getOrigin:function(e){if(!e)return null;var t=new i(e);if("file:"===t.protocol)return null;var n=t.port;return n||(n="https:"===t.protocol?"443":"80"),t.protocol+"//"+t.hostname+":"+n},isOriginEqual:function(e,t){var n=this.getOrigin(e)===this.getOrigin(t);return n},isSchemeEqual:function(e,t){return e.split(":")[0]===t.split(":")[0]},addPath:function(e,t){var n=e.split("?");return n[0]+t+(n[1]?"?"+n[1]:"")},addQuery:function(e,t){return e+(-1===e.indexOf("?")?"?"+t:"&"+t)}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return d})),n.d(t,"a",(function(){return u}));var i=n(2);
/**
 * @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 r;!function(e){e[e.VERTEX=WebGL2RenderingContext.VERTEX_SHADER]="VERTEX",e[e.FRAGMENT=WebGL2RenderingContext.FRAGMENT_SHADER]="FRAGMENT"}(r||(r={}));class s extends Error{constructor(e,t,n,i){const s=`Error compiling ${r[e].toLowerCase()} shader: ${n}`;super(s),this.name="ShaderCompilationError",this.log=n,this.message=s,this.shaderType=e,this.source=t,this.errorMessages=i}}class o extends Error{constructor(e,t,n){const i=`Error linking shader: ${n}`;super(i),this.name="ShaderLinkError",this.log=n,this.message=i,this.vertexSource=e,this.fragmentSource=t}}function a(e,t,n){var i=e.createShader(n);if(e.shaderSource(i,t),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){let r=e.getShaderInfoLog(i)||"";throw new s(n,t,r,function(e){e=e.replace("\0","");let t=[];for(let n of e.split("\n")){let e=n.match(/^ERROR:\s*(\d+):(\d+)\s*(.+)$/);null!==e?t.push({message:e[3].trim(),file:parseInt(e[1],10),line:parseInt(e[2],10)}):(e=n.match(/^ERROR:\s*(.+)$/),null!==e?t.push({message:e[1]}):(n=n.trim(),n&&t.push({message:n})))}return t}(r))}return i}class c extends i.a{constructor(e,t,n,i,r){super(),this.gl=e,this.vertexSource=t,this.fragmentSource=n,this.attributes=new Map,this.uniforms=new Map,this.vertexShaderInputBinders={};let s=this.vertexShader=a(e,t,e.VERTEX_SHADER),c=this.fragmentShader=a(e,n,e.FRAGMENT_SHADER),l=e.createProgram();if(e.attachShader(l,s),e.attachShader(l,c),e.linkProgram(l),!e.getProgramParameter(l,e.LINK_STATUS)){let i=e.getProgramInfoLog(l)||"";throw new o(t,n,i)}this.program=l;let{uniforms:d,attributes:u}=this;if(i)for(let t of i)d.set(t,e.getUniformLocation(l,t));if(r)for(let t of r)u.set(t,e.getAttribLocation(l,t))}uniform(e){return this.uniforms.get(e)}attribute(e){return this.attributes.get(e)}textureUnit(e){return this.textureUnits.get(e)}bind(){this.gl.useProgram(this.program)}disposed(){let{gl:e}=this;e.deleteShader(this.vertexShader),this.vertexShader=void 0,e.deleteShader(this.fragmentShader),this.fragmentShader=void 0,e.deleteProgram(this.program),this.program=void 0,this.gl=void 0,this.attributes=void 0,this.uniforms=void 0}}class l{constructor(){this.code="",this.parts=new Set}add(e){if(!this.parts.has(e))switch(this.parts.add(e),typeof e){case"string":this.code+=e;break;case"function":this.add(e());break;default:if(!Array.isArray(e))throw console.log("Invalid code type",e),new Error("Invalid code type");for(let t of e)this.add(t)}}toString(){return this.code}}const d={sampler2D:WebGL2RenderingContext.TEXTURE_2D,isampler2D:WebGL2RenderingContext.TEXTURE_2D,usampler2D:WebGL2RenderingContext.TEXTURE_2D,sampler3D:WebGL2RenderingContext.TEXTURE_3D,isampler3D:WebGL2RenderingContext.TEXTURE_3D,usampler3D:WebGL2RenderingContext.TEXTURE_3D};class u{constructor(e){this.gl=e,this.nextSymbolID=0,this.nextTextureUnit=0,this.uniformsCode="",this.attributesCode="",this.varyingsCodeVS="",this.varyingsCodeFS="",this.fragmentExtensionsSet=new Set,this.fragmentExtensions="",this.vertexCode=new l,this.vertexMain="",this.fragmentCode=new l,this.outputBufferCode="",this.fragmentMain="",this.required=new Set,this.uniforms=new Array,this.attributes=new Array,this.initializers=[],this.textureUnits=new Map}allocateTextureUnit(e,t=1){if(this.textureUnits.has(e))throw new Error("Duplicate texture unit symbol: "+e.toString());let n=this.nextTextureUnit;return this.nextTextureUnit+=t,this.textureUnits.set(e,n),n}addTextureSampler(e,t,n,i){let r=this.allocateTextureUnit(n,i);return this.addUniform(`highp ${e}`,t,i),this.addInitializer(e=>{if(i){let n=new Int32Array(i);for(let e=0;e<i;++e)n[e]=e+r;e.gl.uniform1iv(e.uniform(t),n)}else e.gl.uniform1i(e.uniform(t),r)}),r}symbol(e){return e+this.nextSymbolID++}addAttribute(e,t,n){return this.attributes.push(t),void 0!==n&&(this.attributesCode+=`layout(location = ${n})`),this.attributesCode+=`in ${e} ${t};\n`,t}addVarying(e,t,n=""){this.varyingsCodeVS+=`${n} out ${e} ${t};\n`,this.varyingsCodeFS+=`${n} in ${e} ${t};\n`}addOutputBuffer(e,t,n){null!==n&&(this.outputBufferCode+=`layout(location = ${n}) `),this.outputBufferCode+=`out ${e} ${t};\n`}addUniform(e,t,n){return this.uniforms.push(t),this.uniformsCode+=null!=n?`uniform ${e} ${t}[${n}];\n`:`uniform ${e} ${t};\n`,t}addFragmentExtension(e){this.fragmentExtensionsSet.has(e)||(this.fragmentExtensionsSet.add(e),this.fragmentExtensions+=`#extension ${e} : require\n`)}addVertexCode(e){this.vertexCode.add(e)}addFragmentCode(e){this.fragmentCode.add(e)}setVertexMain(e){this.vertexMain=e}addVertexMain(e){this.vertexMain=(this.vertexMain||"")+e}setFragmentMain(e){this.fragmentMain=`void main() {\n${e}\n}\n`}setFragmentMainFunction(e){this.fragmentMain=e}addInitializer(e){this.initializers.push(e)}require(e){this.required.has(e)||(this.required.add(e),e(this))}build(){let e=`#version 300 es\nprecision highp float;\nprecision highp int;\n${this.uniformsCode}\n${this.attributesCode}\n${this.varyingsCodeVS}\n${this.vertexCode}\nvoid main() {\n${this.vertexMain}\n}\n`,t=`#version 300 es\n${this.fragmentExtensions}\nprecision highp float;\nprecision highp int;\n${this.uniformsCode}\n${this.varyingsCodeFS}\n${this.outputBufferCode}\n${this.fragmentCode}\n${this.fragmentMain}\n`,n=new c(this.gl,e,t,this.uniforms,this.attributes);n.textureUnits=this.textureUnits;let{initializers:i}=this;if(i.length>0){n.bind();for(let e of i)e(n)}return n}}},function(e,t,n){"use strict";n.d(t,"d",(function(){return a})),n.d(t,"b",(function(){return l})),n.d(t,"a",(function(){return d})),n.d(t,"c",(function(){return u}));var i=n(1);
/**
 * @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 r=i.u.create(),s=i.u.create();function o(e){let t=0;for(var n=0;n<3;++n)e[n]<0&&(t+=1<<n);return t}const a=new Float32Array([0,0,0,1,0,0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,1,1,1,1]),c=(()=>{const e=[0,1,2,4,5,3,6,7],t=[0,1,2,5,3,4,6,7],n=[0,1,1,4,4,7,4,7,1,5,0,1,1,4,4,7,0,2,2,5,5,7,5,7,2,6,0,2,2,5,5,7,0,3,3,6,6,7,6,7,3,4,0,3,3,6,6,7],i=[0,1,2,3,4,5,6,7,1,4,5,0,3,7,2,6,2,6,0,5,7,3,1,4,3,0,6,4,1,2,7,5,4,3,7,1,0,6,5,2,5,2,1,7,6,0,4,3,6,7,3,2,5,4,0,1,7,5,4,6,2,1,3,0],r=new Int32Array(384);for(let s=0;s<8;++s)for(let o=0;o<n.length;++o){const a=8*t[s]+n[o];r[8*s*6+o]=e[i[a]]}return r})();function l(e){e.addUniform("highp vec3","uPlaneNormal"),e.addUniform("highp float","uPlaneDistance"),e.addUniform("highp ivec2","uVertexIndex",24),e.addUniform("highp vec3","uVertexBasePosition",8),e.addInitializer(e=>{e.gl.uniform3fv(e.uniform("uVertexBasePosition"),a)}),e.addVertexCode("\nvec3 getBoundingBoxPlaneIntersectionVertexPosition(vec3 chunkSize, vec3 boxLower, vec3 lowerClipBound, vec3 upperClipBound, int vertexIndex, float planeDistance) {\n  for (int e = 0; e < 4; ++e) {\n    highp ivec2 vidx = uVertexIndex[vertexIndex*4 + e];\n    highp vec3 v1 = max(lowerClipBound, min(upperClipBound, chunkSize * uVertexBasePosition[vidx.x] + boxLower));\n    highp vec3 v2 = max(lowerClipBound, min(upperClipBound, chunkSize * uVertexBasePosition[vidx.y] + boxLower));\n    highp vec3 vDir = v2 - v1;\n    highp float denom = dot(vDir, uPlaneNormal);\n    if (abs(denom) > 0.001) {\n      highp float lambda = (planeDistance - dot(v1, uPlaneNormal)) / denom;\n      if ((lambda >= -0.001) && (lambda <= (1.0 + 0.001))) {\n        lambda = clamp(lambda, 0.0, 1.0);\n        highp vec3 position = v1 + lambda * vDir;\n        return position;\n      }\n    }\n  }\n  return vec3(0, 0, 0);\n}\nvec3 getBoundingBoxPlaneIntersectionVertexPosition(vec3 chunkSize, vec3 boxLower, vec3 lowerClipBound, vec3 upperClipBound, int vertexIndex) {\n  return getBoundingBoxPlaneIntersectionVertexPosition(chunkSize, boxLower, lowerClipBound, upperClipBound, vertexIndex, uPlaneDistance);\n}\n")}function d(e,t,n,r,s,l,d,u=!0){let h=o(s),p=c.subarray(48*h,48*(h+1)),f=[0,0],m=[i.u.create(),i.u.create()],g=i.u.create(),v=i.u.create(),b=e=>a.subarray(3*e,3*e+3);for(let o=0;o<4;++o){for(let r=0;r<2;++r)f[r]=p[2*(4*d+o)+r],i.u.multiply(m[r],e,b(f[r])),i.u.add(m[r],m[r],l),i.u.min(m[r],m[r],n),i.u.max(m[r],m[r],t);i.u.subtract(g,m[1],m[0]);let a=i.u.dot(g,s);if(Math.abs(a)>.001){let e=(r-i.u.dot(m[0],s))/a;if(e>=-.001&&e<=1.001)return u&&console.log(`vertex ${d}, e = ${o}, good, lambda=${e}, denom=${a}, v0=${m[0].join()}, vDir=${g.join()}`),e=Math.max(0,Math.min(1,e)),i.u.scaleAndAdd(v,m[0],g,e),v;u&&console.log(`vertex ${d}, e = ${o}, skipped, denom = ${a}, `+`vDir = ${g.join()}, v0=${m[0].join()}, v1=${m[1].join()}`+`uPlaneNormal = ${Object(i.v)(s)}, `+`lambda=${e}`)}else u&&console.log(`vertex ${d}, e = ${o}, skipped, deom = ${a}, `+`vDir = ${Object(i.v)(g)}, uPlaneNormal = ${Object(i.v)(s)}, `+`uLowerClipBound=${t.join()}, uUpperClipBound=${n.join()}, `+`chunkSize=${e}, uVertexBasePosition(v0)=${b(f[0]).join()}, `+`uVertexBasePosition(v1)=${b(f[1]).join()}, `+`uTranslation=${l.join()}`)}}function u(e,t,n,a,l){const d=Object(i.s)(r,t,a);i.u.normalize(d,d),function(e,t,n){const{gl:i}=e;i.uniform3fv(e.uniform("uPlaneNormal"),t),i.uniform1f(e.uniform("uPlaneDistance"),n);const r=o(t);i.uniform2iv(e.uniform("uVertexIndex"),c.subarray(48*r,48*(r+1)))}(e,d,i.u.dot(i.u.transformMat4(s,n,l),d))}},function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"c",(function(){return r})),n.d(t,"b",(function(){return s}));
/**
 * @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 i=6,r="\nvec2 getQuadVertexPosition(vec2 lower, vec2 upper) {\n  switch (gl_VertexID % 6) {\n    case 0:\n    case 5:\n      return lower;\n    case 1:\n      return vec2(lower.x, upper.y);\n    case 2:\n    case 3:\n      return vec2(upper.x, upper.y);\n    case 4:\n      return vec2(upper.x, lower.y);\n  }\n}\n";function s(e,t,n){e.drawArraysInstanced(WebGL2RenderingContext.TRIANGLES,0,i*t,n)}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(2),r=n(6);n(214);
/**
 * @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 s extends i.a{constructor(e,{min:t=0,max:n=1,step:i=.01}={}){super(),this.value=e,this.element=document.createElement("label"),this.promptElement=document.createElement("span"),this.inputElement=document.createElement("input"),this.numericInputElement=document.createElement("input");let{element:r,promptElement:s,inputElement:o,numericInputElement:a}=this;r.className="range-slider",s.className="range-prompt";const c=e=>{e.min=""+t,e.max=""+n,e.step=""+i,e.valueAsNumber=this.value.value;const r=()=>{this.value.value=e.valueAsNumber};this.registerEventListener(e,"change",r),this.registerEventListener(e,"input",r),this.registerEventListener(e,"wheel",t=>{let{deltaY:n}=t;n>0?(e.stepUp(),r()):n<0&&(e.stepDown(),r())})};o.type="range",c(o),a.type="number";const l=Math.max(t.toString().length,n.toString().length,Math.min(n,t+i).toString().length,Math.max(t,n-i).toString().length);a.style.width=l+2+"ch",c(a),r.appendChild(s),r.appendChild(o),r.appendChild(a),e.changed.add(()=>{this.inputElement.valueAsNumber=this.value.value,this.numericInputElement.valueAsNumber=this.value.value})}disposed(){Object(r.c)(this.element),super.disposed()}}},function(e,t,n){"use strict";n.d(t,"d",(function(){return c})),n.d(t,"a",(function(){return d})),n.d(t,"c",(function(){return u})),n.d(t,"b",(function(){return h}));var i=n(94),r=n(14),s=n(2),o=n(20),a=n(35);
/**
 * @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 c=[o.o,"\nhighp uint hashCombine(highp uint state, highp uint value) {\n  value *= 0xcc9e2d51u;\n  value = (value << 15u) | (value >> 17u);\n  value *= 0x1b873593u;\n  state ^= value;\n  state = (state << 13u) | (state >> 19u);\n  state = (state * 5u) + 0xe6546b64u;\n  return state;\n}\nhighp uint hashCombine(highp uint state, uint64_t x) {\n  state = hashCombine(state, x.value[0]);\n  return hashCombine(state, x.value[1]);\n}\n"],l=Object(a.d)(new a.c,r.c.UINT64,1);class d extends s.a{constructor(e,t){super(),this.gl=e,this.hashTable=t,this.generation=-1,this.texture=null,this.texture=e.createTexture()}copyToGPU(){let{hashTable:e}=this,{generation:t}=e;if(this.generation===t)return;const{gl:n,texture:i}=this;this.generation=t,n.activeTexture(WebGL2RenderingContext.TEXTURE0+n.tempTextureUnit),n.bindTexture(WebGL2RenderingContext.TEXTURE_2D,i),e.tableWithMungedEmptyKey(e=>{Object(a.f)(this.gl,l,e)}),n.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null)}disposed(){let{gl:e}=this;e.deleteTexture(this.texture),this.texture=null,this.gl=void 0,this.hashTable=void 0,super.disposed()}static get(e,t){return e.memoize.get(t,()=>new this(e,t))}}class u{constructor(e,t=i.c){this.prefix=e,this.numAlternatives=t,this.textureUnitSymbol=Symbol.for(`gpuhashtable:${this.prefix}`),this.accessHelper=new a.a(`gpuhashtable_${this.prefix}`),this.samplerName=this.prefix+"_sampler",this.hashSeedsName=this.prefix+"_seeds",this.hashKeyMask=this.prefix+"_keyMask",this.readTable=this.prefix+"_readTable"}defineShader(e){let{hashSeedsName:t,samplerName:n,numAlternatives:i,hashKeyMask:s}=this;e.addUniform("highp uint",t,i),e.addUniform("highp uint",s),e.addTextureSampler("usampler2D",n,this.textureUnitSymbol),e.addFragmentCode(c),e.addFragmentCode(o.o),e.addFragmentCode(o.d),this.accessHelper.defineShader(e),e.addFragmentCode(this.accessHelper.getAccessor(this.readTable,this.samplerName,r.c.UINT64,1));let a="";a+=`\nbool ${this.hasFunctionName}(uint64_t x) {\n`;for(let e=0;e<i;++e)a+=`\n  {\n    uint h = hashCombine(${t}[${e}], x) & ${s};\n    uint64_t key = ${this.readTable}(h);\n    if (equals(key, x)) {\n      return true;\n    }\n  }\n`;a+="\n  return false;\n}\n",e.addFragmentCode(a)}get hasFunctionName(){return`${this.prefix}_has`}enable(e,t,n){n.copyToGPU();const i=t.textureUnit(this.textureUnitSymbol);e.activeTexture(WebGL2RenderingContext.TEXTURE0+i),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,n.texture),e.uniform1ui(t.uniform(this.hashKeyMask),n.hashTable.tableSize-1),e.uniform1uiv(t.uniform(this.hashSeedsName),n.hashTable.hashSeeds)}disable(e,t){const n=t.textureUnit(this.textureUnitSymbol);e.activeTexture(WebGL2RenderingContext.TEXTURE0+n),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null)}}class h extends u{defineShader(e){super.defineShader(e);let{numAlternatives:t,hashSeedsName:n,hashKeyMask:i}=this,r=`\nbool ${this.getFunctionName}(uint64_t x, out uint64_t value) {\n`;for(let e=0;e<t;++e)r+=`\n  {\n    uint h = hashCombine(${n}[${e}], x) & ${i};\n    uint64_t key = ${this.readTable}(h * 2u);\n    if (equals(key, x)) {\n      value = ${this.readTable}(h * 2u + 1u);\n      return true;\n    }\n  }\n`;r+="\n  return false;\n}\n",e.addFragmentCode(r)}get getFunctionName(){return`${this.prefix}_get`}}},function(e,t,n){"use strict";n.d(t,"c",(function(){return p})),n.d(t,"b",(function(){return v})),n.d(t,"a",(function(){return b}));var i=n(5),r=n(34),s=n(38),o=n(39),a=n(2),c=n(0),l=n(19),d=n(57),u=n(3);
/**
 * @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 h(e){return"boolean"==typeof e?{enabled:e}:(Object(c.w)(e),{enabled:Object(c.B)(e,"enabled",c.n)})}function p(e,t){return"string"==typeof e?{url:e,transform:t,enableDefaultSubsources:!0,subsources:new Map}:(Object(c.w)(e),{url:Object(c.y)(e,"url",c.E),transform:Object(c.y)(e,"transform",i.g)||t,enableDefaultSubsources:Object(c.B)(e,"enableDefaultSubsources",c.n,!0),subsources:Object(c.B)(e,"subsources",e=>Object(c.x)(e,h),new Map)})}function f(e){return e.enabled}function m(e){const t=Object(i.i)(e.transform),n={};let r=!0;for(const[t,i]of e.subsources){const e=f(i);void 0!==e&&(n[t]=e,r=!1)}return void 0===t&&r&&!0===e.enableDefaultSubsources?e.url:{url:e.url,transform:t,subsources:r?void 0:n,enableDefaultSubsources:!0===e.enableDefaultSubsources&&void 0}}class g{constructor(e,t,n,i,r){let s;this.loadedDataSource=e,this.subsourceEntry=t,this.subsourceSpec=n,this.subsourceIndex=i,this.activated=void 0,this.messages=new d.a,this.isActiveChanged=new u.a,s=void 0===n||void 0===n.enabled?t.default&&r:n.enabled;const o=e.dataSource.modelTransform.sourceRank;let{modelSubspaceDimensionIndices:a}=t;if(void 0===a){a=new Array(o);for(let e=0;e<o;++e)a[e]=e}const{subsourceToModelSubspaceTransform:c=l.c(Float32Array,a.length+1)}=t;this.enabled=s,this.subsourceToModelSubspaceTransform=c,this.modelSubspaceDimensionIndices=a,this.isActiveChanged.add(e.activatedSubsourcesChanged.dispatch)}activate(e){if(this.messages.clearMessages(),void 0!==this.activated)return;e(this.activated=new a.a),this.isActiveChanged.dispatch()}deactivate(e){this.messages.clearMessages(),this.messages.addMessage({severity:d.b.error,message:e});const{activated:t}=this;void 0!==t&&(this.activated=void 0,t.dispose(),this.isActiveChanged.dispatch())}addRenderLayer(e){const t=this.activated;t.registerDisposer(this.loadedDataSource.layer.addRenderLayer(e)),t.registerDisposer(this.messages.addChild(e.messages))}getRenderLayerTransform(e){const t=this.activated,{layer:n,transform:i}=this.loadedDataSource;return t.registerDisposer(Object(s.h)(n.manager.root.coordinateSpace,n.localPosition.coordinateSpace,i,this,e))}}class v extends a.a{constructor(e,t,n){super(),this.layerDataSource=e,this.dataSource=t,this.error=void 0,this.enabledSubsourcesChanged=new u.a,this.activatedSubsourcesChanged=new u.a,this.messages=new d.a,t.canChangeModelSpaceRank?(this.transform=new i.c(Object(i.z)(Object(i.y)({rank:0,scales:new Float64Array(0),units:[],names:[]})),!0),this.transform.value=t.modelTransform):this.transform=new i.c(t.modelTransform),void 0!==n.transform&&(this.transform.spec=n.transform);const r=n.subsources;this.enableDefaultSubsources=n.enableDefaultSubsources,this.subsources=t.subsources.map((e,t)=>new g(this,e,r.get(e.id),t,this.enableDefaultSubsources))}get enabledSubsources(){return this.subsources.filter(e=>e.enabled)}get layer(){return this.layerDataSource.layer}disposed(){for(const e of this.subsources){const{activated:t}=e;void 0!==t&&(e.activated=void 0,t.dispose())}}}class b extends a.a{constructor(e,t){super(),this.layer=e,this.changed=new u.a,this.messages=new d.a,this.loadState_=void 0,this.specGeneration=-1,this.refCounted_=void 0,this.registerDisposer(this.changed.add(e.dataSourcesChanged.dispatch)),void 0===t?this.spec_=Object(r.f)():this.spec=t}get spec(){const{loadState:e}=this;if(void 0!==e&&void 0===e.error){const t=this.changed.count;t!==this.specGeneration&&(this.specGeneration=t,this.spec_={url:this.spec.url,transform:e.transform.spec,enableDefaultSubsources:e.enableDefaultSubsources,subsources:new Map(Array.from(e.subsources,t=>{const n=e.enableDefaultSubsources&&t.subsourceEntry.default;return[t.subsourceEntry.id,{enabled:t.enabled!==n?t.enabled:void 0}]}))})}return this.spec_}get loadState(){return this.loadState_}set spec(e){const{layer:t}=this;if(this.messages.clearMessages(),0===e.url.length){if(1!==t.dataSources.length){const e=t.dataSources.indexOf(this);if(-1!==e)return t.dataSources.splice(e,1),t.dataSourcesChanged.dispatch(),void this.dispose()}return this.spec_=e,void(void 0!==this.refCounted_&&(this.refCounted_.dispose(),this.refCounted_=void 0,this.loadState_=void 0,this.changed.dispatch()))}const n=new a.a,i=n.registerDisposer(Object(a.c)(t.markLoading()));void 0!==this.refCounted_&&(this.refCounted_.dispose(),this.loadState_=void 0),this.refCounted_=n,this.spec_=e;const r=t.manager.chunkManager,s=t.manager.dataSourceProviderRegistry,c=new o.b;this.messages.addMessage({severity:d.b.info,message:"Loading data source"}),s.get({chunkManager:r,url:e.url,cancellationToken:c,globalCoordinateSpace:t.manager.root.coordinateSpace,transform:e.transform}).then(r=>{if(n.wasDisposed)return;this.messages.clearMessages();const s=n.registerDisposer(new v(this,r,e));s.registerDisposer(t.addCoordinateSpace(s.transform.outputSpace)),s.registerDisposer(s.transform.changed.add(this.changed.dispatch)),this.loadState_=s,s.registerDisposer(s.enabledSubsourcesChanged.add(this.changed.dispatch)),this.changed.dispatch(),i()}).catch(e=>{this.wasDisposed||(this.loadState_={error:e},this.messages.clearMessages(),this.messages.addMessage({severity:d.b.error,message:e.message}),this.changed.dispatch())}),n.registerDisposer(()=>{c.cancel()}),this.changed.dispatch()}disposed(){const e=this.refCounted_;void 0!==e&&e.dispose()}toJSON(){const{loadState:e}=this;return void 0===e||void 0!==e.error?m(this.spec):m({url:this.spec.url,transform:e.transform.spec,enableDefaultSubsources:e.enableDefaultSubsources,subsources:new Map(Array.from(e.subsources,t=>{const n=e.enableDefaultSubsources&&t.subsourceEntry.default;return[t.subsourceEntry.id,{enabled:t.enabled!==n?t.enabled:void 0}]}))})}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"a",(function(){return r})),n.d(t,"d",(function(){return s})),n.d(t,"c",(function(){return o}));
/**
 * @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 i=12,r=8,s="\nvec3 getBoxFaceVertexPosition(int vertexIndex) {\n  const vec3 vertexPositions[] = vec3[](\n  // Front face\n  vec3(0.0, 0.0,  1.0), // 0\n  vec3(1.0, 0.0,  1.0), // 1\n  vec3(1.0,  1.0,  1.0), // 2\n  vec3(0.0,  1.0,  1.0), // 3\n\n  // Back face\n  vec3(0.0, 0.0, 0.0), // 4\n  vec3(0.0,  1.0, 0.0), // 5\n  vec3(1.0,  1.0, 0.0), // 6\n  vec3(1.0, 0.0, 0.0), // 7\n\n  // Top face\n  vec3(0.0,  1.0, 0.0), // 8\n  vec3(0.0,  1.0,  1.0), // 9\n  vec3(1.0,  1.0,  1.0), // 10\n  vec3(1.0,  1.0, 0.0), // 11\n\n  // Bottom face\n  vec3(0.0, 0.0, 0.0), // 12\n  vec3( 1.0, 0.0, 0.0), // 13\n  vec3( 1.0, 0.0,  1.0), // 14\n  vec3(0.0, 0.0,  1.0), // 15\n\n  // Right face\n  vec3( 1.0, 0.0, 0.0), // 16\n  vec3( 1.0,  1.0, 0.0), // 17\n  vec3( 1.0,  1.0,  1.0), // 18\n  vec3( 1.0, 0.0,  1.0), // 19\n\n  // Left face\n  vec3(0.0, 0.0, 0.0), // 20\n  vec3(0.0, 0.0,  1.0), // 21\n  vec3(0.0,  1.0,  1.0), // 22\n  vec3(0.0,  1.0, 0.0) // 23\n  );\n  const int indices[] = int[](\n    0,  1,  2,      0,  2,  3,    // front\n    4,  5,  6,      4,  6,  7,    // back\n    8,  9,  10,     8,  10, 11,   // top\n    12, 13, 14,     12, 14, 15,   // bottom\n    16, 17, 18,     16, 18, 19,   // right\n    20, 21, 22,     20, 22, 23   // left\n  );\n  return vertexPositions[indices[vertexIndex]];\n}\n";function o(e,t,n){e.drawArraysInstanced(WebGL2RenderingContext.TRIANGLES,0,36*t,n)}},function(e,t,n){"use strict";n.d(t,"b",(function(){return l})),n.d(t,"d",(function(){return u})),n.d(t,"a",(function(){return h})),n.d(t,"c",(function(){return p}));var i=n(119),r=n(78),s=n(128),o=n(3),a=n(20),c=n(84);class l{constructor(e){this.prefix=e,this.seedName=this.prefix+"_seed"}defineShader(e){const{seedName:t}=this;e.addUniform("highp uint",t),e.addFragmentCode(a.o),e.addFragmentCode(r.d),e.addFragmentCode(a.g);let n=`\nvec3 ${this.prefix}(uint64_t x) {\n  uint h = hashCombine(${t}, x);\n  vec2 v;\n`;for(let e=0;e<2;++e)n+=`\n  v[${e}] = float(h & 0xFFu) / 255.0;\n  h >>= 8u;\n`;n+="\n  vec3 hsv = vec3(v.x, 0.5 + v.y * 0.5, 1.0);\n  return hsvToRgb(hsv);\n}\n",e.addFragmentCode(n)}enable(e,t,n){e.uniform1ui(t.uniform(this.seedName),n.hashSeed)}}let d=new Float32Array(3);function u(e){return`rgb(${100*e[0]}%,${100*e[1]}%,${100*e[2]}%)`}class h{constructor(e=Object(c.b)()){this.hashSeed=e,this.changed=new o.a}static getDefault(){return new h(0)}compute(e,t){let n=Object(i.a)(this.hashSeed,t.low);n=Object(i.a)(n,t.high);const r=(255&n)/255,o=(n>>8&255)/255;return Object(s.a)(e,r,.5+.5*o,1),e}computeCssColor(e){return this.compute(d,e),u(d)}randomize(){this.hashSeed=Object(c.b)(),this.changed.dispatch()}toString(){return`new SegmentColorHash(${this.hashSeed})`}toJSON(){return 0===this.hashSeed?void 0:this.hashSeed}reset(){this.restoreState(0)}restoreState(e){const t=e>>>0;t!==this.hashSeed&&(this.hashSeed=t,this.changed.dispatch())}}class p{constructor(e){this.prefix=e,this.hashMapShaderManager=new r.b("segmentStatedColorHash")}defineShader(e){this.hashMapShaderManager.defineShader(e);let t=`\nbool ${this.getFunctionName}(uint64_t x, out vec3 value) {\n  uint64_t uint64Value;\n  if (${this.hashMapShaderManager.getFunctionName}(x, uint64Value)) {\n    uint uintValue = uint64Value.value[0];\n    value.x = float((uintValue & 0xff0000u) >> 16) / 255.0;\n    value.y = float((uintValue & 0x00ff00u) >>  8) / 255.0;\n    value.z = float((uintValue & 0x0000ffu))       / 255.0;\n    return true;\n  }\n  return false;\n}\n`;e.addFragmentCode(t)}get getFunctionName(){return`${this.prefix}_get`}enable(e,t,n){this.hashMapShaderManager.enable(e,t,n)}disable(e,t){this.hashMapShaderManager.disable(e,t)}}},function(e,t,n){"use strict";
/**
 * @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.
 */var i=n(16);
/**
 * @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 r=class extends i.b{constructor(e,t){super(),this.provider=e,this.registerDisposer(e),this.initializeCounterpart(t)}get(e,t){return this.provider.get(e,t)}};r=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}([Object(i.g)("CredentialsProvider")],r),Object(i.d)("CredentialsProvider.get",(function(e,t){return this.get(e.providerId).get(e.invalidCredentials,t).then(e=>({value:e}))}));var s=n(45);function o(){return function(e){return class extends e{constructor(...e){super(...e);const t=e[1];this.credentialsProvider=t.credentialsProvider.addRef()}initializeCounterpart(e,t){t.credentialsProvider=
/**
 * @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(e,t){const n=e.memoize.get({type:"getSharedCredentialsProvider",credentialsProvider:Object(s.a)(t)},()=>new r(t.addRef(),e.rpc)),i=n.addCounterpartRef();return n.dispose(),i}(this.chunkManager,this.credentialsProvider),super.initializeCounterpart(e,t)}static encodeOptions(e){const t=super.encodeOptions(e);return t.credentialsProvider=Object(s.a)(e.credentialsProvider),t}}}}n.d(t,"a",(function(){return o}))},function(e,t,n){(function(e,i){var r;/*! JSON v3.3.2 | https://bestiejs.github.io/json3 | Copyright 2012-2015, Kit Cambridge, Benjamin Tan | http://kit.mit-license.org */(function(){var s=n(256),o={function:!0,object:!0},a=o[typeof t]&&t&&!t.nodeType&&t,c=o[typeof window]&&window||this,l=a&&o[typeof e]&&e&&!e.nodeType&&"object"==typeof i&&i;function d(e,t){e||(e=c.Object()),t||(t=c.Object());var n=e.Number||c.Number,i=e.String||c.String,r=e.Object||c.Object,s=e.Date||c.Date,a=e.SyntaxError||c.SyntaxError,l=e.TypeError||c.TypeError,u=e.Math||c.Math,h=e.JSON||c.JSON;"object"==typeof h&&h&&(t.stringify=h.stringify,t.parse=h.parse);var p=r.prototype,f=p.toString,m=p.hasOwnProperty;function g(e,t){try{e()}catch(e){t&&t()}}var v=new s(-0xc782b5b800cec);function b(e){if(null!=b[e])return b[e];var r;if("bug-string-char-index"==e)r="a"!="a"[0];else if("json"==e)r=b("json-stringify")&&b("date-serialization")&&b("json-parse");else if("date-serialization"==e){if(r=b("json-stringify")&&v){var o=t.stringify;g((function(){r='"-271821-04-20T00:00:00.000Z"'==o(new s(-864e13))&&'"+275760-09-13T00:00:00.000Z"'==o(new s(864e13))&&'"-000001-01-01T00:00:00.000Z"'==o(new s(-621987552e5))&&'"1969-12-31T23:59:59.999Z"'==o(new s(-1))}))}}else{var a,c='{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';if("json-stringify"==e){var l="function"==typeof(o=t.stringify);l&&((a=function(){return 1}).toJSON=a,g((function(){l="0"===o(0)&&"0"===o(new n)&&'""'==o(new i)&&void 0===o(f)&&void 0===o(void 0)&&void 0===o()&&"1"===o(a)&&"[1]"==o([a])&&"[null]"==o([void 0])&&"null"==o(null)&&"[null,null,null]"==o([void 0,f,null])&&o({a:[a,!0,!1,null,"\0\b\n\f\r\t"]})==c&&"1"===o(null,a)&&"[\n 1,\n 2\n]"==o([1,2],null,1)}),(function(){l=!1}))),r=l}if("json-parse"==e){var d,u=t.parse;"function"==typeof u&&g((function(){0!==u("0")||u(!1)||(a=u(c),(d=5==a.a.length&&1===a.a[0])&&(g((function(){d=!u('"\t"')})),d&&g((function(){d=1!==u("01")})),d&&g((function(){d=1!==u("1.")}))))}),(function(){d=!1})),r=d}}return b[e]=!!r}if(g((function(){v=-109252==v.getUTCFullYear()&&0===v.getUTCMonth()&&1===v.getUTCDate()&&10==v.getUTCHours()&&37==v.getUTCMinutes()&&6==v.getUTCSeconds()&&708==v.getUTCMilliseconds()})),b["bug-string-char-index"]=b["date-serialization"]=b.json=b["json-stringify"]=b["json-parse"]=null,!b("json")){var y=b("bug-string-char-index"),S=function(e,t){var n,i,r,s=0;for(r in(n=function(){this.valueOf=0}).prototype.valueOf=0,i=new n)m.call(i,r)&&s++;return n=i=null,s?S=function(e,t){var n,i,r="[object Function]"==f.call(e);for(n in e)r&&"prototype"==n||!m.call(e,n)||(i="constructor"===n)||t(n);(i||m.call(e,n="constructor"))&&t(n)}:(i=["valueOf","toString","toLocaleString","propertyIsEnumerable","isPrototypeOf","hasOwnProperty","constructor"],S=function(e,t){var n,r,s="[object Function]"==f.call(e),a=!s&&"function"!=typeof e.constructor&&o[typeof e.hasOwnProperty]&&e.hasOwnProperty||m;for(n in e)s&&"prototype"==n||!a.call(e,n)||t(n);for(r=i.length;n=i[--r];)a.call(e,n)&&t(n)}),S(e,t)};if(!b("json-stringify")&&!b("date-serialization")){var w={92:"\\\\",34:'\\"',8:"\\b",12:"\\f",10:"\\n",13:"\\r",9:"\\t"},x=function(e,t){return("000000"+(t||0)).slice(-e)},C=function(e){var t,n,i,r,s,o,a,c,l;if(v)t=function(e){n=e.getUTCFullYear(),i=e.getUTCMonth(),r=e.getUTCDate(),o=e.getUTCHours(),a=e.getUTCMinutes(),c=e.getUTCSeconds(),l=e.getUTCMilliseconds()};else{var d=u.floor,h=[0,31,59,90,120,151,181,212,243,273,304,334],p=function(e,t){return h[t]+365*(e-1970)+d((e-1969+(t=+(t>1)))/4)-d((e-1901+t)/100)+d((e-1601+t)/400)};t=function(e){for(r=d(e/864e5),n=d(r/365.2425)+1970-1;p(n+1,0)<=r;n++);for(i=d((r-p(n,0))/30.42);p(n,i+1)<=r;i++);r=1+r-p(n,i),o=d((s=(e%864e5+864e5)%864e5)/36e5)%24,a=d(s/6e4)%60,c=d(s/1e3)%60,l=s%1e3}}return(C=function(e){return e>-1/0&&e<1/0?(t(e),e=(n<=0||n>=1e4?(n<0?"-":"+")+x(6,n<0?-n:n):x(4,n))+"-"+x(2,i+1)+"-"+x(2,r)+"T"+x(2,o)+":"+x(2,a)+":"+x(2,c)+"."+x(3,l)+"Z",n=i=r=o=a=c=l=null):e=null,e})(e)};if(b("json-stringify")&&!b("date-serialization")){function O(e){return C(this)}var k=t.stringify;t.stringify=function(e,t,n){var i=s.prototype.toJSON;s.prototype.toJSON=O;var r=k(e,t,n);return s.prototype.toJSON=i,r}}else{var E=function(e){var t=e.charCodeAt(0),n=w[t];return n||"\\u00"+x(2,t.toString(16))},T=/[\x00-\x1f\x22\x5c]/g,M=function(e){return T.lastIndex=0,'"'+(T.test(e)?e.replace(T,E):e)+'"'},D=function(e,t,n,i,r,o,a){var c,d,u,h,p,m,v,b,y;if(g((function(){c=t[e]})),"object"==typeof c&&c&&(c.getUTCFullYear&&"[object Date]"==f.call(c)&&c.toJSON===s.prototype.toJSON?c=C(c):"function"==typeof c.toJSON&&(c=c.toJSON(e))),n&&(c=n.call(t,e,c)),null==c)return void 0===c?c:"null";switch("object"==(d=typeof c)&&(u=f.call(c)),u||d){case"boolean":case"[object Boolean]":return""+c;case"number":case"[object Number]":return c>-1/0&&c<1/0?""+c:"null";case"string":case"[object String]":return M(""+c)}if("object"==typeof c){for(v=a.length;v--;)if(a[v]===c)throw l();if(a.push(c),h=[],b=o,o+=r,"[object Array]"==u){for(m=0,v=c.length;m<v;m++)p=D(m,c,n,i,r,o,a),h.push(void 0===p?"null":p);y=h.length?r?"[\n"+o+h.join(",\n"+o)+"\n"+b+"]":"["+h.join(",")+"]":"[]"}else S(i||c,(function(e){var t=D(e,c,n,i,r,o,a);void 0!==t&&h.push(M(e)+":"+(r?" ":"")+t)})),y=h.length?r?"{\n"+o+h.join(",\n"+o)+"\n"+b+"}":"{"+h.join(",")+"}":"{}";return a.pop(),y}};t.stringify=function(e,t,n){var i,r,s,a;if(o[typeof t]&&t)if("[object Function]"==(a=f.call(t)))r=t;else if("[object Array]"==a){s={};for(var c,l=0,d=t.length;l<d;)c=t[l++],"[object String]"!=(a=f.call(c))&&"[object Number]"!=a||(s[c]=1)}if(n)if("[object Number]"==(a=f.call(n))){if((n-=n%1)>0)for(n>10&&(n=10),i="";i.length<n;)i+=" "}else"[object String]"==a&&(i=n.length<=10?n:n.slice(0,10));return D("",((c={})[""]=e,c),r,s,i,"",[])}}}if(!b("json-parse")){var L,j,I=i.fromCharCode,P={92:"\\",34:'"',47:"/",98:"\b",116:"\t",110:"\n",102:"\f",114:"\r"},A=function(){throw L=j=null,a()},R=function(){for(var e,t,n,i,r,s=j,o=s.length;L<o;)switch(r=s.charCodeAt(L)){case 9:case 10:case 13:case 32:L++;break;case 123:case 125:case 91:case 93:case 58:case 44:return e=y?s.charAt(L):s[L],L++,e;case 34:for(e="@",L++;L<o;)if((r=s.charCodeAt(L))<32)A();else if(92==r)switch(r=s.charCodeAt(++L)){case 92:case 34:case 47:case 98:case 116:case 110:case 102:case 114:e+=P[r],L++;break;case 117:for(t=++L,n=L+4;L<n;L++)(r=s.charCodeAt(L))>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70||A();e+=I("0x"+s.slice(t,L));break;default:A()}else{if(34==r)break;for(r=s.charCodeAt(L),t=L;r>=32&&92!=r&&34!=r;)r=s.charCodeAt(++L);e+=s.slice(t,L)}if(34==s.charCodeAt(L))return L++,e;A();default:if(t=L,45==r&&(i=!0,r=s.charCodeAt(++L)),r>=48&&r<=57){for(48==r&&((r=s.charCodeAt(L+1))>=48&&r<=57)&&A(),i=!1;L<o&&((r=s.charCodeAt(L))>=48&&r<=57);L++);if(46==s.charCodeAt(L)){for(n=++L;n<o&&!((r=s.charCodeAt(n))<48||r>57);n++);n==L&&A(),L=n}if(101==(r=s.charCodeAt(L))||69==r){for(43!=(r=s.charCodeAt(++L))&&45!=r||L++,n=L;n<o&&!((r=s.charCodeAt(n))<48||r>57);n++);n==L&&A(),L=n}return+s.slice(t,L)}i&&A();var a=s.slice(L,L+4);if("true"==a)return L+=4,!0;if("fals"==a&&101==s.charCodeAt(L+4))return L+=5,!1;if("null"==a)return L+=4,null;A()}return"$"},N=function(e){var t,n;if("$"==e&&A(),"string"==typeof e){if("@"==(y?e.charAt(0):e[0]))return e.slice(1);if("["==e){for(t=[];"]"!=(e=R());)n?","==e?"]"==(e=R())&&A():A():n=!0,","==e&&A(),t.push(N(e));return t}if("{"==e){for(t={};"}"!=(e=R());)n?","==e?"}"==(e=R())&&A():A():n=!0,","!=e&&"string"==typeof e&&"@"==(y?e.charAt(0):e[0])&&":"==R()||A(),t[e.slice(1)]=N(R());return t}A()}return e},V=function(e,t,n){var i=_(e,t,n);void 0===i?delete e[t]:e[t]=i},_=function(e,t,n){var i,r=e[t];if("object"==typeof r&&r)if("[object Array]"==f.call(r))for(i=r.length;i--;)V(f,S,r);else S(r,(function(e){V(r,e,n)}));return n.call(e,t,r)};t.parse=function(e,t){var n,i;return L=0,j=""+e,n=N(R()),"$"!=R()&&A(),L=j=null,t&&"[object Function]"==f.call(t)?_(((i={})[""]=n,i),"",t):n}}}return t.runInContext=d,t}if(!l||l.global!==l&&l.window!==l&&l.self!==l||(c=l),a&&!s)d(c,a);else{var u=c.JSON,h=c.JSON3,p=!1,f=d(c,c.JSON3={noConflict:function(){return p||(p=!0,c.JSON=u,c.JSON3=h,u=h=null),f}});c.JSON={parse:f.parse,stringify:f.stringify}}s&&(void 0===(r=function(){return f}.call(t,n,t,e))||(e.exports=r))}).call(this)}).call(this,n(255)(e),n(46))},function(e,t,n){"use strict";
/**
 * @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 i(e=128){const t=Math.ceil(e/32),n=new Uint32Array(t);crypto.getRandomValues(n);let i="";for(let e=0;e<t;++e)i+=("00000000"+n[e].toString(16)).slice(-8);return i}function r(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);for(let e=0,n=t.length;e<n;e+=65536)crypto.getRandomValues(t.subarray(e,Math.min(n,e+65536)));return e}function s(){const e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}n.d(t,"a",(function(){return i})),n.d(t,"c",(function(){return r})),n.d(t,"b",(function(){return s}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return o})),n.d(t,"b",(function(){return a})),n.d(t,"c",(function(){return c}));var i=n(7),r=n(1),s=n(37);
/**
 * @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 o{constructor(){this.globalPosition=s.b,this.width=0,this.height=0,this.projectionMat=r.m.create(),this.viewMatrix=r.m.create(),this.invViewMatrix=r.m.create(),this.viewProjectionMat=r.m.create(),this.invViewProjectionMat=r.m.create()}}function a(e,t){return e.displayDimensionRenderInfo===t.displayDimensionRenderInfo&&e.width===t.width&&e.height===t.height&&Object(i.a)(e.globalPosition,t.globalPosition)&&Object(i.a)(e.projectionMat,t.projectionMat)&&Object(i.a)(e.viewMatrix,t.viewMatrix)}function c(e){const{viewMatrix:t,viewProjectionMat:n}=e;r.m.invert(t,e.invViewMatrix),r.m.multiply(n,e.projectionMat,t),r.m.invert(e.invViewProjectionMat,n)}},function(e,t,n){"use strict";n.d(t,"a",(function(){return 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 i="vec3 colormapJet(float x) {\n  vec3 result;\n  result.r = x < 0.89 ? ((x - 0.35) / 0.31) : (1.0 - (x - 0.89) / 0.11 * 0.5);\n  result.g = x < 0.64 ? ((x - 0.125) * 4.0) : (1.0 - (x - 0.64) / 0.27);\n  result.b = x < 0.34 ? (0.5 + x * 0.5 / 0.11) : (1.0 - (x - 0.34) / 0.31);\n  return clamp(result, 0.0, 1.0);\n}\nvec3 colormapCubehelix(float x) {\n  float xclamp = clamp(x, 0.0, 1.0);\n  float angle = 2.0 * 3.1415926 * (4.0 / 3.0 + xclamp);\n  float amp = xclamp * (1.0 - xclamp) / 2.0;\n  vec3 result;\n  float cosangle = cos(angle);\n  float sinangle = sin(angle);\n  result.r = -0.14861 * cosangle + 1.78277 * sinangle;\n  result.g = -0.29227 * cosangle + -0.90649 * sinangle;\n  result.b = 1.97294 * cosangle;\n  result = clamp(xclamp + amp * result, 0.0, 1.0);\n  return result;\n}\n"},function(e,t,n){"use strict";n.d(t,"c",(function(){return u})),n.d(t,"d",(function(){return h})),n.d(t,"a",(function(){return m})),n.d(t,"b",(function(){return b}));var i=n(4),r=n(2),s=n(0),o=n(40),a=n(53),c=n(101);
/**
 * @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 l=[1.5,2,3,5,7.5,10],d=[{unit:"km",lengthInNanometers:1e12},{unit:"m",lengthInNanometers:1e9},{unit:"mm",lengthInNanometers:1e6},{unit:"µm",lengthInNanometers:1e3},{unit:"nm",lengthInNanometers:1},{unit:"pm",lengthInNanometers:.001}];function u(e){const t=d.length;let n=d[t-1];for(let i=0;i<t;++i){const t=d[i];if(e>=t.lengthInNanometers){n=t;break}}return n}function h(e){const t=d.length;let n=d[t-1];for(let i=0;i<t;++i){const t=d[i];if(e>=Math.pow(t.lengthInNanometers,3)){n=t;break}}return n}class p{constructor(){this.allowedSignificands=l,this.targetLengthInPixels=0,this.physicalSizePerPixel=0,this.prevPhysicalSizePerPixel=0,this.prevTargetLengthInPixels=0,this.prevPhysicalUnit="\0"}update(){let{physicalSizePerPixel:e,targetLengthInPixels:t}=this;if(this.prevPhysicalSizePerPixel===e&&this.prevTargetLengthInPixels===t&&this.prevPhysicalUnit===this.physicalUnit)return!1;this.prevPhysicalSizePerPixel=e,this.prevTargetLengthInPixels=t,this.prevPhysicalUnit=this.physicalUnit;const n=t*e,i=Math.floor(Math.log10(n)),r=10**i,s=n/r;let a=1;for(let e of this.allowedSignificands){if(!(Math.abs(e-s)<Math.abs(a-s)))break;a=e}const c=a*r,l=Object(o.d)(c);return this.lengthInPixels=Math.round(c/e),this.physicalUnit=`${l.prefix}${this.physicalBaseUnit}`,this.physicalLength=a*10**(i-l.exponent),!0}}class f extends r.a{constructor(e,t=new p){super(),this.gl=e,this.dimensions=t,this.texture=null,this.width=0,this.height=0,this.label="",this.factor=1,this.priorOptions=void 0,this.prevLabel=""}update(e){const{dimensions:t,label:n}=this;let{texture:i}=this;if(!t.update()&&null!==i&&e===this.priorOptions&&n==this.prevLabel)return;null===i&&(i=this.texture=this.gl.createTexture());const{width:r,height:s}=function(e,t,n,i,r){const s=document.createElement("canvas"),o=s.getContext("2d"),a=r.textHeightInPixels*r.scaleFactor,l=`bold ${a}px ${r.fontName}`;o.font=l,o.fillStyle="white";const d=`${i}${e.physicalLength} ${e.physicalUnit}`,u=o.measureText(d),h=Math.max(e.lengthInPixels,u.width),p=r.barHeightInPixels*r.scaleFactor,f=r.barTopMarginInPixels*r.scaleFactor,m=p+f+a,g=r.paddingInPixels*r.scaleFactor,v=m+2*g,b=h+2*g;return s.width=b,s.height=v,o.font=l,o.textAlign="center",o.fillStyle="rgba(0, 0, 0, 0.3)",o.fillRect(0,0,b,v),o.fillStyle="white",o.fillText(d,b/2,v-g-p-f),o.fillRect(g,v-g-p,e.lengthInPixels,p),Object(c.d)(t,n,s),{width:b,height:v}}(t,this.gl,i,n,e);this.priorOptions=e,this.prevLabel=n,this.width=r,this.height=s}disposed(){this.gl.deleteTexture(this.texture),this.texture=null,super.disposed()}}class m extends r.a{constructor(e){super(),this.gl=e,this.scaleBarCopyHelper=this.registerDisposer(a.c.get(this.gl)),this.scaleBars=[];for(let t=0;t<3;++t)this.scaleBars.push(this.registerDisposer(new f(e)))}draw(e,t,n,i,r){const{scaleBars:s}=this,{displayRank:o,displayDimensionIndices:a,canonicalVoxelFactors:c,globalDimensionNames:l,displayDimensionUnits:d,displayDimensionScales:u}=t,{factors:h}=n,p=Math.min(r.maxWidthFraction*e,r.maxWidthInPixels*r.scaleFactor);let f=0;for(let e=0;e<o;++e){const t=a[e],n=d[e],r=h[t];let o,m,g;for(o=0;o<f&&(m=s[o],g=m.dimensions,g.physicalBaseUnit!==n||m.factor!==r);++o);o===f&&(++f,m=s[o],m.label="",g=m.dimensions,m.factor=r,g.physicalBaseUnit=n,g.targetLengthInPixels=p,g.physicalSizePerPixel=u[e]*i/c[e]),m.label+=`${l[t]} `}const{gl:m,scaleBarCopyHelper:g}=this;let v=r.bottomPixelOffset*r.scaleFactor;for(let e=f-1;e>=0;--e){const t=s[e];1===f?t.label="":t.label+=": ",t.update(r),m.viewport(r.leftPixelOffset*r.scaleFactor,v,t.width,t.height),g.draw(t.texture),v+=t.height+r.marginPixelsBetweenScaleBars*r.scaleFactor}}}const g=Object.assign(Object.assign({},{scaleFactor:1,textHeightInPixels:15,barHeightInPixels:8,barTopMarginInPixels:5,fontName:"sans-serif",paddingInPixels:2}),{maxWidthInPixels:100,maxWidthFraction:.25,leftPixelOffset:10,bottomPixelOffset:10,marginPixelsBetweenScaleBars:5});function v(e){const t=Object.assign({},g);for(const n of["textHeightInPixels","barTopMarginInPixels","barHeightInPixels","paddingInPixels","scaleFactor","maxWidthInPixels","maxWidthFraction","leftPixelOffset","bottomPixelOffset"])Object(s.y)(e,n,e=>{void 0!==e&&(t[n]=Object(s.s)(e))});return Object(s.y)(e,"fontName",e=>{void 0!==e&&(t.fontName=Object(s.E)(e))}),t}class b extends i.c{constructor(){super(g,v)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return y}));n(215);var i=n(15),r=n.n(i),s=n(92),o=n.n(s),a=n(28),c=n(4),l=n(68),d=n(128),u=n(2),h=n(13),p=n(1),f=n(51),m=n(139),g=n(40),v=n(93);
/**
 * @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 b=h.a.fromObject({mousedown0:{action:"set"},wheel:{action:"adjust-via-wheel"},dblclick0:{action:"reset"}});class y extends u.a{constructor(e,t){super(),this.histogram=e,this.target=t,this.label=document.createElement("div"),this.element=document.createElement("div"),this.canvas=document.createElement("canvas"),this.legend=document.createElement("div"),this.legendRenderScale=document.createElement("div"),this.legendSpatialScale=document.createElement("div"),this.legendChunks=document.createElement("div"),this.ctx=this.canvas.getContext("2d"),this.hoverTarget=new c.e(void 0),this.throttledUpdateView=this.registerCancellable(o()(()=>this.debouncedUpdateView(),200,{leading:!0,trailing:!0})),this.debouncedUpdateView=this.registerCancellable(r()(()=>this.updateView(),0));const{canvas:n,label:i,element:s,legend:l,legendRenderScale:d,legendSpatialScale:u,legendChunks:p}=this;i.className="neuroglancer-render-scale-widget-prompt",s.className="neuroglancer-render-scale-widget",s.title=b.describe(),l.className="neuroglancer-render-scale-widget-legend",s.appendChild(i),s.appendChild(n),s.appendChild(l),d.title="Target resolution of data in screen pixels",p.title="Number of chunks rendered",l.appendChild(d),l.appendChild(p),l.appendChild(u),this.registerDisposer(e.changed.add(this.throttledUpdateView)),this.registerDisposer(e.visibility.changed.add(this.debouncedUpdateView)),this.registerDisposer(t.changed.add(this.debouncedUpdateView)),this.registerDisposer(new f.b(n,b)),this.registerDisposer(t.changed.add(this.debouncedUpdateView)),this.registerDisposer(this.hoverTarget.changed.add(this.debouncedUpdateView));const m=e=>{const t=e.offsetX/n.width*a.d;return Object(a.b)(t)};this.registerEventListener(n,"pointermove",e=>{this.hoverTarget.value=[m(e),e.offsetY]}),this.registerEventListener(n,"pointerleave",()=>{this.hoverTarget.value=void 0}),this.registerDisposer(Object(h.d)(n,"set",e=>{this.target.value=m(e.detail)})),this.registerDisposer(Object(h.d)(n,"adjust-via-wheel",e=>{const t=e.detail,{deltaY:n}=t;0!==n&&(this.hoverTarget.value=void 0,this.target.value*=2**Math.sign(n),t.preventDefault())})),this.registerDisposer(Object(h.d)(n,"reset",e=>{this.hoverTarget.value=void 0,this.target.reset(),e.preventDefault()}));const g=new v.a(()=>this.debouncedUpdateView());g.observe(n),this.registerDisposer(()=>g.disconnect()),this.updateView()}updateView(){const{ctx:e}=this,{canvas:t}=this,n=t.width=t.offsetWidth,i=t.height=t.offsetHeight,r=this.target.value,s=this.hoverTarget.value;{const{legendRenderScale:e}=this,t=function(e){if(e<1||e>1024){const t=0|Math.log2(e),n=e/2**t;return`${Object(m.a)(n,1)}p${t}`}return Math.round(e)+""}(void 0===s?r:s[0]);e.textContent=t+" px"}function o(e){return e*n/a.d}e.clearRect(0,0,n,i);const{histogram:c}=this,{value:u,spatialScales:h}=c;c.visibility.visible||u.fill(0);const f=Array.from(h.keys());f.sort();const v=p.u.create();let b=1;const y=h.size;let S=0,w=0;for(let e=0;e<a.d;++e){let t=0;for(let n=0;n<y;++n){const i=n*a.d*2+e,r=u[i],s=u[i+a.d];S+=r,w+=s,t+=r+s}b=Math.max(t,b)}const x=i/Math.log(1+b);function C(e){return i-Math.log(1+e)*x}let O=void 0;if(void 0!==s){const e=Math.floor(Object(a.c)(s[0]));if(e>=0&&e<a.d){let t=0;const n=s[1];for(let i=y-1;i>=0;--i){const r=f[i],s=2*h.get(r)*a.d+e,o=u[s]+u[s+a.d];if(0===o)continue;const c=Math.round(C(t));if(t+=o,Math.round(C(t))<=n&&n<=c){O=r;break}}}}if(void 0!==O){S=0,w=0;const e=2*h.get(O)*a.d;for(let t=0;t<a.d;++t){const n=e+t;S+=u[n],w+=u[n+a.d]}Number.isFinite(O)?this.legendSpatialScale.textContent=Object(g.b)(O,"m",{precision:2,elide1:!1}):this.legendSpatialScale.textContent="unknown"}else this.legendSpatialScale.textContent="";this.legendChunks.textContent=`${S}/${S+w}`;const k=f.map(e=>{const t=e===O?.5:1;let n;n=Number.isFinite(e)?(.1*Math.log2(e)%1+1)%1:0,Object(d.a)(v,n,t,1);const i=Object(l.d)(v);return Object(d.a)(v,n,t,.5),[i,Object(l.d)(v)]});for(let t=0;t<a.d;++t){let n=0;for(let i=y-1;i>=0;--i){const r=f[i],s=h.get(r)*a.d*2+t,c=u[s],l=u[s+a.d],d=c+l;if(0===d)continue;const p=Math.round(o(t)),m=Math.round(o(t+1)),g=Math.round(C(n));n+=d;const v=Math.round(C(n)),b=(c*v+l*g)/d;e.fillStyle=k[i][1],e.fillRect(p,v,m-p,b-v),e.fillStyle=k[i][0],e.fillRect(p,b,m-p,g-b)}}{const t=r;e.fillStyle="#fff";const n=o(Object(a.c)(t)),s=1;e.fillRect(Math.floor(n),0,s,i)}if(void 0!==s){const t=s[0];e.fillStyle="#888";const n=o(Object(a.c)(t)),r=1;e.fillRect(Math.floor(n),0,r,i)}}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o})),n.d(t,"b",(function(){return a}));var i=n(133),r=n(39),s=n(22);
/**
 * @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 o="google-brainmaps";function a(e,t,n,o=r.e){return Object(i.a)(t,`${e.serverUrl}${n.path}`,{method:n.method,body:n.payload},"json"===n.responseType?s.g:s.f,(e,t)=>{const n=new Headers(t.headers);return n.set("Authorization",`${e.tokenType} ${e.accessToken}`),Object.assign(Object.assign({},t),{headers:n})},e=>{const{status:t}=e;if(401===t)return"refresh";if(504===t||503===t)return"retry";throw e},o)}},function(e,t,n){"use strict";(function(t){var i=n(110),r={},s=!1,o=t.chrome&&t.chrome.app&&t.chrome.app.runtime;e.exports={attachEvent:function(e,n){void 0!==t.addEventListener?t.addEventListener(e,n,!1):t.document&&t.attachEvent&&(t.document.attachEvent("on"+e,n),t.attachEvent("on"+e,n))},detachEvent:function(e,n){void 0!==t.addEventListener?t.removeEventListener(e,n,!1):t.document&&t.detachEvent&&(t.document.detachEvent("on"+e,n),t.detachEvent("on"+e,n))},unloadAdd:function(e){if(o)return null;var t=i.string(8);return r[t]=e,s&&setTimeout(this.triggerUnloadCallbacks,0),t},unloadDel:function(e){e in r&&delete r[e]},triggerUnloadCallbacks:function(){for(var e in r)r[e](),delete r[e]}};o||e.exports.attachEvent("unload",(function(){s||(s=!0,e.exports.triggerUnloadCallbacks())}))}).call(this,n(46))},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"b",(function(){return o}));var i=n(2),r=n(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.
 */
class s{constructor(){this.map=new Map}get(e,t){let{map:n}=this,i=n.get(e);return void 0===i?(i=t(),i.registerDisposer(()=>{n.delete(e)}),n.set(e,i)):i.addRef(),i}}class o extends s{get(e,t){return"string"!=typeof e&&(e=Object(r.h)(e)),super.get(e,t)}getUncounted(e,t){return this.get(e,()=>new i.b(t())).value}}},function(e,t,n){var i=n(15),r=n(142);e.exports=function(e,t,n){var s=!0,o=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return r(n)&&(s="leading"in n?!!n.leading:s,o="trailing"in n?!!n.trailing:o),i(e,t,{leading:s,maxWait:t,trailing:o})}},function(e,t,n){"use strict";(function(e){var n=function(){if("undefined"!=typeof Map)return Map;function e(e,t){var n=-1;return e.some((function(e,i){return e[0]===t&&(n=i,!0)})),n}return(function(){function t(){this.__entries__=[]}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),t.prototype.get=function(t){var n=e(this.__entries__,t),i=this.__entries__[n];return i&&i[1]},t.prototype.set=function(t,n){var i=e(this.__entries__,t);~i?this.__entries__[i][1]=n:this.__entries__.push([t,n])},t.prototype.delete=function(t){var n=this.__entries__,i=e(n,t);~i&&n.splice(i,1)},t.prototype.has=function(t){return!!~e(this.__entries__,t)},t.prototype.clear=function(){this.__entries__.splice(0)},t.prototype.forEach=function(e,t){void 0===t&&(t=null);for(var n=0,i=this.__entries__;n<i.length;n++){var r=i[n];e.call(t,r[1],r[0])}},t}())}(),i="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,r=void 0!==e&&e.Math===Math?e:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")(),s="function"==typeof requestAnimationFrame?requestAnimationFrame.bind(r):function(e){return setTimeout((function(){return e(Date.now())}),1e3/60)};var o=["top","right","bottom","left","width","height","size","weight"],a="undefined"!=typeof MutationObserver,c=function(){function e(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(e,t){var n=!1,i=!1,r=0;function o(){n&&(n=!1,e()),i&&c()}function a(){s(o)}function c(){var e=Date.now();if(n){if(e-r<2)return;i=!0}else n=!0,i=!1,setTimeout(a,t);r=e}return c}(this.refresh.bind(this),20)}return e.prototype.addObserver=function(e){~this.observers_.indexOf(e)||this.observers_.push(e),this.connected_||this.connect_()},e.prototype.removeObserver=function(e){var t=this.observers_,n=t.indexOf(e);~n&&t.splice(n,1),!t.length&&this.connected_&&this.disconnect_()},e.prototype.refresh=function(){this.updateObservers_()&&this.refresh()},e.prototype.updateObservers_=function(){var e=this.observers_.filter((function(e){return e.gatherActive(),e.hasActive()}));return e.forEach((function(e){return e.broadcastActive()})),e.length>0},e.prototype.connect_=function(){i&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),a?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},e.prototype.disconnect_=function(){i&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},e.prototype.onTransitionEnd_=function(e){var t=e.propertyName,n=void 0===t?"":t;o.some((function(e){return!!~n.indexOf(e)}))&&this.refresh()},e.getInstance=function(){return this.instance_||(this.instance_=new e),this.instance_},e.instance_=null,e}(),l=function(e,t){for(var n=0,i=Object.keys(t);n<i.length;n++){var r=i[n];Object.defineProperty(e,r,{value:t[r],enumerable:!1,writable:!1,configurable:!0})}return e},d=function(e){return e&&e.ownerDocument&&e.ownerDocument.defaultView||r},u=v(0,0,0,0);function h(e){return parseFloat(e)||0}function p(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return t.reduce((function(t,n){return t+h(e["border-"+n+"-width"])}),0)}function f(e){var t=e.clientWidth,n=e.clientHeight;if(!t&&!n)return u;var i=d(e).getComputedStyle(e),r=function(e){for(var t={},n=0,i=["top","right","bottom","left"];n<i.length;n++){var r=i[n],s=e["padding-"+r];t[r]=h(s)}return t}(i),s=r.left+r.right,o=r.top+r.bottom,a=h(i.width),c=h(i.height);if("border-box"===i.boxSizing&&(Math.round(a+s)!==t&&(a-=p(i,"left","right")+s),Math.round(c+o)!==n&&(c-=p(i,"top","bottom")+o)),!function(e){return e===d(e).document.documentElement}(e)){var l=Math.round(a+s)-t,f=Math.round(c+o)-n;1!==Math.abs(l)&&(a-=l),1!==Math.abs(f)&&(c-=f)}return v(r.left,r.top,a,c)}var m="undefined"!=typeof SVGGraphicsElement?function(e){return e instanceof d(e).SVGGraphicsElement}:function(e){return e instanceof d(e).SVGElement&&"function"==typeof e.getBBox};function g(e){return i?m(e)?function(e){var t=e.getBBox();return v(0,0,t.width,t.height)}(e):f(e):u}function v(e,t,n,i){return{x:e,y:t,width:n,height:i}}var b=function(){function e(e){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=v(0,0,0,0),this.target=e}return e.prototype.isActive=function(){var e=g(this.target);return this.contentRect_=e,e.width!==this.broadcastWidth||e.height!==this.broadcastHeight},e.prototype.broadcastRect=function(){var e=this.contentRect_;return this.broadcastWidth=e.width,this.broadcastHeight=e.height,e},e}(),y=function(e,t){var n,i,r,s,o,a,c,d=(i=(n=t).x,r=n.y,s=n.width,o=n.height,a="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object,c=Object.create(a.prototype),l(c,{x:i,y:r,width:s,height:o,top:r,right:i+s,bottom:o+r,left:i}),c);l(this,{target:e,contentRect:d})},S=function(){function e(e,t,i){if(this.activeObservations_=[],this.observations_=new n,"function"!=typeof e)throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=e,this.controller_=t,this.callbackCtx_=i}return e.prototype.observe=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(e instanceof d(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var t=this.observations_;t.has(e)||(t.set(e,new b(e)),this.controller_.addObserver(this),this.controller_.refresh())}},e.prototype.unobserve=function(e){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(e instanceof d(e).Element))throw new TypeError('parameter 1 is not of type "Element".');var t=this.observations_;t.has(e)&&(t.delete(e),t.size||this.controller_.removeObserver(this))}},e.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},e.prototype.gatherActive=function(){var e=this;this.clearActive(),this.observations_.forEach((function(t){t.isActive()&&e.activeObservations_.push(t)}))},e.prototype.broadcastActive=function(){if(this.hasActive()){var e=this.callbackCtx_,t=this.activeObservations_.map((function(e){return new y(e.target,e.broadcastRect())}));this.callback_.call(e,t,e),this.clearActive()}},e.prototype.clearActive=function(){this.activeObservations_.splice(0)},e.prototype.hasActive=function(){return this.activeObservations_.length>0},e}(),w="undefined"!=typeof WeakMap?new WeakMap:new n,x=function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var n=c.getInstance(),i=new S(t,n,this);w.set(this,i)};["observe","unobserve","disconnect"].forEach((function(e){x.prototype[e]=function(){var t;return(t=w.get(this))[e].apply(t,arguments)}}));var C=void 0!==r.ResizeObserver?r.ResizeObserver:x;t.a=C}).call(this,n(46))},function(e,t,n){"use strict";n.d(t,"c",(function(){return o})),n.d(t,"b",(function(){return h})),n.d(t,"a",(function(){return v}));var i=n(119),r=n(84),s=n(18);
/**
 * @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 o=3;let a=0,c=0,l=0,d=0;class u{constructor(e=u.generateHashSeeds(o)){this.hashSeeds=e,this.loadFactor=.9,this.size=0,this.emptyLow=4294967295,this.emptyHigh=4294967295,this.maxRehashAttempts=5,this.maxAttempts=5,this.generation=0,this.mungedEmptyKey=-1;let t=8;for(;t<2*e.length;)t*=2;this.allocate(t)}updateHashFunctions(e){this.hashSeeds=u.generateHashSeeds(e),this.mungedEmptyKey=-1}tableWithMungedEmptyKey(e){const t=this.hashSeeds.length,n=new Array(t);for(let e=0;e<t;++e)n[e]=this.getHash(e,this.emptyLow,this.emptyHigh);let{mungedEmptyKey:i}=this;if(-1===i)e:for(;;){i=16777216*Math.random()>>>0;for(let e=0;e<t;++e){let r=this.getHash(e,i,i);for(let e=0;e<t;++e)if(n[e]===r)continue e}this.mungedEmptyKey=i;break}let{table:r,emptyLow:s,emptyHigh:o}=this;for(let e=0;e<t;++e){let t=n[e];r[t]===s&&r[t+1]===o&&(r[t]=i,r[t+1]=i)}try{e(r)}finally{for(let e=0;e<t;++e){let t=n[e];r[t]===i&&r[t+1]===i&&(r[t]=s,r[t+1]=o)}}}static generateHashSeeds(e=o){return Object(r.c)(new Uint32Array(e))}getHash(e,t,n){let r=this.hashSeeds[e];return r=Object(i.a)(r,t),r=Object(i.a)(r,n),this.entryStride*(r&this.tableSize-1)}*keys(e=new s.a){let{emptyLow:t,emptyHigh:n,entryStride:i}=this,{table:r}=this;for(let s=0,o=r.length;s<o;s+=i){let i=r[s],o=r[s+1];i===t&&o===n||(e.low=i,e.high=o,yield e)}}indexOfPair(e,t){let{table:n,emptyLow:i,emptyHigh:r}=this;if(e===i&&t===r)return-1;for(let i=0,r=this.hashSeeds.length;i<r;++i){let r=this.getHash(i,e,t);if(n[r]===e&&n[r+1]===t)return r}return-1}indexOf(e){return this.indexOfPair(e.low,e.high)}chooseAnotherEmptyKey(){let e,t,{emptyLow:n,emptyHigh:i,table:r,entryStride:s}=this;for(;e=4294967296*Math.random()>>>0,t=4294967296*Math.random()>>>0,e===n&&t===i||this.hasPair(e,t););this.emptyLow=e,this.emptyHigh=t;for(let o=0,a=r.length;o<a;o+=s)r[o]===n&&r[o+1]===i&&(r[o]=e,r[o+1]=t)}has(e){return-1!==this.indexOf(e)}hasPair(e,t){return-1!==this.indexOfPair(e,t)}delete(e){let t=this.indexOf(e);if(-1!==t){let{table:e}=this;return e[t]=this.emptyLow,e[t+1]=this.emptyHigh,++this.generation,this.size--,!0}return!1}clearTable(){let{table:e,entryStride:t,emptyLow:n,emptyHigh:i}=this,r=e.length;for(let s=0;s<r;s+=t)e[s]=n,e[s+1]=i}clear(){return 0!==this.size&&(this.size=0,++this.generation,this.clearTable(),!0)}swapPending(e,t){let n=a,i=c;this.storePending(e,t),e[t]=n,e[t+1]=i}storePending(e,t){a=e[t],c=e[t+1]}backupPending(){l=a,d=c}restorePending(){a=l,c=d}tryToInsert(){let e=0,{emptyLow:t,emptyHigh:n,maxAttempts:i,table:r}=this,s=this.hashSeeds.length,o=Math.floor(Math.random()*s);for(;;){let l=this.getHash(o,a,c);if(this.swapPending(r,l),a===t&&c===n)return!0;if(++e===i)break;o=(o+Math.floor(Math.random()*(s-1))+1)%s}return!1}allocate(e){this.tableSize=e;let{entryStride:t}=this;this.table=new Uint32Array(e*t),this.maxAttempts=e,this.clearTable(),this.capacity=e*this.loadFactor,this.mungedEmptyKey=-1}rehash(e,t){this.allocate(t),this.updateHashFunctions(this.hashSeeds.length);let{emptyLow:n,emptyHigh:i,entryStride:r}=this;for(let t=0,s=e.length;t<s;t+=r){let r=e[t],s=e[t+1];if((r!==n||s!==i)&&(this.storePending(e,t),!this.tryToInsert()))return!1}return!0}grow(e){let t=this.table,{tableSize:n}=this;for(;n<e;)n*=2;for(;;){for(let e=0;e<this.maxRehashAttempts;++e)if(this.rehash(t,n))return void 0;n*=2}}insertInternal(){for(++this.generation,a===this.emptyLow&&c===this.emptyHigh&&this.chooseAnotherEmptyKey(),++this.size>this.capacity&&(this.backupPending(),this.grow(2*this.tableSize),this.restorePending());!this.tryToInsert();)this.backupPending(),this.grow(this.tableSize),this.restorePending()}}class h extends u{add(e){let{low:t,high:n}=e;return!this.hasPair(t,n)&&(a=t,c=n,this.insertInternal(),!0)}[Symbol.iterator](){return this.keys()}}h.prototype.entryStride=2;let p=0,f=0,m=0,g=0;class v extends u{set(e,t){let{low:n,high:i}=e;return!this.hasPair(n,i)&&(a=n,c=i,p=t.low,f=t.high,this.insertInternal(),!0)}get(e,t){let n=this.indexOf(e);if(-1===n)return!1;let{table:i}=this;return t.low=i[n+2],t.high=i[n+3],!0}swapPending(e,t){let n=p,i=f;super.swapPending(e,t),e[t+2]=n,e[t+3]=i}storePending(e,t){super.storePending(e,t),p=e[t+2],f=e[t+3]}backupPending(){super.backupPending(),m=p,g=f}restorePending(){super.restorePending(),p=m,f=g}[Symbol.iterator](){return this.entries()}*entries(e=[new s.a,new s.a]){let{emptyLow:t,emptyHigh:n,entryStride:i}=this,{table:r}=this,[o,a]=e;for(let s=0,c=r.length;s<c;s+=i){let i=r[s],c=r[s+1];i===t&&c===n||(o.low=i,o.high=c,a.low=r[s+2],a.high=r[s+3],yield e)}}}v.prototype.entryStride=4},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(27);
/**
 * @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 r(e={}){return Object(i.a)(Object.assign({text:"?"},e))}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(178),r=n.n(i),s=n(27);
/**
 * @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 o(e={}){return Object(s.a)(Object.assign({svg:r.a},e))}},function(e,t,n){"use strict";n.d(t,"a",(function(){return l}));n(216),n(217),n(157),n(158);var i=n(65),r=n.n(i),s=n(15),o=n.n(s),a=n(2),c=n(6);
/**
 * @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.
 */
n(218)(r.a);class l extends a.a{constructor(e){super(),this.state=e,this.changingValue=!1,this.debouncedValueUpdater=o()(()=>{this.changingValue=!0;try{this.state.fragmentMain.value=this.textEditor.getValue()}finally{this.changingValue=!1}},500),this.textEditor=r()(e=>{},{value:this.state.fragmentMain.value,mode:"glsl",gutters:["CodeMirror-lint-markers"]}),this.textEditor.on("change",()=>{this.setValidState(void 0),this.debouncedValueUpdater()}),this.registerDisposer(this.state.fragmentMain.changed.add(()=>{this.changingValue||this.textEditor.setValue(this.state.fragmentMain.value)})),this.element.classList.add("neuroglancer-shader-code-widget"),this.registerDisposer(this.state.shaderError.changed.add(()=>{this.updateErrorState()}));const{shaderControlState:t}=this.state;void 0!==t&&this.registerDisposer(t.parseErrors.changed.add(()=>{this.updateErrorState()})),this.updateErrorState();const n=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&this.textEditor.refresh()},{root:document.body});n.observe(this.element),this.registerDisposer(()=>n.disconnect())}get element(){return this.textEditor.getWrapperElement()}updateErrorState(){const{sourceStringNumber:e=1}=this.state,t=this.state.shaderError.value;let n;const{shaderControlState:i}=this.state;n=void 0!==i?i.parseErrors.value:[],void 0===t&&0===n.length?this.setValidState(void 0):null!=t||0!==n.length?(this.textEditor.setOption("lint",{getAnnotations:()=>{const i=[];for(const e of n)i.push({message:e.message,severity:"error",from:r.a.Pos(e.line)});if(null!=t)if("ShaderCompilationError"===t.name)for(const n of t.errorMessages)i.push({message:n.message,severity:"error",from:r.a.Pos(n.file===e&&n.line||0)});else"ShaderLinkError"===t.name?i.push({message:t.log,severity:"error",from:r.a.Pos(0)}):i.push({message:t.message,severity:"error",from:r.a.Pos(0)});return i}}),this.setValidState(!1)):(this.textEditor.setOption("lint",void 0),this.setValidState(!0))}setValidState(e){let{element:t}=this;t.classList.remove("invalid-input"),t.classList.remove("valid-input"),!0===e?t.classList.add("valid-input"):!1===e&&t.classList.add("invalid-input")}disposed(){this.debouncedValueUpdater.flush(),this.debouncedValueUpdater=void 0,Object(c.c)(this.element),this.textEditor=void 0,super.disposed()}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return l}));var i=n(15),r=n.n(i),s=n(2),o=n(6),a=n(137),c=n(77);
/**
 * @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 l extends s.a{constructor(e){super(),this.state=e,this.element=document.createElement("div"),this.controlDisposer=void 0;const{controls:t}=e;this.registerDisposer(t.changed.add(this.registerCancellable(r()(()=>this.updateControls(),0)))),this.updateControls()}updateControls(){void 0!==this.controlDisposer&&(this.controlDisposer.dispose(),Object(o.b)(this.element));const e=this.controlDisposer=new s.a;for(const[t,n]of this.state.state){const{control:i}=n;switch(i.type){case"slider":{const r=e.registerDisposer(new c.a(n.trackable,{min:i.min,max:i.max,step:i.step}));r.promptElement.textContent=t,this.element.appendChild(r.element);break}case"color":{const i=document.createElement("label");i.textContent=t;const r=e.registerDisposer(new a.a(n.trackable));this.element.appendChild(i),i.appendChild(r.element);break}}}}disposed(){const{controlDisposer:e}=this;void 0!==e&&e.dispose(),super.disposed()}}},function(e,t,n){"use strict";var i=n(22);
/**
 * @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 r(e,t,n,r){if(!n.startsWith("/"))throw null;const s=await async function(e,t,n,r){const s=await Object(i.b)(`${e}?prefix=${encodeURIComponent(t)}`+`&delimiter=${encodeURIComponent(n)}`,{},e=>e.text(),r),o=(new DOMParser).parseFromString(s,"application/xml"),a=o.evaluate('//*[name()="CommonPrefixes"]/*[name()="Prefix"]',o,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null),c=[];for(let e=0,t=a.snapshotLength;e<t;++e)c.push(a.snapshotItem(e).textContent||"");const l=o.evaluate('//*[name()="Contents"]/*[name()="Key"]',o,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);for(let e=0,t=l.snapshotLength;e<t;++e)c.push(l.snapshotItem(e).textContent||"");return c}(t,n.substring(1),"/",r);let o=n.lastIndexOf("/");return{offset:o+e.length+1,completions:s.map(e=>({value:e.substring(o)}))}}async function s(e,t){const n=e.match(/^([a-z]+:\/\/.*\/)([^\/?#]*)$/);if(null===n)throw null;const r=await
/**
 * @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(e,t){const{text:n,contentType:r}=await Object(i.b)(e,{headers:{accept:"text/html"}},async e=>({text:await e.text(),contentType:e.headers.get("content-type")}),t);if("text/html"!==r)return[];const s=(new DOMParser).parseFromString(n,r),o=s.evaluate("//a/@href",s,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null),a=[];for(let t=0,n=o.snapshotLength;t<n;++t){const n=o.snapshotItem(t).textContent;n&&a.push(new URL(n,e).toString())}return a}(n[1],t),s=n[1].length,o=[];for(const t of r)t.startsWith(e)&&o.push({value:t.substring(s)});return{offset:s,completions:o}}async function o(e,t){let n;try{n=Object(i.e)(e)}catch(e){throw null}const{protocol:o,host:a,path:c}=n;if("gs"===o&&c.length>0)return await r(`${o}://${a}`,`https://storage.googleapis.com/${a}`,c,t);const l=e.match(/^((?:http|https):\/\/(?:storage\.googleapis\.com\/[^\/]+|[^\/]+\.storage\.googleapis\.com))(\/.*)$/);if(null!==l)return await r(l[1],l[1],l[2],t);if(("http"===o||"https"===o)&&c.length>0)return await s(e,t);throw null}n.d(t,"a",(function(){return o}))},function(e,t,n){"use strict";var i=n(15),r=n.n(i),s=n(2),o=n(6),a=class{static insertAfter(e,t){let n=e.next0;t.next0=n,t.prev0=e,e.next0=t,n.prev0=t}static insertBefore(e,t){let n=e.prev0;t.prev0=n,t.next0=e,e.prev0=t,n.next0=t}static front(e){let t=e.next0;return t===e?null:t}static back(e){let t=e.prev0;return t===e?null:t}static pop(e){let t=e.next0,n=e.prev0;return t.prev0=n,n.next0=t,e.next0=null,e.prev0=null,e}static*iterator(e){for(let t=e.next0;t!==e;t=t.next0)yield t}static*reverseIterator(e){for(let t=e.prev0;t!==e;t=t.prev0)yield t}static initializeHead(e){e.next0=e.prev0=e}};n.d(t,"a",(function(){return d}));const c=new
/**
 * @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{constructor(){a.initializeHead(this)}},l=r()(()=>{const{activeElement:e}=document;if(null===e||e===document.body){const e=a.front(c);null!==e&&e.element.focus()}});window.addEventListener("focus",()=>{l()},!0),window.addEventListener("blur",()=>{l()},!0);class d extends s.a{constructor(e){super(),this.element=e,this.prev0=null,this.next0=null,this.lastFocusedElement=null,this.scheduleUpdateFocus=this.registerCancellable(r()(()=>{const{activeElement:e}=document,{element:t}=this;t.contains(e)||Object(o.a)(e)||(null==e||e!==this.lastFocusedElement&&!e.contains(t)||this.element.focus(),this.lastFocusedElement=null)},0)),e.tabIndex=-1,this.registerEventListener(e,"pointerdown",t=>{t.target===e&&(this.lastFocusedElement=null,e.focus())}),this.registerEventListener(e,"mouseenter",()=>{this.lastFocusedElement=document.activeElement,this.scheduleUpdateFocus()}),this.registerEventListener(e,"mouseleave",()=>{this.scheduleUpdateFocus.cancel()}),a.insertBefore(c,this),this.registerEventListener(e,"focus",()=>{a.pop(this),a.insertAfter(c,this)}),l()}disposed(){a.pop(this),super.disposed()}}},function(e,t,n){"use strict";
/**
 * @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 i(e){e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_MIN_FILTER,WebGL2RenderingContext.NEAREST),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_MAG_FILTER,WebGL2RenderingContext.NEAREST),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_WRAP_S,WebGL2RenderingContext.CLAMP_TO_EDGE),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_WRAP_T,WebGL2RenderingContext.CLAMP_TO_EDGE)}function r(e){e.texParameteri(WebGL2RenderingContext.TEXTURE_3D,WebGL2RenderingContext.TEXTURE_MIN_FILTER,WebGL2RenderingContext.NEAREST),e.texParameteri(WebGL2RenderingContext.TEXTURE_3D,WebGL2RenderingContext.TEXTURE_MAG_FILTER,WebGL2RenderingContext.NEAREST),e.texParameteri(WebGL2RenderingContext.TEXTURE_3D,WebGL2RenderingContext.TEXTURE_WRAP_S,WebGL2RenderingContext.CLAMP_TO_EDGE),e.texParameteri(WebGL2RenderingContext.TEXTURE_3D,WebGL2RenderingContext.TEXTURE_WRAP_T,WebGL2RenderingContext.CLAMP_TO_EDGE),e.texParameteri(WebGL2RenderingContext.TEXTURE_3D,WebGL2RenderingContext.TEXTURE_WRAP_R,WebGL2RenderingContext.CLAMP_TO_EDGE)}function s(e,t,n,r,s=WebGL2RenderingContext.RGBA8,o=WebGL2RenderingContext.RGBA,a=WebGL2RenderingContext.UNSIGNED_BYTE){e.activeTexture(WebGL2RenderingContext.TEXTURE0+e.tempTextureUnit),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,t),i(e),e.texImage2D(WebGL2RenderingContext.TEXTURE_2D,0,s,n,r,0,o,a,null),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null)}function o(e,t,n){e.activeTexture(WebGL2RenderingContext.TEXTURE0+e.tempTextureUnit),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,t),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_MIN_FILTER,WebGL2RenderingContext.LINEAR),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_MAG_FILTER,WebGL2RenderingContext.LINEAR),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_WRAP_S,WebGL2RenderingContext.CLAMP_TO_EDGE),e.texParameteri(WebGL2RenderingContext.TEXTURE_2D,WebGL2RenderingContext.TEXTURE_WRAP_T,WebGL2RenderingContext.CLAMP_TO_EDGE),e.pixelStorei(WebGL2RenderingContext.UNPACK_FLIP_Y_WEBGL,1),e.pixelStorei(WebGL2RenderingContext.UNPACK_ALIGNMENT,4),e.texImage2D(WebGL2RenderingContext.TEXTURE_2D,0,WebGL2RenderingContext.RGBA8,WebGL2RenderingContext.RGBA,WebGL2RenderingContext.UNSIGNED_BYTE,n),e.pixelStorei(WebGL2RenderingContext.UNPACK_FLIP_Y_WEBGL,0),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null)}n.d(t,"c",(function(){return i})),n.d(t,"b",(function(){return r})),n.d(t,"a",(function(){return s})),n.d(t,"d",(function(){return o}))},function(e,t,n){"use strict";n.d(t,"d",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"a",(function(){return c})),n.d(t,"b",(function(){return l}));var i=n(12),r=n(105);
/**
 * @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 s(e){return e}function o(e,t){return Object(r.a)(e,t)}class a{constructor(e,t){this.ids=e,this.labels=t,this.idToLabel={};const n=this.sortedNames=t.map((t,n)=>[e[n],t]),{idToLabel:i}=this;for(let n=0,r=e.length;n<r;++n)i[e[n]]=t[n];n.sort((e,t)=>o(e[1],t[1]))}has(e){return Object.prototype.hasOwnProperty.call(this.idToLabel,e)}get(e){return this.idToLabel[e]}}class c extends i.f{constructor(e,t){super(e,t),this.properties=t.properties}static encodeOptions(e){return{properties:e.properties}}}class l{constructor(e){const t=this.inlineProperties=e.inlineProperties;if(void 0!==t){const{ids:e}=t,n=this.inlineIdToIndex={};for(let t=0,i=e.length;t<i;++t)n[e[t]]=t;const i=t.properties.find(e=>"label"===e.type);void 0!==i&&(this.labelMap=new a(t.ids,i.values))}this.indexedProperties=e.indexedProperties}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"c",(function(){return o})),n.d(t,"b",(function(){return c}));var i=n(2),r=n(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 s extends i.a{setActive(e){}deactivate(){}}function o(e,t){if(void 0===t)return;"string"==typeof t&&(t={type:t}),Object(r.w)(t);const n=Object(r.y)(t,"type",r.E),i=a.get(n);if(void 0===i)throw new Error(`Invalid tool type: ${JSON.stringify(t)}.`);return i(e,t)}const a=new Map;function c(e,t){a.set(e,t)}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(176),r=n.n(i),s=n(27);
/**
 * @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 o(e={}){const t=Object(s.a)(Object.assign({svg:r.a},e));return t.firstElementChild.style.fill="white",t}},function(e,t,n){"use strict";
/**
 * @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 i(e,t){return e<t?-1:e>t?1:0}n.d(t,"a",(function(){return i}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(0),r=n(3);
/**
 * @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 s{constructor(e,t,n=t){this.enumType=e,this.value_=t,this.defaultValue=n,this.changed=new r.a}set value(e){this.value_!==e&&(this.value_=e,this.changed.dispatch())}get value(){return this.value_}reset(){this.value=this.defaultValue}restoreState(e){this.value=Object(i.o)(e,this.enumType)}toJSON(){if(this.value_!==this.defaultValue)return this.enumType[this.value_].toLowerCase()}}},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="plusIconTitle"><path d="M20 12L4 12M12 4L12 20"></path></svg>'},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(4),r=n(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.
 */
function s(e=.5){return new i.c(e,r.t)}},function(e,t,n){"use strict";var i=n(10),r=n(12),s=n(71),o=n(36);class a extends class{}{}a.RPC_ID="single_mesh/SingleMeshSource";var c=n(4),l=n(14),d=n(1),u=n(31),h=n(86),p=n(32),f=n(2),m=n(43),g=n(20);
/**
 * @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 v extends f.a{constructor(e){super(),this.gl=e,this.buffer=this.registerDisposer(new m.a(e))}resize(e){let t;if(e<256){let n=t=new Uint8Array(e);for(let t=0;t<e;++t)n[t]=t;this.webglType=WebGL2RenderingContext.UNSIGNED_BYTE}else if(e<65536){const n=t=new Uint16Array(e);for(let t=0;t<e;++t)n[t]=t;this.webglType=WebGL2RenderingContext.UNSIGNED_SHORT}else{const n=t=new Uint32Array(e);for(let t=0;t<e;++t)n[t]=t;this.webglType=WebGL2RenderingContext.UNSIGNED_INT}this.buffer.setData(t),this.length=e}ensure(e){return(void 0===this.length||this.length<e)&&this.resize(e),this}bindToVertexAttrib(e){this.buffer.bindToVertexAttribI(e,1,this.webglType)}bind(e,t=0){const n=e.attribute("aIndexRaw");n>=0&&(this.bindToVertexAttrib(n),0!==t&&this.gl.vertexAttribDivisor(n,t))}}function b(e){e.addAttribute("highp uint","aIndexRaw"),e.addVertexCode(g.n),e.addVertexCode("\nuint getPrimitiveIndex() {\n  return aIndexRaw;\n}\n")}class y{constructor(e){this.name=e}defineShader(e){e.addAttribute("highp uint",this.name)}bind(e,t){const n=t.attribute(this.name);e.bindToVertexAttribI(n,1,WebGL2RenderingContext.UNSIGNED_INT)}disable(e){e.gl.disableVertexAttribArray(e.attribute(this.name))}}var S=n(41),w=n(35),x=n(16);n.d(t,"a",(function(){return C})),n.d(t,"c",(function(){return O})),n.d(t,"e",(function(){return M})),n.d(t,"b",(function(){return R})),n.d(t,"d",(function(){return N}));class C{constructor(){this.shaderError=Object(p.b)(),this.fragmentMain=Object(p.a)("void main() {\n  emitGray();\n}\n"),this.shaderControlState=new S.a(this.fragmentMain)}}function O(e){return Object(g.b)(e.dataType,e.numComponents)}const k=[],E=Object(w.d)(new w.c,l.c.FLOAT32,3),T=E;function M(e){const t=new Set;let n=[];for(let i of e){let e=i.split(/[^a-zA-Z0-9]+/).filter(e=>e).join("_"),r="",s=0;for(;t.has(e+r);)r=""+ ++s;n.push(e+r)}return n}class D{constructor(e,t){this.attributeNames=e,this.attributeInfo=t,this.tempLightVec=new Float32Array(4),this.textureAccessHelper=new w.a("vertexData"),this.indexBufferHelper=new y("vertexIndex")}defineAttributeAccess(e,t){let{textureAccessHelper:n}=this;n.defineShader(e);const{attributeNames:i}=this;let r=2+i.length;for(let e=k.length;e<r;++e)k[e]=Symbol(`SingleMeshShaderManager.vertexAttributeTextureUnit${e}`);r=0,e.addTextureSampler("sampler2D","uVertexAttributeSampler0",k[r++]),e.addTextureSampler("sampler2D","uVertexAttributeSampler1",k[r++]),e.addVertexCode(n.getAccessor("readVertexPosition","uVertexAttributeSampler0",l.c.FLOAT32,3)),e.addVertexCode(n.getAccessor("readVertexNormal","uVertexAttributeSampler1",l.c.FLOAT32,3));let s=`\nvec3 vertexPosition = readVertexPosition(${t});\nvec3 vertexNormal = readVertexNormal(${t});\n`;this.attributeInfo.forEach((o,a)=>{e.addTextureSampler(`${Object(w.e)(o.dataType)}sampler2D`,`uVertexAttributeSampler${r}`,k[r]);const c=O(o);e.addVarying(`highp ${c}`,`vCustom${a}`),e.addFragmentCode(`\n#define ${i[a]} vCustom${a}\n`),e.addVertexCode(n.getAccessor(`readAttribute${a}`,`uVertexAttributeSampler${r}`,o.dataType,o.numComponents)),s+=`vCustom${a} = readAttribute${a}(${t});\n`,++r}),e.addVertexMain(s)}defineShader(e){e.require(b),this.indexBufferHelper.defineShader(e),e.addVarying("highp float","vLightingFactor"),e.addUniform("highp vec4","uLightDirection"),e.addUniform("highp vec4","uColor"),e.addUniform("highp mat4","uModelMatrix"),e.addUniform("highp mat4","uProjection"),e.addUniform("highp uint","uPickID"),e.addVarying("highp uint","vPickID","flat"),e.addVertexMain("\nuint triangleIndex = getPrimitiveIndex() / 3u;\nvPickID = uPickID + triangleIndex;\n"),e.addFragmentCode("\nvoid emitPremultipliedRGBA(vec4 color) {\n  emit(vec4(color.rgb * vLightingFactor, color.a), vPickID);\n}\nvoid emitRGBA(vec4 color) {\n  color = clamp(color, 0.0, 1.0);\n  color.xyz *= color.a;\n  emitPremultipliedRGBA(color);\n}\nvoid emitRGB(vec3 color) {\n  emitRGBA(vec4(color, 1.0));\n}\nvoid emitGray() {\n  emitRGB(vec3(1.0, 1.0, 1.0));\n}\n"),e.addFragmentCode(h.a),this.defineAttributeAccess(e,"vertexIndex"),e.addVertexMain("\ngl_Position = uProjection * (uModelMatrix * vec4(vertexPosition, 1.0));\nvec3 normal = normalize((uModelMatrix * vec4(vertexNormal, 0.0)).xyz);\nvLightingFactor = abs(dot(normal, uLightDirection.xyz)) + uLightDirection.w;\n")}beginLayer(e,t,n){const{lightDirection:i,ambientLighting:r,directionalLighting:s,projectionParameters:o}=n,{viewProjectionMat:a}=o;e.uniformMatrix4fv(t.uniform("uProjection"),!1,a);let c=this.tempLightVec;d.u.scale(c,i,s),c[3]=r,e.uniform4fv(t.uniform("uLightDirection"),c)}setPickID(e,t,n){e.uniform1ui(t.uniform("uPickID"),n)}beginObject(e,t,n){e.uniformMatrix4fv(t.uniform("uModelMatrix"),!1,n)}bindVertexData(e,t,n){let i=0;const r=n=>{const r=WebGL2RenderingContext.TEXTURE0+t.textureUnit(k[i]);e.activeTexture(r),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,n),++i};r(n.vertexTexture),r(n.normalTexture);const{attributeNames:s}=this;n.vertexAttributeTextures.forEach((e,t)=>{void 0!==s[t]&&r(e)})}disableVertexData(e,t){let n=2,i=this.attributeInfo.length,{attributeNames:r}=this;for(let e=0;e<i;++e)void 0!==r[e]&&++n;for(let i=0;i<n;++i){let n=t.textureUnit(k[i])+WebGL2RenderingContext.TEXTURE0;e.activeTexture(n),e.bindTexture(e.TEXTURE_2D,null)}}drawFragment(e,t,n,i){i.ensure(n.numIndices).bind(t),this.bindVertexData(e,t,n.vertexData),this.indexBufferHelper.bind(n.indexBuffer,t),e.drawArrays(WebGL2RenderingContext.TRIANGLES,0,n.numIndices)}endLayer(e,t){!function(e,t,n=!1){const i=t.attribute("aIndexRaw");i>=0&&(n&&e.vertexAttribDivisor(i,0),e.disableVertexAttribArray(i))}(e,t),this.indexBufferHelper.disable(t),this.disableVertexData(e,t)}}class L{copyToGPU(e,t){const n=(t,n)=>{let i=e.createTexture();return e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,i),Object(w.f)(e,n,t),i};this.vertexTexture=n(this.vertexPositions,E),this.normalTexture=n(this.vertexNormals,T),this.vertexAttributeTextures=this.vertexAttributes.map((e,i)=>n(e,t[i])),e.bindTexture(WebGL2RenderingContext.TEXTURE_2D,null)}freeGPUMemory(e){e.deleteTexture(this.vertexTexture),e.deleteTexture(this.normalTexture);let{vertexAttributeTextures:t}=this;for(const n of t)e.deleteTexture(n);t.length=0}}class j extends r.b{constructor(e,t){super(e);const n=this.vertexData=new L;n.vertexPositions=t.vertexPositions,n.vertexNormals=t.vertexNormals,n.vertexAttributes=t.vertexAttributes;let i=this.indices=t.indices;this.numIndices=i.length}copyToGPU(e){super.copyToGPU(e),this.vertexData.copyToGPU(e,this.source.attributeTextureFormats),this.indexBuffer=function(e,t){return m.a.fromData(e,t,WebGL2RenderingContext.ARRAY_BUFFER,WebGL2RenderingContext.STATIC_DRAW)}(e,this.indices)}freeGPUMemory(e){super.freeGPUMemory(e),this.vertexData.freeGPUMemory(e),this.indexBuffer.dispose()}}class I extends(Object(r.g)(r.f,a)){constructor(){super(...arguments),this.attributeTextureFormats=this.info.vertexAttributes.map(e=>Object(w.d)(new w.c,e.dataType,e.numComponents))}get info(){return this.parameters.info}getChunk(e){return new j(this,e)}}const P=Object(u.c)(x.b);class A extends P{}class R extends s.a{constructor(e,t,n){var i;super(),this.source=e,this.displayState=t,this.transform=n,this.shaderManager=new D(M(this.source.info.vertexAttributes.map(e=>e.name)),this.source.info.vertexAttributes),this.shaders=new Map,this.sharedObject=this.registerDisposer(new A),this.shaderGetter=Object(p.d)(this,this.gl,{memoizeKey:{t:"single_mesh/RenderLayer",attributes:this.source.info.vertexAttributes},fallbackParameters:new c.e(Object(S.c)("void main() {\n  emitGray();\n}\n")),parameters:this.displayState.shaderControlState.parseResult,encodeParameters:e=>e.source,shaderError:this.displayState.shaderError,defineShader:(e,t)=>{if(0!==t.errors.length)throw new Error("Invalid UI control specification");Object(S.b)(t.controls,e),this.shaderManager.defineShader(e),e.setFragmentMainFunction(Object(p.e)(t.code))}}),this.countingBuffer=this.registerDisposer((i=this.gl).memoize.get("IndexBuffer",()=>new v(i))),this.registerDisposer(t.shaderControlState.parseResult.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(t.shaderControlState.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(n.changed.add(this.redrawNeeded.dispatch));const{sharedObject:r}=this;r.visibility.add(this.visibility),r.RPC_TYPE_ID="single_mesh/SingleMeshLayer",r.initializeCounterpart(e.chunkManager.rpc,{chunkManager:e.chunkManager.rpcId,source:e.addCounterpartRef()})}disposeShaders(){let{shaders:e}=this;for(let t of e.values())null!==t&&t.dispose();e.clear()}disposed(){this.disposeShaders(),super.disposed()}get isTransparent(){return null!==this.displayState.fragmentMain.value.match(/emitRGBA|emitPremultipliedRGBA/)}get gl(){return this.source.gl}draw(e,t){if(!e.emitColor&&e.alreadyEmittedPickID)return;const n=Object(o.g)(this.transform.value,e.projectionParameters.displayDimensionRenderInfo,t);if(void 0===n)return;let r=this.source.chunks.get("");if(void 0===r||r.state!==i.h.GPU_MEMORY)return;const s=this.shaderGetter(e.emitter),{shader:a,parameters:c}=s;if(null===a)return;const{gl:l}=this,d=this.shaderManager;a.bind(),d.beginLayer(l,a,e),Object(S.d)(l,a,this.displayState.shaderControlState,c.controls);let{pickIDs:u}=e;d.beginObject(l,a,n),e.emitPickID&&d.setPickID(l,a,u.register(this,r.numIndices/3)),d.drawFragment(l,a,r,this.countingBuffer),d.endLayer(l,a)}transformPickedValue(e,t){let n=this.source.chunks.get("");if(void 0===n)return;let i=3*t,{indices:r}=n;if(i>=r.length)return;let s=r[i],o=[];const{attributeNames:a}=this.shaderManager;return n.vertexData.vertexAttributes.forEach((e,t)=>{const n=a[t];void 0!==n&&o.push(`${n}=${e[s].toPrecision(6)}`)}),o.join(", ")}}function N(e,t){return function(e,t){return e.memoize.getUncounted({type:"single_mesh:getMeshInfo",parameters:t},()=>e.rpc.promiseInvoke("single_mesh/getSingleMeshInfo",{chunkManager:e.addCounterpartRef(),parameters:t}))}(e,t).then(n=>e.getChunkSource(I,{parameters:Object.assign(Object.assign({},t),{info:n})}))}},function(e,t,n){"use strict";var i=n(247);e.exports={string:function(e){for(var t="abcdefghijklmnopqrstuvwxyz012345".length,n=i.randomBytes(e),r=[],s=0;s<e;s++)r.push("abcdefghijklmnopqrstuvwxyz012345".substr(n[s]%t,1));return r.join("")},number:function(e){return Math.floor(Math.random()*e)},numberString:function(e){var t=(""+(e-1)).length;return(new Array(t+1).join("0")+this.number(e)).slice(-t)}}},function(e,t,n){"use strict";var i=n(33),r=n(73),s=n(162);function o(e,t,n,i){s.call(this,e,t,function(e){return function(t,n,i){var s={};"string"==typeof n&&(s.headers={"Content-type":"text/plain"});var o=r.addPath(t,"/xhr_send"),a=new e("POST",o,n,s);return a.once("finish",(function(e){if(a=null,200!==e&&204!==e)return i(new Error("http status "+e));i()})),function(){a.close(),a=null;var e=new Error("Aborted");e.code=1e3,i(e)}}}(i),n,i)}i(o,s),e.exports=o},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(2),r=n(3);
/**
 * @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 s extends i.a{constructor(e,t){if(super(),this.register=e,this.changed=new r.a,this.disposerMap=new Map,void 0===t)this.map=new Map;else{const n=this.map=new Map(t),{disposerMap:r}=this;for(const[t,s]of n){const n=new i.a;r.set(t,n),e(n,s,t)}}}get value(){return this.map}set(e,t){const{map:n,disposerMap:r}=this;let s=r.get(e);return void 0!==s&&s.dispose(),s=new i.a,r.set(e,s),n.set(e,t),this.register(s,t,e),this.changed.dispatch(),this}delete(e){const{map:t,disposerMap:n}=this,i=n.get(e);return void 0!==i&&(i.dispose(),n.delete(e),t.delete(e),this.changed.dispatch(),!0)}get(e){return this.map.get(e)}has(e){return this.map.has(e)}get size(){return this.map.size}[Symbol.iterator](){return this.map[Symbol.iterator]()}clear(){const{map:e,disposerMap:t}=this;if(e.size>0){for(const e of t.values())e.dispose();e.clear(),t.clear(),this.changed.dispatch()}}values(){return this.map.values()}keys(){return this.map.keys()}disposed(){const{map:e,disposerMap:t}=this;for(const e of t.values())e.dispose();e.clear(),t.clear(),super.disposed()}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return l})),n.d(t,"b",(function(){return u}));var i=n(13);
/**
 * @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 r,s,o,a,c;function l(){return void 0===s&&(s=i.a.fromObject({"control+mousedown2":"select-position"})),s}function d(){return void 0===o&&(o=i.a.fromObject({arrowleft:"x-",arrowright:"x+",arrowup:"y-",arrowdown:"y+",comma:"z-",period:"z+",bracketleft:"t-",bracketright:"t+",keyz:"snap","control+equal":"zoom-in","alt+equal":"depth-range-decrease","control+shift+equal":"zoom-in","alt+shift+equal":"depth-range-decrease","control+minus":"zoom-out","alt+minus":"depth-range-increase",keyr:"rotate-relative-z-",keye:"rotate-relative-z+","shift+arrowdown":"rotate-relative-x-","shift+arrowup":"rotate-relative-x+","shift+arrowleft":"rotate-relative-y-","shift+arrowright":"rotate-relative-y+","control+wheel":{action:"zoom-via-wheel",preventDefault:!0},"alt+wheel":{action:"adjust-depth-range-via-wheel",preventDefault:!0},"at:wheel":{action:"z+1-via-wheel",preventDefault:!0},"at:shift+wheel":{action:"z+10-via-wheel",preventDefault:!0},"at:dblclick0":"select","at:control+mousedown0":"annotate","at:mousedown2":"move-to-mouse-position","at:alt+mousedown0":"move-annotation","at:control+alt+mousedown2":"delete-annotation","at:touchpinch":"zoom-via-touchpinch","at:touchrotate":"rotate-in-plane-via-touchrotate","at:touchtranslate2":"translate-in-plane-via-touchtranslate","at:touchhold1":"move-to-mouse-position","at:touchtap1x2":"select","at:touchtap2x3":"snap"},{label:"All Data Panels",parents:[[l(),0]]})),o}function u(e){e.global.addParent(function(){if(void 0===r){const e=new i.a;e.set("keyl","recolor"),e.set("keyx","clear-segments"),e.set("keys","toggle-show-slices"),e.set("keyb","toggle-scale-bar"),e.set("shift+keyb","toggle-default-annotations"),e.set("keya","toggle-axis-lines"),e.set("keyo","toggle-orthographic-projection");for(let t=1;t<=9;++t)e.set("digit"+t,"toggle-layer-"+t),e.set("control+digit"+t,"select-layer-"+t),e.set("alt+digit"+t,"toggle-pick-layer-"+t);e.set("keyn","add-layer"),e.set("keyh","help"),e.set("space","toggle-layout"),e.set("shift+space","toggle-layout-alternative"),e.set("backslash","toggle-show-statistics"),r=e}return r}(),Number.NEGATIVE_INFINITY),e.sliceView.addParent((void 0===c&&(c=i.a.fromObject({"at:mousedown0":{action:"translate-via-mouse-drag",stopPropagation:!0},"at:shift+mousedown0":{action:"rotate-via-mouse-drag",stopPropagation:!0},"at:touchtranslate1":"translate-z-via-touchtranslate"},{parents:[[d(),Number.NEGATIVE_INFINITY]]})),c),Number.NEGATIVE_INFINITY),e.perspectiveView.addParent((void 0===a&&(a=i.a.fromObject({"at:mousedown0":{action:"rotate-via-mouse-drag",stopPropagation:!0},"at:shift+mousedown0":{action:"translate-via-mouse-drag",stopPropagation:!0},"at:touchtranslate1":"rotate-out-of-plane-via-touchtranslate"},{parents:[[d(),Number.NEGATIVE_INFINITY]]})),a),Number.NEGATIVE_INFINITY)}},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(2);
/**
 * @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 r extends i.a{constructor(e){super(),this.model=e,this.element=document.createElement("select"),this.valueIndexMap=new Map;const{element:t,valueIndexMap:n}=this;let i=0;for(const r of Object.keys(e.enumType))if(isNaN(Number(r))){const s=document.createElement("option");s.textContent=s.value=r.toLowerCase(),t.appendChild(s),n.set(e.enumType[r],i),++i}this.registerDisposer(e.changed.add(()=>this.updateView())),this.registerEventListener(t,"change",()=>this.updateModel()),this.registerEventListener(t,"wheel",e=>{let{deltaY:n}=e;n>0?(t.selectedIndex=(t.options.length+t.selectedIndex-1)%t.options.length,this.updateModel()):n<0&&(t.selectedIndex=(t.options.length+t.selectedIndex+1)%t.options.length,this.updateModel())}),this.updateView()}updateView(){const{element:e}=this;e.selectedIndex=this.valueIndexMap.get(this.model.value)}updateModel(){this.model.restoreState(this.element.value)}}},function(e,t,n){"use strict";n(212);var i=n(8),r=n(118),s=n(61),o=n(55),a=n(75),c=n(7),l=n(80),d=n(43),u=n(60),h=n(29),p=n(20),f=n(49);
/**
 * @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 m=1+l.a,g=m+l.b,v=g+6,b=Float32Array.from([0,0,0,0,0,1,m+0,1,0,0,1,0,1,m+1,0,1,0,0,1,1,m+2,1,1,0,1,1,1,m+3,0,0,0,0,1,0,m+4,0,0,1,0,1,1,m+5,1,0,0,1,1,0,m+6,1,0,1,1,1,1,m+7,0,0,0,1,0,0,m+8,0,0,1,1,0,1,m+9,0,1,0,1,1,0,m+10,0,1,1,1,1,1,m+11]);class y extends o.a{constructor(){super(...arguments),this.vertexIdHelper=this.registerDisposer(f.a.get(this.gl))}defineShader(e){Object(f.b)(e);const{rank:t}=this;Object(p.a)(e,"float",WebGL2RenderingContext.FLOAT,!1,"Bounds",t,2)}enable(e,t,n){super.enable(e,t,e=>{const i=e.vertexShaderInputBinders.Bounds;i.enable(1),this.gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER,t.buffer.buffer),i.bind(this.serializedBytesPerAnnotation,t.bufferOffset);const{vertexIdHelper:r}=this;r.enable(),n(e),r.disable(),i.disable()})}}function S(e){e.addVertexCode("\nvoid setBoundingBoxBorderWidth(float width) {}\nvoid setBoundingBoxBorderColor(vec4 color) {}\n")}function w(e){e.addVertexCode("\nvoid setBoundingBoxFillColor(vec4 color) {}\n")}function x(e){w(e),e.addVertexCode("\nfloat ng_lineWidth;\nvoid setBoundingBoxBorderWidth(float size) {\n  ng_lineWidth = size;\n}\nvoid setBoundingBoxBorderColor(vec4 color) {\n  vColor = color;\n}\n")}Object(o.c)(i.e.AXIS_ALIGNED_BOUNDING_BOX,{sliceViewRenderHelper:class extends y{constructor(){super(...arguments),this.faceShaderGetter=this.getDependentShader("annotation/boundingBox/crossSection/face",e=>{const{rank:t}=this;super.defineShader(e),Object(a.b)(e),Object(h.b)(e),e.addVarying("highp float","vClipCoefficient"),x(e),e.setVertexMain(`\nfloat modelPositionA[${t}] = getBounds0();\nfloat modelPositionB[${t}] = getBounds1();\nfor (int i = 0; i < ${t}; ++i) {\n  float a = modelPositionA[i];\n  float b = modelPositionB[i];\n  modelPositionA[i] = min(a, b);\n  modelPositionB[i] = max(a, b);\n}\nvClipCoefficient = getMaxSubspaceClipCoefficient(modelPositionA, modelPositionB);\nif (vClipCoefficient == 0.0) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nvec3 subspacePositionA = projectModelVectorToSubspace(modelPositionA);\nvec3 subspacePositionB = projectModelVectorToSubspace(modelPositionB);\nint vertexIndex1 = gl_VertexID / ${h.a};\nint vertexIndex2 = vertexIndex1 == 5 ? 0 : vertexIndex1 + 1;\nvec3 vertexPosition1 = getBoundingBoxPlaneIntersectionVertexPosition(subspacePositionB - subspacePositionA, subspacePositionA, subspacePositionA, subspacePositionB, vertexIndex1);\nvec3 vertexPosition2 = getBoundingBoxPlaneIntersectionVertexPosition(subspacePositionB - subspacePositionA, subspacePositionA, subspacePositionA, subspacePositionB, vertexIndex2);\nng_lineWidth = 1.0;\n${this.invokeUserMain}\nemitLine(uModelViewProjection * vec4(vertexPosition1, 1.0),\n         uModelViewProjection * vec4(vertexPosition2, 1.0),\n         ng_lineWidth);\n${this.setPartIndex(e)};\n`),e.setFragmentMain("\nemitAnnotation(vec4(vColor.rgb, vColor.a * getLineAlpha() * vClipCoefficient));\n")}),this.fillShaderGetter=this.getDependentShader("annotation/boundingBox/crossSection/fill",e=>{const{rank:t}=this;super.defineShader(e),Object(a.b)(e),e.addVarying("highp float","vClipCoefficient"),function(e){S(e),e.addVertexCode("\nvoid setBoundingBoxFillColor(vec4 color) {\n  vColor = color;\n}\n")}(e),e.setVertexMain(`\nfloat modelPositionA[${t}] = getBounds0();\nfloat modelPositionB[${t}] = getBounds1();\nfor (int i = 0; i < ${t}; ++i) {\n  float a = modelPositionA[i];\n  float b = modelPositionB[i];\n  modelPositionA[i] = min(a, b);\n  modelPositionB[i] = max(a, b);\n}\nvClipCoefficient = getMaxSubspaceClipCoefficient(modelPositionA, modelPositionB);\nif (vClipCoefficient == 0.0) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nvec3 subspacePositionA = projectModelVectorToSubspace(modelPositionA);\nvec3 subspacePositionB = projectModelVectorToSubspace(modelPositionB);\nint vertexIndex = gl_VertexID;\nvec3 vertexPosition = getBoundingBoxPlaneIntersectionVertexPosition(subspacePositionB - subspacePositionA, subspacePositionA, subspacePositionA, subspacePositionB, vertexIndex);\ngl_Position = uModelViewProjection * vec4(vertexPosition, 1);\n${this.invokeUserMain}\n${this.setPartIndex(e)};\n`),e.setFragmentMain("\nemitAnnotation(vec4(vColor.rgb, vColor.a * vClipCoefficient));\n")})}enableForBoundingBox(e,t,n){super.enable(e,t,e=>{const i=t.renderContext.sliceView.projectionParameters.value;Object(a.c)(e,i.viewportNormalInGlobalCoordinates,i.centerDataPosition,t.renderSubspaceModelMatrix,t.renderSubspaceInvModelMatrix),n(e)})}draw(e){this.shaderControlState.parseResult.value.code.match(/\bsetBoundingBoxFillColor\b/)&&this.enableForBoundingBox(this.fillShaderGetter,e,()=>{this.gl.drawArraysInstanced(WebGL2RenderingContext.TRIANGLE_FAN,0,6,e.count)}),this.enableForBoundingBox(this.faceShaderGetter,e,t=>{Object(h.d)(t,e.renderContext.projectionParameters,1),Object(h.c)(t.gl,6,e.count)})}},perspectiveViewRenderHelper:class extends y{constructor(){super(...arguments),this.edgeBoxCornerOffsetsBuffer=this.registerDisposer(d.a.fromData(this.gl,Object(c.l)(b,7,1,h.a))),this.edgeShaderGetter=this.getDependentShader("annotation/boundingBox/projection/border",e=>{const{rank:t}=this;this.defineShader(e),Object(h.b)(e),e.addAttribute("highp vec3","aBoxCornerOffset1"),e.addAttribute("highp vec4","aBoxCornerOffset2"),e.addVarying("highp float","vClipCoefficient"),x(e),e.setVertexMain(`\nfloat modelPositionA[${t}] = getBounds0();\nfloat modelPositionB[${t}] = getBounds1();\nvec3 subspacePositionA = projectModelVectorToSubspace(modelPositionA);\nvec3 subspacePositionB = projectModelVectorToSubspace(modelPositionB);\nvec3 endpointA = mix(subspacePositionA, subspacePositionB, aBoxCornerOffset1);\nvec3 endpointB = mix(subspacePositionA, subspacePositionB, aBoxCornerOffset2.xyz);\nvClipCoefficient = getMaxSubspaceClipCoefficient(modelPositionA, modelPositionB);\nif (vClipCoefficient == 0.0) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nng_lineWidth = 1.0;\n${this.invokeUserMain}\nemitLine(uModelViewProjection * vec4(endpointA, 1.0),\n         uModelViewProjection * vec4(endpointB, 1.0),\n         ng_lineWidth);\n${this.setPartIndex(e,"uint(aBoxCornerOffset2.w)")};\n`),e.setFragmentMain("\nemitAnnotation(vec4(vColor.rgb, getLineAlpha() * vClipCoefficient));\n")}),this.boxCornerOffsetsBuffer=this.registerDisposer(d.a.fromData(this.gl,Object(c.l)(a.d,3,1,u.a))),this.cornerShaderGetter=this.getDependentShader("annotation/boundingBox/projection/corner",e=>{const{rank:t}=this;this.defineShader(e),Object(u.b)(e,this.targetIsSliceView),e.addAttribute("highp vec3","aBoxCornerOffset"),e.addVarying("highp float","vClipCoefficient"),x(e),e.setVertexMain(`\nfloat modelPositionA[${t}] = getBounds0();\nfloat modelPositionB[${t}] = getBounds1();\nvClipCoefficient = getMaxEndpointSubspaceClipCoefficient(modelPositionA, modelPositionB);\nif (vClipCoefficient == 0.0) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nvec3 subspacePositionA = projectModelVectorToSubspace(modelPositionA);\nvec3 subspacePositionB = projectModelVectorToSubspace(modelPositionB);\nvec3 vertexPosition = mix(subspacePositionA, subspacePositionB, aBoxCornerOffset);\nemitCircle(uModelViewProjection * vec4(vertexPosition, 1.0), ng_lineWidth, 0.0);\nuint cornerIndex = uint(aBoxCornerOffset.x + aBoxCornerOffset.y * 2.0 + aBoxCornerOffset.z * 4.0);\nuint cornerPickOffset = 1u + cornerIndex;\n${this.setPartIndex(e,"cornerPickOffset")};\n`),e.setFragmentMain("\nvec4 borderColor = vec4(0.0, 0.0, 0.0, 1.0);\nvec4 color = getCircleColor(vColor, borderColor);\ncolor.a *= vClipCoefficient;\nemitAnnotation(color);\n")})}drawEdges(e){const{gl:t}=this;this.enable(this.edgeShaderGetter,e,n=>{const i=n.attribute("aBoxCornerOffset1"),r=n.attribute("aBoxCornerOffset2");this.edgeBoxCornerOffsetsBuffer.bindToVertexAttrib(i,3,WebGL2RenderingContext.FLOAT,!1,28,0),this.edgeBoxCornerOffsetsBuffer.bindToVertexAttrib(r,4,WebGL2RenderingContext.FLOAT,!1,28,12),Object(h.d)(n,e.renderContext.projectionParameters,1),Object(h.c)(t,l.b,e.count),t.disableVertexAttribArray(i),t.disableVertexAttribArray(r)})}drawCorners(e){const{gl:t}=this;this.enable(this.cornerShaderGetter,e,n=>{const i=n.attribute("aBoxCornerOffset");this.boxCornerOffsetsBuffer.bindToVertexAttrib(i,3,WebGL2RenderingContext.FLOAT,!1),Object(u.d)(n,e.renderContext.projectionParameters,{featherWidthInPixels:0}),Object(u.c)(n.gl,l.a,e.count),t.disableVertexAttribArray(i)})}draw(e){this.drawEdges(e),this.drawCorners(e)}},defineShaderNoOpSetters(e){w(e),S(e)},pickIdsPerInstance:v,snapPosition(e,t,n,i){const r=new Float32Array(t,n,6);i>=1&&i<m&&function(e,t){const n=e.length;for(let i=0;i<n;++i){const r=t[i],s=t[i+n],o=e[i];e[i]=Math.abs(r-o)<Math.abs(s-o)?r:s}}(e,r)},getRepresentativePoint(e,t,n){e.set(t.pointA)},updateViaRepresentativePoint(e,t,n){const i=t.length,{pointA:r,pointB:s}=e,o=new Float32Array(i),a=new Float32Array(i);for(let e=0;e<i;++e){const n=o[e]=t[e];a[e]=s[e]+(n-r[e])}return Object.assign(Object.assign({},e),{pointA:o,pointB:a})}});var C=n(1);
/**
 * @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 O(e){e.addVertexCode("\nvoid setEndpointMarkerSize(float startSize, float endSize) {}\nvoid setEndpointMarkerBorderWidth(float startSize, float endSize) {}\nvoid setEndpointMarkerColor(vec4 startColor, vec4 endColor) {}\nvoid setEndpointMarkerBorderColor(vec4 startColor, vec4 endColor) {}\n")}function k(e){e.addVertexCode("\nvoid setLineWidth(float width) {}\nvoid setLineColor(vec4 startColor, vec4 endColor) {}\n")}class E extends o.a{constructor(){super(...arguments),this.vertexIdHelper=this.registerDisposer(f.a.get(this.gl)),this.edgeShaderGetter=this.getDependentShader("annotation/line/edge",e=>{const{rank:t}=this;this.defineShader(e),Object(h.b)(e),e.addVarying(`highp float[${t}]`,"vModelPosition"),e.addVertexCode("\nfloat ng_LineWidth;\n"),O(e),e.addVertexCode("\nvoid setLineWidth(float width) {\n  ng_LineWidth = width;\n}\nvoid setLineColor(vec4 startColor, vec4 endColor) {\n  vColor = mix(startColor, endColor, getLineEndpointCoefficient());\n}\n"),e.setVertexMain(`\nfloat modelPositionA[${t}] = getVertexPosition0();\nfloat modelPositionB[${t}] = getVertexPosition1();\nfor (int i = 0; i < ${t}; ++i) {\n  vModelPosition[i] = mix(modelPositionA[i], modelPositionB[i], getLineEndpointCoefficient());\n}\nng_LineWidth = 1.0;\nvColor = vec4(0.0, 0.0, 0.0, 0.0);\n${this.invokeUserMain}\nemitLine(uModelViewProjection * vec4(projectModelVectorToSubspace(modelPositionA), 1.0),\n         uModelViewProjection * vec4(projectModelVectorToSubspace(modelPositionB), 1.0),\n         ng_LineWidth);\n${this.setPartIndex(e)};\n`),e.setFragmentMain(`\nfloat clipCoefficient = getSubspaceClipCoefficient(vModelPosition);\nemitAnnotation(vec4(vColor.rgb, vColor.a * getLineAlpha() *\n                                ${this.getCrossSectionFadeFactor()} *\n                                clipCoefficient));\n`)}),this.endpointShaderGetter=this.getDependentShader("annotation/line/endpoint",e=>{const{rank:t}=this;this.defineShader(e),Object(u.b)(e,this.targetIsSliceView),e.addVarying("highp float","vClipCoefficient"),e.addVarying("highp vec4","vBorderColor"),k(e),e.addVertexCode(`\nfloat ng_markerDiameter;\nfloat ng_markerBorderWidth;\nint getEndpointIndex() {\n  return gl_VertexID / ${u.a};\n}\nvoid setEndpointMarkerSize(float startSize, float endSize) {\n  ng_markerDiameter = mix(startSize, endSize, float(getEndpointIndex()));\n}\nvoid setEndpointMarkerBorderWidth(float startSize, float endSize) {\n  ng_markerBorderWidth = mix(startSize, endSize, float(getEndpointIndex()));\n}\nvoid setEndpointMarkerColor(vec4 startColor, vec4 endColor) {\n  vColor = mix(startColor, endColor, float(getEndpointIndex()));\n}\nvoid setEndpointMarkerBorderColor(vec4 startColor, vec4 endColor) {\n  vBorderColor = mix(startColor, endColor, float(getEndpointIndex()));\n}\n`),e.setVertexMain(`\nfloat modelPosition[${t}] = getVertexPosition0();\nfloat modelPositionB[${t}] = getVertexPosition1();\nfor (int i = 0; i < ${t}; ++i) {\n  modelPosition[i] = mix(modelPosition[i], modelPositionB[i], float(getEndpointIndex()));\n}\nvClipCoefficient = getSubspaceClipCoefficient(modelPosition);\nvColor = vec4(0.0, 0.0, 0.0, 0.0);\nvBorderColor = vec4(0.0, 0.0, 0.0, 1.0);\nng_markerDiameter = 5.0;\nng_markerBorderWidth = 1.0;\n${this.invokeUserMain}\nemitCircle(uModelViewProjection * vec4(projectModelVectorToSubspace(modelPosition), 1.0), ng_markerDiameter, ng_markerBorderWidth);\n${this.setPartIndex(e,"uint(getEndpointIndex()) + 1u")};\n`),e.setFragmentMain("\nvec4 color = getCircleColor(vColor, vBorderColor);\ncolor.a *= vClipCoefficient;\nemitAnnotation(color);\n")})}defineShader(e){Object(f.b)(e);const{rank:t}=this;Object(p.a)(e,"float",WebGL2RenderingContext.FLOAT,!1,"VertexPosition",t,2)}enable(e,t,n){super.enable(e,t,e=>{const i=e.vertexShaderInputBinders.VertexPosition;i.enable(1),this.gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER,t.buffer.buffer),i.bind(this.serializedBytesPerAnnotation,t.bufferOffset);const{vertexIdHelper:r}=this;r.enable(),n(e),r.disable(),i.disable()})}drawEdges(e){this.enable(this.edgeShaderGetter,e,t=>{Object(h.d)(t,e.renderContext.projectionParameters,1),Object(h.c)(t.gl,1,e.count)})}drawEndpoints(e){this.enable(this.endpointShaderGetter,e,t=>{Object(u.d)(t,e.renderContext.projectionParameters,{featherWidthInPixels:.5}),Object(u.c)(t.gl,2,e.count)})}draw(e){this.drawEdges(e),this.drawEndpoints(e)}}Object(o.c)(i.e.LINE,{sliceViewRenderHelper:E,perspectiveViewRenderHelper:E,defineShaderNoOpSetters(e){O(e),k(e)},pickIdsPerInstance:3,snapPosition(e,t,n,i){const r=e.length,s=new Float32Array(t,n,2*r);0===i?function(e,t){const n=e.length;Object(C.o)(e,t.subarray(0,n),t.subarray(n),e)}(e,s):function(e,t,n){const i=e.length,r=i*n;for(let n=0;n<i;++n)e[n]=t[r+n]}(e,s,i-1)},getRepresentativePoint(e,t,n){e.set(0===n||1===n?t.pointA:t.pointB)},updateViaRepresentativePoint(e,t,n){let i=Object.assign({},e);const r=t.length;switch(n){case 0:{const{pointA:n,pointB:i}=e,s=new Float32Array(r),o=new Float32Array(r);for(let e=0;e<r;++e){const r=s[e]=t[e];o[e]=i[e]+(r-n[e])}return Object.assign(Object.assign({},e),{pointA:s,pointB:o})}case 1:return Object.assign(Object.assign({},e),{pointA:new Float32Array(t)});case 2:return Object.assign(Object.assign({},e),{pointB:new Float32Array(t)})}return 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.
 */
class T extends o.a{constructor(){super(...arguments),this.shaderGetter3d=this.getDependentShader("annotation/point:3d",e=>{Object(f.b)(e),Object(u.b)(e,this.targetIsSliceView),this.defineShaderCommon(e),e.addVertexMain("\nemitCircle(uModelViewProjection *\n           vec4(projectModelVectorToSubspace(modelPosition), 1.0), ng_markerDiameter, ng_markerBorderWidth);\n"),e.setFragmentMain("\nvec4 color = getCircleColor(vColor, vBorderColor);\nemitAnnotation(color);\n")}),this.makeShaderGetter2d=e=>this.getDependentShader(`annotation/point:2d:${e}`,t=>{Object(f.b)(t),Object(h.b)(t,!0),this.defineShaderCommon(t),t.addVertexMain(`\nvec3 subspacePositionA = projectModelVectorToSubspace(modelPosition);\nvec3 subspacePositionB = subspacePositionA;\nvec4 baseProjection = uModelViewProjection * vec4(subspacePositionA, 1.0);\nvec4 zCoeffs = uModelViewProjection[${e}];\nfloat minZ = 1e30;\nfloat maxZ = -1e30;\nfor (int i = 0; i < 3; ++i) {\n  // Want: baseProjection[i] + z * zCoeffs[i] = -2.0 * (baseProjection.w - z * zCoeffs.w)\n  //  i.e. baseProjection[i] + 2.0 * baseProjection.w < -z * (2.0 * zCoeffs.w + zCoeffs[i])\n  //  i.e. baseProjection[i] + 2.0 * baseProjection.w < -z * k1\n  float k1 = 2.0 * zCoeffs.w + zCoeffs[i];\n  float q1 = -(baseProjection[i] + 2.0 * baseProjection.w) / k1;\n  if (k1 != 0.0) {\n    minZ = min(minZ, q1);\n    maxZ = max(maxZ, q1);\n  }\n  // Want: baseProjection[i] + z * zCoeffs[i] = 2.0 * (baseProjection.w + z * zCoeffs.w)\n  //  i.e. baseProjection[i] - 2.0 * baseProjection.w > z * (2.0 * zCoeffs.w - zCoeffs[i])\n  //  i.e. baseProjection[i] - 2.0 * baseProjection.w > z * k2\n  float k2 = 2.0 * zCoeffs.w - zCoeffs[i];\n  float q2 = (baseProjection[i] - 2.0 * baseProjection.w) / k2;\n  if (k2 != 0.0) {\n    minZ = min(minZ, q2);\n    maxZ = max(maxZ, q2);\n  }\n}\nif (minZ > maxZ) minZ = maxZ = 0.0;\nsubspacePositionA[${e}] = minZ;\nsubspacePositionB[${e}] = maxZ;\nemitLine(uModelViewProjection, subspacePositionA, subspacePositionB, ng_markerDiameter, ng_markerBorderWidth);\n`),t.setFragmentMain(`\nvec4 color = getRoundedLineColor(vColor, vBorderColor);\nemitAnnotation(vec4(color.rgb, color.a * ${this.getCrossSectionFadeFactor()}));\n`)}),this.shaderGetter2d=this.makeShaderGetter2d(2),this.shaderGetter1d=this.makeShaderGetter2d(1),this.vertexIdHelper=this.registerDisposer(f.a.get(this.gl))}defineShaderCommon(e){const{rank:t}=this;Object(p.a)(e,"float",WebGL2RenderingContext.FLOAT,!1,"VertexPosition",t),e.addVarying("highp vec4","vBorderColor"),e.addVertexCode("\nfloat ng_markerDiameter;\nfloat ng_markerBorderWidth;\nvoid setPointMarkerSize(float size) {\n  ng_markerDiameter = size;\n}\nvoid setPointMarkerBorderWidth(float size) {\n  ng_markerBorderWidth = size;\n}\nvoid setPointMarkerColor(vec4 color) {\n  vColor = color;\n}\nvoid setPointMarkerBorderColor(vec4 color) {\n  vBorderColor = color;\n}\n"),e.addVertexMain(`\nng_markerDiameter = 5.0;\nng_markerBorderWidth = 1.0;\nvBorderColor = vec4(0.0, 0.0, 0.0, 1.0);\nfloat modelPosition[${t}] = getVertexPosition0();\nfloat clipCoefficient = getSubspaceClipCoefficient(modelPosition);\nif (clipCoefficient == 0.0) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\n${this.invokeUserMain}\nvColor.a *= clipCoefficient;\nvBorderColor.a *= clipCoefficient;\n${this.setPartIndex(e)};\n`)}enable(e,t,n){super.enable(e,t,e=>{const i=e.vertexShaderInputBinders.VertexPosition;i.enable(1),this.gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER,t.buffer.buffer),i.bind(this.serializedBytesPerAnnotation,t.bufferOffset);const{vertexIdHelper:r}=this;r.enable(),n(e),r.disable(),i.disable()})}draw(e){const{numChunkDisplayDims:t}=e.chunkDisplayTransform;switch(t){case 3:this.enable(this.shaderGetter3d,e,t=>{Object(u.d)(t,e.renderContext.projectionParameters,{featherWidthInPixels:1}),Object(u.c)(t.gl,1,e.count)});break;case 2:case 1:this.enable(2===t?this.shaderGetter2d:this.shaderGetter1d,e,t=>{Object(h.d)(t,e.renderContext.projectionParameters,1),Object(h.c)(t.gl,1,e.count)})}}}Object(o.c)(i.e.POINT,{sliceViewRenderHelper:T,perspectiveViewRenderHelper:T,defineShaderNoOpSetters(e){e.addVertexCode("\nvoid setPointMarkerSize(float size) {}\nvoid setPointMarkerBorderWidth(float size) {}\nvoid setPointMarkerColor(vec4 color) {}\nvoid setPointMarkerBorderColor(vec4 color) {}\n")},pickIdsPerInstance:1,snapPosition(e,t,n){e.set(new Float32Array(t,n,e.length))},getRepresentativePoint(e,t){e.set(t.point)},updateViaRepresentativePoint:(e,t)=>Object.assign(Object.assign({},e),{point:new Float32Array(t)})});
/**
 * @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 M="\nstruct EllipseQuadraticForm {\n  highp float A;  // x*x coefficient\n  highp float B;  // x*y coefficient\n  highp float C;  // y*y coefficient\n  highp float D;  // x coefficient\n  highp float E;  // y coefficient\n  highp float F;  // 1 coefficient\n};\n",D=[M,"\nEllipseQuadraticForm computeCrossSectionEllipse(mat3 A, vec3 c) {\n  EllipseQuadraticForm p;\n  p.A = A[0][0];\n  p.B = A[0][1] + A[1][0];\n  p.C = A[1][1];\n  p.D = -2.0 * c[0] * A[0][0] - c[1] * (A[0][1] + A[1][0]) +\n        c[2] * (A[0][2] + A[2][0]);\n  p.E = -c[0] * (A[0][1] + A[1][0]) - 2.0 * c[1] * A[1][1] +\n        c[2] * (A[1][2] + A[2][1]);\n  p.F = c[0] * c[0] * A[0][0] + c[0] * c[1] * (A[0][1] + A[1][0]) -\n        c[0] * c[2] * (A[0][2] + A[2][0]) + c[1] * c[1] * A[1][1] -\n        c[1] * c[2] * (A[1][2] + A[2][1]) + c[2] * c[2] * A[2][2] - 1.0;\n  return p;\n}\n"];const L=[M,"\nstruct CenterOrientEllipse {\n  vec2 k;   // center\n  vec2 u1;  // minor axis direction\n  vec2 u2;  // major axis direction\n  float a;  // semimajor axis\n  float b;  // semiminor axis\n  bool valid; // indicates if the ellipse is valid\n};\n","\nCenterOrientEllipse computeCenterOrientEllipse(EllipseQuadraticForm p) {\n  CenterOrientEllipse r;\n  float a11 = p.A;\n  float a12 = p.B / 2.0;\n  float a22 = p.C;\n  float b1 = p.D;\n  float b2 = p.E;\n  float c = p.F;\n  float kdenom = 2.0 * (a12 * a12 - a11 * a22);\n  float k1 = r.k.x = (a22 * b1 - a12 * b2) / kdenom;\n  float k2 = r.k.y = (a11 * b2 - a12 * b1) / kdenom;\n  float mu = 1.0 / (a11 * k1 * k1 + 2.0 * a12 * k1 * k2 + a22 * k2 * k2 - c);\n  float m11 = mu * a11;\n  float m12 = mu * a12;\n  float m22 = mu * a22;\n  float lambdaTerm1 = m11 + m22;\n  float lambdaTerm2 = sqrt((m11 - m22) * (m11 - m22) + 4.0 * m12 * m12);\n  float lambda1 = ((lambdaTerm1 + lambdaTerm2) / 2.0);\n  float lambda2 = ((lambdaTerm1 - lambdaTerm2) / 2.0);\n  r.a = 1.0 / sqrt(lambda1);\n  r.b = 1.0 / sqrt(lambda2);\n  r.valid = lambda1 > 0.0 && lambda2 > 0.0;\n  if (abs(m11 - m22) < 1e-6 && abs(m12) < 1e-6) {\n    r.u1 = vec2(1.0, 0.0);\n  } else if (m11 >= m22) {\n    r.u1 = normalize(vec2(lambda1 - m22, m12));\n  } else {\n    r.u1 = normalize(vec2(m12, lambda1 - m11));\n  }\n  r.u2 = vec2(-r.u1.y, r.u1.x);\n  return r;\n}\n"];var j=n(76),I=n(2);
/**
 * @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 P(e,t){const n=new Float32Array((e+1)*(t+1)*3);let i=0;for(let r=0;r<=e;++r){const s=r*Math.PI/e,o=Math.sin(s),a=Math.cos(s);for(let e=0;e<=t;++e){const r=2*e*Math.PI/t,s=Math.sin(r),c=Math.cos(r);n[i++]=c*o,n[i++]=a,n[i++]=s*o}}return n}function A(e,t){const n=new Uint16Array(e*t*6);let i=0;for(let r=0;r<e;r++)for(let e=0;e<t;e++){const s=r*(t+1)+e,o=s+t+1;n[i++]=s,n[i++]=o,n[i++]=s+1,n[i++]=o,n[i++]=o+1,n[i++]=s+1}return n}class R extends I.a{constructor(e,t,n){super(),this.vertexBuffer=this.registerDisposer(Object(d.b)(e,WebGL2RenderingContext.ARRAY_BUFFER,P,t,n)).value,this.indexBuffer=this.registerDisposer(Object(d.b)(e,WebGL2RenderingContext.ELEMENT_ARRAY_BUFFER,A,t,n)).value,this.numIndices=t*n*6}defineShader(e){e.addAttribute("highp vec3","aSphereVertex"),e.addVarying("highp float","vLightingFactor"),e.addVertexCode("\nvoid emitSphere(mat4 projectionMatrix, mat4 normalTransformMatrix, vec3 centerPosition, vec3 radii, vec4 lightDirection) {\n  vec3 vertexPosition = aSphereVertex * radii + centerPosition;\n  gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);\n  vec3 normal = normalize((normalTransformMatrix * vec4(aSphereVertex / max(radii, 1e-6), 0.0)).xyz);\n  vLightingFactor = abs(dot(normal, uLightDirection.xyz)) + uLightDirection.w;\n}\n")}draw(e,t){const n=e.attribute("aSphereVertex");this.vertexBuffer.bindToVertexAttrib(n,3,WebGL2RenderingContext.FLOAT,!1),this.indexBuffer.bind(),e.gl.drawElementsInstanced(WebGL2RenderingContext.TRIANGLES,this.numIndices,WebGL2RenderingContext.UNSIGNED_SHORT,0,t),e.gl.disableVertexAttribArray(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.
 */const N=C.m.create();class V extends o.a{defineShader(e){const{rank:t}=this;Object(p.a)(e,"float",WebGL2RenderingContext.FLOAT,!1,"CenterAndRadii",t,2),e.addVertexCode(`\nstruct SubspaceParams {\n  highp vec3 subspaceCenter;\n  highp vec3 subspaceRadii;\n  highp float clipCoefficient;\n  bool cull;\n};\nSubspaceParams getSubspaceParams() {\n  SubspaceParams params;\n  highp float modelCenter[${t}] = getCenterAndRadii0();\n  highp float modelRadii[${t}] = getCenterAndRadii1();\n  float radiusAdjustment = 1.0;\n  float clipCoefficient = 1.0;\n  for (int i = 0; i < ${t}; ++i) {\n    float r = modelRadii[i];\n    float c = modelCenter[i];\n    float x = uModelClipBounds[i];\n    float clipRadius = uModelClipBounds[i + ${t}];\n    if (r != 0.0 && clipRadius != 0.0) {\n      float d = c - x;\n      d = d * d;\n      radiusAdjustment -= d / (r * r);\n    }\n    float e = abs(x - clamp(x, c - r, c + r)) * clipRadius;\n    clipCoefficient *= max(0.0, 1.0 - e);\n  }\n  radiusAdjustment = sqrt(max(0.0, radiusAdjustment));\n  params.subspaceCenter = projectModelVectorToSubspace(modelCenter);\n  params.subspaceRadii = projectModelVectorToSubspace(modelRadii) * radiusAdjustment;\n  params.clipCoefficient = clipCoefficient;\n  params.cull = clipCoefficient == 0.0 || radiusAdjustment == 0.0;\n  return params;\n}\nvoid setEllipsoidFillColor(vec4 color) {\n  vColor = color;\n}\n`)}enable(e,t,n){super.enable(e,t,e=>{const i=e.vertexShaderInputBinders.CenterAndRadii;i.enable(1),this.gl.bindBuffer(WebGL2RenderingContext.ARRAY_BUFFER,t.buffer.buffer),i.bind(this.serializedBytesPerAnnotation,t.bufferOffset),n(e),i.disable()})}}Object(o.c)(i.e.ELLIPSOID,{sliceViewRenderHelper:class extends V{constructor(){super(...arguments),this.shaderGetter=this.getDependentShader("annotation/ellipsoid/crossSection",e=>{Object(f.b)(e),this.defineShader(e),e.addUniform("highp mat4","uViewportToObject"),e.addUniform("highp mat4","uObjectToViewport"),e.addUniform("highp mat4","uViewportToDevice"),e.addAttribute("highp vec2","aCornerOffset"),e.addVarying("highp vec2","vCircleCoord"),e.addVarying("highp float","vClipCoefficient"),e.addVertexCode(D),e.addVertexCode(L),e.addVertexCode(j.c),e.setVertexMain(`\nSubspaceParams params = getSubspaceParams();\nif (params.cull) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nvClipCoefficient = params.clipCoefficient;\nmat3 Aobject = mat3(0.0);\nfor (int i = 0; i < 3; ++i) {\n  float r = max(params.subspaceRadii[i], 1e-3);\n  Aobject[i][i] = 1.0 / (r * r);\n}\nmat3 RviewportToObject = mat3(uViewportToObject);\nmat3 Aviewport = transpose(RviewportToObject) * Aobject * RviewportToObject;\nvec3 cViewport = (uObjectToViewport * vec4(params.subspaceCenter, 1.0)).xyz;\nEllipseQuadraticForm quadraticForm = computeCrossSectionEllipse(Aviewport, cViewport);\nvec2 u1, u2;\nfloat a, b;\nCenterOrientEllipse centerOrient = computeCenterOrientEllipse(quadraticForm);\nvec2 cornerOffset = getQuadVertexPosition(vec2(-1.0, -1.0), vec2(1.0, 1.0));\nvec2 viewportCorner = centerOrient.k +\n  centerOrient.u1 * cornerOffset.x * centerOrient.a +\n  centerOrient.u2 * cornerOffset.y * centerOrient.b;\nif (centerOrient.valid) {\n  gl_Position = uViewportToDevice * vec4(viewportCorner, 0.0, 1.0);\n} else {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n}\nvCircleCoord = cornerOffset;\n${this.invokeUserMain}\n${this.setPartIndex(e)};\n`),e.setFragmentMain("\nif (dot(vCircleCoord, vCircleCoord) > 1.0) {\n  discard;\n}\nemitAnnotation(vec4(vColor.rgb, vColor.a * vClipCoefficient));\n")}),this.vertexIdHelper=this.registerDisposer(f.a.get(this.gl))}draw(e){this.enable(this.shaderGetter,e,t=>{const{gl:n}=t,i=e.renderContext.sliceView.projectionParameters.value,r=C.m.multiply(N,e.renderSubspaceInvModelMatrix,i.invViewMatrix);n.uniformMatrix4fv(t.uniform("uViewportToObject"),!1,r),n.uniformMatrix4fv(t.uniform("uViewportToDevice"),!1,i.projectionMat);const s=N;C.m.invert(s,r),n.uniformMatrix4fv(t.uniform("uObjectToViewport"),!1,s);const{vertexIdHelper:o}=this;o.enable(),Object(j.b)(n,1,e.count),o.disable()})}},perspectiveViewRenderHelper:class extends V{constructor(){super(...arguments),this.sphereRenderHelper=this.registerDisposer(new R(this.gl,10,10)),this.shaderGetter=this.getDependentShader("annotation/ellipsoid/projection",e=>{this.defineShader(e),this.sphereRenderHelper.defineShader(e),e.addUniform("highp vec4","uLightDirection"),e.addUniform("highp mat4","uNormalTransform"),e.addVarying("highp float","vClipCoefficient"),e.setVertexMain(`\nSubspaceParams params = getSubspaceParams();\nif (params.cull) {\n  gl_Position = vec4(2.0, 0.0, 0.0, 1.0);\n  return;\n}\nvClipCoefficient = params.clipCoefficient;\n${this.invokeUserMain}\nemitSphere(uModelViewProjection, uNormalTransform, params.subspaceCenter, params.subspaceRadii, uLightDirection);\n${this.setPartIndex(e)};\n`),e.setFragmentMain("\nemitAnnotation(vec4(vColor.rgb * vLightingFactor, vColor.a * vClipCoefficient));\n")}),this.tempLightVec=new Float32Array(4)}draw(e){this.enable(this.shaderGetter,e,t=>{const{gl:n}=t;let i=this.tempLightVec,{lightDirection:r,ambientLighting:s,directionalLighting:o}=e.renderContext;C.u.scale(i,r,o),i[3]=s,n.uniform4fv(t.uniform("uLightDirection"),i),n.uniformMatrix4fv(t.uniform("uNormalTransform"),!1,C.m.transpose(C.m.create(),e.renderSubspaceInvModelMatrix)),this.sphereRenderHelper.draw(t,e.count)})}},defineShaderNoOpSetters(e){e.addVertexCode("\nvoid setEllipsoidFillColor(vec4 color) {}\n")},pickIdsPerInstance:1,snapPosition:()=>{},getRepresentativePoint(e,t){e.set(t.center)},updateViaRepresentativePoint:(e,t)=>Object.assign(Object.assign({},e),{center:new Float32Array(t)})});var _=n(70),B=n(10),F=n(12),z=n(71),U=n(38),G=n(52),$=n(58),W=n(56),H=n(72);
/**
 * @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 J=C.m.create(),q=C.u.create();function Y(e){e.addUniform("highp vec3","uTranslation"),e.addUniform("highp mat4","uProjectionMatrix"),e.addUniform("highp vec3","uChunkDataSize"),e.addUniform("highp vec3","uLowerClipBound"),e.addUniform("highp vec3","uUpperClipBound"),e.setFragmentMain("\nemit(vec4(1.0, 1.0, 1.0, getLineAlpha()), 0u);\n")}const X={defineShader(e){Y(e),Object(h.b)(e),e.addVertexCode("\nconst vec3[24] boxCornerOffsets = vec3[](\n  vec3(0, 0, 0), vec3(0, 0, 1),  // e1\n  vec3(1, 0, 0), vec3(1, 0, 1),  // e2\n  vec3(0, 1, 0), vec3(0, 1, 1),  // e3\n  vec3(1, 1, 0), vec3(1, 1, 1),  // e4\n  vec3(0, 0, 0), vec3(0, 1, 0),  // e5\n  vec3(0, 0, 1), vec3(0, 1, 1),  // e6\n  vec3(1, 0, 0), vec3(1, 1, 0),  // e7\n  vec3(1, 0, 1), vec3(1, 1, 1),  // e8\n  vec3(0, 0, 0), vec3(1, 0, 0),  // e9\n  vec3(0, 0, 1), vec3(1, 0, 1),  // e10\n  vec3(0, 1, 0), vec3(1, 1, 0),  // e11\n  vec3(0, 1, 1), vec3(1, 1, 1)  // e12\n);\n"),e.setVertexMain(`\nint edgeIndex = gl_VertexID / ${h.a};\nvec3 cornerA = max(uLowerClipBound, min(uUpperClipBound, uTranslation));\nvec3 cornerB = max(uLowerClipBound, min(uUpperClipBound, uTranslation + uChunkDataSize));\nvec3 vertexPosition1 = mix(cornerA, cornerB, boxCornerOffsets[edgeIndex * 2]);\nvec3 vertexPosition2 = mix(cornerA, cornerB, boxCornerOffsets[edgeIndex * 2 + 1]);\nemitLine(uProjectionMatrix * vec4(vertexPosition1, 1.0),\n         uProjectionMatrix * vec4(vertexPosition2, 1.0),\n         2.0);\n`)},initialize(e,t){Object(h.d)(e,t,1)},draw(e,t,n){const{gl:i}=e,r=J,{chunkLayout:s}=t;C.m.multiply(r,n.viewProjectionMat,s.transform),i.uniformMatrix4fv(e.uniform("uProjectionMatrix"),!1,r),i.uniform3fv(e.uniform("uChunkDataSize"),s.size),i.uniform3fv(e.uniform("uLowerClipBound"),t.lowerClipDisplayBound),i.uniform3fv(e.uniform("uUpperClipBound"),t.upperClipDisplayBound);const o=s.size,{curPositionInChunks:a,chunkDisplayDimensionIndices:c}=t,d=q;for(let e=0;e<3;++e){const t=c[e];d[e]=(-1===t?0:a[t])*o[e]}i.uniform3fv(e.uniform("uTranslation"),d),Object(h.c)(i,l.b,1)}},K={defineShader(e){Object(a.b)(e),Y(e),Object(h.b)(e),e.setVertexMain(`\nint vertexIndex1 = gl_VertexID / ${h.a};\nint vertexIndex2 = vertexIndex1 == 5 ? 0 : vertexIndex1 + 1;\nvec3 vertexPosition1 = getBoundingBoxPlaneIntersectionVertexPosition(uChunkDataSize, uTranslation, uLowerClipBound, uUpperClipBound, vertexIndex1);\nvec3 vertexPosition2 = getBoundingBoxPlaneIntersectionVertexPosition(uChunkDataSize, uTranslation, uLowerClipBound, uUpperClipBound, vertexIndex2);\nemitLine(uProjectionMatrix * vec4(vertexPosition1, 1.0),\n         uProjectionMatrix * vec4(vertexPosition2, 1.0),\n         2.0);\n`)},initialize(e,t){Object(h.d)(e,t,1)},draw(e,t,n){const{gl:i}=e,r=J,{chunkLayout:s}=t;C.m.multiply(r,n.viewProjectionMat,s.transform),i.uniformMatrix4fv(e.uniform("uProjectionMatrix"),!1,r),i.uniform3fv(e.uniform("uChunkDataSize"),s.size),i.uniform3fv(e.uniform("uLowerClipBound"),t.lowerClipDisplayBound),i.uniform3fv(e.uniform("uUpperClipBound"),t.upperClipDisplayBound);const o=s.size,{curPositionInChunks:c,chunkDisplayDimensionIndices:l}=t,d=q;for(let e=0;e<3;++e){const t=l[e];d[e]=(-1===t?0:c[t])*o[e]}i.uniform3fv(e.uniform("uTranslation"),d),Object(a.c)(e,n.viewportNormalInGlobalCoordinates,n.centerDataPosition,s.transform,s.invTransform),Object(h.c)(i,6,1)}};var Q=n(4),Z=n(57),ee=n(3),te=n(31),ne=n(32),ie=n(16),re=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};const se=C.m.create();let oe=class extends(Object(te.c)(F.e)){constructor(e,t,n,i){super(i),this.chunkManager=e,this.source=t,this.segmentationStates=n,this.initializeCounterpart(this.chunkManager.rpc,{chunkManager:this.chunkManager.rpcId,source:t.rpcId,segmentationStates:this.serializeDisplayState()});this.registerDisposer(n.changed.add(()=>{const e={id:this.rpcId,segmentationStates:this.serializeDisplayState()};this.rpc.invoke(_.i,e)}))}serializeDisplayState(){const{value:e}=this.segmentationStates;if(void 0!==e)return e.map(e=>null==e?e:{segmentEquivalences:e.segmentEquivalences.rpcId,visibleSegments:e.visibleSegments.rpcId})}};oe=re([Object(ie.g)(_.h)],oe);class ae extends I.a{constructor(e,t){super(),this.chunkManager=e,this.state=t,this.layerChunkProgressInfo=new B.i,this.numPickIds=0,this.generation=-1,this.redrawNeeded=new ee.a,this.serializedAnnotations=void 0,this.handleChangeAffectingBuffer=()=>{this.generation=-1,this.redrawNeeded.dispatch()},this.segmentationStates=this.registerDisposer(Object(Q.g)(e=>{const{displayState:t,source:n}=this.state,{relationshipStates:i}=t;return t.displayUnfiltered.value?void 0:n.relationships.map(e=>{const t=i.get(e);return t.showMatches.value?t.segmentationState.value:void 0})},[this.state.displayState.relationshipStates],(e,t)=>void 0===e||void 0===t?e===t:Object(c.a)(e,t))),this.registerDisposer(t),this.registerDisposer(this.source.changed.add(this.handleChangeAffectingBuffer)),this.registerDisposer(Object(Q.k)((e,t)=>{if(this.handleChangeAffectingBuffer(),void 0!==t)for(const n of t)null!=n&&(e.registerDisposer(n.visibleSegments.changed.add(()=>this.handleChangeAffectingBuffer())),e.registerDisposer(n.segmentEquivalences.changed.add(()=>this.handleChangeAffectingBuffer())))},this.segmentationStates)),this.source instanceof i.d||(this.sharedObject=this.registerDisposer(new oe(e,this.source,this.segmentationStates,this.layerChunkProgressInfo)));const{displayState:n}=this.state;this.registerDisposer(n.color.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(n.shader.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(n.shaderControls.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.hoverState.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.transform.changed.add(this.redrawNeeded.dispatch))}get source(){return this.state.source}get transform(){return this.state.transform}get hoverState(){return this.state.displayState.hoverState}get visibility(){const{sharedObject:e}=this;if(void 0!==e)return e.visibility}get gl(){return this.chunkManager.gl}updateBuffer(){const{source:e}=this;if(e instanceof i.d){const t=e.changed.count;if(this.generation!==t){let{buffer:n}=this;void 0===n&&(n=this.buffer=this.registerDisposer(new d.a(this.chunkManager.gl))),this.generation=t;const r=this.serializedAnnotations=function(e,t){const n=new i.c(e.annotationPropertySerializer);for(const i of e)(void 0===t||t(i))&&n.add(i);return n.serialize()}(e,function(e){if(void 0!==e)return t=>{const{relatedSegments:n}=t;if(void 0===n)return!1;for(let t=0,i=n.length;t<i;++t){const i=e[t];if(null==i)continue;const{visibleSegments:r,segmentEquivalences:s}=i;for(const e of n[t])if(r.has(s.get(e)))return!0}return!1}}(this.segmentationStates.value));n.setData(this.serializedAnnotations.data),this.numPickIds=Object(s.c)(r)}}}}function ce(e){const{chunkTransform:t}=e,{unpaddedRank:n}=t.modelTransform,i=new Float32Array(2*n),r=new Float32Array(3*n);r.fill(0),i.fill(1,n);const{numChunkDisplayDims:s,chunkDisplayDimensionIndices:o}=e;for(let e=0;e<s;++e){const t=o[e];i[n+t]=0,r[3*t+e]=1}return{modelClipBounds:i,renderSubspaceTransform:r}}function le(e,t,n){n.clearMessages();const i=e=>{n.addMessage({severity:Z.b.error,message:e})};if(void 0!==e.error)return i(e.error);const r=Object(U.g)(e.modelTransform,t.displayDimensionIndices);let s;try{s=Object(U.d)(e,r)}catch(e){return i(e.message)}const{modelClipBounds:o,renderSubspaceTransform:a}=ce(s);return{chunkTransform:e,chunkDisplayTransform:s,modelClipBounds:o,renderSubspaceTransform:a}}function de(e,t){return class extends e{constructor(e,t){super(),this.base=e,this.renderScaleHistogram=t,this.curRank=-1,this.renderHelpers=[],this.isAnnotation=!0;const n=e.visibility;void 0!==n&&this.registerDisposer(n.add(this.visibility)),this.registerDisposer(this.renderScaleHistogram.visibility.add(this.visibility)),this.registerDisposer(()=>{for(const e of this.renderHelpers)e.dispose()}),this.role=e.state.role,this.registerDisposer(e.redrawNeeded.add(this.redrawNeeded.dispatch)),this.handleRankChanged()}handleRankChanged(){const{rank:e}=this.base.source;if(e===this.curRank)return;this.curRank=e,this.tempChunkPosition=new Float32Array(e);const{renderHelpers:n,gl:r}=this;for(const e of n)e.dispose();const{properties:s}=this.base.source,{displayState:a}=this.base.state;for(const c of i.j){const i=Object(o.b)(c),l=i[t],d=n[c]=new l(r,c,e,s,a.shaderControls,a.fallbackShaderControls,a.shaderError);d.pickIdsPerInstance=i.pickIdsPerInstance,d.targetIsSliceView="sliceViewRenderHelper"===t}}attach(e){super.attach(e),this.handleRankChanged();const{chunkTransform:t}=this,n=e.view.displayDimensionRenderInfo.value;e.state={chunkTransform:t,displayDimensionRenderInfo:n,chunkRenderParameters:le(t,n,e.messages)}}updateAttachmentState(e){const t=e.state;this.handleRankChanged();const{chunkTransform:n}=this,i=e.view.displayDimensionRenderInfo.value;return void 0!==t&&t.chunkTransform===n&&t.displayDimensionRenderInfo===i?t.chunkRenderParameters:(t.chunkTransform=n,t.displayDimensionRenderInfo=i,t.chunkRenderParameters=le(n,i,e.messages))}get chunkTransform(){return this.base.state.chunkTransform.value}updateModelClipBounds(e,t){const{modelClipBounds:n}=t,i=this.curRank,{chunkTransform:r}=t;Object(U.e)(n.subarray(0,i),e.projectionParameters.globalPosition,this.base.state.localPosition.value,r.layerRank,r.combinedGlobalLocalToChunkTransform)}get gl(){return this.base.chunkManager.gl}drawGeometryChunkData(e,t,n,i=1){if(!e.bufferValid){let{buffer:t}=e;void 0===t&&(t=e.buffer=new d.a(this.gl));const{serializedAnnotations:n}=e;t.setData(n.data),e.numPickIds=Object(s.c)(n),e.bufferValid=!0}this.drawGeometry(e,t,n,i)}drawGeometry(e,t,n,r=1){const{base:s}=this,{chunkDisplayTransform:a}=n,{serializedAnnotations:c}=e,{typeToIdMaps:l,typeToOffset:d}=c;let u=0;t.emitPickID&&(u=t.pickIDs.register(this,e.numPickIds,0,0,e));const h=s.hoverState.value,p=C.m.multiply(se,t.projectionParameters.viewProjectionMat,a.displaySubspaceModelMatrix),f={annotationLayer:s,renderContext:t,selectedIndex:0,basePickId:u,buffer:e.buffer,bufferOffset:0,count:0,modelViewProjectionMatrix:p,modelClipBounds:n.modelClipBounds,subspaceMatrix:n.renderSubspaceTransform,renderSubspaceModelMatrix:a.displaySubspaceModelMatrix,renderSubspaceInvModelMatrix:a.displaySubspaceInvModelMatrix,chunkDisplayTransform:a};for(const e of i.j){const t=l[e];let n=t.size;if(n>0){const i=Object(o.b)(e);let s=4294967295;if(void 0!==h){const e=t.get(h.id);void 0!==e&&(s=e*i.pickIdsPerInstance)}n=Math.round(n*r),f.count=n,f.bufferOffset=d[e],f.selectedIndex=s,this.renderHelpers[e].draw(f),f.basePickId+=n*i.pickIdsPerInstance}}}updateMouseState(e,t,n,r){const s=r,{serializedAnnotations:a}=s,{typeToIds:c,typeToOffset:l}=a,d=this.curRank,u=this.chunkTransform;if(void 0===u.error)for(const t of i.j){const r=c[t],s=Object(o.b)(t),h=i.i[t],{pickIdsPerInstance:p}=s;if(n<r.length*p){const i=Math.floor(n/p),o=r[i],c=n%p;e.pickedAnnotationId=o,e.pickedAnnotationLayer=this.base.state,e.pickedOffset=c,e.pickedAnnotationBuffer=a.data.buffer,e.pickedAnnotationBufferOffset=a.data.byteOffset+l[t]+i*(h.serializedBytes(d)+this.base.source.annotationPropertySerializer.serializedBytes);const f=this.tempChunkPosition,{chunkToLayerTransform:m,combinedGlobalLocalToChunkTransform:g,layerRank:v}=u,{globalToRenderLayerDimensions:b}=u.modelTransform,{position:y}=e;if(!Object(U.e)(f,y,this.base.state.localPosition.value,v,g))return;s.snapPosition(f,e.pickedAnnotationBuffer,e.pickedAnnotationBufferOffset,c);const S=b.length;for(let e=0;e<S;++e){const t=b[e];if(-1===t)continue;let n=m[(d+1)*d+t];for(let e=0;e<d;++e)n+=f[e]*m[e*(v+1)+t];Number.isFinite(n)&&(y[e]=n)}return}n-=r.length*p}}transformPickedValue(e,t){}isReady(){const{base:e}=this,{source:t}=e;if(!(t instanceof s.b))return!0;const{value:n}=this.base.segmentationStates;if(void 0===n)return!0;for(let e=0,i=n.length;e<i;++e){const i=n[e];if(null===i)return!1;if(void 0===i)continue;const r=t.segmentFilteredSources[e].chunks;let s=!1;if(Object(G.a)(i,e=>{const t=Object(G.b)(e);r.has(t)||(s=!0)}),s)return!1}return!0}}}const ue=e=>class extends e{constructor(){super(...arguments),this.layerChunkProgressInfo=this.base.layerChunkProgressInfo}draw(e,t){const n=this.updateAttachmentState(t);if(0===this.curRank||void 0===n)return;this.updateModelClipBounds(e,n);const{source:r}=this.base;if(r instanceof i.d){const{base:t}=this;t.updateBuffer(),this.drawGeometry(t,e,n)}else{const{renderScaleHistogram:t}=this;t.begin(this.base.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber),this.drawGeometryChunkData(r.temporary.data,e,n);const{value:i}=this.base.segmentationStates;let s=0,o=0;if(void 0!==i)for(let t=0,a=i.length;t<a;++t){const a=i[t];if(null==a)continue;const c=r.segmentFilteredSources[t].chunks;Object(G.a)(a,t=>{const i=Object(G.b)(t),r=c.get(i);if(void 0!==r&&r.state===B.h.GPU_MEMORY){const{data:t}=r;if(void 0===t)return;this.drawGeometryChunkData(t,e,n),++s}else++o})}t.add(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,s,o)}}},he=de(z.a,"perspectiveViewRenderHelper");class pe extends(ue(he)){}const fe=e=>class extends e{constructor(e){super(e.annotationLayer,e.renderScaleHistogram),this.wireFrameRenderHelper=this instanceof H.a?K:X,this.wireFrameShaderGetter=Object(ne.d)(this,this.gl,{memoizeKey:`annotation/wireFrameShader:${this instanceof H.a}`,parameters:Object(Q.f)(void 0),defineShader:e=>{this.wireFrameRenderHelper.defineShader(e)}}),this.renderScaleTarget=e.renderScaleTarget,this.registerDisposer(this.renderScaleTarget.changed.add(this.redrawNeeded.dispatch));const t=this.registerDisposer(new F.e(this.layerChunkProgressInfo)),n=this.base.chunkManager.rpc;t.RPC_TYPE_ID=_.j,t.initializeCounterpart(n,{chunkManager:this.base.chunkManager.rpcId,localPosition:this.registerDisposer($.a.makeFromExisting(n,this.base.state.localPosition)).rpcId,renderScaleTarget:this.registerDisposer($.a.makeFromExisting(n,this.renderScaleTarget)).rpcId}),this.backend=t}attach(e){super.attach(e),e.state.sources=e.registerDisposer(Object(Q.k)((t,n,i)=>{const r=Object(W.f)(i,n,e=>this.base.state.source.getSources(e),e.messages,this);for(const e of r)for(const n of e)t.registerDisposer(n.source),Object.assign(n,ce(n.chunkDisplayTransform));return e.view.flushBackendProjectionParameters(),this.backend.rpc.invoke(_.e,{layer:this.backend.rpcId,view:e.view.rpcId,sources:Object(W.g)(r)}),this.redrawNeeded.dispatch(),r},this.base.state.transform,e.view.displayDimensionRenderInfo))}draw(e,t){const n=this.updateAttachmentState(t);if(0===this.curRank||void 0===n)return;const i=t.state.sources.value;if(0===i.length)return;this.updateModelClipBounds(e,n);const{renderScaleHistogram:r}=this;r.begin(this.base.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber);const{projectionParameters:s}=e;let o;if(e.wireFrame){const{shader:t}=this.wireFrameShaderGetter(e.emitter);if(null===t)return;t.bind(),this.wireFrameRenderHelper.initialize(t,s),o=t}Object(_.l)(s,this.base.state.localPosition.value,this.renderScaleTarget.value,i[0],()=>{},(t,i,a,c,l)=>{const d=t.source.chunks.get(t.curPositionInChunks.join());let u;if(void 0===d||d.state!==B.h.GPU_MEMORY)u=0;else{const{data:i}=d;if(void 0===i)return;void 0!==o?this.wireFrameRenderHelper.draw(o,t,s):this.drawGeometryChunkData(i,e,n,a),u=1}r.add(c,l,u,1-u)})}},me=fe(he),ge=fe(de(H.a,"sliceViewRenderHelper")),ve=ue(de(H.a,"sliceViewRenderHelper"));var be=n(28),ye=n(36),Se=n(81),we=n(44),xe=n(17),Ce=n(113),Oe=n(103),ke=n(66),Ee=n(6),Te=n(0),Me=n(11),De=n(19),Le=n(51),je=n(40);n(87);var Ie=n(18),Pe=n(37),Ae=n(134),Re=n(137),Ne=n(62),Ve=n(104),_e=n(63),Be=n(129),Fe=n(27),ze=n(138),Ue=n(48);n.d(t,"a",(function(){return ot}));
/**
 * @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 Ge extends I.a{constructor(){super(...arguments),this.changed=new ee.a,this.isLoadingChanged=new ee.a,this.states=[],this.relationships=[],this.loadingCount=0}get value(){return this.states}get isLoading(){return 0!==this.loadingCount}markLoading(){return this.loadingCount++,()=>{0==--this.loadingCount&&this.isLoadingChanged.dispatch()}}sort(){this.states.sort((e,t)=>{let n=e.sourceIndex-t.sourceIndex;return 0!==n?n:e.subsourceIndex-t.subsourceIndex})}updateRelationships(){const e=new Set;for(const t of this.states)for(const n of t.source.relationships)e.add(n);this.relationships=Array.from(e)}add(e){return this.states.push(e),this.sort(),this.updateRelationships(),this.changed.dispatch(),()=>{const t=this.states.indexOf(e);this.states.splice(t,1),this.updateRelationships(),this.changed.dispatch()}}}class $e extends I.a{constructor(e){super(),this.annotationStates=e,this.value_=void 0,this.changed=new ee.a,this.annotationLayer_=void 0,this.reference_=void 0,this.referenceChanged=()=>{this.validate(),this.changed.dispatch()},this.validate=()=>{const e=this.value_;if(void 0===e)return;const{annotationLayer_:t}=this,{annotationStates:n}=this;if(void 0!==t){if(!n.states.includes(t))return this.unbindReference(),void(n.isLoading||(this.value_=void 0,this.changed.dispatch()));const i=this.reference_;let r=!1;i.id!==e.id&&(e.id=i.id,r=!0);const{dataSource:s}=t;return s.layer.dataSources[e.sourceIndex]!==s&&(e.sourceIndex=t.sourceIndex,r=!0),void(r&&this.changed.dispatch())}const i=n.states.find(t=>t.sourceIndex===e.sourceIndex&&(void 0===e.subsource||t.subsourceId===e.subsource));void 0!==i?(this.annotationLayer_=i,(this.reference_=i.source.getReference(e.id)).changed.add(this.referenceChanged),i.source.changed.add(this.validate),i.dataSource.layer.dataSourcesChanged.add(this.validate),this.changed.dispatch()):n.isLoading||(this.value_=void 0,this.changed.dispatch())},this.registerDisposer(e.isLoadingChanged.add(this.validate))}get reference(){return this.reference_}get selectedAnnotationLayer(){return this.annotationLayer_}get value(){return this.validate(),this.value_}get validValue(){return this.validate(),this.annotationLayer_&&this.value_}set value(e){if(this.value_===e)return;if(this.value_=e,void 0===e)return this.unbindReference(),void this.changed.dispatch();const t=this.reference_;if(void 0!==t){const n=this.annotationLayer_;(void 0===e||t.id!==e.id||n.sourceIndex!==e.sourceIndex||void 0!==n.subsourceId&&n.subsourceId!==e.subsource)&&this.unbindReference()}this.validate(),this.changed.dispatch()}disposed(){this.unbindReference(),super.disposed()}unbindReference(){const e=this.reference_;if(void 0!==e){e.changed.remove(this.referenceChanged);const t=this.annotationLayer_;t.source.changed.remove(this.validate),t.dataSource.layer.dataSourcesChanged.remove(this.validate),this.reference_=void 0,this.annotationLayer_=void 0}}toJSON(){const e=this.value_;if(void 0===e)return;let t=e.partIndex;0===t&&(t=void 0);let n=e.sourceIndex;return 0===n&&(n=void 0),{id:e.id,partIndex:t,source:n,subsource:e.subsource}}reset(){this.value=void 0}restoreState(e){void 0!==e?"string"!=typeof e?(Object(Te.w)(e),this.value={id:Object(Te.y)(e,"id",Te.E),partIndex:Object(Te.B)(e,"partIndex",Te.u),sourceIndex:Object(Te.B)(e,"source",Te.u,0),subsource:Object(Te.B)(e,"subsource",Te.E)}):this.value={id:e,partIndex:0,sourceIndex:0}:this.value=void 0}}function We(e,t,n){if(void 0!==t.error)return;const{globalPosition:i}=e.manager.root,{localPosition:r}=e,{modelTransform:s}=t;Object(c.f)(i.value,n,s.globalToRenderLayerDimensions),Object(c.f)(r.value,n,s.localToRenderLayerDimensions),r.changed.dispatch(),i.changed.dispatch()}function He(e,t,n){const{layerRank:r}=t,s=new Float32Array(r);i.i[e.type].visitGeometry(e,(e,i)=>{s.set(e);const o=new Float32Array(r);(i?De.k:De.j)(o,t.chunkToLayerTransform,r+1,s,r),n(o,i)})}class Je extends Ue.b{constructor(e,t,n){super(),this.layer=e,this.state=t,this.displayState=n,this.previousSelectedId=void 0,this.previousSelectedAnnotationLayerState=void 0,this.previousHoverId=void 0,this.previousHoverAnnotationLayerState=void 0,this.listContainer=document.createElement("div"),this.updated=!1,this.mutableControls=document.createElement("div"),this.headerRow=document.createElement("div"),this.attachedAnnotationStates=new Map,this.forceUpdateView=()=>{this.updated=!1,this.updateView()},this.globalDimensionIndices=[],this.localDimensionIndices=[],this.curCoordinateSpaceGeneration=-1,this.prevCoordinateSpaceGeneration=-1,this.element.classList.add("neuroglancer-annotation-layer-view"),this.listContainer.classList.add("neuroglancer-annotation-list"),this.registerDisposer(t),this.registerDisposer(this.visibility.changed.add(()=>this.updateView())),this.registerDisposer(t.annotationStates.changed.add(()=>this.updateAttachedAnnotationLayerStates())),this.headerRow.classList.add("neuroglancer-annotation-list-header");const r=document.createElement("div");r.className="neuroglancer-annotation-toolbox",e.initializeAnnotationLayerViewTab(this);const s=this.registerDisposer(new Re.a(this.displayState.color));s.element.title="Change annotation display color",this.registerDisposer(new xe.a(Object(Q.h)(e=>null!==e.match(/\bdefaultColor\b/),n.shaderControls.processedFragmentMain),s.element)),r.appendChild(s.element);const{mutableControls:o}=this,a=Object(Fe.a)({text:i.i[i.e.POINT].icon,title:"Annotate point",onClick:()=>{this.layer.tool.value=new Ke(this.layer,{})}});o.appendChild(a);const c=Object(Fe.a)({text:i.i[i.e.AXIS_ALIGNED_BOUNDING_BOX].icon,title:"Annotate bounding box",onClick:()=>{this.layer.tool.value=new tt(this.layer,{})}});o.appendChild(c);const l=Object(Fe.a)({text:i.i[i.e.LINE].icon,title:"Annotate line",onClick:()=>{this.layer.tool.value=new nt(this.layer,{})}});o.appendChild(l);const d=Object(Fe.a)({text:i.i[i.e.ELLIPSOID].icon,title:"Annotate ellipsoid",onClick:()=>{this.layer.tool.value=new it(this.layer,{})}});o.appendChild(d),r.appendChild(o),this.element.appendChild(r),this.element.appendChild(this.listContainer),this.listContainer.addEventListener("mouseleave",()=>{this.displayState.hoverState.value=void 0}),this.registerDisposer(new Le.b(this.listContainer,Object(Ce.a)())),this.registerDisposer(this.displayState.hoverState.changed.add(()=>this.updateHoverView())),this.registerDisposer(this.state.changed.add(()=>this.updateSelectionView())),this.registerDisposer(this.layer.localCoordinateSpace.changed.add(()=>{this.updateCoordinateSpace(),this.updateView()})),this.registerDisposer(this.layer.manager.root.coordinateSpace.changed.add(()=>{this.updateCoordinateSpace(),this.updateView()})),this.updateCoordinateSpace(),this.updateAttachedAnnotationLayerStates()}get annotationStates(){return this.state.annotationStates}updateAttachedAnnotationLayerStates(){const e=this.annotationStates.states,{attachedAnnotationStates:t}=this,n=new Map;for(const[n,i]of t)e.includes(n)||(t.delete(n),i.listElements.clear(),i.refCounted.dispose());for(const r of e){const e=t.get(r);if(void 0!==e){n.set(r,e);continue}const s=r.source,o=new I.a;s instanceof i.d&&(o.registerDisposer(s.childAdded.add(e=>this.addAnnotationElement(e,r))),o.registerDisposer(s.childUpdated.add(e=>this.updateAnnotationElement(e,r))),o.registerDisposer(s.childDeleted.add(e=>this.deleteAnnotationElement(e,r)))),o.registerDisposer(r.transform.changed.add(this.forceUpdateView));const a=document.createElement("div");a.classList.add("neuroglancer-annotation-sublist"),n.set(r,{refCounted:o,listElements:new Map,sublistContainer:a})}this.attachedAnnotationStates=n,t.clear(),this.updateCoordinateSpace(),this.forceUpdateView()}updateCoordinateSpace(){const e=this.layer.localCoordinateSpace.value,t=this.layer.manager.root.coordinateSpace.value,n=[],i=[];for(let e=0,i=t.rank;e<i;++e)this.annotationStates.states.some(t=>{const n=t.transform.value;return void 0===n.error&&-1!==n.globalToRenderLayerDimensions[e]})&&n.push(e);for(let t=0,n=e.rank;t<n;++t)this.annotationStates.states.some(e=>{const n=e.transform.value;return void 0===n.error&&-1!==n.localToRenderLayerDimensions[t]})&&i.push(t);Object(c.a)(n,this.globalDimensionIndices)&&Object(c.a)(i,this.localDimensionIndices)||(this.localDimensionIndices=i,this.globalDimensionIndices=n,++this.curCoordinateSpaceGeneration)}clearSelectionClass(){const{previousSelectedAnnotationLayerState:e,previousSelectedId:t}=this;if(void 0!==e){this.previousSelectedAnnotationLayerState=void 0,this.previousSelectedId=void 0;const n=this.attachedAnnotationStates.get(e);if(void 0===n)return;const i=n.listElements.get(t);void 0!==i&&i.classList.remove("neuroglancer-annotation-selected")}}clearHoverClass(){const{previousHoverId:e,previousHoverAnnotationLayerState:t}=this;if(void 0!==t){this.previousHoverAnnotationLayerState=void 0,this.previousHoverId=void 0;const n=this.attachedAnnotationStates.get(t);if(void 0===n)return;const i=n.listElements.get(e);void 0!==i&&i.classList.remove("neuroglancer-annotation-hover")}}updateSelectionView(){const e=this.state.value;let t,n;void 0!==e&&(t=e.id,n=this.state.selectedAnnotationLayer);const{previousSelectedId:i,previousSelectedAnnotationLayerState:r}=this;if(t===i&&r===n)return;if(this.clearSelectionClass(),this.previousSelectedId=t,this.previousSelectedAnnotationLayerState=n,void 0===t)return;const s=this.attachedAnnotationStates.get(n);if(void 0===s)return;const o=s.listElements.get(t);void 0!==o&&(o.classList.add("neuroglancer-annotation-selected"),o.scrollIntoView())}updateHoverView(){const e=this.displayState.hoverState.value;let t,n;void 0!==e&&(t=e.id,n=e.annotationLayerState);const{previousHoverId:i,previousHoverAnnotationLayerState:r}=this;if(t===i&&n===r)return;if(this.clearHoverClass(),this.previousHoverId=t,this.previousHoverAnnotationLayerState=n,void 0===t)return;const s=this.attachedAnnotationStates.get(n);if(void 0===s)return;const o=s.listElements.get(t);void 0!==o&&o.classList.add("neuroglancer-annotation-hover")}updateView(){if(!this.visible)return;if(this.curCoordinateSpaceGeneration!==this.prevCoordinateSpaceGeneration){this.updated=!1;const{headerRow:e}=this,t=document.createElement("div");t.style.gridColumn="symbol";const n=document.createElement("div");n.style.gridColumn="delete",Object(Ee.b)(e),e.appendChild(t);let i=0;const r=(t,n)=>{const r=document.createElement("div");r.classList.add("neuroglancer-annotations-view-dimension");const s=document.createElement("span");s.classList.add("neuroglancer-annotations-view-dimension-name"),s.textContent=t.names[n];const o=document.createElement("scale");o.classList.add("neuroglancer-annotations-view-dimension-scale"),o.textContent=Object(je.b)(t.scales[n],t.units[n],{precision:2}),r.appendChild(s),r.appendChild(o),r.style.gridColumn=`dim ${i+1}`,++i,e.appendChild(r)},s=this.layer.manager.root.coordinateSpace.value;for(const e of this.globalDimensionIndices)r(s,e);const o=this.layer.localCoordinateSpace.value;for(const e of this.localDimensionIndices)r(o,e);e.appendChild(n),this.listContainer.style.gridTemplateColumns=`[symbol] min-content repeat(${i}, [dim] min-content) [delete] min-content`,this.prevCoordinateSpaceGeneration=this.curCoordinateSpaceGeneration}if(this.updated)return;let e=!1;const t=this;Object(Ee.d)(this.listContainer,function*(){yield t.headerRow;for(const[n,{sublistContainer:i,listElements:r}]of t.attachedAnnotationStates)if(n.source.readonly||(e=!0),Object(Ee.b)(i),r.clear(),void 0===n.chunkTransform.value.error){for(const e of n.source)i.appendChild(t.makeAnnotationListElement(e,n));yield i}}()),this.mutableControls.style.display=e?"contents":"none",this.resetOnUpdate()}addAnnotationElement(e,t){if(!this.visible)return void(this.updated=!1);if(!this.updated)return void this.updateView();const n=this.attachedAnnotationStates.get(t);void 0!==n&&n.sublistContainer.appendChild(this.makeAnnotationListElement(e,t)),this.resetOnUpdate()}updateAnnotationElement(e,t){if(!this.visible)return void(this.updated=!1);if(!this.updated)return void this.updateView();const n=this.attachedAnnotationStates.get(t);if(void 0!==n){const{listElements:i}=n,r=i.get(e.id);if(void 0!==r){const s=this.makeAnnotationListElement(e,t);n.sublistContainer.replaceChild(s,r),i.set(e.id,s)}}this.resetOnUpdate()}deleteAnnotationElement(e,t){if(!this.visible)return void(this.updated=!1);if(!this.updated)return void this.updateView();const n=this.attachedAnnotationStates.get(t);if(void 0!==n){let t=n.listElements.get(e);void 0!==t&&(Object(Ee.c)(t),n.listElements.delete(e))}this.resetOnUpdate()}resetOnUpdate(){this.clearHoverClass(),this.clearSelectionClass(),this.updated=!0,this.updateHoverView(),this.updateSelectionView()}makeAnnotationListElement(e,t){const n=t.chunkTransform.value,r=document.createElement("div");r.classList.add("neuroglancer-annotation-list-entry"),r.title="Click to select, right click to recenter view.";const s=document.createElement("div");let o;s.className="neuroglancer-annotation-icon",s.textContent=i.i[e.type].icon,s.classList.add("neuroglancer-annotation-list-entry-highlight"),r.appendChild(s);let a=0;if(He(e,n,(i,s)=>{++a;const c=document.createElement("div");c.className="neuroglancer-annotation-position",r.appendChild(c);let l=0;const d=(e,t)=>{for(const n of e){const e=t[n];if(-1!==e){const t=Math.floor(i[e]),n=document.createElement("div");n.textContent=t.toString(),n.classList.add("neuroglancer-annotation-coordinate"),n.classList.add("neuroglancer-annotation-list-entry-highlight"),n.style.gridColumn=`dim ${l+1}`,c.appendChild(n)}++l}};d(this.globalDimensionIndices,n.modelTransform.globalToRenderLayerDimensions),d(this.localDimensionIndices,n.modelTransform.localToRenderLayerDimensions),t.source.readonly||void 0===o&&(o=Object(Ve.a)({title:"Delete annotation",onClick:()=>{const n=t.source.getReference(e.id);try{t.source.delete(n)}finally{n.dispose()}}}),o.classList.add("neuroglancer-annotation-list-entry-delete"),r.appendChild(o))}),e.description){++a;const t=document.createElement("div");t.classList.add("neuroglancer-annotation-description"),t.classList.add("neuroglancer-annotation-list-entry-highlight"),t.textContent=e.description,r.appendChild(t)}return s.style.gridRow=`span ${a}`,void 0!==o&&(o.style.gridRow=`span ${a}`),this.attachedAnnotationStates.get(t).listElements.set(e.id,r),r.addEventListener("mouseenter",()=>{this.displayState.hoverState.value={id:e.id,partIndex:0,annotationLayerState:t},this.layer.selectAnnotation(t,e.id,!1)}),r.addEventListener("action:select-position",n=>{n.stopPropagation(),this.layer.selectAnnotation(t,e.id,"toggle")}),r.addEventListener("mouseup",t=>{if(2===t.button){const{layerRank:t}=n,r=new Float32Array(t),s=new Float32Array(t);!function(e,t){switch(t.type){case i.e.AXIS_ALIGNED_BOUNDING_BOX:case i.e.LINE:Pe.a(e,t.pointA,t.pointB),Pe.f(e,e,.5);break;case i.e.POINT:e.set(t.point);break;case i.e.ELLIPSOID:e.set(t.center)}}(r,e),De.j(s,n.chunkToLayerTransform,t+1,r,t),We(this.layer,n,s)}}),r}}class qe extends Ue.b{constructor(e,t){super(),this.layer=e,this.state=t,this.layerView=this.registerDisposer(new Je(this.layer,this.state.addRef(),this.layer.annotationDisplayState)),this.registerDisposer(t);const{element:n}=this;n.classList.add("neuroglancer-annotations-tab"),n.appendChild(this.layerView.element)}}function Ye(e){let t=[];const{relationships:n}=e.source,{relationshipStates:i}=e.displayState;for(let e=0,r=n.length;e<r;++e){const r=i.get(n[e]).segmentationState.value;null!=r&&r.segmentSelectionState.hasSelectedSegment?t[e]=[r.segmentSelectionState.selectedSegment.clone()]:t[e]=[]}return t}class Xe extends Oe.a{constructor(e,t){super(),this.layer=e,this.annotationDescription=Object(Te.y)(t,"description",Te.C)}get annotationLayer(){for(const e of this.layer.annotationStates.states)if(!e.source.readonly)return e}}class Ke extends Xe{constructor(e,t){super(e,t)}trigger(e){const{annotationLayer:t}=this;if(void 0!==t&&e.active){const n=Qe(e,t);if(void 0===n)return;const r={id:"",description:"",relatedSegments:Ye(t),point:n,type:i.e.POINT,properties:t.source.properties.map(e=>e.default)},s=t.source.add(r,!0);this.layer.selectAnnotation(t,s.id,!0),s.dispose()}}get description(){return"annotate point"}toJSON(){return"annotatePoint"}}function Qe(e,t){const n=t.chunkTransform.value;if(void 0!==n.error)return;const i=new Float32Array(n.modelTransform.unpaddedRank);return Object(U.e)(i,e.position,t.localPosition.value,n.layerRank,n.combinedGlobalLocalToChunkTransform)?i:void 0}class Ze extends Xe{trigger(e){const{annotationLayer:t}=this;if(void 0!==t&&e.active){const n=()=>{const n=this.inProgressAnnotation,r=n.reference,s=this.getUpdatedAnnotation(r.value,e,t);JSON.stringify(Object(i.h)(s,t.source))!==JSON.stringify(Object(i.h)(r.value,t.source))&&(n.annotationLayer.source.update(r,s),this.layer.selectAnnotation(t,r.id,!0))};if(void 0===this.inProgressAnnotation){const i=t.source.add(this.getInitialAnnotation(e,t),!1);this.layer.selectAnnotation(t,i.id,!0);const r=e.changed.add(n),s=()=>{r(),i.dispose()};this.inProgressAnnotation={annotationLayer:t,reference:i,disposer:s}}else n(),this.inProgressAnnotation.annotationLayer.source.commit(this.inProgressAnnotation.reference),this.inProgressAnnotation.disposer(),this.inProgressAnnotation=void 0}}disposed(){this.deactivate(),super.disposed()}deactivate(){void 0!==this.inProgressAnnotation&&(this.inProgressAnnotation.annotationLayer.source.delete(this.inProgressAnnotation.reference),this.inProgressAnnotation.disposer(),this.inProgressAnnotation=void 0)}}class et extends Ze{getInitialAnnotation(e,t){const n=Qe(e,t);return{id:"",type:this.annotationType,description:"",pointA:n,pointB:n,properties:t.source.properties.map(e=>e.default)}}getUpdatedAnnotation(e,t,n){const i=Qe(t,n);return void 0===i?e:Object.assign(Object.assign({},e),{pointB:i})}}class tt extends et{get description(){return"annotate bounding box"}toJSON(){return"annotateBoundingBox"}}tt.prototype.annotationType=i.e.AXIS_ALIGNED_BOUNDING_BOX;class nt extends et{get description(){return"annotate line"}getInitialAnnotation(e,t){const n=super.getInitialAnnotation(e,t);return this.initialRelationships=n.relatedSegments=Ye(t),n}getUpdatedAnnotation(e,t,n){const i=super.getUpdatedAnnotation(e,t,n),r=this.initialRelationships,s=Ye(n);return i.relatedSegments=void 0===r?s:Array.from(s,(e,t)=>{const n=r[t];return e=e.filter(e=>-1===n.findIndex(t=>Ie.a.equal(e,t))),[...n,...e]}),i}toJSON(){return"annotateLine"}}nt.prototype.annotationType=i.e.LINE;class it extends Ze{getInitialAnnotation(e,t){const n=Qe(e,t);return{type:i.e.ELLIPSOID,id:"",description:"",segments:Ye(t),center:n,radii:C.u.fromValues(0,0,0),properties:t.source.properties.map(e=>e.default)}}getUpdatedAnnotation(e,t,n){const i=Qe(t,n);if(void 0===i)return e;const r=e.center,s=r.length;for(let e=0;e<s;++e)i[e]=Math.abs(r[e]-i[e]);return Object.assign(Object.assign({},e),{radii:i})}get description(){return"annotate ellipsoid"}toJSON(){return"annotateSphere"}}Object(Oe.b)("annotatePoint",(e,t)=>new Ke(e,t)),Object(Oe.b)("annotateBoundingBox",(e,t)=>new tt(e,t)),Object(Oe.b)("annotateLine",(e,t)=>new nt(e,t)),Object(Oe.b)("annotateSphere",(e,t)=>new it(e,t));const rt=Me.a.fromObject({enter:{action:"commit"},escape:{action:"cancel"}});function st(e,t,n,i){return new _e.a(n,(n,r,s)=>{const o=document.createElement("div");o.classList.add("neuroglancer-related-segment-list");const a=document.createElement("div");a.classList.add("neuroglancer-related-segment-list-header");const c=Object(Ne.a)({title:"Copy segment IDs",onClick:()=>{Object(ke.a)(t.map(e=>e.toString()).join(", "))}});let l;if(a.appendChild(c),null!=n&&(l=document.createElement("input"),l.type="checkbox",l.addEventListener("change",()=>{const{visibleSegments:e}=n,i=t.some(t=>!e.has(t));for(const n of t)e.set(n,i)}),a.appendChild(l)),void 0!==i){const e=Object(Ve.a)({title:"Remove all IDs",onClick:()=>{i([])}});a.appendChild(e)}const d=document.createElement("span");if(d.classList.add("neuroglancer-related-segment-list-title"),d.textContent=e,a.appendChild(d),void 0!==i){const e=Object(Ae.a)({title:"Add related segment ID",onClick:()=>{const e=new I.a,r=s.registerDisposer(Object(I.c)(e)),a=document.createElement("div");a.classList.add("neuroglancer-segment-list-entry"),a.classList.add("neuroglancer-segment-list-entry-new");const c=Object(Ne.a)({});if(c.classList.add("neuroglancer-segment-list-entry-copy"),a.appendChild(c),null!=n){const e=document.createElement("input");e.type="checkbox",a.appendChild(e)}const l=Object(Ve.a)({title:"Cancel adding new segment ID",onClick:()=>{r()}});a.appendChild(l);const d=document.createElement("input");d.autocomplete="off",d.spellcheck=!1,d.classList.add("neuroglancer-segment-list-entry-id"),e.registerDisposer(new Me.b(d,rt)).allShortcutsAreGlobal=!0;const u=()=>{const e=new Ie.a;return e.tryParseString(d.value)?(d.dataset.valid="true",e):void(d.dataset.valid="false")};u(),d.addEventListener("input",()=>{u()}),d.addEventListener("blur",()=>{const e=u();void 0!==e&&i([...t,e]),r()}),Object(Me.c)(d,"cancel",r),Object(Me.c)(d,"commit",()=>{const e=u();void 0!==e&&i([...t,e]),r()}),a.appendChild(d),o.appendChild(a),d.focus(),e.registerDisposer(()=>{d.value="",a.remove()})}});a.appendChild(e)}o.appendChild(a);const u=[];for(const e of t){const r=document.createElement("div");r.classList.add("neuroglancer-segment-list-entry"),r.addEventListener("click",()=>{null!=n&&n.selectSegment(e,!0)});const s=Object(Ne.a)({title:"Copy segment ID",onClick:t=>{Object(ke.a)(e.toString()),t.stopPropagation()}});let a;if(s.classList.add("neuroglancer-segment-list-entry-copy"),r.appendChild(s),null!=n&&(a=document.createElement("input"),a.type="checkbox",a.title="Toggle segment visibility",a.addEventListener("click",t=>{const{visibleSegments:i}=n;i.set(e,!i.has(e)),t.stopPropagation()}),r.appendChild(a)),void 0!==i){const n=Object(Ve.a)({title:"Remove ID",onClick:n=>{i(t.filter(t=>!Ie.a.equal(t,e))),n.stopPropagation()}});r.appendChild(n)}const c=document.createElement("span");c.classList.add("neuroglancer-segment-list-entry-id");const l=e.toString();null!=n&&Object(we.h)(n.maxIdLength,l),c.textContent=l,r.appendChild(c);const d=Object(Be.a)({title:"Filter by label",onClick:t=>{null!=n&&n.filterBySegmentLabel(e),t.stopPropagation()}});d.classList.add("neuroglancer-segment-list-entry-filter"),d.style.visibility="hidden",r.appendChild(d);const h=document.createElement("span");h.classList.add("neuroglancer-segment-list-entry-name"),r.appendChild(h),o.appendChild(r),null!=n&&(r.addEventListener("mouseenter",()=>{n.segmentSelectionState.set(e)}),r.addEventListener("mouseleave",()=>{n.segmentSelectionState.set(null)})),u.push({id:e,row:r,checkbox:a,nameElement:h,idElement:c,filterElement:d})}null!=n&&(s.registerDisposer(Object(Q.j)(e=>o.style.setProperty("--neuroglancer-segment-list-width",`${e}ch`),n.maxIdLength)),s.registerDisposer(Object(ee.d)(()=>{const{segmentSelectionState:e,visibleSegments:i}=n;let r=0;for(const{id:t,row:n,checkbox:s}of u){n.dataset.selected=(e.hasSelectedSegment&&Ie.a.equal(e.selectedSegment,t)).toString(),(s.checked=i.has(t))&&++r}l.checked=r===t.length&&r>0,l.indeterminate=r>0&&r<t.length},n.visibleSegments.changed,n.segmentSelectionState.changed)),s.registerDisposer(Object(ee.d)(()=>{const e=n.segmentLabelMap.value;for(const{id:t,nameElement:i,idElement:r,filterElement:s}of u){let o="";void 0!==e&&(o=e.get(t.toString())||""),s.style.visibility=o?"":"hidden",i.textContent=o,r.style.backgroundColor=Object(Se.d)(Object(we.d)(n,t))}},n.segmentColorHash.changed,n.segmentLabelMap.changed))),r.appendChild(o)})}function ot(e){return class extends e{constructor(...e){let t;super(...e),this.annotationStates=this.registerDisposer(new Ge),this.annotationDisplayState=new r.a,this.selectedAnnotation=this.registerDisposer(new $e(this.annotationStates)),this.annotationCrossSectionRenderScaleHistogram=new be.a,this.annotationCrossSectionRenderScaleTarget=Object(be.e)(8),this.annotationProjectionRenderScaleHistogram=new be.a,this.annotationProjectionRenderScaleTarget=Object(be.e)(8),this.selectedAnnotation.changed.add(this.specificationChanged.dispatch),this.annotationDisplayState.color.changed.add(this.specificationChanged.dispatch),this.annotationDisplayState.shader.changed.add(this.specificationChanged.dispatch),this.annotationDisplayState.shaderControls.changed.add(this.specificationChanged.dispatch),this.tabs.add("annotations",{label:"Annotations",order:10,getter:()=>new qe(this,this.selectedAnnotation.addRef())});const n=()=>{const e=this.isReady;e&&void 0!==t?(t(),t=void 0):e||void 0!==t||(t=this.annotationStates.markLoading())};this.readyStateChanged.add(n),n();const{mouseState:i}=this.manager.layerSelectedValues;this.registerDisposer(i.changed.add(()=>{if(i.active){const{pickedAnnotationLayer:e}=i;if(void 0!==e&&this.annotationStates.states.includes(e)){const t=this.annotationDisplayState.hoverState.value;return void(void 0!==t&&t.id===i.pickedAnnotationId&&t.partIndex===i.pickedOffset&&t.annotationLayerState===e||(this.annotationDisplayState.hoverState.value={id:i.pickedAnnotationId,partIndex:i.pickedOffset,annotationLayerState:e}))}}this.annotationDisplayState.hoverState.value=void 0}))}initializeAnnotationLayerViewTab(e){}restoreState(e){super.restoreState(e),this.selectedAnnotation.restoreState(e.selectedAnnotation),this.annotationDisplayState.color.restoreState(e.annotationColor)}captureSelectionState(e,t){super.captureSelectionState(e,t);const n=t.pickedAnnotationLayer;void 0!==n&&this.annotationStates.states.includes(n)&&(e.annotationId=t.pickedAnnotationId,e.annotationPartIndex=t.pickedOffset,e.annotationSourceIndex=n.sourceIndex,e.annotationSubsource=n.subsourceId)}displayAnnotationState(e,t,n){if(void 0===e.annotationId)return!1;const r=this.annotationStates.states.find(t=>t.sourceIndex===e.annotationSourceIndex&&(void 0===e.annotationSubsource||t.subsourceId===e.annotationSubsource));if(void 0===r)return!1;const s=n.registerDisposer(r.source.getReference(e.annotationId));return t.appendChild(n.registerDisposer(new _e.a(n.registerDisposer(new Q.a(()=>({annotation:s,chunkTransform:r.chunkTransform}))),({annotation:e,chunkTransform:t},n,o)=>{if(null==e){const t=document.createElement("div");return t.classList.add("neuroglancer-selection-annotation-status"),t.textContent=null===e?"Annotation not found":"Loading...",void n.appendChild(t)}const a=void 0===t.error?t.layerRank:0,c=document.createElement("div");c.classList.add("neuroglancer-selected-annotation-details-position-grid"),c.style.gridTemplateColumns=`[icon] 0fr [copy] 0fr repeat(${a}, [dim] 0fr [coord] 0fr) [move] 0fr [delete] 0fr`,n.appendChild(c);const l=i.i[e.type],d=document.createElement("div");if(d.className="neuroglancer-selected-annotation-details-icon",d.textContent=l.icon,c.appendChild(d),0!==a){const{layerDimensionNames:n}=t.modelTransform;for(let e=0;e<a;++e){const t=document.createElement("div");t.classList.add("neuroglancer-selected-annotation-details-position-dim"),t.textContent=n[e],t.style.gridColumn=`dim ${e+1}`,c.appendChild(t)}He(e,t,(e,n)=>{const i=Object(Ne.a)({title:"Copy position",onClick:()=>{Object(ke.a)(e.map(e=>Math.floor(e)).join(", "))}});i.style.gridColumn="copy",c.appendChild(i);for(let t=0;t<a;++t){const n=document.createElement("div");n.classList.add("neuroglancer-selected-annotation-details-position-coord"),n.style.gridColumn=`coord ${t+1}`,n.textContent=Math.floor(e[t]).toString(),c.appendChild(n)}if(!n){const n=Object(ze.a)({title:"Move to position",onClick:()=>{We(this,t,e)}});n.style.gridColumn="move",c.appendChild(n)}})}if(!r.source.readonly){const e=Object(Ve.a)({title:"Delete annotation",onClick:()=>{r.source.delete(s)}});e.classList.add("neuroglancer-selected-annotation-details-delete"),c.appendChild(e)}const{relationships:u,properties:h}=r.source,p=r.source.readonly,{relatedSegments:f}=e;for(let e=0,t=u.length;e<t;++e){const t=void 0===f?[]:f[e];if(0===t.length&&p)continue;const i=e,a=u[e];n.appendChild(o.registerDisposer(st(a,t,r.displayState.relationshipStates.get(a).segmentationState,p?void 0:e=>{const t=s.value;if(null==t)return;let{relatedSegments:n}=t;n=void 0===n?r.source.relationships.map(()=>[]):n.slice(),n[i]=e;const o=Object.assign(Object.assign({},t),{relatedSegments:n});r.source.update(s,o),r.source.commit(s)})).element)}for(let t=0,i=h.length;t<i;++t){const i=h[t],r=document.createElement("label");r.classList.add("neuroglancer-annotation-property");const s=document.createElement("span");s.classList.add("neuroglancer-annotation-property-label"),s.textContent=i.identifier,r.appendChild(s);const{description:o}=i;void 0!==o&&(r.title=o);const a=e.properties[t],c=document.createElement("span");c.classList.add("neuroglancer-annotation-property-value"),c.textContent="float32"===i.type?a.toPrecision(6):a.toString(),r.appendChild(c),n.appendChild(r)}if(!r.source.readonly||e.description)if(r.source.readonly){const t=document.createElement("div");t.className="neuroglancer-annotation-details-description",t.textContent=e.description||"",n.appendChild(t)}else{const t=document.createElement("textarea");t.value=e.description||"",t.rows=3,t.className="neuroglancer-annotation-details-description",t.placeholder="Description",t.addEventListener("change",()=>{const n=t.value;r.source.update(s,Object.assign(Object.assign({},e),{description:n||void 0})),r.source.commit(s)}),n.appendChild(t)}})).element),!0}displaySelectionState(e,t,n){let i=this.displayAnnotationState(e,t,n);return super.displaySelectionState(e,t,n)&&(i=!0),i}addLocalAnnotations(e,t,n){const{subsourceEntry:i}=e,s=new r.b({localPosition:this.localPosition,transform:e.getRenderLayerTransform(),source:t,displayState:this.annotationDisplayState,dataSource:e.loadedDataSource.layerDataSource,subsourceIndex:e.subsourceIndex,subsourceId:i.id,role:n});this.addAnnotationLayerState(s,e)}addStaticAnnotations(e){const{subsourceEntry:t}=e,{staticAnnotations:n}=t.subsource;return void 0!==n&&(e.activate(()=>{this.addLocalAnnotations(e,n,ye.c.DEFAULT_ANNOTATION)}),!0)}addAnnotationLayerState(e,t){const n=t.activated;n.registerDisposer(this.annotationStates.add(e));const i=new ae(this.manager.chunkManager,e.addRef());if(i.source instanceof s.b){const e=new ge({annotationLayer:i.addRef(),renderScaleTarget:this.annotationCrossSectionRenderScaleTarget,renderScaleHistogram:this.annotationCrossSectionRenderScaleHistogram});n.registerDisposer(t.messages.addChild(e.messages));const r=new me({annotationLayer:i.addRef(),renderScaleTarget:this.annotationProjectionRenderScaleTarget,renderScaleHistogram:this.annotationProjectionRenderScaleHistogram});n.registerDisposer(t.messages.addChild(r.messages)),n.registerDisposer(Object(Q.k)((t,n)=>{n&&(t.registerDisposer(this.addRenderLayer(e.addRef())),t.registerDisposer(this.addRenderLayer(r.addRef())))},this.annotationDisplayState.displayUnfiltered))}{const e=new ve(i,this.annotationCrossSectionRenderScaleHistogram);n.registerDisposer(this.addRenderLayer(e)),n.registerDisposer(t.messages.addChild(e.messages))}{const e=new pe(i.addRef(),this.annotationProjectionRenderScaleHistogram);n.registerDisposer(this.addRenderLayer(e)),n.registerDisposer(t.messages.addChild(e.messages))}}selectAnnotation(e,t,n){this.manager.root.selectionState.captureSingleLayerState(this,n=>(n.annotationId=t,n.annotationSourceIndex=e.sourceIndex,n.annotationSubsource=e.subsourceId,!0),n)}toJSON(){const e=super.toJSON();return e.selectedAnnotation=this.selectedAnnotation.toJSON(),e.annotationColor=this.annotationDisplayState.color.toJSON(),e}}}},function(e,t,n){"use strict";
/**
 * @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 i;n.d(t,"b",(function(){return i})),n.d(t,"a",(function(){return r})),function(e){e[e.LITTLE=0]="LITTLE",e[e.BIG=1]="BIG"}(i||(i={}));const r=function(){const e=Uint16Array.of(4386);return 17===new Uint8Array(e.buffer)[0]?i.BIG:i.LITTLE}()},function(e,t,n){"use strict";n.d(t,"c",(function(){return i})),n.d(t,"d",(function(){return r})),n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return o}));
/**
 * @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 i="rendered_view.addLayer",r="rendered_view.removeLayer",s="SharedProjectionParameters",o="SharedProjectionParameters.changed"},function(e,t,n){"use strict";n.d(t,"a",(function(){return g})),n.d(t,"b",(function(){return v}));var i=n(38),r=n(36),s=n(17),o=n(4),a=n(68),c=n(2),l=n(127),d=n(1),u=n(112),h=n(32),p=n(41);
/**
 * @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 f extends o.e{}class m extends u.a{constructor(){super((e,{showMatches:t,segmentationState:n})=>{e.registerDisposer(t.changed.add(this.changed.dispatch)),e.registerDisposer(n.changed.add(this.changed.dispatch)),e.registerDisposer(Object(o.k)((e,t)=>{if(null==t)return;const{visibleSegments:n}=t;let i=0===n.size;e.registerDisposer(t.visibleSegments.changed.add(()=>{const e=0===n.size;e!==i&&(i=e,this.changed.dispatch())}))},n))})}get(e){let t=super.get(e);return void 0===t&&(t={segmentationState:new o.e(void 0),showMatches:new s.b(!1)},super.set(e,t)),t}}class g extends c.a{constructor(){super(...arguments),this.shader=Object(h.a)("\nvoid main() {\n  setColor(defaultColor());\n}\n"),this.shaderControls=new p.a(this.shader),this.fallbackShaderControls=new o.e(Object(p.c)("\nvoid main() {\n  setColor(defaultColor());\n}\n")),this.shaderError=Object(h.b)(),this.color=new a.a(d.u.fromValues(1,1,0)),this.relationshipStates=this.registerDisposer(new m),this.ignoreNullSegmentFilter=new s.b(!0),this.displayUnfiltered=Object(o.h)((e,t)=>{for(const n of e.values())if(n.showMatches.value){if(!t)return!1;const e=n.segmentationState.value;if(null!=e&&e.visibleSegments.size>0)return!1}return!0},this.relationshipStates,this.ignoreNullSegmentFilter),this.hoverState=new f(void 0)}}class v extends c.a{constructor(e){super();const{transform:t,localPosition:n,source:s,role:a=r.c.ANNOTATION}=e;this.transform=t,this.localPosition=n,this.source=this.registerDisposer(s),this.role=a,this.displayState=e.displayState,this.chunkTransform=this.registerDisposer(Object(o.h)(e=>Object(l.a)(()=>Object(i.f)(Object(l.b)(e))),this.transform)),this.dataSource=e.dataSource,this.subsourceId=e.subsourceId,this.subsourceIndex=e.subsourceIndex}get sourceIndex(){const{dataSource:e}=this;return e.layer.dataSources.indexOf(e)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));function i(e,t){return t>>>=0,e>>>=0,t=((t=Math.imul(t,3432918353)>>>0)<<15|t>>>17)>>>0,e=5*(e=((e=(e^(t=Math.imul(t,461845907)>>>0))>>>0)<<13|e>>>19)>>>0)+3864292196>>>0}},function(e,t,n){},function(e,t,n){"use strict";var i=n(33),r=n(163);function s(e,t,n){r.call(this,e,t,n,{noCredentials:!0})}i(s,r),s.enabled=r.enabled,e.exports=s},function(e,t,n){"use strict";(function(t){e.exports={isOpera:function(){return t.navigator&&/opera/i.test(t.navigator.userAgent)},isKonqueror:function(){return t.navigator&&/konqueror/i.test(t.navigator.userAgent)},hasDomain:function(){if(!t.document)return!0;try{return!!t.document.domain}catch(e){return!1}}}}).call(this,n(46))},function(e,t,n){"use strict";(function(t){var i=n(90),r=n(83),s=n(122);e.exports={WPrefix:"_jp",currentWindowId:null,polluteGlobalNamespace:function(){e.exports.WPrefix in t||(t[e.exports.WPrefix]={})},postMessage:function(n,i){t.parent!==t&&t.parent.postMessage(r.stringify({windowId:e.exports.currentWindowId,type:n,data:i||""}),"*")},createIframe:function(e,n){var r,s,o=t.document.createElement("iframe"),a=function(){clearTimeout(r);try{o.onload=null}catch(e){}o.onerror=null},c=function(){o&&(a(),setTimeout((function(){o&&o.parentNode.removeChild(o),o=null}),0),i.unloadDel(s))},l=function(e){o&&(c(),n(e))};return o.src=e,o.style.display="none",o.style.position="absolute",o.onerror=function(){l("onerror")},o.onload=function(){clearTimeout(r),r=setTimeout((function(){l("onload timeout")}),2e3)},t.document.body.appendChild(o),r=setTimeout((function(){l("timeout")}),15e3),s=i.unloadAdd(c),{post:function(e,t){setTimeout((function(){try{o&&o.contentWindow&&o.contentWindow.postMessage(e,t)}catch(e){}}),0)},cleanup:c,loaded:a}},createHtmlfile:function(n,r){var s,o,a,c=["Active"].concat("Object").join("X"),l=new t[c]("htmlfile"),d=function(){clearTimeout(s),a.onerror=null},u=function(){l&&(d(),i.unloadDel(o),a.parentNode.removeChild(a),a=l=null,CollectGarbage())},h=function(e){l&&(u(),r(e))};l.open(),l.write('<html><script>document.domain="'+t.document.domain+'";<\/script></html>'),l.close(),l.parentWindow[e.exports.WPrefix]=t[e.exports.WPrefix];var p=l.createElement("div");return l.body.appendChild(p),a=l.createElement("iframe"),p.appendChild(a),a.src=n,a.onerror=function(){h("onerror")},s=setTimeout((function(){h("timeout")}),15e3),o=i.unloadAdd(u),{post:function(e,t){try{setTimeout((function(){a&&a.contentWindow&&a.contentWindow.postMessage(e,t)}),0)}catch(e){}},cleanup:u,loaded:d}}},e.exports.iframeEnabled=!1,t.document&&(e.exports.iframeEnabled=("function"==typeof t.postMessage||"object"==typeof t.postMessage)&&!s.isKonqueror())}).call(this,n(46))},function(e,t,n){"use strict";
/**
 * @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 i(e){return("0"+e.toString(16)).slice(-2)}function r(e){return Array.prototype.map.call(e,i).join("")}function s(e){if(!/^(?:[0-9a-fA-F]{2})*$/.test(e))throw new Error("Invalid hex-encoded string");const t=e.length/2,n=new Uint8Array(t);for(let i=0;i<t;++i)n[i]=parseInt(e.substr(2*i,2),16);return n}n.d(t,"c",(function(){return i})),n.d(t,"b",(function(){return r})),n.d(t,"a",(function(){return s}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(7),r=n(43);
/**
 * @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 s(e=-1,t=-1,n=1,r=1,s=1,o=1){return Object(i.l)(new Float32Array([e,t,e,r,n,r,n,t]),2,s,o)}function o(e,t=-1,n=-1,i=1,o=1,a=1,c=1){return Object(r.b)(e,WebGL2RenderingContext.ARRAY_BUFFER,s,t,n,i,o,a,c).value}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"b",(function(){return o})),n.d(t,"c",(function(){return a}));var i=n(45),r=n(74);
/**
 * @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 s(e){e.addOutputBuffer("vec4","v4f_fragColor",null),e.setFragmentMain("v4f_fragColor = getValue0();")}function o(e,t=s,n=1){return e.memoize.get(`elementWiseTextureShader:${n}:${Object(i.a)(t)}`,()=>{let i=new r.a(e);i.addVarying("vec2","vTexCoord"),i.addUniform("sampler2D","uSampler",n),i.addInitializer(t=>{let i=[];for(let e=0;e<n;++e)i[e]=e;e.uniform1iv(t.uniform("uSampler"),i)});for(let e=0;e<n;++e)i.addFragmentCode(`\nvec4 getValue${e}() {\n  return texture(uSampler[${e}], vTexCoord);\n}\n`);return i.addUniform("mat4","uProjectionMatrix"),i.require(t),i.addAttribute("vec4","aVertexPosition"),i.addAttribute("vec2","aTexCoord"),i.setVertexMain("vTexCoord = aTexCoord; gl_Position = uProjectionMatrix * aVertexPosition;"),i.build()})}function a(e){return e.memoize.get("trivialColorShader",()=>{let t=new r.a(e);return t.addVarying("vec4","vColor"),t.addOutputBuffer("vec4","v4f_fragColor",null),t.setFragmentMain("v4f_fragColor = vColor;"),t.addAttribute("vec4","aVertexPosition"),t.addAttribute("vec4","aColor"),t.addUniform("mat4","uProjectionMatrix"),t.setVertexMain("vColor = aColor; gl_Position = uProjectionMatrix * aVertexPosition;"),t.build()})}},function(e,t,n){"use strict";
/**
 * @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 i(e){try{return e()}catch(e){return{error:e.message}}}function r(e){if(void 0!==e.error)throw new Error(e.error);return e}n.d(t,"a",(function(){return i})),n.d(t,"b",(function(){return r}))},function(e,t,n){"use strict";
/**
 * @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 i(e,t,n,i){t*=6;let r=Math.floor(t),s=t-r,o=i*(1-n),a=i*(1-n*s),c=i*(1-n*(1-s));switch(r%6){case 0:e[0]=i,e[1]=c,e[2]=o;break;case 1:e[0]=a,e[1]=i,e[2]=o;break;case 2:e[0]=o,e[1]=i,e[2]=c;break;case 3:e[0]=o,e[1]=a,e[2]=i;break;case 4:e[0]=c,e[1]=o,e[2]=i;break;case 5:e[0]=i,e[1]=o,e[2]=a}return e}n.d(t,"a",(function(){return i}))},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(177),r=n.n(i),s=n(27);
/**
 * @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 o(e={}){return Object(s.a)(Object.assign({svg:r.a},e))}},function(e,t,n){"use strict";var i=n(33),r=n(64).EventEmitter;function s(e,t){r.call(this);var n=this;this.bufferPosition=0,this.xo=new t("POST",e,null),this.xo.on("chunk",this._chunkHandler.bind(this)),this.xo.once("finish",(function(e,t){n._chunkHandler(e,t),n.xo=null;var i=200===e?"network":"permanent";n.emit("close",null,i),n._cleanup()}))}i(s,r),s.prototype._chunkHandler=function(e,t){if(200===e&&t)for(var n=-1;;this.bufferPosition+=n+1){var i=t.slice(this.bufferPosition);if(-1===(n=i.indexOf("\n")))break;var r=i.slice(0,n);r&&this.emit("message",r)}},s.prototype._cleanup=function(){this.removeAllListeners()},s.prototype.abort=function(){this.xo&&(this.xo.close(),this.emit("close",null,"user"),this.xo=null),this._cleanup()},e.exports=s},function(e,t,n){"use strict";var i=n(33),r=n(163);function s(e,t,n,i){r.call(this,e,t,n,i)}i(s,r),s.enabled=r.enabled&&r.supportsCORS,e.exports=s},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(1),r=n(19);
/**
 * @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 s{constructor(e,t,n){this.size=i.u.clone(e),this.transform=i.m.clone(t),this.finiteRank=n;const s=i.m.create(),o=r.g(s,4,t,4,4);if(0===o)throw new Error("Transform is singular");this.invTransform=s,this.detTransform=o}toObject(){return{size:this.size,transform:this.transform,finiteRank:this.finiteRank}}static fromObject(e){return new s(e.size,e.transform,e.finiteRank)}globalToLocalSpatial(e,t){return i.u.transformMat4(e,t,this.invTransform)}localSpatialVectorToGlobal(e,t){return Object(i.r)(e,t,this.transform)}globalToLocalNormal(e,t){return Object(i.s)(e,t,this.transform)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(39),r=n(22);
/**
 * @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 s(e,t,n,s,o,a,c=i.e){let l;e:for(;;){l=await e.get(l,c);t:for(;;)try{return await Object(r.b)(t,o(l.credentials,n),s,c)}catch(e){if(e instanceof r.a){if("refresh"===a(e))continue e;continue t}throw e}}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var i=n(107),r=n.n(i),s=n(27);
/**
 * @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 o(e={}){return Object(s.a)(Object.assign({svg:r.a},e))}},function(e,t,n){"use strict";n.d(t,"a",(function(){return h}));var i=n(30),r=n(7),s=n(2),o=n(6),a=n(93);class c{constructor(){this.anchorIndex=0,this.anchorClientOffset=0}splice(e){let{anchorIndex:t}=this,n=0;for(const i of e){if(n+=i.retainCount,t<n)break;const{deleteCount:e}=i;if(t<n+e){t=n;break}const{insertCount:r}=i;t=t-e+r,n+=r-r}this.anchorIndex=t}}class l{constructor(){this.startIndex=0,this.endIndex=0,this.anchorIndex=0,this.anchorOffset=0,this.scrollOffset=0}}class d{constructor(){this.itemSize=[],this.totalKnownSize=0,this.numItemsInTotalKnownSize=0}getEstimatedSize(e){const t=this.itemSize[e];return void 0===t?this.totalKnownSize/this.numItemsInTotalKnownSize:t}getEstimatedTotalSize(){return this.totalKnownSize/this.numItemsInTotalKnownSize*this.itemSize.length}getEstimatedOffset(e,t=0,n=0){for(;t<e;++t)n+=this.getEstimatedSize(t);for(;t>e;--t)n-=this.getEstimatedSize(t-1);return n}splice(e){let{itemSize:t}=this;t=this.itemSize=Object(r.k)(t,e),this.totalKnownSize=t.reduce((e,t)=>e+t,0),this.numItemsInTotalKnownSize=t.reduce(e=>e+1,0)}}function u(e,t,n,i,r,s){let o,a,c,l,d,{anchorIndex:u,anchorClientOffset:h}=s,p=r.getEstimatedOffset(u);if(0===i||0===r.totalKnownSize)o=Math.max(0,u-5),a=Math.min(n,o+10),d=u,c=0,l=h;else{const e=r.getEstimatedTotalSize(),s=Math.max(0,e-i);l=p-h,l=Math.max(0,Math.min(s,l));const f=l-1*i,m=l-.5*i,g=l+i+.5*i,v=p-h+i+1*i;o=Math.min(n,t.startIndex);let b=r.getEstimatedOffset(o,u,p);if(b<f)for(;o+1<n;++o){const e=r.getEstimatedSize(o);if(b+e>=m)break;b+=e}if(b>=m)for(;b>f&&o>0;--o){b-=r.getEstimatedSize(o-1)}a=Math.min(n,t.endIndex);let y=r.getEstimatedOffset(a,u,p);if(y<g)for(;y<=v&&a+1<=n;++a){y+=r.getEstimatedSize(a)}else if(y>=v)for(;a>o;--a){const e=r.getEstimatedSize(a-1);if(y-e<g)break;y-=e}for(d=u,c=p;d<o;++d){c+=r.getEstimatedSize(d)}for(;d>a;--d){c-=r.getEstimatedSize(d-1)}}e.startIndex=o,e.endIndex=a,e.anchorIndex=d,e.anchorOffset=c,e.scrollOffset=l}class h extends s.a{constructor(e){super(),this.element=document.createElement("div"),this.spacer=document.createElement("div"),this.topItems=document.createElement("div"),this.bottomItems=document.createElement("div"),this.renderedItems=[],this.renderGeneration=-1,this.listGeneration=-1,this.newRenderedItems=[],this.state=new c,this.renderParams=new l,this.newRenderParams=new l,this.sizes=new d,this.debouncedUpdateView=this.registerCancellable(Object(i.a)(()=>this.updateView())),this.resizeObserver=new a.a(()=>this.updateView());const{selectedIndex:t}=e;void 0!==t&&(this.state.anchorIndex=t,this.state.anchorClientOffset=0);const n=this.source=e.source;this.sizes.itemSize.length=n.length;const{element:r,spacer:s,topItems:o,bottomItems:u}=this;this.resizeObserver.observe(r),this.registerDisposer(()=>this.resizeObserver.disconnect()),r.appendChild(s),r.appendChild(o),o.style.position="absolute",o.style.left="0px",o.style.right="0px",u.style.left="0px",u.style.right="0px",u.style.position="absolute",r.appendChild(u),r.addEventListener("scroll",()=>{const e=r.scrollTop;this.state.anchorClientOffset=this.renderParams.anchorOffset-e,this.renderParams.scrollOffset=e,this.debouncedUpdateView()}),void 0!==n.changed&&this.registerDisposer(n.changed.add(e=>{this.sizes.splice(e),this.state.splice(e),this.renderedItems.length=0,this.debouncedUpdateView()})),void 0!==n.renderChanged&&this.registerDisposer(n.renderChanged.add(this.debouncedUpdateView))}updateView(){const{element:e}=this;if(null===e.offsetParent)return;const t=e.offsetHeight,{source:n,state:i,sizes:r}=this,s=n.length,{spacer:a,topItems:c,bottomItems:l}=this,{changed:d,renderChanged:h}=n;let p;for(;;){p=this.newRenderParams;const e=this.renderParams;let n;if(u(p,e,s,t,r,i),void 0!==h&&h.count!==this.renderGeneration||void 0!==d&&d.count!==this.listGeneration?(this.renderGeneration=void 0===h?-1:h.count,this.listGeneration=void 0===d?-1:d.count,n=!0,this.renderedItems.length=0):n=!1,!(n||(m=p,g=e,m.startIndex<g.startIndex||m.endIndex>g.endIndex))){e.scrollOffset=p.scrollOffset,p=e;break}this.renderParams=p,this.newRenderParams=e;const a=this.renderedItems,v=this.newRenderedItems;v.length=0,this.renderedItems=v,this.newRenderedItems=a;const{source:b}=this,{render:y}=b,{startIndex:S,endIndex:w,anchorIndex:x}=p;function*f(e,t){for(let n=e;n<t;++n){let e=a[n];void 0===e&&(e=y.call(b,n)),v[n]=e,yield e}}Object(o.d)(c,f(S,x)),Object(o.d)(l,f(x,w));for(let e=S;e<w;++e){const t=v[e].getBoundingClientRect().height,n=r.itemSize[e];void 0!==n&&(r.totalKnownSize-=n,--r.numItemsInTotalKnownSize),r.itemSize[e]=t,r.totalKnownSize+=t,++r.numItemsInTotalKnownSize}}var m,g;!function(e,t){const n=t.getEstimatedOffset(e.anchorIndex),i=e.anchorOffset;e.anchorOffset=n,e.scrollOffset+=n-i}(p,r),i.anchorIndex=p.anchorIndex,i.anchorClientOffset=p.anchorOffset-p.scrollOffset,a.style.height=`${r.getEstimatedTotalSize()}px`,c.style.bottom=`calc(100% - ${p.anchorOffset}px)`,l.style.top=`${p.anchorOffset}px`,e.scrollTop=p.scrollOffset}getItemElement(e){return this.renderedItems[e]}forEachRenderedItem(e){if(null===this.element.offsetParent)return;const{startIndex:t,endIndex:n}=this.renderParams,{renderedItems:i}=this;for(let r=t;r<n;++r){const t=i[r];void 0!==t&&e(t,r)}}scrollItemIntoView(e){const t=this.sizes.getEstimatedOffset(e),n=t+this.sizes.getEstimatedSize(e),i=this.element.scrollTop;if(t<i)this.state.anchorIndex=e,this.state.anchorClientOffset=0;else{if(!(t>i&&n>i+this.element.offsetHeight))return;this.state.anchorIndex=e+1,this.state.anchorClientOffset=this.element.offsetHeight}this.debouncedUpdateView()}disposed(){Object(o.c)(this.element)}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return S}));var i=n(10),r=n(5),s=n(38),o=n(26),a=n(75),c=n(72),l=n(25),d=n(4),u=n(1),h=n(45),p=n(32),f=n(29),m=n(49);
/**
 * @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 g=u.m.create();function v(e,t,n,i,r,s){const o=n.projectionParameters.value,{centerDataPosition:c}=o;Object(a.c)(t,o.viewportNormalInGlobalCoordinates,c,s.transform,s.invTransform),e.uniformMatrix4fv(t.uniform("uProjectionMatrix"),!1,u.m.multiply(g,i,s.transform)),e.uniform3fv(t.uniform("uLowerClipBound"),r.lowerClipDisplayBound),e.uniform3fv(t.uniform("uUpperClipBound"),r.upperClipDisplayBound)}function b(e,t,n){e.uniform3fv(t.uniform("uChunkDataSize"),n)}function y(e,t,n,i){e.uniform3fv(t.uniform("uTranslation"),n),i?Object(f.c)(t.gl,6,1):e.drawArrays(e.TRIANGLE_FAN,0,6)}class S extends c.b{constructor(e,t){const{shaderError:n=Object(p.b)(),shaderParameters:i}=t;super(e.chunkManager,e,t);const{gl:s}=this;this.vertexIdHelper=this.registerDisposer(m.a.get(s)),this.shaderParameters=i;const{channelCoordinateSpace:o}=t;this.channelCoordinateSpace=void 0===o?Object(d.f)(r.k):o,this.registerDisposer(i.changed.add(this.redrawNeeded.dispatch));const c=this.registerDisposer(Object(d.g)(e=>e.rank,[this.channelCoordinateSpace]));this.shaderGetter=Object(p.c)(this,s,{memoizeKey:`volume/RenderLayer:${Object(h.a)(this.constructor)}`,fallbackParameters:t.fallbackShaderParameters,parameters:i,encodeParameters:t.encodeShaderParameters,shaderError:n,extraParameters:c,defineShader:(e,t,n,i)=>{!function(e,t){if(Object(m.b)(e),Object(a.b)(e),e.addUniform("highp vec3","uTranslation"),e.addUniform("highp mat4","uProjectionMatrix"),e.addUniform("highp vec3","uChunkDataSize"),e.addUniform("highp vec3","uLowerClipBound"),e.addUniform("highp vec3","uUpperClipBound"),t)return Object(f.b)(e),e.setVertexMain(`\nint vertexIndex1 = gl_VertexID / ${f.a};\nint vertexIndex2 = vertexIndex1 == 5 ? 0 : vertexIndex1 + 1;\nvec3 vertexPosition1 = getBoundingBoxPlaneIntersectionVertexPosition(uChunkDataSize, uTranslation, uLowerClipBound, uUpperClipBound, vertexIndex1);\nvec3 vertexPosition2 = getBoundingBoxPlaneIntersectionVertexPosition(uChunkDataSize, uTranslation, uLowerClipBound, uUpperClipBound, vertexIndex2);\nemitLine(uProjectionMatrix * vec4(vertexPosition1, 1.0),\n         uProjectionMatrix * vec4(vertexPosition2, 1.0),\n         2.0);\n`),void e.setFragmentMain("\nemit(vec4(1.0, 1.0, 1.0, getLineAlpha()));\n");e.addVarying("highp vec3","vChunkPosition"),e.setVertexMain("\nvec3 position = getBoundingBoxPlaneIntersectionVertexPosition(uChunkDataSize, uTranslation, uLowerClipBound, uUpperClipBound, gl_VertexID);\ngl_Position = uProjectionMatrix * vec4(position, 1.0);\nvChunkPosition = (position - uTranslation) +\n    0.001 * abs(uPlaneNormal);\n")}(e,null===t),e.addOutputBuffer("vec4","v4f_fragData0",0),e.addFragmentCode("\nvoid emit(vec4 color) {\n  v4f_fragData0 = color;\n}\n"),null!==t&&(Object(l.d)(e,t,i,"vChunkPosition"),this.defineShader(e,n))},getContextKey:e=>null===e?null:e.shaderKey}),this.tempChunkPosition=new Float32Array(e.rank),this.initializeCounterpart()}get dataType(){return this.multiscaleSource.dataType}getValueAt(e){let{tempChunkPosition:t}=this;for(const{source:n,chunkTransform:i}of this.visibleSourcesList){if(!Object(s.e)(t,e,this.localPosition.value,i.layerRank,i.combinedGlobalLocalToChunkTransform))continue;const r=n.getValueAt(t,i);if(null!=r)return r}return null}beginChunkFormat(e,t,n){const{gl:i}=this,r=this.shaderGetter(t),{shader:s,parameters:o,fallback:a}=r;return null!==s&&(s.bind(),function(e,t,n){n&&Object(f.d)(e,t,1)}(s,n,null===t),null!==t&&(this.initializeShader(e,s,o,a),t.beginDrawing(i,s))),r}endSlice(e,t,n){}draw(e){const{sliceView:t}=e,n=t.visibleLayers.get(this),{visibleSources:r}=n;if(0===r.length)return;const{projectionParameters:s,wireFrame:a}=e,{gl:c}=this;this.vertexIdHelper.enable();const l=u.u.create(),{renderScaleHistogram:d}=this;let h;void 0!==d&&d.begin(this.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber);let p,f=null;const m=u.u.create(),g=()=>{null!==f&&(null!==p&&p.endDrawing(c,f),this.endSlice(t,f,h.parameters))};let S=!0;for(const e of r){const n=Object(o.o)(s,e.chunkLayout),{chunkTransform:{channelToChunkDimensionIndices:r}}=e,u=e.source,{fixedPositionWithinChunk:O,chunkDisplayDimensionIndices:k}=e;for(const e of k)O[e]=0;const E=a?null:u.chunkFormat;if(E!==p&&(p=E,g(),h=this.beginChunkFormat(t,E,s),f=h.shader),null===f)continue;const T=u.chunks;m.fill(1);let M,D=n.size;const L=u.spec.rank;v(c,f,t,s.viewProjectionMat,e,n),null!==E&&E.beginSource(c,f),S=!0;let j=0,I=0;if(t.forEachVisibleChunk(e,e=>{let t=T.get(e);if(t&&t.state===i.h.GPU_MEMORY){let e=t.chunkDataSize;if(e!==M){M=e;for(let e=0;e<3;++e){const t=k[e];m[e]=-1===t||t>=L?1:M[t]}b(c,f,m)}const{chunkGridPosition:n}=t;for(let e=0;e<3;++e){const t=k[e];l[e]=-1===t||t>=L?0:D[e]*n[t]}null!==E&&E.bindChunk(c,f,t,O,k,r,S),S=!1,y(c,f,l,a),++j}else++I}),(0!==j||0!==I)&&void 0!==d){const{effectiveVoxelSize:t}=e,n=(w=t[0],x=t[1],C=t[2],w>x?C>w?w:x>C?x:C:C>x?x:w>C?w:C);d.add(n,n/s.pixelSize,j,I)}}var w,x,C;g(),this.vertexIdHelper.disable()}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var i=n(2),r=n(6);
/**
 * @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 s extends i.a{constructor(e){super(),this.model=e,this.element=document.createElement("input");const{element:t}=this;t.classList.add("neuroglancer-color-widget"),t.type="color",t.addEventListener("change",()=>this.updateModel()),this.registerDisposer(e.changed.add(()=>this.updateView())),this.updateView()}updateView(){this.element.value=this.model.toString()}updateModel(){this.model.restoreState(this.element.value)}disposed(){Object(r.c)(this.element),super.disposed()}}},function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var i=n(27);
/**
 * @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 r(e={}){return Object(i.a)(Object.assign({text:"↗"},e))}},function(e,t,n){"use strict";
/**
 * @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 i(e,t){let n="";for(let i=0;i<=t&&(n=e.toFixed(i),parseFloat(n)!==e);++i);return n}n.d(t,"a",(function(){return i}))},function(e,t,n){"use strict";n.r(t);n(120),n(219);var i=n(15),r=n.n(i),s=n(23),o=n(79),a=n(50),c=n(67),l=n(28),d=n(81),u=n(44),h=n(102),p=n(18);
/**
 * @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=Symbol("disjoint_sets:rank"),m=Symbol("disjoint_sets:parent"),g=Symbol("disjoint_sets:next"),v=Symbol("disjoint_sets:prev");function b(e){let t=e,n=e[m];for(;n!==e;)n=(e=n)[m];for(e=t[m];n!==e;)t[m]=n,t=e,e=t[m];return n}function*y(e){let t=e;do{yield t,t=t[g]}while(t!==e)}const S=Symbol("disjoint_sets:min");class w{constructor(){this.map=new Map,this.generation=0}get(e){let t=e.toString(),n=this.map.get(t);return void 0===n?e:b(n)[S]}isMinElement(e){let t=this.get(e);return t===e||p.a.equal(t,e)}makeSet(e){let t=e.toString(),{map:n}=this,i=n.get(t);return void 0===i?(i=e.clone(),(r=i)[m]=r,r[f]=0,r[g]=r[v]=r,i[S]=i,n.set(t,i),i):b(i);var r}link(e,t){if((e=this.makeSet(e))===(t=this.makeSet(t)))return!1;this.generation++;let n=function(e,t){let n=e[f],i=t[f];return n>i?(t[m]=e,e):(e[m]=t,n===i&&(t[f]=i+1),t)}(e,t);!function(e,t){let n=e[v],i=t[v];t[v]=n,n[g]=t,e[v]=i,i[g]=e}(e,t);let i=e[S],r=t[S];return n[S]=p.a.less(i,r)?i:r,!0}*setElements(e){let t=e.toString(),n=this.map.get(t);void 0===n?yield e:yield*y(n)}clear(){let{map:e}=this;return 0!==e.size&&(++this.generation,e.clear(),!0)}get size(){return this.map.size}*mappings(e=new Array(2)){for(let t of this.map.values())e[0]=t,e[1]=b(t)[S],yield e}[Symbol.iterator](){return this.mappings()}toJSON(){let e=new Array;for(let n of this.map.values())if((t=n)[m]===t){let t=new Array;for(let e of y(n))t.push(e);t.sort(p.a.compare),e.push(t)}var t;return e.sort((e,t)=>p.a.compare(e[0],t[0])),e.map(e=>e.map(e=>e.toString()))}}var x=n(0),C=n(3),O=n(16);let k=class extends O.c{constructor(){super(...arguments),this.disjointSets=new w,this.changed=new C.a}get value(){return this}static makeWithCounterpart(e){let t=new this;return t.initializeCounterpart(e),t}disposed(){this.disjointSets=void 0,this.changed=void 0,super.disposed()}link(e,t){if(this.disjointSets.link(e,t)){let{rpc:n}=this;n&&n.invoke("DisjointUint64Sets.add",{id:this.rpcId,al:e.low,ah:e.high,bl:t.low,bh:t.high}),this.changed.dispatch()}}get(e){return this.disjointSets.get(e)}clear(){if(this.disjointSets.clear()){let{rpc:e}=this;e&&e.invoke("DisjointUint64Sets.clear",{id:this.rpcId}),this.changed.dispatch()}}setElements(e){return this.disjointSets.setElements(e)}get size(){return this.disjointSets.size}toJSON(){return this.disjointSets.toJSON()}restoreState(e){if(this.clear(),void 0!==e){let t=[new p.a,new p.a];Object(x.b)(e,e=>{Object(x.b)(e,(e,n)=>{t[n%2].parseString(String(e),10),0!==n&&this.link(t[0],t[1])})})}}};k=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}([Object(O.f)("DisjointUint64Sets")],k);const E=new p.a,T=new p.a;Object(O.e)("DisjointUint64Sets.add",(function(e){let t=this.get(e.id);E.low=e.al,E.high=e.ah,T.low=e.bl,T.high=e.bh,t.disjointSets.link(E,T)&&t.changed.dispatch()})),Object(O.e)("DisjointUint64Sets.clear",(function(e){let t=this.get(e.id);t.disjointSets.clear()&&t.changed.dispatch()}));var M=n(59),D=n(9),L=n(25),j=n(94),I=n(78),P=n(136),A=n(4);
/**
 * @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 R{constructor(e){this.disjointSets=e,this.generation=Number.NaN,this.hashMap=new j.a}update(){let{disjointSets:e}=this;const{generation:t}=e;if(this.generation!==t){this.generation=t;let{hashMap:n}=this;n.clear();for(let[t,i]of e.mappings())n.set(t,i)}}}class N extends P.a{constructor(e,t){super(e,{shaderParameters:new A.a(e=>({hasEquivalences:e.registerDisposer(Object(A.g)(e=>0!==e.size,[t.segmentEquivalences])),hasHighlightedSegments:e.registerDisposer(Object(A.g)(e=>0!==e.size,[t.highlightedSegments])),hasSegmentStatedColors:e.registerDisposer(Object(A.g)(e=>0!==e.size,[t.segmentStatedColors])),hideSegmentZero:t.hideSegmentZero})),transform:t.transform,renderScaleHistogram:t.renderScaleHistogram,renderScaleTarget:t.renderScaleTarget,localPosition:t.localPosition}),this.displayState=t,this.segmentColorShaderManager=new d.b("segmentColorHash"),this.segmentStatedColorShaderManager=new d.c("segmentStatedColor"),this.gpuSegmentStatedColorHashTable=I.a.get(this.gl,this.displayState.segmentStatedColors.hashTable),this.hashTableManager=new I.c("visibleSegments"),this.gpuHashTable=I.a.get(this.gl,this.displayState.visibleSegments.hashTable),this.hashTableManagerHighlighted=new I.c("highlightedSegments"),this.gpuHashTableHighlighted=I.a.get(this.gl,this.displayState.highlightedSegments.hashTable),this.equivalencesShaderManager=new I.b("equivalences"),this.equivalencesHashMap=new R(this.displayState.segmentEquivalences.disjointSets),this.gpuEquivalencesHashTable=I.a.get(this.gl,this.equivalencesHashMap.hashMap),this.registerDisposer(this.shaderParameters),Object(u.g)(t,this),this.registerDisposer(t.selectedAlpha.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(t.notSelectedAlpha.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(t.ignoreNullVisibleSet.changed.add(this.redrawNeeded.dispatch))}getSources(e){return this.multiscaleSource.getSources(e)}defineShader(e,t){this.hashTableManager.defineShader(e),e.addFragmentCode("\nuint64_t getUint64DataValue() {\n  return toUint64(getDataValue());\n}\n"),t.hasEquivalences?(this.equivalencesShaderManager.defineShader(e),e.addFragmentCode(`\nuint64_t getMappedObjectId() {\n  uint64_t value = getUint64DataValue();\n  uint64_t mappedValue;\n  if (${this.equivalencesShaderManager.getFunctionName}(value, mappedValue)) {\n    return mappedValue;\n  }\n  return value;\n}\n`)):e.addFragmentCode("\nuint64_t getMappedObjectId() {\n  return getUint64DataValue();\n}\n"),this.segmentColorShaderManager.defineShader(e),e.addUniform("highp uvec2","uSelectedSegment"),e.addUniform("highp uint","uShowAllSegments"),e.addUniform("highp float","uSelectedAlpha"),e.addUniform("highp float","uNotSelectedAlpha"),e.addUniform("highp float","uSaturation");let n="\n  uint64_t value = getMappedObjectId();\n\n  float alpha = uSelectedAlpha;\n  float saturation = uSaturation;\n";t.hideSegmentZero&&(n+="\n  if (value.value[0] == 0u && value.value[1] == 0u) {\n    emit(vec4(vec4(0, 0, 0, 0)));\n    return;\n  }\n"),n+=`\n  bool has = uShowAllSegments != 0u ? true : ${this.hashTableManager.hasFunctionName}(value);\n  if (uSelectedSegment == value.value) {\n    float adjustment = has ? 0.5 : 0.75;\n    if (saturation > adjustment) {\n      saturation -= adjustment;\n    } else {\n      saturation += adjustment;\n    }\n  } else if (!has) {\n    alpha = uNotSelectedAlpha;\n  }\n`,t.hasSegmentStatedColors?(this.segmentStatedColorShaderManager.defineShader(e),n+=`\n  vec3 rgb;\n  if (!${this.segmentStatedColorShaderManager.getFunctionName}(value, rgb)) {\n    rgb = segmentColorHash(value);\n  }\n`):n+="\n  vec3 rgb = segmentColorHash(value);\n",t.hasHighlightedSegments&&(this.hashTableManagerHighlighted.defineShader(e),n+=`\n  if (${this.hashTableManagerHighlighted.hasFunctionName}(value)) {\n    rgb = vec3(0.2,0.2,2.0);\n    saturation = 1.0;\n  };\n`),n+="\n  emit(vec4(mix(vec3(1.0,1.0,1.0), rgb, saturation), alpha));\n",e.setFragmentMain(n)}initializeShader(e,t,n){const{gl:i}=this,{displayState:r}=this,{segmentSelectionState:s,visibleSegments:o}=this.displayState,a=this.displayState.ignoreNullVisibleSet.value;let c=0,l=0;if(s.hasSelectedSegment){let e=s.selectedSegment;c=e.low,l=e.high}i.uniform1f(t.uniform("uSelectedAlpha"),this.displayState.selectedAlpha.value),i.uniform1f(t.uniform("uSaturation"),this.displayState.saturation.value),i.uniform1f(t.uniform("uNotSelectedAlpha"),this.displayState.notSelectedAlpha.value),i.uniform2ui(t.uniform("uSelectedSegment"),c,l),i.uniform1ui(t.uniform("uShowAllSegments"),o.hashTable.size||!a?0:1),this.hashTableManager.enable(i,t,this.gpuHashTable),n.hasHighlightedSegments&&this.hashTableManagerHighlighted.enable(i,t,this.gpuHashTableHighlighted),n.hasEquivalences&&(this.equivalencesHashMap.update(),this.equivalencesShaderManager.enable(i,t,this.gpuEquivalencesHashTable)),this.segmentColorShaderManager.enable(i,t,r.segmentColorHash),n.hasSegmentStatedColors&&this.segmentStatedColorShaderManager.enable(i,t,this.gpuSegmentStatedColorHashTable)}endSlice(e,t,n){const{gl:i}=this;this.hashTableManager.disable(i,t),n.hasHighlightedSegments&&this.hashTableManagerHighlighted.disable(i,t),n.hasEquivalences&&this.equivalencesShaderManager.disable(i,t),n.hasSegmentStatedColors&&this.segmentStatedColorShaderManager.disable(i,t),super.endSlice(e,t,n)}}var V,_=n(108),B=n(17),F=n(115),z=n(113);let U=V=class extends O.c{constructor(){super(...arguments),this.hashTable=new j.a,this.changed=new C.b}get value(){return this}static makeWithCounterpart(e){let t=new V;return t.initializeCounterpart(e),t}disposed(){super.disposed(),this.hashTable=void 0,this.changed=void 0}set_(e,t){return this.hashTable.set(e,t)}set(e,t){if(this.set_(e,t)){let{rpc:n}=this;n&&n.invoke("Uint64Map.set",{id:this.rpcId,key:e,value:t}),this.changed.dispatch(e,!0)}}has(e){return this.hashTable.has(e)}get(e,t){return this.hashTable.get(e,t)}[Symbol.iterator](){return this.hashTable.entries()}delete_(e){return this.hashTable.delete(e)}delete(e){if(this.delete_(e)){let{rpc:t}=this;t&&t.invoke("Uint64Map.delete",{id:this.rpcId,key:e}),this.changed.dispatch(e,!1)}}get size(){return this.hashTable.size}clear(){if(this.hashTable.clear()){let{rpc:e}=this;e&&e.invoke("Uint64Map.clear",{id:this.rpcId}),this.changed.dispatch(null,!1)}}toJSON(){let e={};for(let[t,n]of this.hashTable.entries())e[t.toString()]=n.toString();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.
 */
var G;U=V=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}([Object(O.f)("Uint64Map")],U),Object(O.e)("Uint64Map.set",(function(e){let t=this.get(e.id);t.set_(e.key,e.value)&&t.changed.dispatch()})),Object(O.e)("Uint64Map.delete",(function(e){let t=this.get(e.id);t.delete_(e.key)&&t.changed.dispatch()})),Object(O.e)("Uint64Map.clear",(function(e){let t=this.get(e.id);t.hashTable.clear()&&t.changed.dispatch()}));let $=G=class extends O.c{constructor(){super(...arguments),this.hashTable=new j.b,this.changed=new C.b}get value(){return this}static makeWithCounterpart(e){let t=new G;return t.initializeCounterpart(e),t}disposed(){super.disposed(),this.hashTable=void 0,this.changed=void 0}set(e,t){t?this.add(e):this.delete(e)}add_(e){return this.hashTable.add(e)}add(e){if(this.add_(e)){let{rpc:t}=this;t&&t.invoke("Uint64Set.add",{id:this.rpcId,value:e}),this.changed.dispatch(e,!0)}}has(e){return this.hashTable.has(e)}[Symbol.iterator](){return this.hashTable.keys()}delete_(e){return this.hashTable.delete(e)}delete(e){if(this.delete_(e)){let{rpc:t}=this;t&&t.invoke("Uint64Set.delete",{id:this.rpcId,value:e}),this.changed.dispatch(e,!1)}}get size(){return this.hashTable.size}clear(){if(this.hashTable.clear()){let{rpc:e}=this;e&&e.invoke("Uint64Set.clear",{id:this.rpcId}),this.changed.dispatch(null,!1)}}toJSON(){let e=new Array;for(let t of this)e.push(t.toString());return e.sort(),e}};$=G=function(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}([Object(O.f)("Uint64Set")],$),Object(O.e)("Uint64Set.add",(function(e){let t=this.get(e.id);t.add_(e.value)&&t.changed.dispatch()})),Object(O.e)("Uint64Set.delete",(function(e){let t=this.get(e.id);t.delete_(e.value)&&t.changed.dispatch()})),Object(O.e)("Uint64Set.clear",(function(e){let t=this.get(e.id);t.hashTable.clear()&&t.changed.dispatch()}));var W=n(30),H=n(7),J=n(66),q=n(68),Y=n(2),X=n(11),K=n(51),Q=n(32),Z=n(62),ee=n(63),te=n(114),ne=n(129),ie=n(95),re=n(96),se=n(77),oe=n(88),ae=n(97),ce=n(98),le=n(48),de=n(135);n.d(t,"SegmentationUserLayer",(function(){return pe}));
/**
 * @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=new p.a,he=Object(F.a)(s.k);class pe extends he{constructor(e,t){super(e,t),this.sliceViewRenderScaleHistogram=new l.a,this.sliceViewRenderScaleTarget=Object(l.e)(1),this.segmentQuery=new A.c("",x.E),this.segmentQueryFocusTime=new A.e(Number.NEGATIVE_INFINITY),this.selectSegment=(e,t)=>{this.manager.root.selectionState.captureSingleLayerState(this,t=>(t.value=e.clone(),!0),t)},this.filterBySegmentLabel=e=>{const t=e.toString(),n=this.displayState.segmentLabelMap.value;if(void 0===n)return;const i=n.idToLabel[t];i&&this.filterSegments(i)},this.filterSegments=e=>{this.segmentQuery.value=e,this.segmentQueryFocusTime.value=Date.now(),this.tabs.value="segments",this.manager.root.selectedLayer.layer=this.managedLayer},this.displayState={segmentColorHash:d.a.getDefault(),segmentStatedColors:U.makeWithCounterpart(this.manager.worker),segmentSelectionState:new u.a,selectedAlpha:Object(_.a)(.5),saturation:Object(_.a)(1),notSelectedAlpha:Object(_.a)(0),silhouetteRendering:new A.c(0,x.q,0),objectAlpha:Object(_.a)(1),hideSegmentZero:new B.b(!0,!0),ignoreNullVisibleSet:new B.b(!0,!0),visibleSegments:$.makeWithCounterpart(this.manager.worker),highlightedSegments:$.makeWithCounterpart(this.manager.worker),segmentEquivalences:k.makeWithCounterpart(this.manager.worker),skeletonRenderingOptions:new M.c,shaderError:Object(Q.b)(),renderScaleHistogram:new l.a,renderScaleTarget:Object(l.e)(1),segmentLabelMap:new A.e(void 0),segmentPropertyMaps:new A.e([]),maxIdLength:new A.e(1),selectSegment:this.selectSegment,filterBySegmentLabel:this.filterBySegmentLabel,transparentPickEnabled:this.pick},this.has2dLayer=this.registerDisposer(Object(A.h)(e=>e.some(e=>e instanceof N),{changed:this.layersChanged,value:this.renderLayers})),this.has3dLayer=this.registerDisposer(Object(A.h)(e=>e.some(e=>e instanceof a.a||e instanceof a.c||e instanceof M.a||e instanceof M.e),{changed:this.layersChanged,value:this.renderLayers})),this.hasSkeletonsLayer=this.registerDisposer(Object(A.h)(e=>e.some(e=>e instanceof M.a),{changed:this.layersChanged,value:this.renderLayers})),this.displayState.visibleSegments.changed.add(this.specificationChanged.dispatch),this.displayState.segmentEquivalences.changed.add(this.specificationChanged.dispatch),this.displayState.segmentSelectionState.bindTo(this.manager.layerSelectedValues,this),this.displayState.selectedAlpha.changed.add(this.specificationChanged.dispatch),this.displayState.saturation.changed.add(this.specificationChanged.dispatch),this.displayState.notSelectedAlpha.changed.add(this.specificationChanged.dispatch),this.displayState.objectAlpha.changed.add(this.specificationChanged.dispatch),this.displayState.hideSegmentZero.changed.add(this.specificationChanged.dispatch),this.displayState.ignoreNullVisibleSet.changed.add(this.specificationChanged.dispatch),this.displayState.skeletonRenderingOptions.changed.add(this.specificationChanged.dispatch),this.displayState.segmentColorHash.changed.add(this.specificationChanged.dispatch),this.displayState.segmentStatedColors.changed.add(this.specificationChanged.dispatch),this.displayState.renderScaleTarget.changed.add(this.specificationChanged.dispatch),this.displayState.silhouetteRendering.changed.add(this.specificationChanged.dispatch),this.sliceViewRenderScaleTarget.changed.add(this.specificationChanged.dispatch),this.segmentQuery.changed.add(this.specificationChanged.dispatch),this.tabs.add("rendering",{label:"Render",order:-100,getter:()=>new ge(this)}),this.tabs.add("segments",{label:"Seg.",order:-50,getter:()=>new Se(this)}),this.tabs.default="rendering"}bindSegmentListWidth(e){return Object(A.j)(t=>e.style.setProperty("--neuroglancer-segment-list-width",`${t}ch`),this.displayState.maxIdLength)}get volumeOptions(){return{volumeType:D.b.SEGMENTATION}}activateDataSubsources(e){let t;const n=[];for(const i of e){if(this.addStaticAnnotations(i))continue;const{volume:e,mesh:r,segmentPropertyMap:s}=i.subsourceEntry.subsource;if(e instanceof L.a){switch(e.dataType){case D.a.FLOAT32:i.deactivate("Data type not compatible with segmentation layer");continue}i.activate(()=>i.addRenderLayer(new N(e,Object.assign(Object.assign({},this.displayState),{transform:i.getRenderLayerTransform(),renderScaleTarget:this.sliceViewRenderScaleTarget,renderScaleHistogram:this.sliceViewRenderScaleHistogram,localPosition:this.localPosition}))))}else if(void 0!==r)i.activate(()=>{const e=Object.assign(Object.assign({},this.displayState),{transform:i.getRenderLayerTransform()});if(r instanceof a.b)i.addRenderLayer(new a.a(this.manager.chunkManager,r,e));else if(r instanceof a.d)i.addRenderLayer(new a.c(this.manager.chunkManager,r,e));else{const t=new M.b(this.manager.chunkManager,r,e);i.addRenderLayer(new M.a(t.addRef())),i.addRenderLayer(new M.e(t))}});else if(void 0!==s){const{labelMap:e}=s;if(void 0!==e){if(void 0!==t){i.deactivate("Only one segment label map is supported");continue}i.activate(()=>{}),t=e}n.push(s)}else i.deactivate("Not compatible with segmentation layer")}this.displayState.segmentLabelMap.value=t,Object(H.a)(n,this.displayState.segmentPropertyMaps.value)||(this.displayState.segmentPropertyMaps.value=n)}getLegacyDataSourceSpecifications(e,t,n){const i=super.getLegacyDataSourceSpecifications(e,t,n),r=Object(x.B)(t,"mesh",e=>null===e?null:Object(x.E)(e)),s=Object(x.B)(t,"skeletons",e=>null===e?null:Object(x.E)(e));if(void 0!==r||void 0!==s)for(const e of i)e.enableDefaultSubsources=!1,e.subsources=new Map([["default",{enabled:!0}],["bounds",{enabled:!0}]]);return null!=r&&i.push(Object(o.c)(this.manager.dataSourceProviderRegistry.convertLegacyUrl({url:r,type:"mesh"}))),null!=s&&i.push(Object(o.c)(this.manager.dataSourceProviderRegistry.convertLegacyUrl({url:s,type:"skeletons"}))),i}restoreState(e){super.restoreState(e),this.displayState.selectedAlpha.restoreState(e.selectedAlpha),this.displayState.saturation.restoreState(e.saturation),this.displayState.notSelectedAlpha.restoreState(e.notSelectedAlpha),this.displayState.objectAlpha.restoreState(e.objectAlpha),this.displayState.hideSegmentZero.restoreState(e.hideSegmentZero),this.displayState.silhouetteRendering.restoreState(e.meshSilhouetteRendering),this.displayState.ignoreNullVisibleSet.restoreState(e.ignoreNullVisibleSet);const{skeletonRenderingOptions:t}=this.displayState;t.restoreState(e.skeletonRendering);const n=e.skeletonShader;void 0!==n&&t.shader.restoreState(n),this.displayState.segmentColorHash.restoreState(e.colorSeed),this.displayState.renderScaleTarget.restoreState(e.meshRenderScale),Object(x.y)(e,"equivalences",e=>{this.displayState.segmentEquivalences.restoreState(e)});const i=(t,n)=>{Object(x.y)(e,t,e=>{if(void 0!==e){let{segmentEquivalences:t}=this.displayState;Object(x.b)(e,e=>{let i=p.a.parseString(String(e),10);n.add(t.get(i))})}})};i("segments",this.displayState.visibleSegments),i("highlights",this.displayState.highlightedSegments),this.displayState.highlightedSegments.changed.add(this.specificationChanged.dispatch),Object(x.y)(e,"segmentColors",e=>{if(void 0!==e){let{segmentEquivalences:t}=this.displayState,n=Object(x.x)(e,e=>Object(q.c)(String(e)));for(let[e,i]of n){const n=p.a.parseString(String(e)),r=new p.a(Object(q.b)(i));this.displayState.segmentStatedColors.set(t.get(n),r)}}}),this.sliceViewRenderScaleTarget.restoreState(e.crossSectionRenderScale),this.segmentQuery.restoreState(e.segmentQuery)}toJSON(){const e=super.toJSON();e.selectedAlpha=this.displayState.selectedAlpha.toJSON(),e.notSelectedAlpha=this.displayState.notSelectedAlpha.toJSON(),e.saturation=this.displayState.saturation.toJSON(),e.objectAlpha=this.displayState.objectAlpha.toJSON(),e.hideSegmentZero=this.displayState.hideSegmentZero.toJSON(),e.ignoreNullVisibleSet=this.displayState.ignoreNullVisibleSet.toJSON(),e.colorSeed=this.displayState.segmentColorHash.toJSON(),e.meshSilhouetteRendering=this.displayState.silhouetteRendering.toJSON();let{segmentStatedColors:t}=this.displayState;if(t.size>0){let n=t.toJSON();Object.keys(n).map(e=>n[e]="#"+parseInt(n[e],10).toString(16).padStart(6,"0")),e.segmentColors=n}let{visibleSegments:n}=this.displayState;n.size>0&&(e.segments=n.toJSON());let{highlightedSegments:i}=this.displayState;i.size>0&&(e.highlights=i.toJSON());let{segmentEquivalences:r}=this.displayState;return r.size>0&&(e.equivalences=r.toJSON()),e.skeletonRendering=this.displayState.skeletonRenderingOptions.toJSON(),e.meshRenderScale=this.displayState.renderScaleTarget.toJSON(),e.crossSectionRenderScale=this.sliceViewRenderScaleTarget.toJSON(),e.segmentQuery=this.segmentQuery.toJSON(),e}transformPickedValue(e){if(null==e)return e;const{segmentEquivalences:t,segmentLabelMap:{value:n}}=this.displayState;let i,r,s,o;return i="number"==typeof e?new p.a(e,0):e,0!==t.size?(r=t.get(e),s=p.a.equal(r,e)?void 0:r):r=i,void 0!==n&&(o=n.get(r.toString())),void 0===o&&void 0===s?i:new u.c(i,s,o)}handleAction(e){switch(e){case"recolor":this.displayState.segmentColorHash.randomize();break;case"clear-segments":if(!this.pick.value)break;this.displayState.visibleSegments.clear();break;case"select":{if(!this.pick.value)break;const{segmentSelectionState:e}=this.displayState;if(e.hasSelectedSegment){const t=e.selectedSegment,{visibleSegments:n}=this.displayState;n.set(t,!n.has(t))}break}case"highlight":{if(!this.pick.value)break;let{segmentSelectionState:e}=this.displayState;if(e.hasSelectedSegment){let t=e.selectedSegment,{highlightedSegments:n}=this.displayState;n.has(t)?n.delete(t):n.add(t)}break}}}selectionStateFromJson(e,t){super.selectionStateFromJson(e,t);const n=new p.a;let{value:i}=e;"number"==typeof i&&(i=i.toString()),"string"==typeof i&&n.tryParseString(i)?e.value=n:e.value=void 0}selectionStateToJson(e,t){const n=super.selectionStateToJson(e,t);let{value:i}=e;return i instanceof u.c?n.value=t?{key:i.key.toString(),value:i.value?i.value.toString():void 0,label:i.label}:(i.value||i.key).toString():i instanceof p.a&&(n.value=i.toString()),n}displaySegmentationSelection(e,t,n){const{value:i}=e;let r;if(("number"==typeof i||"string"==typeof i)&&(r=new p.a,!r.tryParseString(i.toString())))return!1;if(i instanceof p.a)r=i.clone();else{if(!(i instanceof u.c))return!1;r=i.key.clone()}const{segmentEquivalences:s,segmentLabelMap:{value:o},segmentPropertyMaps:{value:a},visibleSegments:c,segmentSelectionState:l}=this.displayState,h=s.get(r),f=document.createElement("div");let m;f.classList.add("neuroglancer-selection-details-segment"),f.classList.add("neuroglancer-segment-list-entry"),void 0!==o&&(m=o.get(h.toString()));const g=n.registerDisposer(Object(A.h)(e=>e.has(h),c)),v=n.registerDisposer(new B.c({changed:g.changed,get value(){return g.value},set value(e){c.set(h,e)}})).element;n.registerDisposer(Object(C.d)(()=>{f.dataset.selected=l.hasSelectedSegment&&p.a.equal(l.selectedSegment,h)?"true":"false"},l.changed)),f.addEventListener("mouseenter",()=>{this.displayState.segmentSelectionState.set(h)}),f.addEventListener("mouseleave",()=>{this.displayState.segmentSelectionState.set(null)}),v.title="Toggle segment visibility";const b=Object(Z.a)({title:"Copy segment ID",onClick:()=>{Object(J.a)(y)}});b.classList.add("neuroglancer-segment-list-entry-copy"),f.appendChild(b),f.appendChild(v);const y=h.toString();n.registerDisposer(this.bindSegmentListWidth(f));const S=document.createElement("span");S.classList.add("neuroglancer-selection-details-segment-id");const w=r.toString();if(S.textContent=w,fe(this.displayState.maxIdLength,w),fe(this.displayState.maxIdLength,y),f.appendChild(S),p.a.equal(h,r))n.registerDisposer(Object(C.d)(()=>{S.style.backgroundColor=Object(d.d)(Object(u.d)(this.displayState,h))},this.displayState.segmentStatedColors.changed,this.displayState.segmentColorHash.changed));else{const e=document.createElement("span");e.classList.add("neuroglancer-selection-details-segment-mapped-id"),e.textContent=h.toString(),n.registerDisposer(Object(C.d)(()=>{e.style.backgroundColor=Object(d.d)(Object(u.d)(this.displayState,h))},this.displayState.segmentStatedColors.changed,this.displayState.segmentColorHash.changed)),S.style.backgroundColor="white",f.appendChild(e)}const x=Object(ne.a)({title:"Filter by label",onClick:()=>{this.filterBySegmentLabel(h)}});x.classList.add("neuroglancer-segment-list-entry-filter"),f.appendChild(x),m||(x.style.visibility="hidden");const O=document.createElement("span");O.classList.add("neuroglancer-segment-list-entry-name"),O.textContent=m||"",f.appendChild(O),t.appendChild(f);for(const e of a){const{inlineProperties:n}=e;if(void 0===n)continue;const i=e.inlineIdToIndex[y];if(void 0!==i)for(const e of n.properties)if("label"!==e.type&&"description"===e.type){const n=e.values[i];if(!n)continue;const r=document.createElement("div");r.classList.add("neuroglancer-selection-details-segment-description"),r.textContent=n,t.appendChild(r)}}return!0}displaySelectionState(e,t,n){let i=this.displaySegmentationSelection(e,t,n);return super.displaySelectionState(e,t,n)&&(i=!0),i}}function fe(e,t){const{length:n}=t;e.value<n&&(e.value=n)}function me(e){return new ae.a({fragmentMain:e.displayState.skeletonRenderingOptions.shader,shaderError:e.displayState.shaderError,shaderControlState:e.displayState.skeletonRenderingOptions.shaderControlState})}pe.type="segmentation",pe.supportsPickOption=!0;class ge extends le.b{constructor(e){super(),this.layer=e;const{element:t}=this;t.classList.add("segmentation-dropdown");{const e=this.registerDisposer(new se.a(this.layer.displayState.saturation));e.promptElement.textContent="Saturation",t.appendChild(e.element)}const n=this.registerDisposer(new ee.a(e.has2dLayer,(e,t,n)=>{if(!e)return;const i=n.registerDisposer(new se.a(this.layer.displayState.selectedAlpha));i.promptElement.textContent="Opacity (on)",t.appendChild(i.element);const r=n.registerDisposer(new se.a(this.layer.displayState.notSelectedAlpha));r.promptElement.textContent="Opacity (off)",t.appendChild(r.element);{const e=n.registerDisposer(new oe.a(this.layer.sliceViewRenderScaleHistogram,this.layer.sliceViewRenderScaleTarget));e.label.textContent="Resolution (slice)",t.appendChild(e.element)}},this.visibility));t.appendChild(n.element);const i=this.registerDisposer(new ee.a(e.has3dLayer,(e,t,n)=>{if(!e)return;{const e=n.registerDisposer(new oe.a(this.layer.displayState.renderScaleHistogram,this.layer.displayState.renderScaleTarget));e.label.textContent="Resolution (mesh)",t.appendChild(e.element)}const i=n.registerDisposer(new se.a(this.layer.displayState.objectAlpha));i.promptElement.textContent="Opacity (3d)",t.appendChild(i.element);const r=n.registerDisposer(new se.a(this.layer.displayState.silhouetteRendering,{min:0,max:10,step:.1}));r.promptElement.textContent="Silhouette (3d)",r.element.title="Set to a non-zero value to increase transparency of object faces perpendicular to view direction",t.appendChild(r.element)},this.visibility));t.appendChild(i.element);{const n=this.registerDisposer(new B.c(e.displayState.hideSegmentZero));n.element.className="neuroglancer-segmentation-dropdown-hide-segment-zero neuroglancer-noselect";const i=document.createElement("label");i.className="neuroglancer-segmentation-dropdown-hide-segment-zero neuroglancer-noselect",i.appendChild(document.createTextNode("Hide segment ID 0")),i.appendChild(n.element),t.appendChild(i)}{const n=this.registerDisposer(new B.c(e.displayState.ignoreNullVisibleSet));n.element.className="neuroglancer-noselect";const i=document.createElement("label");i.className="neuroglancer-noselect",i.appendChild(document.createTextNode("Show all segments if none selected")),i.appendChild(n.element),t.appendChild(i)}const r=this.registerDisposer(new ee.a(e.hasSkeletonsLayer,(t,n,i)=>{if(!t)return;const r=(e,t)=>{{const r=i.registerDisposer(new te.a(e.mode)),s=document.createElement("label");s.className="neuroglancer-segmentation-dropdown-skeleton-render-mode neuroglancer-noselect",s.appendChild(document.createTextNode(`Skeleton mode (${t})`)),s.appendChild(r.element),n.appendChild(s)}{const i=this.registerDisposer(new se.a(e.lineWidth,{min:1,max:40,step:1}));i.promptElement.textContent=`Skeleton line width (${t})`,n.appendChild(i.element)}};r(e.displayState.skeletonRenderingOptions.params2d,"2d"),r(e.displayState.skeletonRenderingOptions.params3d,"3d");let s=document.createElement("div");s.className="neuroglancer-segmentation-dropdown-skeleton-shader-header";let o=document.createElement("div");o.style.flex="1",o.textContent="Skeleton shader:",s.appendChild(o),s.appendChild(Object(re.a)({title:"Show larger editor view",onClick:()=>{new we(this.layer)}})),s.appendChild(Object(ie.a)({title:"Documentation on skeleton rendering",href:"https://github.com/google/neuroglancer/blob/master/src/neuroglancer/sliceview/image_layer_rendering.md"})),n.appendChild(s);const a=i.registerDisposer(me(this.layer));n.appendChild(a.element),n.appendChild(i.registerDisposer(new ce.a(e.displayState.skeletonRenderingOptions.shaderControlState)).element),a.textEditor.refresh()},this.visibility));t.appendChild(r.element)}}const ve=/^[,\s]*[0-9]+(?:[,\s]+[0-9]+)*[,\s]*$/;class be extends Y.a{constructor(e,t,n){super(),this.query=e,this.segmentLabelMap=t,this.segmentationDisplayState=n,this.changed=new C.b,this.visibleSegmentsGeneration=-1,this.statusText=new A.e(""),this.selectedMatches=0,this.matchStatusTextPrefix="",this.debouncedUpdate=r()(()=>this.update(),0),this.render=(()=>{const e=document.createElement("div");e.classList.add("neuroglancer-segment-list-entry");const t=document.createElement("input");t.type="checkbox",t.title="Toggle segment visibility";const n=Object(Z.a)({title:"Copy segment ID"});n.classList.add("neuroglancer-segment-list-entry-copy"),e.appendChild(n),e.appendChild(t);const i=document.createElement("span");i.classList.add("neuroglancer-segment-list-entry-id"),e.appendChild(i);const r=Object(ne.a)({title:"Filter by label"});r.classList.add("neuroglancer-segment-list-entry-filter"),e.appendChild(r);const s=document.createElement("span");s.classList.add("neuroglancer-segment-list-entry-name"),e.appendChild(s);const{segmentationDisplayState:o}=this;function a(){const e=this.dataset.id;ue.tryParseString(e)&&(o.segmentSelectionState.set(ue),o.selectSegment(ue,!1))}function c(e){e.stopPropagation();const t=this.dataset.id;ue.tryParseString(t)&&o.selectSegment(ue,"toggle")}function l(){const e=this.parentElement.dataset.id;ue.tryParseString(e)&&o.filterBySegmentLabel(ue)}function d(){const e=this.dataset.id;ue.tryParseString(e)&&o.segmentSelectionState.set(null)}function u(e){e.stopPropagation();const t=this.parentElement.dataset.id;ue.parseString(t);const{visibleSegments:n}=o;this.checked?n.add(ue):n.delete(ue)}function h(e){Object(J.a)(this.parentElement.dataset.id),e.stopPropagation()}const{segmentSelectionState:p}=o;return t=>{const{sortedVisibleSegments:n,segmentLabelMap:i}=this;let r,s;const f=e.cloneNode(!0);void 0!==n&&t<n.length?(r=n[t].toString(),void 0!==i&&(s=i.get(r)),f.dataset.visibleList="true"):(void 0!==n&&(t-=n.length),[r,s]=this.matches[t]),f.dataset.selected=p.hasSelectedSegment&&p.selectedSegment.toString()===r?"true":"false";const{children:m}=f;m[1].addEventListener("change",u);const g=m[3];g.addEventListener("click",l),f.addEventListener("mouseenter",a),f.addEventListener("mouseleave",d),m[0].addEventListener("click",h),f.addEventListener("action:select-position",c);const v=m[2],b=m[4];return f.dataset.id=r,v.textContent=r,b.textContent=s||"",s||(g.style.visibility="hidden"),this.updateRendering(f),fe(o.maxIdLength,r),f}})(),this.update(),this.registerDisposer(n.visibleSegments.changed.add(this.debouncedUpdate)),this.registerDisposer(e.changed.add(this.debouncedUpdate))}get numMatches(){const{matches:e}=this;return void 0===e?0:e.length}update(){const e=this.query.value,{segmentLabelMap:t}=this,n=[];let i,r=!1,s="";const{visibleSegments:o}=this.segmentationDisplayState,a=o.changed.count,c=this.visibleSegmentsGeneration;let l;if(0===e.length){if(c!==a||void 0===this.sortedVisibleSegments){this.visibleSegmentsGeneration=a;const e=Array.from(o,e=>e.clone());e.sort(p.a.compare);const{sortedVisibleSegments:t}=this;void 0===t?(this.sortedVisibleSegments=e,n.push({retainCount:0,insertCount:e.length,deleteCount:0})):n.push(...Object(H.h)(t,e,p.a.compare)),this.sortedVisibleSegments=e,r=!0}else n.push({retainCount:this.sortedVisibleSegments.length,deleteCount:0,insertCount:0});void 0!==t&&(i=t.sortedNames,s=`${i.length} listed ids`,l=e=>t.has(e))}else if(void 0!==this.sortedVisibleSegments&&(n.push({deleteCount:this.sortedVisibleSegments.length,retainCount:0,insertCount:0}),this.sortedVisibleSegments=void 0,r=!0),this.visibleSegmentsGeneration=a,this.prevQuery===e)i=this.matches,l=this.matchPredicate,s=this.matchStatusTextPrefix;else if(null!==e.match(ve)){const n=e.split(/[\s,]+/),r=[],o=new Set;for(let e=0,t=n.length;e<t;++e){const t=n[e];if(""===t)continue;const i=new p.a;if(!i.tryParseString(t))continue;const s=i.toString();o.has(s)||(o.add(s),r.push(i))}r.sort(p.a.compare),i=r.map(e=>{const n=e.toString();return[n,void 0===t?"":t.get(n)||""]}),l=e=>o.has(e),s=`${i.length} ids`}else if(e.startsWith("/"))try{const n=new RegExp(e.substring(1));void 0!==t&&(i=t.sortedNames.filter(e=>e[1].match(n)),s=`${i.length}/${t.sortedNames.length} regexp matches`,l=e=>{const i=t.get(e);return void 0!==i&&null!==i.match(n)})}catch(e){}else if(void 0!==t){const{sortedNames:n}=t,r=Object(h.d)(e),o=Object(H.c)(0,n.length,e=>Object(h.c)(n[e][1],r)>=0),a=Object(H.c)(o,n.length,e=>!Object(h.d)(n[e][1]).startsWith(r));i=n.slice(o,a),l=e=>{const n=t.get(e);return void 0!==n&&Object(h.d)(n).startsWith(r)},s=`${i.length}/${t.sortedNames.length} prefix matches`}const d=this.matches;if(i!==d&&(n.push({retainCount:0,deleteCount:void 0===d?0:d.length,insertCount:void 0===i?0:i.length}),r=!0),i!==d||a!==c){let e=s,t=0;if(void 0!==l){for(const e of o)l(e.toString())&&++t;e+=` (${t} visible)`}this.selectedMatches=t,this.statusText.value=e}this.prevQuery=e,this.matches=i,this.matchStatusTextPrefix=s,this.matchPredicate=l;const{sortedVisibleSegments:u}=this;this.length=(void 0===u?0:u.length)+(void 0===i?0:i.length),r&&this.changed.dispatch(n)}updateRendering(e){const t=e.dataset.id;if(void 0===t)return;ue.tryParseString(t);const{children:n}=e,i=n[1],r=n[2],{visibleSegments:s}=this.segmentationDisplayState;i.checked=s.has(ue),r.style.backgroundColor=Object(d.d)(Object(u.d)(this.segmentationDisplayState,ue)),r.textContent=t}updateRenderedItems(e){const{segmentSelectionState:t}=this.segmentationDisplayState,n=t.hasSelectedSegment?t.selectedSegment.toString():"";e.forEachRenderedItem(e=>{this.updateRendering(e),e.dataset.selected=e.dataset.id===n?"true":"false"})}}const ye=X.a.fromObject({enter:{action:"toggle-listed"},"shift+enter":{action:"hide-listed"},"control+enter":{action:"hide-all"},escape:{action:"cancel"}});class Se extends le.b{constructor(e){super(),this.layer=e;const{element:t}=this;t.classList.add("neuroglancer-segment-display-tab");const n=document.createElement("input");n.classList.add("neuroglancer-segment-list-query"),n.addEventListener("focus",()=>{n.select()}),this.registerDisposer(new X.b(n,ye)).allShortcutsAreGlobal=!0;const i=this.registerCancellable(r()(()=>{this.layer.segmentQuery.value=n.value},200));n.autocomplete="off",n.title=ye.describe(),n.spellcheck=!1,n.placeholder="Enter ID, name prefix or /regexp",this.registerDisposer(Object(A.j)(e=>{n.value=e},this.layer.segmentQuery)),this.registerDisposer(Object(A.j)(e=>{Date.now()-e<100&&(setTimeout(()=>{n.focus()},0),this.layer.segmentQueryFocusTime.value=Number.NEGATIVE_INFINITY)},this.layer.segmentQueryFocusTime)),t.appendChild(n),t.appendChild(this.registerDisposer(new ee.a(e.displayState.segmentLabelMap,(t,r,s)=>{const o=s.registerDisposer(new be(this.layer.segmentQuery,t,e.displayState)),a=document.createElement("span"),c=document.createElement("input");c.type="checkbox",c.checked=!0,c.title="Deselect all segment IDs",c.addEventListener("change",()=>{e.displayState.visibleSegments.clear()});const l=Object(Z.a)({title:"Copy visible segment IDs",onClick:()=>{const t=Array.from(e.displayState.visibleSegments,e=>e.clone());t.sort(p.a.compare),Object(J.a)(t.join(", "))}}),d=document.createElement("span");a.appendChild(l),a.appendChild(c),a.appendChild(d);const u=document.createElement("span"),h=document.createElement("input"),f=Object(Z.a)({onClick:()=>{i(),i.flush(),o.debouncedUpdate.flush();const{matches:e}=o;void 0!==e&&Object(J.a)(Array.from(e,e=>e[0]).join(", "))}});h.type="checkbox";const m=()=>{i(),i.flush(),o.debouncedUpdate.flush();const{matches:t}=o;if(void 0===t)return;const{visibleSegments:n}=e.displayState,{selectedMatches:r}=o,s=r!==t.length;if(s&&t.length-r>100){if(!y)return y=!0,g.textContent=`Confirm: show ${t.length-r} segments?`,!1;y=!1,b()}for(const[e]of t)ue.tryParseString(e),n.set(ue,s);return!0};h.addEventListener("click",e=>{m()||e.preventDefault()});const g=document.createElement("span");u.appendChild(f),u.appendChild(h),u.appendChild(g),a.classList.add("neuroglancer-segment-list-status"),u.classList.add("neuroglancer-segment-list-status"),r.appendChild(u),r.appendChild(a);let v=-1;const b=()=>{const t=e.displayState.visibleSegments.size;v!==t&&(v=t,d.textContent=`${t} visible in total`,c.checked=t>0,c.style.visibility=t?"visible":"hidden",l.style.visibility=t?"visible":"hidden"),g.textContent=o.statusText.value;const{numMatches:n,selectedMatches:i}=o;f.style.visibility=n?"visible":"hidden",f.title=`Copy ${n} segment ID(s)`,h.style.visibility=n?"visible":"hidden",0===i?(h.checked=!1,h.indeterminate=!1,h.title=`Show ${n} segment ID(s)`):i===n?(h.checked=!0,h.indeterminate=!1,h.title=`Hide ${i} segment ID(s)`):(h.checked=!0,h.indeterminate=!0,h.title=`Show ${n-i} segment ID(s)`)};b(),o.statusText.changed.add(b),s.registerDisposer(e.displayState.visibleSegments.changed.add(b));let y=!1;s.registerEventListener(n,"input",()=>{i(),y&&(y=!1,b())}),Object(X.c)(n,"cancel",()=>{n.blur(),n.value="",this.layer.segmentQuery.value="",y=!1,b()}),Object(X.c)(n,"toggle-listed",m),Object(X.c)(n,"hide-all",()=>{e.displayState.visibleSegments.clear()}),Object(X.c)(n,"hide-listed",()=>{i(),i.flush(),o.debouncedUpdate.flush();const{visibleSegments:t}=e.displayState;if(""===e.segmentQuery.value)t.clear();else{const{matches:e}=o;if(void 0===e)return;for(const[n]of e)ue.tryParseString(n),t.delete(ue)}});const S=s.registerDisposer(new de.a({source:o})),w=s.registerCancellable(Object(W.a)(()=>{o.updateRenderedItems(S)})),{displayState:x}=this.layer;s.registerDisposer(x.segmentSelectionState.changed.add(w)),s.registerDisposer(x.visibleSegments.changed.add(w)),s.registerDisposer(x.segmentColorHash.changed.add(w)),s.registerDisposer(x.segmentStatedColors.changed.add(w)),S.element.classList.add("neuroglancer-segment-list"),s.registerDisposer(e.bindSegmentListWidth(S.element)),s.registerDisposer(new K.b(S.element,Object(z.a)())),r.appendChild(S.element)})).element)}}class we extends c.a{constructor(e){super(),this.layer=e,this.codeWidget=this.registerDisposer(me(this.layer)),this.content.classList.add("neuroglancer-segmentation-layer-skeleton-shader-overlay"),this.content.appendChild(this.codeWidget.element),this.codeWidget.textEditor.refresh()}}Object(s.r)("segmentation",pe),Object(s.t)(D.b.SEGMENTATION,pe),Object(s.s)(e=>{if(void 0!==e.mesh)return pe})},function(e,t,n){"use strict";n.r(t);var i,r=n(8),s=n(61),o=n(12),a=n(5),c=n(82),l=n(34),d=n(89);!function(e){e[e.RAW=0]="RAW",e[e.JPEG=1]="JPEG",e[e.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION"}(i||(i={}));class u{}u.RPC_ID="brainmaps/VolumeChunkSource";class h{}h.RPC_ID="brainmaps/MultiscaleMeshSource";class p{}p.RPC_ID="brainmaps/MeshSource";class f{}f.RPC_ID="brainmaps/SkeletonSource";class m{}m.RPC_ID="brainmaps/Annotation";class g{}g.RPC_ID="brainmaps/AnnotationSpatialIndex";var v=n(69),b=n(50),y=n(59),S=n(26),w=n(9),x=n(25),C=n(47),O=n(7),k=n(42),E=n(1),T=n(0),M=n(45),D=n(105);n.d(t,"BrainmapsSkeletonSource",(function(){return P})),n.d(t,"VolumeInfo",(function(){return V})),n.d(t,"MultiscaleVolumeInfo",(function(){return z})),n.d(t,"MultiscaleVolumeChunkSource",(function(){return U})),n.d(t,"parseVolumeKey",(function(){return $})),n.d(t,"VolumeList",(function(){return q})),n.d(t,"parseChangeStackList",(function(){return Y})),n.d(t,"BrainmapsAnnotationSource",(function(){return K})),n.d(t,"BrainmapsDataSource",(function(){return Z})),n.d(t,"productionInstance",(function(){return ee}));
/**
 * @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 L extends(Object(o.g)(Object(c.a)()(x.c),u)){}class j extends(Object(o.g)(Object(c.a)()(b.d),h)){}class I extends(Object(o.g)(Object(c.a)()(b.b),p)){}class P extends(Object(o.g)(Object(c.a)()(y.d),f)){}class A extends(Object(o.g)(Object(c.a)()(s.a),g)){}const R=new Map;function N(e){Object(T.w)(e);try{return{corner:Object(T.y)(e,"corner",e=>Object(T.g)(E.u.create(),e,T.p)),size:Object(T.y)(e,"size",e=>Object(T.g)(E.u.create(),e,T.r)),metadata:Object(T.y)(e,"metadata",T.C)}}catch(e){throw new Error(`Failed to parse bounding box: ${e.message}`)}}R.set("UINT8",w.a.UINT8),R.set("FLOAT",w.a.FLOAT32),R.set("UINT32",w.a.UINT32),R.set("UINT64",w.a.UINT64);class V{constructor(e){try{Object(T.w)(e),this.numChannels=Object(T.y)(e,"channelCount",T.D),this.dataType=Object(T.y)(e,"channelType",e=>Object(T.v)(e,R)),this.voxelSize=Object(T.y)(e,"pixelSize",e=>Object(T.g)(E.u.create(),e,T.r)),this.upperVoxelBound=Object(T.y)(e,"volumeSize",e=>Object(T.g)(E.u.create(),e,T.D)),this.boundingBoxes=Object(T.y)(e,"boundingBox",e=>void 0===e?[]:Object(T.b)(e,N))}catch(e){throw new Error(`Failed to parse BrainMaps volume geometry: ${e.message}`)}}}function _(e){return Object(T.w)(e),{name:Object(T.y)(e,"name",T.E),type:Object(T.y)(e,"type",T.E)}}const B=new RegExp("^(.*)_([0-9]+)x([0-9]+)x([0-9]+)_lod([0-9]+)_([0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)$");function F(e,t){const n=function(e,t){const n=new Map,i=e.scales[0],r=new Set;for(const e of t){if("TRIANGLES"!==e.type)continue;const t=e.name.match(B);if(null===t)continue;const s=t[1];let o=n.get(s);void 0===o&&(o={key:s,chunkShape:E.u.create(),lods:[]},n.set(s,o));const a=parseInt(t[5]);if(void 0!==o.lods[a]){r.add(s);continue}const c=E.u.fromValues(parseInt(t[2],10),parseInt(t[3],10),parseInt(t[4],10)),l=new Uint32Array(3);for(let e=0;e<3;++e)l[e]=Math.ceil(i.upperVoxelBound[e]/c[e]);o.lods[a]={info:e,scale:parseFloat(t[6]),relativeBlockShape:c,gridShape:l}}const s=[];e:for(const e of n.values()){if(r.has(e.key))continue e;const t=e.lods[0];if(void 0===t)continue e;const n=t.relativeBlockShape;E.u.multiply(e.chunkShape,n,i.voxelSize);for(let t=1;t<e.lods.length;++t){const i=e.lods[t];if(void 0===i)continue e;const{relativeBlockShape:r}=i;for(let e=0;e<3;++e){const t=r[e],i=n[e];if(t<i||t%i!=0)continue e;r[e]=t/i}}n.fill(1),s.push(e)}return s}(e,t),i=[],r=e=>{i.some(t=>t.name===e.name)||i.push(e)},s=new Set;for(const e of n){r({multi:e,single:void 0,name:e.key,partOfMultiscale:!1});for(const t of e.lods)s.add(t.info)}for(const e of t)r({single:e,multi:void 0,name:e.name,partOfMultiscale:s.has(e)});return i}class z{constructor(e){try{Object(T.w)(e);let t=this.scales=Object(T.y)(e,"geometry",e=>Object(T.b)(e,e=>new V(e)));if(0===t.length)throw new Error("Expected at least one scale.");let n=t[0],i=this.numChannels=n.numChannels,r=this.dataType=n.dataType;for(let e=1,n=t.length;e<n;++e){let n=t[e];if(n.dataType!==r)throw new Error(`Scale ${e} has data type ${w.a[n.dataType]} `+`but scale 0 has data type ${w.a[r]}.`);if(n.numChannels!==i)throw new Error(`Scale ${e} has ${n.numChannels} channel(s) `+`but scale 0 has ${i} channels.`)}this.box={lowerBounds:new Float64Array(3),upperBounds:new Float64Array(n.upperVoxelBound)}}catch(e){throw new Error(`Failed to parse BrainMaps multiscale volume specification: ${e.message}`)}}getModelSpace(e=!1){const t=this.scales[0],n=["x","y","z"],i=["m","m","m"],r=Array.from(t.voxelSize,e=>e/1e9),s=[0,0,0],o=Array.from(t.upperVoxelBound);return e&&(n.push("c^"),i.push(""),r.push(1),s.push(0),o.push(this.numChannels)),Object(a.y)({names:n,units:i,scales:Float64Array.from(r),boundingBoxes:[Object(a.A)({lowerBounds:new Float64Array(n.length),upperBounds:Float64Array.from(o)})]})}}class U extends x.a{constructor(e,t,n,i,r,s,o){super(e),this.instance=t,this.credentialsProvider=n,this.volumeId=i,this.changeSpec=r,this.multiscaleVolumeInfo=s,this.encoding=o.encoding,this.chunkLayoutPreference=o.chunkLayoutPreference;let a=w.b.IMAGE;this.dataType===w.a.UINT64&&(a=w.b.SEGMENTATION),this.volumeType=a}get scales(){return this.multiscaleVolumeInfo.scales}get dataType(){return this.multiscaleVolumeInfo.dataType}get rank(){return 1!==this.multiscaleVolumeInfo.numChannels?4:3}getSources(e){let t=i.RAW;this.dataType===w.a.UINT64&&this.volumeType===w.b.SEGMENTATION?t=i.COMPRESSED_SEGMENTATION:this.volumeType===w.b.IMAGE&&this.dataType===w.a.UINT8&&1===this.multiscaleVolumeInfo.numChannels&&this.encoding!==i.RAW&&!0!==e.discreteValues&&(t=i.JPEG);const n=this.scales[0],{upperVoxelBound:r}=n,s=E.u.create(),{rank:o}=this;return Object(O.m)(this.scales.map((i,a)=>{E.u.divide(s,i.voxelSize,n.voxelSize);let c,l=i.upperVoxelBound,{numChannels:d}=i;const u=new Float32Array((o+1)**2);u[(o+1)*o+o]=1;const h=new Float32Array(o);1!==d&&(l=Float32Array.of(...l,d),c=Uint32Array.of(1,1,1,d),u[3*(o+1)+3]=1,h[3]=d);for(let e=0;e<3;++e)u[(o+1)*e+e]=s[e],h[e]=r[e]/s[e];return Object(w.c)({rank:o,minBlockSize:c,chunkToMultiscaleTransform:u,dataType:i.dataType,upperVoxelBound:l,volumeType:this.volumeType,volumeSourceOptions:e,chunkLayoutPreference:this.chunkLayoutPreference,maxCompressedSegmentationBlockSize:E.u.fromValues(64,64,64)}).map(e=>({chunkSource:this.chunkManager.getChunkSource(L,{credentialsProvider:this.credentialsProvider,spec:e,parameters:{volumeId:this.volumeId,changeSpec:this.changeSpec,scaleIndex:a,encoding:t,instance:this.instance}}),chunkToMultiscaleTransform:u,upperClipBound:h}))}))}}function G(e){const t=E.m.create(),n=e.scales[0].voxelSize;for(let e=0;e<3;++e)t[5*e]=1/n[e];return t}function $(e){const t=e.match(/^([^:?\/]+:[^:?\/]+:[^:?\/]+)(?::([^:?\/]+))?(?:\/([^?]+))?(?:\?(.*))?$/);if(null===t)throw new Error(`Invalid Brain Maps volume key: ${JSON.stringify(e)}.`);let n;void 0!==t[2]&&(n={changeStackId:t[2]});const i=Object(T.f)(t[4]||"");return{volumeId:t[1],changeSpec:n,meshName:t[3],parameters:i}}function W(e){try{return Object(T.w)(e),{id:Object(T.y)(e,"id",T.E),label:Object(T.y)(e,"label",T.E),description:Object(T.y)(e,"description",T.C)}}catch(e){throw new Error(`Failed to parse project: ${e.message}`)}}function H(e){try{return Object(T.w)(e),Object(T.y)(e,"project",e=>void 0===e?[]:Object(T.b)(e,W))}catch(e){throw new Error(`Error parsing project list: ${e.message}`)}}function J(e,t){try{return Object(T.w)(e),Object(T.y)(e,t,e=>void 0===e?[]:Object(T.b)(e,T.E))}catch(e){throw new Error(`Error parsing dataset list: ${e.message}`)}}class q{constructor(e,t){this.projects=new Map,this.hierarchicalVolumeIds=new Map;const{projects:n}=this;for(let t of H(e))n.set(t.id,t);try{Object(T.w)(t);let e=this.volumeIds=Object(T.y)(t,"volumeId",e=>void 0===e?[]:Object(T.b)(e,T.E));e.sort();let n=new Map;for(let t of e){let e=0;for(;;){let i=t.indexOf(":",e);-1===i?i=void 0:++i;let r=t.substring(0,e),s=n.get(r);if(void 0===s&&(s=new Set,n.set(r,s)),s.add(t.substring(e,i)),void 0===i)break;e=i}}let{hierarchicalVolumeIds:i}=this;for(let[e,t]of n)i.set(e,Array.from(t))}catch(e){throw new Error(`Failed to parse Brain Maps volume list reply: ${e.message}`)}}}function Y(e){return Object(T.y)(e,"changeStackId",e=>void 0===e?void 0:Object(T.b)(e,T.E))}const X=Object(o.g)(Object(c.a)()(s.b),m);class K extends X{constructor(e,t){super(e,Object.assign({rank:3,relationships:["segments"],properties:[]},t)),this.credentialsProvider=this.registerDisposer(t.credentialsProvider.addRef())}getSources(){const{upperVoxelBound:e}=this.parameters,t=Object(S.p)({rank:3,chunkDataSize:e,upperVoxelBound:e}),n=E.m.create();return[[{chunkSource:this.chunkManager.getChunkSource(A,{parent:this,spec:Object.assign({limit:0,chunkToMultiscaleTransform:n},t),parameters:this.parameters,credentialsProvider:this.credentialsProvider}),chunkToMultiscaleTransform:n}]]}}const Q=[{key:{value:"encoding",description:"Volume chunk data encoding"},values:[{value:"raw",description:""},{value:"jpeg",description:""},{value:"compressed_segmentation",description:""}]},{key:{value:"chunkLayout",description:"Volume chunk layout preference"},values:[{value:"isotropic",description:""},{value:"flat",description:""}]}];class Z extends l.a{constructor(e,t){super(),this.instance=e,this.credentialsProvider=t}get description(){return this.instance.description}getMultiscaleInfo(e,t){return e.memoize.getUncounted({type:"brainmaps:getMultiscaleInfo",volumeId:t,instance:this.instance,credentialsProvider:Object(M.a)(this.credentialsProvider)},()=>Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:`/v1beta2/volumes/${t}`,responseType:"json"}).then(e=>new z(e)))}getMeshesInfo(e,t){return e.memoize.getUncounted({type:"brainmaps:getMeshesInfo",volumeId:t,instance:this.instance,credentialsProvider:Object(M.a)(this.credentialsProvider)},()=>Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:`/v1beta2/objects/${t}/meshes`,responseType:"json"}).then(e=>function(e){try{return Object(T.w)(e),Object(T.y)(e,"meshes",e=>void 0===e?[]:Object(T.b)(e,_))}catch(e){throw new Error(`Failed to parse BrainMaps meshes specification: ${e.message}`)}}(e)))}get(e){const{volumeId:t,changeSpec:n,meshName:s,parameters:o}=$(e.providerUrl);Object(T.w)(o);const c=Object(T.B)(o,"encoding",e=>Object(T.o)(e,i)),l=Object(T.B)(o,"chunkLayout",e=>Object(T.o)(e,S.a)),d=Object.assign(Object.assign({},e),{encoding:c,chunkLayoutPreference:l});return e.chunkManager.memoize.getUncounted({type:"brainmaps:get",instance:this.instance,volumeId:t,changeSpec:n,brainmapsOptions:d},async()=>{const[i,o]=await Promise.all([this.getMultiscaleInfo(e.chunkManager,t),this.getMeshesInfo(e.chunkManager,t)]),c=new U(e.chunkManager,this.instance,this.credentialsProvider,t,n,i,d),l={modelTransform:Object(a.z)(i.getModelSpace(1!==i.numChannels)),subsources:[{id:void 0===s?"default":"volume",subsource:{volume:c},default:void 0===s}]},u=Object(r.n)(i.box);i.scales[0].boundingBoxes.forEach((e,t)=>{u.add({type:r.e.AXIS_ALIGNED_BOUNDING_BOX,description:e.metadata,pointA:e.corner,pointB:E.u.add(E.u.create(),e.corner,e.size),id:`boundingBox${t}`,properties:[]})}),l.subsources.push({id:"bounds",subsource:{staticAnnotations:u},default:!0});const h=F(i,o),p=(r,o)=>{let a;const{single:c}=r;if(void 0!==c)a="TRIANGLES"===c.type?e.chunkManager.getChunkSource(I,{credentialsProvider:this.credentialsProvider,parameters:{instance:this.instance,volumeId:t,meshName:c.name,changeSpec:n}}):e.chunkManager.getChunkSource(P,{credentialsProvider:this.credentialsProvider,parameters:{instance:this.instance,volumeId:t,meshName:r.name,changeSpec:n}});else{const i=r.multi;a=e.chunkManager.getChunkSource(j,{credentialsProvider:this.credentialsProvider,format:{fragmentRelativeVertices:!1,vertexPositionFormat:v.e.float32},parameters:{instance:this.instance,volumeId:t,info:i,changeSpec:n}})}l.subsources.push({id:void 0===s?`/${r.name}`:"default",subsource:{mesh:a},subsourceToModelSubspaceTransform:G(i),modelSubspaceDimensionIndices:[0,1,2],default:o})};if(void 0!==s){const e=h.find(e=>e.name===s);if(void 0===e)throw new Error(`Mesh/skeleton source not found: ${JSON.stringify(e)}`);p(e,!0)}else{let e=!0;for(const t of h)t.partOfMultiscale||(p(t,e),e=!1)}return void 0!==n&&l.subsources.push({id:"spatials",default:!0,subsource:{annotation:e.chunkManager.getChunkSource(K,{parameters:{volumeId:t,changestack:n.changeStackId,instance:this.instance,upperVoxelBound:i.scales[0].upperVoxelBound},credentialsProvider:this.credentialsProvider})}}),l})}getProjectList(e){return e.memoize.getUncounted({instance:this.instance,type:"brainmaps:getProjectList"},()=>{let e=Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:"/v1beta2/projects",responseType:"json"}).then(e=>H(e));const t=`${this.instance.description} project list`;return C.a.forPromise(e,{delay:!0,initialMessage:`Retrieving ${t}.`,errorPrefix:`Error retrieving ${t}: `}),e})}getDatasetList(e,t){return e.memoize.getUncounted({instance:this.instance,type:`brainmaps:${t}:getDatasetList`},()=>{let e=Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:`/v1beta2/datasets?project_id=${t}`,responseType:"json"}).then(e=>J(e,"datasetIds"));const n=`${this.instance.description} dataset list`;return C.a.forPromise(e,{delay:!0,initialMessage:`Retrieving ${n}`,errorPrefix:`Error retrieving ${n}`}),e})}getVolumeList(e,t,n){return e.memoize.getUncounted({instance:this.instance,type:`brainmaps:${t}:${n}:getVolumeList`},()=>{let e=Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:`/v1beta2/volumes?project_id=${t}&dataset_id=${n}`,responseType:"json"}).then(e=>{const i=J(e,"volumeId"),r=t.length+n.length+2,s=[];for(const e of i)s.push(e.substring(r));return s});const i=`${this.instance.description} volume list`;return C.a.forPromise(e,{delay:!0,initialMessage:`Retrieving ${i}`,errorPrefix:`Error retrieving ${i}`}),e})}getChangeStackList(e,t){return e.memoize.getUncounted({instance:this.instance,type:"brainmaps:getChangeStackList",volumeId:t},()=>{let e=Object(d.b)(this.instance,this.credentialsProvider,{method:"GET",path:`/v1beta2/changes/${t}/change_stacks`,responseType:"json"}).then(e=>Y(e));const n=`change stacks for ${t}`;return C.a.forPromise(e,{delay:!0,initialMessage:`Retrieving ${n}.`,errorPrefix:`Error retrieving ${n}: `}),e})}async completeUrl(e){const{providerUrl:t}=e,n=t.match(/^([^:\/?]*)(?::([^:\/?]*)(?::([^:\/?]*)(?::([^:\/?]*))?(?:\/([^?]*))?(?:\?(.*))?)?)?$/);if(null===n)throw null;const[,i,r,s,o,a,c]=n;if(void 0!==c)return Object(k.a)(t.length-c.length,await Object(k.b)(c,Q));if(void 0!==a){const n=`${i}:${r}:${s}`,o=await this.getMeshesInfo(e.chunkManager,n),c=[],l=new Set;for(const e of o)if(e.name.startsWith(a))switch(e.type){case"LINE_SEGMENTS":c.push({value:e.name,description:"Skeletons"});break;case"TRIANGLES":{c.push({value:e.name,description:"Mesh (single-resolution)"});const t=e.name.match(B);if(null!==t){const e=t[1];if(l.has(e))break;l.add(e),c.push({value:e,description:"Mesh (multi-resolution)"})}break}}return c.sort((e,t)=>Object(D.a)(e.value,t.value)),{offset:t.length-a.length,completions:c}}if(void 0!==o){const n=`${i}:${r}:${s}`,a=await this.getChangeStackList(e.chunkManager,n);if(void 0===a)throw null;return{offset:t.length-o.length,completions:Object(k.c)(o,a)}}if(void 0!==s)return{offset:t.length-s.length,completions:Object(k.c)(s,await this.getVolumeList(e.chunkManager,i,r))};if(void 0!==r){const n=await this.getDatasetList(e.chunkManager,i);return{offset:t.length-r.length,completions:Object(k.c)(r,n.map(e=>`${e}:`))}}const l=await this.getProjectList(e.chunkManager);return{offset:0,completions:Object(k.d)(i,l,e=>`${e.id}:`,e=>e.label)}}}const ee={description:"Google Brain Maps",serverUrl:"https://brainmaps.googleapis.com"}},function(e,t){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},function(e,t,n){"use strict";(function(t){var i=n(64).EventEmitter,r=n(33),s=n(90),o=n(122),a=n(73);function c(e,t,n){var r=this;i.call(this),setTimeout((function(){r._start(e,t,n)}),0)}r(c,i),c.prototype._start=function(e,n,i){var r=this,o=new t.XDomainRequest;n=a.addQuery(n,"t="+ +new Date),o.onerror=function(){r._error()},o.ontimeout=function(){r._error()},o.onprogress=function(){o.responseText,r.emit("chunk",200,o.responseText)},o.onload=function(){r.emit("finish",200,o.responseText),r._cleanup(!1)},this.xdr=o,this.unloadRef=s.unloadAdd((function(){r._cleanup(!0)}));try{this.xdr.open(e,n),this.timeout&&(this.xdr.timeout=this.timeout),this.xdr.send(i)}catch(e){this._error()}},c.prototype._error=function(){this.emit("finish",0,""),this._cleanup(!1)},c.prototype._cleanup=function(e){if(this.xdr){if(this.removeAllListeners(),s.unloadDel(this.unloadRef),this.xdr.ontimeout=this.xdr.onerror=this.xdr.onprogress=this.xdr.onload=null,e)try{this.xdr.abort()}catch(e){}this.unloadRef=this.xdr=null}},c.prototype.close=function(){this._cleanup(!0)},c.enabled=!(!t.XDomainRequest||!o.hasDomain()),e.exports=c}).call(this,n(46))},function(e,t,n){"use strict";(function(t){var i=n(33),r=n(167),s=n(145);e.exports=function(e){function n(t,n){r.call(this,e.transportName,t,n)}return i(n,r),n.enabled=function(n,i){if(!t.document)return!1;var o=s.extend({},i);return o.sameOrigin=!0,e.enabled(o)&&r.enabled()},n.transportName="iframe-"+e.transportName,n.needBody=!0,n.roundTrips=r.roundTrips+e.roundTrips-1,n.facadeTransport=e,n}}).call(this,n(46))},function(e,t,n){"use strict";e.exports={isObject:function(e){var t=typeof e;return"function"===t||"object"===t&&!!e},extend:function(e){if(!this.isObject(e))return e;for(var t,n,i=1,r=arguments.length;i<r;i++)for(n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}}},function(e,t,n){"use strict";function i(e){this.type=e}i.prototype.initEvent=function(e,t,n){return this.type=e,this.bubbles=t,this.cancelable=n,this.timeStamp=+new Date,this},i.prototype.stopPropagation=function(){},i.prototype.preventDefault=function(){},i.CAPTURING_PHASE=1,i.AT_TARGET=2,i.BUBBLING_PHASE=3,e.exports=i},function(e,t,n){"use strict";n.r(t),n.d(t,"VtkDataSource",(function(){return a}));var i=n(5),r=n(34),s=n(109),o=n(99);
/**
 * @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 a extends r.a{get description(){return"VTK mesh file"}async get(e){const t=await Object(s.d)(e.chunkManager,{meshSourceUrl:e.url,attributeSourceUrls:[]}),n=Object(i.y)({rank:3,names:["x","y","z"],units:["m","m","m"],scales:Float64Array.of(1e-9,1e-9,1e-9)});return{modelTransform:Object(i.z)(n),subsources:[{id:"default",default:!0,subsource:{singleMesh:t}}]}}completeUrl(e){return Object(o.a)(e.providerUrl,e.cancellationToken)}}},function(e,t,n){"use strict";n.r(t);var i=n(8),r=n(12),s=n(5),o=n(82),a=n(34),c=n(133),l=n(39);function d(e,t,n,i,r=l.e){return Object(c.a)(e,t,n,i,e=>{const t=new Headers(n.headers);return t.set("Authorization",`Bearer ${e}`),Object.assign(Object.assign({},n),{headers:t})},e=>{const{status:t}=e;if(403===t||401===t)return"refresh";if(504===t)return"retry";throw e},r)}
/**
 * @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 u extends class{}{static stringify(e){return`boss:volume:${e.baseUrl}/${e.collection}/${e.experiment}/${e.channel}/${e.resolution}/${e.encoding}`}}u.RPC_ID="boss/VolumeChunkSource";class h{static stringify(e){return`boss:mesh:${e.baseUrl}`}}h.RPC_ID="boss/MeshChunkSource";var p=n(50),f=n(9),m=n(25),g=n(7),v=n(42),b=n(1),y=n(22),S=n(0);n.d(t,"BossMultiscaleVolumeChunkSource",(function(){return L})),n.d(t,"getExperimentInfo",(function(){return I})),n.d(t,"getChannelInfo",(function(){return P})),n.d(t,"getDownsampleInfoForChannel",(function(){return A})),n.d(t,"parseDownsampleScales",(function(){return R})),n.d(t,"parseDownsampleInfoForChannel",(function(){return N})),n.d(t,"getDataSource",(function(){return V})),n.d(t,"getCollections",(function(){return B})),n.d(t,"getExperiments",(function(){return F})),n.d(t,"getCoordinateFrame",(function(){return z})),n.d(t,"collectionExperimentChannelCompleter",(function(){return U})),n.d(t,"BossDataSource",(function(){return G}));
/**
 * @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 w extends(Object(r.g)(Object(o.a)()(m.c),u)){}class x extends(Object(r.g)(Object(o.a)()(p.b),h)){}let C=new Map;C.set("image",f.b.IMAGE),C.set("annotation",f.b.SEGMENTATION);const O=new Set(["npz","jpeg"]),k=Uint32Array.of(512,512,16);var E;function T(e,t){Object(S.w)(e);const n=Object(S.y)(e,"voxel_unit",e=>Object(S.o)(e,E)),i=function(e){switch(e){case E.MICROMETERS:return 1e6;case E.MILLIMETERS:return 1e3;case E.CENTIMETERS:return 100;case E.NANOMETERS:return 1e9}}(n),r=new Float32Array(3),s=new Float64Array(3),o=new Float64Array(3),a=new Float64Array(3),c=["x","y","z"];for(let t=0;t<3;++t){const n=c[t];r[t]=Object(S.y)(e,`${n}_voxel_size`,S.r),s[t]=r[t]/i,o[t]=Object(S.y)(e,`${n}_start`,S.u),a[t]=Object(S.y)(e,`${n}_stop`,S.u)}return t.coordFrame={voxelSizeBaseInMeters:s,voxelSizeBaseInOriginalUnits:r,voxelOffsetBase:o,imageSizeBase:a,voxelUnit:n,names:c},t}function M(e){let t=C.get(e);return void 0===t&&(t=f.b.UNKNOWN),t}function D(e){Object(S.w)(e);let t=Object(S.y)(e,"type",S.E),n=!1;return"DOWNSAMPLED"===Object(S.y)(e,"downsample_status",S.E)&&(n=!0),{channelType:t,description:Object(S.y)(e,"description",S.E),volumeType:M(t),dataType:Object(S.y)(e,"datatype",e=>Object(S.o)(e,f.a)),downsampled:n,scales:[],key:Object(S.y)(e,"name",S.E)}}!function(e){e[e.NANOMETERS=0]="NANOMETERS",e[e.MICROMETERS=1]="MICROMETERS",e[e.MILLIMETERS=2]="MILLIMETERS",e[e.CENTIMETERS=3]="CENTIMETERS"}(E||(E={}));class L extends m.a{constructor(e,t,n,i,r,s){if(super(e),this.baseUrl=t,this.credentialsProvider=n,this.experimentInfo=i,this.parameters=s,this.meshPath=void 0,this.meshUrl=void 0,void 0===r){const e=Array.from(i.channels.keys());if(1!==e.length)throw new Error(`Experiment contains multiple channels: ${JSON.stringify(e)}`);r=e[0]}const o=i.channels.get(r);if(void 0===o)throw new Error(`Specified channel ${JSON.stringify(r)} is not one of the supported channels ${JSON.stringify(Array.from(i.channels.keys()))}`);if(this.channel=r,this.channelInfo=o,this.scales=o.scales,void 0===i.coordFrame)throw new Error(`Specified experiment ${JSON.stringify(i.key)} does not have a valid coordinate frame`);this.coordinateFrame=i.coordFrame,!1===this.channelInfo.downsampled&&(this.scales=[o.scales[0]]),this.experiment=i.key;let a=Object(S.C)(s.window);if(void 0!==a){let e=b.t.create(),t=a.split(/,/);if(2===t.length)e[0]=Object(S.p)(t[0]),e[1]=Object(S.p)(t[1]);else{if(1!==t.length)throw new Error(`Invalid window. Must be either one value or two comma separated values: ${JSON.stringify(a)}`);e[0]=0,e[1]=Object(S.p)(t[1])}if(this.window=e,this.window[0]===this.window[1])throw new Error(`Invalid window. First element must be different from second: ${JSON.stringify(a)}.`)}let c=Object(S.C)(s.meshurl);void 0!==c&&(this.meshUrl=c);let l=Object(S.C)(s.encoding);if(void 0===l)l=this.volumeType===f.b.IMAGE?"jpeg":"npz";else if(!O.has(l))throw new Error(`Invalid encoding: ${JSON.stringify(l)}.`);this.encoding=l}get dataType(){return this.channelInfo.dataType===f.a.UINT16?f.a.UINT8:this.channelInfo.dataType}get volumeType(){return this.channelInfo.volumeType}get rank(){return 3}getSources(e){return Object(g.m)(this.scales.map(t=>{let{downsampleFactors:n,imageSize:i}=t,r=this.coordinateFrame.voxelOffsetBase,s=b.u.create();for(let e=0;e<3;++e)s[e]=Math.ceil(r[e]);const o=b.m.create();for(let e=0;e<3;++e)o[5*e]=n[e],o[12+e]=r[e];return Object(f.c)({rank:3,volumeType:this.volumeType,dataType:this.dataType,chunkToMultiscaleTransform:o,chunkDataSizes:[k],baseVoxelOffset:s,upperVoxelBound:i,volumeSourceOptions:e}).map(e=>({chunkSource:this.chunkManager.getChunkSource(w,{credentialsProvider:this.credentialsProvider,spec:e,parameters:{baseUrl:this.baseUrl,collection:this.experimentInfo.collection,experiment:this.experimentInfo.key,channel:this.channel,resolution:t.key,encoding:this.encoding,window:this.window}}),chunkToMultiscaleTransform:o}))}))}getMeshSource(){return void 0!==this.meshUrl?this.chunkManager.getChunkSource(x,{credentialsProvider:this.credentialsProvider,parameters:{baseUrl:this.meshUrl}}):null}}const j=/^([^\/?]+)\/([^\/?]+)(?:\/([^\/?]+))?(?:\?(.*))?$/;function I(e,t,n,i,r){return e.memoize.getUncounted({hostname:t,collection:r,experiment:i,type:"boss:getExperimentInfo"},()=>d(n,`${t}/latest/collection/${r}/experiment/${i}/`,{},y.g).then(s=>function(e,t,n,i,r,s){Object(S.w)(e);let o=Object(S.y)(e,"channels",e=>Object(S.b)(e,e=>P(t,n,i,s,r,e)));return Promise.all(o).then(r=>{let s=new Map;r.forEach(e=>{s.set(e.key,e)});let o={channels:s,scalingLevels:Object(S.y)(e,"num_hierarchy_levels",S.u),coordFrameKey:Object(S.y)(e,"coord_frame",S.E),coordFrame:void 0,key:Object(S.y)(e,"name",S.E),collection:Object(S.y)(e,"collection",S.E)};return z(t,n,i,o)})}(s,e,t,n,r,i)))}function P(e,t,n,i,r,s){return e.memoize.getUncounted({hostname:t,collection:r,experiment:i,channel:s,type:"boss:getChannelInfo"},()=>d(n,`${t}/latest/collection/${r}/experiment/${i}/channel/${s}/`,{},y.g).then(D))}function A(e,t,n,i,r,s){return e.memoize.getUncounted({hostname:t,collection:i,experiment:r.key,channel:s,downsample:!0,type:"boss:getDownsampleInfoForChannel"},()=>d(n,`${t}/latest/downsample/${i}/${r.key}/${s}/`,{},y.g)).then(e=>N(e,r,s))}function R(e,t){Object(S.w)(e);let n=Object(S.y)(e,"voxel_size",e=>Object(S.x)(e,S.l)),i=Object(S.y)(e,"extent",e=>Object(S.x)(e,S.k)),r=Object(S.y)(e,"num_hierarchy_levels",S.u),s=new Array;for(let e=0;e<r;e++){let r=String(e);const o=n.get(r),a=i.get(r);if(void 0===o||void 0===a)throw new Error(`Missing voxel_size/extent for resolution ${r}.`);const c=new Float32Array(3);for(let e=0;e<3;++e)c[e]=o[e]=t[e];s[e]={downsampleFactors:c,imageSize:a,key:r}}return s}function N(e,t,n){let i=t.coordFrame;if(void 0===i)throw new Error(`Missing coordinate frame information for experiment ${t.key}. A valid coordinate frame is required to retrieve downsampling information.`);let r=t.channels.get(n);if(void 0===r)throw new Error(`Specified channel ${JSON.stringify(n)} is not one of the supported channels ${JSON.stringify(Array.from(t.channels.keys()))}`);return r.scales=R(e,i.voxelSizeBaseInOriginalUnits),t.channels.set(n,r),t}function V(e,t,n,r){const o=r.match(j);if(null===o)throw new Error(`Invalid volume path ${JSON.stringify(r)}`);const a=o[1],c=o[2],l=o[3],d=Object(S.f)(o[4]||"");return e.memoize.getUncounted({hostname:t,path:r,type:"boss:getVolume"},async()=>{const r=await I(e,t,n,c,a),o=await A(e,t,n,a,r,l),u=new L(e,t,n,o,l,d),h=o.coordFrame,p={lowerBounds:h.voxelOffsetBase,upperBounds:Float64Array.from(h.imageSizeBase,(e,t)=>h.voxelOffsetBase[t]+e)},f=Object(s.y)({rank:3,names:h.names,units:["m","m","m"],scales:h.voxelSizeBaseInMeters,boundingBoxes:[Object(s.A)(p)]});return{modelTransform:Object(s.z)(f),subsources:[{id:"default",default:!0,subsource:{volume:u}},{id:"bounds",default:!0,subsource:{staticAnnotations:Object(i.n)(p)}}]}})}const _=/^((?:http|https):\/\/[^\/?]+)\/(.*)$/;function B(e,t,n){return e.memoize.getUncounted({hostname:t,type:"boss:getCollections"},()=>d(n,`${t}/latest/collection/`,{},y.g).then(e=>Object(S.y)(e,"collections",e=>Object(S.b)(e,S.E))))}function F(e,t,n,i){return e.memoize.getUncounted({hostname:t,collection:i,type:"boss:getExperiments"},()=>d(n,`${t}/latest/collection/${i}/experiment/`,{},y.g).then(e=>Object(S.y)(e,"experiments",e=>Object(S.b)(e,S.E))))}function z(e,t,n,i){let r=i.coordFrameKey;return e.memoize.getUncounted({hostname:t,coordinateframe:r,experimentInfo:i,type:"boss:getCoordinateFrame"},()=>d(n,`${t}/latest/coord/${r}/`,{},y.g).then(e=>T(e,i)))}function U(e,t,n,i){let r=i.match(/^(?:([^\/]+)(?:\/?([^\/]*)(?:\/?([^\/]*)(?:\/?([^\/]*)?))?)?)?$/);if(null===r)return Promise.reject(null);if(void 0===r[1])return Promise.reject(null);if(void 0===r[2]){let i=r[1]||"";return B(e,t,n).then(e=>({offset:0,completions:Object(v.d)(i,e,e=>e+"/",()=>{})}))}if(void 0===r[3]){let i=r[2]||"";return F(e,t,n,r[1]).then(e=>({offset:r[1].length+1,completions:Object(v.d)(i,e,e=>e+"/",()=>{})}))}return I(e,t,n,r[2],r[1]).then(e=>{let t=Object(v.d)(r[3],e.channels,e=>e[0],e=>`${e[1].channelType} (${f.a[e[1].dataType]})`);return{offset:r[1].length+r[2].length+2,completions:t}})}class G extends a.a{constructor(e){super(),this.credentialsManager=e}get description(){return"bossDB: Block & Object Storage System"}getCredentialsProvider(e){let t=function(e){let t=e.match(/^(?:https:\/\/[^.]+([^\/]+))/);if(null===t)throw new Error(`Unable to construct auth server hostname from base hostname ${e}.`);return`https://auth${t[1]}/auth`}(e);return this.credentialsManager.getCredentialsProvider("boss",t)}get(e){const t=e.providerUrl.match(_);if(null===t)throw new Error(`Invalid boss volume path: ${JSON.stringify(e.providerUrl)}`);let n=this.getCredentialsProvider(e.providerUrl);return V(e.chunkManager,t[1],n,t[2])}async completeUrl(e){const t=e.providerUrl.match(_);if(null===t)throw null;let n=t[1],i=this.getCredentialsProvider(t[1]),r=t[2];const s=await U(e.chunkManager,n,i,r);return Object(v.a)(t[1].length+1,s)}}},function(e,t,n){"use strict";n.r(t);var i,r=n(8),s=n(12),o=n(5),a=n(34);!function(e){e[e.JPEG=0]="JPEG",e[e.RAW=1]="RAW",e[e.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION",e[e.COMPRESSED_SEGMENTATIONARRAY=3]="COMPRESSED_SEGMENTATIONARRAY"}(i||(i={}));class c{}class l extends c{}l.RPC_ID="dvid/VolumeChunkSource";class d extends c{}d.RPC_ID="dvid/SkeletonSource";class u extends c{}u.RPC_ID="dvid/MeshSource";var h=n(50),p=n(59),f=n(9),m=n(25),g=n(47),v=n(7),b=n(42),y=n(1),S=n(22),w=n(0);n.d(t,"DataInstanceBaseInfo",(function(){return C})),n.d(t,"DataInstanceInfo",(function(){return O})),n.d(t,"VolumeDataInstanceInfo",(function(){return M})),n.d(t,"parseDataInstance",(function(){return D})),n.d(t,"RepositoryInfo",(function(){return L})),n.d(t,"parseRepositoriesInfo",(function(){return j})),n.d(t,"ServerInfo",(function(){return I})),n.d(t,"getServerInfo",(function(){return P})),n.d(t,"getDataSource",(function(){return N})),n.d(t,"completeInstanceName",(function(){return V})),n.d(t,"completeNodeAndInstance",(function(){return _})),n.d(t,"completeUrl",(function(){return B})),n.d(t,"DVIDDataSource",(function(){return F}));
/**
 * @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 x=new Map;x.set("uint8",f.a.UINT8),x.set("uint32",f.a.UINT32),x.set("uint64",f.a.UINT64);class C{constructor(e){this.obj=e,Object(w.w)(e),Object(w.y)(e,"TypeName",w.E)}get typeName(){return this.obj.TypeName}get compressionName(){return this.obj.Compression}}class O{constructor(e,t,n){this.obj=e,this.name=t,this.base=n}}class k extends(Object(s.g)(m.c,l)){}class E extends(Object(s.g)(p.d,d)){}class T extends(Object(s.g)(h.b,u)){}class M extends O{constructor(e,t,n,r,s){super(e,t,n),this.encoding=r;let o=Object(w.y)(e,"Extended",w.w),a=Object(w.y)(o,"Values",e=>Object(w.b)(e,w.w));if(a.length<1)throw new Error("Expected Extended.Values property to have length >= 1, but received: ${JSON.stringify(extendedValues)}.");this.numLevels=1;let c=new Set(s);if(r===i.COMPRESSED_SEGMENTATIONARRAY){let e=Object(w.y)(o,"MaxDownresLevel",w.D);this.numLevels=e+1}else for(;c.has(t+"_"+this.numLevels.toString());)this.numLevels+=1;c.has(t+"_meshes")?this.meshSrc=t+"_meshes":this.meshSrc="",c.has(t+"_skeletons")?this.skeletonSrc=t+"_skeletons":this.skeletonSrc="",this.dataType=Object(w.y)(a[0],"DataType",e=>Object(w.v)(e,x)),this.voxelSize=Object(w.y)(o,"VoxelSize",e=>Object(w.d)(y.u.create(),e,w.r)),this.blockSize=Object(w.y)(o,"BlockSize",e=>Object(w.d)(y.u.create(),e,w.r)),this.lowerVoxelBound=Object(w.y)(o,"MinPoint",e=>Object(w.e)(y.u.create(),e)),this.upperVoxelBoundInclusive=Object(w.y)(o,"MaxPoint",e=>Object(w.e)(y.u.create(),e))}get volumeType(){return this.encoding===i.COMPRESSED_SEGMENTATION||this.encoding===i.COMPRESSED_SEGMENTATIONARRAY?f.b.SEGMENTATION:f.b.IMAGE}getSources(e,t,n){let{encoding:r}=this,s=[];for(let o=0;o<this.numLevels;++o){const a=Math.pow(2,o),c=Math.pow(2,-o);let l=y.u.create(),d=y.u.create();for(let e=0;e<3;++e){let t=Math.floor(this.lowerVoxelBound[e]*c);l[e]=t-t%64;let n=Math.ceil((this.upperVoxelBoundInclusive[e]+1)*c);d[e]=n,n%64!=0&&(d[e]+=64-n%64)}let u=t.dataInstanceKey;r!==i.COMPRESSED_SEGMENTATIONARRAY&&o>0&&(u+="_"+o.toString());let h={baseUrl:t.baseUrl,nodeKey:t.nodeKey,dataInstanceKey:u,dataScale:o.toString(),encoding:r};const p=y.m.create();for(let e=0;e<3;++e)p[5*e]=a,p[12+e]=l[e]*a;let m=Object(f.c)({rank:3,chunkToMultiscaleTransform:p,dataType:this.dataType,baseVoxelOffset:l,upperVoxelBound:y.u.subtract(y.u.create(),d,l),volumeType:this.volumeType,volumeSourceOptions:n,compressedSegmentationBlockSize:r===i.COMPRESSED_SEGMENTATION||r===i.COMPRESSED_SEGMENTATIONARRAY?y.u.fromValues(8,8,8):void 0}).map(t=>({chunkSource:e.getChunkSource(k,{spec:t,parameters:h}),chunkToMultiscaleTransform:p}));s.push(m)}return Object(v.m)(s)}}function D(e,t,n){Object(w.w)(e);let r=Object(w.y)(e,"Base",e=>new C(e));switch(r.typeName){case"uint8blk":case"grayscale8":let s=-1!==r.compressionName.indexOf("jpeg");return new M(e,t,r,s?i.JPEG:i.RAW,n);case"labels64":case"labelblk":return new M(e,t,r,i.COMPRESSED_SEGMENTATION,n);case"labelarray":case"labelmap":return new M(e,t,r,i.COMPRESSED_SEGMENTATIONARRAY,n);default:throw new Error(`DVID data type ${JSON.stringify(r.typeName)} is not supported.`)}}class L{constructor(e){if(this.errors=[],this.dataInstances=new Map,this.vnodes=new Set,e instanceof L)return this.alias=e.alias,this.description=e.description,this.errors=e.errors,void(this.dataInstances=e.dataInstances);Object(w.w)(e),this.alias=Object(w.y)(e,"Alias",w.E),this.description=Object(w.y)(e,"Description",w.E);let t=Object(w.y)(e,"DataInstances",w.w),n=Object.keys(t);for(let e of n)try{this.dataInstances.set(e,D(t[e],e,n))}catch(t){let n=`Failed to parse data instance ${JSON.stringify(e)}: ${t.message}`;console.log(n),this.errors.push(n)}let i=Object(w.y)(e,"DAG",w.w),r=Object(w.y)(i,"Nodes",w.w);for(let e of Object.keys(r))this.vnodes.add(e)}}function j(e){try{let t=Object(w.x)(e,e=>new L(e)),n=new Map;for(let[e,i]of t){n.set(e,i);for(let t of i.vnodes)if(t!==e){let e=new L(i);n.set(t,e)}}for(let[e,t]of n)t.uuid=e;return n}catch(e){throw new Error(`Failed to parse DVID repositories info: ${e.message}`)}}class I{constructor(e){this.repositories=j(e)}getNode(e){let t=[];for(let n of this.repositories.keys())n.startsWith(e)&&t.push(n);if(1!==t.length)throw new Error(`Node key ${JSON.stringify(e)} matches ${JSON.stringify(t)} nodes.`);return this.repositories.get(t[0])}}function P(e,t){return e.memoize.getUncounted({type:"dvid:getServerInfo",baseUrl:t},()=>{const e=Object(S.c)(`${t}/api/repos/info`).then(e=>e.json()).then(e=>new I(e)),n=`repository info for DVID server ${t}`;return g.a.forPromise(e,{initialMessage:`Retrieving ${n}.`,delay:!0,errorPrefix:`Error retrieving ${n}: `}),e})}class A extends m.a{constructor(e,t,n,i,r){super(e),this.baseUrl=t,this.nodeKey=n,this.dataInstanceKey=i,this.info=r}get dataType(){return this.info.dataType}get volumeType(){return this.info.volumeType}get rank(){return 3}getSources(e){return this.info.getSources(this.chunkManager,{baseUrl:this.baseUrl,nodeKey:this.nodeKey,dataInstanceKey:this.dataInstanceKey},e)}}const R=/^((?:http|https):\/\/[^\/]+)\/([^\/]+)\/([^\/]+)$/;function N(e){const t=function(e){let t=e.match(R);if(null===t)throw new Error(`Invalid DVID URL: ${JSON.stringify(e)}.`);return{baseUrl:t[1],nodeKey:t[2],dataInstanceKey:t[3]}}(e.providerUrl),{baseUrl:n,nodeKey:i,dataInstanceKey:s}=t;return e.chunkManager.memoize.getUncounted({type:"dvid:MultiscaleVolumeChunkSource",baseUrl:n,nodeKey:i,dataInstanceKey:s},async()=>{let a=(await P(e.chunkManager,n)).getNode(i);if(void 0===a)throw new Error(`Invalid node: ${JSON.stringify(i)}.`);const c=a.dataInstances.get(s);if(!(c instanceof M))throw new Error(`Invalid data instance ${s}.`);return function(e,t,n){const i=t.baseUrl,s=t.nodeKey,a=t.dataInstanceKey,c=n,l={lowerBounds:new Float64Array(c.lowerVoxelBound),upperBounds:Float64Array.from(c.upperVoxelBoundInclusive,e=>e+1)},d=Object(o.y)({rank:3,names:["x","y","z"],units:["m","m","m"],scales:Float64Array.from(c.voxelSize,e=>e/1e9),boundingBoxes:[Object(o.A)(l)]}),u=new A(e.chunkManager,i,s,a,c),h={modelTransform:Object(o.z)(d),subsources:[{id:"default",subsource:{volume:u},default:!0}]};if(c.meshSrc){const n=y.m.create();for(let e=0;e<3;++e)n[5*e]=1/c.voxelSize[e];h.subsources.push({id:"meshes",default:!0,subsource:{mesh:e.chunkManager.getChunkSource(T,{parameters:Object.assign(Object.assign({},t),{dataInstanceKey:c.meshSrc})})},subsourceToModelSubspaceTransform:n})}return c.skeletonSrc&&h.subsources.push({id:"skeletons",default:!0,subsource:{mesh:e.chunkManager.getChunkSource(E,{parameters:Object.assign(Object.assign({},t),{dataInstanceKey:c.skeletonSrc})})}}),h.subsources.push({id:"bounds",subsource:{staticAnnotations:Object(r.n)(l)},default:!0}),h}(e,t,c)})}function V(e,t){return{offset:0,completions:Object(b.d)(t,e.dataInstances.values(),e=>e.name,e=>`${e.base.typeName}`)}}function _(e,t){let n=t.match(/^(?:([^\/]+)(?:\/([^\/]*))?)?$/);if(null===n)throw new Error("Invalid DVID URL syntax.");if(void 0===n[2])return{offset:0,completions:Object(b.d)(t,e.repositories.values(),e=>e.uuid+"/",e=>`${e.alias}: ${e.description}`)};let i=n[1],r=e.getNode(i);return Object(b.a)(i.length+1,V(r,n[2]))}async function B(e){let t=e.providerUrl.match(/^((?:http|https):\/\/[^\/]+)\/(.*)$/);if(null===t)throw null;let n=t[1],i=t[2];const r=await P(e.chunkManager,n);return Object(b.a)(n.length+1,_(r,i))}class F extends a.a{get description(){return"DVID"}get(e){return N(e)}completeUrl(e){return B(e)}}},function(e,t,n){"use strict";n.r(t);var i=n(8),r=n(12),s=n(5),o=n(34);class a extends class extends
/**
 * @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{}{}{}a.RPC_ID="render/TileChunkSource";var c=n(9),l=n(25),d=n(7),u=n(42),h=n(1),p=n(22),f=n(0);n.d(t,"computeStackHierarchy",(function(){return T})),n.d(t,"getOwnerInfo",(function(){return M})),n.d(t,"stackAndProjectCompleter",(function(){return j})),n.d(t,"volumeCompleter",(function(){return I})),n.d(t,"RenderDataSource",(function(){return P}));
/**
 * @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 m=new Set(["jpg","raw16"]),g=Object(r.g)(l.c,a);class v extends g{}const b=new Set(["COMPLETE","READ_ONLY"]),y=new Set(["LOADING"]);function S(e){let t=Object(f.b)(e,f.w);if(t.length<1)throw new Error("No stacks found for owner object.");let n=new Map,i=Object(f.y)(t[0],"stackId",x);for(let e of t){let t=Object(f.y)(e,"stackId",w),i=C(e);if(void 0!==i){let e=i.project,r=n.get(e);if(void 0===r){let t=new Map;n.set(e,{stacks:t}),r=n.get(e)}r.stacks.set(t,i)}}return{owner:i,projects:n}}function w(e){return Object(f.w)(e),Object(f.y)(e,"stack",f.E)}function x(e){return Object(f.w)(e),Object(f.y)(e,"owner",f.E)}function C(e){Object(f.w)(e);let t=Object(f.y)(e,"state",f.E),n=[],i=h.u.create(),r=h.u.create();if(b.has(t)){let t=Object(f.y)(e,"stats",f.w);i=function(e){Object(f.w)(e);let t=Object(f.y)(e,"stackBounds",f.w),n=h.u.create();return n[0]=Object(f.y)(t,"minX",f.s),n[1]=Object(f.y)(t,"minY",f.s),n[2]=Object(f.y)(t,"minZ",f.s),n}(t),r=function(e){Object(f.w)(e);let t=Object(f.y)(e,"stackBounds",f.w),n=h.u.create();return n[0]=Object(f.y)(t,"maxX",f.s)+1,n[1]=Object(f.y)(t,"maxY",f.s)+1,n[2]=Object(f.y)(t,"maxZ",f.s)+1,n}(t),t.hasOwnProperty("channelNames")&&(n=function(e){return Object(f.w)(e),Object(f.y)(e,"channelNames",e=>Object(f.b)(e,f.E))}(t))}else if(!y.has(t))return;return{lowerVoxelBound:i,upperVoxelBound:r,voxelResolution:Object(f.y)(e,"currentVersion",O),project:Object(f.y)(e,"stackId",k),channels:n}}function O(e){Object(f.w)(e);let t=h.u.create();try{t[0]=Object(f.y)(e,"stackResolutionX",f.s),t[1]=Object(f.y)(e,"stackResolutionY",f.s),t[2]=Object(f.y)(e,"stackResolutionZ",f.s)}catch(e){t[0]=1,t[1]=1,t[2]=1}return t}function k(e){return Object(f.w)(e),Object(f.y)(e,"project",f.E)}class E extends l.a{constructor(e,t,n,i,r,s,o){super(e),this.baseUrl=t,this.ownerInfo=n,this.project=r,this.parameters=o;let a=n.projects.get(r);if(void 0===a)throw new Error(`Specified project ${JSON.stringify(r)} does not exist for `+`specified owner ${JSON.stringify(n.owner)}`);if(void 0===i){const e=Array.from(a.stacks.keys());if(1!==e.length)throw new Error(`Dataset contains multiple stacks: ${JSON.stringify(e)}`);i=e[0]}const c=a.stacks.get(i);if(void 0===c)throw new Error(`Specified stack ${JSON.stringify(i)} is not one of the supported stacks: `+JSON.stringify(Array.from(a.stacks.keys())));this.stack=i,this.stackInfo=c,void 0!==s&&s.length>0&&(this.channel=s),this.minIntensity=Object(f.A)(o.minIntensity),this.maxIntensity=Object(f.A)(o.maxIntensity),this.maxTileSpecsToRender=Object(f.A)(o.maxTileSpecsToRender),this.filter=Object(f.z)(o.filter),this.minX=Object(f.A)(o.minX),this.minY=Object(f.A)(o.minY),this.minZ=Object(f.A)(o.minZ),this.maxX=Object(f.A)(o.maxX),this.maxY=Object(f.A)(o.maxY),this.maxZ=Object(f.A)(o.maxZ),void 0!==this.minX&&(c.lowerVoxelBound[0]=this.minX),void 0!==this.minY&&(c.lowerVoxelBound[1]=this.minY),void 0!==this.minZ&&(c.lowerVoxelBound[2]=this.minZ),void 0!==this.maxX&&(c.upperVoxelBound[0]=this.maxX),void 0!==this.maxY&&(c.upperVoxelBound[1]=this.maxY),void 0!==this.maxZ&&(c.upperVoxelBound[2]=this.maxZ);let l=Object(f.C)(o.encoding);if(void 0===l)l="jpg";else if(!m.has(l))throw new Error(`Invalid encoding: ${JSON.stringify(l)}.`);this.encoding=l,this.numLevels=Object(f.A)(o.numlevels),this.dims=h.u.create();let d=Object(f.A)(o.tilesize);void 0===d&&(d=1024),this.dims[0]=d,this.dims[1]=d,this.dims[2]=1}get dataType(){return"raw16"===this.parameters.encoding?c.a.UINT16:c.a.UINT8}get volumeType(){return c.b.IMAGE}get rank(){return 3}getSources(e){const t=[];let n=this.numLevels;void 0===n&&(n=T(this.stackInfo,this.dims[0]));const{lowerVoxelBound:i,upperVoxelBound:r}=this.stackInfo;for(let e=0;e<n;e++){const n=h.m.create(),s=Uint32Array.of(1,1,1);for(let t=0;t<2;++t)n[5*t]=Math.pow(2,e),s[t]=this.dims[t];const o=h.u.create(),a=h.u.create(),l=h.u.create(),d=h.u.create();for(let e=0;e<3;e++){const t=n[5*e],s=l[e]=i[e]/t,c=d[e]=r[e]/t;o[e]=Math.floor(s),a[e]=Math.ceil(c)}const u=Object(c.d)({rank:3,chunkDataSize:s,dataType:this.dataType,lowerVoxelBound:o,upperVoxelBound:a}),p=this.chunkManager.getChunkSource(v,{spec:u,parameters:{baseUrl:this.baseUrl,owner:this.ownerInfo.owner,project:this.stackInfo.project,stack:this.stack,channel:this.channel,minIntensity:this.minIntensity,maxIntensity:this.maxIntensity,maxTileSpecsToRender:this.maxTileSpecsToRender,filter:this.filter,dims:`${this.dims[0]}_${this.dims[1]}`,level:e,encoding:this.encoding}});t.push([{chunkSource:p,chunkToMultiscaleTransform:n,lowerClipBound:l,upperClipBound:d}])}return Object(d.m)(t)}}function T(e,t){let n=0;for(let t=0;t<2;t++)n=n<e.upperVoxelBound[t]?e.upperVoxelBound[t]:n;if(t>=n)return 1;let i=0;for(;n>t;)n/=2,i++;return i}function M(e,t,n){return e.memoize.getUncounted({type:"render:getOwnerInfo",hostname:t,owner:n},()=>Object(p.c)(`${t}/render-ws/v1/owner/${n}/stacks`).then(e=>e.json()).then(S))}const D=/^([^\/?]+)(?:\/([^\/?]+))?(?:\/([^\/?]+))(?:\/([^\/?]*))?(?:\?(.*))?$/,L=/^((?:(?:(?:http|https):\/\/[^,\/]+)[^\/?]))\/(.*)$/;async function j(e,t,n){const i=n.match(/^(?:([^\/]+)(?:\/([^\/]*))?(?:\/([^\/]*))?(\/.*?)?)?$/);if(null===i)throw null;if(void 0===i[2])throw null;if(void 0===i[3]){let n=i[2]||"";const r=await M(e,t,i[1]);let s=Object(u.d)(n,r.projects,e=>e[0]+"/",()=>{});return{offset:i[1].length+1,completions:s}}if(void 0===i[4]){let n=i[3]||"";let r=(await M(e,t,i[1])).projects.get(i[2]);if(void 0===r)throw null;let s=Object(u.d)(n,r.stacks,e=>e[0]+"/",e=>e[1].project);return{offset:i[1].length+i[2].length+2,completions:s}}let r=i[4].substr(1)||"";let s=(await M(e,t,i[1])).projects.get(i[2]);if(void 0===s)throw null;let o=s.stacks.get(i[3]);if(void 0===o)throw null;let a=o.channels;if(0===a.length)throw null;let c=Object(u.d)(r,a,e=>e,()=>{});return{offset:i[1].length+i[2].length+i[3].length+3,completions:c}}async function I(e,t){let n=e.match(L);if(null===n)throw null;let i=n[1],r=n[2];const s=await j(t,i,r);return Object(u.a)(n[1].length+1,s)}class P extends o.a{get description(){return"Render"}get(e){return function(e,t){let n,r;{let e=t.match(L);if(null===e)throw new Error(`Invalid render volume path: ${JSON.stringify(t)}`);n=e[1],r=e[2]}const o=r.match(D);if(null===o)throw new Error(`Invalid volume path ${JSON.stringify(r)}`);const a=o[1],c=o[2],l=o[3],d=o[4],u=Object(f.f)(o[5]||"");return e.memoize.getUncounted({type:"render:MultiscaleVolumeChunkSource",hostname:n,path:r},async()=>{const t=await M(e,n,a),r=new E(e,n,t,l,c,d,u),o=Object(s.y)({rank:3,names:["x","y","z"],units:["m","m","m"],scales:Float64Array.from(r.stackInfo.voxelResolution,e=>e/1e9),boundingBoxes:[Object(s.A)({lowerBounds:new Float64Array(r.stackInfo.lowerVoxelBound),upperBounds:new Float64Array(r.stackInfo.upperVoxelBound)})]});return{modelTransform:Object(s.z)(o),subsources:[{id:"default",default:!0,subsource:{volume:r}},{id:"bounds",default:!0,subsource:{staticAnnotations:Object(i.n)(o.bounds)}}]}})}(e.chunkManager,e.providerUrl)}completeUrl(e){return I(e.providerUrl,e.chunkManager)}}},function(e,t,n){"use strict";n.r(t);var i,r,s,o=n(8),a=n(61),c=n(12),l=n(5),d=n(34);!function(e){e[e.RAW=0]="RAW",e[e.JPEG=1]="JPEG",e[e.COMPRESSED_SEGMENTATION=2]="COMPRESSED_SEGMENTATION"}(i||(i={}));class u{}u.RPC_ID="precomputed/VolumeChunkSource";class h{}h.RPC_ID="precomputed/MeshSource",function(e){e[e.RAW=0]="RAW",e[e.GZIP=1]="GZIP"}(r||(r={})),function(e){e[e.IDENTITY=0]="IDENTITY",e[e.MURMURHASH3_X86_128=1]="MURMURHASH3_X86_128"}(s||(s={}));class p{}p.RPC_ID="precomputed/MultiscaleMeshSource";class f{}f.RPC_ID="precomputed/SkeletonSource";class m{}m.RPC_ID="precomputed/AnnotationSpatialIndexSource";class g{}g.RPC_ID="precomputed/AnnotationSource";class v{}v.RPC_ID="precomputed/IndexedSegmentPropertySource";var b=n(69),y=n(50),S=n(102),w=n(59),x=n(26),C=n(9),O=n(25),k=n(7),E=n(1),T=n(99),M=n(22),D=n(0),L=n(19);n.d(t,"PrecomputedAnnotationSource",(function(){return F})),n.d(t,"PrecomputedIndexedSegmentPropertySource",(function(){return se})),n.d(t,"PrecomputedDataSource",(function(){return de}));
/**
 * @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 j extends(Object(c.g)(O.c,u)){}class I extends(Object(c.g)(y.b,h)){}class P extends(Object(c.g)(y.d,p)){}class A extends(Object(c.g)(w.d,f)){get skeletonVertexCoordinatesInVoxels(){return!1}get vertexAttributes(){return this.parameters.metadata.vertexAttributes}}function R(e,t){const n=e.split("/");for(const e of t.split("/"))".."!==e||0===n.length?n.push(e):n.length=n.length-1;return n.join("/")}class N{constructor(e,t){Object(D.w)(e);const n=1===t?3:4,r=this.resolution=new Float64Array(n),s=this.voxelOffset=new Float32Array(n),o=this.size=new Float32Array(n);if(4===n&&(r[3]=1,o[3]=t),Object(D.y)(e,"resolution",e=>Object(D.d)(r.subarray(0,3),e,D.r)),Object(D.B)(e,"voxel_offset",e=>Object(D.d)(s.subarray(0,3),e,D.u)),Object(D.y)(e,"size",e=>Object(D.d)(o.subarray(0,3),e,D.D)),this.chunkSizes=Object(D.y)(e,"chunk_sizes",e=>Object(D.b)(e,e=>{const i=new Uint32Array(n);return 4===n&&(i[3]=t),Object(D.d)(i.subarray(0,3),e,D.D),i})),0===this.chunkSizes.length)throw new Error("No chunk sizes specified.");if(this.sharding=Object(D.y)(e,"sharding",W),void 0!==this.sharding&&1!==this.chunkSizes.length)throw new Error("Sharding requires a single chunk size per scale");(this.encoding=Object(D.y)(e,"encoding",e=>Object(D.o)(e,i)))===i.COMPRESSED_SEGMENTATION&&(this.compressedSegmentationBlockSize=Object(D.y)(e,"compressed_segmentation_block_size",e=>Object(D.d)(E.u.create(),e,D.D))),this.key=Object(D.y)(e,"key",D.E)}}class V extends O.a{constructor(e,t,n){super(e),this.url=t,this.info=n}get dataType(){return this.info.dataType}get volumeType(){return this.info.volumeType}get rank(){return this.info.modelSpace.rank}getSources(e){const t=this.info.scales[0].resolution,{rank:n}=this;return Object(k.m)(this.info.scales.map(i=>{const{resolution:r}=i,s=n+1,o=new Float32Array(s*s);o[o.length-1]=1;for(let e=0;e<3;++e){const a=r[e]/t[e];o[s*e+e]=a,o[s*n+e]=i.voxelOffset[e]*a}return 4===n&&(o[3*s+3]=1),Object(C.c)({rank:n,dataType:this.dataType,chunkToMultiscaleTransform:o,upperVoxelBound:i.size,volumeType:this.volumeType,chunkDataSizes:i.chunkSizes,baseVoxelOffset:i.voxelOffset,compressedSegmentationBlockSize:i.compressedSegmentationBlockSize,volumeSourceOptions:e}).map(e=>({chunkSource:this.chunkManager.getChunkSource(j,{spec:e,parameters:{url:R(this.url,i.key),encoding:i.encoding,sharding:i.sharding}}),chunkToMultiscaleTransform:o}))}))}}const _=Object(c.g)(a.b,g);class B extends(Object(c.g)(a.a,m)){}class F extends _{constructor(e,t){const{parameters:n}=t;super(e,{rank:n.rank,relationships:n.relationships.map(e=>e.name),properties:n.properties,parameters:n}),this.readonly=!0,this.metadata=t.metadata}getSources(){return[this.metadata.spatialIndices.map(e=>{const{spec:t}=e;return{chunkSource:this.chunkManager.getChunkSource(B,{parent:this,spec:t,parameters:e.parameters}),chunkToMultiscaleTransform:t.chunkToMultiscaleTransform}})]}}function z(e,t){return e.getChunkSource(I,{parameters:t})}function U(e){return Object(D.y)(e,"transform",e=>{const t=E.m.create();return void 0!==e&&Object(D.d)(t.subarray(0,12),e,D.p),E.m.transpose(t,t),t})}async function G(e,t){let n;try{n=await X(e,t)}catch(e){if(e instanceof M.a&&(404===e.status||403===e.status))return{metadata:void 0};throw e}return function(e){Object(D.w)(e);const t=Object(D.y)(e,"@type",D.E);let n;if("neuroglancer_legacy_mesh"===t)n=void 0;else{if("neuroglancer_multilod_draco"!==t)throw new Error(`Unsupported mesh type: ${JSON.stringify(t)}`);{const t=Object(D.y)(e,"lod_scale_multiplier",D.r),i=Object(D.y)(e,"vertex_quantization_bits",D.D);n={lodScaleMultiplier:t,transform:U(e),sharding:Object(D.y)(e,"sharding",W),vertexQuantizationBits:i}}}return{metadata:n,segmentPropertyMap:Object(D.y)(e,"segment_properties",D.C)}}(n)}function $(e){return void 0===e?r.RAW:Object(D.o)(e,r)}function W(e){if(void 0===e)return;Object(D.w)(e);const t=Object(D.y)(e,"@type",D.E);if("neuroglancer_uint64_sharded_v1"!==t)throw new Error(`Unsupported sharding format: ${JSON.stringify(t)}`);return{hash:Object(D.y)(e,"hash",e=>Object(D.o)(e,s)),preshiftBits:Object(D.y)(e,"preshift_bits",D.u),shardBits:Object(D.y)(e,"shard_bits",D.u),minishardBits:Object(D.y)(e,"minishard_bits",D.u),minishardIndexEncoding:Object(D.y)(e,"minishard_index_encoding",$),dataEncoding:Object(D.y)(e,"data_encoding",$)}}async function H(e,t){return function(e){Object(D.w)(e);const t=Object(D.y)(e,"@type",D.E);if("neuroglancer_skeletons"!==t)throw new Error(`Unsupported skeleton type: ${JSON.stringify(t)}`);const n=U(e),i=new Map;Object(D.y)(e,"vertex_attributes",e=>{void 0!==e&&Object(D.b)(e,e=>{Object(D.w)(e);const t=Object(D.y)(e,"id",D.E);if(""===t)throw new Error("vertex attribute id must not be empty");if(i.has(t))throw new Error(`duplicate vertex attribute id ${JSON.stringify(t)}`);const n=Object(D.y)(e,"data_type",e=>Object(D.o)(e,C.a)),r=Object(D.y)(e,"num_components",D.D);i.set(t,{dataType:n,numComponents:r})})});const r=Object(D.y)(e,"sharding",W),s=Object(D.y)(e,"segment_properties",D.C);return{metadata:{transform:n,vertexAttributes:i,sharding:r},segmentPropertyMap:s}}(await X(e,t))}function J(){return Object(l.y)({names:["x","y","z"],units:["m","m","m"],scales:Float64Array.of(1e-9,1e-9,1e-9)})}async function q(e,t){const{metadata:n,segmentPropertyMap:i}=await G(e,t);if(void 0===n)return{source:z(e,{url:t,lod:0}),transform:E.m.create(),segmentPropertyMap:i};let r;const{vertexQuantizationBits:s}=n;if(10===s)r=b.e.uint10;else{if(16!==s)throw new Error(`Invalid vertex quantization bits: ${s}`);r=b.e.uint16}return{source:e.getChunkSource(P,{parameters:{url:t,metadata:n},format:{fragmentRelativeVertices:!0,vertexPositionFormat:r}}),transform:n.transform,segmentPropertyMap:i}}async function Y(e,t){const{metadata:n,segmentPropertyMap:i}=await H(e,t);return{source:e.getChunkSource(A,{parameters:{url:t,metadata:n}}),transform:n.transform,segmentPropertyMap:i}}function X(e,t){return t=Object(M.d)(t),e.memoize.getUncounted({type:"precomputed:metadata",url:t},async()=>(await Object(M.c)(`${t}/info`)).json())}function K(e){const t=E.m.create(),n=e.scales[0].resolution;for(let e=0;e<3;++e)t[5*e]=1/n[e];return t}async function Q(e,t,n,i){const r=function(e){Object(D.w)(e);const t=Object(D.y)(e,"data_type",e=>Object(D.o)(e,C.a)),n=Object(D.y)(e,"num_channels",D.D),i=Object(D.y)(e,"type",e=>Object(D.o)(e,C.b)),r=Object(D.y)(e,"mesh",D.C),s=Object(D.y)(e,"skeletons",D.C),o=Object(D.y)(e,"segment_properties",D.C),a=Object(D.y)(e,"scales",e=>Object(D.b)(e,e=>new N(e,n)));if(0===a.length)throw new Error("Expected at least one scale");const c=a[0],d=1===n?3:4,u=new Float64Array(d),h=new Float64Array(d),p=new Float64Array(d),f=["x","y","z"],m=["m","m","m"];for(let e=0;e<3;++e)u[e]=c.resolution[e]/1e9,h[e]=c.voxelOffset[e],p[e]=h[e]+c.size[e];4===d&&(u[3]=1,p[3]=n,f[3]="c^",m[3]="");const g={lowerBounds:h,upperBounds:p};return{dataType:t,volumeType:i,mesh:r,skeletons:s,segmentPropertyMap:o,scales:a,modelSpace:Object(l.y)({rank:d,names:f,units:m,scales:u,boundingBoxes:[Object(l.A)(g)]})}}(i),s=new V(e.chunkManager,n,r),{modelSpace:a}=r,c=[{id:"default",default:!0,subsource:{volume:s}},{id:"bounds",default:!0,subsource:{staticAnnotations:Object(o.n)(a.bounds)}}];if(void 0!==r.segmentPropertyMap){const n=R(t,r.segmentPropertyMap),i=Object(M.d)(n),s=await X(e.chunkManager,i),o=oe(e.chunkManager,s,i);c.push({id:"properties",default:!0,subsource:{segmentPropertyMap:o}})}if(void 0!==r.mesh){const n=R(t,r.mesh),{source:i,transform:s}=await q(e.chunkManager,Object(M.d)(n)),o=K(r);E.m.multiply(o,o,s),c.push({id:"mesh",default:!0,subsource:{mesh:i},subsourceToModelSubspaceTransform:o})}if(void 0!==r.skeletons){const n=R(t,r.skeletons),{source:i,transform:s}=await Y(e.chunkManager,Object(M.d)(n)),o=K(r);E.m.multiply(o,o,s),c.push({id:"skeletons",default:!0,subsource:{mesh:i},subsourceToModelSubspaceTransform:o})}return{modelTransform:Object(l.z)(a),subsources:c}}function Z(e,t){return Object(D.w)(t),{url:R(e,Object(D.y)(t,"key",D.E)),sharding:Object(D.y)(t,"sharding",W)}}function ee(e){Object(D.w)(e);const t=Object(D.y)(e,"id",e=>{const t=Object(D.E)(e);if(null===t.match(/^[a-z][a-zA-Z0-9_]*$/))throw new Error(`Invalid property identifier: ${JSON.stringify(e)}`);return t});return{type:Object(D.y)(e,"type",e=>{if(Object(D.E)(e),!Object.prototype.hasOwnProperty.call(o.g,e))throw new Error("Unsupported property type: $JSON.stringify(tJson)}");return e}),identifier:t,description:Object(D.B)(e,"description",D.E),default:0}}function te(e){const t=Object(D.b)(e,ee),n=new Set;for(const e of t){if(n.has(e.identifier))throw new Error(`Duplicate property identifier: ${e.identifier}`);n.add(e.identifier)}return t}class ne{constructor(e,t){this.url=e,Object(D.w)(t);const n=Object(D.y)(t,"dimensions",l.e),{rank:i}=n,r=Object(D.y)(t,"lower_bound",e=>Object(D.d)(new Float64Array(i),e,D.p)),s=Object(D.y)(t,"upper_bound",e=>Object(D.d)(new Float64Array(i),e,D.p));this.coordinateSpace=Object(l.y)({rank:i,names:n.names,units:n.units,scales:n.scales,boundingBoxes:[Object(l.A)({lowerBounds:r,upperBounds:s})]}),this.parameters={type:Object(D.y)(t,"annotation_type",e=>Object(D.o)(e,o.e)),rank:i,relationships:Object(D.y)(t,"relationships",t=>Object(D.b)(t,t=>{const n=Z(e,t),i=Object(D.y)(t,"id",D.E);return Object.assign(Object.assign({},n),{name:i})})),properties:Object(D.y)(t,"properties",te),byId:Object(D.y)(t,"by_id",t=>Z(e,t))},this.spatialIndices=Object(D.y)(t,"spatial",t=>Object(D.b)(t,t=>{const n=Z(e,t),s=Object(D.y)(t,"grid_shape",e=>Object(D.d)(new Float32Array(i),e,D.D)),o=Object(D.y)(t,"chunk_size",e=>Object(D.d)(new Float32Array(i),e,D.r)),a=Object(D.y)(t,"limit",D.D),c=new Float32Array(i);for(let e=0;e<i;++e)c[e]=s[e]*o[e];const l=L.c(Float32Array,i+1);for(let e=0;e<i;++e)l[(i+1)*i+e]=r[e];const d=Object.assign({limit:a,chunkToMultiscaleTransform:l},Object(x.p)({rank:i,chunkDataSize:o,upperVoxelBound:c}));return d.upperChunkBound=s,{parameters:n,spec:d,limit:a}})),this.spatialIndices.reverse()}}async function ie(e,t){const{source:n,transform:i,segmentPropertyMap:r}=await q(e.chunkManager,t),s=[{id:"default",default:!0,subsource:{mesh:n},subsourceToModelSubspaceTransform:i}];if(void 0!==r){const n=R(t,r),i=Object(M.d)(n),o=await X(e.chunkManager,i),a=oe(e.chunkManager,o,i);s.push({id:"properties",default:!0,subsource:{segmentPropertyMap:a}})}return{modelTransform:Object(l.z)(J()),subsources:s}}function re(e){Object(D.w)(e);const t=Object(D.y)(e,"ids",D.F),n=Object(D.y)(e,"properties",e=>Object(D.b)(e,e=>(Object(D.w)(e),{id:Object(D.y)(e,"id",D.E),description:Object(D.B)(e,"description",D.E),type:Object(D.y)(e,"type",e=>{if("label"!==e&&"description"!==e&&"string"!==e)throw new Error(`Invalid property type: ${JSON.stringify(e)}`);return e}),values:Object(D.y)(e,"values",e=>{if(Object(D.F)(e),e.length!==t.length)throw new Error(`Expected ${t.length} values, but received: ${e.length}`);return e})})));return{ids:t,properties:n}}const se=Object(c.g)(S.a,v);function oe(e,t,n){try{const i=Object(D.y)(t,"@type",D.E);if("neuroglancer_segment_properties"!==i)throw new Error(`Unsupported segment property map type: ${JSON.stringify(i)}`);const r=Object(D.B)(t,"inline",re),s=Object(D.B)(t,"indexed",t=>{const{sharding:i,properties:r}=function(e){return Object(D.w)(e),{sharding:Object(D.y)(e,"sharding",W),properties:Object(D.y)(e,"properties",e=>Object(D.b)(e,e=>({id:Object(D.y)(e,"id",D.E),description:Object(D.B)(e,"description",D.E),type:Object(D.y)(e,"type",e=>{if("string"!==e)throw new Error(`Invalid property type: ${JSON.stringify(e)}`);return e})})))}}(t);return e.getChunkSource(se,{properties:r,parameters:{sharding:i,url:n}})});return new S.b({inlineProperties:r,indexedProperties:s})}catch(e){throw new Error(`Error parsing segment property map: ${e.message}`)}}const ae=/^([^#]*)(?:#(.*))?$/;function ce(e){let[,t,n]=e.match(ae);return t.endsWith("/")&&(t=t.substring(0,t.length-1)),{url:t,parameters:Object(D.f)(n||"")}}function le(e,t){const n=Object(D.i)(t);return n&&(e+=`#${n}`),e}class de extends d.a{get description(){return"Precomputed file-backed data source"}normalizeUrl(e){const{url:t,parameters:n}=ce(e.providerUrl);return e.providerProtocol+"://"+le(t,n)}convertLegacyUrl(e){const{url:t,parameters:n}=ce(e.providerUrl);return"mesh"===e.type&&(n.type="mesh"),e.providerProtocol+"://"+le(t,n)}get(e){const{url:t,parameters:n}=ce(e.providerUrl);return e.chunkManager.memoize.getUncounted({type:"precomputed:get",url:t},async()=>{const i=Object(M.d)(t);let r;try{r=await X(e.chunkManager,i)}catch(t){if(t instanceof M.a&&404===t.status&&"mesh"===n.type)return await ie(e,i);throw t}Object(D.w)(r);const s=Object(D.B)(r,"redirect",D.E);if(void 0!==s)throw new d.d(s);const o=Object(D.B)(r,"@type",D.E);switch(o){case"neuroglancer_skeletons":return await async function(e,t){const{source:n,transform:i,segmentPropertyMap:r}=await Y(e.chunkManager,t),s=[{id:"default",default:!0,subsource:{mesh:n},subsourceToModelSubspaceTransform:i}];if(void 0!==r){const n=R(t,r),i=Object(M.d)(n),o=await X(e.chunkManager,i),a=oe(e.chunkManager,o,i);s.push({id:"properties",default:!0,subsource:{segmentPropertyMap:a}})}return{modelTransform:Object(l.z)(J()),subsources:s}}(e,i);case"neuroglancer_multilod_draco":case"neuroglancer_legacy_mesh":return await ie(e,i);case"neuroglancer_annotations_v1":return await async function(e,t,n){const i=new ne(t,n);return{modelTransform:Object(l.z)(i.coordinateSpace),subsources:[{id:"default",default:!0,subsource:{annotation:e.chunkManager.getChunkSource(F,{metadata:i,parameters:i.parameters})}}]}}(e,i,r);case"neuroglancer_segment_properties":return await async function(e,t,n){return{modelTransform:Object(l.z)(l.l),subsources:[{id:"default",default:!0,subsource:{segmentPropertyMap:oe(e.chunkManager,n,t)}}]}}(e,i,r);case"neuroglancer_multiscale_volume":case void 0:return await Q(e,t,i,r);default:throw new Error(`Invalid type: ${JSON.stringify(o)}`)}})}completeUrl(e){return Object(T.a)(e.providerUrl,e.cancellationToken)}}},function(e,t,n){"use strict";n.r(t);var i=n(8),r=n(12),s=n(5),o=n(34);class a{}a.RPC_ID="nifti/VolumeChunkSource";var c=n(9),l=n(25),d=n(39),u=n(99),h=n(19);n.d(t,"NiftiMultiscaleVolumeChunkSource",(function(){return f})),n.d(t,"NiftiDataSource",(function(){return m}));
/**
 * @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 p extends(Object(r.g)(l.c,a)){}class f extends l.a{constructor(e,t,n){super(e),this.url=t,this.info=n}get dataType(){return this.info.dataType}get volumeType(){return c.b.UNKNOWN}get rank(){return this.info.rank}getSources(e){let{info:t}=this;const n=h.c(Float32Array,t.rank+1),i=Object(c.e)({rank:t.rank,volumeType:c.b.UNKNOWN,chunkDataSize:t.volumeSize,dataType:t.dataType,upperVoxelBound:Float32Array.from(t.volumeSize),chunkToMultiscaleTransform:n,volumeSourceOptions:e});return[[{chunkSource:this.chunkManager.getChunkSource(p,{spec:i,parameters:{url:this.url}}),chunkToMultiscaleTransform:n}]]}}class m extends o.a{get description(){return"Single NIfTI file"}get(e){return t=e.chunkManager,n=e.providerUrl,t.memoize.getUncounted({type:"nifti/getVolume",url:n},async()=>{const e=await function(e,t,n){return e.rpc.promiseInvoke("nifti/getNiftiVolumeInfo",{chunkManager:e.addCounterpartRef(),url:t},n)}(t,n,d.e),r=new f(t,n,e),o={lowerBounds:new Float64Array(e.rank),upperBounds:Float64Array.from(e.volumeSize)},a=Object(s.y)({rank:e.rank,names:e.sourceNames,scales:e.sourceScales,units:e.units,boundingBoxes:[Object(s.A)(o)]}),c=Object(s.y)({rank:e.rank,names:e.viewNames,scales:e.viewScales,units:e.units});return{subsources:[{id:"default",default:!0,subsource:{volume:r}},{id:"bounds",default:!0,subsource:{staticAnnotations:Object(i.n)(o)}}],modelTransform:{sourceRank:e.rank,rank:e.rank,inputSpace:a,outputSpace:c,transform:e.transform}}});var t,n}completeUrl(e){return Object(u.a)(e.providerUrl,e.cancellationToken)}}},function(e,t,n){"use strict";n.r(t);var i,r=n(8),s=n(12),o=n(5),a=n(34);!function(e){e[e.RAW=0]="RAW",e[e.GZIP=1]="GZIP"}(i||(i={}));class c{}c.RPC_ID="n5/VolumeChunkSource";var l=n(9),d=n(25),u=n(7),h=n(99),p=n(22),f=n(0),m=n(19),g=n(40);n.d(t,"MultiscaleVolumeChunkSource",(function(){return b})),n.d(t,"N5DataSource",(function(){return 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.
 */
class v extends(Object(s.g)(d.c,c)){}class b extends d.a{constructor(e,t,n){let i,r;if(super(e),this.multiscaleMetadata=t,this.scales=n,n.forEach((e,t)=>{if(void 0!==e){if(void 0===r&&(r=t),void 0!==i&&e.dataType!==i)throw new Error(`Scale s${t} has data type ${l.a[e.dataType]} but expected ${l.a[i]}.`);i=e.dataType}}),void 0===i)throw new Error("At least one scale must be specified.");const s=t.scales[r],a=n[r];this.dataType=i,this.volumeType=l.b.IMAGE,this.baseScaleIndex=r;const c=t.modelSpace,{rank:d}=c;this.modelSpace=Object(o.y)({names:c.names,scales:c.scales,units:c.units,boundingBoxes:[{transform:Object(m.b)(Float64Array,s.downsamplingFactor,!1),box:{lowerBounds:new Float64Array(d),upperBounds:new Float64Array(a.size)}}]})}get rank(){return this.modelSpace.rank}getSources(e){const{}=this,{scales:t,rank:n}=this,i=this.multiscaleMetadata.scales;return Object(u.m)(t.filter(e=>void 0!==e).map((t,r)=>{const s=i[r],o=Object(m.b)(Float32Array,s.downsamplingFactor);return Object(l.c)({rank:n,chunkToMultiscaleTransform:o,dataType:t.dataType,upperVoxelBound:t.size,volumeType:this.volumeType,chunkDataSizes:[t.chunkSize],volumeSourceOptions:e}).map(e=>({chunkSource:this.chunkManager.getChunkSource(v,{spec:e,parameters:{url:Object(p.d)(s.url),encoding:t.encoding}}),chunkToMultiscaleTransform:o}))}))}}class y{constructor(e){let t;Object(f.w)(e),this.dataType=Object(f.y)(e,"dataType",e=>Object(f.o)(e,l.a)),this.size=Float32Array.from(Object(f.y)(e,"dimensions",e=>Object(f.b)(e,f.D))),this.chunkSize=Object(f.y)(e,"blockSize",e=>Object(f.d)(new Uint32Array(this.size.length),e,f.D)),Object(f.B)(e,"compression",e=>{t=Object(f.y)(e,"type",e=>Object(f.o)(e,i))}),void 0===t&&(t=Object(f.y)(e,"compressionType",e=>Object(f.o)(e,i))),this.encoding=t}}async function S(e,t,n){const i=function(e){let{protocol:t,host:n,path:i}=Object(p.e)(e);i.endsWith("/")&&(i=i.substring(0,i.length-1));const r=[];for(;;){r.push(`${t}://${n}${i}/attributes.json`);const e=i.lastIndexOf("/");if(-1===e)break;i=i.substring(0,e)}return r}(t).map(p.d),r=await Promise.all(i.map((t,r)=>function(e,t,n){return t=Object(p.d)(t),e.memoize.getUncounted({type:"n5:attributes.json",url:t},()=>Object(p.c)(t).then(e=>e.json()).then(e=>{try{return Object(f.w)(e)}catch(e){throw new Error(`Error reading attributes from ${t}: ${e.message}`)}}).catch(e=>{if(e instanceof p.a&&404===e.status){if(n)return;return{}}throw e}))}(e,t,n&&r===i.length-1)));if(-1===r.indexOf(void 0))return r.reverse(),Object.assign({},...r)}function w(e,t){if(-1!==e&&t!==e)throw new Error(`Rank mismatch, received ${t} but expected ${e}`);return t}function x(e){return Float64Array.from(Object(f.b)(e,f.r))}function C(e){const t=Object(f.a)(e);if(0===t.length)throw new Error("Expected non-empty array");let n=-1;return{all:Object(f.b)(t,e=>{const t=x(e);return n=w(n,t.length),t}),single:void 0,rank:n}}const O=["x","y","z","t","c"];function k(e,t){Object(f.w)(t);let n,i,r=-1,s=Object(f.B)(t,"resolution",e=>{const t=Float64Array.from(Object(f.b)(e,f.r));return r=w(r,t.length),t}),a=Object(f.B)(t,"axes",e=>{const t=Object(f.b)(e,f.E);return r=w(r,t.length),t}),c=Object(f.B)(t,"units",e=>{const t=Object(f.b)(e,g.g);return r=w(r,t.length),t}),l={unit:"m",exponent:-9};Object(f.B)(t,"downsamplingFactors",e=>{const{single:t,all:s,rank:o}=function(e){const t=Object(f.a)(e);if(0===t.length)throw new Error("Expected non-empty array");if(Array.isArray(t[0]))return C(t);const n=x(e);return{all:void 0,single:n,rank:n.length}}(e);r=w(r,o),void 0!==t&&(n=t),void 0!==s&&(i=s)}),Object(f.B)(t,"pixelResolution",e=>{l=Object(f.y)(e,"unit",g.g),Object(f.B)(e,"dimensions",e=>{s=Float64Array.from(Object(f.b)(e,f.r)),r=w(r,s.length)})}),Object(f.B)(t,"scales",e=>{const{all:t,rank:n}=C(e);r=w(r,n),i=t});const d=Object(f.B)(t,"dimensions",e=>{const t=Object(f.b)(e,f.D);return r=w(r,t.length),t});if(-1===r)throw new Error("Unable to determine rank of dataset");void 0===a&&(a=function(e){const t=O.slice(0,e);for(;t.length<e;)t.push(`d${t.length+1}`);return t}(r)),void 0===c&&(c=new Array(r),c.fill(l)),void 0===s&&(s=new Float64Array(r),s.fill(1));for(let e=0;e<r;++e)s[e]=Object(g.e)(s[e],c[e].exponent);const u=Object(o.y)({rank:r,valid:!0,names:a,scales:s,units:c.map(e=>e.unit)});if(void 0===d){if(void 0===i)throw new Error("Not valid single-resolution or multi-resolution dataset");return{modelSpace:u,url:e,attributes:t,scales:i.map((t,n)=>({url:`${e}/s${n}`,downsamplingFactor:t}))}}return void 0===n&&(n=new Float64Array(r),n.fill(1)),{modelSpace:u,url:e,attributes:t,scales:[{url:e,downsamplingFactor:n}]}}class E extends a.a{get description(){return"N5 data source"}get(e){let t=e.providerUrl;return t.endsWith("/")&&(t=t.substring(0,t.length-1)),e.chunkManager.memoize.getUncounted({type:"n5:MultiscaleVolumeChunkSource",url:t},async()=>{const n=await S(e.chunkManager,t,!1),i=k(t,n),s=await function(e,t){return Promise.all(t.scales.map(async t=>{const n=await S(e,t.url,!0);if(void 0!==n)return new y(n)}))}(e.chunkManager,i),a=new b(e.chunkManager,i,s);return{modelTransform:Object(o.z)(a.modelSpace),subsources:[{id:"default",default:!0,url:void 0,subsource:{volume:a}},{id:"bounds",default:!0,url:void 0,subsource:{staticAnnotations:Object(r.n)(a.modelSpace.bounds)}}]}})}completeUrl(e){return Object(h.a)(e.providerUrl,e.cancellationToken)}}},function(e,t,n){"use strict";n.r(t);var i,r=n(8),s=n(12),o=n(5),a=n(34);!function(e){e[e.JPEG=0]="JPEG",e[e.NPZ=1]="NPZ",e[e.RAW=2]="RAW"}(i||(i={}));class c{}class l extends c{}l.RPC_ID="python/VolumeChunkSource";class d extends c{}d.RPC_ID="python/MeshSource";class u extends c{}u.RPC_ID="python/SkeletonSource";var h=n(50),p=n(59),f=n(26),m=n(9),g=n(25),v=n(7),b=n(22),y=n(0),S=n(19),w=n(45),x=n(37);
/**
 * @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 C(e){return class extends e{constructor(...e){super(...e);const t=e[1],n=this.dataSource=this.registerDisposer(t.dataSource.addRef());this.generation=t.generation;const i=t.parameters.key;n.registerSource(i,this)}static encodeOptions(e){const t=super.encodeOptions(e);return t.dataSource=Object(w.a)(e.dataSource),t}}}n.d(t,"computeNearIsotropicDownsamplingLevels",(function(){return E})),n.d(t,"PythonMultiscaleVolumeChunkSource",(function(){return M})),n.d(t,"PythonSkeletonSource",(function(){return D})),n.d(t,"PythonDataSource",(function(){return j}));class O extends(C(Object(s.g)(g.c,l))){}class k extends(C(Object(s.g)(h.b,d))){}function E(e,t,n,i,r,s){console.log({shape:e,downsampleDims:t,effectiveVoxelSize:n,maxDownsampling:i,maxDownsamplingScales:r,maxDownsampledSize:s});const o=e.length,a=new Float32Array(o);a.fill(1);const c=[a.slice()];let l=1;const d=t.length;if(0===d)return c;for(;!(c.length>=r||l>=i||a.every((t,n)=>e[n]/t<=s));){let e=t[0];const r=e=>a[e]*n[e];for(let n=1;n<d;++n){const i=t[n];r(i)<r(e)&&(e=i)}a[e]*=2,l*=2;const s=r(e);for(let n=0;n<d&&l<i;++n){const i=t[n];if(i===e)continue;const o=r(i);Math.abs(o-s)>Math.abs(2*o-s)&&(a[i]*=2,l*=2)}c.push(new Float32Array(a))}return c}function T(e){Object(y.w)(e);const t=Object.assign(Object.assign({},Object(y.y)(e,"coordinateSpace",o.e)),{valid:!0}),{rank:n}=t,i=S.f(new Float32Array((n+1)*(n+1)),n+1,n+1),r=Object(y.y)(e,"voxelOffset",e=>Object(y.d)(new Float64Array(n),e,y.p));for(let e=0;e<n;++e)i[(n+1)*n+e]=r[e];return{subsourceToModelTransform:i,baseModelSpace:t,voxelOffset:r}}class M extends g.a{constructor(e,t,n,r){super(t),this.dataSource=e,this.key=n,this.response=r;const{baseModelSpace:s,subsourceToModelTransform:a,voxelOffset:c}=T(r);this.dataType=Object(y.y)(r,"dataType",e=>Object(y.o)(e,f.c)),this.volumeType=Object(y.y)(r,"volumeType",e=>Object(y.o)(e,m.b)),this.encoding=Object(y.y)(r,"encoding",e=>Object(y.o)(e,i));const l=s.rank;this.subsourceToModelTransform=a;const d=Object(y.y)(r,"shape",e=>Object(y.d)(new Float32Array(l),e,y.D));this.shape=d,this.maxDownsampling=Object(y.y)(r,"maxDownsampling",e=>null===e?Number.POSITIVE_INFINITY:Object(y.u)(e)),this.maxDownsampledSize=Object(y.y)(r,"maxDownsampledSize",e=>null===e?Number.POSITIVE_INFINITY:Object(y.u)(e)),this.maxDownsamplingScales=Object(y.y)(r,"maxDownsamplingScales",e=>null===e?Number.POSITIVE_INFINITY:Object(y.u)(e)),this.downsamplingLayout=Object(y.y)(r,"downsamplingLayout",e=>"2d"===e?f.a.FLAT:f.a.ISOTROPIC),this.chunkLayoutPreference=Object(y.y)(r,"chunkLayout",e=>Object(y.o)(e,f.a));const u={lowerBounds:c,upperBounds:x.a(new Float64Array(l),c,d)},h=Object(o.y)({rank:l,names:s.names,scales:s.scales,units:s.units,boundingBoxes:[Object(o.A)(u)]});this.modelSpace=h,this.generation=Object(y.y)(r,"generation",e=>e),this.maxVoxelsPerChunkLog2=Object(y.B)(r,"maxVoxelsPerChunkLog2",y.D,f.b)}get rank(){return this.modelSpace.rank}getSources(e){const t=[],{rank:n,volumeType:i,dataType:r,shape:s,encoding:o}=this,a=new Float32Array(n),{multiscaleToViewTransform:c,modelChannelDimensionIndices:l}=e;for(let e=0;e<n;++e){let n=0;for(let t=0;t<3;++t){const i=c[3*e+t];n+=i*i}0!==n&&t.push(e),a[e]=Math.sqrt(n)}const d=(t,a,c)=>{const d=new Float32Array((n+1)**2);d[d.length-1]=1;for(let e=0;e<n;++e)d[(n+2)*e]=t[e];const u=new Float32Array(n),h=new Float32Array(n);for(let e=0;e<n;++e)u[e]=Math.ceil(s[e]/t[e]),h[e]=s[e]/t[e];const p=new Uint32Array(n);p.fill(1);for(const e of a)p[e]=4294967295;for(const e of l)p[e]=4294967295;return Object(m.c)({chunkToMultiscaleTransform:d,rank:n,dataType:r,volumeType:i,maxBlockSize:p,upperVoxelBound:u,volumeSourceOptions:e,chunkLayoutPreference:c}).map(e=>({chunkSource:this.chunkManager.getChunkSource(O,{spec:e,dataSource:this.dataSource,generation:this.generation,parameters:{key:this.key,scaleKey:t.join(),encoding:o}}),chunkToMultiscaleTransform:d,upperClipBound:h}))},u=e=>E(this.shape,e,a,this.maxDownsampling,this.maxDownsamplingScales,this.maxDownsampledSize).map(t=>d(t,e,f.a.ISOTROPIC)[0]),{downsamplingLayout:h}=this;return h===f.a.FLAT?[u([t[0],t[1]]),u([t[0],t[2]]),u([t[1],t[2]])]:Object(v.m)(E(this.shape,t,a,this.maxDownsampling,this.maxDownsamplingScales,this.maxDownsampledSize).map(e=>d(e,t,this.chunkLayoutPreference)))}getMeshSource(){const{skeletonVertexAttributes:e}=this;return void 0!==e?this.chunkManager.getChunkSource(D,{dataSource:this.dataSource,generation:this.generation,parameters:{key:this.key,vertexAttributes:e}}):this.chunkManager.getChunkSource(k,{dataSource:this.dataSource,generation:this.generation,parameters:{key:this.key}})}}class D extends(C(Object(s.g)(p.d,u))){get vertexAttributes(){return this.parameters.vertexAttributes}}function L(e){return Object(y.w)(e),{dataType:Object(y.y)(e,"dataType",e=>Object(y.o)(e,f.c)),numComponents:Object(y.y)(e,"numComponents",y.D)}}class j extends a.a{constructor(){super(...arguments),this.sources=new Map,this.sourceGenerations=new Map}registerSource(e,t){let n=this.sources.get(e);void 0===n&&(n=new Set,this.sources.set(e,n));const i=this.sourceGenerations.get(e);void 0!==i&&(t.generation=i),n.add(t),t.registerDisposer(()=>{n.delete(t),0===n.size&&this.sources.delete(e)})}setSourceGeneration(e,t){const{sourceGenerations:n}=this;if(n.get(e)===t)return;n.set(e,t);const i=this.sources.get(e);if(void 0!==i)for(const e of i)e.generation!==t&&(e.generation=t,e.invalidateCache())}deleteSourceGeneration(e){this.sourceGenerations.delete(e)}get description(){return"Python-served volume"}get(e){const t=e.providerUrl.match("^(volume|skeleton)/(.*)$");if(null===t)throw new Error(`Invalid Python data source URL: ${JSON.stringify(e.providerUrl)}`);const n=t[2];return"volume"===t[1]?function(e,t,n){return t.chunkManager.memoize.getUncounted({type:"python:VolumeDataSource",key:n},async()=>{const i=await(await Object(b.c)(`/neuroglancer/info/${n}`)).json(),s=new M(e,t.chunkManager,n,i),a={modelTransform:Object(o.z)(s.modelSpace),subsources:[{id:"default",default:!0,subsource:{volume:s},subsourceToModelSubspaceTransform:s.subsourceToModelTransform},{id:"bounds",default:!0,subsource:{staticAnnotations:Object(r.n)(s.modelSpace.bounds)}}]};if(3===s.rank&&s.dataType!==f.c.FLOAT32){const i=new Float32Array(s.subsourceToModelTransform),{scales:r,rank:o}=s.modelSpace;for(let e=0;e<o;++e)i[(o+2)*e]=1/r[e];a.subsources.push({id:"meshes",default:!0,subsourceToModelSubspaceTransform:i,subsource:{mesh:t.chunkManager.getChunkSource(k,{dataSource:e,generation:s.generation,parameters:{key:n}})}})}return a})}(this,e,n):function(e,t,n){return t.chunkManager.memoize.getUncounted({type:"python:SkeletonDataSource",key:n},async()=>{const i=await(await Object(b.c)(`/neuroglancer/skeletoninfo/${n}`)).json(),{baseModelSpace:r,subsourceToModelTransform:s}=T(i),a=Object(y.y)(i,"attributes",e=>Object(y.x)(e,L)),c=Object(y.y)(i,"generation",e=>e),l=t.chunkManager.getChunkSource(D,{dataSource:e,generation:c,parameters:{key:n,vertexAttributes:a}});return{modelTransform:Object(o.z)(r),subsources:[{id:"default",subsourceToModelSubspaceTransform:s,default:!0,subsource:{mesh:l}}]}})}(this,e,n)}}},function(e,t,n){var i=n(189),r="object"==typeof self&&self&&self.Object===Object&&self,s=i||r||Function("return this")();e.exports=s},function(e,t,n){var i=n(155).Symbol;e.exports=i},function(e,t,n){},function(e,t,n){},function(e,t,n){!function(e){"use strict";function t(t,n,r,s){if(r&&r.call){var o=r;r=null}else o=i(t,r,"rangeFinder");"number"==typeof n&&(n=e.Pos(n,0));var a=i(t,r,"minFoldSize");function c(e){var i=o(t,n);if(!i||i.to.line-i.from.line<a)return null;for(var r=t.findMarksAt(i.from),c=0;c<r.length;++c)if(r[c].__isFold&&"fold"!==s){if(!e)return null;i.cleared=!0,r[c].clear()}return i}var l=c(!0);if(i(t,r,"scanUp"))for(;!l&&n.line>t.firstLine();)n=e.Pos(n.line-1,0),l=c(!1);if(l&&!l.cleared&&"unfold"!==s){var d=function(e,t,n){var r=i(e,t,"widget");if("function"==typeof r&&(r=r(n.from,n.to)),"string"==typeof r){var s=document.createTextNode(r);(r=document.createElement("span")).appendChild(s),r.className="CodeMirror-foldmarker"}else r&&(r=r.cloneNode(!0));return r}(t,r,l);e.on(d,"mousedown",(function(t){u.clear(),e.e_preventDefault(t)}));var u=t.markText(l.from,l.to,{replacedWith:d,clearOnEnter:i(t,r,"clearOnEnter"),__isFold:!0});u.on("clear",(function(n,i){e.signal(t,"unfold",t,n,i)})),e.signal(t,"fold",t,l.from,l.to)}}e.newFoldFunction=function(e,n){return function(i,r){t(i,r,{rangeFinder:e,widget:n})}},e.defineExtension("foldCode",(function(e,n,i){t(this,e,n,i)})),e.defineExtension("isFolded",(function(e){for(var t=this.findMarksAt(e),n=0;n<t.length;++n)if(t[n].__isFold)return!0})),e.commands.toggleFold=function(e){e.foldCode(e.getCursor())},e.commands.fold=function(e){e.foldCode(e.getCursor(),null,"fold")},e.commands.unfold=function(e){e.foldCode(e.getCursor(),null,"unfold")},e.commands.foldAll=function(t){t.operation((function(){for(var n=t.firstLine(),i=t.lastLine();n<=i;n++)t.foldCode(e.Pos(n,0),null,"fold")}))},e.commands.unfoldAll=function(t){t.operation((function(){for(var n=t.firstLine(),i=t.lastLine();n<=i;n++)t.foldCode(e.Pos(n,0),null,"unfold")}))},e.registerHelper("fold","combine",(function(){var e=Array.prototype.slice.call(arguments,0);return function(t,n){for(var i=0;i<e.length;++i){var r=e[i](t,n);if(r)return r}}})),e.registerHelper("fold","auto",(function(e,t){for(var n=e.getHelpers(t,"fold"),i=0;i<n.length;i++){var r=n[i](e,t);if(r)return r}}));var n={rangeFinder:e.fold.auto,widget:"↔",minFoldSize:0,scanUp:!1,clearOnEnter:!0};function i(e,t,i){if(t&&void 0!==t[i])return t[i];var r=e.options.foldOptions;return r&&void 0!==r[i]?r[i]:n[i]}e.defineOption("foldOptions",null),e.defineExtension("foldOption",(function(e,t){return i(this,e,t)}))}(n(65))},function(e,t,n){"use strict";(function(t){var i=n(248),r=n(249),s=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,o=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,a=new RegExp("^[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]+");function c(e){return(e||"").toString().replace(a,"")}var l=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],d={hash:1,query:1};function u(e){var n,i=("undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:{}).location||{},r={},o=typeof(e=e||i);if("blob:"===e.protocol)r=new p(unescape(e.pathname),{});else if("string"===o)for(n in r=new p(e,{}),d)delete r[n];else if("object"===o){for(n in e)n in d||(r[n]=e[n]);void 0===r.slashes&&(r.slashes=s.test(e.href))}return r}function h(e){e=c(e);var t=o.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function p(e,t,n){if(e=c(e),!(this instanceof p))return new p(e,t,n);var s,o,a,d,f,m,g=l.slice(),v=typeof t,b=this,y=0;for("object"!==v&&"string"!==v&&(n=t,t=null),n&&"function"!=typeof n&&(n=r.parse),t=u(t),s=!(o=h(e||"")).protocol&&!o.slashes,b.slashes=o.slashes||s&&t.slashes,b.protocol=o.protocol||t.protocol||"",e=o.rest,o.slashes||(g[3]=[/(.*)/,"pathname"]);y<g.length;y++)"function"!=typeof(d=g[y])?(a=d[0],m=d[1],a!=a?b[m]=e:"string"==typeof a?~(f=e.indexOf(a))&&("number"==typeof d[2]?(b[m]=e.slice(0,f),e=e.slice(f+d[2])):(b[m]=e.slice(f),e=e.slice(0,f))):(f=a.exec(e))&&(b[m]=f[1],e=e.slice(0,f.index)),b[m]=b[m]||s&&d[3]&&t[m]||"",d[4]&&(b[m]=b[m].toLowerCase())):e=d(e);n&&(b.query=n(b.query)),s&&t.slashes&&"/"!==b.pathname.charAt(0)&&(""!==b.pathname||""!==t.pathname)&&(b.pathname=function(e,t){if(""===e)return t;for(var n=(t||"/").split("/").slice(0,-1).concat(e.split("/")),i=n.length,r=n[i-1],s=!1,o=0;i--;)"."===n[i]?n.splice(i,1):".."===n[i]?(n.splice(i,1),o++):o&&(0===i&&(s=!0),n.splice(i,1),o--);return s&&n.unshift(""),"."!==r&&".."!==r||n.push(""),n.join("/")}(b.pathname,t.pathname)),i(b.port,b.protocol)||(b.host=b.hostname,b.port=""),b.username=b.password="",b.auth&&(d=b.auth.split(":"),b.username=d[0]||"",b.password=d[1]||""),b.origin=b.protocol&&b.host&&"file:"!==b.protocol?b.protocol+"//"+b.host:"null",b.href=b.toString()}p.prototype={set:function(e,t,n){var s=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(n||r.parse)(t)),s[e]=t;break;case"port":s[e]=t,i(t,s.protocol)?t&&(s.host=s.hostname+":"+t):(s.host=s.hostname,s[e]="");break;case"hostname":s[e]=t,s.port&&(t+=":"+s.port),s.host=t;break;case"host":s[e]=t,/:\d+$/.test(t)?(t=t.split(":"),s.port=t.pop(),s.hostname=t.join(":")):(s.hostname=t,s.port="");break;case"protocol":s.protocol=t.toLowerCase(),s.slashes=!n;break;case"pathname":case"hash":if(t){var o="pathname"===e?"/":"#";s[e]=t.charAt(0)!==o?o+t:t}else s[e]=t;break;default:s[e]=t}for(var a=0;a<l.length;a++){var c=l[a];c[4]&&(s[c[1]]=s[c[1]].toLowerCase())}return s.origin=s.protocol&&s.host&&"file:"!==s.protocol?s.protocol+"//"+s.host:"null",s.href=s.toString(),s},toString:function(e){e&&"function"==typeof e||(e=r.stringify);var t,n=this,i=n.protocol;i&&":"!==i.charAt(i.length-1)&&(i+=":");var s=i+(n.slashes?"//":"");return n.username&&(s+=n.username,n.password&&(s+=":"+n.password),s+="@"),s+=n.host+n.pathname,(t="object"==typeof n.query?e(n.query):n.query)&&(s+="?"!==t.charAt(0)?"?"+t:t),n.hash&&(s+=n.hash),s}},p.extractProtocol=h,p.location=u,p.trimLeft=c,p.qs=r,e.exports=p}).call(this,n(46))},function(e,t,n){"use strict";function i(){this._listeners={}}i.prototype.addEventListener=function(e,t){e in this._listeners||(this._listeners[e]=[]);var n=this._listeners[e];-1===n.indexOf(t)&&(n=n.concat([t])),this._listeners[e]=n},i.prototype.removeEventListener=function(e,t){var n=this._listeners[e];if(n){var i=n.indexOf(t);-1===i||(n.length>1?this._listeners[e]=n.slice(0,i).concat(n.slice(i+1)):delete this._listeners[e])}},i.prototype.dispatchEvent=function(){var e=arguments[0],t=e.type,n=1===arguments.length?[e]:Array.apply(null,arguments);if(this["on"+t]&&this["on"+t].apply(this,n),t in this._listeners)for(var i=this._listeners[t],r=0;r<i.length;r++)i[r].apply(this,n)},e.exports=i},function(e,t,n){"use strict";var i=n(33),r=n(73),s=n(252),o=n(253);function a(e,t,n,i,a){var c=r.addPath(e,t),l=this;s.call(this,e,n),this.poll=new o(i,c,a),this.poll.on("message",(function(e){l.emit("message",e)})),this.poll.once("close",(function(e,t){l.poll=null,l.emit("close",e,t),l.close()}))}i(a,s),a.prototype.close=function(){s.prototype.close.call(this),this.removeAllListeners(),this.poll&&(this.poll.abort(),this.poll=null)},e.exports=a},function(e,t,n){"use strict";(function(t){var i=n(64).EventEmitter,r=n(33),s=n(90),o=n(73),a=t.XMLHttpRequest;function c(e,t,n,r){var s=this;i.call(this),setTimeout((function(){s._start(e,t,n,r)}),0)}r(c,i),c.prototype._start=function(e,t,n,i){var r=this;try{this.xhr=new a}catch(e){}if(!this.xhr)return this.emit("finish",0,"no xhr support"),void this._cleanup();t=o.addQuery(t,"t="+ +new Date),this.unloadRef=s.unloadAdd((function(){r._cleanup(!0)}));try{this.xhr.open(e,t,!0),this.timeout&&"timeout"in this.xhr&&(this.xhr.timeout=this.timeout,this.xhr.ontimeout=function(){r.emit("finish",0,""),r._cleanup(!1)})}catch(e){return this.emit("finish",0,""),void this._cleanup(!1)}if(i&&i.noCredentials||!c.supportsCORS||(this.xhr.withCredentials=!0),i&&i.headers)for(var l in i.headers)this.xhr.setRequestHeader(l,i.headers[l]);this.xhr.onreadystatechange=function(){if(r.xhr){var e,t,n=r.xhr;switch(n.readyState,n.readyState){case 3:try{t=n.status,e=n.responseText}catch(e){}1223===t&&(t=204),200===t&&e&&e.length>0&&r.emit("chunk",t,e);break;case 4:1223===(t=n.status)&&(t=204),12005!==t&&12029!==t||(t=0),n.responseText,r.emit("finish",t,n.responseText),r._cleanup(!1)}}};try{r.xhr.send(n)}catch(e){r.emit("finish",0,""),r._cleanup(!1)}},c.prototype._cleanup=function(e){if(this.xhr){if(this.removeAllListeners(),s.unloadDel(this.unloadRef),this.xhr.onreadystatechange=function(){},this.xhr.ontimeout&&(this.xhr.ontimeout=null),e)try{this.xhr.abort()}catch(e){}this.unloadRef=this.xhr=null}},c.prototype.close=function(){this._cleanup(!0)},c.enabled=!!a;var l=["Active"].concat("Object").join("X");!c.enabled&&l in t&&(a=function(){try{return new t[l]("Microsoft.XMLHTTP")}catch(e){return null}},c.enabled=!!new a);var d=!1;try{d="withCredentials"in new a}catch(e){}c.supportsCORS=d,e.exports=c}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(111),s=n(130),o=n(143);function a(e){if(!o.enabled)throw new Error("Transport created when disabled");r.call(this,e,"/xhr_streaming",s,o)}i(a,r),a.enabled=function(e){return!e.cookie_needed&&!e.nullOrigin&&(o.enabled&&e.sameScheme)},a.transportName="xdr-streaming",a.roundTrips=2,e.exports=a},function(e,t,n){"use strict";var i=n(33),r=n(111),s=n(254),o=n(131),a=n(166);function c(e){if(!c.enabled())throw new Error("Transport created when disabled");r.call(this,e,"/eventsource",s,o)}i(c,r),c.enabled=function(){return!!a},c.transportName="eventsource",c.roundTrips=2,e.exports=c},function(e,t,n){(function(t){e.exports=t.EventSource}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(83),s=n(64).EventEmitter,o=n(168),a=n(73),c=n(123),l=n(90),d=n(110);function u(e,t,n){if(!u.enabled())throw new Error("Transport created when disabled");s.call(this);var i=this;this.origin=a.getOrigin(n),this.baseUrl=n,this.transUrl=t,this.transport=e,this.windowId=d.string(8);var r=a.addPath(n,"/iframe.html")+"#"+this.windowId;this.iframeObj=c.createIframe(r,(function(e){i.emit("close",1006,"Unable to load an iframe ("+e+")"),i.close()})),this.onmessageCallback=this._message.bind(this),l.attachEvent("message",this.onmessageCallback)}i(u,s),u.prototype.close=function(){if(this.removeAllListeners(),this.iframeObj){l.detachEvent("message",this.onmessageCallback);try{this.postMessage("c")}catch(e){}this.iframeObj.cleanup(),this.iframeObj=null,this.onmessageCallback=this.iframeObj=null}},u.prototype._message=function(e){if(e.data,!a.isOriginEqual(e.origin,this.origin))return e.origin,void this.origin;var t;try{t=r.parse(e.data)}catch(t){return void e.data}if(t.windowId!==this.windowId)return t.windowId,void this.windowId;switch(t.type){case"s":this.iframeObj.loaded(),this.postMessage("s",r.stringify([o,this.transport,this.transUrl,this.baseUrl]));break;case"t":this.emit("message",t.data);break;case"c":var n;try{n=r.parse(t.data)}catch(e){return void t.data}this.emit("close",n[0],n[1]),this.close()}},u.prototype.postMessage=function(e,t){this.iframeObj.post(r.stringify({windowId:this.windowId,type:e,data:t||""}),this.origin)},u.prototype.send=function(e){this.postMessage("m",e)},u.enabled=function(){return c.iframeEnabled},u.transportName="iframe",u.roundTrips=2,e.exports=u},function(e,t){e.exports="1.4.0"},function(e,t,n){"use strict";var i=n(33),r=n(257),s=n(121),o=n(111);function a(e){if(!r.enabled)throw new Error("Transport created when disabled");o.call(this,e,"/htmlfile",r,s)}i(a,o),a.enabled=function(e){return r.enabled&&e.sameOrigin},a.transportName="htmlfile",a.roundTrips=2,e.exports=a},function(e,t,n){"use strict";var i=n(33),r=n(111),s=n(130),o=n(131),a=n(121);function c(e){if(!a.enabled&&!o.enabled)throw new Error("Transport created when disabled");r.call(this,e,"/xhr",s,o)}i(c,r),c.enabled=function(e){return!e.nullOrigin&&(!(!a.enabled||!e.sameOrigin)||o.enabled)},c.transportName="xhr-polling",c.roundTrips=2,e.exports=c},function(e,t,n){"use strict";(function(t){e.exports=t.location||{origin:"http://localhost:80",protocol:"http:",host:"localhost",port:80,href:"http://localhost/",hash:""}}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(64).EventEmitter,s=n(83),o=n(121),a=n(173);function c(e){var t=this;r.call(this),this.ir=new a(e,o),this.ir.once("finish",(function(e,n){t.ir=null,t.emit("message",s.stringify([e,n]))}))}i(c,r),c.transportName="iframe-info-receiver",c.prototype.close=function(){this.ir&&(this.ir.close(),this.ir=null),this.removeAllListeners()},e.exports=c},function(e,t,n){"use strict";var i=n(64).EventEmitter,r=n(33),s=n(83),o=n(145);function a(e,t){i.call(this);var n=this,r=+new Date;this.xo=new t("GET",e),this.xo.once("finish",(function(e,t){var i,a;if(200===e){if(a=+new Date-r,t)try{i=s.parse(t)}catch(e){}o.isObject(i)||(i={})}n.emit("finish",i,a),n.removeAllListeners()}))}r(a,i),a.prototype.close=function(){this.removeAllListeners(),this.xo.close()},e.exports=a},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="arrowUpIconTitle"><path d="M18 9l-6-6-6 6"></path><path d="M12 21V4"></path><path stroke-linecap="round" d="M12 3v1"></path></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="copyIconTitle"><rect width="12" height="14" x="8" y="7"></rect><polyline points="16 3 4 3 4 17"></polyline></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="binIconTitle"><path d="M19 6L5 6M14 5L10 5M6 10L6 20C6 20.6666667 6.33333333 21 7 21 7.66666667 21 11 21 17 21 17.6666667 21 18 20.6666667 18 20 18 19.3333333 18 16 18 10"></path></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="filterIconTitle"><path d="M10 12.261L4.028 3.972h16L14 12.329V17l-4 3z"></path></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="maximiseIconTitle"><polyline points="21 16 21 21 16 21"></polyline><polyline points="8 21 3 21 3 16"></polyline><polyline points="16 3 21 3 21 8"></polyline><polyline points="3 8 3 3 8 3"></polyline></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="closeIconTitle"><path d="M6.34314575 6.34314575L17.6568542 17.6568542M6.34314575 17.6568542L17.6568542 6.34314575"></path></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="cursorIconTitle"><polygon points="7 20 7 4 19 16 12 16 7 21"></polygon></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="arrowLeftIconTitle"><path d="M9 6l-6 6 6 6"></path><path d="M21 12H4"></path><path stroke-linecap="round" d="M3 12h1"></path></svg>'},function(e,t){e.exports='<svg role="img" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="arrowRightIconTitle"><path d="M15 18l6-6-6-6"></path><path d="M3 12h17"></path><path stroke-linecap="round" d="M21 12h-1"></path></svg>'},function(e,t,n){"use strict";(function(t){var i=n(245);e.exports=n(262)(i),"_sockjs_onload"in t&&setTimeout(t._sockjs_onload,1)}).call(this,n(46))},,,,function(e,t,n){n(141),n(197),n(148),n(198),n(149),n(199),n(150),n(200),n(151),n(201),n(152),n(202),n(153),n(203),n(147),n(204),n(154),n(276),n(140),n(220),n(277),e.exports=n(275)},function(e,t,n){var i=n(155);e.exports=function(){return i.Date.now()}},function(e,t,n){(function(t){var n="object"==typeof t&&t&&t.Object===Object&&t;e.exports=n}).call(this,n(46))},function(e,t,n){var i=n(142),r=n(191),s=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,c=/^0o[0-7]+$/i,l=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(r(e))return NaN;if(i(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=i(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(s,"");var n=a.test(e);return n||c.test(e)?l(e.slice(2),n?2:8):o.test(e)?NaN:+e}},function(e,t,n){var i=n(192),r=n(195);e.exports=function(e){return"symbol"==typeof e||r(e)&&"[object Symbol]"==i(e)}},function(e,t,n){var i=n(156),r=n(193),s=n(194),o=i?i.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":o&&o in Object(e)?r(e):s(e)}},function(e,t,n){var i=n(156),r=Object.prototype,s=r.hasOwnProperty,o=r.toString,a=i?i.toStringTag:void 0;e.exports=function(e){var t=s.call(e,a),n=e[a];try{e[a]=void 0;var i=!0}catch(e){}var r=o.call(e);return i&&(t?e[a]=n:delete e[a]),r}},function(e,t){var n=Object.prototype.toString;e.exports=function(e){return n.call(e)}},function(e,t){e.exports=function(e){return null!=e&&"object"==typeof e}},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var i=n(141),r=n(89),s=n(54);
/**
 * @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.
 */
Object(s.b)("brainmaps",e=>new i.BrainmapsDataSource(i.productionInstance,e.credentialsManager.getCredentialsProvider(r.a)))},function(e,t,n){"use strict";n.r(t);var i=n(148),r=n(54);
/**
 * @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.
 */
Object(r.b)("boss",e=>new i.BossDataSource(e.credentialsManager))},function(e,t,n){"use strict";n.r(t);var i=n(149),r=n(54);
/**
 * @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.
 */
Object(r.b)("dvid",()=>new i.DVIDDataSource)},function(e,t,n){"use strict";n.r(t);var i=n(54),r=n(150);
/**
 * @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.
 */
Object(i.b)("render",()=>new r.RenderDataSource)},function(e,t,n){"use strict";n.r(t);var i=n(151),r=n(54);
/**
 * @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.
 */
Object(r.b)("precomputed",()=>new i.PrecomputedDataSource)},function(e,t,n){"use strict";n.r(t);var i=n(152),r=n(54);
/**
 * @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.
 */
Object(r.b)("nifti",()=>new i.NiftiDataSource)},function(e,t,n){"use strict";n.r(t);var i=n(54),r=n(153);
/**
 * @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.
 */
Object(i.b)("n5",()=>new r.N5DataSource)},function(e,t,n){"use strict";n.r(t);var i=n(54),r=n(147);
/**
 * @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.
 */
Object(i.b)("vtk",()=>new r.VtkDataSource)},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){!function(e){"use strict";var t="CodeMirror-lint-markers";function n(e){e.parentNode&&e.parentNode.removeChild(e)}function i(t,i,r){var s=function(t,n){var i=document.createElement("div");function r(t){if(!i.parentNode)return e.off(document,"mousemove",r);i.style.top=Math.max(0,t.clientY-i.offsetHeight-5)+"px",i.style.left=t.clientX+5+"px"}return i.className="CodeMirror-lint-tooltip",i.appendChild(n.cloneNode(!0)),document.body.appendChild(i),e.on(document,"mousemove",r),r(t),null!=i.style.opacity&&(i.style.opacity=1),i}(t,i);function o(){var t;e.off(r,"mouseout",o),s&&((t=s).parentNode&&(null==t.style.opacity&&n(t),t.style.opacity=0,setTimeout((function(){n(t)}),600)),s=null)}var a=setInterval((function(){if(s)for(var e=r;;e=e.parentNode){if(e&&11==e.nodeType&&(e=e.host),e==document.body)return;if(!e){o();break}}if(!s)return clearInterval(a)}),400);e.on(r,"mouseout",o)}function r(e,t,n){this.marked=[],this.options=t,this.timeout=null,this.hasGutter=n,this.onMouseOver=function(t){!function(e,t){var n=t.target||t.srcElement;if(/\bCodeMirror-lint-mark-/.test(n.className)){for(var r=n.getBoundingClientRect(),s=(r.left+r.right)/2,o=(r.top+r.bottom)/2,c=e.findMarksAt(e.coordsChar({left:s,top:o},"client")),l=[],d=0;d<c.length;++d){var u=c[d].__annotation;u&&l.push(u)}l.length&&function(e,t){for(var n=t.target||t.srcElement,r=document.createDocumentFragment(),s=0;s<e.length;s++){var o=e[s];r.appendChild(a(o))}i(t,r,n)}(l,t)}}(e,t)},this.waitingFor=0}function s(e){var n=e.state.lint;n.hasGutter&&e.clearGutter(t);for(var i=0;i<n.marked.length;++i)n.marked[i].clear();n.marked.length=0}function o(t,n,r,s){var o=document.createElement("div"),a=o;return o.className="CodeMirror-lint-marker-"+n,r&&((a=o.appendChild(document.createElement("div"))).className="CodeMirror-lint-marker-multiple"),0!=s&&e.on(a,"mouseover",(function(e){i(e,t,a)})),o}function a(e){var t=e.severity;t||(t="error");var n=document.createElement("div");return n.className="CodeMirror-lint-message-"+t,void 0!==e.messageHTML?n.innerHTML=e.messageHTML:n.appendChild(document.createTextNode(e.message)),n}function c(t){var n=t.state.lint.options,i=n.options||n,r=n.getAnnotations||t.getHelper(e.Pos(0,0),"lint");if(r)if(n.async||r.async)!function(t,n,i){var r=t.state.lint,s=++r.waitingFor;function o(){s=-1,t.off("change",o)}t.on("change",o),n(t.getValue(),(function(n,i){t.off("change",o),r.waitingFor==s&&(i&&n instanceof e&&(n=i),t.operation((function(){l(t,n)})))}),i,t)}(t,r,i);else{var s=r(t.getValue(),i,t);if(!s)return;s.then?s.then((function(e){t.operation((function(){l(t,e)}))})):t.operation((function(){l(t,s)}))}}function l(e,n){s(e);for(var i,r,c=e.state.lint,l=c.options,d=function(e){for(var t=[],n=0;n<e.length;++n){var i=e[n],r=i.from.line;(t[r]||(t[r]=[])).push(i)}return t}(n),u=0;u<d.length;++u){var h=d[u];if(h){for(var p=null,f=c.hasGutter&&document.createDocumentFragment(),m=0;m<h.length;++m){var g=h[m],v=g.severity;v||(v="error"),r=v,p="error"==(i=p)?i:r,l.formatAnnotation&&(g=l.formatAnnotation(g)),c.hasGutter&&f.appendChild(a(g)),g.to&&c.marked.push(e.markText(g.from,g.to,{className:"CodeMirror-lint-mark-"+v,__annotation:g}))}c.hasGutter&&e.setGutterMarker(u,t,o(f,p,h.length>1,c.options.tooltips))}}l.onUpdateLinting&&l.onUpdateLinting(n,d,e)}function d(e){var t=e.state.lint;t&&(clearTimeout(t.timeout),t.timeout=setTimeout((function(){c(e)}),t.options.delay||500))}e.defineOption("lint",!1,(function(n,i,o){if(o&&o!=e.Init&&(s(n),!1!==n.state.lint.options.lintOnChange&&n.off("change",d),e.off(n.getWrapperElement(),"mouseover",n.state.lint.onMouseOver),clearTimeout(n.state.lint.timeout),delete n.state.lint),i){for(var a=n.getOption("gutters"),l=!1,u=0;u<a.length;++u)a[u]==t&&(l=!0);var h=n.state.lint=new r(n,(p=i)instanceof Function?{getAnnotations:p}:(p&&!0!==p||(p={}),p),l);!1!==h.options.lintOnChange&&n.on("change",d),0!=h.options.tooltips&&"gutter"!=h.options.tooltips&&e.on(n.getWrapperElement(),"mouseover",h.onMouseOver),c(n)}var p})),e.defineExtension("performLint",(function(){this.state.lint&&c(this)}))}(n(65))},function(e,t,n){},function(e,t){e.exports=function(e){function t(e){for(var t={},n=e.split(" "),i=0;i<n.length;++i)t[n[i]]=!0;return t}e.defineMode("glsl",(function(e,r){var s,o=e.indentUnit,a=r.keywords||t(n),c=r.builtins||t(i),l=r.blockKeywords||t("case do else for if switch while struct"),d=r.atoms||t("null"),u=r.hooks||{},h=r.multiLineStrings,p=/[+\-*&%=<>!?|\/]/;function f(e,t){var n,i=e.next();if(u[i]){var r=u[i](e,t);if(!1!==r)return r}if('"'==i||"'"==i)return t.tokenize=(n=i,function(e,t){for(var i,r=!1,s=!1;null!=(i=e.next());){if(i==n&&!r){s=!0;break}r=!r&&"\\"==i}return(s||!r&&!h)&&(t.tokenize=f),"string"}),t.tokenize(e,t);if(/[\[\]{}\(\),;\:\.]/.test(i))return s=i,"bracket";if(/\d/.test(i))return e.eatWhile(/[\w\.]/),"number";if("/"==i){if(e.eat("*"))return t.tokenize=m,m(e,t);if(e.eat("/"))return e.skipToEnd(),"comment"}if("#"==i)return e.eatWhile(/[\S]+/),e.eatWhile(/[\s]+/),e.eatWhile(/[\S]+/),e.eatWhile(/[\s]+/),"comment";if(p.test(i))return e.eatWhile(p),"operator";e.eatWhile(/[\w\$_]/);var o=e.current();return a.propertyIsEnumerable(o)?(l.propertyIsEnumerable(o)&&(s="newstatement"),"keyword"):c.propertyIsEnumerable(o)?"builtin":d.propertyIsEnumerable(o)?"atom":"word"}function m(e,t){for(var n,i=!1;n=e.next();){if("/"==n&&i){t.tokenize=f;break}i="*"==n}return"comment"}function g(e,t,n,i,r){this.indented=e,this.column=t,this.type=n,this.align=i,this.prev=r}function v(e,t,n){return e.context=new g(e.indented,t,n,null,e.context)}function b(e){var t=e.context.type;return")"!=t&&"]"!=t&&"}"!=t||(e.indented=e.context.indented),e.context=e.context.prev}return{startState:function(e){return{tokenize:null,context:new g((e||0)-o,0,"top",!1),indented:0,startOfLine:!0}},token:function(e,t){var n=t.context;if(e.sol()&&(null==n.align&&(n.align=!1),t.indented=e.indentation(),t.startOfLine=!0),e.eatSpace())return null;s=null;var i=(t.tokenize||f)(e,t);if("comment"==i||"meta"==i)return i;if(null==n.align&&(n.align=!0),";"!=s&&":"!=s||"statement"!=n.type)if("{"==s)v(t,e.column(),"}");else if("["==s)v(t,e.column(),"]");else if("("==s)v(t,e.column(),")");else if("}"==s){for(;"statement"==n.type;)n=b(t);for("}"==n.type&&(n=b(t));"statement"==n.type;)n=b(t)}else s==n.type?b(t):("}"==n.type||"top"==n.type||"statement"==n.type&&"newstatement"==s)&&v(t,e.column(),"statement");else b(t);return t.startOfLine=!1,i},indent:function(e,t){if(e.tokenize!=f&&null!=e.tokenize)return 0;var n=t&&t.charAt(0),i=e.context,r=n==i.type;return"statement"==i.type?i.indented+("{"==n?0:o):i.align?i.column+(r?0:1):i.indented+(r?0:o)},electricChars:"{}"}}));var n="attribute const uniform varying break continue do for while if else in out inout float int void bool true false lowp mediump highp precision invariant discard return mat2 mat3 mat4 vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 sampler2D samplerCube struct gl_FragCoord gl_FragColor",i="radians degrees sin cos tan asin acos atan pow exp log exp2 log2 sqrt inversesqrt abs sign floor ceil fract mod min max clamp mix step smoothstep length distance dot cross normalize faceforward reflect refract matrixCompMult lessThan lessThanEqual greaterThan greaterThanEqual equal notEqual any all not dFdx dFdy fwidth texture2D texture2DProj texture2DLod texture2DProjLod textureCube textureCubeLod require export";function r(e,t){return!!t.startOfLine&&(e.skipToEnd(),"meta")}e.defineMIME("text/x-glsl",{name:"glsl",keywords:t(n),builtins:t(i),blockKeywords:t("case do else for if switch while struct"),atoms:t("null"),hooks:{"#":r}})}},function(e,t,n){},function(e,t,n){"use strict";n.r(t),n.d(t,"SingleMeshUserLayer",(function(){return f}));n(221);var i=n(23),r=n(67),s=n(109),o=n(4),a=n(2),c=n(6),l=n(95),d=n(96),u=n(97),h=n(48),p=n(98);class f extends i.k{constructor(e,t){super(e,t),this.managedLayer=e,this.displayState=new s.a,this.vertexAttributes=new o.e(void 0),this.registerDisposer(this.displayState.shaderControlState.changed.add(this.specificationChanged.dispatch)),this.registerDisposer(this.displayState.fragmentMain.changed.add(this.specificationChanged.dispatch)),this.tabs.add("rendering",{label:"Rendering",order:-100,getter:()=>new b(this)}),this.tabs.default="rendering"}restoreState(e){super.restoreState(e),this.displayState.fragmentMain.restoreState(e.shader),this.displayState.shaderControlState.restoreState(e.shaderControls)}activateDataSubsources(e){let t=!1;for(const n of e){const{subsourceEntry:e}=n,{subsource:i}=e,{singleMesh:r}=i;if(void 0===r)n.deactivate("Not compatible with image layer");else{if(t){n.deactivate("Only one single-mesh source supported");continue}t=!0,n.activate(e=>{n.addRenderLayer(new s.b(r,this.displayState,n.getRenderLayerTransform())),this.vertexAttributes.value=r.info.vertexAttributes,e.registerDisposer(()=>{this.vertexAttributes.value=void 0})})}}}toJSON(){let e=super.toJSON();return e.shader=this.displayState.fragmentMain.toJSON(),e.shaderControls=this.displayState.shaderControlState.toJSON(),e}}function m(e){return new u.a({fragmentMain:e.displayState.fragmentMain,shaderError:e.displayState.shaderError,shaderControlState:e.displayState.shaderControlState})}f.type="mesh";class g extends a.a{constructor(e){super(),this.attributes=e,this.element=document.createElement("div"),this.element.className="neuroglancer-single-mesh-attribute-widget",this.updateView(),this.registerDisposer(e.changed.add(()=>{this.updateView()}))}updateView(){const{element:e}=this,t=this.attributes.value;if(void 0===t)return void Object(c.b)(e);const n=Object(s.e)(t.map(e=>e.name)),i=t.length;for(let r=0;r<i;++r){const i=t[r],o=document.createElement("div");o.className="neuroglancer-single-mesh-attribute";const a=document.createElement("div");a.className="neuroglancer-single-mesh-attribute-type",a.textContent=Object(s.c)(i);const c=document.createElement("div");if(c.className="neuroglancer-single-mesh-attribute-name",c.textContent=n[r],o.appendChild(a),o.appendChild(c),void 0!==i.min&&void 0!==i.max){const e=document.createElement("neuroglancer-single-mesh-attribute-minmax");e.className="neuroglancer-single-mesh-attribute-range",e.textContent=`[${i.min.toPrecision(6)}, ${i.max.toPrecision(6)}]`,o.appendChild(e)}e.appendChild(o)}}disposed(){Object(c.c)(this.element)}}function v(e){return new g(e.vertexAttributes)}class b extends h.b{constructor(e){super(),this.layer=e,this.attributeWidget=this.registerDisposer(v(this.layer)),this.codeWidget=this.registerDisposer(m(this.layer));const{element:t}=this;t.classList.add("neuroglancer-single-mesh-dropdown");let n=document.createElement("div");n.className="neuroglancer-single-mesh-dropdown-top-row";let i=document.createElement("div");i.style.flex="1",n.appendChild(i),n.appendChild(Object(d.a)({title:"Show larger editor view",onClick:()=>{new y(this.layer)}})),n.appendChild(Object(l.a)({title:"Documentation on single mesh layer rendering",href:"https://github.com/google/neuroglancer/blob/master/src/neuroglancer/sliceview/image_layer_rendering.md"})),t.appendChild(n),t.appendChild(this.attributeWidget.element),t.appendChild(this.codeWidget.element),t.appendChild(this.registerDisposer(new p.a(e.displayState.shaderControlState)).element)}}class y extends r.a{constructor(e){super(),this.layer=e,this.attributeWidget=this.registerDisposer(v(this.layer)),this.codeWidget=this.registerDisposer(m(this.layer)),this.content.classList.add("neuroglancer-single-mesh-layer-shader-overlay"),this.content.appendChild(this.attributeWidget.element),this.content.appendChild(this.codeWidget.element),this.codeWidget.textEditor.refresh()}}Object(i.r)("mesh",f),Object(i.s)(e=>{if(void 0!==e.singleMesh)return f})},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){!function(e){"use strict";e.defineMode("javascript",(function(t,n){var i,r,s=t.indentUnit,o=n.statementIndent,a=n.jsonld,c=n.json||a,l=n.typescript,d=n.wordCharacters||/[\w$\xa1-\uffff]/,u=function(){function e(e){return{type:e,style:"keyword"}}var t=e("keyword a"),n=e("keyword b"),i=e("keyword c"),r=e("keyword d"),s=e("operator"),o={type:"atom",style:"atom"};return{if:e("if"),while:t,with:t,else:n,do:n,try:n,finally:n,return:r,break:r,continue:r,new:e("new"),delete:i,void:i,throw:i,debugger:e("debugger"),var:e("var"),const:e("var"),let:e("var"),function:e("function"),catch:e("catch"),for:e("for"),switch:e("switch"),case:e("case"),default:e("default"),in:s,typeof:s,instanceof:s,true:o,false:o,null:o,undefined:o,NaN:o,Infinity:o,this:e("this"),class:e("class"),super:e("atom"),yield:i,export:e("export"),import:e("import"),extends:i,await:i}}(),h=/[+\-*&%=<>!?|~^@]/,p=/^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;function f(e,t,n){return i=e,r=n,t}function m(e,t){var n,i=e.next();if('"'==i||"'"==i)return t.tokenize=(n=i,function(e,t){var i,r=!1;if(a&&"@"==e.peek()&&e.match(p))return t.tokenize=m,f("jsonld-keyword","meta");for(;null!=(i=e.next())&&(i!=n||r);)r=!r&&"\\"==i;return r||(t.tokenize=m),f("string","string")}),t.tokenize(e,t);if("."==i&&e.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/))return f("number","number");if("."==i&&e.match(".."))return f("spread","meta");if(/[\[\]{}\(\),;\:\.]/.test(i))return f(i);if("="==i&&e.eat(">"))return f("=>","operator");if("0"==i&&e.match(/^(?:x[\dA-Fa-f_]+|o[0-7_]+|b[01_]+)n?/))return f("number","number");if(/\d/.test(i))return e.match(/^[\d_]*(?:n|(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?/),f("number","number");if("/"==i)return e.eat("*")?(t.tokenize=g,g(e,t)):e.eat("/")?(e.skipToEnd(),f("comment","comment")):Je(e,t,1)?(function(e){for(var t,n=!1,i=!1;null!=(t=e.next());){if(!n){if("/"==t&&!i)return;"["==t?i=!0:i&&"]"==t&&(i=!1)}n=!n&&"\\"==t}}(e),e.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/),f("regexp","string-2")):(e.eat("="),f("operator","operator",e.current()));if("`"==i)return t.tokenize=v,v(e,t);if("#"==i)return e.skipToEnd(),f("error","error");if("<"==i&&e.match("!--")||"-"==i&&e.match("->"))return e.skipToEnd(),f("comment","comment");if(h.test(i))return">"==i&&t.lexical&&">"==t.lexical.type||(e.eat("=")?"!"!=i&&"="!=i||e.eat("="):/[<>*+\-]/.test(i)&&(e.eat(i),">"==i&&e.eat(i))),f("operator","operator",e.current());if(d.test(i)){e.eatWhile(d);var r=e.current();if("."!=t.lastType){if(u.propertyIsEnumerable(r)){var s=u[r];return f(s.type,s.style,r)}if("async"==r&&e.match(/^(\s|\/\*.*?\*\/)*[\[\(\w]/,!1))return f("async","keyword",r)}return f("variable","variable",r)}}function g(e,t){for(var n,i=!1;n=e.next();){if("/"==n&&i){t.tokenize=m;break}i="*"==n}return f("comment","comment")}function v(e,t){for(var n,i=!1;null!=(n=e.next());){if(!i&&("`"==n||"$"==n&&e.eat("{"))){t.tokenize=m;break}i=!i&&"\\"==n}return f("quasi","string-2",e.current())}function b(e,t){t.fatArrowAt&&(t.fatArrowAt=null);var n=e.string.indexOf("=>",e.start);if(!(n<0)){if(l){var i=/:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(e.string.slice(e.start,n));i&&(n=i.index)}for(var r=0,s=!1,o=n-1;o>=0;--o){var a=e.string.charAt(o),c="([{}])".indexOf(a);if(c>=0&&c<3){if(!r){++o;break}if(0==--r){"("==a&&(s=!0);break}}else if(c>=3&&c<6)++r;else if(d.test(a))s=!0;else if(/["'\/`]/.test(a))for(;;--o){if(0==o)return;if(e.string.charAt(o-1)==a&&"\\"!=e.string.charAt(o-2)){o--;break}}else if(s&&!r){++o;break}}s&&!r&&(t.fatArrowAt=o)}}var y={atom:!0,number:!0,variable:!0,string:!0,regexp:!0,this:!0,"jsonld-keyword":!0};function S(e,t,n,i,r,s){this.indented=e,this.column=t,this.type=n,this.prev=r,this.info=s,null!=i&&(this.align=i)}function w(e,t){for(var n=e.localVars;n;n=n.next)if(n.name==t)return!0;for(var i=e.context;i;i=i.prev)for(n=i.vars;n;n=n.next)if(n.name==t)return!0}var x={state:null,column:null,marked:null,cc:null};function C(){for(var e=arguments.length-1;e>=0;e--)x.cc.push(arguments[e])}function O(){return C.apply(null,arguments),!0}function k(e,t){for(var n=t;n;n=n.next)if(n.name==e)return!0;return!1}function E(e){var t=x.state;if(x.marked="def",t.context)if("var"==t.lexical.info&&t.context&&t.context.block){var i=function e(t,n){if(n){if(n.block){var i=e(t,n.prev);return i?i==n.prev?n:new M(i,n.vars,!0):null}return k(t,n.vars)?n:new M(n.prev,new D(t,n.vars),!1)}return null}(e,t.context);if(null!=i)return void(t.context=i)}else if(!k(e,t.localVars))return void(t.localVars=new D(e,t.localVars));n.globalVars&&!k(e,t.globalVars)&&(t.globalVars=new D(e,t.globalVars))}function T(e){return"public"==e||"private"==e||"protected"==e||"abstract"==e||"readonly"==e}function M(e,t,n){this.prev=e,this.vars=t,this.block=n}function D(e,t){this.name=e,this.next=t}var L=new D("this",new D("arguments",null));function j(){x.state.context=new M(x.state.context,x.state.localVars,!1),x.state.localVars=L}function I(){x.state.context=new M(x.state.context,x.state.localVars,!0),x.state.localVars=null}function P(){x.state.localVars=x.state.context.vars,x.state.context=x.state.context.prev}function A(e,t){var n=function(){var n=x.state,i=n.indented;if("stat"==n.lexical.type)i=n.lexical.indented;else for(var r=n.lexical;r&&")"==r.type&&r.align;r=r.prev)i=r.indented;n.lexical=new S(i,x.stream.column(),e,null,n.lexical,t)};return n.lex=!0,n}function R(){var e=x.state;e.lexical.prev&&(")"==e.lexical.type&&(e.indented=e.lexical.indented),e.lexical=e.lexical.prev)}function N(e){return function t(n){return n==e?O():";"==e||"}"==n||")"==n||"]"==n?C():O(t)}}function V(e,t){return"var"==e?O(A("vardef",t),be,N(";"),R):"keyword a"==e?O(A("form"),z,V,R):"keyword b"==e?O(A("form"),V,R):"keyword d"==e?x.stream.match(/^\s*$/,!1)?O():O(A("stat"),G,N(";"),R):"debugger"==e?O(N(";")):"{"==e?O(A("}"),I,se,R,P):";"==e?O():"if"==e?("else"==x.state.lexical.info&&x.state.cc[x.state.cc.length-1]==R&&x.state.cc.pop()(),O(A("form"),z,V,R,Oe)):"function"==e?O(Me):"for"==e?O(A("form"),ke,V,R):"class"==e||l&&"interface"==t?(x.marked="keyword",O(A("form","class"==e?e:t),Pe,R)):"variable"==e?l&&"declare"==t?(x.marked="keyword",O(V)):l&&("module"==t||"enum"==t||"type"==t)&&x.stream.match(/^\s*\w/,!1)?(x.marked="keyword","enum"==t?O(We):"type"==t?O(Le,N("operator"),de,N(";")):O(A("form"),ye,N("{"),A("}"),se,R,R)):l&&"namespace"==t?(x.marked="keyword",O(A("form"),B,V,R)):l&&"abstract"==t?(x.marked="keyword",O(V)):O(A("stat"),Q):"switch"==e?O(A("form"),z,N("{"),A("}","switch"),I,se,R,R,P):"case"==e?O(B,N(":")):"default"==e?O(N(":")):"catch"==e?O(A("form"),j,_,V,R,P):"export"==e?O(A("stat"),Ve,R):"import"==e?O(A("stat"),Be,R):"async"==e?O(V):"@"==t?O(B,V):C(A("stat"),B,N(";"),R)}function _(e){if("("==e)return O(je,N(")"))}function B(e,t){return U(e,t,!1)}function F(e,t){return U(e,t,!0)}function z(e){return"("!=e?C():O(A(")"),B,N(")"),R)}function U(e,t,n){if(x.state.fatArrowAt==x.stream.start){var i=n?Y:q;if("("==e)return O(j,A(")"),ie(je,")"),R,N("=>"),i,P);if("variable"==e)return C(j,ye,N("=>"),i,P)}var r=n?W:$;return y.hasOwnProperty(e)?O(r):"function"==e?O(Me,r):"class"==e||l&&"interface"==t?(x.marked="keyword",O(A("form"),Ie,R)):"keyword c"==e||"async"==e?O(n?F:B):"("==e?O(A(")"),G,N(")"),R,r):"operator"==e||"spread"==e?O(n?F:B):"["==e?O(A("]"),$e,R,r):"{"==e?re(ee,"}",null,r):"quasi"==e?C(H,r):"new"==e?O(function(e){return function(t){return"."==t?O(e?K:X):"variable"==t&&l?O(me,e?W:$):C(e?F:B)}}(n)):"import"==e?O(B):O()}function G(e){return e.match(/[;\}\)\],]/)?C():C(B)}function $(e,t){return","==e?O(B):W(e,t,!1)}function W(e,t,n){var i=0==n?$:W,r=0==n?B:F;return"=>"==e?O(j,n?Y:q,P):"operator"==e?/\+\+|--/.test(t)||l&&"!"==t?O(i):l&&"<"==t&&x.stream.match(/^([^>]|<.*?>)*>\s*\(/,!1)?O(A(">"),ie(de,">"),R,i):"?"==t?O(B,N(":"),r):O(r):"quasi"==e?C(H,i):";"!=e?"("==e?re(F,")","call",i):"."==e?O(Z,i):"["==e?O(A("]"),G,N("]"),R,i):l&&"as"==t?(x.marked="keyword",O(de,i)):"regexp"==e?(x.state.lastType=x.marked="operator",x.stream.backUp(x.stream.pos-x.stream.start-1),O(r)):void 0:void 0}function H(e,t){return"quasi"!=e?C():"${"!=t.slice(t.length-2)?O(H):O(B,J)}function J(e){if("}"==e)return x.marked="string-2",x.state.tokenize=v,O(H)}function q(e){return b(x.stream,x.state),C("{"==e?V:B)}function Y(e){return b(x.stream,x.state),C("{"==e?V:F)}function X(e,t){if("target"==t)return x.marked="keyword",O($)}function K(e,t){if("target"==t)return x.marked="keyword",O(W)}function Q(e){return":"==e?O(R,V):C($,N(";"),R)}function Z(e){if("variable"==e)return x.marked="property",O()}function ee(e,t){return"async"==e?(x.marked="property",O(ee)):"variable"==e||"keyword"==x.style?(x.marked="property","get"==t||"set"==t?O(te):(l&&x.state.fatArrowAt==x.stream.start&&(n=x.stream.match(/^\s*:\s*/,!1))&&(x.state.fatArrowAt=x.stream.pos+n[0].length),O(ne))):"number"==e||"string"==e?(x.marked=a?"property":x.style+" property",O(ne)):"jsonld-keyword"==e?O(ne):l&&T(t)?(x.marked="keyword",O(ee)):"["==e?O(B,oe,N("]"),ne):"spread"==e?O(F,ne):"*"==t?(x.marked="keyword",O(ee)):":"==e?C(ne):void 0;var n}function te(e){return"variable"!=e?C(ne):(x.marked="property",O(Me))}function ne(e){return":"==e?O(F):"("==e?C(Me):void 0}function ie(e,t,n){function i(r,s){if(n?n.indexOf(r)>-1:","==r){var o=x.state.lexical;return"call"==o.info&&(o.pos=(o.pos||0)+1),O((function(n,i){return n==t||i==t?C():C(e)}),i)}return r==t||s==t?O():n&&n.indexOf(";")>-1?C(e):O(N(t))}return function(n,r){return n==t||r==t?O():C(e,i)}}function re(e,t,n){for(var i=3;i<arguments.length;i++)x.cc.push(arguments[i]);return O(A(t,n),ie(e,t),R)}function se(e){return"}"==e?O():C(V,se)}function oe(e,t){if(l){if(":"==e)return O(de);if("?"==t)return O(oe)}}function ae(e,t){if(l&&(":"==e||"in"==t))return O(de)}function ce(e){if(l&&":"==e)return x.stream.match(/^\s*\w+\s+is\b/,!1)?O(B,le,de):O(de)}function le(e,t){if("is"==t)return x.marked="keyword",O()}function de(e,t){return"keyof"==t||"typeof"==t||"infer"==t?(x.marked="keyword",O("typeof"==t?F:de)):"variable"==e||"void"==t?(x.marked="type",O(fe)):"|"==t||"&"==t?O(de):"string"==e||"number"==e||"atom"==e?O(fe):"["==e?O(A("]"),ie(de,"]",","),R,fe):"{"==e?O(A("}"),ie(he,"}",",;"),R,fe):"("==e?O(ie(pe,")"),ue,fe):"<"==e?O(ie(de,">"),de):void 0}function ue(e){if("=>"==e)return O(de)}function he(e,t){return"variable"==e||"keyword"==x.style?(x.marked="property",O(he)):"?"==t||"number"==e||"string"==e?O(he):":"==e?O(de):"["==e?O(N("variable"),ae,N("]"),he):"("==e?C(De,he):void 0}function pe(e,t){return"variable"==e&&x.stream.match(/^\s*[?:]/,!1)||"?"==t?O(pe):":"==e?O(de):"spread"==e?O(pe):C(de)}function fe(e,t){return"<"==t?O(A(">"),ie(de,">"),R,fe):"|"==t||"."==e||"&"==t?O(de):"["==e?O(de,N("]"),fe):"extends"==t||"implements"==t?(x.marked="keyword",O(de)):"?"==t?O(de,N(":"),de):void 0}function me(e,t){if("<"==t)return O(A(">"),ie(de,">"),R,fe)}function ge(){return C(de,ve)}function ve(e,t){if("="==t)return O(de)}function be(e,t){return"enum"==t?(x.marked="keyword",O(We)):C(ye,oe,xe,Ce)}function ye(e,t){return l&&T(t)?(x.marked="keyword",O(ye)):"variable"==e?(E(t),O()):"spread"==e?O(ye):"["==e?re(we,"]"):"{"==e?re(Se,"}"):void 0}function Se(e,t){return"variable"!=e||x.stream.match(/^\s*:/,!1)?("variable"==e&&(x.marked="property"),"spread"==e?O(ye):"}"==e?C():"["==e?O(B,N("]"),N(":"),Se):O(N(":"),ye,xe)):(E(t),O(xe))}function we(){return C(ye,xe)}function xe(e,t){if("="==t)return O(F)}function Ce(e){if(","==e)return O(be)}function Oe(e,t){if("keyword b"==e&&"else"==t)return O(A("form","else"),V,R)}function ke(e,t){return"await"==t?O(ke):"("==e?O(A(")"),Ee,R):void 0}function Ee(e){return"var"==e?O(be,Te):"variable"==e?O(Te):C(Te)}function Te(e,t){return")"==e?O():";"==e?O(Te):"in"==t||"of"==t?(x.marked="keyword",O(B,Te)):C(B,Te)}function Me(e,t){return"*"==t?(x.marked="keyword",O(Me)):"variable"==e?(E(t),O(Me)):"("==e?O(j,A(")"),ie(je,")"),R,ce,V,P):l&&"<"==t?O(A(">"),ie(ge,">"),R,Me):void 0}function De(e,t){return"*"==t?(x.marked="keyword",O(De)):"variable"==e?(E(t),O(De)):"("==e?O(j,A(")"),ie(je,")"),R,ce,P):l&&"<"==t?O(A(">"),ie(ge,">"),R,De):void 0}function Le(e,t){return"keyword"==e||"variable"==e?(x.marked="type",O(Le)):"<"==t?O(A(">"),ie(ge,">"),R):void 0}function je(e,t){return"@"==t&&O(B,je),"spread"==e?O(je):l&&T(t)?(x.marked="keyword",O(je)):l&&"this"==e?O(oe,xe):C(ye,oe,xe)}function Ie(e,t){return"variable"==e?Pe(e,t):Ae(e,t)}function Pe(e,t){if("variable"==e)return E(t),O(Ae)}function Ae(e,t){return"<"==t?O(A(">"),ie(ge,">"),R,Ae):"extends"==t||"implements"==t||l&&","==e?("implements"==t&&(x.marked="keyword"),O(l?de:B,Ae)):"{"==e?O(A("}"),Re,R):void 0}function Re(e,t){return"async"==e||"variable"==e&&("static"==t||"get"==t||"set"==t||l&&T(t))&&x.stream.match(/^\s+[\w$\xa1-\uffff]/,!1)?(x.marked="keyword",O(Re)):"variable"==e||"keyword"==x.style?(x.marked="property",O(l?Ne:Me,Re)):"number"==e||"string"==e?O(l?Ne:Me,Re):"["==e?O(B,oe,N("]"),l?Ne:Me,Re):"*"==t?(x.marked="keyword",O(Re)):l&&"("==e?C(De,Re):";"==e||","==e?O(Re):"}"==e?O():"@"==t?O(B,Re):void 0}function Ne(e,t){if("?"==t)return O(Ne);if(":"==e)return O(de,xe);if("="==t)return O(F);var n=x.state.lexical.prev;return C(n&&"interface"==n.info?De:Me)}function Ve(e,t){return"*"==t?(x.marked="keyword",O(Ge,N(";"))):"default"==t?(x.marked="keyword",O(B,N(";"))):"{"==e?O(ie(_e,"}"),Ge,N(";")):C(V)}function _e(e,t){return"as"==t?(x.marked="keyword",O(N("variable"))):"variable"==e?C(F,_e):void 0}function Be(e){return"string"==e?O():"("==e?C(B):C(Fe,ze,Ge)}function Fe(e,t){return"{"==e?re(Fe,"}"):("variable"==e&&E(t),"*"==t&&(x.marked="keyword"),O(Ue))}function ze(e){if(","==e)return O(Fe,ze)}function Ue(e,t){if("as"==t)return x.marked="keyword",O(Fe)}function Ge(e,t){if("from"==t)return x.marked="keyword",O(B)}function $e(e){return"]"==e?O():C(ie(F,"]"))}function We(){return C(A("form"),ye,N("{"),A("}"),ie(He,"}"),R,R)}function He(){return C(ye,xe)}function Je(e,t,n){return t.tokenize==m&&/^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(t.lastType)||"quasi"==t.lastType&&/\{\s*$/.test(e.string.slice(0,e.pos-(n||0)))}return P.lex=!0,R.lex=!0,{startState:function(e){var t={tokenize:m,lastType:"sof",cc:[],lexical:new S((e||0)-s,0,"block",!1),localVars:n.localVars,context:n.localVars&&new M(null,null,!1),indented:e||0};return n.globalVars&&"object"==typeof n.globalVars&&(t.globalVars=n.globalVars),t},token:function(e,t){if(e.sol()&&(t.lexical.hasOwnProperty("align")||(t.lexical.align=!1),t.indented=e.indentation(),b(e,t)),t.tokenize!=g&&e.eatSpace())return null;var n=t.tokenize(e,t);return"comment"==i?n:(t.lastType="operator"!=i||"++"!=r&&"--"!=r?i:"incdec",function(e,t,n,i,r){var s=e.cc;for(x.state=e,x.stream=r,x.marked=null,x.cc=s,x.style=t,e.lexical.hasOwnProperty("align")||(e.lexical.align=!0);;)if((s.length?s.pop():c?B:V)(n,i)){for(;s.length&&s[s.length-1].lex;)s.pop()();return x.marked?x.marked:"variable"==n&&w(e,i)?"variable-2":t}}(t,n,i,r,e))},indent:function(t,i){if(t.tokenize==g)return e.Pass;if(t.tokenize!=m)return 0;var r,a=i&&i.charAt(0),c=t.lexical;if(!/^\s*else\b/.test(i))for(var l=t.cc.length-1;l>=0;--l){var d=t.cc[l];if(d==R)c=c.prev;else if(d!=Oe)break}for(;("stat"==c.type||"form"==c.type)&&("}"==a||(r=t.cc[t.cc.length-1])&&(r==$||r==W)&&!/^[,\.=+\-*:?[\(]/.test(i));)c=c.prev;o&&")"==c.type&&"stat"==c.prev.type&&(c=c.prev);var u=c.type,p=a==u;return"vardef"==u?c.indented+("operator"==t.lastType||","==t.lastType?c.info.length+1:0):"form"==u&&"{"==a?c.indented:"form"==u?c.indented+s:"stat"==u?c.indented+(function(e,t){return"operator"==e.lastType||","==e.lastType||h.test(t.charAt(0))||/[,.]/.test(t.charAt(0))}(t,i)?o||s:0):"switch"!=c.info||p||0==n.doubleIndentSwitch?c.align?c.column+(p?0:1):c.indented+(p?0:s):c.indented+(/^(?:case|default)\b/.test(i)?s:2*s)},electricInput:/^\s*(?:case .*?:|default:|\{|\})$/,blockCommentStart:c?null:"/*",blockCommentEnd:c?null:"*/",blockCommentContinue:c?null:" * ",lineComment:c?null:"//",fold:"brace",closeBrackets:"()[]{}''\"\"``",helperType:c?"json":"javascript",jsonldMode:a,jsonMode:c,expressionAllowed:Je,skipExpression:function(e){var t=e.cc[e.cc.length-1];t!=B&&t!=F||e.cc.pop()}}})),e.registerHelper("wordChars","javascript",/[\w$]/),e.defineMIME("text/javascript","javascript"),e.defineMIME("text/ecmascript","javascript"),e.defineMIME("application/javascript","javascript"),e.defineMIME("application/x-javascript","javascript"),e.defineMIME("application/ecmascript","javascript"),e.defineMIME("application/json",{name:"javascript",json:!0}),e.defineMIME("application/x-json",{name:"javascript",json:!0}),e.defineMIME("application/ld+json",{name:"javascript",jsonld:!0}),e.defineMIME("text/typescript",{name:"javascript",typescript:!0}),e.defineMIME("application/typescript",{name:"javascript",typescript:!0})}(n(65))},function(e,t,n){!function(e){"use strict";e.defineOption("foldGutter",!1,(function(t,i,r){var s;r&&r!=e.Init&&(t.clearGutter(t.state.foldGutter.options.gutter),t.state.foldGutter=null,t.off("gutterClick",c),t.off("changes",l),t.off("viewportChange",d),t.off("fold",u),t.off("unfold",u),t.off("swapDoc",l)),i&&(t.state.foldGutter=new n((!0===(s=i)&&(s={}),null==s.gutter&&(s.gutter="CodeMirror-foldgutter"),null==s.indicatorOpen&&(s.indicatorOpen="CodeMirror-foldgutter-open"),null==s.indicatorFolded&&(s.indicatorFolded="CodeMirror-foldgutter-folded"),s)),a(t),t.on("gutterClick",c),t.on("changes",l),t.on("viewportChange",d),t.on("fold",u),t.on("unfold",u),t.on("swapDoc",l))}));var t=e.Pos;function n(e){this.options=e,this.from=this.to=0}function i(e,n){for(var i=e.findMarks(t(n,0),t(n+1,0)),r=0;r<i.length;++r)if(i[r].__isFold){var s=i[r].find(-1);if(s&&s.line===n)return i[r]}}function r(e){if("string"==typeof e){var t=document.createElement("div");return t.className=e+" CodeMirror-guttermarker-subtle",t}return e.cloneNode(!0)}function s(e,n,s){var a=e.state.foldGutter.options,c=n-1,l=e.foldOption(a,"minFoldSize"),d=e.foldOption(a,"rangeFinder"),u="string"==typeof a.indicatorFolded&&o(a.indicatorFolded),h="string"==typeof a.indicatorOpen&&o(a.indicatorOpen);e.eachLine(n,s,(function(n){++c;var s=null,o=n.gutterMarkers;if(o&&(o=o[a.gutter]),i(e,c)){if(u&&o&&u.test(o.className))return;s=r(a.indicatorFolded)}else{var p=t(c,0),f=d&&d(e,p);if(f&&f.to.line-f.from.line>=l){if(h&&o&&h.test(o.className))return;s=r(a.indicatorOpen)}}(s||o)&&e.setGutterMarker(n,a.gutter,s)}))}function o(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function a(e){var t=e.getViewport(),n=e.state.foldGutter;n&&(e.operation((function(){s(e,t.from,t.to)})),n.from=t.from,n.to=t.to)}function c(e,n,r){var s=e.state.foldGutter;if(s){var o=s.options;if(r==o.gutter){var a=i(e,n);a?a.clear():e.foldCode(t(n,0),o)}}}function l(e){var t=e.state.foldGutter;if(t){var n=t.options;t.from=t.to=0,clearTimeout(t.changeUpdate),t.changeUpdate=setTimeout((function(){a(e)}),n.foldOnChangeTimeSpan||600)}}function d(e){var t=e.state.foldGutter;if(t){var n=t.options;clearTimeout(t.changeUpdate),t.changeUpdate=setTimeout((function(){var n=e.getViewport();t.from==t.to||n.from-t.to>20||t.from-n.to>20?a(e):e.operation((function(){n.from<t.from&&(s(e,n.from,t.from),t.from=n.from),n.to>t.to&&(s(e,t.to,n.to),t.to=n.to)}))}),n.updateViewportTimeSpan||400)}}function u(e,t){var n=e.state.foldGutter;if(n){var i=t.line;i>=n.from&&i<n.to&&s(e,i,i+1)}}}(n(65),n(159))},function(e,t,n){!function(e){"use strict";e.registerHelper("fold","brace",(function(t,n){var i,r=n.line,s=t.getLine(r);function o(o){for(var a=n.ch,c=0;;){var l=a<=0?-1:s.lastIndexOf(o,a-1);if(-1!=l){if(1==c&&l<n.ch)break;if(i=t.getTokenTypeAt(e.Pos(r,l+1)),!/^(comment|string)/.test(i))return l+1;a=l-1}else{if(1==c)break;c=1,a=s.length}}}var a="{",c="}",l=o("{");if(null==l&&(a="[",c="]",l=o("[")),null!=l){var d,u,h=1,p=t.lastLine();e:for(var f=r;f<=p;++f)for(var m=t.getLine(f),g=f==r?l:0;;){var v=m.indexOf(a,g),b=m.indexOf(c,g);if(v<0&&(v=m.length),b<0&&(b=m.length),(g=Math.min(v,b))==m.length)break;if(t.getTokenTypeAt(e.Pos(f,g+1))==i)if(g==v)++h;else if(!--h){d=f,u=g;break e}++g}if(null!=d&&r!=d)return{from:e.Pos(r,l),to:e.Pos(d,u)}}})),e.registerHelper("fold","import",(function(t,n){function i(n){if(n<t.firstLine()||n>t.lastLine())return null;var i=t.getTokenAt(e.Pos(n,1));if(/\S/.test(i.string)||(i=t.getTokenAt(e.Pos(n,i.end+1))),"keyword"!=i.type||"import"!=i.string)return null;for(var r=n,s=Math.min(t.lastLine(),n+10);r<=s;++r){var o=t.getLine(r).indexOf(";");if(-1!=o)return{startCh:i.end,end:e.Pos(r,o)}}}var r,s=n.line,o=i(s);if(!o||i(s-1)||(r=i(s-2))&&r.end.line==s-1)return null;for(var a=o.end;;){var c=i(a.line+1);if(null==c)break;a=c.end}return{from:t.clipPos(e.Pos(s,o.startCh+1)),to:a}})),e.registerHelper("fold","include",(function(t,n){function i(n){if(n<t.firstLine()||n>t.lastLine())return null;var i=t.getTokenAt(e.Pos(n,1));return/\S/.test(i.string)||(i=t.getTokenAt(e.Pos(n,i.end+1))),"meta"==i.type&&"#include"==i.string.slice(0,8)?i.start+8:void 0}var r=n.line,s=i(r);if(null==s||null!=i(r-1))return null;for(var o=r;null!=i(o+1);)++o;return{from:e.Pos(r,s+1),to:t.clipPos(e.Pos(o))}}))}(n(65))},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){"use strict";e.exports=[n(246),n(251),n(164),n(165),n(144)(n(165)),n(169),n(144)(n(169)),n(170),n(258),n(144)(n(170)),n(259)]},function(e,t,n){"use strict";var i=n(90),r=n(73),s=n(33),o=n(64).EventEmitter,a=n(250);function c(e,t,n){if(!c.enabled())throw new Error("Transport created when disabled");o.call(this);var s=this,l=r.addPath(e,"/websocket");l="https"===l.slice(0,5)?"wss"+l.slice(5):"ws"+l.slice(4),this.url=l,this.ws=new a(this.url,[],n),this.ws.onmessage=function(e){e.data,s.emit("message",e.data)},this.unloadRef=i.unloadAdd((function(){s.ws.close()})),this.ws.onclose=function(e){e.code,e.reason,s.emit("close",e.code,e.reason),s._cleanup()},this.ws.onerror=function(e){s.emit("close",1006,"WebSocket connection broken"),s._cleanup()}}s(c,o),c.prototype.send=function(e){var t="["+e+"]";this.ws.send(t)},c.prototype.close=function(){var e=this.ws;this._cleanup(),e&&e.close()},c.prototype._cleanup=function(){var e=this.ws;e&&(e.onmessage=e.onclose=e.onerror=null),i.unloadDel(this.unloadRef),this.unloadRef=this.ws=null,this.removeAllListeners()},c.enabled=function(){return!!a},c.transportName="websocket",c.roundTrips=2,e.exports=c},function(e,t,n){"use strict";(function(t){t.crypto&&t.crypto.getRandomValues?e.exports.randomBytes=function(e){var n=new Uint8Array(e);return t.crypto.getRandomValues(n),n}:e.exports.randomBytes=function(e){for(var t=new Array(e),n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t}}).call(this,n(46))},function(e,t,n){"use strict";e.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},function(e,t,n){"use strict";var i=Object.prototype.hasOwnProperty;function r(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}t.stringify=function(e,t){t=t||"";var n,r,s=[];for(r in"string"!=typeof t&&(t="?"),e)if(i.call(e,r)){if((n=e[r])||null!=n&&!isNaN(n)||(n=""),r=encodeURIComponent(r),n=encodeURIComponent(n),null===r||null===n)continue;s.push(r+"="+n)}return s.length?t+s.join("&"):""},t.parse=function(e){for(var t,n=/([^=?&]+)=?([^&]*)/g,i={};t=n.exec(e);){var s=r(t[1]),o=r(t[2]);null===s||null===o||s in i||(i[s]=o)}return i}},function(e,t,n){"use strict";(function(t){var n=t.WebSocket||t.MozWebSocket;e.exports=n?function(e){return new n(e)}:void 0}).call(this,n(46))},function(e,t,n){"use strict";(function(t){var i=n(33),r=n(111),s=n(130),o=n(131),a=n(121),c=n(122);function l(e){if(!a.enabled&&!o.enabled)throw new Error("Transport created when disabled");r.call(this,e,"/xhr_streaming",s,o)}i(l,r),l.enabled=function(e){return!e.nullOrigin&&(!c.isOpera()&&o.enabled)},l.transportName="xhr-streaming",l.roundTrips=2,l.needBody=!!t.document,e.exports=l}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(64).EventEmitter;function s(e,t){r.call(this),this.sendBuffer=[],this.sender=t,this.url=e}i(s,r),s.prototype.send=function(e){this.sendBuffer.push(e),this.sendStop||this.sendSchedule()},s.prototype.sendScheduleWait=function(){var e,t=this;this.sendStop=function(){t.sendStop=null,clearTimeout(e)},e=setTimeout((function(){t.sendStop=null,t.sendSchedule()}),25)},s.prototype.sendSchedule=function(){this.sendBuffer.length;var e=this;if(this.sendBuffer.length>0){var t="["+this.sendBuffer.join(",")+"]";this.sendStop=this.sender(this.url,t,(function(t){e.sendStop=null,t?(e.emit("close",t.code||1006,"Sending error: "+t),e.close()):e.sendScheduleWait()})),this.sendBuffer=[]}},s.prototype._cleanup=function(){this.removeAllListeners()},s.prototype.close=function(){this._cleanup(),this.sendStop&&(this.sendStop(),this.sendStop=null)},e.exports=s},function(e,t,n){"use strict";var i=n(33),r=n(64).EventEmitter;function s(e,t,n){r.call(this),this.Receiver=e,this.receiveUrl=t,this.AjaxObject=n,this._scheduleReceiver()}i(s,r),s.prototype._scheduleReceiver=function(){var e=this,t=this.poll=new this.Receiver(this.receiveUrl,this.AjaxObject);t.on("message",(function(t){e.emit("message",t)})),t.once("close",(function(n,i){e.pollIsClosing,e.poll=t=null,e.pollIsClosing||("network"===i?e._scheduleReceiver():(e.emit("close",n||1006,i),e.removeAllListeners()))}))},s.prototype.abort=function(){this.removeAllListeners(),this.pollIsClosing=!0,this.poll&&this.poll.abort()},e.exports=s},function(e,t,n){"use strict";var i=n(33),r=n(64).EventEmitter,s=n(166);function o(e){r.call(this);var t=this,n=this.es=new s(e);n.onmessage=function(e){e.data,t.emit("message",decodeURI(e.data))},n.onerror=function(e){n.readyState;var i=2!==n.readyState?"network":"permanent";t._cleanup(),t._close(i)}}i(o,r),o.prototype.abort=function(){this._cleanup(),this._close("user")},o.prototype._cleanup=function(){var e=this.es;e&&(e.onmessage=e.onerror=null,e.close(),this.es=null)},o.prototype._close=function(e){var t=this;setTimeout((function(){t.emit("close",null,e),t.removeAllListeners()}),200)},e.exports=o},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t){(function(t){e.exports=t}).call(this,{})},function(e,t,n){"use strict";(function(t){var i=n(33),r=n(123),s=n(73),o=n(64).EventEmitter,a=n(110);function c(e){o.call(this);var n=this;r.polluteGlobalNamespace(),this.id="a"+a.string(6),e=s.addQuery(e,"c="+decodeURIComponent(r.WPrefix+"."+this.id)),c.htmlfileEnabled;var i=c.htmlfileEnabled?r.createHtmlfile:r.createIframe;t[r.WPrefix][this.id]={start:function(){n.iframeObj.loaded()},message:function(e){n.emit("message",e)},stop:function(){n._cleanup(),n._close("network")}},this.iframeObj=i(e,(function(){n._cleanup(),n._close("permanent")}))}i(c,o),c.prototype.abort=function(){this._cleanup(),this._close("user")},c.prototype._cleanup=function(){this.iframeObj&&(this.iframeObj.cleanup(),this.iframeObj=null),delete t[r.WPrefix][this.id]},c.prototype._close=function(e){this.emit("close",null,e),this.removeAllListeners()},c.htmlfileEnabled=!1;var l=["Active"].concat("Object").join("X");if(l in t)try{c.htmlfileEnabled=!!new t[l]("htmlfile")}catch(e){}c.enabled=c.htmlfileEnabled||r.iframeEnabled,e.exports=c}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(111),s=n(164),o=n(130),a=n(143);function c(e){if(!a.enabled)throw new Error("Transport created when disabled");r.call(this,e,"/xhr",o,a)}i(c,r),c.enabled=s.enabled,c.transportName="xdr-polling",c.roundTrips=2,e.exports=c},function(e,t,n){"use strict";(function(t){var i=n(33),r=n(162),s=n(260),o=n(261);function a(e){if(!a.enabled())throw new Error("Transport created when disabled");r.call(this,e,"/jsonp",o,s)}i(a,r),a.enabled=function(){return!!t.document},a.transportName="jsonp-polling",a.roundTrips=1,a.needBody=!0,e.exports=a}).call(this,n(46))},function(e,t,n){"use strict";(function(t){var i=n(123),r=n(110),s=n(122),o=n(73),a=n(33),c=n(64).EventEmitter;function l(e){var n=this;c.call(this),i.polluteGlobalNamespace(),this.id="a"+r.string(6);var s=o.addQuery(e,"c="+encodeURIComponent(i.WPrefix+"."+this.id));t[i.WPrefix][this.id]=this._callback.bind(this),this._createScript(s),this.timeoutId=setTimeout((function(){n._abort(new Error("JSONP script loaded abnormally (timeout)"))}),l.timeout)}a(l,c),l.prototype.abort=function(){if(t[i.WPrefix][this.id]){var e=new Error("JSONP user aborted read");e.code=1e3,this._abort(e)}},l.timeout=35e3,l.scriptErrorTimeout=1e3,l.prototype._callback=function(e){this._cleanup(),this.aborting||(e&&this.emit("message",e),this.emit("close",null,"network"),this.removeAllListeners())},l.prototype._abort=function(e){this._cleanup(),this.aborting=!0,this.emit("close",e.code,e.message),this.removeAllListeners()},l.prototype._cleanup=function(){if(clearTimeout(this.timeoutId),this.script2&&(this.script2.parentNode.removeChild(this.script2),this.script2=null),this.script){var e=this.script;e.parentNode.removeChild(e),e.onreadystatechange=e.onerror=e.onload=e.onclick=null,this.script=null}delete t[i.WPrefix][this.id]},l.prototype._scriptError=function(){var e=this;this.errorTimer||(this.errorTimer=setTimeout((function(){e.loadedOkay||e._abort(new Error("JSONP script loaded abnormally (onerror)"))}),l.scriptErrorTimeout))},l.prototype._createScript=function(e){var n,i=this,o=this.script=t.document.createElement("script");if(o.id="a"+r.string(8),o.src=e,o.type="text/javascript",o.charset="UTF-8",o.onerror=this._scriptError.bind(this),o.onload=function(){i._abort(new Error("JSONP script loaded abnormally (onload)"))},o.onreadystatechange=function(){if(o.readyState,/loaded|closed/.test(o.readyState)){if(o&&o.htmlFor&&o.onclick){i.loadedOkay=!0;try{o.onclick()}catch(e){}}o&&i._abort(new Error("JSONP script loaded abnormally (onreadystatechange)"))}},void 0===o.async&&t.document.attachEvent)if(s.isOpera())(n=this.script2=t.document.createElement("script")).text="try{var a = document.getElementById('"+o.id+"'); if(a)a.onerror();}catch(x){};",o.async=n.async=!1;else{try{o.htmlFor=o.id,o.event="onclick"}catch(e){}o.async=!0}void 0!==o.async&&(o.async=!0);var a=t.document.getElementsByTagName("head")[0];a.insertBefore(o,a.firstChild),n&&a.insertBefore(n,a.firstChild)},e.exports=l}).call(this,n(46))},function(e,t,n){"use strict";(function(t){var i,r,s=n(110),o=n(73);e.exports=function(e,n,a){i||((i=t.document.createElement("form")).style.display="none",i.style.position="absolute",i.method="POST",i.enctype="application/x-www-form-urlencoded",i.acceptCharset="UTF-8",(r=t.document.createElement("textarea")).name="d",i.appendChild(r),t.document.body.appendChild(i));var c="a"+s.string(8);i.target=c,i.action=o.addQuery(o.addPath(e,"/jsonp_send"),"i="+c);var l=function(e){try{return t.document.createElement('<iframe name="'+e+'">')}catch(i){var n=t.document.createElement("iframe");return n.name=e,n}}(c);l.id=c,l.style.display="none",i.appendChild(l);try{r.value=n}catch(e){}i.submit();var d=function(e){l.onerror&&(l.onreadystatechange=l.onerror=l.onload=null,setTimeout((function(){l.parentNode.removeChild(l),l=null}),500),r.value="",a(e))};return l.onerror=function(){d()},l.onload=function(){d()},l.onreadystatechange=function(e){l.readyState,"complete"===l.readyState&&d()},function(){d(new Error("Aborted"))}}}).call(this,n(46))},function(e,t,n){"use strict";(function(t){n(263);var i,r=n(160),s=n(33),o=n(83),a=n(110),c=n(264),l=n(73),d=n(90),u=n(265),h=n(145),p=n(122),f=n(266),m=n(146),g=n(161),v=n(171),b=n(267),y=n(268),S=n(269);function w(e,t,n){if(!(this instanceof w))return new w(e,t,n);if(arguments.length<1)throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");g.call(this),this.readyState=w.CONNECTING,this.extensions="",this.protocol="",(n=n||{}).protocols_whitelist&&f.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead."),this._transportsWhitelist=n.transports,this._transportOptions=n.transportOptions||{},this._timeout=n.timeout||0;var i=n.sessionId||8;if("function"==typeof i)this._generateSessionId=i;else{if("number"!=typeof i)throw new TypeError("If sessionId is used in the options, it needs to be a number or a function.");this._generateSessionId=function(){return a.string(i)}}this._server=n.server||a.numberString(1e3);var s=new r(e);if(!s.host||!s.protocol)throw new SyntaxError("The URL '"+e+"' is invalid");if(s.hash)throw new SyntaxError("The URL must not contain a fragment");if("http:"!==s.protocol&&"https:"!==s.protocol)throw new SyntaxError("The URL's scheme must be either 'http:' or 'https:'. '"+s.protocol+"' is not allowed.");var o="https:"===s.protocol;if("https:"===v.protocol&&!o)throw new Error("SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS");t?Array.isArray(t)||(t=[t]):t=[];var c=t.sort();c.forEach((function(e,t){if(!e)throw new SyntaxError("The protocols entry '"+e+"' is invalid.");if(t<c.length-1&&e===c[t+1])throw new SyntaxError("The protocols entry '"+e+"' is duplicated.")}));var d=l.getOrigin(v.href);this._origin=d?d.toLowerCase():null,s.set("pathname",s.pathname.replace(/\/+$/,"")),this.url=s.href,this.url,this._urlInfo={nullOrigin:!p.hasDomain(),sameOrigin:l.isOriginEqual(this.url,v.href),sameScheme:l.isSchemeEqual(this.url,v.href)},this._ir=new S(this.url,this._urlInfo),this._ir.once("finish",this._receiveInfo.bind(this))}function x(e){return 1e3===e||e>=3e3&&e<=4999}s(w,g),w.prototype.close=function(e,t){if(e&&!x(e))throw new Error("InvalidAccessError: Invalid code");if(t&&t.length>123)throw new SyntaxError("reason argument has an invalid length");if(this.readyState!==w.CLOSING&&this.readyState!==w.CLOSED){this._close(e||1e3,t||"Normal closure",!0)}},w.prototype.send=function(e){if("string"!=typeof e&&(e=""+e),this.readyState===w.CONNECTING)throw new Error("InvalidStateError: The connection has not been established yet");this.readyState===w.OPEN&&this._transport.send(c.quote(e))},w.version=n(168),w.CONNECTING=0,w.OPEN=1,w.CLOSING=2,w.CLOSED=3,w.prototype._receiveInfo=function(e,t){if(this._ir=null,e){this._rto=this.countRTO(t),this._transUrl=e.base_url?e.base_url:this.url,e=h.extend(e,this._urlInfo);var n=i.filterToEnabled(this._transportsWhitelist,e);this._transports=n.main,this._transports.length,this._connect()}else this._close(1002,"Cannot connect to server")},w.prototype._connect=function(){for(var e=this._transports.shift();e;e=this._transports.shift()){if(e.transportName,e.needBody&&(!t.document.body||void 0!==t.document.readyState&&"complete"!==t.document.readyState&&"interactive"!==t.document.readyState))return this._transports.unshift(e),void d.attachEvent("load",this._connect.bind(this));var n=Math.max(this._timeout,this._rto*e.roundTrips||5e3);this._transportTimeoutId=setTimeout(this._transportTimeout.bind(this),n);var i=l.addPath(this._transUrl,"/"+this._server+"/"+this._generateSessionId()),r=this._transportOptions[e.transportName],s=new e(i,this._transUrl,r);return s.on("message",this._transportMessage.bind(this)),s.once("close",this._transportClose.bind(this)),s.transportName=e.transportName,void(this._transport=s)}this._close(2e3,"All transports failed",!1)},w.prototype._transportTimeout=function(){this.readyState===w.CONNECTING&&(this._transport&&this._transport.close(),this._transportClose(2007,"Transport timed out"))},w.prototype._transportMessage=function(e){var t,n=this,i=e.slice(0,1),r=e.slice(1);switch(i){case"o":return void this._open();case"h":return this.dispatchEvent(new m("heartbeat")),void this.transport}if(r)try{t=o.parse(r)}catch(e){}if(void 0!==t)switch(i){case"a":Array.isArray(t)&&t.forEach((function(e){n.transport,n.dispatchEvent(new y(e))}));break;case"m":this.transport,this.dispatchEvent(new y(t));break;case"c":Array.isArray(t)&&2===t.length&&this._close(t[0],t[1],!0)}},w.prototype._transportClose=function(e,t){this.transport,this._transport&&(this._transport.removeAllListeners(),this._transport=null,this.transport=null),x(e)||2e3===e||this.readyState!==w.CONNECTING?this._close(e,t):this._connect()},w.prototype._open=function(){this._transport&&this._transport.transportName,this.readyState,this.readyState===w.CONNECTING?(this._transportTimeoutId&&(clearTimeout(this._transportTimeoutId),this._transportTimeoutId=null),this.readyState=w.OPEN,this.transport=this._transport.transportName,this.dispatchEvent(new m("open")),this.transport):this._close(1006,"Server lost session")},w.prototype._close=function(e,t,n){this.transport,this.readyState;var i=!1;if(this._ir&&(i=!0,this._ir.close(),this._ir=null),this._transport&&(this._transport.close(),this._transport=null,this.transport=null),this.readyState===w.CLOSED)throw new Error("InvalidStateError: SockJS has already been closed");this.readyState=w.CLOSING,setTimeout(function(){this.readyState=w.CLOSED,i&&this.dispatchEvent(new m("error"));var r=new b("close");r.wasClean=n||!1,r.code=e||1e3,r.reason=t,this.dispatchEvent(r),this.onmessage=this.onclose=this.onerror=null}.bind(this),0)},w.prototype.countRTO=function(e){return e>100?4*e:300+e},e.exports=function(e){return i=u(e),n(272)(w,e),w}}).call(this,n(46))},function(e,t,n){"use strict";var i,r=Array.prototype,s=Object.prototype,o=Function.prototype,a=String.prototype,c=r.slice,l=s.toString,d=function(e){return"[object Function]"===s.toString.call(e)},u=function(e){return"[object String]"===l.call(e)},h=Object.defineProperty&&function(){try{return Object.defineProperty({},"x",{}),!0}catch(e){return!1}}();i=h?function(e,t,n,i){!i&&t in e||Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:!0,value:n})}:function(e,t,n,i){!i&&t in e||(e[t]=n)};var p=function(e,t,n){for(var r in t)s.hasOwnProperty.call(t,r)&&i(e,r,t[r],n)},f=function(e){if(null==e)throw new TypeError("can't convert "+e+" to object");return Object(e)};function m(e){var t=+e;return t!=t?t=0:0!==t&&t!==1/0&&t!==-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t))),t}function g(){}p(o,{bind:function(e){var t=this;if(!d(t))throw new TypeError("Function.prototype.bind called on incompatible "+t);for(var n=c.call(arguments,1),i=function(){if(this instanceof a){var i=t.apply(this,n.concat(c.call(arguments)));return Object(i)===i?i:this}return t.apply(e,n.concat(c.call(arguments)))},r=Math.max(0,t.length-n.length),s=[],o=0;o<r;o++)s.push("$"+o);var a=Function("binder","return function ("+s.join(",")+"){ return binder.apply(this, arguments); }")(i);return t.prototype&&(g.prototype=t.prototype,a.prototype=new g,g.prototype=null),a}}),p(Array,{isArray:function(e){return"[object Array]"===l.call(e)}});var v,b,y,S=Object("a"),w="a"!==S[0]||!(0 in S);p(r,{forEach:function(e){var t=f(this),n=w&&u(this)?this.split(""):t,i=arguments[1],r=-1,s=n.length>>>0;if(!d(e))throw new TypeError;for(;++r<s;)r in n&&e.call(i,n[r],r,t)}},(v=r.forEach,b=!0,y=!0,v&&(v.call("foo",(function(e,t,n){"object"!=typeof n&&(b=!1)})),v.call([1],(function(){y="string"==typeof this}),"x")),!(v&&b&&y)));var x=Array.prototype.indexOf&&-1!==[0,1].indexOf(1,2);p(r,{indexOf:function(e){var t=w&&u(this)?this.split(""):f(this),n=t.length>>>0;if(!n)return-1;var i=0;for(arguments.length>1&&(i=m(arguments[1])),i=i>=0?i:Math.max(0,n+i);i<n;i++)if(i in t&&t[i]===e)return i;return-1}},x);var C,O=a.split;2!=="ab".split(/(?:ab)*/).length||4!==".".split(/(.?)(.?)/).length||"t"==="tesst".split(/(s)*/)[1]||4!=="test".split(/(?:)/,-1).length||"".split(/.?/).length||".".split(/()()/).length>1?(C=void 0===/()??/.exec("")[1],a.split=function(e,t){var n=this;if(void 0===e&&0===t)return[];if("[object RegExp]"!==l.call(e))return O.call(this,e,t);var i,s,o,a,c=[],d=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.extended?"x":"")+(e.sticky?"y":""),u=0;for(e=new RegExp(e.source,d+"g"),n+="",C||(i=new RegExp("^"+e.source+"$(?!\\s)",d)),t=void 0===t?-1>>>0:t>>>0;(s=e.exec(n))&&!((o=s.index+s[0].length)>u&&(c.push(n.slice(u,s.index)),!C&&s.length>1&&s[0].replace(i,(function(){for(var e=1;e<arguments.length-2;e++)void 0===arguments[e]&&(s[e]=void 0)})),s.length>1&&s.index<n.length&&r.push.apply(c,s.slice(1)),a=s[0].length,u=o,c.length>=t));)e.lastIndex===s.index&&e.lastIndex++;return u===n.length?!a&&e.test("")||c.push(""):c.push(n.slice(u)),c.length>t?c.slice(0,t):c}):"0".split(void 0,0).length&&(a.split=function(e,t){return void 0===e&&0===t?[]:O.call(this,e,t)});var k=a.substr,E="".substr&&"b"!=="0b".substr(-1);p(a,{substr:function(e,t){return k.call(this,e<0&&(e=this.length+e)<0?0:e,t)}},E)},function(e,t,n){"use strict";var i,r=n(83),s=/[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g;e.exports={quote:function(e){var t=r.stringify(e);return s.lastIndex=0,s.test(t)?(i||(i=function(e){var t,n={},i=[];for(t=0;t<65536;t++)i.push(String.fromCharCode(t));return e.lastIndex=0,i.join("").replace(e,(function(e){return n[e]="\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4),""})),e.lastIndex=0,n}(s)),t.replace(s,(function(e){return i[e]}))):t}}},function(e,t,n){"use strict";e.exports=function(e){return{filterToEnabled:function(t,n){var i={main:[],facade:[]};return t?"string"==typeof t&&(t=[t]):t=[],e.forEach((function(e){e&&("websocket"===e.transportName&&!1===n.websocket||(t.length&&-1===t.indexOf(e.transportName)?e.transportName:e.enabled(n)?(e.transportName,i.main.push(e),e.facadeTransport&&i.facade.push(e.facadeTransport)):e.transportName))})),i}}}},function(e,t,n){"use strict";(function(t){var n={};["log","debug","warn"].forEach((function(e){var i;try{i=t.console&&t.console[e]&&t.console[e].apply}catch(e){}n[e]=i?function(){return t.console[e].apply(t.console,arguments)}:"log"===e?function(){}:n.log})),e.exports=n}).call(this,n(46))},function(e,t,n){"use strict";var i=n(33),r=n(146);function s(){r.call(this),this.initEvent("close",!1,!1),this.wasClean=!1,this.code=0,this.reason=""}i(s,r),e.exports=s},function(e,t,n){"use strict";var i=n(33),r=n(146);function s(e){r.call(this),this.initEvent("message",!1,!1),this.data=e}i(s,r),e.exports=s},function(e,t,n){"use strict";var i=n(64).EventEmitter,r=n(33),s=n(73),o=n(143),a=n(131),c=n(121),l=n(270),d=n(271),u=n(173);function h(e,t){var n=this;i.call(this),setTimeout((function(){n.doXhr(e,t)}),0)}r(h,i),h._getReceiver=function(e,t,n){return n.sameOrigin?new u(t,c):a.enabled?new u(t,a):o.enabled&&n.sameScheme?new u(t,o):d.enabled()?new d(e,t):new u(t,l)},h.prototype.doXhr=function(e,t){var n=this,i=s.addPath(e,"/info");this.xo=h._getReceiver(e,i,t),this.timeoutRef=setTimeout((function(){n._cleanup(!1),n.emit("finish")}),h.timeout),this.xo.once("finish",(function(e,t){n._cleanup(!0),n.emit("finish",e,t)}))},h.prototype._cleanup=function(e){clearTimeout(this.timeoutRef),this.timeoutRef=null,!e&&this.xo&&this.xo.close(),this.xo=null},h.prototype.close=function(){this.removeAllListeners(),this._cleanup(!1)},h.timeout=8e3,e.exports=h},function(e,t,n){"use strict";var i=n(64).EventEmitter;function r(){var e=this;i.call(this),this.to=setTimeout((function(){e.emit("finish",200,"{}")}),r.timeout)}n(33)(r,i),r.prototype.close=function(){clearTimeout(this.to)},r.timeout=2e3,e.exports=r},function(e,t,n){"use strict";(function(t){var i=n(64).EventEmitter,r=n(33),s=n(83),o=n(90),a=n(167),c=n(172);function l(e,n){var r=this;i.call(this);var l=function(){var t=r.ifr=new a(c.transportName,n,e);t.once("message",(function(e){if(e){var t;try{t=s.parse(e)}catch(e){return r.emit("finish"),void r.close()}var n=t[0],i=t[1];r.emit("finish",n,i)}r.close()})),t.once("close",(function(){r.emit("finish"),r.close()}))};t.document.body?l():o.attachEvent("load",l)}r(l,i),l.enabled=function(){return a.enabled()},l.prototype.close=function(){this.ifr&&this.ifr.close(),this.removeAllListeners(),this.ifr=null},e.exports=l}).call(this,n(46))},function(e,t,n){"use strict";var i=n(73),r=n(90),s=n(83),o=n(273),a=n(172),c=n(123),l=n(171);e.exports=function(e,t){var n,d={};t.forEach((function(e){e.facadeTransport&&(d[e.facadeTransport.transportName]=e.facadeTransport)})),d[a.transportName]=a,e.bootstrap_iframe=function(){var t;c.currentWindowId=l.hash.slice(1);r.attachEvent("message",(function(r){if(r.source===parent&&(void 0===n&&(n=r.origin),r.origin===n)){var a;try{a=s.parse(r.data)}catch(e){return void r.data}if(a.windowId===c.currentWindowId)switch(a.type){case"s":var u;try{u=s.parse(a.data)}catch(e){a.data;break}var h=u[0],p=u[1],f=u[2],m=u[3];if(h!==e.version)throw new Error('Incompatible SockJS! Main site uses: "'+h+'", the iframe: "'+e.version+'".');if(!i.isOriginEqual(f,l.href)||!i.isOriginEqual(m,l.href))throw new Error("Can't connect to different domain from within an iframe. ("+l.href+", "+f+", "+m+")");t=new o(new d[p](f,m));break;case"m":t._send(a.data);break;case"c":t&&t._close(),t=null}}})),c.postMessage("s")}}},function(e,t,n){"use strict";var i=n(83),r=n(123);function s(e){this._transport=e,e.on("message",this._transportMessage.bind(this)),e.on("close",this._transportClose.bind(this))}s.prototype._transportClose=function(e,t){r.postMessage("c",i.stringify([e,t]))},s.prototype._transportMessage=function(e){r.postMessage("t",e)},s.prototype._send=function(e){this._transport.send(e)},s.prototype._close=function(){this._transport.close(),this._transport.removeAllListeners()},e.exports=s},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var i=n(15),r=n.n(i),s=n(39),o=n(2),a=n(91);
/**
 * @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 c extends o.a{}function l(e){let t,n,i;return(r,o)=>void 0===n||void 0!==t&&void 0!==r&&t.generation===r.generation?(t=void 0,i=new s.c,n=e(r,i).then(e=>(t=e,i=void 0,e),e=>{throw i.isCanceled&&(i=void 0,n=void 0),e}),n):(void 0===t&&i.addConsumer(o),n)}class d{constructor(){this.providers=new Map}register(e,t){this.providers.set(e,t)}getCredentialsProvider(e,t){const n=this.providers.get(e);if(void 0===n)throw new Error(`No registered credentials provider: ${JSON.stringify(e)}`);return n(t)}}class u extends o.a{constructor(e){super(),this.base=e,this.memoize=new a.b}getCredentialsProvider(e,t){return this.memoize.get({key:e,parameters:t},()=>this.registerDisposer(this.base.getCredentialsProvider(e,t).addRef()))}}var h=n(54),p=n(154),f=n(4),m=n(24),g=n(0);
/**
 * @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 v extends c{constructor(){super(...arguments),this.invalidCredentials=new f.c(void 0,e=>e),this.validCredentials=new f.c(void 0,e=>e),this.get=l(e=>new Promise(t=>{const n=this.validCredentials.value,i=void 0!==e?e.generation:null,r=e=>void 0!==e&&i!==e.generation;if(r(n))return void t(n);let s;this.invalidCredentials.value=i,s=this.validCredentials.changed.add(()=>{const e=this.validCredentials.value;r(e)&&(s(),t(e))})}))}}class b{constructor(){this.inputState=new m.b,this.outputState=new m.b,this.memoize=new a.a}getCredentialsProvider(e,t){void 0===t&&(t=null);const n=Object(g.h)({key:e,parameters:t});return this.memoize.get(n,()=>{const e=new v;return e.registerDisposer(this.inputState.add(n,e.validCredentials)),e.registerDisposer(this.outputState.add(n,e.invalidCredentials)),e})}}var y=n(3),S=n(13);
/**
 * @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 w{constructor(){this.eventActionMap=new S.a,this.changed=new y.a}reset(){this.eventActionMap.clear(),this.changed.dispatch()}restoreState(e){Object(g.w)(e);const{eventActionMap:t}=this;for(const n of Object.keys(e)){const i=Object(g.E)(e[n]);t.set(n,i)}this.changed.dispatch()}toJSON(){const e={};for(const[t,n]of this.eventActionMap.bindings)e[t]=n.action;return e}}n(223),n(120);var x=n(12),C=n(5);
/**
 * @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 O=new class extends u{constructor(){super(new d)}register(e,t){this.base.register(e,t)}};n(224);
/**
 * @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 k(e,t){return n=>{n.style.flex=e,t(n)}}function E(e,t){return n=>{n.style.display="flex",n.style.flexDirection=e;for(let e of t){let t=n.ownerDocument.createElement("div");n.appendChild(t),e(t)}}}var T=n(21),M=(n(225),n(43)),D=n(126);
/**
 * @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 L extends o.a{constructor(e){super(),this.gl=e,this.vertexBuffer=this.registerDisposer(M.a.fromData(e,new Float32Array([0,0,0,1,1,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,1]),e.ARRAY_BUFFER,e.STATIC_DRAW));this.colorBuffer=this.registerDisposer(M.a.fromData(e,new Float32Array([1,0,0,.5,1,0,0,.5,0,1,0,.5,0,1,0,.5,0,0,1,.5,0,0,1,.5]),e.ARRAY_BUFFER,e.STATIC_DRAW)),this.trivialColorShader=this.registerDisposer(Object(D.c)(e))}static get(e){return e.memoize.get("SliceViewPanel:AxesLineHelper",()=>new L(e))}draw(e,t=!0){let n=this.trivialColorShader,i=this.gl;n.bind(),i.uniformMatrix4fv(n.uniform("uProjectionMatrix"),!1,e);let r=n.attribute("aVertexPosition");this.vertexBuffer.bindToVertexAttrib(r,4);let s=n.attribute("aColor");this.colorBuffer.bindToVertexAttrib(s,4),t&&(i.colorMask(!1,!1,!1,!0),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.colorMask(!0,!0,!0,!0),i.enable(i.BLEND),i.blendFunc(i.ONE_MINUS_DST_ALPHA,i.DST_ALPHA)),i.lineWidth(1),i.drawArrays(i.LINES,0,6),t&&i.disable(i.BLEND),i.disableVertexAttribArray(r),i.disableVertexAttribArray(s)}}var j=n(23);
/**
 * @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.
 */var I=n(71),P=n(85),A=(n(226),n(55)),R=n(30);var N=n(93);
/**
 * @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 V extends o.a{constructor(e,t,n){super(),this.context=e,this.element=t,this.visibility=n,this.gl=e.gl,e.addPanel(this)}scheduleRedraw(){this.visible&&this.context.scheduleRedraw()}setGLViewport(){let e=this.element;const t=e.getBoundingClientRect(),n=this.context.canvasRect,i=n.width/this.context.canvas.width,r=n.height/this.context.canvas.height;let s=(e.clientLeft+t.left-n.left)*i,o=e.clientWidth,a=(t.top-n.top+e.clientTop)*r,c=e.clientHeight,l=a+c,d=this.gl;d.enable(d.SCISSOR_TEST);let u=this.context.canvas.height-l;d.viewport(s,u,o,c),d.scissor(s,u,o,c)}disposed(){this.context.removePanel(this),super.disposed()}get visible(){return this.visibility.visible}}class _ extends o.a{constructor(e){super(),this.container=e,this.canvas=document.createElement("canvas"),this.updateStarted=new y.a,this.updateFinished=new y.a,this.changed=this.updateFinished,this.panels=new Set,this.frameNumber=0,this.resizeObserver=new N.a(()=>this.scheduleRedraw()),this.scheduleRedraw=this.registerCancellable(Object(R.a)(()=>this.draw()));const{canvas:t,resizeObserver:n}=this;e.style.position="relative",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.width="100%",t.style.height="100%",t.style.zIndex="0",n.observe(t),e.appendChild(t),this.gl=function(e){let t={antialias:!1,stencil:!0},n=e.getContext("webgl2",t);if(null==n)throw new Error("WebGL not supported.");n.memoize=new a.a,n.maxTextureSize=n.getParameter(n.MAX_TEXTURE_SIZE),n.max3dTextureSize=n.getParameter(n.MAX_3D_TEXTURE_SIZE),n.maxTextureImageUnits=n.getParameter(n.MAX_TEXTURE_IMAGE_UNITS),n.tempTextureUnit=n.maxTextureImageUnits-1;for(const e of["EXT_color_buffer_float"])if(!n.getExtension(e))throw new Error(`${e} extension not available`);for(const e of["EXT_float_blend"])n.getExtension(e);return n}(t)}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.resizeObserver.disconnect()}addPanel(e){this.panels.add(e),this.resizeObserver.observe(e.element),this.scheduleRedraw()}removePanel(e){this.resizeObserver.unobserve(e.element),this.panels.delete(e),this.scheduleRedraw()}draw(){++this.frameNumber,this.updateStarted.dispatch();let e=this.gl,t=this.canvas;t.width=t.offsetWidth,t.height=t.offsetHeight,this.canvasRect=t.getBoundingClientRect(),this.gl.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);for(let e of this.panels){let{element:t}=e;e.visible&&0!==t.clientWidth&&0!==t.clientHeight&&0!==t.offsetWidth&&0!==t.offsetHeight&&(e.setGLViewport(),e.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()}}
/**
 * @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 B{constructor(){this.renderLayers=[null],this.pickData=[null],this.values=[0,0,0],this.nextPickID=1}clear(){this.renderLayers.length=1,this.pickData.length=1,this.values.length=3,this.nextPickID=1}registerUint64(e,t,n=1){return this.register(e,n,t.low,t.high)}register(e,t=1,n=0,i=0,r=null){let{renderLayers:s,values:o}=this,a=this.nextPickID;this.nextPickID+=t;let c=s.length;s[c]=e;let l=3*c;return o[l]=a,o[l+1]=n,o[l+2]=i,this.pickData[c]=r,a}setMouseState(e,t){const{renderLayers:n,values:i}=this;let r=0,s=n.length-1;for(;r<s;){const e=Math.ceil(r+(s-r)/2);i[3*e]>t?s=e-1:r=e}const o=e.pickedRenderLayer=n[r],a=3*r,c=e.pickedOffset=t-i[a];let{pickedValue:l}=e;l.low=i[a+1],l.high=i[a+2],e.pickedAnnotationId=void 0,e.pickedAnnotationLayer=void 0,null!==o&&o.updateMouseState(e,l,c,this.pickData[r])}}var F=n(38),z=n(100),U=n(1),G=n(11),$=n(19),W=n(51);
/**
 * @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 H(e,t,n){const{document:i}=e.view;let r=e.clientX,s=e.clientY;const o=e=>{const n=e.clientX-r,i=e.clientY-s;r=e.clientX,s=e.clientY,t(e,n,i)},a=e.button,c=e=>{i.removeEventListener("pointermove",o,!0),i.removeEventListener("pointerup",l,!1),void 0!==n&&n(e,e.clientX-r,e.clientY-s)},l=e=>{e.button===a&&c(e)};i.addEventListener("pointermove",o,!0),i.addEventListener("pointerup",l,!1),i.addEventListener("pointercancel",c,!1)}var J=n(92),q=n.n(J);
/**
 * @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 Y=Math.PI/20;function X(e,t){return Math.sqrt(e*e+t*t)}function K(e){let[t,n]=e;t.identifier>n.identifier&&([n,t]=[t,n]);const i=t.clientX-n.clientX,r=t.clientY-n.clientY;return{distance:X(i,r),angle:Math.atan2(i,r)}}class Q extends o.a{constructor(e,t){super(),this.target=e,this.eventMap=t,this.prevTouches=new Map,this.moved=!1,this.prevAngle=0,this.rotated=!1,this.prevDistance=0,this.pinched=!1,this.prevCenterX=0,this.prevCenterY=0,this.translated=!1,this.startHold=this.registerCancellable(q()((e,t,n,i)=>{const r={event:e,centerX:n,centerY:i};this.dispatch(`touchhold${e.targetTouches.length}`,e,r,t)},1e3,{leading:!1,trailing:!0})),this.numPriorTaps=0,this.priorTapNumTouches=0,this.tapStartTime=0,this.tapEndTime=0,this.curTapNumTouches=0,this.registerEventListener(e,"touchstart",e=>{this.handleTouchEvent(e)}),this.registerEventListener(e,"touchmove",e=>{this.handleTouchEvent(e)}),this.registerEventListener(e,"touchend",e=>{this.handleTouchEvent(e)})}dispatch(e,t,n,i=t.eventPhase){Object(S.b)(e,t,i,n,this.eventMap)}handleTouchEvent(e){if(e.target!==this.target)return;e.preventDefault();const t=new Map,{prevTouches:n,prevEvent:i}=this;let r=0,s=0;for(const n of e.targetTouches)t.set(n.identifier,n),r+=n.clientX,s+=n.clientY;r/=t.size,s/=t.size;for(const[e,i]of n.entries()){const r=t.get(e);if(void 0===r)n.delete(e);else{const e=r.clientX-i.clientX,t=r.clientY-i.clientY;(Math.abs(e)>=10||Math.abs(t)>=10)&&(this.moved=!0)}}if(void 0===i||i.targetTouches.length!==t.size||0==t.size){if(this.moved=!1,"touchstart"===e.type)this.startHold(e,e.eventPhase,r,s),void 0!==i&&0!==i.targetTouches.length||(this.tapStartTime=Date.now(),this.curTapNumTouches=0),this.curTapNumTouches=Math.max(this.curTapNumTouches,e.targetTouches.length);else{if("touchend"==e.type){const t=Date.now();if(0===e.targetTouches.length&&t-this.tapStartTime<400){(this.curTapNumTouches!==this.priorTapNumTouches||t-this.tapEndTime>=500)&&(this.numPriorTaps=0),++this.numPriorTaps,this.tapEndTime=t,this.priorTapNumTouches=this.curTapNumTouches;const n={event:e,centerX:r,centerY:s};this.dispatch(`touchtap${this.curTapNumTouches}x${this.numPriorTaps}`,e,n)}}this.startHold.cancel()}if(this.prevTouches=t,this.prevEvent=e,this.prevCenterX=r,this.prevCenterY=s,this.translated=!1,2===t.size){const{distance:e,angle:n}=K(t.values());this.prevDistance=e,this.prevAngle=n,this.rotated=!1,this.pinched=!1}return}if(!this.moved)return;this.tapStartTime=0,this.startHold.cancel(),this.prevTouches=t,this.prevEvent=e;let{prevCenterX:o,prevCenterY:a,translated:c}=this;const l=r-o,d=s-a;if(!1===c&&X(l,d)>=10&&(c=this.translated=!0),!0===c&&(0!==l||0!==d)){this.prevCenterX=r,this.prevCenterY=s;const n={event:e,deltaX:l,deltaY:d,centerX:r,centerY:s};this.dispatch(`touchtranslate${t.size}`,e,n)}if(2===t.size){const{distance:n,angle:i}=K(t.values());let{pinched:o,rotated:a,prevDistance:c,prevAngle:l}=this;!1===o&&Math.abs(n-c)>=20&&(this.pinched=o=!0);const d=function(e,t){const n=2*Math.PI,i=Math.abs(e-t)%n;return Math.min(i,n-i)}(i,l);if(!1===a&&d>=Y&&(this.rotated=a=!0),!0===o&&n!=c){this.prevDistance=n;const t={event:e,distance:n,prevDistance:c,centerX:r,centerY:s};this.dispatch("touchpinch",e,t)}!0===a&&i!==l&&(this.prevAngle=i,this.dispatch("touchrotate",e,{event:e,centerX:r,centerY:s,angle:i,prevAngle:l}))}}}
/**
 * @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 Z(e){let t=0,{deltaMode:n}=e;switch(n){case 0:t=.005;break;case 1:t=.1;break;case 2:t=2}return Math.exp(e.deltaY*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.
 */const ee=U.u.create();class te{constructor(){this.pickIDs=new B,this.viewportWidth=0,this.viewportHeight=0,this.invTransform=U.m.create(),this.frameNumber=-1}}class ne{constructor(){this.buffer=null,this.glWindowX=0,this.glWindowY=0}}const ie=(()=>{const e=(e,t)=>(e-5)**2+(t-5)**2;let t=new Uint32Array(121),n=0;for(let i=0;i<11;++i)for(let r=0;r<11;++r)e(i,r)>25||(t[n++]=11*r+i);return t=t.subarray(0,n),t.sort((t,n)=>{const i=t%11,r=n%11,s=(n-r)/11;return e(i,(t-i)/11)-e(r,s)}),t})();function re(e,t,n,i,r,s,o){const a=i-5,c=r-5;if(!(a>=0&&c>=0&&a+11<=s&&c+11<=o))for(let i=0;i<11;++i)for(let r=0;r<11;++r){const l=a+r,d=c+i;(l<0||d<0||l>=s||d>=o)&&(e[t+(11*d+l)*n]=0)}}class se extends V{constructor(e,t,n){super(e,t,n.visibility),this.viewer=n,this.mouseX=-1,this.mouseY=-1,this.pickRequestPending=!1,this.mouseStateForcer=()=>this.blockOnPickRequest(),this.pickingData=[new te,new te],this.pickRequests=[new ne,new ne],this.pickBufferContents=new Float32Array(968),this.pickTimerId=-1,this.nextPickRequestTime=0,this.pendingPickRequestTimerId=-1,this.pendingPickRequestTimerExpired=()=>{this.pendingPickRequestTimerId=-1,this.pickRequestPending&&this.attemptToIssuePickRequest()},this.inputEventMap=n.inputEventMap,t.classList.add("neuroglancer-rendered-data-panel"),t.classList.add("neuroglancer-panel"),t.classList.add("neuroglancer-noselect"),this.registerDisposer(new z.a(t)),this.registerDisposer(new G.b(t,this.inputEventMap)),this.registerDisposer(new W.b(t,this.inputEventMap)),this.registerDisposer(new Q(t,this.inputEventMap)),this.registerEventListener(t,"mousemove",this.onMousemove.bind(this)),this.registerEventListener(t,"touchstart",this.onTouchstart.bind(this)),this.registerEventListener(t,"mouseleave",()=>this.onMouseout()),this.registerEventListener(t,"mouseover",e=>{e.target!==t&&this.onMouseout()},!0),Object(S.d)(t,"select-position",()=>{this.viewer.selectionDetailsState.select()}),Object(S.d)(t,"snap",()=>{this.navigationState.pose.snap()}),Object(S.d)(t,"zoom-in",()=>{this.navigationState.zoomBy(.5)}),Object(S.d)(t,"zoom-out",()=>{this.navigationState.zoomBy(2)}),Object(S.d)(t,"depth-range-decrease",()=>{this.navigationState.depthRange.value*=.5}),Object(S.d)(t,"depth-range-increase",()=>{this.navigationState.depthRange.value*=2}),Object(S.d)(t,"highlight",()=>{this.viewer.layerManager.invokeAction("highlight")});for(let e=0;e<3;++e){let n=U.a[e];for(let i of[-1,1]){let r=i<0?"-":"+";Object(S.d)(t,`rotate-relative-${n}${r}`,()=>{this.navigationState.pose.rotateRelative(U.i[e],.1*i)});let s=U.u.create();Object(S.d)(t,`${n}${r}`,()=>{let{navigationState:t}=this,n=s;n[0]=0,n[1]=0,n[2]=0,n[e]=i,t.pose.translateVoxelsRelative(n,!0)})}}Object(S.d)(t,"zoom-via-wheel",e=>{const t=e.detail;this.onMousemove(t,!1),this.zoomByMouse(Z(t))}),Object(S.d)(t,"adjust-depth-range-via-wheel",e=>{const t=e.detail;this.navigationState.depthRange.value*=Z(t)}),Object(S.d)(t,"translate-via-mouse-drag",e=>{H(e.detail,(e,t,n)=>{this.translateByViewportPixels(t,n)})}),Object(S.d)(t,"translate-in-plane-via-touchtranslate",e=>{const{detail:t}=e;this.translateByViewportPixels(t.deltaX,t.deltaY)}),Object(S.d)(t,"translate-z-via-touchtranslate",e=>{const{detail:t}=e;let{navigationState:n}=this,i=ee;i[0]=0,i[1]=0,i[2]=t.deltaY+t.deltaX,n.pose.translateVoxelsRelative(i,!0)});for(const e of[1,10])Object(S.d)(t,`z+${e}-via-wheel`,t=>{const n=t.detail;let{navigationState:i}=this,r=ee,s=0!==n.deltaY?n.deltaY:n.deltaX;r[0]=0,r[1]=0,r[2]=(s>0?-1:1)*e,i.pose.translateVoxelsRelative(r,!0)});Object(S.d)(t,"move-to-mouse-position",()=>{const{mouseState:e}=this.viewer;e.updateUnconditionally()&&(this.navigationState.position.value=e.position)}),Object(S.d)(t,"snap",()=>this.navigationState.pose.snap()),Object(S.d)(t,"move-annotation",e=>{const{mouseState:t}=this.viewer,n=t.pickedAnnotationId,i=t.pickedAnnotationLayer;if(void 0!==i&&void 0!==n){e.stopPropagation();let r=i.source.getReference(n),s=r.value;const o=Object(A.b)(s.type),a=t.pickedOffset,{chunkTransform:{value:c}}=i;if(void 0!==c.error)return;const{layerRank:l}=c,d=new Float32Array(l);o.getRepresentativePoint(d,s,t.pickedOffset);let u=U.t.set(U.t.create(),0,0);t.updateUnconditionally()&&H(e.detail,(e,t,n)=>{U.t.add(u,u,[t,n]);const h=new Float32Array(l);$.j(h,c.chunkToLayerTransform,l+1,d,l);const p=ee,{displayDimensionIndices:f}=this.navigationState.pose.displayDimensions.value;Object(F.i)(p,h,c.modelTransform,f),this.translateDataPointByViewportPixels(p,p,u[0],u[1]),Object(F.a)(h,p,c.modelTransform,f);const m=new Float32Array(l);$.j(m,c.layerToChunkTransform,l+1,h,l);let g=o.updateViaRepresentativePoint(s,m,a);i.source.update(r,g)},e=>{i.source.commit(r),r.dispose()})}}),Object(S.d)(t,"delete-annotation",()=>{const{mouseState:e}=this.viewer,t=e.pickedAnnotationId,n=e.pickedAnnotationLayer;if(void 0!==n&&!n.source.readonly&&void 0!==t){const e=n.source.getReference(t);try{n.source.delete(e)}finally{e.dispose()}}}),Object(S.d)(t,"zoom-via-touchpinch",e=>{const{detail:t}=e;this.handleMouseMove(t.centerX,t.centerY);const n=t.prevDistance/t.distance;n>.1&&n<10&&this.zoomByMouse(n)})}cancelPickRequests(){const{gl:e}=this;for(const t of this.pickRequests){const{sync:n}=t;null!==n&&e.deleteSync(n),t.sync=null}clearTimeout(this.pickTimerId),this.pickTimerId=-1}checkForResize(){const{clientWidth:e,clientHeight:t}=this.element;e===this.width&&t===this.height||(this.width=e,this.height=t,this.panelSizeChanged())}issuePickRequestInternal(e){const{gl:t}=this;let{buffer:n}=e;null===n?(n=e.buffer=t.createBuffer(),t.bindBuffer(WebGL2RenderingContext.PIXEL_PACK_BUFFER,n),t.bufferData(WebGL2RenderingContext.PIXEL_PACK_BUFFER,3872,WebGL2RenderingContext.STREAM_READ)):t.bindBuffer(WebGL2RenderingContext.PIXEL_PACK_BUFFER,n);let i=this.mouseX,r=this.height-this.mouseY;this.issuePickRequest(i,r),e.sync=t.fenceSync(WebGL2RenderingContext.SYNC_GPU_COMMANDS_COMPLETE,0),e.frameNumber=this.context.frameNumber,e.glWindowX=i,e.glWindowY=r,t.flush(),t.bindBuffer(WebGL2RenderingContext.PIXEL_PACK_BUFFER,null),-1===this.pickTimerId&&this.scheduleCheckForPickRequestCompletion(),this.pickRequestPending=!1;const{pickRequests:s}=this;e!==s[0]&&(s[1]=s[0],s[0]=e),this.nextPickRequestTime=Date.now()+30}completePickInternal(e){const{gl:t}=this,{pickBufferContents:n}=this;t.bindBuffer(WebGL2RenderingContext.PIXEL_PACK_BUFFER,e.buffer),t.getBufferSubData(WebGL2RenderingContext.PIXEL_PACK_BUFFER,0,n),t.bindBuffer(WebGL2RenderingContext.PIXEL_PACK_BUFFER,null);const{pickingData:i}=this,{frameNumber:r}=e;this.completePickRequest(e.glWindowX,e.glWindowY,n,i[0].frameNumber===r?i[0]:i[1])}scheduleCheckForPickRequestCompletion(){this.pickTimerId=setTimeout(()=>{this.pickTimerId=-1,this.checkForPickRequestCompletion()},0)}checkForPickRequestCompletion(e=!1,t=!1){let n=this.context.frameNumber,i=-1;e&&(--n,i=n-1);const{pickRequests:r}=this,{gl:s}=this;let o,a=!1,c=!1;for(const e of r){const{sync:r}=e;if(null===r)continue;const{frameNumber:l}=e;if(!c&&l>=n-1)if(t||s.getSyncParameter(r,WebGL2RenderingContext.SYNC_STATUS)===WebGL2RenderingContext.SIGNALED)this.completePickInternal(e),c=!0;else if(l!==i){a=!0;continue}s.deleteSync(r),e.sync=null,o=e}const{pickTimerId:l}=this;a&&-1===l?this.scheduleCheckForPickRequestCompletion():a||-1===l||(clearTimeout(l),this.pickTimerId=-1),!e&&void 0!==o&&this.pickRequestPending&&this.canIssuePickRequest()&&this.issuePickRequestInternal(o)}blockOnPickRequest(){this.pickRequestPending&&(this.cancelPickRequests(),this.nextPickRequestTime=0,this.attemptToIssuePickRequest()),this.checkForPickRequestCompletion(!1,!0)}draw(){this.checkForResize();const{width:e,height:t}=this;if(0===e||0===t)return;this.checkForPickRequestCompletion(!0);const{pickingData:n}=this;n[0]=n[1];const i=this.context.frameNumber,r=n[1];r.frameNumber=i,r.viewportWidth=e,r.viewportHeight=t,r.pickIDs.clear(),this.drawWithPicking(r)?(this.nextPickRequestTime=0,this.mouseX>0&&this.attemptToIssuePickRequest()):r.frameNumber=-1}canIssuePickRequest(){const e=Date.now(),{nextPickRequestTime:t,pendingPickRequestTimerId:n}=this;return!(e<t)||(-1==n&&(this.pendingPickRequestTimerId=setTimeout(this.pendingPickRequestTimerExpired,t-e)),!1)}attemptToIssuePickRequest(){if(!this.canIssuePickRequest())return;const e=this.context.frameNumber,{gl:t}=this,{pickRequests:n}=this;for(const i of n){let{sync:n}=i;if(null!==n){if(!(i.frameNumber<e-1))continue;t.deleteSync(n)}return void this.issuePickRequestInternal(i)}}updateMousePosition(e,t){if(e===this.mouseX&&t===this.mouseY)return;if(this.mouseX=e,this.mouseY=t,e<0)return this.pickRequestPending=!1,void this.cancelPickRequests();const n=this.context.frameNumber,i=this.pickingData[1];i.frameNumber===n&&this.width===i.viewportWidth&&this.height===i.viewportHeight&&(this.pickRequestPending=!0,this.attemptToIssuePickRequest())}onMouseout(){this.updateMousePosition(-1,-1),this.viewer.mouseState.setForcer(void 0)}handleMouseMove(e,t){const{element:n}=this,i=n.getBoundingClientRect(),r=e-(i.left+n.clientLeft),s=t-(i.top+n.clientTop),{mouseState:o}=this.viewer;o.pageX=e+window.scrollX,o.pageY=t+window.scrollY,o.setForcer(this.mouseStateForcer),this.updateMousePosition(r,s)}onMousemove(e,t=!0){const{element:n}=this;t&&e.target!==n||this.handleMouseMove(e.clientX,e.clientY)}onTouchstart(e){let{element:t}=this;if(e.target!==t||1!==e.targetTouches.length)return;const{clientX:n,clientY:i}=e.targetTouches[0];this.handleMouseMove(n,i)}disposed(){let{mouseState:e}=this.viewer;e.removeForcer(this.mouseStateForcer);const{gl:t}=this;this.cancelPickRequests();const{pendingPickRequestTimerId:n}=this;-1!==n&&clearTimeout(n);for(const e of this.pickRequests)t.deleteBuffer(e.buffer);super.disposed()}}var oe,ae=n(36),ce=n(56),le=n(17),de=n(112),ue=n(31),he=n(53),pe=n(87),fe=n(16);!function(e){e[e.COLOR=0]="COLOR",e[e.Z=1]="Z",e[e.PICK=2]="PICK",e[e.NUM_TEXTURES=3]="NUM_TEXTURES"}(oe||(oe={}));const me=["\nfloat computeOITWeight(float alpha) {\n  float a = min(1.0, alpha) * 8.0 + 0.01;\n  float b = -gl_FragCoord.z * 0.95 + 1.0;\n  return a * a * a * b * b * b;\n}\n","\nvoid emit(vec4 color, highp uint pickId) {\n  float weight = computeOITWeight(color.a);\n  vec4 accum = color * weight;\n  v4f_fragData0 = vec4(accum.rgb, color.a);\n  v4f_fragData1 = vec4(accum.a, 0.0, 0.0, 0.0);\n}\n"];function ge(e){e.addOutputBuffer("vec4","out_color",oe.COLOR),e.addOutputBuffer("highp vec4","out_z",oe.Z),e.addOutputBuffer("highp vec4","out_pickId",oe.PICK),e.addFragmentCode("\nvoid emit(vec4 color, highp uint pickId) {\n  out_color = color;\n  float zValue = 1.0 - gl_FragCoord.z;\n  out_z = vec4(zValue, zValue, zValue, 1.0);\n  float pickIdFloat = float(pickId);\n  out_pickId = vec4(pickIdFloat, pickIdFloat, pickIdFloat, 1.0);\n}\n")}function ve(e){e.addOutputBuffer("vec4","v4f_fragData0",0),e.addOutputBuffer("vec4","v4f_fragData1",1),e.addFragmentCode(me)}const be=U.u.create(),ye=U.w.create(),Se=U.m.create();function we(e){e.addOutputBuffer("vec4","v4f_fragColor",null),e.setFragmentMain("\nvec4 v0 = getValue0();\nvec4 v1 = getValue1();\nvec4 accum = vec4(v0.rgb, v1.r);\nfloat revealage = v0.a;\n\nv4f_fragColor = vec4(accum.rgb / accum.a, revealage);\n")}const xe=Object(ue.c)(fe.b);class Ce extends xe{constructor(e){super(),this.panel=e}initializeCounterpart(e,t){this.sharedProjectionParameters=this.registerDisposer(new ae.d(e,this.panel.projectionParameters)),t.projectionParameters=this.sharedProjectionParameters.rpcId,super.initializeCounterpart(e,t)}}class Oe extends se{constructor(e,t,n){super(e,t,n),this.sliceViews=this.registerDisposer(new de.a((e,t,n)=>{e.registerDisposer(n),e.registerDisposer(n.visibility.add(this.visibility))})),this.axesLineHelper=this.registerDisposer(L.get(this.gl)),this.sliceViewRenderHelper=this.registerDisposer(ce.e.get(this.gl,ge)),this.offscreenFramebuffer=this.registerDisposer(new he.b(this.gl,{colorBuffers:[new he.e(this.gl,WebGL2RenderingContext.RGBA8,WebGL2RenderingContext.RGBA,WebGL2RenderingContext.UNSIGNED_BYTE),new he.e(this.gl,WebGL2RenderingContext.R32F,WebGL2RenderingContext.RED,WebGL2RenderingContext.FLOAT),new he.e(this.gl,WebGL2RenderingContext.R32F,WebGL2RenderingContext.RED,WebGL2RenderingContext.FLOAT)],depthBuffer:new he.a(this.gl)})),this.offscreenCopyHelper=this.registerDisposer(he.c.get(this.gl)),this.transparencyCopyHelper=this.registerDisposer(he.c.get(this.gl,we,2)),this.scaleBars=this.registerDisposer(new pe.a(this.gl)),this.projectionParameters=this.registerDisposer(new ae.a({navigationState:this.navigationState,update:(e,t)=>{const{invViewMatrix:n,projectionMat:i,width:r,height:s}=e,o=r/s,a=Math.PI/4;let{relativeDepthRange:c}=t;let l=t.zoomFactor.value/2;if(this.viewer.orthographicProjection.value){const e=Math.max(.1,1-c),t=1+c;U.m.ortho(i,-o,o,-1,1,e,t)}else{const e=1/Math.tan(a/2);c/=e;const t=Math.max(.1,1-c),n=1+c;l*=e,U.m.perspective(i,a,o,t,n)}t.pose.toMat4(n,l),U.m.scale(n,n,U.u.set(be,1,-1,-1)),U.m.translate(n,n,U.i[2]),Object(P.c)(e)}})),this.projectionParameters.changed.add(()=>this.context.scheduleRedraw());const i=this.sharedObject=this.registerDisposer(new Ce(this));if(i.RPC_TYPE_ID="perspective_view/PerspectiveView",i.initializeCounterpart(n.rpc,{}),i.visibility.add(this.visibility),this.visibleLayerTracker=Object(j.q)(this.viewer.layerManager,I.a,this.viewer.visibleLayerRoles,this),Object(S.d)(t,"rotate-via-mouse-drag",e=>{H(e.detail,(e,t,n)=>{this.navigationState.pose.rotateRelative(U.i[1],t/4*Math.PI/180),this.navigationState.pose.rotateRelative(U.i[0],-n/4*Math.PI/180)})}),Object(S.d)(t,"rotate-in-plane-via-touchrotate",e=>{const{detail:t}=e;this.navigationState.pose.rotateRelative(U.i[2],t.angle-t.prevAngle)}),Object(S.d)(t,"rotate-out-of-plane-via-touchtranslate",e=>{const{detail:t}=e;this.navigationState.pose.rotateRelative(U.i[1],t.deltaX/4*Math.PI/180),this.navigationState.pose.rotateRelative(U.i[0],-t.deltaY/4*Math.PI/180)}),n.showSliceViewsCheckbox){let e=this.registerDisposer(new le.c(n.showSliceViews));e.element.className="perspective-panel-show-slice-views neuroglancer-noselect";let t=document.createElement("label");t.className="perspective-panel-show-slice-views neuroglancer-noselect",t.appendChild(document.createTextNode("Sections")),t.appendChild(e.element),this.element.appendChild(t)}this.registerDisposer(n.orthographicProjection.changed.add(()=>{this.projectionParameters.update(),this.scheduleRedraw()})),this.registerDisposer(n.showScaleBar.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.scaleBarOptions.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.showSliceViews.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.showAxisLines.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.crossSectionBackgroundColor.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.perspectiveViewBackgroundColor.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.wireFrame.changed.add(()=>this.scheduleRedraw())),this.sliceViews.changed.add(()=>this.scheduleRedraw())}get rpc(){return this.sharedObject.rpc}get rpcId(){return this.sharedObject.rpcId}get displayDimensionRenderInfo(){return this.navigationState.displayDimensionRenderInfo}flushBackendProjectionParameters(){this.sharedObject.sharedProjectionParameters.flush()}translateByViewportPixels(e,t){const n=be,{viewProjectionMat:i,invViewProjectionMat:r,width:s,height:o}=this.projectionParameters.value,{pose:a}=this.viewer.navigationState;a.updateDisplayPosition(a=>{U.u.transformMat4(n,a,i),n[0]=-2*e/s,n[1]=2*t/o,U.u.transformMat4(a,n,r)})}get navigationState(){return this.viewer.navigationState}isReady(){if(!this.visible)return!0;for(const[e,t]of this.sliceViews)if((t||this.viewer.showSliceViews.value)&&!e.isReady())return!1;this.checkForResize();const{width:e,height:t}=this;if(0===e||0===t)return!0;const n={projectionParameters:this.projectionParameters.value},{visibleLayers:i}=this.visibleLayerTracker;for(const[e,t]of i)if(!e.isReady(n,t))return!1;return!0}panelSizeChanged(){this.projectionParameters.setViewportShape(this.width,this.height)}disposed(){this.sliceViews.clear(),super.disposed()}issuePickRequest(e,t){const{offscreenFramebuffer:n}=this;n.readPixelFloat32IntoBuffer(oe.Z,e-5,t-5,0,11,11),n.readPixelFloat32IntoBuffer(oe.PICK,e-5,t-5,1936,11,11)}completePickRequest(e,t,n,i){const{mouseState:r}=this.viewer;r.pickedRenderLayer=null,re(n,0,4,e,t,i.viewportWidth,i.viewportHeight);const s=ie.length;for(let o=0;o<s;++o){const s=ie[o];let a=n[4*s];if(0===a)continue;const c=s%11,l=(s-c)/11;let d=1-a;be[0]=2*(e+c-5)/i.viewportWidth-1,be[1]=2*(t+l-5)/i.viewportHeight-1,be[2]=2*d-1,U.u.transformMat4(be,be,i.invTransform);let{position:u}=r;const{value:h}=this.navigationState.position,p=h.length;u.length!==p&&(u=r.position=new Float32Array(p)),u.set(h),r.coordinateSpace=this.navigationState.coordinateSpace.value;const f=this.navigationState.pose.displayDimensions.value,{displayDimensionIndices:m}=f;for(let e=0,t=m.length;e<t;++e)u[m[e]]=be[e];const g=n[484+4*s];return i.pickIDs.setMouseState(r,g),r.displayDimensions=f,void r.setActive(!0)}r.setActive(!1)}translateDataPointByViewportPixels(e,t,n,i){const r=be,{viewProjectionMat:s,invViewProjectionMat:o,width:a,height:c}=this.projectionParameters.value;return U.u.transformMat4(r,t,s),r[0]+=2*n/a,r[1]+=-2*i/c,U.u.transformMat4(e,r,o)}get transparentConfiguration(){let e=this.transparentConfiguration_;return void 0===e&&(e=this.transparentConfiguration_=this.registerDisposer(new he.b(this.gl,{colorBuffers:Object(he.f)(this.gl,2,this.gl.RGBA32F,this.gl.RGBA,this.gl.FLOAT),depthBuffer:this.offscreenFramebuffer.depthBuffer.addRef()}))),e}drawWithPicking(e){if(!this.navigationState.valid)return!1;const{width:t,height:n}=this,i=this.viewer.showSliceViews.value;for(const[e,t]of this.sliceViews)(t||i)&&e.updateRendering();let r=this.gl;this.offscreenFramebuffer.bind(t,n),r.disable(r.SCISSOR_TEST);const s=this.viewer.perspectiveViewBackgroundColor.value;this.gl.clearColor(s[0],s[1],s[2],0),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),r.enable(r.DEPTH_TEST);const o=this.projectionParameters.value;let a=U.u.create();U.u.transformQuat(a,U.i[2],this.navigationState.pose.orientation.orientation),U.u.scale(a,a,-1);const c={wireFrame:this.viewer.wireFrame.value,projectionParameters:o,lightDirection:a,ambientLighting:.2,directionalLighting:.8,pickIDs:e.pickIDs,emitter:ge,emitColor:!0,emitPickID:!0,alreadyEmittedPickID:!1};U.m.copy(e.invTransform,o.invViewProjectionMat);const{visibleLayers:l}=this.visibleLayerTracker;let d=!1,u=!1;for(const[e,t]of l)e.isTransparent?d=!0:e.isAnnotation?u=!0:e.draw(c,t);if(this.drawSliceViews(c),u){r.enable(WebGL2RenderingContext.BLEND),r.depthFunc(WebGL2RenderingContext.LEQUAL),r.blendFunc(WebGL2RenderingContext.SRC_ALPHA,WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA);for(const[e,t]of l)e.isAnnotation&&e.draw(c,t);r.depthFunc(WebGL2RenderingContext.LESS),r.disable(WebGL2RenderingContext.BLEND)}if(this.viewer.showAxisLines.value&&this.drawAxisLines(),d){r.depthMask(!1),r.enable(WebGL2RenderingContext.BLEND);const{transparentConfiguration:e}=this;e.bind(t,n),this.gl.clearColor(0,0,0,1),r.clear(WebGL2RenderingContext.COLOR_BUFFER_BIT),c.emitter=ve,r.blendFuncSeparate(WebGL2RenderingContext.ONE,WebGL2RenderingContext.ONE,WebGL2RenderingContext.ZERO,WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA),c.emitPickID=!1;for(const[e,t]of l)e.isTransparent&&e.draw(c,t);r.disable(WebGL2RenderingContext.DEPTH_TEST),this.offscreenFramebuffer.bindSingle(oe.COLOR),r.blendFunc(WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA,WebGL2RenderingContext.SRC_ALPHA),this.transparencyCopyHelper.draw(e.colorBuffers[0].texture,e.colorBuffers[1].texture),r.depthMask(!0),r.disable(WebGL2RenderingContext.BLEND),r.enable(WebGL2RenderingContext.DEPTH_TEST),this.offscreenFramebuffer.bind(t,n)}r.drawBuffers([r.NONE,r.COLOR_ATTACHMENT1,r.COLOR_ATTACHMENT2]),c.emitter=ge,c.emitPickID=!0,c.emitColor=!1,r.enable(WebGL2RenderingContext.POLYGON_OFFSET_FILL),r.polygonOffset(-1,-1);for(const[e,t]of l)e.isTransparent&&e.transparentPickEnabled&&e.draw(c,t);if(r.disable(WebGL2RenderingContext.POLYGON_OFFSET_FILL),this.viewer.showScaleBar.value&&this.viewer.orthographicProjection.value){r.drawBuffers([r.COLOR_ATTACHMENT0]),r.disable(WebGL2RenderingContext.DEPTH_TEST),r.enable(WebGL2RenderingContext.BLEND),r.blendFunc(WebGL2RenderingContext.SRC_ALPHA,WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA);const{scaleBars:e}=this,n=this.viewer.scaleBarOptions.value;e.draw(t,this.navigationState.displayDimensionRenderInfo.value,this.navigationState.relativeDisplayScales.value,this.navigationState.zoomFactor.value/this.height,n),r.disable(WebGL2RenderingContext.BLEND)}return this.offscreenFramebuffer.unbind(),this.setGLViewport(),this.offscreenCopyHelper.draw(this.offscreenFramebuffer.colorBuffers[oe.COLOR].texture),!0}drawSliceViews(e){let{sliceViewRenderHelper:t}=this,{lightDirection:n,ambientLighting:i,directionalLighting:r,projectionParameters:{viewProjectionMat:s}}=e;const o=this.viewer.showSliceViews.value;for(const[e,a]of this.sliceViews){if(!a&&!o)continue;const{width:c,height:l,invViewMatrix:d,viewportNormalInCanonicalCoordinates:u}=e.projectionParameters.value;if(0===c||0===l||!e.valid)continue;let h=i+Math.abs(U.u.dot(n,u))*r,p=Se;U.m.identity(p),p[0]=c/2,p[5]=-l/2,U.m.multiply(p,d,p),U.m.multiply(p,s,p);const f=ye,m=this.viewer.crossSectionBackgroundColor.value;f[0]=m[0],f[1]=m[1],f[2]=m[2],f[3]=1,t.draw(e.offscreenFramebuffer.colorBuffers[0].texture,p,U.w.fromValues(h,h,h,1),ye,0,0,1,1)}}drawAxisLines(){const{position:{value:e},zoomFactor:{value:t},displayDimensionRenderInfo:{value:{canonicalVoxelFactors:n,displayDimensionIndices:i}}}=this.viewer.navigationState,r=t*(Math.min(this.width,this.height)/this.height/4),s=Se;U.m.identity(s);for(let t=0;t<3;++t){const o=i[t];s[12+t]=-1===o?0:e[o],s[5*t]=r/n[t]}U.m.multiply(s,this.projectionParameters.value.viewProjectionMat,s);const{gl:o}=this;o.drawBuffers([o.COLOR_ATTACHMENT0]),this.axesLineHelper.draw(s,!1)}zoomByMouse(e){this.navigationState.zoomBy(e)}}var ke,Ee=n(72);
/**
 * @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 Te(e){e.addOutputBuffer("vec4","out_fragColor",0),e.addOutputBuffer("highp vec4","out_pickId",1),e.addFragmentCode("\nvoid emit(vec4 color, highp uint pickId) {\n  out_fragColor = color;\n  float pickIdFloat = float(pickId);\n  out_pickId = vec4(pickIdFloat, pickIdFloat, pickIdFloat, 1.0);\n}\n")}function Me(e){e.addOutputBuffer("vec4","out_fragColor",null),e.addFragmentCode("\nvoid emit(vec4 color, highp uint pickId) {\n  out_fragColor = color;\n}\n")}!function(e){e[e.COLOR=0]="COLOR",e[e.PICK=1]="PICK",e[e.NUM_TEXTURES=2]="NUM_TEXTURES"}(ke||(ke={}));const De=U.u.create(),Le=U.u.create(),je=U.w.create();class Ie extends se{constructor(e,t,n,i){super(e,t,i),this.sliceView=n,this.axesLineHelper=this.registerDisposer(L.get(this.gl)),this.sliceViewRenderHelper=this.registerDisposer(ce.e.get(this.gl,Me)),this.colorFactor=U.w.fromValues(1,1,1,1),this.pickIDs=new B,this.offscreenFramebuffer=this.registerDisposer(new he.b(this.gl,{colorBuffers:[new he.e(this.gl,WebGL2RenderingContext.RGBA8,WebGL2RenderingContext.RGBA,WebGL2RenderingContext.UNSIGNED_BYTE),new he.e(this.gl,WebGL2RenderingContext.R32F,WebGL2RenderingContext.RED,WebGL2RenderingContext.FLOAT)]})),this.offscreenCopyHelper=this.registerDisposer(he.c.get(this.gl)),this.scaleBars=this.registerDisposer(new pe.a(this.gl)),i.wireFrame.changed.add(()=>this.scheduleRedraw()),Object(S.d)(t,"rotate-via-mouse-drag",e=>{const{mouseState:t}=this.viewer;if(t.updateUnconditionally()){const n=Float32Array.from(t.position);H(e.detail,(e,t,i)=>{const{pose:r}=this.navigationState,s=U.u.transformQuat(De,U.i[0],r.orientation.orientation),o=U.u.transformQuat(Le,U.i[1],r.orientation.orientation);this.viewer.navigationState.pose.rotateAbsolute(o,-t/4*Math.PI/180,n),this.viewer.navigationState.pose.rotateAbsolute(s,-i/4*Math.PI/180,n)})}}),Object(S.d)(t,"rotate-in-plane-via-touchrotate",e=>{const{detail:t}=e,{mouseState:n}=this.viewer;this.handleMouseMove(t.centerX,t.centerY),n.updateUnconditionally()&&this.navigationState.pose.rotateAbsolute(this.sliceView.projectionParameters.value.viewportNormalInCanonicalCoordinates,t.angle-t.prevAngle,n.position)}),this.registerDisposer(n),this.visibleLayerTracker=Object(j.q)(this.viewer.layerManager,Ee.a,this.viewer.visibleLayerRoles,this),this.registerDisposer(i.crossSectionBackgroundColor.changed.add(()=>this.scheduleRedraw())),this.registerDisposer(n.visibility.add(this.visibility)),this.registerDisposer(n.viewChanged.add(()=>{this.visible&&e.scheduleRedraw()})),this.registerDisposer(i.showAxisLines.changed.add(()=>{this.visible&&this.scheduleRedraw()})),this.registerDisposer(i.showScaleBar.changed.add(()=>{this.visible&&this.context.scheduleRedraw()})),this.registerDisposer(i.scaleBarOptions.changed.add(()=>{this.visible&&this.context.scheduleRedraw()}))}flushBackendProjectionParameters(){this.sliceView.flushBackendProjectionParameters()}get displayDimensionRenderInfo(){return this.navigationState.displayDimensionRenderInfo}get rpc(){return this.sliceView.rpc}get rpcId(){return this.sliceView.rpcId}get navigationState(){return this.sliceView.navigationState}translateByViewportPixels(e,t){const{pose:n}=this.viewer.navigationState;n.updateDisplayPosition(n=>{U.u.set(n,-e,-t,0),U.u.transformMat4(n,n,this.sliceView.projectionParameters.value.invViewMatrix)})}translateDataPointByViewportPixels(e,t,n,i){const r=this.sliceView.projectionParameters.value;return U.u.transformMat4(e,t,r.viewMatrix),U.u.set(e,e[0]+n,e[1]+i,e[2]),U.u.transformMat4(e,e,r.invViewMatrix),e}isReady(){if(!this.visible)return!1;const{sliceView:e}=this;if(!e.isReady())return!1;const t={projectionParameters:e.projectionParameters.value,sliceView:e};for(const[e,n]of this.visibleLayerTracker.visibleLayers)if(!e.isReady(t,n))return!1;return!0}drawWithPicking(e){const{sliceView:t}=this;if(!t.valid)return!1;t.projectionParameters.setViewportShape(this.width,this.height),t.updateRendering();const n=t.projectionParameters.value,{width:i,height:r,invViewMatrix:s,viewProjectionMat:o}=n;U.m.copy(e.invTransform,s);const{gl:a}=this;this.offscreenFramebuffer.bind(i,r),a.disable(WebGL2RenderingContext.SCISSOR_TEST),this.gl.clearColor(0,0,0,0),a.clear(WebGL2RenderingContext.COLOR_BUFFER_BIT);const c=je,l=this.viewer.crossSectionBackgroundColor.value;c[0]=l[0],c[1]=l[1],c[2]=l[2],c[3]=1,this.offscreenFramebuffer.bindSingle(ke.COLOR),this.sliceViewRenderHelper.draw(t.offscreenFramebuffer.colorBuffers[0].texture,U.f,this.colorFactor,c,0,0,1,1);const{visibleLayers:d}=this.visibleLayerTracker;let{pickIDs:u}=this;u.clear();const{displayDimensionRenderInfo:h}=n,p={wireFrame:this.viewer.wireFrame.value,projectionParameters:n,pickIDs:u,emitter:Te,emitColor:!0,emitPickID:!0,sliceView:t};this.offscreenFramebuffer.bind(i,r),a.enable(WebGL2RenderingContext.BLEND),a.blendFunc(WebGL2RenderingContext.SRC_ALPHA,WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA);for(const[e,t]of d)e.draw(p,t);if(a.disable(WebGL2RenderingContext.BLEND),this.viewer.showAxisLines.value||this.viewer.showScaleBar.value){let e=U.m.create();if(this.viewer.showAxisLines.value){U.m.copy(e,o);for(let t=0;t<3;++t)e[12+t]=0;for(let t=0;t<4;++t)e[2+4*t]=0;const t=Math.min(i,r)/4*1.5,s=n.pixelSize,{voxelPhysicalScales:a,displayRank:c}=h;for(let n=0;n<c;++n)for(let i=0;i<2;++i)e[4*n+i]*=t*s/a[n]}this.offscreenFramebuffer.bindSingle(ke.COLOR),this.viewer.showAxisLines.value&&this.axesLineHelper.draw(e),this.viewer.showScaleBar.value&&(a.enable(WebGL2RenderingContext.BLEND),a.blendFunc(WebGL2RenderingContext.SRC_ALPHA,WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA),this.scaleBars.draw(this.width,this.navigationState.displayDimensionRenderInfo.value,this.navigationState.relativeDisplayScales.value,this.navigationState.zoomFactor.value,this.viewer.scaleBarOptions.value),a.disable(WebGL2RenderingContext.BLEND))}return this.offscreenFramebuffer.unbind(),this.setGLViewport(),this.offscreenCopyHelper.draw(this.offscreenFramebuffer.colorBuffers[ke.COLOR].texture),!0}panelSizeChanged(){this.sliceView.projectionParameters.setViewportShape(this.width,this.height)}issuePickRequest(e,t){const{offscreenFramebuffer:n}=this;n.readPixelFloat32IntoBuffer(ke.PICK,e-5,t-5,0,11,11)}completePickRequest(e,t,n,i){const{mouseState:r}=this.viewer;r.pickedRenderLayer=null,re(n,0,4,e,t,i.viewportWidth,i.viewportHeight);const{viewportWidth:s,viewportHeight:o}=i,a=ie.length,c=(n,a,c)=>{const l=e+n-5,d=i.viewportHeight-(t+a-5);U.u.set(De,l-s/2,d-o/2,0),U.u.transformMat4(De,De,i.invTransform);let{position:u}=r;const{value:h}=this.navigationState.position,p=h.length;u.length!==p&&(u=r.position=new Float32Array(p)),u.set(h),r.coordinateSpace=this.navigationState.coordinateSpace.value;const f=this.navigationState.pose.displayDimensions.value,{displayRank:m,displayDimensionIndices:g}=f;for(let e=0;e<m;++e)u[g[e]]=De[e];this.pickIDs.setMouseState(r,c),r.displayDimensions=f,r.setActive(!0)};for(let e=0;e<a;++e){const t=ie[e],i=n[4*e];if(0===i)continue;const r=t%11;return void c(r,(t-r)/11,i)}c(5,5,0)}zoomByMouse(e){const{navigationState:t}=this;if(!t.valid)return;const{sliceView:n}=this,{width:i,height:r,invViewMatrix:s,displayDimensionRenderInfo:{displayDimensionIndices:o,displayRank:a}}=n.projectionParameters.value;let{mouseX:c,mouseY:l}=this;c-=i/2,l-=r/2;const d=this.navigationState.position.value;for(let t=0;t<a;++t){const n=o[t],i=s[t]*c+s[4+t]*l;d[n]+=i*(1-e)}this.navigationState.position.changed.dispatch(),t.zoomBy(e)}}var Pe=n(6),Ae=(n(227),n(7)),Re=n(139),Ne=n(40);
/**
 * @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 Ve=["#f00","#0f0","#00f"],_e=W.a.fromObject({arrowup:{action:"move-up"},arrowdown:{action:"move-down"},wheel:{action:"adjust-via-wheel"},enter:{action:"commit"},escape:{action:"cancel"}});function Be(e){if(e<1||e>1024){const t=0|Math.log2(e),n=e/2**t;return`${Object(Re.a)(n,1)}p${t}`}return e.toString()}const Fe=[e=>e.name,e=>e.scaleFactor];class ze extends o.a{constructor(e,t,n,i="px"){super(),this.displayDimensionRenderInfo=e,this.zoom=t,this.depthRange=n,this.displayUnit=i,this.element=document.createElement("div"),this.dimensionGridContainer=document.createElement("div"),this.depthGridContainer=document.createElement("div"),this.defaultCheckbox=document.createElement("input"),this.dimensionElements=Array.from(Array(3),(e,t)=>{const n=document.createElement("div");n.classList.add("neuroglancer-display-dimensions-widget-dimension"),n.style.display="contents",Object(G.c)(n,"adjust-via-wheel",e=>{const n=e.detail,{deltaY:i}=n;0!==i&&this.zoomDimension(t,Math.sign(i))});const i=document.createElement("input");i.classList.add("neuroglancer-display-dimensions-widget-name"),i.title="Change display dimensions",i.spellcheck=!1,i.autocomplete="off",i.style.color=Ve[t],i.style.gridColumn="1",i.style.gridRow=`${t+1}`,i.addEventListener("focus",()=>{i.select()}),n.appendChild(i);const r=document.createElement("span");r.classList.add("neuroglancer-display-dimensions-widget-scale-factor");const s=document.createElement("input");s.spellcheck=!1,s.title="Change relative scale at which dimension is displayed",s.autocomplete="off",r.style.gridColumn="2",r.style.gridRow=`${t+1}`,s.addEventListener("focus",()=>{s.select()}),r.appendChild(s),n.appendChild(r);const o=document.createElement("span");o.classList.add("neuroglancer-display-dimensions-widget-scale"),o.style.gridColumn="3",o.style.gridRow=`${t+1}`,n.appendChild(o),this.dimensionGridContainer.appendChild(n);const a={name:i,container:n,scaleFactor:s,scale:o,scaleFactorModified:!1};i.addEventListener("input",()=>{Object(Pe.e)(i),this.updateNameValidity()}),Object(G.c)(i,"commit",()=>{this.updateNames()}),i.addEventListener("blur",e=>{const{relatedTarget:t}=e;this.dimensionElements.some(e=>e.name===t)||this.updateNames()||this.updateView()}),r.addEventListener("click",e=>{const{target:t}=e;t!==s&&(s.focus(),e.preventDefault())}),s.addEventListener("input",()=>{Object(Pe.e)(s),a.scaleFactorModified=!0}),Object(G.c)(s,"commit",()=>{this.updateScaleFactors()}),s.addEventListener("blur",()=>{this.updateScaleFactors()||this.updateView()});for(const e of Fe)Object(G.c)(e(a),"move-up",()=>{0!==t&&e(this.dimensionElements[t-1]).focus()}),Object(G.c)(e(a),"move-down",()=>{2!==t&&e(this.dimensionElements[t+1]).focus()});return a}),this.scheduleUpdateView=Object(R.a)(()=>this.updateView());const{element:s,dimensionGridContainer:o,defaultCheckbox:a}=this,c=document.createElement("label"),l=this.registerCancellable(r()(()=>{s.dataset.active="false"},2e3)),d=()=>{s.dataset.active="true",l()};this.registerDisposer(t.changed.add(d)),this.registerDisposer(e.relativeDisplayScales.changed.add(d)),this.registerDisposer(n.changed.add(d)),s.classList.add("neuroglancer-display-dimensions-widget"),s.appendChild(o),o.classList.add("neuroglancer-display-dimensions-widget-dimension-grid"),s.addEventListener("pointerleave",()=>{const e=document.activeElement;e instanceof HTMLElement&&s.contains(e)&&e.blur()}),a.type="checkbox",c.appendChild(a),c.appendChild(document.createTextNode("Default")),c.title="Display first 3 dimensions",c.classList.add("neuroglancer-display-dimensions-widget-default"),a.addEventListener("change",()=>{this.updateDefault()}),o.appendChild(c),this.registerDisposer(e),this.registerDisposer(n),this.registerDisposer(t.changed.add(this.scheduleUpdateView)),this.registerDisposer(e.changed.add(this.scheduleUpdateView)),this.registerDisposer(new G.b(s,_e)).allShortcutsAreGlobal=!0,this.registerDisposer(new W.b(s,_e)),Object(G.c)(o,"cancel",()=>{this.updateView();const e=document.activeElement;e instanceof HTMLElement&&s.contains(e)&&e.blur()});const{depthGridContainer:u}=this;u.classList.add("neuroglancer-depth-range-widget-grid"),s.appendChild(u);const h=document.createElement("label"),p=document.createElement("input");p.type="checkbox",h.classList.add("neuroglancer-depth-range-relative-checkbox-label"),p.classList.add("neuroglancer-depth-range-relative-checkbox"),h.appendChild(p),h.appendChild(document.createTextNode("Zoom-relative")),p.addEventListener("change",()=>{const e=p.checked;let t=this.depthRange.value;e!==t<0&&(t=e?-t/this.zoom.value:-t*this.zoom.value,this.depthRange.value=t)}),h.title="Depth range is multiplied by scale",s.appendChild(h),Object(G.c)(u,"adjust-via-wheel",e=>{const t=e.detail,{deltaY:n}=t;if(0===n)return;const i=this.depthRange.value;this.depthRange.value=i*2**Math.sign(n)}),this.registerDisposer(Object(f.k)((e,t,{factors:n})=>{Object(Pe.b)(u);const{displayRank:i,globalDimensionNames:r,displayDimensionIndices:s,displayDimensionUnits:o,canonicalVoxelFactors:a,canonicalVoxelPhysicalSize:c}=t,l=[],d=()=>{p.checked=this.depthRange.value<0;let e=this.depthRange.value;e<0&&(e*=-this.zoom.value);for(const t of l){const{input:n}=t;n.value=Object(Ne.b)(e*t.scale,t.unit,{precision:2,elide1:!1}),Object(Pe.e)(n)}},h=e=>{const t=Object(Ne.c)(e.input.value);if(void 0===t||t.unit!==e.unit)return!1;let n=t.scale/e.scale;return this.depthRange.value<0&&(n=-n/this.zoom.value),this.depthRange.value=n,!0};for(let e=0;e<i;++e){const t=s[e],i=r[t],p=o[e],f=n[t];let m=l.find(e=>e.unit===p&&e.factor===f);if(void 0===m){const t=document.createElement("div");t.title="Visible depth range",t.style.display="contents",u.appendChild(t);const n=document.createElement("span");n.textContent="±",t.appendChild(n);const i=document.createElement("input");i.spellcheck=!1,i.autocomplete="off",i.addEventListener("focus",()=>{i.select()}),Object(G.c)(i,"commit",()=>{h(m)}),i.addEventListener("change",()=>{h(m)||d()}),i.addEventListener("input",()=>{Object(Pe.e)(i)}),t.appendChild(i);const r=document.createElement("span");r.classList.add("neuroglancer-depth-range-widget-dimension-names"),t.appendChild(r),m={unit:p,factor:f,dimensionNames:[],input:i,label:r,scale:c*a[e]},l.push(m)}m.dimensionNames.push(i)}for(const e of l)e.dimensionNames.length!==i&&(e.label.textContent=e.dimensionNames.join(" "));e.registerDisposer(Object(G.c)(u,"cancel",()=>{d();const e=document.activeElement;e instanceof HTMLElement&&u.contains(e)&&e.blur()}));const f=e.registerCancellable(Object(R.a)(d));e.registerDisposer(this.depthRange.changed.add(f)),e.registerDisposer(this.zoom.changed.add(f)),d()},e,this.relativeDisplayScales)),this.updateView()}zoomDimension(e,t){this.updateScaleFactors();const{displayDimensions:n}=this,{relativeDisplayScales:i}=this,{displayDimensionIndices:r}=n.value,s=r[e];if(-1===s)return;const{factors:o}=i.value,a=new Float64Array(o);a[s]*=2**-t,i.setFactors(a)}updateNameValidity(){const{dimensionElements:e}=this,{displayDimensionIndices:t}=this.displayDimensions.value,n=e.map(e=>e.name.value),i=Object(C.q)(n),r=this.displayDimensions.coordinateSpace.value,{names:s}=r,o=n.length;for(let r=0;r<o;++r){let o=i[r];const a=n[r];let c=-1;0===a.length?o=!0:(c=s.indexOf(a),-1===c&&(o=!1));const l=e[r];l.name.dataset.isValid=o.toString(),l.container.dataset.isModified=(c!==t[r]).toString()}}get displayDimensions(){return this.displayDimensionRenderInfo.displayDimensions}get relativeDisplayScales(){return this.displayDimensionRenderInfo.relativeDisplayScales}updateNames(){const e=this.dimensionElements.map(e=>e.name.value).filter(e=>e.length>0);if(!Object(C.E)(e))return!1;const{displayDimensions:t}=this.displayDimensionRenderInfo;if(0===e.length)return t.reset(),!0;const n=new Int32Array(3);n.fill(-1);const i=t.coordinateSpace.value,{names:r}=i,s=e.length;for(let t=0;t<s;++t){const i=r.indexOf(e[t]);if(-1===i)return!1;n[t]=i}return!!Object(Ae.a)(n,t.value.displayDimensionIndices)||(t.setDimensionIndices(s,n),!0)}updateDefault(){this.displayDimensions.default=this.defaultCheckbox.checked}updateScaleFactors(){const{displayDimensions:e}=this,{relativeDisplayScales:t}=this,{displayDimensionIndices:n,displayRank:i}=e.value,{factors:r}=t.value,{dimensionElements:s}=this,o=new Float64Array(r);for(let e=0;e<i;++e){const t=s[e];if(!t.scaleFactorModified)continue;const i=Number(t.scaleFactor.value),r=n[e];!Number.isFinite(i)||i<=0||(o[r]=i)}return Object(Ae.a)(o,r)||t.setFactors(o),!0}updateView(){const{dimensionElements:e,displayDimensions:{default:t}}=this,{displayDimensionIndices:n,canonicalVoxelFactors:i,displayDimensionUnits:r,displayDimensionScales:s,globalDimensionNames:o}=this.displayDimensionRenderInfo.value,{factors:a}=this.relativeDisplayScales.value;this.defaultCheckbox.checked=t;const c=this.zoom.value,l=n[0];let d=!0;if(-1!==l){const e=r[0],t=a[l];for(let i=1;i<3;++i){const s=n[i];if(-1!==s&&(r[i]!==e||a[s]!==t)){d=!1;break}}}for(let t=0;t<3;++t){const l=n[t],u=e[t];if(delete u.name.dataset.isValid,u.container.dataset.isModified=(-1===l).toString(),-1===l)u.name.value="",u.scale.textContent="",u.scaleFactor.value="";else{u.name.value=o[l];const e=s[t]*c/i[t];if(0!==t&&d)u.scale.textContent="";else{const n=Object(Ne.b)(e,r[t],{precision:2,elide1:!1});u.scale.textContent=`${n}/${this.displayUnit}`}u.scaleFactor.value=Be(a[l])}Object(Pe.e)(u.name),Object(Pe.e)(u.scaleFactor)}}disposed(){Object(Pe.c)(this.element),super.disposed()}}
/**
 * @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=new Map([["xy",void 0],["xz",U.p.rotateX(U.p.create(),U.p.create(),Math.PI/2)],["yz",U.p.rotateY(U.p.create(),U.p.create(),Math.PI/2)]]),Ge=new Map([["4panel","◱"],["3d","◻"]]);function $e(e,t){return function(e,t){let n;return n=void 0===t?e.navigationState.addRef():new T.i(new T.a(e.navigationState.pose.position.addRef(),e.navigationState.pose.displayDimensionRenderInfo.addRef(),T.j.makeRelative(e.navigationState.pose.orientation,t)),e.navigationState.zoomFactor.addRef(),e.navigationState.depthRange.addRef()),new ce.b(e.chunkManager,e.layerManager,n,e.wireFrame)}(e,Ue.get(t))}function We(e){return{crossSectionBackgroundColor:e.crossSectionBackgroundColor,perspectiveViewBackgroundColor:e.perspectiveViewBackgroundColor,selectionDetailsState:e.selectionDetailsState,mouseState:e.mouseState,layerManager:e.layerManager,showAxisLines:e.showAxisLines,wireFrame:e.wireFrame,visibleLayerRoles:e.visibleLayerRoles,selectedLayer:e.selectedLayer,visibility:e.visibility,scaleBarOptions:e.scaleBarOptions}}function He(e){const{viewer:t}=e;return Object.assign(Object.assign({},We(t)),{navigationState:t.perspectiveNavigationState,inputEventMap:t.inputEventBindings.perspectiveView,orthographicProjection:e.specification.orthographicProjection,showScaleBar:t.showScaleBar,rpc:t.chunkManager.rpc})}function Je(e){return Object.assign(Object.assign({},We(e)),{navigationState:e.navigationState,inputEventMap:e.inputEventBindings.sliceView})}function qe(e,t){const{navigationState:n}=t;t.element.appendChild(e.registerDisposer(new ze(n.pose.displayDimensionRenderInfo.addRef(),n.zoomFactor,n.depthRange.addRef(),t instanceof Ie?"px":"vh")).element)}function Ye(e,t,n){const i=document.createElement("div");i.className="neuroglancer-data-panel-layout-controls",e.registerDisposer(()=>Object(Pe.c)(i));for(let i=0;i<2;++i){const r=n[Math.min(n.length-1,i)];e.registerDisposer(Object(S.d)(t.element,0===i?"toggle-layout":"toggle-layout-alternative",t=>{e.container.name=r,t.stopPropagation()}))}for(const t of n){const n=document.createElement("button"),r=document.createElement("div");n.appendChild(r),r.textContent=Ge.get(t),n.title=`Switch to ${t} layout.`,n.addEventListener("click",()=>{e.container.name=t}),i.appendChild(n)}t.element.appendChild(i)}function Xe(e,t){const n=new ce.b(e.chunkManager,e.layerManager,t.navigationState.addRef(),e.wireFrame),i=()=>{n.projectionParameters.setViewportShape(t.width.value,t.height.value)};return n.registerDisposer(t.width.changed.add(i)),n.registerDisposer(t.height.changed.add(i)),i(),n}function Ke(e,t,n){const i=new Map;(()=>{const r=new Set;for(const s of n.values()){if(r.add(s),i.has(s))continue;const n=Xe(e,s);t.sliceViews.set(n,!0),i.set(s,n)}for(const[e,n]of i)r.has(e)||t.sliceViews.delete(n)})()}class Qe extends o.a{constructor(e,t,n,i){super(),this.container=e,this.rootElement=t,this.viewer=n;let r=(s=n,new Map([["xy",$e(s,"xy")],["xz",$e(s,"xz")],["yz",$e(s,"yz")]]));var s;let{display:o}=n;const a=Object.assign(Object.assign({},He(e)),{showSliceViews:n.showPerspectiveSliceViews,showSliceViewsCheckbox:!0}),c=Object.assign(Object.assign({},Je(n)),{showScaleBar:n.showScaleBar}),l=Object.assign(Object.assign({},Je(n)),{showScaleBar:new le.b(!1,!1)}),d=(e,t,n,i)=>{const s=this.registerDisposer(new Ie(o,t,r.get(e),n));return i&&qe(this,s),Ye(this,s,[e,`${e}-3d`]),s};let u=[k(1,E("column",[k(1,E("row",[k(1,e=>{d("xy",e,c,!0)}),k(1,e=>{d("xz",e,l,!1)})])),k(1,E("row",[k(1,e=>{let t=this.registerDisposer(new Oe(o,e,a));for(let e of r.values())t.sliceViews.set(e.addRef(),!1);qe(this,t),Ke(n,t,i),Ye(this,t,["3d"])}),k(1,e=>{d("yz",e,l,!1)})]))]))];E("row",u)(t)}disposed(){Object(Pe.b)(this.rootElement),super.disposed()}}class Ze extends o.a{constructor(e,t,n,i,r,s){super(),this.container=e,this.rootElement=t,this.viewer=n,this.direction=i;let o=$e(n,r),{display:a}=n;const c=Object.assign(Object.assign({},He(e)),{showSliceViews:n.showPerspectiveSliceViews,showSliceViewsCheckbox:!0}),l=Object.assign(Object.assign({},Je(n)),{showScaleBar:n.showScaleBar});k(1,E(i,[k(1,e=>{const t=this.registerDisposer(new Ie(a,e,o,l));qe(this,t),Ye(this,t,[r,"4panel"])}),k(1,e=>{let t=this.registerDisposer(new Oe(a,e,c));t.sliceViews.set(o.addRef(),!1),Ke(n,t,s),qe(this,t),Ye(this,t,["3d","4panel"])})]))(t)}disposed(){Object(Pe.b)(this.rootElement),super.disposed()}}class et extends o.a{constructor(e,t,n,i){super(),this.container=e,this.rootElement=t,this.viewer=n;let r=$e(n,i);const s=Object.assign(Object.assign({},Je(n)),{showScaleBar:n.showScaleBar});E("row",[k(1,e=>{const t=this.registerDisposer(new Ie(n.display,e,r,s));qe(this,t),Ye(this,t,["4panel",`${i}-3d`])})])(t)}disposed(){Object(Pe.b)(this.rootElement),super.disposed()}}class tt extends o.a{constructor(e,t,n,i){super(),this.container=e,this.rootElement=t,this.viewer=n;let r=Object.assign(Object.assign({},He(e)),{showSliceViews:new le.b(!1,!1)});E("row",[k(1,e=>{const t=this.registerDisposer(new Oe(n.display,e,r));Ke(n,t,i),qe(this,t),Ye(this,t,["4panel"])})])(t)}disposed(){Object(Pe.b)(this.rootElement),super.disposed()}}const nt=new Map([["4panel",{factory:(e,t,n,i)=>new Qe(e,t,n,i)}],["3d",{factory:(e,t,n,i)=>new tt(e,t,n,i)}]]);for(const e of Ue.keys()){nt.set(e,{factory:(t,n,i)=>new et(t,n,i,e)});const t=`${e}-3d`;Ge.set(e,"◻"),Ge.set(t,"◫"),nt.set(t,{factory:(t,n,i,r)=>new Ze(t,n,i,"row",e,r)})}function it(e){let t=nt.get(e);if(void 0===t)throw new Error(`Invalid layout name: ${JSON.stringify(e)}.`);return t}function rt(e){return it(e),e}class st extends o.a{constructor(e){super(),this.width=new f.c(1e3,g.D),this.height=new f.c(1e3,g.D),this.changed=new y.a,this.position=new T.e(e.position.addRef()),this.position.changed.add(this.changed.dispatch),this.orientation=new T.d(e.pose.orientation.addRef()),this.orientation.changed.add(this.changed.dispatch),this.width.changed.add(this.changed.dispatch),this.height.changed.add(this.changed.dispatch),this.scale=new T.g(e.zoomFactor.addRef(),e.zoomFactor.displayDimensionRenderInfo.addRef()),this.scale.changed.add(this.changed.dispatch),this.navigationState=this.registerDisposer(new T.i(new T.a(this.position.value,e.pose.displayDimensionRenderInfo.addRef(),this.orientation.value),this.scale.value,e.depthRange.addRef()))}restoreState(e){Object(g.w)(e),Object(m.d)(e,"width",this.width),Object(m.d)(e,"height",this.height),Object(m.d)(e,"position",Object(T.r)(this.position)),Object(m.d)(e,"orientation",this.orientation),Object(m.d)(e,"scale",this.scale),Object(m.d)(e,"zoom",Object(T.r)(this.scale))}reset(){this.width.reset(),this.height.reset(),this.position.reset(),this.orientation.reset(),this.scale.reset()}toJSON(){return{width:this.width.toJSON(),height:this.height.toJSON(),position:this.position.toJSON(),orientation:this.orientation.toJSON(),scale:this.scale.toJSON()}}}class ot extends de.a{constructor(e){super((e,t)=>e.registerDisposer(e.registerDisposer(t).changed.add(this.changed.dispatch))),this.parentNavigationState=e,this.registerDisposer(e)}restoreState(e){Object(g.w)(e);for(const t of Object.keys(e)){const n=new st(this.parentNavigationState);try{this.set(t,n.addRef()),n.restoreState(e[t])}finally{n.dispose()}}}reset(){this.clear()}toJSON(){if(0===this.size)return;const e={};for(const[t,n]of this)e[t]=n.toJSON();return e}}class at extends o.a{constructor(e,t){super(),this.changed=new y.a,this.orthographicProjection=new le.b(!1),this.type=new f.c(t,rt),this.type.changed.add(this.changed.dispatch),this.crossSections=this.registerDisposer(new ot(e.addRef())),this.crossSections.changed.add(this.changed.dispatch),this.orthographicProjection.changed.add(this.changed.dispatch),this.registerDisposer(e)}reset(){this.crossSections.clear(),this.orthographicProjection.reset(),this.type.reset()}restoreState(e){this.crossSections.clear(),this.orthographicProjection.reset(),"string"==typeof e?this.type.restoreState(e):(Object(g.w)(e),Object(g.y)(e,"type",e=>this.type.restoreState(e)),Object(g.y)(e,"orthographicProjection",e=>this.orthographicProjection.restoreState(e)),Object(g.y)(e,"crossSections",e=>void 0!==e&&this.crossSections.restoreState(e)))}toJSON(){const{type:e,crossSections:t,orthographicProjection:n}=this,i=n.toJSON();return 0===t.size&&void 0===i?e.value:{type:e.value,crossSections:t.toJSON(),orthographicProjection:i}}}class ct extends o.a{constructor(e,t){super(),this.viewer=e,this.element=document.createElement("div"),this.specification=this.registerDisposer(new at(this.viewer.navigationState.addRef(),t)),this.element.style.flex="1";const n=this.registerCancellable(r()(()=>this.updateLayout(),0));this.specification.type.changed.add(n),Object(S.d)(this.element,"toggle-orthographic-projection",()=>this.specification.orthographicProjection.toggle()),this.registerDisposer(this.viewer.display.updateStarted.add(()=>n.flush())),n()}get name(){return this.specification.type.value}set name(e){this.specification.type.value=e}get changed(){return this.specification.changed}toJSON(){return this.specification.toJSON()}restoreState(e){this.specification.restoreState(e)}reset(){this.specification.reset()}disposeLayout(){let{layout:e}=this;void 0!==e&&(e.dispose(),this.layout=void 0)}updateLayout(){this.disposeLayout(),this.layout=it(this.name).factory(this,this.element,this.viewer,this.specification.crossSections)}disposed(){this.disposeLayout(),super.disposed()}}var lt=n(67);n(228);
/**
 * @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 dt(e){return e.startsWith("key")?e.substring(3):e.startsWith("digit")?e.substring(5):e.startsWith("arrow")?e.substring(5):e}class ut extends lt.a{constructor(e){super();let{content:t}=this;t.classList.add("describe-key-bindings");let n=document.createElement("div");n.classList.add("describe-key-bindings-container");const i=new Map;function r(e,t){if(i.has(t))return;const n={label:e,entries:new Map};!function e(t,n){for(const i of t.parents)void 0!==i.label?r(i.label,i):e(i,n);for(const[e,i]of t.bindings.entries()){const t=e.indexOf(":"),r=e.substring(t+1);n.set(r,i.action)}}(t,n.entries),i.set(t,n)}for(const[t,n]of e)r(t,n);for(const e of i.values()){let t=document.createElement("h2");t.textContent=e.label,n.appendChild(t);for(const[t,i]of e.entries){let e=document.createElement("div");e.className="dt",e.textContent=t.split("+").map(dt).join("+");let r=document.createElement("div");r.className="dd",r.textContent=i,n.appendChild(e),n.appendChild(r)}}t.appendChild(n)}}n(229),n(230),n(231);var ht=n(107),pt=n.n(ht),ft=n(124);
/**
 * @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 mt(e){return Object(ft.b)((new TextEncoder).encode(e))}function gt(e,t){var n;if(e.startsWith(t))try{const i=(n=e.substring(t.length),(new TextDecoder).decode(Object(ft.a)(n)));return JSON.parse(i)}catch(e){return}}let vt;function bt(e,t){return e.dataTransfer.dropEffect=t,vt=t,t}function yt(){return vt}let St;function wt(e,t){var n,i;let r;e.dataTransfer.setData((n="neuroglancer-layer\0",i=t.layers.map(e=>({name:e.name,visible:e.visible})),n+mt(JSON.stringify(i))),JSON.stringify({layers:t.layers.map(e=>e.toJSON()),layout:t.layoutSpec})),void 0!==St&&St.disposer();let s=()=>{t.manager.unregisterDisposer(s);for(const e of t.layers)e.dispose();t.manager.dispose(),St===r&&(St=void 0)};St=r={manager:t.manager.addRef(),layers:t.layers.map(e=>e.addRef()),layoutSpec:t.layoutSpec,disposer:s}}function xt(e){if(void 0!==St){if(e&&"move"===e.dataTransfer.dropEffect){const e=new Set(St.layers);St.manager.layerManager.filter(t=>!e.has(t))}St.disposer()}}function Ct(e){return function(e,t){for(const n of e){const e=gt(n,t);if(void 0!==e)return{parameters:e,dragType:n}}}(e.dataTransfer.types,"neuroglancer-layer\0")}function Ot(e){if(void 0!==St&&St.manager.rootLayers===e.rootLayers)return St}class kt{finalize(e){const{dragType:t}=this;if(void 0!==t)try{const{layers:n,layout:i}=JSON.parse(e.dataTransfer.getData(t));if(!Array.isArray(n)||this.numSourceLayers!==n.length)throw new Error("Invalid layer drop data");this.layoutSpec=i;for(const[e,t]of this.layers)this.manager.initializeLayerFromSpec(e,n[t]);return!0}catch(e){return!1}return!0}get method(){return void 0!==this.sourceManager?this.manager===this.sourceManager?"move":"link":"copy"}compatibleWithMethod(e){return this.method===e||!this.moveSupported&&"move"===e}}function Et(e,t,n=!1){return e.shiftKey?"copy":e.ctrlKey?"move":function(e,t=!1){const n=Ot(e);return void 0===n?"copy":t||n.manager!==e?"link":"move"}(t,n)}function Tt(e,t,n,i,r){const s=Ot(t),o=!r&&void 0!==s&&s.manager===t;if(!n&&void 0!==s){const e=new kt;if(e.manager=t,e.numSourceLayers=s.layers.length,e.sourceManager=s.manager,e.moveSupported=o,e.layers=new Map,e.layoutSpec=s.layoutSpec,!r&&s.manager===t){if(!i)return;s.layers.forEach((t,n)=>{e.layers.set(t,n)})}return s.layers.forEach((n,i)=>{!r&&t.layerManager.has(n)||e.layers.set(n.addRef(),i)}),e}const a=Ct(e);if(void 0!==a)try{const e=Object(g.b)(a.parameters,(e,n)=>{const i=Object(g.y)(e,"name",g.E),r=Object(g.y)(e,"visible",g.n),s=new j.e(i,null,t);return s.visible=r,[s,n]}),n=new kt;return n.numSourceLayers=e.length,n.moveSupported=o,n.manager=t,n.dragType=a.dragType,n.layers=new Map(e),n}catch(e){}}var Mt=n(179),Dt=n.n(Mt),Lt=n(27);
/**
 * @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 jt(e={}){return Object(Lt.a)(Object.assign({svg:Dt.a},e))}n(232);var It=n(47),Pt=n(66),At=n(62);
/**
 * @license
 * Copyright 2017-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 Rt=W.a.fromObject({arrowup:{action:"adjust-up"},arrowdown:{action:"adjust-down"},arrowleft:{action:"maybe-tab-backward",preventDefault:!1},arrowright:{action:"maybe-tab-forward",preventDefault:!1},tab:{action:"tab-forward"},"shift+tab":{action:"tab-backward"},wheel:{action:"adjust-via-wheel"},backspace:{action:"delete-backward",preventDefault:!1},enter:{action:"commit"},escape:{action:"cancel"}}),Nt=[e=>e.nameElement,e=>e.coordinate,e=>e.scaleElement];class Vt{constructor(e){this.coordinateSpace=e,this.container=document.createElement("div"),this.nameContainer=document.createElement("span"),this.nameElement=document.createElement("input"),this.scaleContainer=document.createElement("span"),this.scaleElement=document.createElement("input"),this.coordinate=document.createElement("input"),this.dropdownOwner=void 0,this.modified=!1,this.draggingPosition=!1,this.hasFocus=!1;const{container:t,scaleElement:n,scaleContainer:i,coordinate:r,nameElement:s,nameContainer:o}=this;t.title="",t.classList.add("neuroglancer-position-dimension"),t.draggable=!0,t.tabIndex=-1,t.appendChild(o),t.appendChild(n),o.appendChild(s),o.title="Drag to reorder, double click to rename.  Names ending in ' or ^ indicate dimensions local to the layer; names ending in ^ indicate channel dimensions (image layers only).",i.appendChild(n),s.classList.add("neuroglancer-position-dimension-name"),s.disabled=!0,s.spellcheck=!1,s.autocomplete="off",s.required=!0,s.placeholder=" ",i.classList.add("neuroglancer-position-dimension-scale-container"),n.classList.add("neuroglancer-position-dimension-scale"),n.disabled=!0,n.spellcheck=!1,n.autocomplete="off",i.title="Drag to reorder, double click to change scale",t.appendChild(i),t.appendChild(r),r.type="text",r.classList.add("neuroglancer-position-dimension-coordinate"),r.spellcheck=!1,r.autocomplete="off",r.pattern=String.raw`(-?\d+(?:\.(?:\d+)?)?)`,r.required=!0,r.placeholder=" "}}function _t(e,t,n,i){return Math.floor((e-t)*(i-1)/(n-t))}function Bt(e,t){Object(Pe.e)(e,t.length+1)}function Ft(e){const{value:t}=e;Object(Pe.e)(e),e.parentElement.dataset.isEmpty=""===t?"true":"false"}class zt extends o.a{constructor(e,t,{copyButton:n=!0}={}){super(),this.position=e,this.combiner=t,this.element=document.createElement("div"),this.dimensionContainer=document.createElement("div"),this.coordinateSpace=void 0,this.dimensionWidgets=new Map,this.dimensionWidgetList=[],this.dragSource=void 0;const{element:i,dimensionContainer:r}=this;if(this.registerDisposer(e.coordinateSpace.changed.add(this.registerCancellable(Object(R.a)(()=>this.updateDimensions())))),i.className="neuroglancer-position-widget",r.style.display="contents",i.appendChild(r),n){const t=Object(At.a)({title:"Copy position to clipboard",onClick:()=>{const e=Object(Pt.a)(this.getPositionText());It.a.showTemporaryMessage(e?"Position copied to clipboard":"Failed to copy position to clipboard")}});t.addEventListener("dragstart",t=>{t.dataTransfer.setData("neuroglancer-position",JSON.stringify({position:e.toJSON(),dimensions:e.coordinateSpace.value.names})),t.dataTransfer.setData("text",this.getPositionText()),t.stopPropagation()}),t.draggable=!0,i.appendChild(t)}this.registerDisposer(e.changed.add(this.registerCancellable(Object(R.a)(()=>this.updateView())))),this.registerDisposer(new G.b(i,Rt)).allShortcutsAreGlobal=!0,this.registerDisposer(new W.b(i,Rt)),this.registerDisposer(Object(G.c)(i,"cancel",e=>{this.coordinateSpace=void 0,this.updateView(),this.closeDropdown();const{target:t}=e;t instanceof HTMLElement&&t.blur()})),this.updateView()}openDropdown(e){if(void 0!==e.dropdownOwner)return;this.closeDropdown();const t=e.dropdownOwner=new o.a,n=document.createElement("div");n.draggable=!0,n.addEventListener("dragstart",e=>{e.stopPropagation(),e.preventDefault()}),n.addEventListener("pointerenter",()=>{e.hasFocus=!0}),n.tabIndex=-1,n.classList.add("neuroglancer-position-dimension-dropdown");const i=document.createElement("canvas"),r=i.getContext("2d"),s=document.createElement("div"),a=document.createElement("div");a.appendChild(s);const c=document.createTextNode("");s.appendChild(c);const l=document.createElement("div"),d=document.createElement("div");a.classList.add("neuroglancer-position-dimension-dropdown-lowerbound"),l.classList.add("neuroglancer-position-dimension-dropdown-upperbound"),d.classList.add("neuroglancer-position-dimension-dropdown-hoverposition"),n.appendChild(a),n.appendChild(l),n.appendChild(d),n.appendChild(i),e.container.appendChild(n);let u,h;i.width=35,i.height=100,l.style.marginTop="99px";let p=void 0;const f=()=>{const t=this.dimensionWidgetList.indexOf(e);if(-1===t)return;const{coordinateSpace:o}=e,a=function(e,t,n){const{boundingBoxes:i,bounds:r}=e,s=Math.floor(r.lowerBounds[t]),o=Math.ceil(r.upperBounds[t]-1);if(!Number.isFinite(s)||!Number.isFinite(o))return;const a=[],c=e=>_t(e,s,o,n),{rank:l}=e;for(const e of i){const n=Object(C.d)(e,t,l);void 0!==n&&(n.lower=c(n.lower),n.upper=c(Math.ceil(n.upper-1)),a.push(n))}return a.sort((e,t)=>{const n=e.lower-t.lower;return 0!==n?n:t.upper-t.upper}),Object(Ae.d)(a,(e,t)=>{if(0===t)return!0;const n=a[t-1];return n.lower!==e.lower||n.upper!==e.upper}),{lowerBound:s,upperBound:o,normalizedBounds:a}}(o,t,100);if(void 0===a||o.bounds.lowerBounds[t]+1===o.bounds.upperBounds[t])return n.style.display="none",void(e.container.dataset.dropdownVisible=void 0);e.container.dataset.dropdownVisible="true",n.style.display="";const{lowerBound:f,upperBound:m}=a;u=f,h=m,c.textContent=f.toString(),l.textContent=m.toString(),function(e,t,n){t.clearRect(0,0,e.width,e.height);const{normalizedBounds:i}=n;function r(e){t.fillRect(0,e,10,1)}t.fillStyle="#fff";for(const{lower:e,upper:t}of i)r(e),r(t);const s=i.length;t.fillStyle="#ccc";for(let e=0;e<s;++e){const{lower:n,upper:r}=i[e],o=Math.floor(15*e/s),a=Math.max(1,15/s);t.fillRect(o+10,n,a,r+1-n)}}(i,r,a);const g=this.position.value[t];if(g>=f&&g<=m&&(r.fillStyle="#f66",r.fillRect(0,_t(g,f,m,100),35,1)),void 0!==p&&p>=f&&p<=m){r.fillStyle="#66f";const e=_t(p,f,m,100);r.fillRect(0,e,35,1),d.textContent=p.toString();const t=s.clientHeight;s.style.visibility=e>t?"":"hidden",l.style.visibility=e<100-t?"":"hidden",d.style.display="",d.style.visibility="visible",d.style.marginTop=`${e}px`}else s.style.visibility="",d.style.display="none",l.style.visibility=""},m=t.registerCancellable(Object(R.a)(f));t.registerDisposer(this.position.changed.add(m));const g=e=>{if(void 0===u||void 0===h)return;const t=i.getBoundingClientRect();let n=(e.clientY-t.top)/t.height;return n=Math.max(0,n),n=Math.min(1,n),Math.round(n*(h-u))+u},v=t=>{const n=this.dimensionWidgetList.indexOf(e);if(-1===n)return;const i=g(t);if(void 0===i)return;const{position:r}=this,s=r.value;s[n]=i+.5,e.modified=!1,r.value=s};i.addEventListener("pointermove",e=>{const t=g(e);p=t,m()}),i.addEventListener("pointerleave",()=>{p=void 0,m()}),i.addEventListener("pointerdown",t=>{t.preventDefault(),t.stopPropagation(),t.ctrlKey||t.altKey||t.shiftKey||t.metaKey||(H(t,t=>{void 0!==e.dropdownOwner&&(p=void 0,v(t),m(),e.draggingPosition=!0)},()=>{e.draggingPosition=!1,this.updateDropdownVisibility(e)}),v(t))}),f(),this.widgetWithOpenDropdown=e,t.registerDisposer(()=>{Object(Pe.c)(n),e.dropdownOwner=void 0,delete e.container.dataset.dropdownVisible,this.widgetWithOpenDropdown=void 0}),t.registerEventListener(document,"pointerdown",t=>{const{target:n}=t;n instanceof Node&&e.container.contains(n)||this.closeDropdown(e)},{capture:!0})}closeDropdown(e=this.widgetWithOpenDropdown){if(void 0===e)return;const{dropdownOwner:t}=e;void 0!==t&&t.dispose()}pasteString(e,t){for(;;){e.coordinate.focus();const n=t.match(/^\s*(-?\d+(?:\.(?:\d+)?)?)((?:\s+(?![\s,]))|(?:\s*,\s*))?/);if(null===n)break;if(void 0!==n[1]&&document.execCommand("insertText",void 0,n[1]),void 0===n[2])break;{const{dimensionWidgetList:i}=this,r=i.indexOf(e);if(-1===r||r+1===i.length)break;const s=t.substring(n[0].length);e=i[r+1],t=s}}}reorderDimensionTo(e,t){if(e===t)return;const{coordinateSpace:n}=this.position;n.value=Object(C.t)(n.value,e,t)}updateDropdownVisibility(e){e.hasFocus||e.draggingPosition?this.openDropdown(e):this.closeDropdown(e)}newDimension(e){const t=new Vt(e);t.container.addEventListener("dragstart",e=>{this.dragSource=t,e.stopPropagation(),e.dataTransfer.setData("neuroglancer-dimension","")}),t.container.addEventListener("dragenter",e=>{const{dragSource:n}=this;if(void 0===n||n===t)return;const{dimensionWidgetList:i}=this,r=i.indexOf(n),s=i.indexOf(t);-1!==r&&-1!==s&&(e.preventDefault(),this.reorderDimensionTo(s,r))}),t.container.addEventListener("dragend",e=>{this.dragSource===t&&(this.dragSource=void 0)}),t.nameContainer.addEventListener("dblclick",()=>{t.nameElement.disabled=!1,t.nameElement.focus(),t.nameElement.select()}),t.scaleContainer.addEventListener("dblclick",()=>{t.scaleElement.disabled=!1,t.scaleElement.focus(),t.scaleElement.select()}),t.coordinate.addEventListener("focus",()=>{t.coordinate.select()}),t.container.addEventListener("focusin",()=>{t.hasFocus=!0,this.updateDropdownVisibility(t)}),t.container.addEventListener("focusout",e=>{const{relatedTarget:n}=e;n instanceof Node&&t.container.contains(n)||(t.hasFocus=!1,this.updateDropdownVisibility(t))}),t.container.addEventListener("click",e=>{e.target instanceof HTMLInputElement&&!e.target.disabled||t.coordinate.focus()}),t.coordinate.addEventListener("paste",e=>{const n=t.coordinate,i=n.value,{clipboardData:r}=e;if(null===r)return;let s=r.getData("text"),{selectionEnd:o,selectionStart:a}=n;if(0!==a||o!==i.length){null==a&&(a=0),null==o&&(o=0);const e=s.match(/[^\-0-9\.]/);null!==e&&(s=s.substring(0,e.index)),s.length>0&&document.execCommand("insertText",void 0,s)}else this.pasteString(t,s);e.preventDefault(),e.stopPropagation()}),t.coordinate.addEventListener("input",()=>{t.modified=!0;const e=t.coordinate,n=e.value;let{selectionDirection:i,selectionEnd:r,selectionStart:s}=e;null===s&&(s=0),null===r&&(r=s);let o="";const a=/[^\-0-9\.]/g;o+=n.substring(0,s).replace(a,"");const c=o.length;o+=n.substring(s,r).replace(a,"");const l=o.length;o+=n.substring(r).replace(a,""),e.value=o,e.selectionStart=c,e.selectionEnd=l,e.selectionDirection=i,Bt(e,o),r===s&&r===n.length&&n.match(/^(-?\d+(?:\.(?:\d+)?)?)((?:\s+(?![\s,]))|(?:\s*,\s*))$/)&&this.selectAdjacentCoordinate(t,1)}),t.nameElement.addEventListener("input",()=>{const{nameElement:e}=t;Object(Pe.e)(e),this.updateNameValidity()}),t.scaleElement.addEventListener("input",()=>{const{scaleElement:e}=t;Ft(e),this.updateScaleValidity(t)}),t.coordinate.addEventListener("blur",e=>{const{relatedTarget:n}=e;this.dimensionWidgetList.some(e=>e.coordinate===n)||t.modified&&this.updatePosition()}),t.nameElement.addEventListener("blur",e=>{t.nameElement.disabled=!0;const{relatedTarget:n}=e;this.dimensionWidgetList.some(e=>e.nameElement===n)||this.updateNames()||this.forceUpdateDimensions()}),t.scaleElement.addEventListener("blur",e=>{t.scaleElement.disabled=!0;const{relatedTarget:n}=e;this.dimensionWidgetList.some(e=>e.scaleElement===n)||this.updateScales()||this.forceUpdateDimensions()}),Object(G.c)(t.container,"adjust-via-wheel",e=>{const n=e.detail,{deltaY:i}=n;0!==i&&this.adjustDimension(t,Math.sign(i))}),Object(G.c)(t.container,"adjust-up",()=>{this.adjustDimension(t,-1)}),Object(G.c)(t.container,"adjust-down",()=>{this.adjustDimension(t,1)});for(const e of Nt){const n=e(t);Object(G.c)(n,"maybe-tab-forward",n=>{this.handleLeftRightMovement(n,t,1,e)}),Object(G.c)(n,"maybe-tab-backward",n=>{this.handleLeftRightMovement(n,t,-1,e)}),Object(G.c)(n,"tab-forward",()=>{this.selectAdjacentField(t,1,e)}),Object(G.c)(n,"tab-backward",()=>{this.selectAdjacentField(t,-1,e)})}return Object(G.c)(t.coordinate,"commit",()=>{this.updatePosition()}),Object(G.c)(t.nameElement,"commit",()=>{this.updateNames()}),Object(G.c)(t.scaleElement,"commit",()=>{this.updateScales()}),Object(G.c)(t.coordinate,"delete-backward",e=>{e.stopPropagation();const{coordinate:n}=t;n.selectionStart===n.selectionEnd&&0===n.selectionStart&&(e.preventDefault(),this.selectAdjacentCoordinate(t,-1))}),t}forceUpdateDimensions(){let{position:{coordinateSpace:{value:e}}}=this;e.valid||(e=C.k),this.coordinateSpace=e;const{dimensionWidgets:t,dimensionWidgetList:n}=this;n.length=0;const{names:i,ids:r,scales:s,units:o}=e;Object(Pe.d)(this.dimensionContainer,r.map((r,a)=>{let c=t.get(r);void 0===c?(c=this.newDimension(e),t.set(r,c)):c.coordinateSpace=e;const l=i[a];c.nameElement.value=l,delete c.nameElement.dataset.isValid,Object(Pe.e)(c.nameElement);const{scale:d,prefix:u,unit:h}=Object(Ne.a)(s[a],o[a]),p=`${d}${u}${h}`;return c.scaleElement.value=p,delete c.scaleElement.dataset.isValid,Ft(c.scaleElement),n.push(c),c.container}));for(const[n,i]of t)i.coordinateSpace!==e&&(this.closeDropdown(i),t.delete(n))}updateDimensions(){const{position:{coordinateSpace:{value:e}}}=this;e!==this.coordinateSpace&&this.forceUpdateDimensions()}selectAdjacentField(e,t,n){const{dimensionWidgetList:i}=this,r=i.indexOf(e);if(-1===r)return;const s=r+t;if(s<0||s>=i.length)return!1;const o=n(i[s]);return o.disabled=!1,o.focus(),o.selectionStart=0,o.selectionEnd=o.value.length,o.selectionDirection=1===t?"forward":"backward",!0}selectAdjacentCoordinate(e,t){return this.selectAdjacentField(e,t,e=>e.coordinate)}handleLeftRightMovement(e,t,n,i){e.stopPropagation();const r=i(t);r.selectionStart===r.selectionEnd&&r.selectionStart===(1===n?r.value.length:0)&&this.selectAdjacentField(t,n,i)&&e.preventDefault()}updateNameValidity(){const{dimensionWidgetList:e}=this,t=e.map(e=>e.nameElement.value),n=t.length,i=this.combiner.getRenameValidity(t);for(let t=0;t<n;++t)e[t].nameElement.dataset.isValid=!1===i[t]?"false":"true"}updateScaleValidity(e){const t=void 0!==Object(Ne.c)(e.scaleElement.value);e.scaleElement.dataset.isValid=t.toString()}adjustDimension(e,t){const n=this.dimensionWidgetList.indexOf(e);if(-1===n)return;this.updatePosition();const{position:i}=this;if(!i.valid)return;const r=i.coordinateSpace.value,{bounds:s}=r,o=Float32Array.from(i.value);let a=Math.floor(o[n]+t);if(t>0){const e=s.upperBounds[n];Number.isFinite(e)&&(a=Math.min(a,Math.ceil(e-1)))}else{const e=s.lowerBounds[n];Number.isFinite(e)&&(a=Math.max(a,Math.floor(e)))}o[n]=a+.5,this.position.value=o,this.updateView()}updatePosition(){const{dimensionWidgetList:e}=this,{position:t}=this,{value:n}=t;if(void 0===n)return;const i=e.length;for(let t=0;t<i;++t){const i=e[t];i.modified=!1;const r=Number(i.coordinate.value);Number.isFinite(r)&&(n[t]=r+(Number.isInteger(r)?.5:0))}t.value=n}updateNames(){const{dimensionWidgetList:e}=this,{position:{coordinateSpace:t}}=this,n=t.value,i=e.map(e=>e.nameElement.value);if(this.combiner.getRenameValidity(i).includes(!1))return!1;const r=n.names;if(Object(Ae.a)(r,i))return!1;const s=n.timestamps.map((e,t)=>r[t]===i[t]?e:Date.now()),o=Object.assign(Object.assign({},n),{names:i,timestamps:s});return t.value=o,!0}updateScales(){const{dimensionWidgetList:e}=this,{position:{coordinateSpace:t}}=this,n=t.value,i=e.map(e=>Object(Ne.c)(e.scaleElement.value));if(i.includes(void 0))return!1;const r=Float64Array.from(i,e=>e.scale),s=Array.from(i,e=>e.unit),{scales:o,units:a}=n;if(Object(Ae.a)(o,r)&&Object(Ae.a)(a,s))return!1;const c=n.timestamps.map((e,t)=>r[t]===o[t]&&s[t]===a[t]?e:Date.now()),l=Object(C.y)({valid:n.valid,rank:n.rank,scales:r,units:s,timestamps:c,ids:n.ids,names:n.names,boundingBoxes:n.boundingBoxes});return t.value=l,!0}getPositionText(){const{position:e}=this;return e.valid?e.value.map(e=>Math.floor(e)).join(", "):""}updateView(){this.updateDimensions();const{position:{value:e},dimensionWidgetList:t}=this,n=t.length;if(void 0!==e)for(let i=0;i<n;++i){const n=t[i].coordinate,r=Math.floor(e[i]).toString();Bt(n,r),n.value=r}}disposed(){this.closeDropdown(),Object(Pe.c)(this.element),super.disposed()}}class Ut extends o.a{constructor(e,t,n){super(),this.element=e,this.mouseState=t,this.coordinateSpace=n,this.tempPosition=U.u.create(),e.className="neuroglancer-mouse-position-widget";const i=this.registerCancellable(Object(R.a)(()=>this.updateView()));this.registerDisposer(t.changed.add(i)),this.registerDisposer(n.changed.add(i))}updateView(){let e="";const{mouseState:t,coordinateSpace:{value:n}}=this;if(t.active&&void 0!==n){const i=t.position,{rank:r,names:s}=n;for(let t=0;t<r;++t)0!==t&&(e+="  "),e+=`${s[t]} ${Math.floor(i[t])}`}this.element.textContent=e}disposed(){Object(Pe.c)(this.element),super.disposed()}}
/**
 * @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 Gt(e,t){return"move"!==e.method&&(e.manager.layerManager.filter(t=>!e.layers.has(t)),void 0!==t&&e.layers.has(t))}function $t(e,t,n){function i(t,i){let r=e.dropLayers;const s=i?Et(t,e.manager):yt();let o=!0;if(void 0===r||(i&&bt(t,s),r.compatibleWithMethod(s)||(e.dropLayers=void 0,!Gt(r,n)))){if(void 0===r){if(r=e.dropLayers=Tt(t,e.manager,"copy"===s,!0,!1),void 0===r)return;o="move"===r.method}if(void 0!==n&&r.layers.has(n))return r;if(o){const{layerManager:t}=e.manager,i=new Set;let s=Number.POSITIVE_INFINITY;const o=t.managedLayers=t.managedLayers.filter((e,t)=>!r.layers.has(e)||(s===Number.POSITIVE_INFINITY&&(s=t),i.add(e),!1));let a;void 0!==n?(a=o.indexOf(n),s<=a&&++a):a=o.length;for(const e of r.layers.keys())i.has(e)||r.layers.delete(e);o.splice(a,0,...r.layers.keys()),t.layersChanged.dispatch()}else{let t;void 0!==n&&(t=e.manager.layerManager.managedLayers.indexOf(n));for(const n of r.layers.keys())e.manager.add(n,t)}return r}}const r=Object(o.e)(t,"dragenter",e=>{void 0!==i(e,!0)&&e.preventDefault()}),s=Object(o.e)(t,"drop",t=>{t.preventDefault();const n=i(t,!1);void 0!==n&&(n.finalize(t)?(t.dataTransfer.dropEffect=yt(),xt("move"===n.method?void 0:t)):Gt(n)),e.dropLayers=void 0}),a=Object(o.e)(t,"dragover",e=>{void 0!==i(e,!0)&&(e.preventDefault(),e.stopPropagation())});return()=>{a(),s(),r()}}class Wt extends o.a{constructor(e,t){super(),this.layer=e,this.panel=t,this.element=document.createElement("div"),this.layerNumberElement=document.createElement("div"),this.labelElement=document.createElement("div"),this.visibleProgress=document.createElement("div"),this.prefetchProgress=document.createElement("div"),this.labelElementText=document.createTextNode(""),this.valueElement=document.createElement("div"),this.maxLength=0,this.prevValueText="";const{element:n,labelElement:i,layerNumberElement:r,valueElement:s,visibleProgress:o,prefetchProgress:a,labelElementText:c}=this;n.className="neuroglancer-layer-item neuroglancer-noselect",n.appendChild(o),n.appendChild(a),i.className="neuroglancer-layer-item-label",i.appendChild(c),o.className="neuroglancer-layer-item-visible-progress",a.className="neuroglancer-layer-item-prefetch-progress",r.className="neuroglancer-layer-item-number",s.className="neuroglancer-layer-item-value";const l=jt();l.title="Remove layer from this layer group",this.registerEventListener(l,"click",e=>{this.panel.layerManager.removeManagedLayer(this.layer),e.stopPropagation()}),n.appendChild(r),n.appendChild(i),n.appendChild(s);const d=this.registerDisposer(new zt(e.localPosition,e.localCoordinateSpaceCombiner,{copyButton:!1}));n.appendChild(d.element),d.element.addEventListener("click",e=>{e.stopPropagation()}),d.element.addEventListener("dblclick",e=>{e.stopPropagation()}),n.appendChild(l),this.registerEventListener(n,"click",n=>{n.ctrlKey?(t.selectedLayer.layer=e,t.selectedLayer.visible=!0):n.altKey?e.pickEnabled=!e.pickEnabled:e.setVisible(!e.visible)}),this.registerEventListener(n,"contextmenu",n=>{t.selectedLayer.layer=e,t.selectedLayer.visible=!0,n.stopPropagation(),n.preventDefault()}),n.draggable=!0,this.registerEventListener(n,"dragstart",e=>{wt(e,{manager:t.manager,layers:[this.layer],layoutSpec:t.getLayoutSpecForDrag()}),e.stopPropagation()}),this.registerEventListener(n,"dragend",e=>{xt(e)}),this.registerDisposer($t(this.panel,n,this.layer))}update(){const{layer:e,element:t}=this;this.labelElementText.textContent=e.name,t.dataset.visible=e.visible.toString(),t.dataset.selected=(e===this.panel.selectedLayer.layer).toString(),t.dataset.pick=e.pickEnabled.toString();let n=`Click to ${e.visible?"hide":"show"}, control+click to show side panel`;e.supportsPickOption&&(n+=`, alt+click to ${e.pickEnabled?"disable":"enable"} spatial object selection`),n+=", drag to move, shift+drag to copy",t.title=n}disposed(){this.element.remove(),super.disposed()}}class Ht extends o.a{constructor(e,t,n,i,r,s){super(),this.display=e,this.manager=t,this.viewerNavigationState=n,this.selectedLayer=i,this.getLayoutSpecForDrag=r,this.showLayerHoverValues=s,this.layerWidgets=new Map,this.element=document.createElement("div"),this.layerUpdateNeeded=!0,this.valueUpdateNeeded=!1,this.layerWidgetInsertionPoint=document.createElement("div"),this.positionWidget=this.registerDisposer(new zt(this.viewerNavigationState.position.value,this.manager.root.coordinateSpaceCombiner)),this.scheduleUpdate=this.registerCancellable(Object(R.a)(()=>this.update())),this.registerDisposer(i);const{element:a}=this;a.className="neuroglancer-layer-panel",this.registerDisposer(t.layerSelectedValues.changed.add(()=>{this.handleLayerValuesChanged()})),this.registerDisposer(t.layerManager.layersChanged.add(()=>{this.handleLayersChanged()})),this.registerDisposer(i.changed.add(()=>{this.handleLayersChanged()})),this.registerDisposer(s.changed.add(()=>{this.handleLayerItemValueChanged()})),this.element.dataset.showHoverValues=this.showLayerHoverValues.value.toString(),this.layerWidgetInsertionPoint.style.display="none",this.element.appendChild(this.layerWidgetInsertionPoint);let c=Object(Lt.a)({svg:pt.a,title:"Click to add layer, control+click/right click/⌘+click to add local annotation layer."});c.classList.add("neuroglancer-layer-add-button");let l=this.dropZone=document.createElement("div");l.className="neuroglancer-layer-panel-drop-zone";const d=e=>{if(e.ctrlKey||e.metaKey||"contextmenu"===e.type){const e=new j.e("annotation",{},this.manager);this.manager.initializeLayerFromSpec(e,{type:"annotation",source:"local://annotations"}),this.manager.add(e),this.selectedLayer.layer=e,this.selectedLayer.visible=!0}else this.addLayerMenu()};this.registerEventListener(c,"click",d),this.registerEventListener(c,"contextmenu",d),a.appendChild(c),a.appendChild(l),this.registerDisposer(function(e){return e.draggable=!0,Object(o.e)(e,"dragstart",e=>{e.stopPropagation(),e.preventDefault()})}
/**
 * @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.
 */(c)),a.appendChild(this.positionWidget.element);const u=()=>{const e=this.viewerNavigationState.position.link.value;this.positionWidget.element.style.display=e===T.h.LINKED?"none":""};this.registerDisposer(this.viewerNavigationState.position.link.changed.add(u)),u(),this.update(),this.updateChunkStatistics(),this.registerEventListener(a,"dragleave",e=>{if(e.relatedTarget&&a.contains(e.relatedTarget))return;const{dropLayers:t}=this;void 0!==t&&(Gt(t),this.dropLayers=void 0)}),this.registerDisposer($t(this,c,void 0)),this.registerDisposer($t(this,l,void 0)),this.registerDisposer(e.updateStarted.add(()=>this.updateLayers())),this.registerDisposer(t.chunkManager.layerChunkStatisticsUpdated.add(this.registerCancellable(Object(R.a)(()=>this.updateChunkStatistics()))))}get layerManager(){return this.manager.layerManager}disposed(){this.layerWidgets.forEach(e=>e.dispose()),this.layerWidgets=void 0,Object(Pe.c)(this.element),super.disposed()}handleLayersChanged(){this.layerUpdateNeeded=!0,this.handleLayerValuesChanged()}handleLayerValuesChanged(){this.valueUpdateNeeded||(this.valueUpdateNeeded=!0,this.scheduleUpdate())}handleLayerItemValueChanged(){this.element.dataset.showHoverValues=this.showLayerHoverValues.value.toString()}update(){if(this.valueUpdateNeeded=!1,this.updateLayers(),!1===this.showLayerHoverValues.value)return;let e=this.manager.layerSelectedValues;for(let[t,n]of this.layerWidgets){let i=t.layer,r="";if(null!==i){let t=e.get(i);if(void 0!==t){const{value:e}=t;void 0!==e&&(r=""+e)}}if(r!==n.prevValueText){if(n.prevValueText=r,r.length>n.maxLength){const e=n.maxLength=r.length;n.valueElement.style.width=`${e}ch`}n.valueElement.textContent=r}}}updateChunkStatistics(){for(const[e,t]of this.layerWidgets){let n=0,i=0,r=0,s=0;const o=e.layer;if(null!==o)for(const{layerChunkProgressInfo:e}of o.renderLayers)n+=e.numVisibleChunksNeeded,i+=e.numVisibleChunksAvailable,r+=e.numPrefetchChunksNeeded,s+=e.numPrefetchChunksAvailable;t.visibleProgress.style.width=`${i/Math.max(1,n)*100}%`,t.prefetchProgress.style.width=`${s/Math.max(1,r)*100}%`}}updateLayers(){if(!this.layerUpdateNeeded)return;this.layerUpdateNeeded=!1;let e=this.element,t=new Set,n=this.layerWidgetInsertionPoint.nextElementSibling;this.manager.layerManager.managedLayers.forEach(i=>{t.add(i);let r=this.layerWidgets.get(i);const s=this.manager.rootLayers.managedLayers.indexOf(i);void 0===r&&(r=new Wt(i,this),this.layerWidgets.set(i,r)),r.layerNumberElement.textContent=""+(1+s),r.update();let{element:o}=r;o!==n&&e.insertBefore(r.element,n),n=o.nextElementSibling});for(let[e,n]of this.layerWidgets)t.has(e)||(this.layerWidgets.delete(e),n.dispose())}addLayerMenu(){Object(j.l)(this.manager,this.selectedLayer)}}n(233);
/**
 * @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 Jt extends o.a{constructor(e){super(),this.element=document.createElement("div"),this.parentDisposers=new Map,this.disabledValue=!1,this.opened=new y.a,this.closed=new y.a;const{element:t}=this;t.className="neuroglancer-context-menu",t.style.display="none",t.tabIndex=-1,document.body.appendChild(t),void 0!==e&&this.registerParent(e)}get disabled(){return this.disabledValue}set disabled(e){this.disabledValue!==e&&(this.disabledValue=e,e&&this.hide())}get open(){return void 0!==this.menuDisposer}registerParent(e){const{parentDisposers:t}=this;t.has(e)||t.set(e,Object(o.e)(e,"contextmenu",e=>{this.show(e),e.stopPropagation(),e.preventDefault()}))}show(e){if(this.disabledValue)return;this.hide();const{element:t}=this,n=Object(o.e)(document,"mousedown",e=>{e.target instanceof Node&&!t.contains(e.target)&&this.hide()},!0),i=Object(o.e)(document,"keydown",e=>{"Escape"===e.code&&this.hide()},!0);this.opened.dispatch(),function(e,t){e.style.display="block";const{offsetWidth:n,offsetHeight:i}=e,r=document.documentElement.clientWidth,s=document.documentElement.clientHeight,o=document.documentElement.scrollLeft+Math.min(r-n,t.clientX),a=document.documentElement.scrollTop+Math.min(s-i,t.clientY);e.style.left=o+"px",e.style.top=a+"px"}(t,e),this.menuDisposer=()=>{i(),n(),t.style.display="none"}}unregisterParent(e){const{parentDisposers:t}=this,n=t.get(e);void 0!==n&&(n(),t.delete(e))}disposed(){const{parentDisposers:e}=this;for(const t of e.values())t();e.clear(),Object(Pe.c)(this.element)}hide(){void 0!==this.menuDisposer&&(this.menuDisposer(),this.menuDisposer=void 0,this.closed.dispatch())}}
/**
 * @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 qt(e,t){const n=Object(o.e)(e,"drop",e=>{if(e.preventDefault(),-1!==e.dataTransfer.types.indexOf("neuroglancer-position")){e.stopPropagation();const n=Object(g.w)(JSON.parse(e.dataTransfer.getData("neuroglancer-position"))),i=Object(g.y)(n,"dimensions",C.j),r=Object(g.y)(n,"position",e=>Object(g.b)(e,g.p));if(r.length!==i.length)throw new Error("length mismatch between position and dimensions");const s=r.length,{coordinateSpace:{value:{names:o}},value:a}=t;for(let e=0;e<s;++e){const t=o.indexOf(i[e]);-1!==t&&(a[t]=r[e])}t.changed.dispatch()}}),i=e=>{-1!==e.dataTransfer.types.indexOf("neuroglancer-position")&&(e.dataTransfer.dropEffect="link",e.preventDefault(),e.stopPropagation())},r=Object(o.e)(e,"dragenter",i),s=Object(o.e)(e,"dragover",i);return()=>{r(),s(),n()}}var Yt=n(114);
/**
 * @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 Xt="neuroglancer-layer-group-viewer";function Kt(e){return-1!==e.dataTransfer.types.indexOf(Xt)}let Qt;function Zt(e){return void 0!==function(e){return Qt&&Qt.viewer.layerSpecification.rootLayers===e.rootLayers?Qt.viewer:void 0}(e)?"move":"copy"}class en extends o.a{constructor(e){super(),this.relativeDisplayScales=new T.f(e.navigationState.pose.relativeDisplayScales.addRef()),this.displayDimensions=new T.c(e.navigationState.pose.displayDimensions.addRef()),this.position=new T.e(e.navigationState.position.addRef()),this.crossSectionOrientation=new T.d(e.navigationState.pose.orientation.addRef()),this.displayDimensionRenderInfo=this.registerDisposer(new T.q(this.relativeDisplayScales.value,this.displayDimensions.value)),this.crossSectionScale=new T.g(e.navigationState.zoomFactor.addRef(),this.displayDimensionRenderInfo.addRef()),this.crossSectionDepthRange=new T.b(e.navigationState.depthRange.addRef(),this.displayDimensionRenderInfo),this.projectionDepthRange=new T.b(e.perspectiveNavigationState.depthRange.addRef(),this.displayDimensionRenderInfo),this.navigationState=this.registerDisposer(new T.i(new T.a(this.position.value,this.displayDimensionRenderInfo.addRef(),this.crossSectionOrientation.value),this.crossSectionScale.value,this.crossSectionDepthRange.value)),this.projectionOrientation=new T.d(e.perspectiveNavigationState.pose.orientation.addRef()),this.projectionScale=new T.g(e.perspectiveNavigationState.zoomFactor.addRef(),this.displayDimensionRenderInfo.addRef()),this.projectionNavigationState=this.registerDisposer(new T.i(new T.a(this.position.value.addRef(),this.displayDimensionRenderInfo.addRef(),this.projectionOrientation.value),this.projectionScale.value,this.projectionDepthRange.value))}copyToParent(){for(const e of[this.relativeDisplayScales,this.displayDimensions,this.position,this.crossSectionOrientation,this.crossSectionScale,this.projectionOrientation,this.projectionScale])e.copyToPeer()}register(e){e.add("dimensionRenderScales",this.relativeDisplayScales),e.add("displayDimensions",this.displayDimensions),e.add("position",Object(T.r)(this.position)),e.add("crossSectionOrientation",this.crossSectionOrientation),e.add("crossSectionScale",this.crossSectionScale),e.add("crossSectionDepth",this.crossSectionDepthRange),e.add("projectionOrientation",this.projectionOrientation),e.add("projectionScale",this.projectionScale),e.add("projectionDepth",this.projectionDepthRange)}}class tn extends o.a{constructor(e,t,n={}){super(),this.element=e,this.viewerState=t,this.state=new m.a,this.options=Object.assign({showLayerPanel:new le.b(!0),showViewerMenu:!1,showLayerHoverValues:new le.b(!0)},n),this.layerSpecification=this.registerDisposer(t.layerSpecification),this.viewerNavigationState=this.registerDisposer(new en(t)),this.viewerNavigationState.register(this.state),this.layerSpecification instanceof j.d?this.state.add("layers",this.layerSpecification):this.state.add("layers",{changed:this.layerSpecification.changed,toJSON:()=>this.layerSpecification.layerManager.managedLayers.map(e=>e.name),reset:()=>{throw new Error("not implemented")},restoreState:()=>{throw new Error("not implemented")}}),e.classList.add("neuroglancer-layer-group-viewer"),this.registerDisposer(new z.a(e)),this.layout=this.registerDisposer(new ct(this,"xy")),this.state.add("layout",this.layout),this.registerActionBindings(),this.registerDisposer(this.layerManager.useDirectly()),this.registerDisposer(qt(e,this.navigationState.position)),this.registerDisposer(this.options.showLayerPanel.changed.add(this.registerCancellable(r()(()=>this.updateUI(),0)))),this.makeUI()}get perspectiveNavigationState(){return this.viewerNavigationState.projectionNavigationState}get navigationState(){return this.viewerNavigationState.navigationState}get selectionDetailsState(){return this.layerSpecification.root.selectionState}get display(){return this.viewerState.display}get selectedLayer(){return this.viewerState.selectedLayer}get layerManager(){return this.layerSpecification.layerManager}get chunkManager(){return this.layerSpecification.chunkManager}get mouseState(){return this.viewerState.mouseState}get showAxisLines(){return this.viewerState.showAxisLines}get wireFrame(){return this.viewerState.wireFrame}get showScaleBar(){return this.viewerState.showScaleBar}get showPerspectiveSliceViews(){return this.viewerState.showPerspectiveSliceViews}get inputEventBindings(){return this.viewerState.inputEventBindings}get visibility(){return this.viewerState.visibility}get visibleLayerRoles(){return this.viewerState.visibleLayerRoles}get crossSectionBackgroundColor(){return this.viewerState.crossSectionBackgroundColor}get perspectiveViewBackgroundColor(){return this.viewerState.perspectiveViewBackgroundColor}get scaleBarOptions(){return this.viewerState.scaleBarOptions}get changed(){return this.state.changed}bindAction(e,t){this.registerDisposer(Object(S.d)(this.element,e,t))}registerActionBindings(){this.bindAction("add-layer",()=>{this.layerPanel&&this.layerPanel.addLayerMenu()}),this.bindAction("t-",()=>{this.navigationState.pose.translateNonDisplayDimension(0,-1)}),this.bindAction("t+",()=>{this.navigationState.pose.translateNonDisplayDimension(0,1)})}toJSON(){return Object.assign({type:"viewer"},this.state.toJSON())}reset(){this.state.reset()}restoreState(e){this.state.restoreState(e),Object(m.d)(e,"crossSectionZoom",Object(T.r)(this.viewerNavigationState.crossSectionScale)),Object(m.d)(e,"perspectiveZoom",Object(T.r)(this.viewerNavigationState.projectionScale)),Object(m.d)(e,"perspectiveOrientation",this.viewerNavigationState.projectionOrientation)}makeUI(){this.element.style.flex="1",this.element.style.display="flex",this.element.style.flexDirection="column",this.element.appendChild(this.layout.element),this.updateUI()}updateUI(){const{options:e}=this,t=e.showLayerPanel.value;if(void 0!==this.layerPanel&&!t)return this.layerPanel.dispose(),void(this.layerPanel=void 0);if(t&&void 0===this.layerPanel){const t=this.layerPanel=new Ht(this.display,this.layerSpecification,this.viewerNavigationState,this.viewerState.selectedLayer.addRef(),()=>this.layout.toJSON(),this.options.showLayerHoverValues);e.showViewerMenu?(t.registerDisposer(function(e,t){const n=new Jt(e),i=n.element;i.classList.add("neuroglancer-layer-group-viewer-context-menu");const r=document.createElement("button");r.textContent="Remove layer group",i.appendChild(r),n.registerEventListener(r,"click",()=>{t.layerSpecification.layerManager.clear()});const{viewerNavigationState:s}=t;for(const[e,t]of[["Render scale factors",s.relativeDisplayScales.link],["Render dimensions",s.displayDimensions.link],["Position",s.position.link],["Cross-section orientation",s.crossSectionOrientation.link],["Cross-section zoom",s.crossSectionScale.link],["Cross-section depth range",s.crossSectionDepthRange.link],["3-D projection orientation",s.projectionOrientation.link],["3-D projection zoom",s.projectionScale.link],["3-D projection depth range",s.projectionDepthRange.link]]){const r=n.registerDisposer(new Yt.a(t)),s=document.createElement("label");s.style.display="flex",s.style.flexDirection="row",s.style.whiteSpace="nowrap",s.textContent=e,s.appendChild(r.element),i.appendChild(s)}return n}(t.element,this)),t.element.title="Right click for options, drag to move/copy layer group."):t.element.title="Drag to move/copy layer group.",t.element.draggable=!0,this.registerEventListener(t.element,"dragstart",e=>{wt(e,{manager:this.layerSpecification,layers:this.layerManager.managedLayers,layoutSpec:this.layout.toJSON()});const t=()=>{Qt&&Qt.viewer===this&&(Qt=void 0),this.unregisterDisposer(t)};Qt={viewer:this,disposer:t},this.registerDisposer(t);const n=this.toJSON();delete n.layers,e.dataTransfer.setData(Xt,JSON.stringify(n))}),this.registerEventListener(t.element,"dragend",e=>{xt(e),void 0!==Qt&&Qt.viewer===this&&Qt.disposer()}),this.element.insertBefore(t.element,this.element.firstChild)}}disposed(){Object(Pe.b)(this.element);const{layerPanel:e}=this;void 0!==e&&(e.dispose(),this.layerPanel=void 0),super.disposed()}}
/**
 * @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 nn=Symbol("layoutComponentContainer");class rn extends o.a{constructor(e,t,n){super(),this.viewer=e,this.parent=n,this.changed=new y.a,this.element=document.createElement("div");const{element:i}=this;i.style.display="flex",i.style.flex="1",i.style.position="relative",i.style.alignItems="stretch",i.foo="hello",i[nn]=this,this.setSpecification(t);const r=[],s=e=>{const t=document.createElement("div");let n;switch(t.className="neuroglancer-layout-split-drop-zone",t.style[e]="0",e){case"left":case"right":n="row",t.style.width="10px",t.style.height="100%";break;case"top":case"bottom":n="column",t.style.height="10px",t.style.width="100%"}t.style.display="none",r.push({element:t,direction:n,orientation:e}),i.appendChild(t),this.registerDisposer(an(t,this.viewer.layerSpecification,()=>this.split(e).newContainer.component))};s("left"),s("right"),s("top"),s("bottom");let o=!1;this.registerEventListener(i,"dragenter",e=>{if(!o&&void 0!==Ct(e)){o=!0;for(const{element:e,direction:t,orientation:i}of r){if(void 0!==n&&t===n.direction&&(("left"===i||"top"===i)&&n.get(0)!==this||("bottom"===i||"right"===i)&&n.get(n.length-1)!==this))continue;const{component:r}=this;r instanceof cn&&r.direction===t||(e.style.display="block")}}},!0),this.registerEventListener(i,"drop",e=>{if(o){o=!1;for(const{element:e}of r)e.style.display="none"}},!0),this.registerEventListener(i,"dragleave",e=>{const{relatedTarget:t}=e;if(o&&!(t instanceof HTMLElement&&this.element.contains(t))){o=!1;for(const{element:e}of r)e.style.display="none"}},!0)}unsetComponent(){const e=this.componentValue;void 0!==e&&(e.changed.remove(this.changed.dispatch),this.element.removeChild(e.element),e.dispose())}get component(){return this.componentValue}setComponent(e){if(this.unsetComponent(),this.componentValue=e,e.changed.add(this.changed.dispatch),this.element.appendChild(e.element),e instanceof tn){const{layerManager:t}=e,n=e.registerCancellable(r()(()=>{0===t.managedLayers.length&&this.dispose()},0));e.registerDisposer(t.layersChanged.add(()=>{0===t.managedLayers.length&&n()})),n()}else if(e instanceof cn){const t=e.registerCancellable(r()(()=>{const{length:t}=e;if(0===t&&void 0!==this.parent)this.dispose();else if(1===t){const t=e.get(0).component;let n;if(void 0===this.parent&&t instanceof tn){n=t.layout.specification.toJSON(),t.viewerNavigationState.copyToParent();const e=new Set(t.layerManager.managedLayers),{layerSpecification:i}=t;i.rootLayers.filter(t=>e.has(t)),i.rootLayers.managedLayers=Array.from(t.layerManager.managedLayers),i.rootLayers.layersChanged.dispatch()}else n=t.toJSON();this.setSpecification(n)}},0));e.registerDisposer(e.changed.add(()=>{e.length<2&&t()})),t()}this.changed.dispatch()}toJSON(){return this.component.toJSON()}setSpecification(e){this.setComponent(function(e,t){const n=document.createElement("div");if(n.style.flex="1",n.style.width="0px","string"==typeof t){if(void 0!==e.parent)throw new Error(`Invalid layout component specification: ${JSON.stringify(t)}`);return new on(n,t,e.viewer)}Object(g.w)(t);const i=Object(g.y)(t,"type",g.E);switch(i){case"row":case"column":return new cn(n,i,Object(g.y)(t,"children",t=>{const n=Object(g.b)(t,e=>e);if(void 0===e.parent&&0===n.length)throw new Error("Stack layout requires at least one child.");return n}),e);case"viewer":{const i=e.viewer,r=new j.d(i.layerSpecification.addRef()),s=new tn(n,Object.assign({display:i.display,layerSpecification:r},sn(i)),{showLayerPanel:i.uiControlVisibility.showLayerPanel,showViewerMenu:!0,showLayerHoverValues:i.uiControlVisibility.showLayerHoverValues});try{s.restoreState(t)}catch(e){throw s.dispose(),e}return s}default:return new on(n,t,e.viewer)}}(this,e))}static getFromElement(e){return e[nn]}disposed(){this.unsetComponent(),this.componentValue=void 0,super.disposed()}split(e){const t={type:"viewer"},{parent:n}=this;if(void 0!==n){if("left"===e&&"row"===n.direction||"top"===e&&"column"===n.direction)return{newContainer:n.insertChild(t,this),existingContainer:this};if("right"===e&&"row"===n.direction||"bottom"===e&&"column"===n.direction)return{newContainer:n.insertChild(t),existingContainer:this}}let i;const r=this.component;let s,o;i=r instanceof on?r.layerGroupViewer.toJSON():r.toJSON();const a="left"===e||"right"===e?"row":"column";switch(e){case"left":case"top":s={type:a,children:[t,i]},o=0;break;case"right":case"bottom":s={type:a,children:[i,t]},o=1}this.setSpecification(s);const c=this.component;return{newContainer:c.get(o),existingContainer:c.get(1-o)}}}function sn(e){return{mouseState:e.mouseState,showAxisLines:e.showAxisLines,wireFrame:e.wireFrame,showScaleBar:e.showScaleBar,scaleBarOptions:e.scaleBarOptions,showPerspectiveSliceViews:e.showPerspectiveSliceViews,inputEventBindings:e.inputEventBindings,visibility:e.visibility,selectedLayer:e.selectedLayer,visibleLayerRoles:e.visibleLayerRoles,navigationState:e.navigationState.addRef(),perspectiveNavigationState:e.perspectiveNavigationState.addRef(),crossSectionBackgroundColor:e.crossSectionBackgroundColor,perspectiveViewBackgroundColor:e.perspectiveViewBackgroundColor}}class on extends o.a{constructor(e,t,n){super(),this.element=e,this.layerGroupViewer=this.registerDisposer(new tn(e,Object.assign({display:n.display,layerSpecification:n.layerSpecification.addRef()},sn(n)),{showLayerPanel:n.uiControlVisibility.showLayerPanel,showViewerMenu:!1,showLayerHoverValues:n.uiControlVisibility.showLayerHoverValues})),this.layerGroupViewer.layout.restoreState(t)}toJSON(){return this.layerGroupViewer.layout.specification.toJSON()}get changed(){return this.layerGroupViewer.layout.changed}}function an(e,t,n){const i=Object(o.e)(e,"dragenter",t=>{void 0!==Ct(t)&&e.classList.add("neuroglancer-drag-over")}),r=Object(o.e)(e,"dragleave",()=>{e.classList.remove("neuroglancer-drag-over")}),s=Object(o.e)(e,"dragover",e=>Kt(e)?(bt(e,function(e,t){return e.shiftKey?"copy":e.ctrlKey?"move":Zt(t)}(e,t)),e.stopPropagation(),void e.preventDefault()):void 0!==Ct(e)?(function(e,t,n=!1){bt(e,Et(e,t,n))}(e,t,!0),e.stopPropagation(),void e.preventDefault()):void 0),a=Object(o.e)(e,"drop",i=>{if(e.classList.remove("neuroglancer-drag-over"),Kt(i)){let e;i.stopPropagation();try{e=JSON.parse(i.dataTransfer.getData(Xt))}catch(e){return}const r=Tt(i,t,!1,!1,!0);if(void 0!==r&&r.finalize(i)){i.preventDefault(),i.dataTransfer.dropEffect=yt(),xt(i);const t=n();for(const e of r.layers.keys())t.layerSpecification.add(e);try{t.restoreState(e)}catch(e){}}}else{const e=Tt(i,t,"copy"===yt(),!1,!0);if(void 0!==e&&e.finalize(i)){i.preventDefault(),i.dataTransfer.dropEffect=yt(),xt(i);const t=n();for(const n of e.layers.keys())t.layerSpecification.add(n);try{t.layout.restoreState(e.layoutSpec)}catch(e){t.layout.reset()}return}}});return()=>{a(),s(),r(),i()}}class cn extends o.a{constructor(e,t,n,i){super(),this.element=e,this.direction=t,this.container=i,this.changed=new y.a,e.classList.add("neuroglancer-stack-layout"),e.classList.add(`neuroglancer-stack-layout-${t}`),e.style.display="flex",e.style.flexDirection=t,e.appendChild(this.makeDropPlaceholder(this));for(const e of n)this.insertChild(e)}get length(){return(this.element.childElementCount-1)/2}makeDropPlaceholder(e){const t=document.createElement("div");return t.className="neuroglancer-stack-layout-drop-placeholder",e.registerDisposer(an(t,this.viewer.layerSpecification,()=>{const e=t.nextElementSibling;let n;return null!==e&&(n=rn.getFromElement(e)),this.insertChild({type:"viewer",layers:[]},n).component})),e.registerDisposer(()=>{Object(Pe.c)(t)}),t}get viewer(){return this.container.viewer}get(e){return rn.getFromElement(this.element.children[2*e+1])}insertChild(e,t){const n=new rn(this.viewer,e,this),i=this.makeDropPlaceholder(n);n.element.classList.add("neuroglancer-stack-layout-child"),n.registerDisposer(n.changed.add(this.changed.dispatch)),n.registerDisposer(()=>{this.element.removeChild(n.element),this.changed.dispatch()});const r=void 0!==t?t.element:null;return this.element.insertBefore(n.element,r),this.element.insertBefore(i,r),this.changed.dispatch(),n}disposed(){this.clear(),super.disposed()}clear(){for(;0!==this.length;)this.get(0).dispose()}*[Symbol.iterator](){const{length:e}=this;for(let t=0;t<e;++t)yield this.get(t)}toJSON(){return{type:this.direction,children:Array.from(this).map(e=>e.toJSON())}}}class ln extends o.a{constructor(e,t){super(),this.viewer=e,this.defaultSpecification=t,this.container=this.registerDisposer(new rn(this.viewer,this.defaultSpecification,void 0))}get changed(){return this.container.changed}get element(){return this.container.element}reset(){this.container.setSpecification(this.defaultSpecification)}restoreState(e){this.container.setSpecification(e)}disposed(){super.disposed()}toJSON(){return this.container.toJSON()}}n(234);
/**
 * @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 dn extends o.a{constructor(e,t,n,i,r=0){super(),this.element=e,this.visible=t,this.size=n,this.direction=i,this.minSize=r,this.gutter=document.createElement("div"),this.sizeProp="horizontal"===this.direction?"width":"height";const{gutter:s}=this;s.className=`neuroglancer-resize-gutter-${i}`,e.insertAdjacentElement("beforebegin",s),this.registerDisposer(t.changed.add(()=>this.updateView())),this.registerDisposer(n.changed.add(()=>this.updateView()));this.registerEventListener(s,"pointerdown",t=>{if("button"in t&&0!==t.button)return;t.preventDefault();let n=e.getBoundingClientRect()[this.sizeProp];const r=this.minSize/2;H(t,(e,t,s)=>{n-="horizontal"===i?t:s,n<r?this.visible.value=!1:!1===this.visible.value&&n>r&&(this.visible.value=!0),this.size.value=Math.max(this.minSize,n)})}),this.updateView()}updateView(){const{element:e,gutter:t}=this,{visible:n}=this;if(!n.value)return e.style.display="none",void(t.style.display="none");e.style.display="",t.style.display="",e.style[this.sizeProp]=Math.max(this.minSize,this.size.value)+"px"}disposed(){Object(Pe.c)(this.gutter),super.disposed()}}n(235);var un=n(180),hn=n.n(un);n(236);
/**
 * @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.
 */
class pn extends o.a{constructor(e,t){super(),this.element=Object(Lt.a)(Object.assign(Object.assign({},t),{onClick:()=>{e.value=!e.value}})),this.element.classList.add("neuroglancer-checkbox-icon");const n=()=>{const n=e.value;this.element.dataset.checked=n?"true":"false",this.element.title=(n?t.disableTitle:t.enableTitle)||""};this.registerDisposer(e.changed.add(n)),n()}}var fn=n(104),mn=n(48);
/**
 * @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 gn extends mn.b{constructor(e){super(),this.layer=e,this.tabView=this.registerDisposer(new mn.d(this.layer.tabs.addRef(),this.visibility)),this.element.appendChild(this.tabView.element),this.element.classList.add("neuroglancer-layer-side-panel-info-panel"),this.tabView.element.style.flex="1"}}const vn=W.a.fromObject({escape:{action:"cancel"}});class bn extends mn.b{get layer(){return null}constructor(){super(),this.element.classList.add("neuroglancer-layer-side-panel-info-panel-empty"),this.element.textContent="Information about this layer will be available once it finishes loading."}}class yn extends mn.b{constructor(e,t,n){super(),this.layer=e,this.layerManager=t,this.collapse=n,this.element=document.createElement("div"),this.typeSelect=document.createElement("select"),this.typeSelectMeasure=document.createElement("div"),this.title=document.createElement("div"),this.layerName=document.createElement("input"),this.stack=this.registerDisposer(new mn.a(e=>null===e?new bn:new gn(e),(()=>{const{layer:e}=this;return{changed:e.layerChanged,get value(){return e.layer}}})(),this.visibility,!0));const{element:i,title:r,layerName:s,stack:o,typeSelect:a,typeSelectMeasure:c}=this;i.className="neuroglancer-managed-user-layer-info-panel",r.className="neuroglancer-layer-side-panel-title",o.element.classList.add("neuroglancer-layer-side-panel-content-container"),r.appendChild(a),i.appendChild(r),i.appendChild(o.element),document.body.appendChild(c),a.classList.add("neuroglancer-layer-side-panel-type"),c.classList.add("neuroglancer-layer-side-panel-type-measure"),a.title="Change layer type";for(const[e,t]of j.p){if(t.type!==e)continue;const n=document.createElement("option");n.textContent=e,n.value=e,a.appendChild(n)}a.addEventListener("change",()=>{if(null===this.layer.layer)return void this.handleLayerNameModelChanged();const e=a.value,t=j.p.get(e);Object(j.n)(this.layer,t)}),r.appendChild(s),s.classList.add("neuroglancer-layer-side-panel-name"),s.spellcheck=!1,s.autocomplete="off",s.addEventListener("focus",()=>{s.select()}),this.registerDisposer(new G.b(s,vn)).allShortcutsAreGlobal=!0,Object(G.c)(s,"cancel",e=>{this.handleLayerNameModelChanged(),s.blur(),e.stopPropagation(),e.preventDefault()}),s.title="Rename layer";const l=this.registerDisposer(new pn({get value(){return e.pickEnabled},set value(t){e.pickEnabled=t},changed:e.layerChanged},{svg:hn.a,enableTitle:"Spatial object selection: disabled",disableTitle:"Spatial object selection: enabled"}));this.registerDisposer(new le.a({get value(){return e.supportsPickOption},changed:e.layerChanged},l.element)),r.appendChild(l.element),r.appendChild(Object(fn.a)({title:"Delete layer",onClick:()=>{Object(j.o)(this.layer)}})),r.appendChild(jt({title:"Close side panel",onClick:()=>{this.collapse()}})),s.addEventListener("change",()=>this.handleLayerNameViewChanged()),s.addEventListener("blur",()=>this.handleLayerNameViewChanged()),this.registerDisposer(e.layerChanged.add(()=>this.handleLayerNameModelChanged())),this.handleLayerNameModelChanged()}handleLayerNameModelChanged(){const e=this.layer.layer,t=null!==e?e.type:"auto",{typeSelect:n,typeSelectMeasure:i}=this;i.textContent=t,n.value=t,n.style.width=`${i.offsetWidth}px`,this.layerName.value=this.layer.name}handleLayerNameViewChanged(){Object(j.m)(this.layer,this.layerName.value)}}class Sn extends o.a{constructor(e){super(),this.state=e,this.element=document.createElement("div"),this.stack=this.registerDisposer(new mn.a(e=>new yn(e,this.state.layerManager,this.collapse.bind(this)),(()=>{const{state:e}=this;return{changed:e.changed,get value(){return e.layer}}})())),this.debouncedUpdateView=this.registerCancellable(Object(R.a)(()=>this.handleStateChanged())),this.debouncedUpdateLayers=this.registerCancellable(Object(R.a)(()=>this.handleLayersChanged()));const{element:t,stack:n}=this;t.className="neuroglancer-layer-side-panel",n.element.classList.add("neuroglancer-layer-info-panel-container"),t.appendChild(n.element),this.registerDisposer(e.changed.add(()=>this.handleStateChanged())),this.registerDisposer(e.layerManager.layersChanged.add(this.debouncedUpdateLayers)),this.debouncedUpdateView()}handleLayersChanged(){const{layerManager:e}=this.state,{stack:t}=this;for(const n of t.tabs.keys())e.has(n)||t.invalidate(n)}collapse(){const{state:e}=this;!0===e.visible&&(this.state.visible=!1,this.state.changed.dispatch())}handleStateChanged(){const{state:e}=this,{visible:t}=e;this.element.style.display=t?"":"none",this.stack.visibility.value=t?ue.b.VISIBLE:ue.b.IGNORED}disposed(){Object(Pe.c)(this.element),super.disposed()}}n(237);var wn=n(181),xn=n.n(wn),Cn=n(182),On=n.n(Cn),kn=n(63),En=n(138);
/**
 * @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.
 */
class Tn extends o.a{constructor(e,t,n){super(),this.state=e,this.manager=t,this.selectedLayer=n,this.element=document.createElement("div"),this.body=document.createElement("div");const{element:i,body:r}=this;i.classList.add("neuroglancer-selection-details");const s=document.createElement("div"),o=document.createElement("div");s.appendChild(o);const a=Object(Lt.a)({svg:xn.a,title:"Previous selection",onClick:()=>{this.state.goBack()}}),c=Object(Lt.a)({svg:On.a,title:"Next selection",onClick:()=>{this.state.goForward()}});s.appendChild(a),s.appendChild(c),s.classList.add("neuroglancer-selection-details-titlebar"),o.classList.add("neuroglancer-selection-details-title"),o.textContent="Selection",s.appendChild(this.registerDisposer(new pn(e.pin,{text:"📌",enableTitle:"Pin selection",disableTitle:"Unpin selection"})).element),s.appendChild(jt({title:"Close selection panel",onClick:()=>{this.state.visible.value=!1,this.state.value=void 0,this.state.pin.value=!0}})),r.classList.add("neuroglancer-selection-details-body"),i.appendChild(s),i.appendChild(r),r.appendChild(this.registerDisposer(new kn.a(e,(t,n,i)=>{if(a.style.visibility=e.canGoBack()?"visible":"hidden",c.style.visibility=e.canGoForward()?"visible":"hidden",void 0===t)return;const{position:r}=t;if(void 0!==r){const e=document.createElement("div");e.classList.add("neuroglancer-selection-details-position");const i=Object(At.a)({title:"Copy position",onClick:()=>{Object(Pt.a)(o.map(e=>Math.floor(e)).join(", "))}});e.appendChild(i);const{coordinateSpace:{rank:r,names:s},position:o}=t;for(let t=0;t<r;++t){const n=document.createElement("span");n.classList.add("neuroglancer-selection-details-position-dimension");const i=document.createElement("span");i.classList.add("neuroglancer-selection-details-position-dimension-name"),i.textContent=s[t];const r=document.createElement("span");r.classList.add("neuroglancer-selection-details-position-dimension-coordinate"),r.textContent=Math.floor(o[t]).toString(),n.appendChild(i),n.appendChild(r),e.appendChild(n)}const a=Object(En.a)({title:"Move to position",onClick:()=>{this.manager.globalPosition.value=o}});e.appendChild(a),n.appendChild(e)}for(const e of t.layers){const{layer:t}=e;n.appendChild(i.registerDisposer(new kn.a({value:void 0,changed:t.managedLayer.layerChanged},(n,i,r)=>{if(t.wasDisposed)return;if(!t.isReady)return;const s=document.createElement("div");if(s.classList.add("neuroglancer-selection-details-layer-body"),!t.displaySelectionState(e.state,s,r))return;const o=document.createElement("div");i.appendChild(o),o.classList.add("neuroglancer-selection-details-layer");const a=document.createElement("div");a.classList.add("neuroglancer-selection-details-layer-title"),a.textContent=t.managedLayer.name,a.addEventListener("click",()=>{this.selectedLayer.layer=t.managedLayer,this.selectedLayer.visible=!0}),a.title="Click to show layer side panel",o.appendChild(a),o.appendChild(s)})).element)}})).element)}}n(157),n(238),n(159),n(239),n(240),n(241),n(158),n(242);var Mn=n(65),Dn=n.n(Mn);class Ln extends lt.a{constructor(e){super(),this.viewer=e,this.parsedValue=null,this.debouncedValueUpdater=r()(()=>{const e=this.textEditor.getValue();try{const t=JSON.parse(e);this.parsedValue=t,this.applyButton.disabled=!1,this.textEditor.setOption("lint",void 0)}catch(t){this.parsedValue=null,this.applyButton.disabled=!0;let n=0,i=0,r="Unknown parse error";if(t instanceof Error){const s=t.message.match(/^((?:.|\n)*) in JSON at position ([0-9]+)$/);if(null!==s){r=s[1];const t=parseInt(s[2],10),o=e.substring(0,t).split("\n");n=o.length-1,i=o[o.length-1].length}else r=t.message}this.textEditor.setOption("lint",{getAnnotations:()=>[{message:r,severity:"error",from:Dn.a.Pos(n,i)}]})}},100),this.content.classList.add("neuroglancer-state-editor");const t=this.applyButton=document.createElement("button");t.textContent="Apply changes",this.content.appendChild(t),t.addEventListener("click",()=>this.applyChanges()),t.disabled=!0,this.textEditor=Dn()(e=>{},{value:"",mode:{name:"javascript",json:!0},foldGutter:!0,gutters:["CodeMirror-lint-markers","CodeMirror-foldgutter"]}),this.updateView(),this.textEditor.on("change",()=>{this.debouncedValueUpdater()}),this.content.appendChild(this.textEditor.getWrapperElement()),this.textEditor.refresh()}applyChanges(){null!==this.parsedValue&&(this.viewer.state.reset(),this.viewer.state.restoreState(this.parsedValue)),this.applyButton.disabled=!0}updateView(){this.textEditor.setValue(this.getJson()),this.textEditor.execCommand("foldAll"),this.textEditor.execCommand("unfold")}getJson(){return JSON.stringify(Object(m.c)(this.viewer.state).value,null,"  ")}}n(243);var jn=n(10);
/**
 * @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 In{constructor(){this.tracker=new m.a,this.visible=new le.b(!1),this.size=new f.c(100,g.D),this.tracker.add("visible",this.visible),this.tracker.add("size",this.size)}get changed(){return this.tracker.changed}restoreState(e){this.tracker.restoreState(e)}reset(){this.tracker.reset()}toJSON(){const e=this.tracker.toJSON();for(const t of Object.keys(e))if(void 0!==e[t])return e}}function Pn(e){const t=new Map;return function e(n,i){if("object"==typeof n)for(const t of Object.keys(n))e(n[t],i+"."+t);else t.set(i,""+n)}(e,""),t}function An(e){const t=e.map(Pn),n=function(e){const t=new Set;t.add(".type");const n=new Set;function i(n,i){for(const r of t)if(e[n].get(r)!==e[i].get(r))return!0;return!1}for(let r=0,s=e.length;r<s;++r){for(const t of e[r].keys())n.add(t);let s=[];for(let e=0;e<r;++e)i(r,e)||s.push(e);for(;s.length>0;){let i=s,o=void 0;for(const a of n){if(t.has(a))continue;const n=[];for(const t of s)e[t].get(a)===e[r].get(a)&&n.push(t);if(n.length<i.length&&(i=n,o=a),0===n.length)break}if(void 0===o)break;s=i,t.add(o)}}return Array.from(t)}(t);return t.map(e=>function(e,t){const n={};for(const i of t){const t=e.get(i);if(void 0!==t){if(""===i)return t;n[i]=t}}return JSON.stringify(n)}(e,n))}class Rn extends o.a{constructor(e,t){super(),this.chunkQueueManager=e,this.displayState=t,this.element=document.createElement("div"),this.columns=new Map,this.data=void 0,this.requestDataTimerId=-1,this.dataRequested=!1,this.debouncedUpdateView=this.registerCancellable(r()(()=>this.updateView(),0));const{element:n}=this;n.className="neuroglancer-statistics-panel",this.registerDisposer(this.displayState.changed.add(this.debouncedUpdateView)),this.registerDisposer(this.displayState.visible.changed.add(()=>this.requestData())),this.requestData();const{columns:i}=this;i.set("Visible chunks/T",e=>{let t=0;for(let n=0;n<jn.n;++n)t+=e[Object(jn.l)(n,jn.g.VISIBLE)*jn.m+jn.f.numChunks];return t}),i.set("Visible chunks/D",e=>e[Object(jn.l)(jn.h.DOWNLOADING,jn.g.VISIBLE)*jn.m+jn.f.numChunks]),i.set("Visible chunks/M",e=>e[Object(jn.l)(jn.h.SYSTEM_MEMORY,jn.g.VISIBLE)*jn.m+jn.f.numChunks]+e[Object(jn.l)(jn.h.SYSTEM_MEMORY_WORKER,jn.g.VISIBLE)*jn.m+jn.f.numChunks]),i.set("Visible chunks/G",e=>e[Object(jn.l)(jn.h.GPU_MEMORY,jn.g.VISIBLE)*jn.m+jn.f.numChunks]),i.set("Visible chunks/F",e=>e[Object(jn.l)(jn.h.FAILED,jn.g.VISIBLE)*jn.m+jn.f.numChunks]),i.set("Visible memory",e=>e[Object(jn.l)(jn.h.GPU_MEMORY,jn.g.VISIBLE)*jn.m+jn.f.gpuMemoryBytes]),i.set("Download latency",e=>e[Object(jn.k)(jn.e.totalTime)]/e[Object(jn.k)(jn.e.totalChunks)])}disposed(){clearTimeout(this.requestDataTimerId),Object(Pe.c)(this.element),super.disposed()}requestData(){if(!this.displayState.visible.value)return;if(this.dataRequested)return;const{chunkQueueManager:e}=this,t=e.rpc;this.dataRequested=!0,t.promiseInvoke(jn.j,{queue:e.rpcId}).then(e=>{this.dataRequested=!1,this.data=e,this.debouncedUpdateView(),this.requestDataTimerId=setTimeout(()=>{this.requestDataTimerId=-1,this.requestData()},1e3)})}updateView(){if(!this.displayState.visible.value)return;const{data:e}=this;if(void 0===e)return;const{columns:t}=this,n=this.chunkQueueManager.rpc,i=document.createElement("table"),r=[];for(const[i,s]of e){const e=n.get(i);if(void 0===e)continue;const o=[e];for(const e of t.values())o.push(e(s));r.push(o)}const s=An(r.map(e=>Object.assign({type:e[0].RPC_TYPE_ID},e[0].key||{}))),o=new Map;s.forEach((e,t)=>{o.set(r[t][0],e)});{const e=document.createElement("thead");let n=document.createElement("tr");e.appendChild(n);const r=e=>{const t=document.createElement("td");t.textContent=e,n.appendChild(t)};r("Name");let s=void 0;for(const e of t.keys()){const t=e.indexOf("/");let i=e;if(-1!==t){if(i=e.substring(0,t),i===s){++n.lastElementChild.colSpan;continue}s=i}r(i)}n=document.createElement("tr"),e.appendChild(n);{const e=document.createElement("td");n.appendChild(e)}for(const e of t.keys()){const t=e.indexOf("/");let i="";-1!==t&&(i=e.substring(t+1));const r=document.createElement("td");r.textContent=i,n.appendChild(r)}i.appendChild(e)}const a=document.createElement("tbody");for(const[e,...t]of r){const n=document.createElement("tr"),i=e=>{const t=document.createElement("td");t.textContent=e,n.appendChild(t)};i(o.get(e));for(const e of t)i(""+e);a.appendChild(n)}i.appendChild(a),Object(Pe.b)(this.element),this.element.appendChild(i)}}var Nn=n(68);n(244);
/**
 * @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 Vn extends o.a{constructor(e){super(),this.selectedLayer=e,this.element=document.createElement("div");const{element:t}=this;t.className="neuroglancer-annotation-tool-status-widget",this.registerDisposer(e.changed.add(()=>this.selectedLayerChanged())),this.selectedLayerChanged()}selectedLayerChanged(){let{unbindPreviousLayer:e}=this;void 0!==e&&e();const t=this.selectedLayer.layer;void 0!==t&&(this.unbindPreviousLayer=t.specificationChanged.add(()=>{this.updateView()})),this.updateView()}disposed(){const{unbindPreviousLayer:e}=this;void 0!==e&&e(),this.unbindPreviousLayer=void 0}getDescriptionText(){const e=this.selectedLayer.layer;if(void 0===e)return;const t=e.layer;if(null===t)return;const n=t.tool.value;return void 0!==n?n.description:void 0}updateView(){this.element.textContent=this.getDescriptionText()||""}}
/**
 * @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 _n extends o.a{constructor(e,t={}){super(),this.model=e,this.element=document.createElement("label"),this.inputElement=document.createElement("input");let{validator:n,label:i}=t;const{element:r,inputElement:s}=this;void 0===n&&(n=e instanceof f.c?e.validator:e=>e),this.validator=n,void 0!==i&&(r.textContent=i),r.appendChild(s),r.className="neuroglancer-number-input",s.type="input",this.registerDisposer(this.model.changed.add(()=>this.updateView())),this.registerEventListener(s,"change",()=>this.updateModel()),this.updateView()}updateView(){this.inputElement.value=""+this.model.value}updateModel(){let e=parseFloat(this.inputElement.value.trim());if(Number.isNaN(e))this.updateView();else try{e=this.validator(e),this.model.value=e}catch(e){this.updateView()}}disposed(){Object(Pe.c)(this.element),super.disposed()}}
/**
 * @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 Bn extends o.a{constructor(e,t,n=""){super(),this.gl=e,this.frameNumberCounter=t;const i=n+"chunk_worker.bundle.js";this.worker=new Worker(i),this.chunkQueueManager=this.registerDisposer(new x.d(new fe.a(this.worker),this.gl,this.frameNumberCounter,{gpuMemory:new x.a({defaultItemLimit:1e6,defaultSizeLimit:1e9}),systemMemory:new x.a({defaultItemLimit:1e7,defaultSizeLimit:2e9}),download:new x.a({defaultItemLimit:32,defaultSizeLimit:Number.POSITIVE_INFINITY}),compute:new x.a({defaultItemLimit:128,defaultSizeLimit:5e8})})),this.chunkQueueManager.registerDisposer(()=>this.worker.terminate()),this.chunkManager=this.registerDisposer(new x.c(this.chunkQueueManager))}get rpc(){return this.chunkQueueManager.rpc}}const Fn=["showHelpButton","showEditStateButton","showLayerPanel","showLocation","showLayerHoverValues","showAnnotationToolStatus"],zn=["showUIControls","showPanelBorders",...Fn];class Un extends class{constructor(){this.showHelpButton=new le.b(!0),this.showEditStateButton=new le.b(!0),this.showLayerPanel=new le.b(!0),this.showLocation=new le.b(!0),this.showLayerHoverValues=new le.b(!0),this.showAnnotationToolStatus=new le.b(!0)}}{constructor(){super(...arguments),this.showUIControls=new le.b(!0),this.showPanelBorders=new le.b(!0)}}const Gn="undefined"!=typeof NEUROGLANCER_OVERRIDE_DEFAULT_VIEWER_OPTIONS?NEUROGLANCER_OVERRIDE_DEFAULT_VIEWER_OPTIONS:{showLayerDialog:!0,resetStateWhenEmpty:!0};class $n extends m.a{constructor(e){super(),this.viewer=e,this.add("dimensions",e.coordinateSpace),this.add("relativeDisplayScales",e.relativeDisplayScales),this.add("displayDimensions",e.displayDimensions),this.add("position",e.position),this.add("crossSectionOrientation",e.crossSectionOrientation),this.add("crossSectionScale",e.crossSectionScale),this.add("crossSectionDepth",e.crossSectionDepthRange),this.add("projectionOrientation",e.projectionOrientation),this.add("projectionScale",e.projectionScale),this.add("projectionDepth",e.projectionDepthRange),this.add("layers",e.layerSpecification),this.add("showAxisLines",e.showAxisLines),this.add("wireFrame",e.wireFrame),this.add("showScaleBar",e.showScaleBar),this.add("showDefaultAnnotations",e.showDefaultAnnotations),this.add("showSlices",e.showPerspectiveSliceViews),this.add("gpuMemoryLimit",e.dataContext.chunkQueueManager.capacities.gpuMemory.sizeLimit),this.add("prefetch",e.dataContext.chunkQueueManager.enablePrefetch),this.add("systemMemoryLimit",e.dataContext.chunkQueueManager.capacities.systemMemory.sizeLimit),this.add("concurrentDownloads",e.dataContext.chunkQueueManager.capacities.download.itemLimit),this.add("selectedLayer",e.selectedLayer),this.add("crossSectionBackgroundColor",e.crossSectionBackgroundColor),this.add("projectionBackgroundColor",e.perspectiveViewBackgroundColor),this.add("layout",e.layout),this.add("statistics",e.statisticsDisplayState),this.add("selection",e.selectionDetailsState)}restoreState(e){const{viewer:t}=this;super.restoreState(e),Object(g.B)(e,"navigation",e=>{Object(g.w)(e),Object(g.B)(e,"pose",e=>{Object(g.w)(e),Object(g.B)(e,"position",e=>{Object(g.w)(e),Object(m.d)(e,"voxelCoordinates",t.position),Object(g.B)(e,"voxelSize",e=>{const n=Object(g.d)(new Float64Array(3),e,g.r);for(let e=0;e<3;++e)n[e]*=1e-9;t.coordinateSpace.value=Object(C.y)({valid:!1,names:["x","y","z"],units:["m","m","m"],scales:n})})}),Object(m.d)(e,"orientation",t.crossSectionOrientation)}),Object(m.d)(e,"zoomFactor",t.crossSectionScale.legacyJsonView)}),Object(m.d)(e,"perspectiveOrientation",t.projectionOrientation),Object(m.d)(e,"perspectiveZoom",t.projectionScale.legacyJsonView),Object(m.d)(e,"perspectiveViewBackgroundColor",t.perspectiveViewBackgroundColor)}}class Wn extends o.a{constructor(e,t={}){super(),this.display=e,this.coordinateSpace=new C.b,this.position=this.registerDisposer(new T.k(this.coordinateSpace)),this.relativeDisplayScales=this.registerDisposer(new T.p(this.coordinateSpace)),this.displayDimensions=this.registerDisposer(new T.n(this.coordinateSpace)),this.displayDimensionRenderInfo=this.registerDisposer(new T.q(this.relativeDisplayScales.addRef(),this.displayDimensions.addRef())),this.crossSectionOrientation=this.registerDisposer(new T.j),this.crossSectionScale=this.registerDisposer(new T.l(this.displayDimensionRenderInfo.addRef())),this.projectionOrientation=this.registerDisposer(new T.j),this.crossSectionDepthRange=this.registerDisposer(new T.m(-10,this.displayDimensionRenderInfo)),this.projectionDepthRange=this.registerDisposer(new T.m(-50,this.displayDimensionRenderInfo)),this.projectionScale=this.registerDisposer(new T.o(this.displayDimensionRenderInfo.addRef())),this.navigationState=this.registerDisposer(new T.i(new T.a(this.position.addRef(),this.displayDimensionRenderInfo.addRef(),this.crossSectionOrientation.addRef()),this.crossSectionScale.addRef(),this.crossSectionDepthRange.addRef())),this.perspectiveNavigationState=this.registerDisposer(new T.i(new T.a(this.position.addRef(),this.displayDimensionRenderInfo.addRef(),this.projectionOrientation.addRef()),this.projectionScale.addRef(),this.projectionDepthRange.addRef())),this.mouseState=new j.f,this.layerManager=this.registerDisposer(new j.a),this.selectedLayer=this.registerDisposer(new j.h(this.layerManager.addRef())),this.showAxisLines=new le.b(!0,!0),this.wireFrame=new le.b(!1,!1),this.showScaleBar=new le.b(!0,!0),this.showPerspectiveSliceViews=new le.b(!0,!0),this.visibleLayerRoles=Object(ae.f)(),this.showDefaultAnnotations=new le.b(!0,!0),this.crossSectionBackgroundColor=new Nn.a(U.u.fromValues(.5,.5,.5)),this.perspectiveViewBackgroundColor=new Nn.a(U.u.fromValues(0,0,0)),this.scaleBarOptions=new pe.b,this.statisticsDisplayState=new In,this.layerSelectedValues=this.registerDisposer(new j.c(this.layerManager,this.mouseState)),this.selectionDetailsState=this.registerDisposer(new j.j(this.coordinateSpace,this.layerSelectedValues)),this.resetInitiated=new y.a,this.uiControlVisibility={},this.visible=!0;const{dataContext:n=new Bn(e.gl,e,t.bundleRoot),visibility:i=new ue.b(ue.b.VISIBLE),inputEventBindings:s={global:new G.a,sliceView:new G.a,perspectiveView:new G.a},element:o=e.makeCanvasOverlayElement(),dataSourceProvider:a=Object(h.a)({credentialsManager:O}),uiConfiguration:c=new Un}=t;this.visibility=i,this.inputEventBindings=s,this.element=o,this.dataSourceProvider=a,this.uiConfiguration=c,this.registerDisposer(()=>Object(Pe.c)(this.element)),this.dataContext=this.registerDisposer(n),function(e,t){for(const n of zn){const i=t[n];void 0!==i&&(e[n].value=i)}}(c,t);const l=Object.assign(Object.assign({},Gn),t),{resetStateWhenEmpty:d,showLayerDialog:u}=l;for(const e of Fn)this.uiControlVisibility[e]=this.makeUiControlVisibilityState(e);this.registerDisposer(this.uiConfiguration.showPanelBorders.changed.add(()=>{this.updateShowBorders()})),this.showLayerDialog=u,this.resetStateWhenEmpty=d,this.layerSpecification=new j.i(this.dataSourceProvider,this.layerManager,this.chunkManager,this.selectionDetailsState,this.selectedLayer,this.navigationState.coordinateSpace,this.navigationState.pose.position),this.registerDisposer(e.updateStarted.add(()=>{this.onUpdateDisplay()})),this.showDefaultAnnotations.changed.add(()=>{this.showDefaultAnnotations.value?this.visibleLayerRoles.add(ae.c.DEFAULT_ANNOTATION):this.visibleLayerRoles.delete(ae.c.DEFAULT_ANNOTATION)}),this.registerDisposer(this.navigationState.changed.add(()=>{this.handleNavigationStateChanged()}));const p=this.registerCancellable(r()(()=>{!this.wasDisposed&&0===this.layerManager.managedLayers.length&&this.resetStateWhenEmpty&&(this.navigationState.reset(),this.perspectiveNavigationState.pose.orientation.reset(),this.perspectiveNavigationState.zoomFactor.reset(),this.resetInitiated.dispatch(),!lt.b&&this.showLayerDialog&&this.visibility.visible&&Object(j.l)(this.layerSpecification,this.selectedLayer))}));this.layerManager.layersChanged.add(p),p(),this.registerDisposer(this.dataContext.chunkQueueManager.visibleChunksChanged.add(()=>{this.layerSelectedValues.handleLayerChange()})),this.registerDisposer(this.dataContext.chunkQueueManager.visibleChunksChanged.add(()=>{this.visible&&e.scheduleRedraw()})),this.makeUI(),this.updateShowBorders(),this.registerActionListeners(),this.registerEventActionBindings(),this.registerDisposer(qt(o,this.navigationState.position)),this.state=new $n(this)}get chunkManager(){return this.dataContext.chunkManager}get chunkQueueManager(){return this.dataContext.chunkQueueManager}makeUiControlVisibilityState(e){const t=this.uiConfiguration.showUIControls,n=this.uiConfiguration[e];return this.registerDisposer(Object(f.i)((e,t)=>e&&t,t,n))}get inputEventMap(){return this.inputEventBindings.global}updateShowBorders(){const{element:e}=this,t="neuroglancer-show-panel-borders";this.uiConfiguration.showPanelBorders.value?e.classList.add(t):e.classList.remove(t)}makeUI(){const e=this.element;e.classList.add("neuroglancer-viewer"),e.classList.add("neuroglancer-noselect"),e.style.display="flex",e.style.flexDirection="column";const t=document.createElement("div");t.title="Right click for settings",t.classList.add("neuroglancer-viewer-top-row"),(this.contextMenu=this.registerDisposer(function(e){const t=new Jt,{element:n}=t;n.classList.add("neuroglancer-viewer-context-menu");const i=(e,i)=>{const r=t.registerDisposer(new _n(i,{label:e}));r.element.classList.add("neuroglancer-viewer-context-menu-limit-widget"),n.appendChild(r.element)};i("GPU memory limit",e.chunkQueueManager.capacities.gpuMemory.sizeLimit),i("System memory limit",e.chunkQueueManager.capacities.systemMemory.sizeLimit),i("Concurrent chunk requests",e.chunkQueueManager.capacities.download.itemLimit);const r=(e,i)=>{const r=document.createElement("label");r.textContent=e;const s=t.registerDisposer(new le.c(i));r.appendChild(s.element),n.appendChild(r)};return r("Show axis lines",e.showAxisLines),r("Show scale bar",e.showScaleBar),r("Show cross sections in 3-d",e.showPerspectiveSliceViews),r("Show default annotations",e.showDefaultAnnotations),r("Show chunk statistics",e.statisticsDisplayState.visible),r("Wire frame rendering",e.wireFrame),r("Enable prefetching",e.chunkQueueManager.enablePrefetch),t}(this))).registerParent(t),t.style.display="flex",t.style.flexDirection="row",t.style.alignItems="stretch";const n=this.registerDisposer(new zt(this.navigationState.position,this.layerSpecification.coordinateSpaceCombiner));this.registerDisposer(new le.a(this.uiControlVisibility.showLocation,n.element)),t.appendChild(n.element);const i=this.registerDisposer(new Ut(document.createElement("div"),this.mouseState,this.navigationState.coordinateSpace));i.element.style.flex="1",i.element.style.alignSelf="center",this.registerDisposer(new le.a(this.uiControlVisibility.showLocation,i.element)),t.appendChild(i.element);const r=this.registerDisposer(new Vn(this.selectedLayer));t.appendChild(r.element),this.registerDisposer(new le.a(this.uiControlVisibility.showAnnotationToolStatus,r.element));{const e=Object(Lt.a)({text:"{}",title:"Edit JSON state"});this.registerEventListener(e,"click",()=>{this.editJsonState()}),this.registerDisposer(new le.a(this.uiControlVisibility.showEditStateButton,e)),t.appendChild(e)}{const e=Object(Lt.a)({text:"?",title:"Help"});this.registerEventListener(e,"click",()=>{this.showHelpDialog()}),this.registerDisposer(new le.a(this.uiControlVisibility.showHelpButton,e)),t.appendChild(e)}this.registerDisposer(new le.a(Object(f.i)((...e)=>e.reduce((e,t)=>e||t,!1),this.uiControlVisibility.showHelpButton,this.uiControlVisibility.showEditStateButton,this.uiControlVisibility.showLocation,this.uiControlVisibility.showAnnotationToolStatus),t)),e.appendChild(t);const s=document.createElement("div");s.style.display="flex",s.style.flex="1",s.style.flexDirection="row",this.layout=this.registerDisposer(new ln(this,"4panel")),s.appendChild(this.layout.element);const o=document.createElement("div");o.classList.add("neuroglancer-viewer-side-panel"),s.appendChild(o);const a=this,c={changed:new y.b,get value(){return a.selectedLayer.visible||a.selectionDetailsState.visible.value},set value(e){a.selectedLayer.visible=e,a.selectionDetailsState.visible.value=e}};this.registerDisposer(this.selectedLayer.changed.add(c.changed.dispatch)),this.registerDisposer(this.selectionDetailsState.changed.add(c.changed.dispatch)),this.registerDisposer(new dn(o,c,this.selectedLayer.size,"horizontal",290));const l=this.registerDisposer(new Sn(this.selectedLayer.addRef()));this.registerDisposer(new le.a({changed:a.selectedLayer.changed,get value(){return a.selectedLayer.visible}},l.element)),o.appendChild(l.element);const d=this.registerDisposer(new Tn(this.selectionDetailsState,this.layerSpecification,this.selectedLayer));o.appendChild(d.element),this.registerDisposer(new le.a(this.selectionDetailsState.visible,d.element)),e.appendChild(s);const u=this.registerDisposer(new Rn(this.chunkQueueManager,this.statisticsDisplayState));e.appendChild(u.element),u.registerDisposer(new dn(u.element,this.statisticsDisplayState.visible,this.statisticsDisplayState.size,"vertical"));const h=()=>{const t=this.visibility.visible;t!==this.visible&&(e.style.visibility=t?"inherit":"hidden",this.visible=t)};h(),this.registerDisposer(this.visibility.changed.add(h))}registerEventActionBindings(){const{element:e}=this;this.registerDisposer(new G.b(e,this.inputEventMap)),this.registerDisposer(new z.a(e))}bindAction(e,t){this.registerDisposer(Object(S.d)(this.element,e,t))}registerActionListeners(){for(const e of["recolor","clear-segments"])this.bindAction(e,()=>{this.layerManager.invokeAction(e)});for(const e of["select"])this.bindAction(e,()=>{this.mouseState.updateUnconditionally(),this.layerManager.invokeAction(e)});this.bindAction("help",()=>this.showHelpDialog());for(let e=1;e<=9;++e)this.bindAction(`toggle-layer-${e}`,()=>{const t=e-1,n=this.layerManager.managedLayers;if(t<n.length){let e=n[t];e.setVisible(!e.visible)}}),this.bindAction(`toggle-pick-layer-${e}`,()=>{const t=e-1,n=this.layerManager.managedLayers;if(t<n.length){let e=n[t];e.pickEnabled=!e.pickEnabled}}),this.bindAction(`select-layer-${e}`,()=>{const t=e-1,n=this.layerManager.managedLayers;if(t<n.length){const e=n[t];this.selectedLayer.layer=e,this.selectedLayer.visible=!0}});this.bindAction("annotate",()=>{const e=this.selectedLayer.layer;if(void 0===e)return void It.a.showTemporaryMessage("The annotate command requires a layer to be selected.");const t=e.layer;null!==t&&void 0!==t.tool.value?t.tool.value.trigger(this.mouseState):It.a.showTemporaryMessage(`The selected layer (${JSON.stringify(e.name)}) does not have an active annotation tool.`)}),this.bindAction("toggle-axis-lines",()=>this.showAxisLines.toggle()),this.bindAction("toggle-scale-bar",()=>this.showScaleBar.toggle()),this.bindAction("toggle-default-annotations",()=>this.showDefaultAnnotations.toggle()),this.bindAction("toggle-show-slices",()=>this.showPerspectiveSliceViews.toggle()),this.bindAction("toggle-show-statistics",()=>this.showStatistics())}showHelpDialog(){const{inputEventBindings:e}=this;new ut([["Global",e.global],["Cross section view",e.sliceView],["3-D projection view",e.perspectiveView]])}editJsonState(){new Ln(this)}showStatistics(e){void 0===e&&(e=!this.statisticsDisplayState.visible.value),this.statisticsDisplayState.visible.value=e}get gl(){return this.display.gl}onUpdateDisplay(){this.visible&&(this.dataContext.chunkQueueManager.chunkUpdateDeadline=null)}handleNavigationStateChanged(){if(this.visible){let{chunkQueueManager:e}=this.dataContext;null===e.chunkUpdateDeadline&&(e.chunkUpdateDeadline=Date.now()+10)}}}
/**
 * @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 Hn extends o.a{constructor(e,t,n,i){super(),this.display=e,this.dataSourceProvider=t,this.dataContext=n,this.uiConfiguration=i,this.prefetchStates=new Map,this.changed=new y.a,this.specification=[],this.updatePrefetchStates=this.registerCancellable(r()(()=>{const{specification:e,prefetchStates:t}=this,n=new Set;for(const{state:i,priority:r}of e){const e=JSON.stringify(i);n.add(e);let s=t.get(e);void 0===s?(s=this.makePrefetchState(i,r),t.set(e,s)):s.visibility.value=r}for(const[e,i]of t)n.has(e)||(t.delete(e),i.dispose())},0)),this.registerDisposer(n)}makePrefetchState(e,t){const n=new Wn(this.display,{showLayerDialog:!1,resetStateWhenEmpty:!1,dataSourceProvider:this.dataSourceProvider,dataContext:this.dataContext.addRef(),visibility:new ue.b(t),uiConfiguration:this.uiConfiguration});try{n.state.restoreState(e)}catch(e){console.log(`Error setting prefetch state: ${e.message}`)}return n}reset(){this.specification=[],this.changed.dispatch(),this.updatePrefetchStates()}restoreState(e){this.specification=Object(g.b)(e,e=>(Object(g.w)(e),{state:Object(g.y)(e,"state",g.w),priority:Object(g.y)(e,"priority",e=>void 0===e?0:Object(g.u)(e))})),this.changed.dispatch(),this.updatePrefetchStates()}toJSON(){const{specification:e}=this;return 0===e.length?void 0:this.specification}}
/**
 * @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 Jn extends o.a{constructor(e){super(),this.viewer=e,this.actionSet=new f.c(new Set,e=>new Set(Object(g.F)(e))),this.actionDisposers=[],this.sendActionRequested=new y.b,this.actionSet.changed.add(r()(()=>this.updateActions(),0))}clearListeners(){for(const e of this.actionDisposers)e();this.actionDisposers.length=0}disposed(){this.clearListeners(),super.disposed()}updateActions(){this.clearListeners();for(const e of this.actionSet.value)this.actionDisposers.push(Object(S.d)(this.viewer.element,e,()=>this.handleAction(e)))}handleAction(e){const{mouseState:t,layerSelectedValues:n}=this.viewer,i={};t.updateUnconditionally()&&(i.mousePosition=Array.prototype.slice.call(t.position)),i.selectedValues=n.toJSON(),i.viewerState=Object(m.c)(this.viewer.state).value,this.sendActionRequested.dispatch(e,JSON.parse(JSON.stringify(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.
 */class qn extends o.a{constructor(){super(),this.existingMessages=new Map,this.changed=new y.a,this.messages=new Map,this.changed.add(this.registerCancellable(r()(()=>this.updateMessages(),0)))}reset(){this.messages.clear(),this.changed.dispatch()}restoreState(e){Object(g.w)(e),this.messages.clear();for(const t of Object.keys(e)){const n=e[t],i=Object(g.E)(n);this.messages.set(t,i)}this.changed.dispatch()}disposed(){for(const e of this.existingMessages.values())e.dispose();this.existingMessages.clear()}updateMessages(){const{existingMessages:e}=this,t=this.messages;for(const[n,i]of e){const r=t.get(n);void 0===r?(i.dispose(),e.delete(n)):i.setText(r)}for(const[n,i]of t){if(e.has(n))continue;const t=new It.a;t.setText(i),e.set(n,t)}}toJSON(){const e={};for(const[t,n]of this.messages)e[t]=n;return e}}
/**
 * @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 Yn extends o.a{constructor(e){super(),this.viewer=e,this.sendScreenshotRequested=new y.b,this.requestState=new f.c(void 0,g.C),this.wasAlreadyVisible=!1,this.previousRequest=void 0,this.debouncedMaybeSendScreenshot=this.registerCancellable(r()(()=>this.maybeSendScreenshot(),0)),this.requestState.changed.add(this.debouncedMaybeSendScreenshot),this.registerDisposer(e.display.updateFinished.add(this.debouncedMaybeSendScreenshot))}maybeSendScreenshot(){const e=this.requestState.value,{previousRequest:t}=this,{layerSelectedValues:n}=this.viewer;if(void 0===e||e===t)return void(this.wasAlreadyVisible=!1);const{viewer:i}=this;if(!i.display.isReady())return void(this.wasAlreadyVisible=!1);for(const e of i.layerManager.managedLayers)if(!e.isReady())return void(this.wasAlreadyVisible=!1);if(!this.wasAlreadyVisible)return this.wasAlreadyVisible=!0,void this.debouncedMaybeSendScreenshot();this.wasAlreadyVisible=!1,this.previousRequest=e,i.display.draw();const r=i.display.canvas.toDataURL(),s="data:image/png;base64,";let o,a;r.startsWith(s)?(o="image/png",a=r.substring(s.length)):(o="",a="");const c={viewerState:JSON.parse(JSON.stringify(Object(m.c)(this.viewer.state).value)),selectedValues:JSON.parse(JSON.stringify(n)),screenshot:{id:e,image:a,imageType:o}};this.sendScreenshotRequested.dispatch(c)}}var Xn=n(84);
/**
 * @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 Kn extends o.a{constructor(e,t=100,n=!0){super(),this.state=e,this.receiveUpdates=n,this.serverGeneration="",this.clientGeneration=-1,this.connected_=!1,this.receiveUpdateRequested=new y.b,this.sendUpdateRequested=new y.b,null!==t?(this.sendUpdates=!0,this.registerDisposer(e.changed.add(this.registerCancellable(q()(this.registerCancellable(r()(()=>this.handleStateChanged(),0)),t,{leading:!1}))))):this.sendUpdates=!1}set connected(e){e!==this.connected_&&(this.connected_=e,!0===e&&(this.receiveUpdates&&this.receiveUpdateRequested.dispatch(this.serverGeneration),this.handleStateChanged()))}get connected(){return this.connected_}setState(e,t){this.receiveUpdates&&t!==this.serverGeneration&&(this.lastServerState=JSON.stringify(e),this.state.reset(),this.state.restoreState(e),this.serverGeneration=t,this.clientGeneration=this.state.changed.count)}handleStateChanged(){if(!this.sendUpdates)return;if(!this.connected_||this.receiveUpdates&&""===this.serverGeneration||this.clientGeneration===this.state.changed.count)return;const e=Object(m.c)(this.state).value,t=JSON.stringify(e);if(t===this.lastServerState)return void(this.clientGeneration=this.state.changed.count);const n=Object(Xn.a)(160);this.serverGeneration=n,this.lastServerState=t,this.sendUpdateRequested.dispatch(e,n)}}var Qn=n(183),Zn=n.n(Qn);class ei extends o.a{constructor(e,t,n,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.
 */
function(){const e=window.location.pathname.match(/^(.*)\/v\/([^\/]+)/);if(null===e)throw new Error("Failed to determine token from URL.");return`${window.location.origin}${e[1]}/socket/${e[2]}`}()){super(),this.sharedState=e,this.privateState=t,this.configState=n,this.url=i,this.reconnectionDelay=1e3,this.waitingToReconnect=-1,this.isOpen=!1,this.updateClients=new Map,this.status=this.registerDisposer(new It.a(!0)),this.actionQueue=[],this.nextActionId=0,this.lastActionAcknowledged=-1;const r=[{key:"p",state:t,receiveUpdates:!1,sendUpdates:0},{key:"c",state:n,receiveUpdates:!0,sendUpdates:null}];void 0!==e&&r.push({key:"s",state:e,receiveUpdates:!0,sendUpdates:100});for(const{key:e,state:t,receiveUpdates:n,sendUpdates:i}of r){const r=this.registerDisposer(new Kn(t,i,n));this.updateClients.set(e,r),null!==i&&r.sendUpdateRequested.add((t,n)=>this.send("setState",{k:e,s:t,g:n})),n&&r.receiveUpdateRequested.add(t=>this.send("getState",{g:t,k:e}))}this.connect()}dispose(){void 0!==this.socket&&(this.socket.close(),this.socket=void 0),-1!==this.waitingToReconnect&&(clearInterval(this.waitingToReconnect),this.waitingToReconnect=-1)}send(e,t){t.t=e,this.socket.send(JSON.stringify(t))}connect(){this.status.setText("Connecting to Python server"),this.status.setVisible(!0);const e=this.socket=new Zn.a(this.url,{transports:["websocket","xhr-streaming"]});e.onopen=()=>{this.isOpen=!0,this.reconnectionDelay=1e3,this.status.setVisible(!1);for(const e of this.updateClients.values())e.connected=!0;this.flushActionQueue()},e.onclose=()=>{this.isOpen=!1;const{reconnectionDelay:e}=this;for(const e of this.updateClients.values())e.connected=!1;const t=Date.now()+e;this.status.setVisible(!0);const n=e=>{this.status.setText("Disconnected from Python server.  "+`Retrying in ${Math.ceil(e/1e3)} seconds.`)};this.waitingToReconnect=setInterval(()=>{const e=t-Date.now();e<0?(clearInterval(this.waitingToReconnect),this.waitingToReconnect=-1,this.connect()):n(e)},1e3),n(e),this.reconnectionDelay=Math.min(3e4,2*e)},e.onmessage=e=>{const t=JSON.parse(e.data);if("object"!=typeof t||Array.isArray(t))throw new Error("Invalid message received over server connection.");switch(t.t){case"setState":{const e=this.updateClients.get(t.k);if(void 0===e)throw new Error(`Invalid state key: ${JSON.stringify(t.k)}`);e.setState(t.s,t.g);break}case"ackAction":{const e=parseInt(t.id,10);if(e<this.lastActionAcknowledged||e>=this.nextActionId)throw new Error("Invalid action acknowledged message");this.actionQueue.splice(0,e-this.lastActionAcknowledged),this.lastActionAcknowledged=e;break}}}}flushActionQueue(){const{actionQueue:e}=this;0!==e.length&&this.send("action",{id:this.nextActionId-1,actions:e})}sendActionNotification(e,t){this.actionQueue.push({action:e,state:t}),++this.nextActionId,this.isOpen&&this.flushActionQueue()}}
/**
 * @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 ti(e){e.registerEventListener(document,"paste",t=>{if(Object(Pe.a)(t.target))return;const{clipboardData:n}=t;if(null!==n){const t=function(e,t){let n=String.raw`^[\[\]{}()\s,]*`;for(let e=0;e<t;++e)0!==e&&(n+=String.raw`[,\s]+`),n+=String.raw`(\d+(?:\.\d+)?)`;n+=String.raw`[\[\]{}()\s,]*$`;const i=e.match(n);if(null===i)return;const r=new Float32Array(t);for(let e=0;e<t;++e){const t=Number(i[e+1]);if(!Number.isFinite(t))return;r[e]=t}return r}(n.getData("text/plain"),e.coordinateSpace.value.rank);void 0!==t&&(e.navigationState.position.value=t)}t.preventDefault()})}var ni=n(113);n(274);var ii=n(25),ri=n(74);
/**
 * @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 si=Symbol("SingleTextureVolumeChunk.textureUnit"),oi=Symbol("SingleTextureVolumeChunk.textureLayout");class ai extends o.a{constructor(e,t){super(),this.shaderKey=e,this.dataType=t}defineShader(e,t){e.addTextureSampler(this.shaderSamplerType,"uVolumeChunkSampler",si)}beginDrawing(e,t){let n=t.textureUnit(si);e.activeTexture(WebGL2RenderingContext.TEXTURE0+n),t[oi]=null}endDrawing(e,t){e.bindTexture(ri.b[this.shaderSamplerType],null),t[oi]=null}bindChunk(e,t,n,i,r,s,o){let a=n.textureLayout;(t[oi]!==a||o)&&(t[oi]=a,this.setupTextureLayout(e,t,a,i,r,s)),e.bindTexture(ri.b[this.shaderSamplerType],n.texture)}beginSource(e,t){}}class ci extends ii.b{constructor(e,t){super(e,t),this.texture=null,this.data=t.data}copyToGPU(e){super.copyToGPU(e);let t=this.texture=e.createTexture();const n=ri.b[this.chunkFormat.shaderSamplerType];e.bindTexture(n,t),this.setTextureData(e),e.bindTexture(n,null)}freeGPUMemory(e){super.freeGPUMemory(e),e.deleteTexture(this.texture),this.texture=null,this.textureLayout.dispose(),this.textureLayout=null}}var li=n(9),di=n(18),ui=n(20),hi=n(35);
/**
 * @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 pi extends o.a{constructor(e,t,n){super(),this.chunkDataSize=t,this.textureDims=n,this.textureShape=new Uint32Array(this.textureDims);const i=t.length;let r=0;for(const e of t)1!==e&&++r;const s=this.strides=new Uint32Array(i*n),o=3===n?e.max3dTextureSize:e.maxTextureSize;let a=0,c=1;const{textureShape:l}=this;l.fill(1);for(let e=0;e<i;++e){const i=t[e];if(1===i)continue;const d=i*c;let u;d>o||1!==c&&a+r<n?(++a,c=i,u=1):(u=c,c=d),s[n*e+a]=u,l[a]=c}}static get(e,t,n){return e.memoize.get(`sliceview.UncompressedTextureLayout:${t.join()}:${n}`,()=>new pi(e,t,n))}}let fi=new Uint32Array(15);class mi extends ai{constructor(e,t,n,i){super(n,t),this.textureDims=i,Object(hi.d)(this,t),this.shaderSamplerType=`${this.samplerPrefix}sampler${i}D`,this.textureAccessHelper=new hi.b("chunkData",i)}static get(e,t,n){const i=`sliceview.UncompressedChunkFormat:${t}:${n}`;return e.memoize.get(i,()=>new mi(e,t,i,n))}defineShader(e,t){super.defineShader(e,t);const{textureDims:n}=this,i=`ivec${this.textureDims}`;let{textureAccessHelper:r}=this;const s=(4+t)*n;fi.length<s&&(fi=new Uint32Array(s)),e.addUniform(`highp ${i}`,"uVolumeChunkStrides",4+t),e.addFragmentCode(r.getAccessor("readVolumeData","uVolumeChunkSampler",this.dataType));let o=`\n${Object(ui.b)(this.dataType)} getDataValueAt(highp ivec3 p`;for(let e=0;e<t;++e)o+=`, highp int channelIndex${e}`;o+=`) {\n  highp ${i} offset = uVolumeChunkStrides[0]\n                     + p.x * uVolumeChunkStrides[1]\n                     + p.y * uVolumeChunkStrides[2]\n                     + p.z * uVolumeChunkStrides[3];\n`;for(let e=0;e<t;++e)o+=`\n  offset += channelIndex${e} * uVolumeChunkStrides[${4+e}];\n`;o+="\n  return readVolumeData(offset);\n}\n",e.addFragmentCode(o)}setupTextureLayout(e,t,n,i,r,s){const o=fi,a=s.length,{strides:c}=n,l=i.length,{textureDims:d}=this;for(let e=0;e<d;++e){let t=0;for(let n=0;n<l;++n)t+=i[n]*c[n*d+e];o[e]=t}for(let e=0;e<3;++e){const t=r[e];if(!(t>=l))for(let n=0;n<d;++n)o[(e+1)*d+n]=c[t*d+n]}for(let e=0;e<a;++e){const t=s[e];if(-1===t)o.fill(0,(4+e)*d,(4+e+1)*d);else for(let n=0;n<d;++n)o[(4+e)*d+n]=c[t*d+n]}const u=(4+a)*d;3===d?e.uniform3iv(t.uniform("uVolumeChunkStrides"),o,0,u):e.uniform2iv(t.uniform("uVolumeChunkStrides"),o,0,u)}getTextureLayout(e,t){return pi.get(e,t,this.textureDims)}setTextureData(e,t,n){const{textureShape:i}=t;(3===this.textureDims?hi.g:hi.h)(e,this,n,i[0],i[1],i[2])}}class gi extends ci{setTextureData(e){let t,{source:n}=this,{chunkFormatHandler:i}=n,{chunkFormat:r}=i;this.chunkDataSize===n.spec.chunkDataSize?this.textureLayout=t=i.textureLayout.addRef():this.textureLayout=t=r.getTextureLayout(e,this.chunkDataSize),this.chunkFormat.setTextureData(e,t,this.data)}getValueAt(e){let{chunkFormat:t}=this;const{chunkDataSize:n}=this;let i=0,r=1;const s=e.length;for(let t=0;t<s;++t)i+=r*e[t],r*=n[t];let o=t.dataType,a=this.data;switch(o){case li.a.UINT8:case li.a.INT8:case li.a.FLOAT32:case li.a.UINT16:case li.a.INT16:case li.a.UINT32:case li.a.INT32:return a[i];case li.a.UINT64:{let e=2*i;return new di.a(a[e],a[e+1])}}}}class vi extends o.a{constructor(e,t){super();let n=0;for(const e of t.chunkDataSize)e>1&&++n;this.chunkFormat=this.registerDisposer(mi.get(e,t.dataType,n>=3?3:2)),this.textureLayout=this.registerDisposer(this.chunkFormat.getTextureLayout(e,t.chunkDataSize))}getChunk(e,t){return new gi(e,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 bi(e,t,n,i,r,s){let o=0,a=0,c=1,l=1;for(let e=0;e<3;++e){let t=r[e],s=i[e],d=t%s;o+=Math.floor(t/s)*c,c*=Math.ceil(n[e]/s),a+=d*l,l*=s}let d=t+2*o,u=e[d],h=e[d+1],p=16777215&u,f=u>>24&255;if(f>0){p+=s*(e[(t+h&16777215)+Math.floor(a*f/32)]>>a*f%32&(1<<f)-1)}return p}
/**
 * @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 yi(e,t,n,i,r){return e[bi(e,t,n,i,r,1)+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 Si(e,t,n,i,r,s){let o=bi(t,n,i,r,s,2)+n;return e.low=t[o],e.high=t[o+1],e}Object(ii.e)((e,t)=>null==t.compressedSegmentationBlockSize?new vi(e,t):null);
/**
 * @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 wi extends o.a{constructor(e,t){super(),this.chunkDataSize=e,this.subchunkSize=t;const n=this.subchunkGridSize=U.u.create();for(let i=0;i<3;++i)n[i]=Math.ceil(e[i]/t[i])}static get(e,t,n){return e.memoize.get(`sliceview.CompressedSegmentationTextureLayout:${Object(U.v)(t)},`+`${Object(U.v)(n)}`,()=>new wi(t,n))}}const xi=Object(hi.d)(new hi.c,li.a.UINT32);let Ci=new Uint32Array(16);class Oi extends ai{constructor(e,t,n,i){super(i,e),this.subchunkSize=t,this.numChannels=n,this.textureAccessHelper=new hi.a("chunkData")}static get(e,t,n,i){let r=`sliceview.CompressedSegmentationChunkFormat:${t}:${i}`,s=`${r}:${Object(U.v)(n)}`;return e.memoize.get(s,()=>new Oi(t,n,i,r))}get shaderSamplerType(){return"usampler2D"}defineShader(e,t){super.defineShader(e,t);const n=4*(4+t);Ci.length<n&&(Ci=new Uint32Array(n));let{textureAccessHelper:i}=this;i.defineShader(e);let r=e=>"compressedSegmentationChunkFormat_"+e;e.addUniform("highp ivec3","uSubchunkGridSize"),e.addUniform("highp ivec3","uSubchunkSize"),e.addUniform("highp ivec4","uVolumeChunkStrides",4+t),e.addFragmentCode(ui.f);const{dataType:s}=this,o=Object(ui.b)(s);s===li.a.UINT64?e.addFragmentCode(ui.o):e.addFragmentCode(ui.n),e.addFragmentCode(i.getAccessor(r("readTextureValue"),"uVolumeChunkSampler",li.a.UINT32,1));let a=`\nuint ${r("getChannelOffset")}(int channelIndex) {\n  if (channelIndex == 0) {\n    return ${this.numChannels}u;\n  }\n  return ${r("readTextureValue")}(uint(channelIndex)).value;\n}\n${o} getDataValueAt(highp ivec3 p`;for(let e=0;e<t;++e)a+=`, highp int channelIndex${e}`;a+=") {\n  highp ivec4 chunkPositionFull = uVolumeChunkStrides[0] +\n                     + p.x * uVolumeChunkStrides[1]\n                     + p.y * uVolumeChunkStrides[2]\n                     + p.z * uVolumeChunkStrides[3];\n";for(let e=0;e<t;++e)a+=`\n  chunkPositionFull += channelIndex${e} * uVolumeChunkStrides[${4+e}];\n`;a+=`\n  highp ivec3 chunkPosition = chunkPositionFull.xyz;\n\n  // TODO: maybe premultiply this and store as uniform.\n  ivec3 subchunkGridPosition = chunkPosition / uSubchunkSize;\n  int subchunkGridOffset = getFortranOrderIndex(subchunkGridPosition, uSubchunkGridSize);\n\n  int channelOffset = int(${r("getChannelOffset")}(chunkPositionFull[3]));\n\n  // TODO: Maybe just combine this offset into subchunkGridStrides.\n  int subchunkHeaderOffset = subchunkGridOffset * 2 + channelOffset;\n\n  highp uint subchunkHeader0 = ${r("readTextureValue")}(uint(subchunkHeaderOffset)).value;\n  highp uint subchunkHeader1 = ${r("readTextureValue")}(uint(subchunkHeaderOffset + 1)).value;\n  highp uint outputValueOffset = (subchunkHeader0 & 0xFFFFFFu) + uint(channelOffset);\n  highp uint encodingBits = subchunkHeader0 >> 24u;\n  if (encodingBits > 0u) {\n    ivec3 subchunkPosition = chunkPosition - subchunkGridPosition * uSubchunkSize;\n    int subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);\n    uint encodedValueBaseOffset = subchunkHeader1 + uint(channelOffset);\n    uint encodedValueOffset = encodedValueBaseOffset + uint(subchunkOffset) * encodingBits / 32u;\n    uint encodedValue = ${r("readTextureValue")}(encodedValueOffset).value;\n    uint wordOffset = uint(subchunkOffset) * encodingBits % 32u;\n    uint encodedValueShifted = encodedValue >> wordOffset;\n    uint decodedValue = encodedValueShifted - (encodedValueShifted >> encodingBits << encodingBits);\n    outputValueOffset += decodedValue * ${this.dataType===li.a.UINT64?"2u":"1u"};\n  }\n  ${o} result;\n`,s===li.a.UINT64?a+=`\n  result.value[0] = ${r("readTextureValue")}(outputValueOffset).value;\n  result.value[1] = ${r("readTextureValue")}(outputValueOffset+1u).value;\n`:a+=`\n  result.value = ${r("readTextureValue")}(outputValueOffset).value;\n`,a+="\n  return result;\n}\n",e.addFragmentCode(a)}setupTextureLayout(e,t,n,i,r,s){const{subchunkGridSize:o}=n;e.uniform3i(t.uniform("uSubchunkGridSize"),o[0],o[1],o[2]);const a=Ci,c=s.length;a.fill(0);for(let e=0;e<3;++e){a[e]=i[e];const t=r[e];-1!==t&&(a[4*(e+1)+t]=1)}for(let e=0;e<c;++e){const t=s[e];-1!==t&&(a[4*(4+e)+t]=1)}e.uniform4iv(t.uniform("uVolumeChunkStrides"),a,0,4*(c+4))}setTextureData(e,t,n){Object(hi.f)(e,xi,n)}getTextureLayout(e,t){return wi.get(e,t,this.subchunkSize)}beginSource(e,t){super.beginSource(e,t);const{subchunkSize:n}=this;e.uniform3i(t.uniform("uSubchunkSize"),n[0],n[1],n[2])}}class ki extends ci{setTextureData(e){let{data:t}=this,{chunkFormat:n}=this,i=this.textureLayout=n.getTextureLayout(e,this.chunkDataSize);n.setTextureData(e,i,t)}getValueAt(e){let{chunkDataSize:t,chunkFormat:n}=this,{data:i}=this,r=i[e[3]||0];if(n.dataType===li.a.UINT64){let s=new di.a;return Si(s,i,r,t,n.subchunkSize,e),s}return yi(i,r,t,n.subchunkSize,e)}}class Ei extends o.a{constructor(e,t){super();let{dataType:n}=t;if(n!==li.a.UINT64&&n!==li.a.UINT32)throw new Error(`Unsupported compressed segmentation data type: ${li.a[n]}`);this.chunkFormat=this.registerDisposer(Oi.get(e,t.dataType,t.compressedSegmentationBlockSize,t.chunkDataSize[3]||1))}getChunk(e,t){return new ki(e,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 Ti(e){return Object(o.e)(document,"contextmenu",e=>{e.preventDefault()}),Object(o.e)(document,"wheel",e=>{e.ctrlKey&&e.preventDefault()},{passive:!1}),
/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @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(e,t=document.getElementById("neuroglancer-container")){try{let n=new _(t);return new Wn(n,e)}catch(e){throw It.a.showMessage(`Error: ${e.message}`),e}}(e)}Object(ii.e)((e,t)=>null!=t.compressedSegmentationBlockSize?new Ei(e,t):null);var Mi=n(22);
/**
 * @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 extends o.a{constructor(e,t=200){super(),this.root=e,this.parseError=new f.e(void 0),this.registerEventListener(window,"hashchange",()=>this.updateFromUrlHash());const n=r()(()=>this.setUrlHash(),t);this.registerDisposer(e.changed.add(n)),this.registerDisposer(()=>n.cancel())}setUrlHash(){const e=Object(m.c)(this.root),{generation:t}=e;if(t!==this.prevStateGeneration){this.prevStateGeneration=e.generation;let t=(n=JSON.stringify(e.value),encodeURI(n).replace(/[!'()*;,]/g,(function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})));t!==this.prevStateString&&(this.prevStateString=t,"{}"===decodeURIComponent(t)?history.replaceState(null,"","#"):history.replaceState(null,"","#!"+t))}var n}updateFromUrlHash(){try{let e=location.href.replace(/^[^#]+/,"");if(""!==e&&"#"!==e&&"#!"!==e||(e="#!{}"),e.match(/^#!(http|https|gs):\/\//)){const t=e.substring(2),n=Object(Mi.d)(t);It.a.forPromise(Object(Mi.c)(n).then(e=>e.json()).then(e=>{Object(g.w)(e),this.root.reset(),this.root.restoreState(e)}),{initialMessage:`Loading state from ${t}`,errorPrefix:"Error loading state:"})}else if(e.startsWith("#!+")){e=e.slice(3),e=decodeURIComponent(e);let t=Object(g.j)(e);Object(g.w)(t),this.root.restoreState(t),this.prevStateString=void 0}else{if(!e.startsWith("#!"))throw new Error('URL hash is expected to be of the form "#!{...}" or "#!+{...}".');{if(e=e.slice(2),e=decodeURIComponent(e),e===this.prevStateString)return;this.prevStateString=e,this.root.reset();let t=Object(g.j)(e);Object(g.w)(t),this.root.restoreState(t)}}this.parseError.value=void 0}catch(e){this.parseError.value=e}}}
/**
 * @license
 * Copyright 2016 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */window.addEventListener("DOMContentLoaded",()=>{const e=new m.a,t=new m.a,n=new b;e.add("credentials",n.inputState),t.add("credentials",n.outputState);const i=Object(h.a)({credentialsManager:new u(n)}),s=new p.PythonDataSource;i.register("python",s),e.add("sourceGenerations",function(e){const t=new f.c({},e=>{for(const t of Object.keys(e)){const n=e[t];if("number"!=typeof n)throw new Error(`Expected key ${JSON.stringify(t)} to have a numeric value, but received: ${JSON.stringify(n)}.`)}return e});return t.changed.add(r()(()=>{const n=t.value;for(const t of Object.keys(n))e.setSourceGeneration(t,n[t]);for(const t of e.sourceGenerations.keys())n.hasOwnProperty(t)||e.deleteSourceGeneration(t)},0)),t}(s));let o=window.viewer=Ti({showLayerDialog:!1,resetStateWhenEmpty:!1,dataSourceProvider:i});Object(ni.b)(o.inputEventBindings),e.add("inputEventBindings",function(e){const t=new m.a,n=new w;t.add("viewer",n),e.global.addParent(n.eventActionMap,1e3);const i=new w;t.add("sliceView",i),e.sliceView.addParent(i.eventActionMap,1e3);const r=new w;t.add("perspectiveView",r),e.perspectiveView.addParent(r.eventActionMap,1e3);const s=new w;return t.add("dataView",s),e.perspectiveView.addParent(s.eventActionMap,999),e.sliceView.addParent(s.eventActionMap,999),t}(o.inputEventBindings));const a=new Jn(o);window.remoteActionHandler=a,e.add("actions",a.actionSet),e.add("statusMessages",new qn);const c=new Yn(o);e.add("screenshot",c.requestState);let l=o.state;if(window.location.hash){o.registerDisposer(new Di(o.state)).updateFromUrlHash(),l=void 0}const d=new Hn(o.display,i,o.dataContext.addRef(),o.uiConfiguration);e.add("prefetch",d),e.add("showUIControls",o.uiConfiguration.showUIControls),e.add("showLayerPanel",o.uiConfiguration.showLayerPanel),e.add("showHelpButton",o.uiConfiguration.showHelpButton),e.add("showLocation",o.uiConfiguration.showLocation),e.add("showPanelBorders",o.uiConfiguration.showPanelBorders),e.add("showLayerHoverValues",o.uiConfiguration.showLayerHoverValues),e.add("scaleBarOptions",o.scaleBarOptions);const v=new f.c(void 0,e=>null==e?void 0:Object(g.d)([0,0],e,g.u));e.add("viewerSize",v);const y=()=>{const e=o.display.container,t=v.value;if(void 0===t)e.style.position="relative",e.style.width="",e.style.height="",e.style.transform="",e.style.transformOrigin="";else{e.style.position="absolute",e.style.width=`${t[0]}px`,e.style.height=`${t[1]}px`;const n=document.documentElement.clientWidth,i=document.documentElement.clientHeight,r=n/t[0],s=i/t[1],o=Math.min(r,s);e.style.transform=`scale(${o})`,e.style.transformOrigin="top left"}};y(),window.addEventListener("resize",y),v.changed.add(r()(()=>y(),0));const S=new ei(l,t,e);a.sendActionRequested.add((e,t)=>S.sendActionNotification(e,t)),c.sendScreenshotRequested.add(e=>S.sendActionNotification("screenshot",e)),function(e){e.registerEventListener(document,"copy",t=>{if(Object(Pe.a)(t.target))return;const n=document.getSelection();if(null!==n&&"Range"===n.type)return;const i=Object(m.c)(e.state).value,{clipboardData:r}=t;null!==r&&r.setData("text/plain",JSON.stringify(i,void 0,"  ")),t.preventDefault()})}(o),ti(o)})},function(e,t,n){"use strict";n.r(t);n(205);var i,r=n(5),s=n(23),o=n(67),a=n(38),c=n(28),l=n(9),d=n(25),u=n(136),h=n(106);!function(e){e[e.DEFAULT=0]="DEFAULT",e[e.ADDITIVE=1]="ADDITIVE"}(i||(i={}));const p=new Map([[i.DEFAULT,e=>{e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)}],[i.ADDITIVE,e=>{e.blendFunc(e.SRC_ALPHA,e.ONE)}]]);var f=n(4),m=n(86),g=n(32),v=n(41);
/**
 * @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 b="void main() {\n  emitGrayscale(toNormalized(getDataValue()));\n}\n";class y extends u.a{constructor(e,t){const{opacity:n,blendMode:i,shaderControlState:r}=t;super(e,Object.assign(Object.assign({},t),{fallbackShaderParameters:new f.e(Object(v.c)(b)),encodeShaderParameters:e=>e.source,shaderParameters:r.parseResult})),this.shaderControlState=r,this.opacity=n,this.blendMode=i,this.registerDisposer(n.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(i.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(r.changed.add(this.redrawNeeded.dispatch))}defineShader(e,t){if(0!==t.errors.length)throw new Error("Invalid UI control specification");e.addUniform("highp float","uOpacity"),e.addFragmentCode("\n\n#define VOLUME_RENDERING false\n\nvoid emitRGBA(vec4 rgba) {\n  emit(vec4(rgba.rgb, rgba.a * uOpacity));\n}\nvoid emitRGB(vec3 rgb) {\n  emit(vec4(rgb, uOpacity));\n}\nvoid emitGrayscale(float value) {\n  emit(vec4(value, value, value, uOpacity));\n}\nvoid emitTransparent() {\n  emit(vec4(0.0, 0.0, 0.0, 0.0));\n}\n"),e.addFragmentCode(m.a),Object(v.b)(t.controls,e),e.setFragmentMainFunction(Object(g.e)(t.code))}initializeShader(e,t,n){const{gl:i}=this;i.uniform1f(t.uniform("uOpacity"),this.opacity.value),Object(v.d)(i,t,this.shaderControlState,n.controls)}setGLBlendMode(e,t){const n=this.blendMode.value;(n===i.ADDITIVE||t>0)&&(e.enable(e.BLEND),p.get(n)(e))}}var S=n(108),w=n(17),x=n(115),C=n(66),O=n(127),k=n(0),E=n(10),T=n(12),M=n(71),D=n(58),L=n(26),j=n(56),I=n(1),P=n(45);
/**
 * @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 A=I.k.create();function R(e,t,n,i,r,s){if(0===i.length)return;const{viewMatrix:o,projectionMat:a,displayDimensionRenderInfo:c}=e,{voxelPhysicalScales:l}=c,d=Object(I.n)(l),u=(Object(I.d)(a)/64)**3,h=I.k.determinant(Object(I.l)(A,o)),p=e=>i[e].chunkLayout.detTransform*h;let f=i.length-1,m=p(f);for(let e=f-1;e>=0;--e){const t=p(e);if(!(Math.abs(t-u)<Math.abs(m-u)))break;m=t,f=e}const g=Math.pow(m*d/h,1/3),v=Math.pow(m,1/3)*e.width/(2*a[0]);let b=!0;const y=i[f];Object(L.l)(e,t,y,(e,t)=>{b&&(r(y,f,g,v,t),b=!1),s(y,f,e)})}var N=n(80),V=n(49);
/**
 * @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 _=I.m.create(),B=new Float32Array(24);class F extends M.a{constructor(e){super(),this.multiscaleSource=e.multiscaleSource,this.transform=e.transform,this.channelCoordinateSpace=e.channelCoordinateSpace,this.shaderControlState=e.shaderControlState,this.localPosition=e.localPosition,this.renderScaleTarget=e.renderScaleTarget,this.renderScaleHistogram=e.renderScaleHistogram,this.registerDisposer(this.renderScaleHistogram.visibility.add(this.visibility));const t=this.registerDisposer(Object(f.g)(e=>e.rank,[this.channelCoordinateSpace]));this.shaderGetter=Object(g.c)(this,this.gl,{memoizeKey:"VolumeRenderingRenderLayer",parameters:e.shaderControlState.parseResult,getContextKey:({emitter:e,chunkFormat:t})=>`${Object(P.a)(e)}:${t.shaderKey}`,shaderError:e.shaderError,extraParameters:t,defineShader:(e,{emitter:t,chunkFormat:n},i,r)=>{Object(V.b)(e),e.addFragmentCode("\n#define VOLUME_RENDERING true\n"),t(e),e.addUniform("highp float","uNearLimitFraction"),e.addUniform("highp float","uFarLimitFraction"),e.addUniform("highp int","uMaxSteps"),e.addUniform("highp vec3","uTranslation"),e.addUniform("highp mat4","uModelViewProjectionMatrix"),e.addUniform("highp mat4","uInvModelViewProjectionMatrix"),e.addUniform("highp vec3","uChunkDataSize"),e.addUniform("highp vec3","uLowerClipBound"),e.addUniform("highp vec3","uUpperClipBound"),e.addUniform("highp float","uBrightnessFactor"),e.addVarying("highp vec4","vNormalizedPosition"),e.addVertexCode(N.d),e.setVertexMain("\nvec3 boxVertex = getBoxFaceVertexPosition(gl_VertexID);\nvec3 position = max(uLowerClipBound, min(uUpperClipBound, uTranslation + boxVertex * uChunkDataSize));\nvNormalizedPosition = gl_Position = uModelViewProjectionMatrix * vec4(position, 1.0);\ngl_Position.z = 0.0;\n"),e.addFragmentCode("\nvec3 curChunkPosition;\nvec4 outputColor;\nvoid userMain();\n"),Object(d.d)(e,n,r,"curChunkPosition"),e.addFragmentCode("\nvoid emitRGBA(vec4 rgba) {\n  float alpha = rgba.a * uBrightnessFactor;\n  outputColor += vec4(rgba.rgb * alpha, alpha);\n}\nvoid emitRGB(vec3 rgb) {\n  emitRGBA(vec4(rgb, 1.0));\n}\nvoid emitGrayscale(float value) {\n  emitRGB(vec3(value, value, value));\n}\nvoid emitTransparent() {\n  emitRGBA(vec4(0.0, 0.0, 0.0, 0.0));\n}\n"),e.setFragmentMainFunction("\nvoid main() {\n  vec2 normalizedPosition = vNormalizedPosition.xy / vNormalizedPosition.w;\n  vec4 nearPointH = uInvModelViewProjectionMatrix * vec4(normalizedPosition, -1.0, 1.0);\n  vec4 farPointH = uInvModelViewProjectionMatrix * vec4(normalizedPosition, 1.0, 1.0);\n  vec3 nearPoint = nearPointH.xyz / nearPointH.w;\n  vec3 farPoint = farPointH.xyz / farPointH.w;\n  vec3 rayVector = farPoint - nearPoint;\n  vec3 boxStart = max(uLowerClipBound, uTranslation);\n  vec3 boxEnd = min(boxStart + uChunkDataSize, uUpperClipBound);\n  float intersectStart = uNearLimitFraction;\n  float intersectEnd = uFarLimitFraction;\n  for (int i = 0; i < 3; ++i) {\n    float startPt = nearPoint[i];\n    float endPt = farPoint[i];\n    float boxLower = boxStart[i];\n    float boxUpper = boxEnd[i];\n    float r = rayVector[i];\n    float startFraction;\n    float endFraction;\n    if (startPt >= boxLower && startPt <= boxUpper) {\n      startFraction = 0.0;\n    } else {\n      startFraction = min((boxLower - startPt) / r, (boxUpper - startPt) / r);\n    }\n    if (endPt >= boxLower && endPt <= boxUpper) {\n      endFraction = 1.0;\n    } else {\n      endFraction = max((boxLower - startPt) / r, (boxUpper - startPt) / r);\n    }\n    intersectStart = max(intersectStart, startFraction);\n    intersectEnd = min(intersectEnd, endFraction);\n  }\n  float stepSize = (uFarLimitFraction - uNearLimitFraction) / float(uMaxSteps - 1);\n  int startStep = int(floor((intersectStart - uNearLimitFraction) / stepSize));\n  int endStep = min(uMaxSteps, int(floor((intersectEnd - uNearLimitFraction) / stepSize)) + 1);\n  outputColor = vec4(0, 0, 0, 0);\n  for (int step = startStep; step < endStep; ++step) {\n    vec3 position = mix(nearPoint, farPoint, uNearLimitFraction + float(step) * stepSize);\n    curChunkPosition = position - uTranslation;\n    userMain();\n  }\n  emit(outputColor, 0u);\n}\n"),e.addFragmentCode(m.a),Object(v.b)(i.controls,e),e.addFragmentCode("\n#define main userMain\n"+Object(g.e)(i.code)+"\n#undef main\n")}}),this.vertexIdHelper=this.registerDisposer(V.a.get(this.gl)),this.registerDisposer(this.renderScaleTarget.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.shaderControlState.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.localPosition.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.transform.changed.add(this.redrawNeeded.dispatch)),this.registerDisposer(this.shaderControlState.fragmentMain.changed.add(this.redrawNeeded.dispatch));const{chunkManager:n}=this.multiscaleSource,i=this.registerDisposer(new T.e(this.layerChunkProgressInfo)),r=n.rpc;i.RPC_TYPE_ID="volume_rendering/VolumeRenderingRenderLayer",i.initializeCounterpart(r,{chunkManager:n.rpcId,localPosition:this.registerDisposer(D.a.makeFromExisting(r,this.localPosition)).rpcId,renderScaleTarget:this.registerDisposer(D.a.makeFromExisting(r,this.renderScaleTarget)).rpcId}),this.backend=i}get gl(){return this.multiscaleSource.chunkManager.gl}get isTransparent(){return!0}get isVolumeRendering(){return!0}get dataType(){return this.multiscaleSource.dataType}attach(e){super.attach(e),e.state={sources:e.registerDisposer(Object(f.k)((t,n,i)=>{const r=Object(j.f)(i,n,e=>this.multiscaleSource.getSources(e),e.messages,this);for(const e of r)for(const n of e)t.registerDisposer(n.source);return e.view.flushBackendProjectionParameters(),this.backend.rpc.invoke("volume_rendering/VolumeRenderingRenderLayer/update",{layer:this.backend.rpcId,view:e.view.rpcId,sources:Object(j.g)(r)}),this.redrawNeeded.dispatch(),r},this.transform,e.view.displayDimensionRenderInfo))}}get chunkManager(){return this.multiscaleSource.chunkManager}draw(e,t){if(!e.emitColor)return;const n=t.state.sources.value;if(0===n.length)return;let i,r,s=0,o=0,a=null;const c=I.u.create(),{gl:l}=this;this.vertexIdHelper.enable();const{renderScaleHistogram:d}=this;d.begin(this.chunkManager.chunkQueueManager.frameNumberCounter.frameNumber);const u=()=>{null!==a&&(null!==i&&i.endDrawing(l,a),0===g&&0===b||d.add(s,o,g,b))};let h=!0;const{projectionParameters:p}=e;let f,m,g=0,b=0;const y=this.multiscaleSource.rank,S=I.u.create();l.enable(WebGL2RenderingContext.CULL_FACE),l.cullFace(WebGL2RenderingContext.FRONT),R(e.projectionParameters,this.localPosition.value,this.renderScaleTarget.value,n[0],(t,n,d,h)=>{s=d,o=h;const g=Object(L.o)(p,t.chunkLayout),b=t.source,{fixedPositionWithinChunk:y,chunkDisplayDimensionIndices:S}=t;for(const e of S)y[e]=0;const w=b.chunkFormat;if(w!==i&&(i=w,u(),r=this.shaderGetter({emitter:e.emitter,chunkFormat:w}),a=r.shader,null!==a&&(a.bind(),null!==w&&(Object(v.d)(l,a,this.shaderControlState,r.parameters.controls),w.beginDrawing(l,a),w.beginSource(l,a)))),m=void 0,null===a)return;f=b.chunks,c.fill(1);const x=I.m.multiply(_,p.viewProjectionMat,g.transform);l.uniformMatrix4fv(a.uniform("uModelViewProjectionMatrix"),!1,x);const C=B;Object(I.c)(C,x),I.m.invert(x,x),l.uniformMatrix4fv(a.uniform("uInvModelViewProjectionMatrix"),!1,x);const{near:O,far:k,adjustedNear:E,adjustedFar:T}=function(e,t,n){let i=0,r=0;for(let s=0;s<3;++s){const o=e[16+s],a=o*t[s],c=o*n[s];i+=Math.min(a,c),r+=Math.max(a,c)}const s=-e[19],o=Math.max(s,i),a=e[23];return{near:s,far:a,adjustedNear:o,adjustedFar:Math.min(a,r)}}(C,t.lowerClipDisplayBound,t.upperClipDisplayBound),M=(T-E)/63/(k-O);l.uniform1f(a.uniform("uBrightnessFactor"),M);const D=(E-O)/(k-O),j=(T-O)/(k-O);l.uniform1f(a.uniform("uNearLimitFraction"),D),l.uniform1f(a.uniform("uFarLimitFraction"),j),l.uniform1i(a.uniform("uMaxSteps"),64),l.uniform3fv(a.uniform("uLowerClipBound"),t.lowerClipDisplayBound),l.uniform3fv(a.uniform("uUpperClipBound"),t.upperClipDisplayBound)},e=>{if(null===a)return;const t=e.curPositionInChunks.join(),n=f.get(t);if(void 0!==n&&n.state===E.h.GPU_MEMORY){const t=e.chunkLayout.size;let r=n.chunkDataSize;const{chunkDisplayDimensionIndices:s,fixedPositionWithinChunk:o,chunkTransform:{channelToChunkDimensionIndices:d}}=e,{}=e;if(r!==m){m=r;for(let e=0;e<3;++e){const t=s[e];c[e]=-1===t||t>=y?1:m[t]}l.uniform3fv(a.uniform("uChunkDataSize"),c)}const{chunkGridPosition:u}=n;for(let e=0;e<3;++e){const n=s[e];S[e]=-1===n||n>=y?0:t[e]*u[n]}null!=i&&i.bindChunk(l,a,n,o,s,d,h),h=!1,l.uniform3fv(a.uniform("uTranslation"),S),Object(N.c)(l,1,1),++g}else++b}),l.disable(WebGL2RenderingContext.CULL_FACE),u(),this.vertexIdHelper.disable()}isReady(e,t){const n=t.state.sources.value;if(0===n.length)return!0;let i=!1;return R(e.projectionParameters,this.localPosition.value,this.renderScaleTarget.value,n[0],()=>{},e=>{const t=e.source.chunks.get(e.curPositionInChunks.join());void 0!==t&&t.state===E.h.GPU_MEMORY||(i=!0)}),i}}n(213);var z=n(30),U=n(7),G=n(2),$=n(6),W=n(11);
/**
 * @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 H=n(51).a.fromObject({arrowup:{action:"tab-backward"},arrowdown:{action:"tab-forward"},tab:{action:"tab-forward"},"shift+tab":{action:"tab-backward"},enter:{action:"commit"},escape:{action:"cancel"}});class J{constructor(e){this.id=e,this.element=document.createElement("div"),this.nameContainer=document.createElement("div"),this.nameElement=document.createElement("input"),this.lowerElement=document.createElement("div"),this.upperElement=document.createElement("div");const{element:t,nameContainer:n,nameElement:i,lowerElement:r,upperElement:s}=this;t.classList.add("neuroglancer-channel-dimensions-widget-dim"),n.classList.add("neuroglancer-channel-dimensions-widget-name-container"),i.classList.add("neuroglancer-channel-dimensions-widget-name"),n.appendChild(i),r.classList.add("neuroglancer-channel-dimensions-widget-lower"),s.classList.add("neuroglancer-channel-dimensions-widget-upper"),t.appendChild(n),t.appendChild(r),t.appendChild(s),n.draggable=!0,i.disabled=!0,i.spellcheck=!1,i.autocomplete="off",i.required=!0,i.placeholder=" ",n.title="Drag to reorder, double click to rename.  Names ending in ' or ^ indicate dimensions local to the layer; names ending in ^ indicate channel dimensions (image layers only).",n.addEventListener("dblclick",()=>{i.disabled=!1,i.focus(),i.select()}),i.addEventListener("focus",()=>{i.select()})}}class q extends G.a{constructor(e){super(),this.combiner=e,this.element=document.createElement("div"),this.dimensionWidgets=[],this.curCoordinateSpace=void 0,this.dragSource=void 0,this.coordinateSpace=this.combiner.combined;const{element:t}=this;t.classList.add("neuroglancer-channel-dimensions-widget");const n=this.registerCancellable(Object(z.a)(()=>this.updateView()));this.registerDisposer(e.combined.changed.add(n)),this.registerDisposer(new W.b(t,H)).allShortcutsAreGlobal=!0,this.registerDisposer(Object(W.c)(t,"cancel",e=>{this.forceUpdateView();const{target:t}=e;t instanceof HTMLElement&&t.blur()})),this.updateView()}reorderDimensionTo(e,t){if(e===t)return;const{coordinateSpace:n}=this;n.value=Object(r.t)(n.value,e,t)}makeNewDimensionWidget(e){const t=new J(e);return t.nameContainer.addEventListener("dragstart",e=>{this.dragSource=t,e.stopPropagation(),e.dataTransfer.setData("neuroglancer-dimension","")}),t.nameContainer.addEventListener("dragenter",e=>{const{dragSource:n}=this;if(void 0===n||n===t)return;const{dimensionWidgets:i}=this,r=i.indexOf(n),s=i.indexOf(t);-1!==r&&-1!==s&&(e.preventDefault(),this.reorderDimensionTo(s,r))}),t.nameContainer.addEventListener("dragend",e=>{this.dragSource===t&&(this.dragSource=void 0)}),t.nameElement.addEventListener("blur",e=>{t.nameElement.disabled=!0;const{relatedTarget:n}=e;this.dimensionWidgets.some(e=>e.nameElement===n)||this.updateNames()||this.forceUpdateView()}),t.nameElement.addEventListener("input",()=>{const{nameElement:e}=t;Object($.e)(e),this.updateNameValidity()}),Object(W.c)(t.nameElement,"commit",()=>{this.updateNames()}),Object(W.c)(t.nameElement,"tab-forward",e=>this.selectAdjacentField(e,t,1)),Object(W.c)(t.nameElement,"tab-backward",e=>this.selectAdjacentField(e,t,-1)),t}selectAdjacentField(e,t,n){e.stopPropagation();const{dimensionWidgets:i}=this,r=i.indexOf(t);if(-1===r)return;const s=r+n;if(s<0||s>=i.length)return;const o=i[s];o.nameElement.disabled=!1,o.nameElement.focus(),e.preventDefault()}updateNames(){const{dimensionWidgets:e,coordinateSpace:t}=this,n=t.value,i=e.map(e=>e.nameElement.value);if(this.combiner.getRenameValidity(i).includes(!1))return!1;const r=n.names;if(Object(U.a)(r,i))return!1;const s=n.timestamps.map((e,t)=>r[t]===i[t]?e:Date.now()),o=Object.assign(Object.assign({},n),{names:i,timestamps:s});return t.value=o,!0}updateNameValidity(){const{dimensionWidgets:e}=this,t=e.map(e=>e.nameElement.value),n=t.length,i=this.combiner.getRenameValidity(t);for(let t=0;t<n;++t)e[t].nameElement.dataset.isValid=!1===i[t]?"false":"true"}forceUpdateView(){this.curCoordinateSpace=void 0,this.updateView()}updateView(){const{coordinateSpace:{value:e}}=this;if(this.curCoordinateSpace===e)return;this.curCoordinateSpace=e;const{element:t}=this,n=this.dimensionWidgets,i=this.dimensionWidgets=e.ids.map(e=>n.find(t=>t.id===e)||this.makeNewDimensionWidget(e));Object($.d)(t,function*(){const{names:t,rank:n,bounds:{lowerBounds:r,upperBounds:s}}=e;for(let e=0;e<n;++e){const n=i[e];n.nameElement.value=t[e],delete n.nameElement.dataset.isValid,Object($.e)(n.nameElement),n.lowerElement.textContent=r[e].toString(),n.upperElement.textContent=s[e].toString(),yield n.element}}.call(this))}}var Y=n(62),X=n(63),K=n(114),Q=n(95),Z=n(96),ee=n(77),te=n(88),ne=n(97),ie=n(98),re=n(48);n.d(t,"ImageUserLayer",(function(){return oe}));
/**
 * @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 se=Object(x.a)(s.k);class oe extends se{constructor(e,t){super(e,t),this.opacity=Object(S.a)(.5),this.blendMode=function(e=i.DEFAULT){return new h.a(i,e)}(),this.fragmentMain=function(e=b){return Object(g.a)(e)}(),this.shaderError=Object(g.b)(),this.shaderControlState=new v.a(this.fragmentMain),this.sliceViewRenderScaleHistogram=new c.a,this.sliceViewRenderScaleTarget=Object(c.e)(1),this.volumeRenderingRenderScaleHistogram=new c.a,this.volumeRenderingRenderScaleTarget=Object(c.e)(1),this.channelCoordinateSpace=new r.b,this.channelCoordinateSpaceCombiner=new r.a(this.channelCoordinateSpace,r.u),this.channelSpace=this.registerDisposer(Object(f.h)(e=>Object(O.a)(()=>Object(a.c)(e)),this.channelCoordinateSpace)),this.volumeRendering=new w.b(!1,!1),this.localCoordinateSpaceCombiner.includeDimensionPredicate=r.w,this.blendMode.changed.add(this.specificationChanged.dispatch),this.opacity.changed.add(this.specificationChanged.dispatch),this.fragmentMain.changed.add(this.specificationChanged.dispatch),this.shaderControlState.changed.add(this.specificationChanged.dispatch),this.sliceViewRenderScaleTarget.changed.add(this.specificationChanged.dispatch),this.volumeRendering.changed.add(this.specificationChanged.dispatch),this.tabs.add("rendering",{label:"Rendering",order:-100,getter:()=>new ce(this)}),this.tabs.default="rendering"}markLoading(){const e=super.markLoading(),t=this.channelCoordinateSpaceCombiner.retain();return()=>{e(),t()}}addCoordinateSpace(e){const t=super.addCoordinateSpace(e),n=this.channelCoordinateSpaceCombiner.bind(e);return()=>{t(),n()}}activateDataSubsources(e){let t;for(const n of e){if(this.addStaticAnnotations(n))continue;const{subsourceEntry:e}=n,{subsource:i}=e,{volume:r}=i;r instanceof d.a?t&&r.dataType!==t?n.deactivate(`Data type must be ${l.a[r.dataType].toLowerCase()}`):(t=r.dataType,n.activate(e=>{n.addRenderLayer(new y(r,{opacity:this.opacity,blendMode:this.blendMode,shaderControlState:this.shaderControlState,shaderError:this.shaderError,transform:n.getRenderLayerTransform(this.channelCoordinateSpace),renderScaleTarget:this.sliceViewRenderScaleTarget,renderScaleHistogram:this.sliceViewRenderScaleHistogram,localPosition:this.localPosition,channelCoordinateSpace:this.channelCoordinateSpace}));const t=e.registerDisposer(new F({multiscaleSource:r,shaderControlState:this.shaderControlState,shaderError:this.shaderError,transform:n.getRenderLayerTransform(this.channelCoordinateSpace),renderScaleTarget:this.volumeRenderingRenderScaleTarget,renderScaleHistogram:this.volumeRenderingRenderScaleHistogram,localPosition:this.localPosition,channelCoordinateSpace:this.channelCoordinateSpace}));e.registerDisposer(n.messages.addChild(t.messages)),e.registerDisposer(Object(f.k)((e,n)=>{n&&e.registerDisposer(this.addRenderLayer(t.addRef()))},this.volumeRendering)),this.shaderError.changed.dispatch()})):n.deactivate("Not compatible with image layer")}}restoreState(e){super.restoreState(e),this.opacity.restoreState(e.opacity),Object(k.B)(e,"blend",e=>this.blendMode.restoreState(e)),this.fragmentMain.restoreState(e.shader),this.shaderControlState.restoreState(e.shaderControls),this.sliceViewRenderScaleTarget.restoreState(e.crossSectionRenderScale),this.channelCoordinateSpace.restoreState(e.channelDimensions),this.volumeRendering.restoreState(e.volumeRendering)}toJSON(){const e=super.toJSON();return e.opacity=this.opacity.toJSON(),e.blend=this.blendMode.toJSON(),e.shader=this.fragmentMain.toJSON(),e.shaderControls=this.shaderControlState.toJSON(),e.crossSectionRenderScale=this.sliceViewRenderScaleTarget.toJSON(),e.channelDimensions=this.channelCoordinateSpace.toJSON(),e.volumeRendering=this.volumeRendering.toJSON(),e}displayImageSelectionState(e,t){const{value:n}=e;if(null==n)return!1;const i=this.channelSpace.value;if(void 0!==i.error)return!1;const{numChannels:r,coordinates:s,channelCoordinateSpace:{names:o,rank:a}}=i,c=document.createElement("div");c.classList.add("neuroglancer-selection-details-value-grid");let l="[copy] 0fr ";0!==a&&(l+=`repeat(${a}, [dim] 0fr [coord] 0fr) `),l+="[value] 1fr",c.style.gridTemplateColumns=l;for(let e=0;e<r;++e){const t=(0===a?n:n[e]).toString(),i=Object(Y.a)({title:"Copy value",onClick:()=>{Object(C.a)(t)}});c.appendChild(i);for(let t=0;t<a;++t){const n=document.createElement("div");n.classList.add("neuroglancer-selection-details-value-grid-dim"),n.textContent=o[t],c.appendChild(n);const i=document.createElement("div");i.classList.add("neuroglancer-selection-details-value-grid-coord"),i.textContent=s[e*a+t].toString(),c.appendChild(i)}const r=document.createElement("div");r.classList.add("neuroglancer-selection-details-value-grid-value"),r.textContent=t,c.appendChild(r)}return t.appendChild(c),!0}displaySelectionState(e,t,n){let i=this.displayImageSelectionState(e,t);return super.displaySelectionState(e,t,n)&&(i=!0),i}}function ae(e){return new ne.a({shaderError:e.shaderError,fragmentMain:e.fragmentMain,shaderControlState:e.shaderControlState})}oe.type="image";class ce extends re.b{constructor(e){super(),this.layer=e,this.opacityWidget=this.registerDisposer(new ee.a(this.layer.opacity)),this.codeWidget=this.registerDisposer(ae(this.layer));const{element:t}=this;t.classList.add("neuroglancer-image-dropdown");let{opacityWidget:n}=this,i=document.createElement("div");i.className="neuroglancer-image-dropdown-top-row",n.promptElement.textContent="Opacity";{const e=this.registerDisposer(new te.a(this.layer.sliceViewRenderScaleHistogram,this.layer.sliceViewRenderScaleTarget));e.label.textContent="Resolution (slice)",t.appendChild(e.element)}{const n=document.createElement("label");n.textContent="Blending",n.appendChild(this.registerDisposer(new K.a(e.blendMode)).element),t.appendChild(n)}{const n=this.registerDisposer(new w.c(e.volumeRendering));n.element.className="neuroglancer-noselect";const i=document.createElement("label");i.className="neuroglancer-noselect",i.appendChild(document.createTextNode("Volume rendering (experimental)")),i.appendChild(n.element),t.appendChild(i)}const r=this.registerDisposer(new X.a(e.volumeRendering,(e,t,n)=>{if(e){const e=n.registerDisposer(new te.a(this.layer.volumeRenderingRenderScaleHistogram,this.layer.volumeRenderingRenderScaleTarget));e.label.textContent="Resolution (3d)",t.appendChild(e.element)}},this.visibility));t.appendChild(r.element);let s=document.createElement("div");s.style.flex="1",i.appendChild(this.opacityWidget.element),i.appendChild(s),i.appendChild(Object(Z.a)({title:"Show larger editor view",onClick:()=>{new le(this.layer)}})),i.appendChild(Object(Q.a)({title:"Documentation on image layer rendering",href:"https://github.com/google/neuroglancer/blob/master/src/neuroglancer/sliceview/image_layer_rendering.md"})),t.appendChild(i),t.appendChild(this.registerDisposer(new q(e.channelCoordinateSpaceCombiner)).element),t.appendChild(this.codeWidget.element),t.appendChild(this.registerDisposer(new ie.a(e.shaderControlState)).element)}}class le extends o.a{constructor(e){super(),this.layer=e,this.codeWidget=this.registerDisposer(ae(this.layer)),this.content.classList.add("neuroglancer-image-layer-shader-overlay"),this.content.appendChild(this.codeWidget.element),this.codeWidget.textEditor.refresh()}}Object(s.r)("image",oe),Object(s.t)(l.b.IMAGE,oe)},function(e,t,n){"use strict";n.r(t);n(222);var i=n(8),r=n(118),s=n(61),o=n(5),a=n(34),c=n(23),l=n(67),d=n(38),u=n(36),h=n(140),p=n(17),f=n(4),m=n(115),g=n(30),v=n(2),b=n(6),y=n(0),S=n(3),w=n(63),x=n(95),C=n(15),O=n.n(C);
/**
 * @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 k extends v.a{constructor(e){super(),this.ref=e,this.element=document.createElement("label"),this.selectElement=document.createElement("select"),this.registerDisposer(e);const{element:t,selectElement:n}=this;t.appendChild(n),this.updateView(),this.registerEventListener(n,"change",()=>this.updateModel()),this.registerDisposer(this.ref.changed.add(O()(()=>this.updateView(),0)))}updateModel(){this.ref.layerName=this.selectElement.value||void 0}updateView(){const{selectElement:e,ref:t}=this,{filter:n}=t;Object(b.b)(e);const i=document.createElement("option");e.appendChild(i);for(const t of this.ref.layerManager.managedLayers)if(n(t)){const n=document.createElement("option"),{name:i}=t;n.textContent=i,n.value=i,e.appendChild(n)}e.value=t.layerName||""}}var E=n(96),T=n(88),M=n(97),D=n(98),L=n(48);n.d(t,"AnnotationUserLayer",(function(){return N}));function j(e){const t=e.layer;return null===t||t instanceof h.SegmentationUserLayer}class I extends v.a{constructor(e,t,n){super(),this.layerManager=e,this.annotationStates=t,this.annotationDisplayState=n,this.changed=new S.a,this.curGeneration=-1,this.wasLoading=void 0,this.map=new Map,this.registerDisposer(t.changed.add(()=>this.update())),this.registerDisposer(t.isLoadingChanged.add(()=>this.update())),this.update()}update(){const e=this.annotationStates.changed.count,t=this.annotationStates.isLoading;if(this.curGeneration===e&&t===this.wasLoading)return;this.wasLoading=t,this.curGeneration=e;const{map:n}=this;let i=!1;for(const t of this.annotationStates.relationships){let r=n.get(t);void 0===r&&(r=this.addRelationship(t),i=!0),r.seenGeneration=e}if(!t)for(const[t,r]of n)r.seenGeneration!==e&&(n.delete(t),i=!0);i&&this.changed.dispatch()}addRelationship(e){const t=this.annotationDisplayState.relationshipStates.get(e),n=new c.b(this.layerManager.addRef(),j);n.registerDisposer(n.changed.add(()=>{t.segmentationState.value=void 0===n.layerName?void 0:function(e){if(void 0===e)return null;const t=e.layer;return null===t?null:t instanceof h.SegmentationUserLayer?t.displayState:null}(n.layer)}));const{showMatches:i}=t,r={layerRef:n,showMatches:i,seenGeneration:-1};return n.changed.add(this.changed.dispatch),i.changed.add(this.changed.dispatch),this.map.set(e,r),r}get(e){return this.update(),this.map.get(e)}unbind(e){e.layerRef.changed.remove(this.changed.dispatch),e.showMatches.changed.remove(this.changed.dispatch)}reset(){for(const e of this.map.values())e.showMatches.reset()}toJSON(){const{map:e}=this;if(0===e.size)return{};let t=void 0;const n=[];for(const[i,r]of e){r.showMatches.value&&n.push(i);const{layerName:e}=r.layerRef;void 0!==e&&((t=t||{})[i]=e)}return n.sort(),{linkedSegmentationLayer:t,filterBySegmentation:0===n.length?void 0:n}}restoreState(e){const{isLoading:t}=this.annotationStates;Object(y.B)(e,"linkedSegmentationLayer",e=>{"string"==typeof e&&(e={segments:e}),Object(y.w)(e);for(const n of Object.keys(e)){const i=Object(y.E)(e[n]);let r=this.map.get(n);if(void 0===r){if(!t)continue;r=this.addRelationship(n)}r.layerRef.layerName=i}for(const[t,n]of this.map)Object.prototype.hasOwnProperty.call(e,t)||(n.layerRef.layerName=void 0)}),Object(y.B)(e,"filterBySegmentation",e=>{"boolean"==typeof e&&(e=!0===e?["segments"]:[]);for(const n of Object(y.F)(e)){let e=this.map.get(n);if(void 0===e){if(!t)continue;e=this.addRelationship(n)}e.showMatches.value=!0}})}disposed(){const{map:e}=this;for(const t of e.values())this.unbind(t);e.clear(),super.disposed()}}class P extends v.a{constructor(e,t){super(),this.relationship=e,this.state=t,this.element=document.createElement("label"),this.seenGeneration=-1;const{element:n}=this,i=this.registerDisposer(new p.c(t.showMatches)),r=new k(t.layerRef);n.appendChild(i.element),n.appendChild(document.createTextNode(e)),n.appendChild(r.element)}}class A extends v.a{constructor(e){super(),this.linkedSegmentationLayers=e,this.widgets=new Map,this.element=document.createElement("div"),this.element.style.display="contents";const t=this.registerCancellable(Object(g.a)(()=>this.updateView()));this.registerDisposer(this.linkedSegmentationLayers.annotationStates.changed.add(t)),this.updateView()}updateView(){const{linkedSegmentationLayers:e}=this,{annotationStates:t}=e,n=t.changed.count,{widgets:i}=this;for(const[e,t]of i)t.seenGeneration!==n&&(t.dispose(),i.delete(e));Object(b.d)(this.element,function*(){for(const r of t.relationships){let t=i.get(r);void 0===t&&(t=new P(r,e.get(r))),t.seenGeneration=n,yield t.element}}.call(this))}disposed(){super.disposed();for(const e of this.widgets.values())e.dispose()}}const R=Object(m.a)(c.k);class N extends R{constructor(e,t){super(e,t),this.annotationProperties=new f.e(void 0),this.localAnnotationsJson=void 0,this.pointAnnotationsJson=void 0,this.linkedSegmentationLayers=this.registerDisposer(new I(this.manager.rootLayers,this.annotationStates,this.annotationDisplayState)),this.linkedSegmentationLayers.restoreState(t),this.linkedSegmentationLayers.changed.add(this.specificationChanged.dispatch),this.annotationDisplayState.ignoreNullSegmentFilter.changed.add(this.specificationChanged.dispatch),this.annotationCrossSectionRenderScaleTarget.changed.add(this.specificationChanged.dispatch),this.localAnnotationsJson=t.annotations,this.pointAnnotationsJson=t.points,this.annotationCrossSectionRenderScaleTarget.restoreState(t.crossSectionAnnotationSpacing),this.annotationProjectionRenderScaleTarget.restoreState(t.projectionAnnotationSpacing),this.annotationDisplayState.ignoreNullSegmentFilter.restoreState(t.ignoreNullSegmentFilter),this.tabs.add("rendering",{label:"Rendering",order:-100,getter:()=>new B(this)}),this.tabs.default="annotations"}disposed(){const{localAnnotations:e}=this;void 0!==e&&e.dispose(),super.disposed()}restoreState(e){super.restoreState(e),this.annotationDisplayState.shader.restoreState(e.shader),this.annotationDisplayState.shaderControls.restoreState(e.shaderControls)}getLegacyDataSourceSpecifications(e,t,n){if(Object.prototype.hasOwnProperty.call(t,"source"))return super.getLegacyDataSourceSpecifications(e,t,n);const i=Object(y.B)(t,"voxelSize",e=>Object(y.d)(new Float64Array(3),e,e=>Object(y.r)(e)/1e9)),r=["m","m","m"];if(void 0!==i){const e=Object(o.y)({rank:3,units:r,scales:i,names:["x","y","z"]});n=void 0===n?{outputSpace:e,sourceRank:3,transform:void 0,inputSpace:e}:Object.assign(Object.assign({},n),{inputSpace:e})}return[{url:a.e,transform:n,enableDefaultSubsources:!0,subsources:new Map}]}activateDataSubsources(e){let t,n=!1;for(const s of e){const{subsourceEntry:e}=s,{local:o}=e.subsource;if(o===a.c.annotations){if(n){s.deactivate("Only one local annotations source per layer is supported");continue}n=!0,s.activate(t=>{const n=this.localAnnotations=new i.f(s.loadedDataSource.transform);try{n.restoreState(this.localAnnotationsJson)}catch(e){}t.registerDisposer(()=>{n.dispose(),this.localAnnotations=void 0}),t.registerDisposer(this.localAnnotations.changed.add(this.specificationChanged.dispatch));try{o=this.localAnnotations,void 0!==(a=this.pointAnnotationsJson)&&Object(y.b)(a,(e,t)=>{o.add({type:i.e.POINT,id:""+t,point:Object(y.m)(e),properties:[]})})}catch(e){}var o,a;this.pointAnnotationsJson=void 0,this.localAnnotationsJson=void 0;const c=new r.b({localPosition:this.localPosition,transform:t.registerDisposer(Object(d.h)(this.manager.root.coordinateSpace,this.localPosition.coordinateSpace,s.loadedDataSource.transform,void 0)),source:n.addRef(),displayState:this.annotationDisplayState,dataSource:s.loadedDataSource.layerDataSource,subsourceIndex:s.subsourceIndex,subsourceId:e.id,role:u.c.ANNOTATION});this.addAnnotationLayerState(c,s)});continue}const{annotation:c}=e.subsource;if(void 0===c)s.deactivate("Not compatible with annotation layer");else{if(void 0!==t&&Object(y.h)(c.properties)!==Object(y.h)(t)){s.deactivate("Annotation properties are not compatible");continue}t=c.properties,s.activate(()=>{const t=new r.b({localPosition:this.localPosition,transform:s.getRenderLayerTransform(),source:c,displayState:this.annotationDisplayState,dataSource:s.loadedDataSource.layerDataSource,subsourceIndex:s.subsourceIndex,subsourceId:e.id,role:u.c.ANNOTATION});this.addAnnotationLayerState(t,s)})}}const s=this.annotationProperties.value;Object(y.h)(s)!==Object(y.h)(t)&&(this.annotationProperties.value=t)}initializeAnnotationLayerViewTab(e){const t=e.registerDisposer(Object(f.h)(e=>e.some(e=>e.source instanceof s.b),this.annotationStates)),n=e.registerDisposer(new w.a(t,(e,t,n)=>{if(e){{const e=n.registerDisposer(new T.a(this.annotationCrossSectionRenderScaleHistogram,this.annotationCrossSectionRenderScaleTarget));e.label.textContent="Spacing (cross section)",t.appendChild(e.element)}{const e=n.registerDisposer(new T.a(this.annotationProjectionRenderScaleHistogram,this.annotationProjectionRenderScaleTarget));e.label.textContent="Spacing (projection)",t.appendChild(e.element)}}}));e.element.insertBefore(n.element,e.element.firstChild);{const t=e.registerDisposer(new p.c(this.annotationDisplayState.ignoreNullSegmentFilter)),n=document.createElement("label");n.appendChild(document.createTextNode("Ignore null related segment filter")),n.title="Display all annotations if filtering by related segments is enabled but no segments are selected",n.appendChild(t.element),e.element.appendChild(n)}e.element.appendChild(e.registerDisposer(new A(this.linkedSegmentationLayers)).element)}toJSON(){const e=super.toJSON();return e.crossSectionAnnotationSpacing=this.annotationCrossSectionRenderScaleTarget.toJSON(),e.projectionAnnotationSpacing=this.annotationProjectionRenderScaleTarget.toJSON(),void 0!==this.localAnnotations?e.annotations=this.localAnnotations.toJSON():void 0!==this.localAnnotationsJson&&(e.annotations=this.localAnnotationsJson),e.ignoreNullSegmentFilter=this.annotationDisplayState.ignoreNullSegmentFilter.toJSON(),e.shader=this.annotationDisplayState.shader.toJSON(),e.shaderControls=this.annotationDisplayState.shaderControls.toJSON(),Object.assign(e,this.linkedSegmentationLayers.toJSON()),e}}function V(e){return new M.a({shaderError:e.annotationDisplayState.shaderError,fragmentMain:e.annotationDisplayState.shader,shaderControlState:e.annotationDisplayState.shaderControls})}N.type="annotation";class _ extends l.a{constructor(e){super(),this.layer=e,this.codeWidget=this.registerDisposer(V(this.layer)),this.content.appendChild(this.codeWidget.element),this.codeWidget.textEditor.refresh()}}class B extends L.b{constructor(e){super(),this.layer=e,this.codeWidget=this.registerDisposer(V(this.layer));const{element:t}=this;t.appendChild(this.registerDisposer(new w.a(e.annotationProperties,(e,t)=>{if(void 0!==e)for(const n of e){const e=document.createElement("div");e.classList.add("neuroglancer-annotation-shader-property");const i=document.createElement("span");i.classList.add("neuroglancer-annotation-shader-property-type"),i.textContent=n.type;const r=document.createElement("span");r.classList.add("neuroglancer-annotation-shader-property-identifier"),r.textContent=`prop_${n.identifier}`,e.appendChild(i),e.appendChild(r);const{description:s}=n;void 0!==s&&(e.title=s),t.appendChild(e)}})).element);let n=document.createElement("div");n.className="neuroglancer-segmentation-dropdown-skeleton-shader-header";let i=document.createElement("div");i.style.flex="1",i.textContent="Annotation shader:",n.appendChild(i),n.appendChild(Object(E.a)({title:"Show larger editor view",onClick:()=>{new _(this.layer)}})),n.appendChild(Object(x.a)({title:"Documentation on annotation rendering",href:"https://github.com/google/neuroglancer/blob/master/src/neuroglancer/annotation/rendering.md"})),t.appendChild(n),t.appendChild(this.codeWidget.element),t.appendChild(this.registerDisposer(new D.a(e.annotationDisplayState.shaderControls)).element)}}Object(c.r)("annotation",N),Object(c.r)("pointAnnotation",N),Object(c.s)(e=>e.local===a.c.annotations?N:void 0!==e.annotation?N:void 0)}]);
//# sourceMappingURL=main.bundle.js.map